emacs使用了purcell的配置,由于该配置的文档不是很多,所以只能通过阅读源码来学习。
purcell emacs配置的安装
git clone https://github.com/purcell/emacs.d ~/.emacs.d
首次启动会下载许多包,如果下载不成功可以考虑设置代理
必备基础知识
- 函数调用的方式是(func arg),例如设置行号可以通
(global-linum-mode t) - 变量赋值的方式是
(setq 'varial arg),例如(setq gc-cons-threshold (* 128 1024 1024))
此外(add-to-list LIST-VAR ELEMENT)也是设置变量值的方式,例如(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory)) - 面向切面编程:(add-hook hook function)是emacs lisp中面向切面编程的一个体现,例如
(add-hook 'after-init-hook (lambda () (setq gc-cons-threshold sanityinc/initial-gc-cons-threshold)))
其中after-init-hook是GNU Emacs Lisp提供的一个standard hook,表示在在加载了初始化脚本(.emacs, .emacs.d/init.el, site-start.el等)之后执行的操作,更多的standard hooks可以refer如下链接:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Hooks.html
可以把hook和面向切面编程中的joinpoint/pointcut/advice的概念相比较。
(after-load FILE &rest BODY)
看下面的例子
(after-load 'compile
(defadvice compilation-start (after sanityinc/save-compilation-buffer activate)
"Save the compilation buffer to find it later."
(setq sanityinc/last-compilation-buffer next-error-last-buffer))
(defadvice recompile (around sanityinc/find-prev-compilation (&optional edit-command) activate)
"Find the previous compilation buffer, if present, and recompile there."
(if (and (null edit-command)
(not (derived-mode-p 'compilation-mode))
sanityinc/last-compilation-buffer
(buffer-live-p (get-buffer sanityinc/last-compilation-buffer)))
(with-current-buffer sanityinc/last-compilation-buffer
ad-do-it)
ad-do-it)))
- 打印调试信息
- (message format-string &rest args)会在底部打印消息,同时在message buffer中显示。例如
(message "init completed in %.2fms" (sanityinc/time-substract-millis after-init-time before-init-time)) - (error string &rest args)显示错误信息
- (message format-string &rest args)会在底部打印消息,同时在message buffer中显示。例如
init.el
init.el是整个配置的初始化脚本,该脚本会通过require加载需要的.el,同时通过require-package使用elpa安装第三方的包。包管理是通过init-elpa.el来初始化的。通过require加载的.el都是预先放置在lisp目录下,而通过require-package安装的第三方包则会放置在elpa目录下。
这篇博客记录了使用purcell的emacs配置的学习过程,包括安装步骤和基础操作。作者强调了理解init.el和hook的重要性,介绍了面向切面编程在Emacs Lisp中的应用,并给出了错误处理和调试的方法。
282

被折叠的 条评论
为什么被折叠?



