views:

36

answers:

1

I have written function (actually a macro, but whatever) that works similarly to progn. How can I tell emacs that this function should be indented in the same way as progn?

+3  A: 

This should do it

(put 'myfunc 'lisp-indent-function 0)

alt text

Documentation for lisp-indent-function (found by C-h f lisp-indent-function RET):

lisp-indent-function is a compiled Lisp function in `lisp-mode.el'.

(lisp-indent-function indent-point state)

This function is the normal value of the variable lisp-indent-function. It is used when indenting a line within a function call, to see if the called function says anything special about how to indent the line.

indent-point is the position where the user typed TAB, or equivalent. Point is located at the point to indent under (for default indentation); state is the parse-partial-sexp state for that position.

If the current line is in a call to a Lisp function which has a non-nil property lisp-indent-function, that specifies how to do the indentation. The property value can be * defun, meaning indent defun-style; * an integer N, meaning indent the first N arguments specially like ordinary function arguments and then indent any further arguments like a body; * a function to call just as this function was called. If that function returns nil, that means it doesn't specify the indentation.

This function also returns nil meaning don't specify the indentation.

6502
Care to elaborate, or at least link to documentation?
Ryan Thompson
Actually, that doesn't seem to do anything.
Ryan Thompson
I've found some time ago (and I don't remember where) a page describing how to fix emacs indentation for "if", "do" and and a few other common lisp constructs. From that page I decided to put in my .emacs a couple of those suggestions (now I've lisp-indent-function set to nil for "if" and to 2 for "do" and "do*").I agree with you that the documentation for list-indent-function isn't that detailed.
6502
Oops, maybe it would have worked the first time if I changed `myfunc` to the actual name of the function. I ended up going with `(put 'myfunc 'lisp-indent-function (get 'progn 'lisp-indent-function))`, i.e. "do whatever `progn` does."
Ryan Thompson
@Ryan That's even better than the try-and-see approach I used
6502