使用Emacs将内置样式应用于文件

使用Emacs将内置样式应用于文件,emacs,code-formatting,Emacs,Code Formatting,我有一个c文件是这样写的: int main(void){ } 我想根据“linux”格式更改文件中的每个括号 如何使用Emacs实现这一点 编辑1: 这是我的.emacs文件: (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should

我有一个c文件是这样写的:

int main(void){

}
我想根据“linux”格式更改文件中的每个括号

如何使用Emacs实现这一点

编辑1:

这是我的.emacs文件:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(custom-enabled-themes (quote (tango-dark)))
 '(inhibit-startup-screen t)
 '(package-archives
   (quote
    (("melpa" . "https://melpa.org/packages/")
     ("gnu" . "http://elpa.gnu.org/packages/")))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(setq make-backup-files nil) ; stop creating backup~ files
(setq auto-save-default nil) ; stop creating #autosave# files
(setq c-default-style "linux"
      c-basic-offset 4)
编辑2:


通过创建一个调用GNU缩进的emacs宏来解决这个问题。

如何实现这一点的主要来源是。要在emacs中使用
linux
样式:

(setq c-default-style“linux”)
如果为emacs定义了xdg路径,请将上述行放在~/.emacs或~/.config/emacs/config中


CtrlM\将重新缩进任意区域,因此在将c-default-style设置为linux后,只需选择缓冲区的内容并重新缩进即可。更多信息请参见

,但这将仅在我使用Ctrl-M-\n写入新文件时应用,它仅更正缩进,而不更正括号位置可能的重复
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(custom-enabled-themes (quote (tango-dark)))
 '(inhibit-startup-screen t)
 '(package-archives
   (quote
    (("melpa" . "https://melpa.org/packages/")
     ("gnu" . "http://elpa.gnu.org/packages/")))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(setq make-backup-files nil) ; stop creating backup~ files
(setq auto-save-default nil) ; stop creating #autosave# files
(setq c-default-style "linux"
      c-basic-offset 4)