Emacs library that provides functions to easily reformat C code using astyle. This library leverages reformatter.el which makes working with formatters a breeze.
Typical installation using use-package looks like this:
(use-package astyle
:ensure t
:when (executable-find "astyle")
:hook (c-mode-common . astyle-on-save-mode))c-mode-common-hook is used to enable format on save functionality.
Formatting can be invoked by running either astyle-buffer or astyle-region.
If astyle configuration file is found (customize file name bu editing variable astyle-default-rc-name) it will be prefered.
If no configuration file is found either astyle-custom-args or astyle-default-args is used
There are two ways of enabling format on save functionality.
Either enable astyle-format-on-save in mode hook or place the following in your project .dir-locals.el:
((c-mode
(mode . astyle-format-on-save)))- Easily customizable with sane defaults.
- Uses
c-basic-offsetfor indent. - Will prefere
.astylercconfiguration file if present in parent dirs.