emacs - 如何使用文件局部变量设置 Emacs 缓冲区名称?

标签 emacs

我希望我的 emacs 缓冲区的名称与文件名不同。我不想每次都手动设置,而是希望根据文件内容自动发生这种情况,例如:

//局部变量:
//缓冲区名称:MyName
//结尾:

但这不起作用,因为 buffer-name 是一个函数,而不是一个变量。我怎样才能做到这一点?

最佳答案

你可以说:

// Local Variables:
// eval: (rename-buffer "my-buffer-name-here")
// end:

虽然这是一个技巧。

否则,您可以对 find-file-hook 进行编程。挂上你的.emacs它将缓冲区重命名为特定的局部变量内容。就像是:
(defvar pdp-buffer-name nil)

(defun pdp-rename-buffer-if-necessary ()
  "Rename the current buffer according to the value of variable"
  (interactive)
  (if (and pdp-buffer-name (stringp pdp-buffer-name))
      (rename-buffer pdp-buffer-name)))

(add-hook 'find-file-hook 'pdp-rename-buffer-if-necessary)

然后在您的特定文件中
// Local Variables:
// pdp-buffer-name: "pierre" 
// end:

有了更多的脑力,你可以有一个更好的解决方案。

请注意,可能已经存在满足您需要的扩展。查看 Emacs wiki .

关于emacs - 如何使用文件局部变量设置 Emacs 缓冲区名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/353246/

相关文章:

emacs - 如何升级leiningen的nrepl版本?

emacs - 如何防止 emacs 在第一行添加编码信息?

当按下 'return' 键时,Emacs 返回到缩进的代码行

emacs - 为 Windows/C++ 程序员学习 Common Lisp 技巧

macos - 如何在 Mac 上安装 clangd?

emacs ( 重新编译 -y )

emacs - 在 Emacs 中为 Clojure 设置 SLIME 和 Inferior-Lisp

python - 尝试让终端在 Emacs 中工作

haskell - 使用 Emacs 编辑源文件时在 ghci 中评估 haskell 的函数

emacs - 在 sml 中,为什么会产生错误 : syntax error: deleting IN IF