How do I customize my init.el so that it auto-indents the whole file only for clojure/clojurescript files? I tried:
(defun my--clojure-mode-hook ()
(make-local-variable 'before-save-hook)
(add-hook 'before-save-hook
'(lambda ()
(clojure-indent-region (point-min) (point-max)))))
(add-hook 'clojure-mode-hook 'my--clojure-mode-hook)
But it seems to indent files of all typesInstead of trying to make before-save-hook
local you could have your hook always run, but only indent if the current major mode is one of the Clojure major mode (`.clj`, .cljs
, or .cljc
).
Any suggestions on how to do that? I’m not an elisper so much
https://emacsredux.com/blog/2020/06/14/checking-the-major-mode-in-emacs-lisp/
So, perhaps something like this:
(add-hook 'before-save-hook
'(lambda ()
(when (derived-mode-p 'clojure-mode)
(clojure-indent-region (point-min) (point-max)))
Alternatively you could turn on aggressive-indent-mode
for Clojure files only.
Thanks! Giving that a try. Seems to be working.
Glad to hear it!
Hey all, I used to have this great re-mapping for slurp and barf that an old co-worker gave me but I can't for the life of me figure out how to get it back. I could do "slurp forwards" (`sp-forward-slurp-sexp` ) with shift + >
and and "slurp backwards" with shift + <
any advice on how to achieve this again?
@njustice I assume you don't want to use the built-in key bindings, SPC k s
and SPC k S
for those slurp commands. I prefer these over the more awkward custom key bindings I used to use.
Edit the .spacemacs file and add one of the following to the dotspaceamcs/user-config
section
The global approach would be
(define-key global-map (kbd "S->") 'sp-forward-slurp-sexp)
For just Clojure mode, then
(define-key clojure-mode-map (kbd "S->") 'sp-forward-slurp-sexp)
These will over-ride any existing key bindingsSweet let me give that a go