3

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?

  • You might want to use a file-local variable to do this instead. – wasamasa May 28 '16 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. – Qudit May 28 '16 at 9:15
  • 1
  • Perfect! That does exactly what I'd hoped for. – Qudit May 28 '16 at 13:47
2

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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.