29.1 已经在 2023-07-30[1] 发布了💥
作为日常使用 Emacs 进行开发的重度用户,困扰笔者的一个问题时,同时打开多个项目时, xref 会错乱,这十分烦人,忍受一段时间后,最终去 SO 提问[2]了一下,Emacs 又一次没令我失望,29 里面已经有了解法:
(setq xref-history-storage 'xref-window-local-history)
于是花了一点点时间,从 28 升级到了 29,只能说太香了,还在 28 踌躇的读者可以着手升级了。这里列举一些笔者认为 29 中一些比较实用的更新,完整列表可以去看 NEWS.29[3]。
tree-sitter 选项时启用。sqlite 库。 sqlite-mode-open-file 可以直接以 sqlite-mode 打开 sqlite 数据库文件,并且可以直接浏览、修改表数据!笔者计划后续会单独写一篇文章来介绍。emoji-recent 使用到了,用户也可以通过 define-multisession-variable 来添加新变量。另外值得一提的是,该包除了使用文件作为存储介质外,还支持 sqlite,可通过 multisession-storage 配置。variable-pitch 字体来格式化数据rename-visited-file: Emacs 终于支持同时重命名 buffer 和文件名了。👍
delete-process: 变成了交互式命令
restart-emacs: 与 save-buffers-kill-emacs 类似,只是在关闭 emacs 后,会重新用同样的启动参数再次启动
scratch-buffer: 交互式命令,切换到 *scratch* buffer,可以解决误删的问题
project-list-buffers: 用于展示当前项目的 buffer
xref-find-references-and-replace: 重命名变量
xref-go-forward: 与 xref-go-back 对应,默认快捷键 C-M-,
duplicate-line 和 duplicate-dwim: 复制当前行,当有 active region 时 dwim 会复制当前 region,否则就是当前行
ensure-empty-lines : 确保当前行上面是空行
find-sibling-file: 寻找“兄弟”文件,兄弟文件是由 find-sibling-rules 这个变量定义的。比如可以定义如下规则来打开 .c 对应的 .h 文件:
("\\\\([^/]+\\\\)\\\\.c\\\\\\='" "\\\\1.h")
emoji-insert, emoji-list, emoji-search, emoji-recent: 方便快捷的在 Emacs 中输入 emoji 💯 😎
package-update, package-update-all: 更新包,无需再使用 list-packages
package-vc-install: 从制定仓库安装包
split-root-window-below split-root-window-right: 把 root 窗口分成 2 个,窗口相关的命令可以在 C-x w 内找到
elisp-eval-region-or-buffer: 如果有 region,执行 region 内的 elisp 代码,否则就是整个 buffer
recentf-open: 打开最新的文件
eww-url-transformers: 用于在访问 URL 前进行改写,默认它会移除 utm_ 这个用于追踪的参数。 之前写的 [URL 重定向](file:///post/018/ "URL 重定向")就可以利用它来实现。eww-auto-rename-buffer: 自动给 eww buffer 命名,默认为 nil,可以设置为 'title 或 'urlbrowse-url-default-scheme: 当使用 browse-url 等函数时,默认的 URl scheme,默认是 httpxref-history-storage : 如何保存 xref 的历史 marker,一个有用的选项是 xref-window-local-history ,这样在用 Emacs 同时打开多个项目时, xref 就不会错乱了。show-paren-context-when-offscreen: 当光标在右括号时,如果左括号不在屏幕时,会在 echo area 中展示相关信息,在 GUI 中,可以设置成 overlay 或 child-framepackage-install-upgrade-built-in: 是否允许升级内置包,比如 eglot。默认 niltramp-use-scp-direct-remote-copying: 当设置为 true 时,使用 scp 来复制文件python-shell-dedicated: 是否为每个项目、buffer 开启特定的 Python shell,默认为 nilM-SPC 现在绑定 cycle-spacing ,之前是 just-one-space 。循环的操作可以通过 cycle-spacing-actions 配置。so-long-mode 了, long-line-threshold 控制长行的阈值,超过即进行优化展示。kill-buffer 如果没有保存会给出 save then kill 的提示tramp 支持了 docker podman kuberneteslinum.el 正式作废,推荐使用 display-line-numbers-mode 来替代。defmethod defgeneric 函数,如果之前配置中有用到,可以直接加上前缀 cl- 即可,比如下面这个 PR:Fix defmethod by sarg · Pull Request #3 · ukaszg/aria2[6]除此之外,在升级过程中还有可能遇到下面的 warning,根据提示来修复即可。
twittering-mode.el: Warning: ‘block’ is an obsolete alias (as of 27.1); use ‘cl-block’ instead.
twittering-mode.el: Warning: ‘return-from’ is an obsolete alias (as of 27.1); use ‘cl-return-from’ instead.
twittering-mode.el: Warning: ‘decf’ is an obsolete alias (as of 27.1); use ‘cl-decf’ instead.
twittering-mode.el: Warning: ‘incf’ is an obsolete alias (as of 27.1); use ‘cl-incf’ instead.
-r: 复用现有的 GUI frame,如果没有的话,则新创建一个-w: 超时时间,如果 Emacs 没有在规定时间内响应,那么 client 就会自动退出。--batch --script 现在会调整 GC 参数, gc-cons-percentage 会设置成 1(默认是 0.1)。#!/usr/bin/emacs -x 会跳过 init.el 文件,直接执行文件后面的内容,最后一个表达式为脚本的退出码。--init-directory 设置 user-emacs-directory 变量.eld 结尾的文件默认用 lisp-data-mode 打开。[1]
2023-07-30: https://lists.gnu.org/archive/html/emacs-devel/2023-07/msg00879.html
[2]
SO 提问: https://stackoverflow.com/questions/75791497/
[3]
NEWS.29: https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS.29
[4]
joshwnj/json-mode: https://github.com/joshwnj/json-mode
[5]
Improvements to long lines handling.: https://github.com/emacs-mirror/emacs/commit/e7b5912b235936b304701ba6b1e808d9b197fd4f
[6]
Fix defmethod by sarg · Pull Request #3 · ukaszg/aria2: https://github.com/ukaszg/aria2/pull/3
[7]
What's New in Emacs 29.1?: https://www.masteringemacs.org/article/whats-new-in-emacs-29-1
[8]
Marcin Borkowski: 2022-12-19 A few new things in Emacs 29: https://mbork.pl/2022-12-19_A_few_new_things_in_Emacs_29