-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinit.el
278 lines (240 loc) · 9.74 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
;;; init.el --- the entry of emacs config -*- lexical-binding: t -*-
;; Author: Cabins
;; Github: https://github.com/cabins-emacs.d
;;; Commentary:
;; (c) Cabins Kong, 2022-
;;; Code:
(defvar cabins-os-win (memq system-type '(ms-dos windows-nt cygwin)))
(defvar cabins-os-mac (eq system-type 'darwin))
(when (find-font (font-spec :family "Sarasa Mono SC"))
(set-face-attribute 'default nil :family "Sarasa Mono SC"))
;; packages
(add-to-list 'load-path (concat user-emacs-directory "lisp"))
(require 'init-functions)
(use-package package
:hook after-init-hook
:config
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(unless (bound-and-true-p package--initialized)
(package-initialize)))
;; Emacs builtin packages
(setq-default auto-window-vscroll nil
default-directory "~"
default-text-properties '(line-spacing 0.2 line-height 1.2) ;default line height
frame-title-format "%b"
help-window-select t
initial-major-mode 'fundamental-mode
inhibit-startup-screen t ; disable the startup screen splash
isearch-allow-motion t
isearch-lazy-count t
kill-whole-line t
mode-line-compact t
make-backup-files nil ; disable backup file
read-process-output-max (* 4 1024 1024)
require-final-newline t
scroll-conservatively 1000
show-trailing-whitespace t
system-time-locale "C"
use-short-answers t)
;; auto revert
;; `global-auto-revert-mode' is provided by autorevert.el (builtin)
(add-hook 'after-init-hook 'global-auto-revert-mode)
;; auto save to the visited file (provided by `files.el')
(add-hook 'after-init-hook 'auto-save-visited-mode)
;; Delete Behavior
;; `delete-selection-mode' is provided by delsel.el (builtin)
(add-hook 'after-init-hook 'delete-selection-mode)
;; visual-line-mode
(add-hook 'after-init-hook 'global-visual-line-mode)
;; pixel-scroll-precise-mode
(add-hook 'after-init-hook 'pixel-scroll-precision-mode)
;; fido-mode
;; `fido-mode' is provided by icomplete.el
(use-package icomplete
:hook (after-init . fido-mode)
:config (setq completions-detailed t))
;; Highlight Current Line
(use-package hl-line
:when (display-graphic-p)
:hook (prog-mode . hl-line-mode))
;; ibuffer
(defalias 'list-buffers 'ibuffer)
;; Org Mode
(use-package org
:hook (org-mode . org-num-mode)
:config
(setq org-hide-leading-stars t
org-hide-emphasis-markers t
org-startup-indented t))
;; Pulse the cursor line
(dolist (cmd '(recenter-top-bottom other-window))
(advice-add cmd :after (lambda (&rest _) (pulse-momentary-highlight-one-line))))
;; Show Paren Mode
(use-package paren
:config
(setq show-paren-when-point-in-periphery t
show-paren-when-point-inside-paren t
show-paren-style 'mixed))
;; Recentf
(use-package recentf
:hook (after-init . recentf-mode)
;; recentf-open since v29.1, recentf-open-files since v22
:bind (("C-c r" . #'recentf-open)))
;; windmove.el, use <SHIFT - arrow key> to switch buffers
(use-package windmove
:config (windmove-default-keybindings))
;; Third part packages
;; make use-package default behavior better
;; with `use-package-always-ensure' you won't need ":ensure t" all the time
;; with `use-package-always-defer' you won't need ":defer t" all the time
(setq use-package-enable-imenu-support t
use-package-expand-minimally t)
;; Settings for company, auto-complete only for coding.
(use-package company
:ensure t
:hook (prog-mode . company-mode))
;; Settings for exec-path-from-shell
;; fix the PATH environment variable issue
(use-package exec-path-from-shell
:ensure t
:when (or (memq window-system '(mac ns x))
(unless cabins-os-win
(daemonp)))
:init (exec-path-from-shell-initialize))
;; format all, formatter for almost languages
;; great for programmers
(use-package format-all :ensure t
;; enable format on save with format-all-mode
;; :hook ((prog-mode . format-all-mode)
;; (format-all-mode . format-all-ensure-formatter))
;; and bind a shortcut to manual format
:bind ("C-c f" . #'format-all-region-or-buffer))
;; iedit - edit same text in one buffer or region
(use-package iedit
:ensure t
:bind ("C-;" . iedit-mode))
;; move-dup, move/copy line or region
(use-package move-dup
:ensure t
:hook (after-init . global-move-dup-mode))
;; Settings for which-key - suggest next key
(use-package which-key :ensure t
:hook (after-init . which-key-mode))
;;Configs for OS
;; Special configs for MS-Windows
(when (and cabins-os-win
(boundp 'w32-get-true-file-attributes))
(setq w32-get-true-file-attributes nil
w32-pipe-read-delay 0
w32-pipe-buffer-size (* 64 1024)))
;; Special configs for macOS
(when cabins-os-mac
(setq mac-command-modifier 'meta
mac-option-modifier 'super
ns-use-native-fullscreen t))
;; solve the Chinese paste issue
;; let Emacs auto-guess the selection coding according to the Windows/system settings
(prefer-coding-system 'utf-8)
;; (setq locale-coding-system 'utf-8)
(unless cabins-os-win
(set-selection-coding-system 'utf-8))
;; Configs for programming languages
(add-hook 'prog-mode-hook (lambda () (setq-local column-number-mode t)))
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'prog-mode-hook 'electric-pair-mode)
(add-hook 'prog-mode-hook 'flymake-mode)
(add-hook 'prog-mode-hook 'hs-minor-mode)
(add-hook 'prog-mode-hook 'prettify-symbols-mode)
(add-hook 'prog-mode-hook 'which-function-mode)
;; Flymake
(use-package flymake
:hook (prog-mode . flymake-mode)
:bind (("M-n" . #'flymake-goto-next-error)
("M-p" . #'flymake-goto-prev-error)))
;; Protobuf file support
(use-package protobuf-mode
:ensure t
:mode "\\.proto\\'")
;; Markdown file support
(use-package markdown-mode
:ensure t)
;; Run code
(use-package quickrun
:ensure t
:when (derived-mode-p 'prog-mode))
;; HTTP Request
(use-package restclient
:ensure t
:mode (("\\.http\\'" . restclient-mode)))
;; Language Server (eglot - builtin since v29)
(use-package eglot
:bind ("C-c e f" . eglot-format)
:init
(advice-add 'eglot-code-action-organize-imports :before #'eglot-format-buffer)
(add-hook 'eglot-managed-mode-hook (lambda () (add-hook 'before-save-hook #'eglot-format-buffer)))
(add-hook 'prog-mode-hook
(lambda () (unless (member major-mode '(emacs-lisp-mode))
(eglot-ensure)))))
(use-package treesit
:when (and (fboundp 'treesit-available-p) (treesit-available-p))
:mode (("\\(?:Dockerfile\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'" . dockerfile-ts-mode)
("\\.go\\'" . go-ts-mode)
("/go\\.mod\\'" . go-mod-ts-mode)
("\\.rs\\'" . rust-ts-mode)
("\\.ts\\'" . typescript-ts-mode)
("\\.y[a]?ml\\'" . yaml-ts-mode))
:config (setq treesit-font-lock-level 4)
:init
(setq major-mode-remap-alist
'((sh-mode . bash-ts-mode)
(c-mode . c-ts-mode)
(c++-mode . c++-ts-mode)
(c-or-c++-mode . c-or-c++-ts-mode)
(css-mode . css-ts-mode)
(js-mode . js-ts-mode)
(java-mode . java-ts-mode)
(js-json-mode . json-ts-mode)
(makefile-mode . cmake-ts-mode)
(python-mode . python-ts-mode)
(ruby-mode . ruby-ts-mode)
(conf-toml-mode . toml-ts-mode)))
(setq treesit-language-source-alist
'((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
(c . ("https://github.com/tree-sitter/tree-sitter-c"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
(css . ("https://github.com/tree-sitter/tree-sitter-css"))
(cmake . ("https://github.com/uyha/tree-sitter-cmake"))
(csharp . ("https://github.com/tree-sitter/tree-sitter-c-sharp.git"))
(dockerfile . ("https://github.com/camdencheek/tree-sitter-dockerfile"))
(elisp . ("https://github.com/Wilfred/tree-sitter-elisp"))
(go . ("https://github.com/tree-sitter/tree-sitter-go"))
(gomod . ("https://github.com/camdencheek/tree-sitter-go-mod.git"))
(html . ("https://github.com/tree-sitter/tree-sitter-html"))
(java . ("https://github.com/tree-sitter/tree-sitter-java.git"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(json . ("https://github.com/tree-sitter/tree-sitter-json"))
(lua . ("https://github.com/Azganoth/tree-sitter-lua"))
(make . ("https://github.com/alemuller/tree-sitter-make"))
(markdown . ("https://github.com/MDeiml/tree-sitter-markdown" nil "tree-sitter-markdown/src"))
(ocaml . ("https://github.com/tree-sitter/tree-sitter-ocaml" nil "ocaml/src"))
(org . ("https://github.com/milisims/tree-sitter-org"))
(python . ("https://github.com/tree-sitter/tree-sitter-python"))
(php . ("https://github.com/tree-sitter/tree-sitter-php"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" nil "typescript/src"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" nil "tsx/src"))
(ruby . ("https://github.com/tree-sitter/tree-sitter-ruby"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
(sql . ("https://github.com/m-novikov/tree-sitter-sql"))
(vue . ("https://github.com/merico-dev/tree-sitter-vue"))
(yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))
(toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
(zig . ("https://github.com/GrayJack/tree-sitter-zig")))))
(setq custom-file (locate-user-emacs-file "custom.el"))
(when (file-exists-p custom-file)
(load custom-file))
(provide 'init)
;;; init.el ends here
;;; Local Variables:
;; coding: utf-8
;; byte-compile-warnings: (not unresolved obsolete)
;; End: