Skip to content

Instantly share code, notes, and snippets.

@longjie
Created February 16, 2017 12:39
Show Gist options
  • Save longjie/c4ea4c04a7426eff68cf083ea936446d to your computer and use it in GitHub Desktop.
Save longjie/c4ea4c04a7426eff68cf083ea936446d to your computer and use it in GitHub Desktop.
Emacs setting to run GNU indent automatically after save C/C++ files
;; Function to format C/C++ code with GNU indent
(defun c-auto-format ()
"Function to format C/C++ code with GNU indent"
(interactive)
(when (find major-mode '(c-mode c++-mode))
(shell-command
(format "indent %s" (shell-quote-argument (buffer-file-name))))
(revert-buffer t t t)))
;; Add after-save-hook
(add-hook 'after-save-hook 'c-auto-format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment