我的 Emacs 基本配置

Posted by koocyton on 2023-07-27
Estimated Reading Time 9 Minutes
Words 1.6k In Total
Viewed Times

主配置,基础设定 ~/.emacs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

;; -*-coding:utf-8;-*-

(custom-set-variables
'(column-number-mode t)
'(gnus-init-file "~/Emacs/28/gnus.el")
'(package-selected-packages
'(projectile yasnippet-snippets which-key use-package-chords quickrun lsp-ui lsp-java helm-swoop helm-lsp helm-descbinds heaven-and-hell flycheck exec-path-from-shell doom-themes company))
'(safe-local-variable-values '((default-directory . "~/Emacs/tmp/")))
'(scroll-bar-mode 'right)
'(show-paren-mode t)
'(text-mode-hook '(text-mode-hook-identify)))
(custom-set-faces
'(erc-timestamp-face ((t (:foreground "black" :weight normal))))
'(eshell-prompt ((t (:foreground "Black" :weight bold)))))

;;_+ load lisp path
(add-to-list 'load-path "~/Emacs/28/lisp")

;;_+ load config
(mapc '(lambda (file)
(load (file-name-sans-extension file)))
(directory-files "~/Emacs/28/config/" t "\\.el$"))

我使用的模块配置,会按照第一个数字按顺序加载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$> ll ~/Emacs/28/config
total 120
-rw-r--r-- 1 staff staff 6507 Feb 1 2022 11.base.el
-rw-r--r-- 1 staff staff 155 Oct 31 2022 12.color-theme.el
-rw-r--r-- 1 staff staff 417 Oct 31 2022 13.font.el
-rw-r--r-- 1 staff staff 1560 Jun 24 2014 14.hotkeys.el
-rw-r--r-- 1 staff staff 4743 Oct 31 2022 15.develop.el
-rw-r--r-- 1 staff staff 361 Sep 25 2018 16.speedbar.el
-rw-r--r--@ 1 staff staff 154 Oct 13 2016 17.magit.el
-rw-r--r--@ 1 staff staff 133 Oct 31 2022 18.git-emacs.el
-rw-r--r-- 1 staff staff 2620 Oct 31 2022 19.php.el.re
-rw-r--r--@ 1 staff staff 7499 Nov 1 2022 30.java.el
-rw-r--r-- 1 staff staff 1110 Oct 31 2022 31.python.el.re
-rw-r--r-- 1 staff staff 883 Feb 1 2022 32.client.el

11.base.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
;; -*- coding:utf-8; mode:lisp-mode; -*-

;;_+ 用户资料设定
(setq user-full-name "YOUR NAME")
(setq user-mail-address "YOUR EMAIL")

;;_+ 当有问题出现显示错误信息,便于调试
;;(setq debug-on-error t)

;;_+ 可执行文件的路径
(setq exec-path '("/bin"
"/usr/bin"
"/usr/local/bin"))
(setenv "PATH" (mapconcat 'identity exec-path path-separator))

;;_+ 禁用启动信息
(setq inhibit-startup-message t)

;;_+ 关闭烦人的出错时的提示声
;; (setq visible-bell nil)
(setq visible-bell t)
(setq ring-bell-function 'ignore)

;;_+ 把title设置为“文件名@LC's Emacs"
(setq show-date (format-time-string "%Y年%m月%d日 %A"))
(setq frame-title-format
'("" show-date " [ "(buffer-file-name "%f"
(dired-directory dired-directory "%b"))" ] "))

;;_+ 光标靠近鼠标的时候,让鼠标自动让开,别挡住视线
;; (mouse-avoidance-mode 'animate)

;;_+ 下面的这个设置可以让光标指到某个括号的时候显示与它匹配的括号
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;;_+ 设置缺省模式是text,而不是基本模式
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

;;_+ 设置tab为4个空格的宽度,而不是原来的2
(setq default-tab-width 4)
(setq indent-tabs-mode t)

;;_+ don't hide DOS lineendings (^M):
(setq inhibit-eol-conversion nil)

;;_+ highlight query
(defconst query-replace-highlight t)

;;_+ 防止页面滚动时跳动
(setq scroll-step 0
scroll-margin 0
scroll-conservatively 10000)

;;_+
(setq ansi-color-for-comint-mode t)

;;_+ 所有的备份文件转移到~/backups目录下
(setq backup-directory-alist (quote (("." . "~/Emacs/backups"))))
(setq version-control t)
(setq kept-old-versions 2)
(setq kept-new-versions 5)
(setq delete-old-versions t)
(setq backup-directory-alist '(("." . "~/Emacs/backups")))
(setq backup-by-copying t)

;;_+ 不产生备份文件
(setq make-backup-files nil)

;;_+ News 目录
(setq gnus-directory "~/Emacs/News/")

;;_+ Mail 目录
(setq message-directory "~/Emacs/Mail/")

;;_+ 设置自动换行
(setq hscroll-margin 1)
(setq hscroll-step 1)

;;_+ 设置kill-ring-max(我不知道怎么翻译这个词:)为200,以防不测:)
;;默认是保存前面60个删除的内容
(setq kill-ring-max 200)

;;_+ 设置时间戳,标识出最后一次保存文件的时间。
(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S K.T")

;;_+ 默认的日记文件
(setq diary-file "~/Emacs/diary.txt")

;;_+ 设置默认工作目录
(setq default-directory "~/Desktop")

;;_+ 显示列号
(setq column-number-mode t)

;;_+ 设置默认的列数是123
(setq default-fill-column 123)

;;_+ 'y' for 'yes', 'n' for 'no'
(fset 'yes-or-no-p 'y-or-n-p)

;;_+ 让ediff不再单独出来一个窗口
(setq ediff-window-setup-function 'ediff-setup-windows-plain)

;;_+ 开启图片浏览
(require 'thumbs)
(auto-image-file-mode t)

;;_+ 不要 tool-bar 和 scroll-bar。
;;(scroll-bar-mode -1)
;;(if (or (string-match "26.1" emacs-version))
;; (tool-bar-mode -1))
(if (fboundp 'tool-bar-mode)
(tool-bar-mode -1))

;;_+ 不要 menu-bar。
(if (not (fboundp 'tool-bar-mode))
(menu-bar-mode -1))

;;_+ 开启语法高亮,打开Emacs容易挂。
;;(global-font-lock-mode 1)
;;(set-variable 'jit-lock-stealth-time 0)

;;_+ 打开压缩文件时自动解压缩。
(auto-compression-mode 1)

;;_+ 光标不要闪烁。
;; (blink-cursor-mode -1)

;;_+ DIRED CONFIG
(require 'dired)
(require 'dired-x)
;;_+ C-x C-j 跳转到当前文件所在目录的 dired 缓冲[x]
(global-set-key "\C-x\C-j" 'dired-jump)
(define-key dired-mode-map "b" 'dired-mark-extension)
(define-key dired-mode-map "c" 'dired-up-directory)
(define-key dired-mode-map "e" 'dired-mark-files-containing-regexp)
(define-key dired-mode-map "o" 'chunyu-dired-open-explorer)
(define-key dired-mode-map "r" 'dired-mark-files-regexp)
(define-key dired-mode-map "/" 'dired-mark-directories)
(define-key dired-mode-map "K" 'dired-kill-subdir)
(define-key dired-mode-map [(control ?/)] 'dired-undo)

(defun chunyu-dired-open-explorer ()
(interactive)
(let ((file-name (dired-get-file-for-visit)))
(if (file-exists-p file-name)
(w32-shell-execute "open" file-name nil 1))))

(setq dired-listing-switches "-avl" ;; ls 文件列表参数
dired-recursive-copies 'top ;; 复制目录时,递归复制所有字目录
dired-recursive-deletes 'top ;; 删除目录时,递归删除所有字目录
cvs-dired-use-hook 'always) ;; 浏览 CVS 时,自动打开 pcl-cvs 界面

;;_+ 关闭shell buffer
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(defun wcy-shell-mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'wcy-shell-mode-kill-buffer-on-exit)
)
(defun wcy-shell-mode-kill-buffer-on-exit (process state)
(message "%s" state)
(if (or
(string-match "exited abnormally with code.*" state)
(string-match "finished" state))
(kill-buffer (current-buffer))))

;; dos-unix unix-dos
(defun dos-unix () (interactive)
(goto-char (point-min))
(while (search-forward "\r" nil t) (replace-match "")))
(defun unix-dos () (interactive)
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "\r\n")))

;;_+ 显示制表符号
;;(require 'blank-mode)

;;_+ 保存上次的操作记录到SESSION
;;(add-to-list 'load-path "~/tmp")
(require 'session)
(add-hook 'after-init-hook 'session-initialize)
;;_+ 有时候无法推出就是因为这个东西
(add-to-list 'session-globals-exclude 'org-mark-ring)

;;_+ 加载 desktop
(load "desktop")
;;(desktop-load-default)
(desktop-read)

;;_+ ansi-color
(autoload 'ansi-color-apply-on-region "ansi-color")
(defun article-treat-ansi-sequences ()
"Translate ANSI SGR control sequences into overlays or extents."
(interactive)
(save-excursion
(when (article-goto-body)
(let ((inhibit-read-only t))
(ansi-color-apply-on-region (point) (point-max))))))
(add-hook 'gnus-part-display-hook 'article-treat-ansi-sequences)


如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !