如何在emacs中自动格式化(而不仅仅是自动缩进)c++代码

How to autoformat (not just auto-indent) C++ code in emacs?

本文关键字:不仅仅是 缩进 代码 c++ 格式化 emacs      更新时间:2023-10-16

如何在emacs中按照gnu风格自动格式化c++代码?

有这个自动换行的东西:https://www.gnu.org/software/emacs/manual/html_node/ccmode/Auto_002dnewlines.html,但即使我将style设置为GNU,它也不会将返回值与函数名分开放在单独的行上。

我还想在参数列表中的参数之间添加空格。我可以在我写完代码后"运行"一些东西(而不仅仅是在我输入的时候移动东西)

这里已经回答过了。有一个叫做astyle(艺术风格)的工具,可以用c++格式化代码。

(defun astyle-this-buffer (pmin pmax)
  (interactive "r")
  (shell-command-on-region pmin pmax
                           "astyle" ;; add options here...
                           (current-buffer) t 
                           (get-buffer-create "*Astyle Errors*") t))