Format

Improved (maybe) indenting on save

code format align emacs

I realized that sometimes identing the whole buffer might not be the desired output. That because if the file is on different identation, your git commit might be hard to follow.

Because of that I studied a bit emacs lisp and came up with similar idea. On save, indent only the function that you are working on.

(defun le2m/indent-function ()
"indent only function"
;; (interactive)
(delete-trailing-whitespace)
(let ((begin (save-excursion (beginning-of-defun) (point)))
      (end (save-excursion (end-of-defun) (point))))
  (indent-region begin end nil)))

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Improved (maybe) indenting on save

Indent file on save, please

code format align

So, I discovered that I really like to format the code on save (I am not the best typer). So emacs to the rescue:

(defun le2m/indent-buffer ()
  "indent whole buffer"
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

(add-hook 'clojure-mode-hook
          (lambda ()
            (add-hook 'before-save-hook
                      #'le2m/indent-buffer
                      t t)))

I did this on clojure-mode but it can be done in any mode I guess.

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Indent file on save, please