-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emacs
467 lines (362 loc) · 13.3 KB
/
.emacs
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
;; -*- Emacs-Lisp -*-
;; Time-stamp: <2010-11-03 17:45:59 Wednesday by taoshanwen>
(defconst my-emacs-path "~/emacs/" "我的emacs相关配置文件的路径")
(defconst my-emacs-my-lisps-path (concat my-emacs-path "my-lisps/") "我自己写的emacs lisp包的路径")
(defconst my-emacs-lisps-path (concat my-emacs-path "lisps/") "我下载的emacs lisp包的路径")
(defconst my-emacs-templates-path (concat my-emacs-path "templates/") "Path for templates")
;; 把`my-emacs-lisps-path'的所有子目录都加到`load-path'里面
(load (concat my-emacs-my-lisps-path "my-subdirs"))
(my-add-subdirs-to-load-path my-emacs-lisps-path)
(my-add-subdirs-to-load-path my-emacs-my-lisps-path)
;; 一些基本的小函数
(require 'ahei-misc)
;; 利用`eval-after-load'加快启动速度的库
;; 用eval-after-load避免不必要的elisp包的加载
;; http://emacser.com/eval-after-load.htm
(require 'eval-after-load)
(require 'util)
;; 一些Emacs的小设置
(require 'misc-settings)
;; 编码设置
(require 'coding-settings)
;; CUA的矩阵区域操作特别方便
(require 'cua-settings)
;; 矩形区域操作
(require 'rect-mark-settings)
;; 鼠标配置
(require 'mouse-settings)
;; 关于mark的一些设置,使你非常方便的选择region
(require 'mark-settings)
;; `mode-line'显示格式
(require 'mode-line-settings)
;; ffap,打开当前point的文件
(require 'ffap-settings)
;; 各种语言开发方面的设置
(require 'dev-settings)
;; 不要menu-bar和tool-bar
;; (unless window-system
;; (menu-bar-mode -1))
(menu-bar-mode -1)
;; GUI下显示toolbar的话select-buffer会出问题
(if (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
;; 打开压缩文件时自动解压缩
;; 必须放在session前面
(auto-compression-mode 1)
;; 所有关于buffer方面的配置
(require 'all-buffer-settings)
;; frame-cmds.el必须放在multi-term前面,否则ediff退出时会出现错误
;; 而icicles soft-requires frame-cmds.el, 所以icicles也必须放在multi-term前面
;; emacs22下也必须放在kde-emacs前面, 否则会说shell-command是void-function
;; http://emacser.com/icicles-doremi-palette.htm
(require 'icicles-settings)
(require 'doremi-settings)
(require 'palette-settings)
;; edit-settings中对M-w重新定义,但是kde-emacs中也对其定义了
;; 所以必须要放在kde-emacs后面
(require 'edit-settings)
;; 用M-x执行某个命令的时候,在输入的同时给出可选的命令名提示
(require 'icomplete-settings)
;; minibuffer中输入部分命令就可以使用补全
(unless is-after-emacs-23
(partial-completion-mode 1))
;; 图片mode
(require 'image-mode-settings)
;; 用一个很大的kill ring. 这样防止我不小心删掉重要的东西
(setq kill-ring-max 200)
;; 方便的在kill-ring里寻找需要的东西
(require 'browse-kill-ring-settings)
;; 显示行号
(require 'linum-settings)
;; color theme Emacs主题
(require 'color-theme-settings)
(require 'ahei-face)
(require 'color-theme-ahei)
(require 'face-settings)
;; 高亮当前行
(require 'hl-line-settings)
;; 字体配置
(require 'font-settings)
;; diff
(require 'diff-settings)
;; Emacs的diff: ediff
(require 'ediff-settings)
;; 最近打开的文件
(require 'recentf-settings)
;; 在buffer中方便的查找字符串: color-moccur
(require 'moccur-settings)
;; Emacs超强的增量搜索Isearch配置
(require 'isearch-settings)
;; 非常酷的一个扩展。可以“所见即所得”的编辑一个文本模式的表格
(if is-before-emacs-21 (require 'table "table-for-21"))
;; 把文件或buffer彩色输出成html
(require 'htmlize)
;; time-stamp, 在文件头记录修改时间, 并动态更新
(require 'time-stamp-settings)
;; Emacs可以做为一个server, 然后用emacsclient连接这个server,
;; 无需再打开两个Emacs
(require 'emacs-server-settings)
(require 'apropos-settings)
(require 'completion-list-mode-settings)
;; 显示ascii表
(require 'ascii)
;; 所有关于查看帮助方面的配置
(require 'all-help-settings)
;; 定义一些emacs 21没有的函数
(if is-before-emacs-21 (require 'for-emacs-21))
;; 简写模式
(setq-default abbrev-mode t)
(setq save-abbrevs nil)
;; 可以为重名的buffer在前面加上其父目录的名字来让buffer的名字区分开来,而不是单纯的加一个没有太多意义的序号
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; 以目录形式显示linkd文档
(require 'linkd-settings)
;; Emacs的超强文件管理器
(require 'dired-settings)
;; 方便的切换major mode
(defvar switch-major-mode-last-mode nil)
(defun major-mode-heuristic (symbol)
(and (fboundp symbol)
(string-match ".*-mode$" (symbol-name symbol))))
(defun switch-major-mode (mode)
"切换major mode"
(interactive
(let ((fn switch-major-mode-last-mode) val)
(setq val
(completing-read
(if fn (format "切换major-mode为(缺省为%s): " fn) "切换major mode为: ")
obarray 'major-mode-heuristic t nil nil (symbol-name fn)))
(list (intern val))))
(let ((last-mode major-mode))
(funcall mode)
(setq switch-major-mode-last-mode last-mode)))
(global-set-key (kbd "C-x q") 'switch-major-mode)
(defun get-mode-name ()
"显示`major-mode'及`mode-name'"
(interactive)
(message "major-mode为%s, mode-name为%s" major-mode mode-name))
(global-set-key (kbd "C-x m") 'get-mode-name)
;; 查看Emacs内进程
(autoload 'list-processes+ "list-processes+" "增强的`list-processes'命令" t)
(require 'view-mode-settings)
(defun revert-buffer-no-confirm ()
"执行`revert-buffer'时不需要确认"
(interactive)
(when (buffer-file-name)
(let ((emaci emaci-mode))
(revert-buffer buffer-file-name t)
(emaci-mode (if emaci 1 -1)))))
(eal-define-keys-commonly
global-map
`(("C-x u" revert-buffer-no-confirm)
("C-x M-K" revert-buffer-with-gbk)
("C-x U" revert-buffer-with-coding-system-no-confirm-sb)))
(defun count-brf-lines (&optional is-fun)
"显示当前buffer或region或函数的行数和字符数"
(interactive "P")
(let (min max)
(if is-fun
(save-excursion
(beginning-of-defun) (setq min (point))
(end-of-defun) (setq max (point))
(message "当前函数%s内共有%d行, %d个字符" (which-function) (count-lines min max) (- max min)))
(if mark-active
(progn
(setq min (min (point) (mark)))
(setq max (max (point) (mark))))
(setq min (point-min))
(setq max (point-max)))
(if (or (= 1 (point-min)) mark-active)
(if mark-active
(message "当前region内共有%d行, %d个字符" (count-lines min max) (- max min))
(message "当前buffer内共有%d行, %d个字符" (count-lines min max) (- max min)))
(let ((nmin min) (nmax max))
(save-excursion
(save-restriction
(widen)
(setq min (point-min))
(setq max (point-max))))
(message "narrow下buffer内共有%d行, %d个字符, 非narrow下buffer内共有%d行, %d个字符"
(count-lines nmin nmax) (- nmax nmin) (count-lines min max) (- max min)))))))
(eal-define-keys-commonly
global-map
`(("C-x l" count-brf-lines)
("C-x L" (lambda () (interactive) (count-brf-lines t)))))
;; 增加更丰富的高亮
(require 'generic-x)
(defun switch-to-scratch ()
"切换到*scratch*"
(interactive)
(let ((buffer (get-buffer-create "*scratch*")))
(switch-to-buffer buffer)
(unless (equal major-mode 'lisp-interaction-mode)
(lisp-interaction-mode))))
(global-set-key (kbd "C-x s") 'switch-to-scratch)
(defun visit-.emacs ()
"访问.emacs文件"
(interactive)
(find-file (concat my-emacs-path ".emacs")))
(global-set-key (kbd "C-x E") 'visit-.emacs)
;; grep
(require 'grep-settings)
;; ack-grep, grep纯perl的代替品
(require 'full-ack-settings)
(eal-define-keys-commonly
global-map
`(("M-r" query-replace-sb)
("M-%" query-replace-sb)
("ESC M-%" query-replace-regexp-sb)
("ESC M-r" query-replace-regexp-sb)
("C-x M-r" query-replace-regexp-sb)
("M-z" zap-to-char-sb)
("C-j" goto-line)
("C-x C-s" save-buffer-sb)))
(am-add-hooks
`(find-file-hook)
(lambda ()
(local-set-key (kbd "C-M-j") 'goto-line)))
;; 返回到最近去过的地方
(require 'recent-jump-settings)
;; 统计命令使用频率
(require 'command-frequence)
;; Emacs中的文本浏览器w3m
;; http://emacser.com/w3m.htm
(require 'w3m-settings)
;; 以另一用户编辑文件, 或者编辑远程主机文件
(require 'tramp-settings)
;; erc: Emacs中的IRC
;; ERC使用简介 emacser.com/erc.htm
(require 'erc-settings)
;; spell check
(setq-default ispell-program-name "aspell")
(define-key global-map (kbd "C-q") 'quoted-insert-sb)
;; Emacs中的包管理器
(require 'package)
(package-initialize)
(require 'auto-install)
(setq auto-install-directory (concat my-emacs-lisps-path "auto-install"))
(unless mswin
(defun install-.emacs ()
(interactive)
(shell-command (concat my-emacs-path "install.emacs.sh")))
(add-hook 'kill-emacs-hook 'install-.emacs))
;; 把pdf,ps,dvi文件转换为png格式, 在Emacs里面浏览
(if is-after-emacs-23
(require 'doc-view)
(setq doc-view-conversion-refresh-interval 3))
;; 在Emacs里面使用shell
(require 'term-settings)
(require 'multi-term-settings)
;; (require 'anything-settings)
(require 'ioccur)
;; 查询天气预报
(require 'weather-settings)
;; 可以把光标由方块变成一个小长条
(require 'bar-cursor)
(defun goto-my-emacs-lisps-dir ()
"Goto `my-emacs-lisps-path'."
(interactive)
(dired my-emacs-lisps-path))
(defun goto-my-emacs-my-lisps-dir ()
"Goto `my-emacs-my-lisps-path'."
(interactive)
(dired my-emacs-my-lisps-path))
(defun goto-my-emacs-dir ()
"Goto `my-emacs-path'."
(interactive)
(dired my-emacs-path))
(defun goto-my-home-dir ()
"Goto my home directory."
(interactive)
(dired "~"))
(define-key-list
global-map
`(("C-x G l" goto-my-emacs-lisps-dir)
("C-x G m" goto-my-emacs-my-lisps-dir)
("C-x G e" goto-my-emacs-dir)
("C-x M-H" goto-my-home-dir)))
(define-key global-map (kbd "C-x M-c") 'describe-char)
;; 启动Emacs的时候最大化Emacs
(require 'maxframe-settings)
(defun dos2unix ()
"dos2unix on current buffer."
(interactive)
(set-buffer-file-coding-system 'unix))
(defun unix2dos ()
"unix2dos on current buffer."
(interactive)
(set-buffer-file-coding-system 'dos))
(define-key global-map (kbd "C-x M-D") 'dos2unix)
(define-key-list
global-map
`(("C-x M-k" Info-goto-emacs-key-command-node)
("C-x ESC ESC" repeat-complex-command-sb)))
;; Emacs才是世界上最强大的IDE - 智能的改变光标形状
;; http://emacser.com/cursor-change.htm
(require 'cursor-change)
(cursor-change-mode 1)
(defun copy-file-name (&optional full)
"Copy file name of current-buffer.
If FULL is t, copy full file name."
(interactive "P")
(let ((file (buffer-name)))
(if full
(setq file (expand-file-name file)))
(kill-new file)
(message "File `%s' copied." file)))
(eal-define-keys
`(emacs-lisp-mode-map lisp-interaction-mode-map java-mode-map sh-mode-map
c-mode-base-map text-mode-map ruby-mode-map html-mode-map
java-mode-map conf-javaprop-mode-map conf-space-mode-map
python-mode-map)
`(("C-c M-C" copy-file-name)))
;; notification tool
(require 'todochiku-settings)
;; twitter client
(require 'eagle-settings)
(require 'twit-settings)
;; 模拟vi的点(.)命令
(require 'dot-mode)
;; 用渐变颜色显示你最近的修改
;; http://emacser.com/highlight-tail.htm
;; 与semantic冲突,启动了它后,打开大文件的时候,会发现buffer大范围的刷屏
;; (require 'highlight-tail-settings)
;; Emacs才是世界上最强大的IDE - 用Emaci阅读文件
;; http://emacser.com/emaci.htm
(require 'emaci-settings)
;;;###autoload
(defun update-current-file-autoloads (file &optional save-after)
"`update-file-autoloads' for current file."
(interactive "fUpdate autoloads for file: \np")
(let* ((load-file (expand-file-name "loaddefs.el"))
(generated-autoload-file load-file))
(unless (file-exists-p load-file)
(shell-command (concat "touch " load-file)))
(update-file-autoloads file save-after)))
;; 大纲mode
(require 'outline-settings)
;; org是一个非常强大的GTD工具
(require 'org-settings)
;; 强大的发布工具
(require 'muse-settings)
;; 用weblogger写WordPress博客
;; http://emacser.com/weblogger.htm
(require 'weblogger-settings)
;; 非常强大的文本画图的工具
(require 'artist-settings)
;; google-maps-el – Emacs中的谷歌地图
;; http://emacser.com/emacs-google-map.htm
(require 'google-maps-settings)
;; 关闭buffer的时候, 如果该buffer有对应的进程存在, 不提示, 烦
(delq 'process-kill-buffer-query-function kill-buffer-query-functions)
;; session,可以保存很多东西,例如输入历史(像搜索、打开文件等的输入)、
;; register的内容、buffer的local variables以及kill-ring和最近修改的文件列表等。非常有用。
(require 'session-settings)
;; 王纯业的desktop, 比desktop快多了
(require 'wcy-desktop-settings)
;; HACK: 要放在最后,免得会出现比较奇怪的现象
;; 保存和恢复工作环境
;; desktop,用来保存Emacs的桌面环境 — buffers、以及buffer的文件名、major modes和位置等等
;; (require 'desktop-settings)
(sb-update)