Getting Emacs to untabify when saving certain file types (and only those file types)

后端 未结 3 1241
忘了有多久
忘了有多久 2020-12-15 09:02

I have the following in my .emacs file:

 (defun c++-mode-untabify ()
   (save-excursion
     (goto-char (point-min))
     (while (re-search-forward \"[ \\t]+         


        
3条回答
  •  一整个雨季
    2020-12-15 10:00

    The documentation in my Emacs says that make-local-hook is now obsolete as of 21.1, since add-hook now takes an optional argument for making a hook buffer-local. So you could try:

    (add-hook 'c++-mode-hook
               '(lambda ()
                  (add-hook 'write-contents-hooks 'c++-mode-untabify nil t)))
    

    Another option is to have the c++-mode-untabify function check the current mode. I'd probably just write that as something like:

    (defun c++-mode-untabify ()
      (if (string= (substring mode-name 0 3) "C++")
          (save-excursion
           (delete-trailing-whitespace)
           (untabify (point-min) (point-max)))))
    

提交回复
热议问题