help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic smart indentation


From: Kevin Rodgers
Subject: Re: Automatic smart indentation
Date: Fri, 31 Oct 2003 09:04:57 -0700
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Martin Stone Davis wrote:

I've read the threads in this list pertaining to indentation, but I haven't found a solution to the following problem: While editing a lisp program, I want to keep the indentation "correct" at all times.

i.e. If I yank I want to reindent. If I delete a ), I want it to reindent, If I insert a (, change the name of a function from if to when, undo etc. etc. etc., I want to reindent.

The solution I came up with is:

(setq lisp-indent-function 'common-lisp-indent-function)
(add-hook 'after-change-functions
       (lambda (start end pre-change-length)
             (indent-region start (buffer-size) nil)))

The problem is that it somehow gets into an endless loop *sometimes* when I undo. It might have problems in other situations, but that's whet I've found so far.

Sorry, I can't help you with that.  But I can tell you that (buffer-size)
should almost certainly be (point-max).  And you might want to add a check
for (eq major-mode 'lisp-mode), or make after-change-functions a local hook
variable in Lisp mode buffers (by putting the add-hook in a lisp-mode-hook
function, and specifying the optional LOCAL arg).

You might also have better luck if you call indent-region with a region
that starts at the beginning of the line:
(save-excursion (goto-char start) (line-beginning-position))

--
Kevin Rodgers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]