forked from qinains/clojure-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
304 lines (251 loc) · 10.1 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
;;; init.el --- Clojure 开发常用配置
;;; Commentary:
;; 请查看 README.md 文件
;;; Code:
;; 40MB以后才进行垃圾回收(默认是 400000 )
(setq gc-cons-threshold 40000000)
;; 当打开超过100MB的文件的时候警告
(setq large-file-warning-threshold 100000000)
(setq inhibit-startup-screen t)
;; 稳定的安装包
(defvar melpa-stable-packages
'(cider
clj-refactor
clojure-mode
clojure-mode-extra-font-locking
clojure-snippets
company
flx-ido
magit
markdown-mode
projectile
rainbow-delimiters
smex
undo-tree
web-mode))
;; 开发中的安装包
(defvar melpa-dev-packages
'(4clojure
flycheck-clojure
flycheck-pos-tip
moe-theme
smartparens
sr-speedbar))
(defun install ()
"Install the packages."
(interactive)
(package-initialize)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/")))
(package-refresh-contents)
(dolist (p melpa-stable-packages)
(unless (package-installed-p p)
(message "Installing %s" (symbol-name p))
(package-install p)))
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(package-refresh-contents)
(dolist (p melpa-dev-packages)
(unless (package-installed-p p)
(message "Installing %s" (symbol-name p))
(package-install p)))
(message "All packages has installed."))
(defun update-packages ()
"刷新包内容,更新包."
(package-refresh-contents)
(require 'epl)
(epl-upgrade))
(defun update-stable-packages ()
"只更新稳定的安装包."
(interactive)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://stable.melpa.org/packages/")))
(update-packages)
(message "Stable-packages has updated."))
(defun update-dev-packages ()
"只更新开发中的安装包."
(interactive )
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(package-refresh-contents)
(require 'epl)
(dolist (p melpa-dev-packages)
(if (epl-package-outdated-p p)
(progn
(epl-package-install (epl-upgrade-available (car (epl-find-upgrades (epl-find-installed-packages p)))) 'force)
(epl-package-delete (epl-upgrade-installed (car (epl-find-upgrades (epl-find-installed-packages p))))))))
(message "Dev-packages has updated."))
(defun update ()
"所有的安装包都更新到开发中的版本."
(interactive)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(update-packages)
(message "All packages has updated."))
(add-hook 'after-init-hook
(lambda ()
(when (not (version< emacs-version "24.1"))
;; 设置字体
(set-frame-font "-outline-文泉驿等宽微米黑-normal-normal-normal-sans-13-*-*-*-p-*-iso8859-1")
(tool-bar-mode -1)
(scroll-bar-mode -1)
(electric-indent-mode)
(global-linum-mode)
;; 更好的显示函数名
(global-prettify-symbols-mode))
;; 如果是windows系统
(if (memq window-system '(w32))
(progn
;; 修复https的git push不了的问题
(setenv "GIT_ASKPASS" "git-gui--askpass")))
;; 光标显示为一竖线
(setq-default cursor-type 'bar)
;; 设置标题栏显示文件的完整路径名
(setq frame-title-format
'("%S" (buffer-file-name "%f" (dired-directory dired-directory "%b"))))
;; C-x C-f后默认打开的文件夹
(setq default-directory "~/")
;; 当要回答yes或no时,直接输入y或n
(fset 'yes-or-no-p 'y-or-n-p)
;; 编码
;; 显示当前文件编码,C-h C (或者M-x describe-current-coding-system)
;; 如果打开的文件有乱码,还原成文件默认编码:C-x <RET> r <RET> (或者 M-x revert-buffer-with-coding-system)
;; 如果想转码,改变当前buffer的编码为UTF-8:C-x <RET> f utf-8 (或者 M-x set-buffer-file-coding-system)
(prefer-coding-system 'utf-8)
;; 新建的文件都保存成UTF-8编码
(setq buffer-file-coding-system 'utf-8)
;; tab键和新行自动缩进
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))
(setq column-number-mode t)
(setq size-indication-mode t)
(setq visible-bell t)
;; C-c,C-v,C-x,C-z复制、粘贴、剪切、撤销
(cua-mode)
(setq cua-auto-tabify-rectangles nil)
(transient-mark-mode 1)
(setq cua-keep-region-after-copy t)
(setq x-select-enable-clipboard t)
(setq mouse-yank-at-point t)
;; 选择文字后输入文字,不再追加,而是直接替换
(delete-selection-mode)
(show-paren-mode)
;; 文件有更改时自动更新
(global-auto-revert-mode)
;; 按键绑定
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "C-<return>") 'newline)
;; F4键弹出eshell
(global-set-key [f4] 'eshell)
;; 按Shift+方向键即可切换窗口
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))))
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; 记住关闭前光标的位置
(require 'saveplace)
(setq-default save-place t)
(defmacro after-load (mode &rest body)
"`eval-after-load' MODE evaluate BODY."
(declare (indent defun))
`(eval-after-load ,mode
'(progn ,@body)))
;; 括号高亮
(after-load "rainbow-delimiters-autoloads"
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode-enable))
;; C-x u开启。p n f b q试试这几个键
(after-load "undo-tree-autoloads"
(global-undo-tree-mode))
;; 按F12键启动magit-status
(after-load "magit-autoloads"
(global-set-key [f12] 'magit-status))
;;开启自动补齐模式
(after-load "company-autoloads"
(global-company-mode)
(global-set-key "\t" 'company-complete-common))
;; 显示左侧导航,按F9键可以切换
(after-load "sr-speedbar-autoloads"
(global-set-key [f9] 'sr-speedbar-toggle)
(setq speedbar-show-unknown-files t)
(setq speedbar-verbosity-level 1)
(setq sr-speedbar-auto-refresh nil)
(setq sr-speedbar-right-side nil))
;; 扩展M-x功能
(after-load "smex-autoloads"
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; 原配的M-x
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command))
;; 添加主题。白天黑夜自动切换主题,19:00自动切换
(after-load "moe-theme-autoloads"
(require 'moe-theme-switcher))
;; clojure
(after-load "clojure-mode-autoloads"
(add-hook 'clojure-mode-hook 'subword-mode)
(add-hook 'clojure-mode-hook 'turn-on-eldoc-mode))
(after-load "clojure-mode-extra-font-locking-autoloads"
(setq cider-repl-use-clojure-font-lock t))
(after-load "clj-refactor-autoloads"
(add-hook 'clojure-mode-hook
(lambda ()
(clj-refactor-mode)
(cljr-add-keybindings-with-prefix "C-c RET"))))
(after-load "cider-autoloads"
(setq cider-repl-wrap-history t)
(setq nrepl-log-messages t)
(setq cider-repl-history-size 3000)
(setq cider-repl-history-file "~/.emacs.d/cider-history")
(add-hook 'cider-mode-hook #'eldoc-mode)
(add-hook 'cider-repl-mode-hook #'subword-mode)
(global-set-key (kbd "C-c C-z") 'cider-switch-to-repl-buffer))
(after-load "flycheck-autoloads"
(add-hook 'after-init-hook #'global-flycheck-mode))
(after-load "flycheck-clojure-autoloads"
(flycheck-clojure-setup))
(after-load "flycheck-pos-tip-autoloads"
(setq flycheck-display-errors-function #'flycheck-pos-tip-error-messages))
(after-load "yasnippet-autoloads"
(add-hook 'web-mode-hook #'(lambda () (yas-activate-extra-mode 'html-mode)))
(add-hook 'prog-mode-hook #'yas-minor-mode)
(add-hook 'clojure-mode-hook #'yas-minor-mode)
(add-hook 'cider-repl-mode-hook #'yas-minor-mode)
(add-hook 'emacs-lisp-mode-hook #'yas-minor-mode))
(after-load "projectile-autoloads"
(projectile-global-mode))
(after-load "smartparens-autoloads"
(add-hook 'lisp-mode-hook #'smartparens-strict-mode)
(add-hook 'lisp-interaction-mode-hook #'smartparens-strict-mode)
(add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'smartparens-strict-mode)
(add-hook 'ielm-mode-hook #'smartparens-strict-mode)
(add-hook 'scheme-mode-hook #'smartparens-strict-mode)
(add-hook 'clojure-mode-hook #'smartparens-strict-mode)
(add-hook 'cider-repl-mode-hook #'smartparens-strict-mode))
(after-load "web-mode-autoloads"
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(defun my-web-mode-hook ()
"Hooks for Web mode."
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq web-mode-enable-auto-pairing t)
(setq web-mode-enable-current-element-highlight t))
(add-hook 'web-mode-hook 'my-web-mode-hook))
(after-load "flx-ido-autoloads"
(ido-mode)
(ido-everywhere)
(flx-ido-mode)
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil))
(provide 'init)
;;; init.el ends here