-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyinit.org
513 lines (456 loc) · 14.7 KB
/
myinit.org
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
* Exec Path
#+begin_src emacs-lisp
(add-to-list 'exec-path "/home/bogon/lib/go/bin")
(add-to-list 'exec-path "/home/bogon/.local/share/gem/ruby/3.0.0/bin/")
(remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
#+end_src
* Package Management
对于一个可扩展的工具,包管理是首要的,有关包管理初始化的内容放在了 init.el 中,这里仅仅设置了自动下载
** Use Package
对所有 use-package 管理的包开启 ~:ensure~ 确保自动安装
#+begin_src emacs-lisp
(require 'use-package-ensure)
(setq use-package-always-ensure t)
#+end_src
* Makeup Interface
然后开始设置一个让人有兴趣一直用下去的外观
** 整体外观
首先去掉一些没有用的影响整体观感的部分,因为 Emacs 作为一款程序员喜欢的编辑器,大部分情况下都使用快捷键工作,所以菜单等等并不需要,另外状态很重要,所以需要一个靠谱的 modeline
#+BEGIN_SRC emacs-lisp
(menu-bar-mode 0)
(tool-bar-mode 0)
(scroll-bar-mode 0)
(use-package powerline
:config
(powerline-default-theme))
#+END_SRC
** 编辑界面
程序文本一向以行计数,显示行号是编辑器的重要一项,下面设置显示行号并高亮当前行,
#+BEGIN_SRC emacs-lisp
(setq column-number-mode t)
(global-hl-line-mode t)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
;; 设置默认 Tab 宽度
(setq-default tab-width 4)
;; 高亮行号
(use-package hlinum
:config
(hlinum-activate))
#+END_SRC
** 边缘
#+begin_src emacs-lisp
(set-face-attribute 'fringe nil :background nil)
#+end_src
Disable ugly [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Fringe-Bitmaps.html][bitmap]] in fringe.
#+begin_src emacs-lisp
(define-fringe-bitmap 'left-arrow [])
(define-fringe-bitmap 'left-curly-arrow [])
(define-fringe-bitmap 'left-triangle [])
#+end_src
Display … and ↩ for truncation and wrap.
#+begin_src emacs-lisp
(defface fallback '((t :family "Fira Code Light"
:foreground "gray")) "Fallback")
(set-display-table-slot standard-display-table 'truncation
(make-glyph-code ?… 'fallback))
(set-display-table-slot standard-display-table 'wrap
(make-glyph-code ?↩ 'fallback))
#+end_src
** 主题
主题配置,使用 doom 主题
#+BEGIN_SRC emacs-lisp
(use-package doom-themes
:ensure t
:init
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
(load-theme 'doom-one t)
(doom-themes-visual-bell-config))
#+END_SRC
** 字体
主字体在 early-init.el 中设置了,这里仅涉及中文字体
#+BEGIN_SRC emacs-lisp
;; Default Font
; (set-face-attribute 'default nil :font "Fira Mono 13")
;; Chinese Font
(dolist (charset '(kana han symbol cjk-misc bopomofo))
(set-fontset-font (frame-parameter nil 'font)
charset (font-spec :family "Sarasa Mono SC")))
(setq face-font-rescale-alist '(("Sarasa Mono SC" . 1.2)))
#+END_SRC
Valign 方案听说能完美解决表格编排,不过和 org-indent-mode 一起用有问题,暂时不用,使用换字体的方案
#+begin_src emacs-lisp
;; (use-package valign
;; :config
;; (setq valign-fancy-bar nil))
;; (when (display-graphic-p) (set-face-attribute 'org-table nil :family "M+ 1m" :height 120 :weight 'bold))
#+end_src
* Better Use
一些实用的配置
** try package
#+BEGIN_SRC emacs-lisp
(use-package try
:ensure t)
#+END_SRC
** which-key
#+BEGIN_SRC emacs-lisp
(use-package which-key
:ensure t
:config (which-key-mode))
#+END_SRC
** scrolling
平滑滚动
#+BEGIN_SRC emacs-lisp
(use-package smooth-scrolling
:ensure t
:config
(setq smooth-scroll-margin 3)
(smooth-scrolling-mode 1))
;; (setq scroll-up-aggressively 0.01
;; scroll-down-aggressively 0.01
;; scroll-margin 0
;; scroll-conservatively 5
;; redisplay-skip-fontification-on-input t)
#+END_SRC
** buffer management
#+BEGIN_SRC emacs-lisp
(defalias 'list-buffers 'ibuffer)
#+END_SRC
** window
#+BEGIN_SRC emacs-lisp
(winner-mode 1)
(use-package ace-window
:ensure t
:init
(progn
(global-set-key [remap other-window] 'ace-window)
(custom-set-faces
'(aw-leading-char-face
((t (:inherit ace-jump-face-foreground :height 3.0)))))
))
#+END_SRC
** rainbow-delimiters
#+BEGIN_SRC emacs-lisp
(use-package rainbow-delimiters
:ensure t
:init
(add-hook 'scheme-mode-hook 'rainbow-delimiters-mode)
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
(add-hook 'racket-mode-hook 'rainbow-delimiters-mode)
)
#+END_SRC
** lisp edit
Paredit YYDS
#+begin_src emacs-lisp
(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
#+end_src
* Org-mode
Org mode 是使用 Emacs 的一个重要原因
** Base Config
#+begin_src emacs-lisp
(defun turn-on-org-show-all-inline-images ()
(org-display-inline-images t t))
(setq org-startup-truncated nil)
;; 设置自动折行,但好像吊用没有
(add-hook 'org-mode-hook
(lambda()
(setq truncate-lines nil)))
(add-hook 'org-mode-hook 'turn-on-org-show-all-inline-images)
(add-hook 'org-mode-hook 'org-indent-mode)
(setq org-export-with-sub-superscripts (quote {}))
(setq org-src-fontify-natively t)
;; (use-package org-superstar
;; :after org
;; :hook (org-mode . org-superstar-mode))
#+end_src
** Org-mode todo
#+begin_src emacs-lisp
(setq org-todo-keywords
'((sequence "未开始(p!)" "进行中(t!)" "阻塞中(s!)" "|" "已完成(d!)" "已取消(a@/!)")))
;; 设置任务样式
(setq org-todo-keyword-faces
'(("未开始" . (:foreground "#66cccc" :weight bold))
("阻塞中" . (:foreground "red" :weight bold))
("进行中" . (:foreground "orange" :weight bold))
("已完成" . (:foreground "green" :weight bold))
("已取消" . (:foreground "black" :weight bold))
))
(setq gtd-path (expand-file-name "~/ProjectW/Record"))
(defvar org-gtd-file
(concat gtd-path "/project.org"))
(defun gtd ()
"Open the GTD file."
(interactive)
(find-file org-gtd-file))
;; 设置 Org Agenda 快捷键
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c g") 'gtd)
;; 加入到日程列表里
(setq org-agenda-files (list org-gtd-file))
#+end_src
* File Tree
安装 NeoTree
#+BEGIN_SRC emacs-lisp
(use-package neotree
:ensure t
:init
(global-set-key [f8] 'neotree-toggle)
(global-set-key [f7] 'neotree-find)
(setq neo-theme 'arrow))
#+END_SRC
* Project Navigate
使用 projectile
#+begin_src emacs-lisp
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("C-c p" . projectile-command-map)))
#+end_src
* Helm
#+BEGIN_SRC emacs-lisp
(use-package helm)
(require 'helm)
(require 'helm-config) ;?
(require 'helm-eshell) ;?
(require 'helm-files) ;?
(require 'helm-grep)
(use-package helm-xref
:ensure t)
; do not display invisible candidates
(setq helm-quick-update t)
; open helm buffer inside current window, not occupy whole other window
(setq helm-split-window-in-side-p t)
; fuzzy matching buffer names when non--nil
(setq helm-buffers-fuzzy-matching t)
; move to end or beginning of source when reaching top or bottom of source.
(setq helm-move-to-line-cycle-in-source nil)
; search for library in `require' and `declare-function' sexp.
(setq helm-ff-search-library-in-sexp t)
; scroll 8 lines other window using M-<next>/M-<prior>
(setq helm-scroll-amount 8)
(setq helm-ff-file-name-history-use-recentf t)
(use-package helm-swoop
:bind (("C-s" . helm-swoop)
("C-r" . helm-swoop)))
(define-key global-map [remap find-file] #'helm-find-files)
(define-key global-map [remap execute-extended-command] #'helm-M-x)
(define-key global-map [remap switch-to-buffer] #'helm-mini)
;; (use-package helm-xref
;; :config
;; (setq xref-show-xrefs-function 'helm-xref-show-xrefs))
(helm-mode 1)
#+END_SRC
* Complete
通用补全插件
#+BEGIN_SRC emacs-lisp
(use-package company
:defer t
:init
(add-hook 'prog-mode-hook 'company-mode)
:config
(setq company-minimum-prefix-length 3)
(setq company-tooltip-align-annotations t)
(setq company-show-numbers t)
(setq company-tooltip-limit 10)
(setq company-dabbrev-downcase nil)
(setq company-transformers '(company-sort-by-occurrence))
(setq company-idle-delay 0.1)
:bind
(("M-/" . company-complete)))
(use-package company-box
:hook (company-mode . company-box-mode))
#+END_SRC
* Lsp
#+BEGIN_SRC emacs-lisp
(use-package lsp-mode
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "C-c l")
(setq lsp-python-server 'pyls)
:hook ((python-mode . lsp)
(sh-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration))
:commands lsp
)
;; optionally
(use-package lsp-ui
:commands lsp-ui-mode
:config
(define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
(define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)
:bind
(("s-i" . lsp-ui-imenu))
)
(use-package helm-lsp :commands helm-lsp-workspace-symbol)
#+END_SRC
* Program Langrage
** Python
** C&C++
补全索引使用 lsp ccls
#+BEGIN_SRC emacs-lisp
(setq c-default-style "linux"
c-basic-offset 2)
;; (add-hook 'c-mode-common-hook
;; '(lambda () (setq indent-tabs-mode t)))
(use-package ccls
:hook ((c-mode c++-mode objc-mode cuda-mode) .
(lambda ()
(require 'ccls)
(unless (or (member major-mode '(bison-mode))
(member major-mode '(flex-mode)))
(lsp))))
:config (setq ccls-executable "/usr/bin/ccls"))
#+END_SRC
** Go
#+begin_src emacs-lisp
(add-hook 'go-mode-hook #'lsp-deferred)
;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
#+end_src
** Scheme
#+BEGIN_SRC emacs-lisp
(require 'myscheme)
(use-package racket-mode
:ensure t
:config
(setq racket-racket-program "racket")
(setq racket-raco-program "raco")
:bind
(:map racket-mode-map
("C-x C-j" . racket-run)))
#+END_SRC
** Emacs-lisp
#+BEGIN_SRC emacs-lisp
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)
#+END_SRC
** Clojure
#+begin_src emacs-lisp
(use-package clojure-mode
:ensure t
:hook ((clojure-mode . enable-paredit-mode)
(clojure-mode . rainbow-delimiters-mode)))
#+end_src
* Marked Language
** markdown
#+BEGIN_SRC emacs-lisp
(use-package markdown-mode
:ensure t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init
;; 配置输出指令
(setq markdown-command
"pandoc -f markdown -t html -s -c ~/.emacs.d/markdown/style.css --mathjax --highlight-style pygments"))
(use-package ox-gfm
:ensure ox-gfm)
#+END_SRC
* Other Language Support
#+BEGIN_SRC emacs-lisp
(use-package yaml-mode
:ensure t)
(use-package cmake-mode
:hook
((cmake-mode . lsp)))
#+END_SRC
* Yasnippet
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:ensure t
:init
(yas-global-mode 1)
:config
(yas-reload-all)
(add-hook 'prog-mode-hook #'yas-minor-mode)
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map [C-tab] 'yas-expand))
(use-package yasnippet-snippets
:ensure t)
#+END_SRC
* LaTeX
使用 AuCTex 插件
#+BEGIN_SRC emacs-lisp
(use-package auctex
:defer t
:ensure auctex
:init
(require 'advance-words-count)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook
(lambda ()
(turn-on-auto-fill)
(turn-on-reftex)
(LaTeX-math-mode 1)
(setq TeX-show-complilation nil)
(setq TeX-clean-confirm nil)
(setq TeX-save-query nil)
(setq TeX-view-program-list '(("Okular" "okular %o")))
(setq TeX-view-program-selection
'((output-pdf "Okular")))
(setq TeX-engine 'xetex)
(TeX-global-PDF-mode t)
(add-to-list 'TeX-command-list
'("XeLaTeX" "%'xelatex%(mode)%' %t"
TeX-run-TeX nil t))
(setq TeX-command-default "XeLaTeX")
(setq lsp-tex-server 'texlab)
(lsp))
)
:config
(setq TeX-fold-env-spec-list
(quote (("[figure]" ("figure"))
("[table]" ("table"))
("[itemize]" ("itemize"))
("[overpic]" ("overpic"))))))
#+END_SRC
* Version Control
** Magit
使用 Magit
#+BEGIN_SRC emacs-lisp
(use-package magit
:ensure t
:init
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch-popup))
#+END_SRC
** Diff HL
diff-hl highlights uncommitted changes in the left fringe.
#+begin_src emacs-lisp
(use-package diff-hl
:ensure t
:init
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
:config
(global-diff-hl-mode)
;; Highlight changes on editing.
(diff-hl-flydiff-mode)
;; Makes fringe and margin react to mouse clicks to show the curresponding hunk.
(diff-hl-show-hunk-mouse-mode)
:custom
(diff-hl-draw-borders nil)
:custom-face
(diff-hl-change ((t (:background "#e9cd43"))))
(diff-hl-insert ((t (:background "#03e94f"))))
(diff-hl-delete ((t (:background "#f5597e")))))
#+end_src
* Eshell
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f9>") 'eshell)
#+END_SRC