我正在尝试使用emacs批量缩进源文件。我使用的是命令:
$ emacs -batch Source.h -l emacs-format-file.el -f emacs-format-function其中emacs-format-file.el包含:
(defun emacs-format-function ()
(c-set-style "gnu")
(setq c-basic-offset 4)
(c-set-offset 'access-label nil)
(c-set-offset 'substatement-open 0)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))
(save-buffer)
)Emacs根据我的喜好缩进文件,但有一个例外。"public“、"private”和"protected“关键字都缩进了一个额外的空格:
class Foo
{
-public:
+ public:我想将这些关键字与前面的左括号对齐。基于this question,我认为设置'access-label‘可以解决这个问题,但似乎没有任何效果。
我遗漏了什么?
发布于 2012-12-06 04:48:35
结果表明,emacs将头文件作为C而不是C++处理。修复方法是更改.el文件以手动切换到C++模式:
(defun c++-indent-region ()
(c++-mode)
(c-set-style "gnu")
(setq c-basic-offset 4)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))
(save-buffer)
)https://stackoverflow.com/questions/13715747
复制相似问题