emacs align-regexp与空格而不是选项卡 [英] emacs align-regexp with spaces instead of tabs

查看:124
本文介绍了emacs align-regexp与空格而不是选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用emacs中的 Mx align-regexp 来缩小我的Perl代码,但是默认情况下它使用的是tab而不是空格,这是不应该按照Perl评论家。



有没有办法改变 align-regexp 的行为,以便它填入

解决方案

一般来说,您应该避免使用建议,但由于 align .el 直接读取 indent-tabs-mode 的值,这可能是最好的方法:


$ b $
(let((indent-tabs-mode nil))
ad -do-it))






这是我原来的版本:

 (defadvice align-regexp(around -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出来,这是不必要的复杂和不太愚蠢的证明,所以使用帖子顶部的代码。


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?

解决方案

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.

这篇关于emacs align-regexp与空格而不是选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆