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.
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 '())))
Ok, I will admit.. this took a while. But I have found a nice way of
doing this.
What is this? Well, let’s say that you have a command to start your
server in user
namespace. With this cool feature, now you can run
this with a emacs command (or shortcut if you bind it).
The cool thing about this is that the command will run with the
namespace from the repl and not the last ns that you loaded with cider
=].
Here is a taste:
(defun le2m/cool-repl-command ()
(interactive)
(cider-interactive-eval
(cider-insert-in-repl (format "(clojure.core/require 'a-namespace)
(a-namespace/do-something
(fn lambda-example [t] (:get-a-key (meta t))))") 't)))
- stackoverflow reference that started this
/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Indent file on save, please