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