Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does (declare (indent *)) work?

Tags:

emacs

elisp

The info page doesn't mention this declaration. I found uses where it is set to either 1, 2 or 3, but what other options are possible? What exactly does it do?

On the surface of it, it looks like the digit means the number of lines after the macro name to indent further right, but in that case, how do I tell it to indent all forms as the first one?

Examples:

(declare (indent 1)) does this:

(-iter 
    (with (a b c))
  (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

(declare (indent 2)) does this:

(-iter 
    (with (a b c))
    (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

(declare (indent 256)) (or just any large enough number) does this:

(-iter 
    (with (a b c))
    (for i from 0 to 5)
    (collect i)
    (message "i: %s" i))

I would like to do the last one, except for providing an arbitrary large number. Is there any way to tell "all" or some thing to that effect?


2 Answers

It's in the manual:

C-hig (elisp) Indenting Macros RET

Linked to from the index entry for declare, FYI. (Emacs 24.2.1)

like image 58
phils Avatar answered Jul 13 '26 21:07

phils


Since the accepted answer doesn't actually answer the question, and the manual is fairly obtuse, let me point to this blog which reveals that a value of 0 actually works here, and is synonymous to defun.

However, the indentation level does not go as far as with a number. Examine:

With (indent nil) or without an (indent ...) declaration:

(-iter
 (with (a b c))
 (for i from 0  to 5)
 (collect i)
 (message "i: %s" i))

With (indent defun) or (indent 0):

(-iter
  (with (a b c))
  (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

With (indent 256):

(-iter
    (with (a b c))
    (for i from 0 to 5)
    (collect i)
    (message "i: %s" i))

With (indent (lambda (x y) 4)) you get the same result as for (indent 256). Hardcoding an indent probably conflicts slightly with the mechanisms for specifying different indentation styles with lisp-indent-function, though.

like image 32
tripleee Avatar answered Jul 13 '26 22:07

tripleee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!