小编Dan*_*McP的帖子

保存某些文件类型(并且只保存那些文件类型)时让Emacs解除保护

我的.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)))
Run Code Online (Sandbox Code Playgroud)

大部分都是从http://www.jwz.org/doc/tabs-vs-spaces.html中删除的.这会导致emacs untabify在保存C++文件之前在缓冲区上运行.

问题是,在我加载了C++文件之后,untabify钩子正被应用于所有后续文件写入,即使对于其他文件类型的缓冲区也是如此.这意味着如果我打开一个C++文件然后编辑一个制表符分隔的文本文件,那么在保存文件时这些选项卡会被破坏.

我不是一个elisp大师,但我认为该(make-local-hook 'write-contents-hooks)行试图使添加write-contents-hooks仅适用于本地缓冲区.但是,它不起作用,并且c++-mode-untabify适用于write-contents-hooks所有缓冲区.

我在Windows XP机器上使用EmacsW32 22.0.有没有人知道如何在write-contents-hooks特定缓冲区本地进行更改或如何nil在切换到其他非C++缓冲区时将其重置为?

emacs tabs

12
推荐指数
2
解决办法
5239
查看次数

标签 统计

emacs ×1

tabs ×1