为emacs转换此untabify on-save挂钩以使用espresso模式(或所有模式)

时间:2010-07-22 20:36:04

标签: elisp

我发现这个片段会添加到我的.emacs中,在保存时会删除标签并用空格替换它们(以帮助我的文件与使用空格的团队中的其他人很好地合作。)

不幸的是,我的lisp和emacs lisp印章并不是很强大。似乎这个片段只适用于java主模式 - 我如何才能使用espresso模式?

(defun java-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 'java-mode-hook 
            (lambda ()
               (add-hook 'write-contents-hooks 'java-mode-untabify nil 'local)))

2 个答案:

答案 0 :(得分:4)

我的.emacs中有以下代码可供我使用:

;; untabify some modes
(setq alexott/untabify-modes '(haskell-mode emacs-lisp-mode lisp-mode scheme-mode
                                        erlang-mode clojure-mode))
(defun alexott/untabify-hook ()
  (when (member major-mode alexott/untabify-modes)
     (untabify (point-min) (point-max))))
(add-hook 'before-save-hook 'alexott/untabify-hook)

您可以通过以下方式更改alexott / untabify-modes变量中的列表,将espresso模式添加到模式列表中,其中将执行untabify:

(setq alexott/untabify-modes '(haskell-mode emacs-lisp-mode lisp-mode scheme-mode
                                        erlang-mode clojure-mode espresso-mode))

答案 1 :(得分:1)