2

I'd like to transform:

function arg(a,b,c){}

to

function arg( a, b, c ){}

Is there a way to do this or set it as part of c style auto indentation? So it will happen when editing JavaScript, C++, etc?

1

Another option for this is clang-format. There's even a Melpa plugin for using it: clang-format.

Personally, I bind C-c f to clang-format-region to fix the coding style for the currently selected region:

(global-set-key (kbd "C-c f") 'clang-format-region)
0

If Artistic Style (astyle) is installed outside emacs:

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

Reference
https://stackoverflow.com/questions/801983/how-do-i-use-astyle-within-emacs

On OSX I installed astyle with brew install astyle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.