4

I'd like to know if there is a way to define the indentation for a custom macro within the clojure source file. It is possible to define the indentation using clojure-mode, but as far as I can tell, it has to be done using elisp as described here.

Is there a way to do this from within a clojure source file? For example, in an elisp source file, one can do something like

(defmacro mac (arg)
  (declare (indent 1))
  ...)

Does the combination of clojure and clojure-mode support something like this?

4
  • You might want to use a file-local variable to do this instead. Commented May 28, 2016 at 9:08
  • 2
    @wasamasa That would work for the file that the macros are defined in, but I'd also like it to work in other Clojure code that requires that file (like the above elisp code does) without having to explicitly set a file local variable each time. Commented May 28, 2016 at 9:15
  • 1
    cider.readthedocs.io/en/latest/indent_spec Commented May 28, 2016 at 12:51
  • Perfect! That does exactly what I'd hoped for. Commented May 28, 2016 at 13:47

1 Answer 1

3

CIDER offers that functionality. Instead of using an extra declaration form, one puts the indentation info into the function's metadata:

(defmacro comment
  "Ignores body, yields nil"
  {:style/indent 1}
  [& body])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.