gpt4 book ai didi

emacs:保存前 Hook 是局部变量吗?

转载 作者:行者123 更新时间:2023-12-04 01:18:59 24 4
gpt4 key购买 nike

我该如何解决这个问题?

我加了 delete-trailing-whitespacebefore-save-hook在我的 c-mode-common-hook ,但它看起来像 delete-trailing-whitespace正在为每个文件调用,而不仅仅是使用 c-mode 和衍生物的缓冲区。

我可以制作 before-save-hook缓冲本地?

最佳答案

添加到 write-contents-functions相反:

(add-hook 'c-mode-common-hook
(lambda()
(add-hook 'write-contents-functions
(lambda()
(save-excursion
(delete-trailing-whitespace)))
nil t)))

正如 Emacs Lisp 引用手册解释的那样:

This works just like write-file-functions, but it is intended for hooks that pertain to the buffer's contents, not to the particular visited file or its location. Such hooks are usually set up by major modes, as buffer-local bindings for this variable. This variable automatically becomes buffer-local whenever it is set; switching to a new major mode always resets this variable, but calling set-visited-file-name does not.



这在 Emacs 24.2.1 中对我来说正常工作(即,它从 C 文件中删除所有尾随空格,但保留所有其他文件类型中的尾随空格)。

关于emacs:保存前 Hook 是局部变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1931784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com