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?

Dan
  • 32,584
  • 6
  • 98
  • 168
Qudit
  • 828
  • 8
  • 16
  • You might want to use a file-local variable to do this instead. – wasamasa May 28 '16 at 09: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 09:15
  • 1
    http://cider.readthedocs.io/en/latest/indent_spec/ – wasamasa May 28 '16 at 12:51
  • Perfect! That does exactly what I'd hoped for. – Qudit May 28 '16 at 13:47

1 Answers1

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])
wasamasa
  • 21,803
  • 1
  • 65
  • 97