Fork me on GitHub
#spacemacs
<
2018-04-02
>
lemons13:04:07

Hey. Is there a way to configure specific indentation rules for macros? Right now I'm writing some rest services using compojure-api and this is what I end up with

(context "/api/v1/accounts" []
           :tags ["Accounts"]
           (GET "/" []
                :summary "Retrieves all accounts"
                (ok (accounts-repository/all)))
           (POST "/" []
                 :return Account-Response
                 :body [acc Account]
                 :summary "Create an account"
                 (ok (accounts-repository/insert acc)))

           (context "/:account-id" []
                    :path-params [account-id :- s/Int]
                    (GET "/" []
                         :summary "Retrieve account by id"
                         (ok (accounts-repository/find-by-id account-id)))
                    (context "/transactions" []
                             (GET "/" []
                                  :summary "Retrieve transactions for account"
                                  (ok (transactions-repository/all)))))))

what I would like is this indentation style:
(context "/hello-async" []
  (resource
    {:coercion :spec
     :get {:parameters {:query-params (s/keys :req-un [::name])}
           :responses {200 {:schema (s/keys :req-un [::message])}}
           :handler (fn [{{:keys [name]} :query-params}]
                      (a/go
                        (a/<! (a/timeout 500))
                        (ok {:message (str "Hello, " name)})))}}))
is there a way to do this?

spfeiffer14:04:41

I have no experience with this, but i stumbled across the docucentation. Perhaps it helps.

jeff.terrell15:04:07

IIRC, the indent spec is for when you're the author of the macro. Otherwise, use indentation overrides for clojure-mode, as documented here: https://github.com/clojure-emacs/clojure-mode#indentation-options

jeff.terrell15:04:19

For example, I have this in my dotspacemacs/user-config, for using speclj for testing:

(with-eval-after-load 'clojure
    (define-clojure-indent
      (describe 1)
      (context 1)
      (it 1)
      (with 1)))

spfeiffer16:04:58

@jeff.terrell Ah ok, sorry for pointing in a wrong direction…

jeff.terrell16:04:25

Ha, no worries, it's an easy mistake to make. simple_smile

jeff.terrell16:04:44

Besides, better to try and fail than not to try, right?

spfeiffer16:04:31

Yeah, but obviously it had nothing to do with CIDER, but clojure-mode, so i had the wrong association. Nice you are into that stuff ☺️

simple_smile 4
lemons16:04:47

Thanks, that does look like what I need. I'm having problems getting it to work though... I've added this into my user-config section:

(with-eval-after-load 'clojure
    (define-clojure-indent
      (->> 1)))
but this macro is still being formatted as usual
(->> a
     b)
any ideas? I'm kinda new to spacemacs

lemons16:04:53

yeah no worries 🙂

jeff.terrell16:04:04

Try it in the ex-mode line while editing a Clojure buffer, e.g. :(define-clojure-indent (->> 1)) from normal mode.

jeff.terrell16:04:36

(I'm assuming you're using vim-style editing, i.e. "evil mode" in Spacemacs, btw.)

jeff.terrell16:04:06

Then go to the beginning of your ->> expression and type =% to indent according to the current rules.

lemons16:04:35

that did work

👍 4
lemons16:04:56

it would seem my init code isn't executed or is overwritten somehow

spfeiffer16:04:17

@lemons Did you reload using SPC f-e-R?

lemons16:04:11

yeah. I've added some printing inside with-eval-after-load call to make sure the code was not called

spfeiffer16:04:01

Well, sometimes i feel like i have to restart spacemacs to make things work

jeff.terrell16:04:09

@lemons - I'm not sure, but I wonder if clojure-mode is only loaded once, when a clj file is first encountered.

jeff.terrell16:04:41

So yeah, to tag on what @spfeiffer said, if you restart spacemacs and load a clj file, is the with-eval-after-load code still not being executed?

spfeiffer16:04:01

Yeah, might be the mode gets not reinitialized.

lemons16:04:32

(with-eval-after-load 'clojure-mode <----
theres apparently two different packages/libraries/whatever this thing is in emacs. clojure-mode is the one I needed

lemons17:04:19

thanks for the help guys!

spfeiffer17:04:39

Ah, it was clojure vs clojure-mode?

jeff.terrell17:04:26

Ah, didn't notice that, but it's obvious in retrospect, isn't it? simple_smile Glad you got it figured out.

lemons17:04:17

yeah, and now I know a tiny little bit about emacs. How to print messages to help debugging for example