I'd like to transform:

function arg(a,b,c){}


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?


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)
| improve this answer | |

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))


On OSX I installed astyle with brew install astyle

| improve this answer | |

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.