-
Notifications
You must be signed in to change notification settings - Fork 15
/
init.el
572 lines (481 loc) · 16.5 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
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
;;; package -- Summary
;;; Commentary:
;;; Code:
;;; -*- 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)
(setq package-archives
'(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(require 'use-package)
;;; guess-word
(use-package guess-word
:load-path "./site-lisp/emacs-guess-word-game"
:config
(setq guess-word-org-file (f-expand "~/org/esl.org"))
:commands (guess-word))
;;; org-mode
(use-package org
:config
(defun org-clocking-buffer (&rest _))
(auto-save-mode)
(org-clock-persistence-insinuate)
(setq org-clock-history-length 23)
(setq org-clock-in-resume t)
(setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
(setq org-clock-into-drawer t)
(setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
(setq org-clock-report-include-clocking-task t)
(setq org-enforce-todo-checkbox-dependencies t)
(setq org-enforce-todo-dependencies t)
(require 'org-crypt)
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt")))
(when (and (file-exists-p "~/org")
(file-directory-p "~/org"))
(setq org-agenda-files '("~/org")))
(setq org-crypt-key "liquanwei")
(define-key org-mode-map (kbd "C-c u d") 'org-decrypt-entry)
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t)
(emacs-lisp . t)
(C . t)
(js . t)
(calc . t)
(octave . t)
(python . t)))
(setq org-clock-into-drawer t)
(setq org-agenda-include-diary t)
(setq org-src-fontify-natively t)
(setq org-confirm-babel-evaluate nil)
(setq org-image-actual-width 400)
(setq org-log-done 'time)
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
(defun skip-item-by-closed-in-two-weeks ()
"Skip tree when out two weeks"
(let ((closed (org-entry-get (point) "CLOSED" nil)))
(if (and
closed
(< (- (float-time)
(org-time-string-to-seconds closed))
(* 14 24 60 60)))
nil
(save-excursion (org-end-of-subtree)))))
(setq org-agenda-custom-commands
'(
("a" "Agenda for work"
(
(agenda "" ((org-agenda-skip-function '(org-agenda-skip-entry-if 'nottodo '("TODO" "DONE")))))
(todo "NOTE" ((org-agenda-skip-function 'skip-item-by-closed-in-two-weeks)))
(todo "LATER")
(alltodo "" ((org-agenda-skip-function '(org-agenda-skip-entry-if 'scheduled))))
))
("n" todo "NOTE")))
;; 关于org—capture的配置,灵感捕捉会存放在 work.org 目录中
(setq org-default-notes-file (expand-file-name (concat (car org-agenda-files) "/work.org")))
;; 配置模板,我常用的就是一级目录的模板,直接放个一级entry为该项
(setq org-capture-templates
'(
("t" "添加一条到work.org"
entry (file org-default-notes-file)
"* TODO %?\n CAPTURE: %T %i \n %F"
:jump-to-captured t
:empty-lines 1)))
(setq org-todo-keyword-faces
'(("TODO" . org-warning) ("LATER" . "purple")
("NOTE" . (:foreground "blue" :weight bold))
("CANCELED" . "gray")))
(setq org-todo-keywords
'((sequence "TODO(t)" "|" "DONE(d)")
(sequence "TODO" "LATER(l)" "|" "DONE")
(sequence "|" "NOTE(n)")
(sequence "|" "CANCELED(c)")
))
:bind
("C-c a" . org-agenda)
("C-c c" . org-capture)
("C-c b" . org-switchb)
)
;;; smartparens
(use-package smartparens
:ensure
:init
(use-package smartparens-config)
(use-package smartparens-html)
(use-package smartparens-org)
(use-package smartparens-python)
(smartparens-global-mode 1)
(show-smartparens-global-mode 1)
:bind (
("C-M-f" . sp-forward-sexp)
("C-M-b" . sp-backward-sexp)
("C-M-n" . sp-next-sexp)
("C-M-p" . sp-previous-sexp)
("C-M-k" . sp-kill-sexp)
("M-[" . sp-unwrap-sexp)))
(use-package dash
:ensure)
;;; yasnippet
(use-package yasnippet
:ensure
:config
(yas-reload-all)
:hook (after-load . (lambda () (yas-global-mode t))))
(use-package yasnippet-snippets
:ensure)
(use-package dockerfile-mode
:ensure)
;;; avy
(use-package avy
:ensure t
:bind (("M-1" . avy-goto-char)
("M-l" . avy-goto-line)))
;;; projectile
(use-package projectile
:config
(setq projectile-create-missing-test-files t)
(setq projectile-enable-caching t)
(setq projectile-require-project-root nil)
(projectile-register-project-type
'npm '("package.json")
:compile "npm run build"
:test "npm run test"
:run "npm run start"
:test-suffix ".spec"))
(use-package neotree
:ensure t
:config
(setq neo-autorefresh nil)
(defun neotree-project-dir ()
"Open NeoTree using the git root."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-toggle)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-find file-name)))
(message "Could not find git project root."))))
(global-set-key [f8] 'neotree-project-dir))
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(projectile-global-mode)
;;; magit
(use-package magit
:ensure
:init
(use-package magit-blame)
(setq magit-refresh-status-buffer nil)
:bind (("C-c g c" . magit-checkout)
("C-c g f c" . magit-file-checkout)))
;;; js config
(use-package emmet-mode
:ensure)
;; 默认C-j补全配置
(use-package emmet-mode
:init
(add-hook 'js-mode-hook 'emmet-mode)
(add-hook 'js-mode-hook 'editorconfig-mode)
:config
(setq emmet-preview-default nil))
;; js,jsx,ts,tsx自动补全配置
(use-package posframe
:ensure)
(use-package yasnippet :ensure
:init
(yas-global-mode 1))
(use-package lsp-bridge
:load-path "./site-lisp/lsp-bridge"
:hook
(after-init . global-lsp-bridge-mode)
:config
(setq lsp-bridge-lang-server-extension-list
'(
(("js") . "javascript")
(("ts") . "typescript")
(("tsx") . "typescriptreact"))))
(setq acm-enable-icon nil)
;; 在写css时候还是希望能有company补全一下的
(add-hook 'less-css-mode-hook 'company-mode)
(add-hook 'css-mode 'company-mode)
;; 为了使用js2-refactor, 需要开启js2-minor-mode
(use-package js2-mode :ensure)
(use-package js2-refactor :ensure
:config
(js2r-add-keybindings-with-prefix "C-c C-r")
)
;;; theme
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(markdown-code-face ((t (:inherit fixed-pitch :background "gray20" :foreground "dark orange"))))
'(markdown-header-face-1 ((t (:inherit markdown-header-face :height 2.0))))
'(markdown-header-face-2 ((t (:inherit markdown-header-face :height 1.8)))))
;;; dashboard
(use-package dashboard
:ensure
:init
(dashboard-setup-startup-hook)
:config
(setq dashboard-banner-logo-title "Happy Coding")
(setq dashboard-startup-banner "~/.emacs.d/logo.png")
(setq dashboard-items
'((recents . 5)
(bookmarks . 5)
(projects . 3)
(agenda . 5))))
(use-package diminish
:ensure
:init
(diminish 'projectile-mode)
(diminish 'company-mode)
(diminish 'guide-key-mode)
(diminish 'ivy-mode))
(use-package pass
:ensure
:config
(setq password-store-executable "pass"))
(use-package comint
:config
(add-hook 'comint-mode-hook 'company-mode))
(use-package dimmer
:ensure
:init
(dimmer-activate))
(use-package slime
:ensure
:config
(setq inferior-lisp-program "sbcl"))
(use-package youdao-dictionary
:bind (("C-c t y" . youdao-dictionary-search-at-point+)
("C-c t C-y" . youdao-dictionary-play-voice-at-point)))
(use-package mw-thesaurus
:ensure
:bind (("C-c t w" . mw-thesaurus--lookup-at-point)))
(use-package expand-region
:ensure)
(global-set-key (kbd "C-=") 'er/expand-region)
(use-package which-key
:ensure
:init
(which-key-mode))
;;; markdown
(use-package markdown-mode
:ensure
:config
(define-key markdown-mode-map (kbd "C-c C-c") 'markdown-preview-mode))
(use-package markdown-preview-mode
:ensure t
:defer t)
;;; editorconfig
(use-package editorconfig
:ensure)
;;; helpful
(use-package helpful
:ensure
:bind
(
("C-h f" . helpful-function)
("C-h g" . helpful-macro)))
;;; display
(setq-default indent-tabs-mode nil)
(tool-bar-mode 0)
(menu-bar-mode 0)
(setq frame-title-format
(list (format "%s %%S: %%j" (system-name))
'(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
(eval-after-load
'compile
'(add-hook 'compilation-filter-hook
(lambda () (ansi-color-process-output nil))))
(display-time-mode)
(when (display-graphic-p)
(scroll-bar-mode -1))
;;; macos
(setq mac-option-key-is-meta t)
(setq mac-command-key-is-meta nil)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(if (string-equal system-type "cygwin")
(progn
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)
))
;;; whitespace
(use-package whitespace-cleanup-mode
:ensure t
:config
(add-hook 'before-save-hook 'whitespace-cleanup))
;;; ivy
(use-package ivy
:ensure
:config
(ivy-mode t)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
(define-key global-map (kbd "C-x C-b") 'ivy-switch-buffer)
(define-key global-map (kbd "C-s") 'swiper)
(define-key global-map (kbd "C-x C-f") 'counsel-find-file)
(define-key global-map (kbd "M-x") 'counsel-M-x))
;;; dash
(use-package counsel-dash
:ensure
:config
(setq counsel-dash-browser-func 'browse-web)
:bind (("C-c C-v a" . counsel-dash-activate-docset)
("C-c C-v q" . counsel-dash)))
;;; haskell-mode
(use-package haskell-mode
:ensure
:config
(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile))
;;; emacs-lisp-mode
(add-hook 'emacs-lisp-mode-hook 'company-mode)
(define-key lisp-mode-map (kbd "C-c C-c") 'eval-buffer)
(define-key emacs-lisp-mode-map (kbd "C-c C-c") 'eval-buffer)
;;; web-mode
(use-package web-beautify
:ensure)
(defun setup-web-mode-company-mode ()
(setq-local
company-backends
'(company-files company-etags company-dabbrev company-yasnippet company-keywords company-css)))
(use-package web-mode
:ensure t
:mode (
("\\.vue\\'" . web-mode)
("\\.less\\'" . css-mode)
("\\.json\\'" . web-mode)
("\\.html\\'" . web-mode))
:config
(add-hook 'web-mode-hook 'company-mode)
(add-hook 'web-mode-hook 'setup-web-mode-company-mode)
(add-hook 'web-mode-hook 'emmet-mode)
(add-hook 'web-mode-hook 'smartparens-mode)
(add-hook 'web-mode-hook 'editorconfig-mode)
(add-hook 'web-mode-hook
(lambda ()
(progn
(setq web-mode-script-padding 0)
(when (string= web-mode-content-type "jsx")
(progn
(setq-local emmet-expand-jsx-className? t))))))
(define-key web-mode-map (kbd "C-j") 'emmet-expand-line)
(define-key web-mode-map (kbd "C-c z z") 'nodejs-repl)
(define-key web-mode-map (kbd "C-c z r") 'nodejs-repl-send-region)
(define-key web-mode-map (kbd "C-c z l") 'nodejs-repl-send-last-sexp)
(add-to-list 'web-mode-indentation-params '("lineup-calls" . nil))
(add-to-list 'web-mode-content-types '("html" . "\\.vue\\'"))
(add-to-list 'web-mode-content-types '("json" . "\\.json\\'"))
(add-to-list 'web-mode-content-types '("jsx" . ".\\.js[x]?\\'")))
;;; company
(use-package company-quickhelp
:ensure)
(use-package company
:ensure t
:config
(setq company-minimum-prefix-length 1)
(setq company-dabbrev-downcase nil)
(setq company-dabbrev-ignore-case nil)
(setq company-idle-delay 0.5)
(setq company-echo-delay 0.5)
(add-hook 'company-mode-hook 'company-quickhelp-mode)
(define-key company-active-map (kbd "M-n") nil)
(define-key company-active-map (kbd "M-p") nil)
(define-key company-active-map (kbd "C-n") 'company-select-next)
(define-key company-active-map (kbd "<tab>") 'company-select-next)
(define-key company-active-map (kbd "C-p") 'company-select-previous))
;;; eshell
(use-package eshell-git-prompt
:ensure)
(use-package eshell
:config
(remove-hook 'completion-at-point-functions 'pcomplete-completions-at-point t))
(use-package eshell-functions
:load-path "./lisp")
;;; emacs config
(let ((tempname (expand-file-name "setting.el" user-emacs-directory)))
(when (file-exists-p tempname)
(delete-file tempname)))
(setq-default browse-url-browser-function 'eww-browse-url)
(global-unset-key (kbd "C-\\"))
;; (require 'f)
;; (when (f-exists-p "/usr/share/emacs/site-lisp/mu4e/mu4e.el")
;; (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
;; (require 'mu4e))
(use-package citre
:load-path "./site-lisp/citre")
(use-package eaf
:load-path "./site-lisp/emacs-application-framework"
:commands (eaf-open)
:config
(require 'eaf-pdf-viewer)
)
;; (require 'citre)
;; (require 'citre-config)
(unless (f-directory-p "~/.emacs.d/backups")
(f-mkdir "~/.emacs.d/backups"))
(unless (f-directory-p "~/.emacs.d/autosaves")
(f-mkdir "~/.emacs.d/autosaves"))
(custom-set-variables
'(auto-save-file-name-transforms '((".*" "~/.emacs.d/autosaves/" t)))
'(backup-directory-alist '((".*" . "~/.emacs.d/backups/"))))
(setq create-lockfiles nil)
(global-auto-revert-mode)
(define-key global-map (kbd "C-x C-n") '(lambda () (interactive) (other-window 1)))
(define-key global-map (kbd "C-x C-p") '(lambda () (interactive) (other-window -1)))
(define-key global-map (kbd "C--") 'execute-extended-command)
(setq backup-by-copying t
backup-directory-alist
'(("." . "~/.saves"))
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(set-language-environment "UTF-8")
(define-key global-map (kbd "C-c ,") 'rename-buffer)
(use-package exec-path-from-shell
:ensure)
(exec-path-from-shell-copy-env "PATH")
(setenv "TZ" "Asia/Shanghai")
(use-package hl-line
:ensure
:hook (after-init . global-hl-line-mode))
;;; init.el ends here
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-save-file-name-transforms '((".*" "~/.emacs.d/autosaves/" t)))
'(backup-directory-alist '((".*" . "~/.emacs.d/backups/")))
'(dired-listing-switches "-alh")
'(line-number-mode nil)
'(package-selected-packages
'(lsp-bridge rust-mode js2-refactor multiple-cursors emmet-jsx-major-modes js-mode js2-mode posframe yaml-mode pdf-tools csv-mode org-analyzer edit-indirect org tide flycheck-mode flycheck web-beautify neotree json-mode ag company-quickhelp company-tern window-purpose markdown-preview-mode markdown-mode python-mode editorconfig helpful pass diminish dashboard snazzy-theme base16-theme dante grizzl hackernews youdao-dictionary counsel-projectile projectile avy magit whitespace-cleanup-mode counsel-dash haskell-mode web-mode nodejs-repl emmet-mode dumb-jump dockerfile-mode company-jedi company eshell-git-prompt smartparens mode-icons org-download s)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(markdown-code-face ((t (:inherit fixed-pitch :background "gray20" :foreground "dark orange"))))
'(markdown-header-face-1 ((t (:inherit markdown-header-face :height 2.0))))
'(markdown-header-face-2 ((t (:inherit markdown-header-face :height 1.8))))
'(minibuffer-prompt ((t (:foreground "blue" :weight bold)))))
(with-current-buffer (get-buffer " *Echo Area 0*") ; the leading space character is correct
(setq-local face-remapping-alist
'((default (:foreground "red") variable-pitch)))) ; etc.