如何在 GNU Emacs 中打开文件后自动执行命令

How to auto execute commands after opening a file in GNU Emacs

如何做这样的事情:打开文件后自动执行命令(split-window-right) (follow-mode) (visual-line-mode)

一种方法是编写您自己的 "open file" 命令:

(defun my-find-file ()
  "Like `find-file', but splits screen and enables Follow Mode."
  (interactive)
  (call-interactively #'find-file)
  (follow-delete-other-windows-and-split)
  (visual-line-mode 1))

可以绑定到C-x C-f:

(global-set-key (kbd "C-x C-f") #'my-find-file)

我使用了 follow-delete-other-windows-and-split 而不是 split-window-rightfollow-mode,后者在一个框架已经包含多个 windows 时效果不佳。

此外,您可以考虑使用其他机制启用 visual-line-mode,例如模式特定的挂钩或 global-visual-line-mode