Lucas E M M. opinions

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

Wait, do you want to choose a alias with cider?

code clojure cider

Another thing you may want/need is to use an alias when connecting cider. I know that cider can have that set up on your configuration. You can use .dir-locals.el to set up per project but I personally prefer to be able to choose when connecting.

(defun start-cider-repl-with-lein-profile ()
   (interactive)
   (letrec ((profile (read-string "Enter profile name: "))
          (lein-params (concat "with-profile +" profile " repl :headless :host localhost")))
     (message "lein-params set to: %s" lein-params)
     (set-variable 'cider-lein-parameters lein-params)
     (cider-jack-in '())))

 (defun start-cider-repl-with-cli-profile ()
   (interactive)
   (letrec ((profile (read-string "Enter profile name: "))
          (cli-params (concat "-A:" profile)))
     (message "cli-params set to: %s" cli-params)
     (set-variable 'cider-clojure-cli-aliases cli-params)
     (cider-jack-in '())))

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Wait, do you want to choose a alias with cider?