emacs align-regexp with spaces instead of tabs

大憨熊 提交于 2019-12-07 03:41:42

问题


I use M-x align-regexp in emacs to prettify my Perl code, but by default it is using tabs instead of spaces, which is something one should not do according to Perl critic.

Is there a way to change the behaviour of align-regexp so that it fills in with the right amount of spaces instead of tabs?


回答1:


In general you should avoid using advice, but since align.el directly reads the value of indent-tabs-mode, it's probably the best way:

(defadvice align-regexp (around align-regexp-with-spaces activate)
  (let ((indent-tabs-mode nil))
    ad-do-it))

Here was my original version:

(defadvice align-regexp (around align-regexp-with-spaces activate)
  (let ((old-indent-tabs-mode indent-tabs-mode))
    (setq indent-tabs-mode nil)
    ad-do-it
    (setq indent-tabs-mode old-indent-tabs-mode)))

As @Phils pointed out, this is unnecessarily complex and less fool proof, so use the code at the top of the post.



来源:https://stackoverflow.com/questions/22710040/emacs-align-regexp-with-spaces-instead-of-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!