purcell emacs.d学习笔记

这篇博客记录了使用purcell的emacs配置的学习过程,包括安装步骤和基础操作。作者强调了理解init.el和hook的重要性,介绍了面向切面编程在Emacs Lisp中的应用,并给出了错误处理和调试的方法。

emacs使用了purcell的配置,由于该配置的文档不是很多,所以只能通过阅读源码来学习。

purcell emacs配置的安装

git clone https://github.com/purcell/emacs.d ~/.emacs.d
首次启动会下载许多包,如果下载不成功可以考虑设置代理

必备基础知识

  1. 函数调用的方式是(func arg),例如设置行号可以通(global-linum-mode t)
  2. 变量赋值的方式是(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))
  3. 面向切面编程:(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)))
  1. 打印调试信息
    1. (message format-string &rest args)会在底部打印消息,同时在message buffer中显示。例如
      (message "init completed in %.2fms" (sanityinc/time-substract-millis after-init-time before-init-time))
    2. (error string &rest args)显示错误信息

init.el

init.el是整个配置的初始化脚本,该脚本会通过require加载需要的.el,同时通过require-package使用elpa安装第三方的包。包管理是通过init-elpa.el来初始化的。通过require加载的.el都是预先放置在lisp目录下,而通过require-package安装的第三方包则会放置在elpa目录下。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值