dotfiles

Alpine Linux dotfiles

git clone git://git.lin.moe/dotfiles.git

  1;;; package --- 编程语言配置
  2;;; Commentary:
  3
  4;;; Code:
  5;; Python
  6(use-package python
  7  :if (executable-find "python")
  8  :mode ("SCon\(struct\|script\)$" . python-mode)
  9  :config
 10  (setq lsp-diagnostic-package :none
 11        python-indent-offset 4)
 12  :hook
 13  (flycheck-add-next-checker 'python-flake8 'lsp)
 14  :interpreter ("python[0-9.]*" . python-mode))
 15
 16(use-package py-autopep8
 17  :config
 18  (setq py-autopep8-options '("--max-line-length=130" "--aggressive"))
 19  :hook ((python-mode) . py-autopep8-mode))
 20
 21;; Golang
 22(use-package go-mode
 23  :if (executable-find "go")
 24  :mode (("\\.go\\'" . go-mode))
 25  :hook  ((before-save . gofmt-before-save))
 26  :config
 27  (setq gofmt-command "goimports"
 28        godoc-command "go doc -all"))
 29
 30(use-package ob-go)
 31
 32;; C
 33(use-package cc-mode
 34  :hook ((c-mode . (lambda () (indent-tabs-mode 1)))
 35         (c++-mode . (lambda () (indent-tabs-mode 1))))
 36  :config
 37  ;; fix completion for c-mode
 38  (when (equal tab-always-indent 'complete)
 39    (define-key c-mode-base-map [remap c-indent-line-or-region] #'completion-at-point))
 40  :bind
 41  (:map c++-mode-map
 42        ("TAB" . indent-for-tab-command))
 43  (:map c-mode-map
 44        ("TAB" . indent-for-tab-command)))
 45
 46(use-package clang-format
 47  :init
 48  (setq clang-format-style '"file")
 49  (setq clang-format-fallback-style '"LLVM")
 50  :hook ((c-mode . clang-format-on-save-mode)
 51         (c++-mode . clang-format-on-save-mode)))
 52
 53;;  Zig
 54(use-package zig-mode
 55  :if (executable-find "zig")
 56  :mode (("\\.zig\\'" . zig-mode))
 57  :config
 58  (setq zig-format-on-save nil)
 59  :hook ((zig-mode . (lambda () (indent-tabs-mode -1)))))
 60
 61(use-package vue-mode
 62  :mode (("\\.vue\\'" . vue-mode))
 63  :hook ((vue-mode . (lambda () (indent-tabs-mode -1)))))
 64
 65(use-package sh-script
 66  :mode(("\\.sh\\'" . sh-mode)
 67        ("APKBUILD" . sh-mode))
 68  :config (setq sh-basic-offset 8)
 69
 70  :hook ((sh-mode . 'indent-tabs-mode))
 71         (after-save . (lambda () (executable-make-buffer-file-executable-if-script-p))))
 72
 73(use-package emacs
 74  :config
 75  (setq which-func-modes '(prog-mode))
 76  :hook ((prog-mode . (lambda () (which-function-mode 1)))
 77         (prog-mode . (lambda () (hs-minor-mode 1)))))
 78(use-package hideshow
 79  :config
 80  (defun hs-cycle (&optional level)
 81  (interactive "p")
 82  (let (message-log-max
 83        (inhibit-message t))
 84    (if (= level 1)
 85        (pcase last-command
 86          ('hs-cycle
 87           (hs-hide-level 1)
 88           (setq this-command 'hs-cycle-children))
 89          ('hs-cycle-children
 90           ;; TODO: Fix this case. `hs-show-block' needs to be
 91           ;; called twice to open all folds of the parent
 92           ;; block.
 93           (save-excursion (hs-show-block))
 94           (hs-show-block)
 95           (setq this-command 'hs-cycle-subtree))
 96          ('hs-cycle-subtree
 97           (hs-hide-block))
 98          (_
 99           (if (not (hs-already-hidden-p))
100               (hs-hide-block)
101             (hs-hide-level 1)
102             (setq this-command 'hs-cycle-children))))
103      (hs-hide-level level)
104      (setq this-command 'hs-hide-level))))
105  (defun hs-global-cycle ()
106    (interactive)
107    (pcase last-command
108      ('hs-global-cycle
109       (save-excursion (hs-show-all))
110       (setq this-command 'hs-global-show))
111      (_ (hs-hide-all))))
112  :bind
113  (:map hs-minor-mode-map
114   ("C-<tab>" . hs-cycle)
115   ("<backtab>" . hs-global-cycle)))
116
117(use-package compile
118  :config
119  (require 'ansi-color)
120  :hook ((compilation-filter . ansi-color-compilation-filter)))
121
122(use-package compile-multi
123  :config
124  (setq compile-multi-config '(((file-exists-p "Makefile")
125                                ("make:build" . "make build")
126                                ("make:test" . "make test")
127                                ("make:all" . "make all"))
128                               ((file-exists-p "meson.build")
129                                ("meson:test" . "meson test -C build")
130                                ("meson:compile" . "meson compile -C build")
131                                ("meson:setup" . "meson setup build"))
132                               ((file-exists-p "APKBUILD")
133                                ("apk:all" . "abuild -r")
134                                ("apk:build-depends" . "abuild deps")
135                                ("apk:prepare-source" . "abuild clean && abuild fetch && abuild unpack && abuild prepare")
136                                ("apk:build" . "abuild build")
137                                ("apk:check" . "abuild check")
138                                ("apk:clean" . "abuild clean"))))
139  :bind
140  ("C-c C-e" . compile-multi))
141
142(provide 'init-programing)
143;;; init-programing.el ends here