(defun er-indent-defun () "Indent the current defun." (interactive) (save-excursion (mark-defun) (indent-region (region-beginning) (region-end))))
This function should work in all properly written major programming modes.
Why would you want to use
er-indent-defun instead of
er-indent-region-or-buffer? Pretty simple - indenting huge buffers can
take quite a while and you might want to save a bit of time if you
know that a buffer’s indentation is correct pretty much everywhere
I’d suggest binding the command to
C-M-z (since it kind of resembles
the keybinding for function evaluation in major modes for dynamic
(global-set-key (kbd "C-M-z") #'er-indent-defun)
Special thanks to
Fuco 2 who
suggested that command in the previous post.
er-indent-defun is available in
crux (but with a