-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
350 lines (283 loc) · 10.4 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
;; -*- lexical-binding: t -*-
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
;;(package-initialize)
(add-to-list 'load-path "~/.emacs.d/lisp")
(require 'init-basic)
(require 'init-elpa)
(require 'init-org)
(require 'init-markdown-mode)
;;(require 'init-company)
(require 'init-rust)
(require 'init-pyim)
(require 'init-consult)
(require 'init-embark)
(require 'init-yasnippet)
(require 'init-lsp-bridge)
(require 'init-move-mode)
(require 'init-youdao-dictionary)
(require 'init-eaf)
;;(pp (macroexpand '(use-package init-xxx)))
(use-package restart-emacs
:ensure t
:bind ("M-s r" . restart-emacs))
(use-package atomic-chrome
:ensure t
:config (atomic-chrome-start-server))
(use-package savehist
:ensure nil
:hook (after-init . savehist-mode)
:init (setq enable-recursive-minibuffers t ; Allow commands in minibuffers
history-length 1000
savehist-additional-variables '(mark-ring
global-mark-ring
search-ring
regexp-search-ring
extended-command-history)
savehist-autosave-interval 300))
(use-package saveplace
:ensure nil
:hook (after-init . save-place-mode))
;; Fix magit issue: (void-function cursor-sensor-move-to-tangible) after 3224b17 #4931
(require 'cursor-sensor)
;;modeline上显示我的所有的按键和执行的命令
;;(keycast-mode t)
;; 增强 minibuffer 补全:vertico 和 Orderless
(vertico-mode t)
;; 无序搜索增强,配置 Marginalia 增强 minubuffer 的 annotation
(setq completion-styles '(orderless))
;; 不用进入变量,在minibuffer就可以预览变量值
(marginalia-mode t)
(setq prefix-help-command 'embark-prefix-help-command) ;; C-key C-h ...
;; 找到描述变量,<f8>,根据提示选项操作
;; 增强文件内搜索和跳转函数定义:Consult
;;replace swiper
;;在文件最开头添加地个 文件作用域的变量设置,设置变量的绑定方式
;; -*- lexical-binding: t -*-
;;(let ((x 1)) ; x is lexically bound.
;; (+ x 3))
;; ⇒ 4
;;(defun getx ()
;; x) ; x is used free in this function.
;;(let ((x 1)) ; x is lexically bound.
;; (getx))
;;error→ Symbol's value as variable is void: x
;;(server-mode t)
(setq tab-always-indent 'complete) ;; 在编辑的时候也可以补全
;;(icomplete-mode t) ;; 当按下 M-x 过一会儿会出现交互式的可选补全
(setq name "geometryolife")
(message name)
(defun func()
(interactive)
(message "hello, %s" name))
(setq name "Joe")
(func)
(global-set-key (kbd "<f2>") 'func)
;; lispy s-expression introduce later
;; mode line
;; eldoc-mode 会在 mini-buffer 告诉你函数签名
;; C-h m ->
;; font-lock-mode 开启语法高亮
;; 更改光标的样式(不能生效,解决方案见第二集)
;; (setq cursor-type 'hollow) ;; 缓冲区
;; (setq-default cursor-type 'box) ;; 全局
;; 重新加载配置文件 M-x load-file
;; 执行当前缓冲区所有 Lisp 命令 M-x eval-buffer
;; REPL read eval print loop -> Happy Hacking
;; C-x C-h => 显示 C-x 绑定的所有快捷键
;; 同理 C-x C-h ...
;; 更改显示字体大小 16pt
;; http://stackoverflow.com/questions/294664/how-to-set-the-font-size-in-emacs
;;(set-face-attribute 'default nil :height 160)
;;让鼠标滚动更好用
;;(setq mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control) . nil)))
;;(setq mouse-wheel-progressive-speed nil)
;; 开启 Tab
;;(add-to-list 'load-path (expand-file-name "~/.emacs.d/elpa/awesome-tab"))
;;(require 'awesome-tab)
;;(awesome-tab-mode t)
(defun awesome-tab-buffer-groups ()
"`awesome-tab-buffer-groups' control buffers' group rules.
Group awesome-tab with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'.
All buffer name start with * will group to \"Emacs\".
Other buffer group by `awesome-tab-get-group-name' with project name."
(list
(cond
((or (string-equal "*" (substring (buffer-name) 0 1))
(memq major-mode '(magit-process-mode
magit-status-mode
magit-diff-mode
magit-log-mode
magit-file-mode
magit-blob-mode
magit-blame-mode)))
"Emacs")
((derived-mode-p 'eshell-mode)
"EShell")
((derived-mode-p 'dired-mode)
"Dired")
((memq major-mode '(org-mode org-agenda-mode diary-mode))
"OrgMode")
((derived-mode-p 'eaf-mode)
"EAF")
(t
(awesome-tab-get-group-name (current-buffer))))))
;; 下面两行的效果完全相同的
;; (quote foo)
;; 'foo
;; quote 的意思是不要执行后面的内容,返回它原本的内容(具体请参考下面的例子)
;;(print '(+ 1 1)) ;; -> (+ 1 1)
;;(print (+ 1 1)) ;; -> 2
;;(require 'recentf)
(recentf-mode 1)
;;(setq recentf-max-menu-item 10)
;; 这个快捷键绑定可以用之后的插件 counsel 代替
;; (global-set-key (kbd "C-x C-r") 'recentf-open-files)
;; (shell-command-to-string "explorer.exe C:\\") ;; 打开C盘
;; (shell-command-to-string "explorer.exe ~/.emacs.d")
;;(shell-command-to-string
;; (encode-coding-string
;; (replace-regexp-in-string "/" "\\\\"
;; (format "explorer.exe %s" (expand-file-name "~/.emacs.d")))
;; 'gbk)) ;; 中文编码,适应中文目录
(defun consult-directory-externally (file)
"Open FILE externally using the default application of the system."
(interactive "fOpen externally: ")
(if (and (eq system-type 'windows-nt)
(fboundp 'w32-shell-execute))
(shell-command-to-string (encode-coding-string (replace-regexp-in-string "/" "\\\\"
(format "explorer.exe %s" (file-name-directory (expand-file-name file)))) 'gbk))
(call-process (pcase system-type
('darwin "open")
('cygwin "cygstart")
(_ "xdg-open"))
nil 0 nil
(file-name-directory (expand-file-name file)))))
;;(define-key embark-file-map (kbd "E") #'consult-directory-externally)
;;打开当前文件的目录
(defun my-open-current-directory ()
(interactive)
(consult-directory-externally default-directory))
;; grep < ack < ag < ripgrep(rg)
;; 增强 embark 和 consult,批量搜索替换大杀器
(package-install 'embark-consult)
(package-install 'wgrep)
(setq wgrep-auto-save-buffer t)
(eval-after-load ;; 延迟加载
'consult ;; 加载完才执行下面的语句
'(eval-after-load
'embark
'(progn
(require 'embark-consult)
(add-hook ;; 希望在 embark-collect-mode 之后执行一个特定的功能,可以使用 add-hook
'embark-collect-mode-hook
#'consult-preview-at-point-mode))))
(defun embark-export-write ()
"Export the current vertico results to a writable buffer if possible.
Supports exporting consult-grep to wgrep, file to wdeired, and consult-location to occur-edit"
(interactive)
(require 'embark)
(require 'wgrep)
(pcase-let ((`(,type . ,candidates)
(run-hook-with-args-until-success 'embark-candidate-collectors)))
(pcase type
('consult-grep (let ((embark-after-export-hook #'wgrep-change-to-wgrep-mode))
(embark-export)))
('file (let ((embark-after-export-hook #'wdired-change-to-wdired-mode))
(embark-export)))
('consult-location (let ((embark-after-export-hook #'occur-edit-mode))
(embark-export)))
(x (user-error "embark category %S doesn't support writable export" x)))))
(define-key minibuffer-local-map (kbd "C-c C-e") 'embark-export-write)
;; C-c C-e -> C-M-% query-replace-regexp
;;使用ripgrep来进行搜索
;;consult-ripgrep
;;everyting
;;consult-locate
;; Encoding -> UTF-8 as the default coding system
;;(when (fboundp 'set-charset-priority)
;; (set-charset-priority 'unicode))
;;(reset-language-environment 'chinese-gbk)
;;(prefer-coding-system 'utf-8-auto)
;; 配置搜索中文
(progn
(setq consult-locate-args (encode-coding-string "es.exe -i -p -r" 'gbk))
(add-to-list 'process-coding-system-alist '("es" gbk . gbk))
)
(eval-after-load 'consult
(progn
(setq
consult-narrow-key "<"
consult-line-numbers-widen t
consult-async-min-input 2
consult-async-refresh-delay 0.15
consult-async-input-throttle 0.2
consult-async-input-debounce 0.1)
))
;; 使用拼音进行搜索
;;(package-install 'pyim)
;;
;;(defun eh-orderless-regexp (orig_func component)
;; (let ((result (funcall orig_func component)))
;; (pyim-cregexp-build result)))
;;
;;
;; (defun toggle-chinese-search ()
;; (interactive)
;; (if (not (advice-member-p #'eh-orderless-regexp 'orderless-regexp))
;; ;; advice-add 不修改已有函数的基础上,使用一个补丁
;; ;; orderless-regexp 对文本过滤时,运用补丁——pyim来增强正则的拼音搜索
;; (advice-add 'orderless-regexp :around #'eh-orderless-regexp)
;; (advice-remove 'orderless-regexp #'eh-orderless-regexp)))
;;
;; (defun disable-py-search (&optional args)
;; (if (advice-member-p #'eh-orderless-regexp 'orderless-regexp)
;; (advice-remove 'orderless-regexp #'eh-orderless-regexp)))
;;
;; ;; (advice-add 'exit-minibuffer :after #'disable-py-search)
;; (add-hook 'minibuffer-exit-hook 'disable-py-search) ;; 退出时禁用,提高流畅性
;;
;; (global-set-key (kbd "s-p") 'toggle-chinese-search) ;; 默认关闭,需要时打开
;;(package-install 'monokai-theme)
;;(load-theme 'monokai t)
(package-install 'doom-themes)
(load-theme 'doom-one t)
;; 增强delete
(require 'hungry-delete)
(global-hungry-delete-mode)
;; 括号匹配
;;(require 'smartparens-config)
;; 宏与函数的区别
;;(setq my-var 1)
;;(setq my-var (1+ my-var))
;; 使用宏实现上面的功能
;;(defmacro inc (var)
;; (list 'setq var (list '1+ var)))
;;(inc my-var)
;;(macroexpand '(inc my-var)) ; DSL
;; 函数无法实现 pass by value
;;(defun inc-2 (var)
;; (setq var (1+ var)))
;; (inc-2 my-var)
;; Backquote allows you to:
;; quote a list, and
;; selectively evaluate elements of the list (with comma ,), or:
;; splice (eval & spread) the element with ,@
;; , 号可以动态求值
;; `(a list of ,(+ 2 3) elements)
;; (a list of 5 elements)
;; '(a list of ,(+ 2 3) elements)
;; (a list of (\, (+ 2 3)) elements)
;; `(a list of (+ 2 3) elements)
;; (a list of (+ 2 3) elements)
;; '(a list of (+ 2 3) elements)
;; (a list of (+ 2 3) elements)
;; ,@ 组合符号
;; (setq some-list '(2 3))
;; 展开列表成元素
;; `(1 ,@some-list 4 ,@some-list) ; form
;; (1 2 3 4 2 3)
(setq custom-file (expand-file-name "~/.emacs.d/custom.el"))
(load custom-file 'no-error 'no-message)