Fork me on GitHub
#spacemacs
<
2020-09-17
>
rberger19:09:08

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 types

zane23:09:47

Instead 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).

rberger23:09:18

Any suggestions on how to do that? I’m not an elisper so much

zane18:09:37

So, perhaps something like this:

(add-hook 'before-save-hook
          '(lambda ()
             (when (derived-mode-p 'clojure-mode)
               (clojure-indent-region (point-min) (point-max)))

zane18:09:48

Alternatively you could turn on aggressive-indent-mode for Clojure files only.

rberger22:10:44

Thanks! Giving that a try. Seems to be working.

zane18:10:09

Glad to hear it!

njj20:09:01

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 + <

njj20:09:47

any advice on how to achieve this again?

practicalli-johnny20:09:57

@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 bindings

njj21:09:34

Sweet let me give that a go