我在我的 .emacs 文件中有以下内容:
(defun c++-mode-untabify ()
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[ \t]+$" nil t)
(delete-region (match-beginning 0) (match-end 0)))
(goto-char (point-min))
(if (search-forward "\t" nil t)
(untabify (1- (point)) (point-max))))
nil)
(add-hook 'c++-mode-hook
'(lambda ()
(make-local-hook 'write-contents-hooks)
(add-hook 'write-contents-hooks 'c++-mode-untabify)))
大部分内容来自于http://www.jwz.org/doc/tabs-vs-spaces.html。这会导致在保存C++文件之前,emacs会对缓冲区运行untabify
。
问题是,在我加载了一个C++文件之后,untabify
钩子将被应用于所有后续的文件写入,即使是其他文件类型的缓冲区。这意味着如果我打开一个C++文件,然后编辑一个制表符分隔的文本文件,当保存该文件时,制表符会被覆盖。
我不是elisp大师,但我认为(make-local-hook 'write-contents-hooks)
行试图使对write-contents-hooks
的添加仅适用于本地缓冲区。然而,它并没有起作用,并且在所有缓冲区的write-contents-hooks
中。
我正在Windows XP机器上使用EmacsW32 22.0。有人知道如何使write-contents-hooks
更改为特定缓冲区的本地或如何在切换到其他非C++缓冲区时将其重置为nil
吗?