[gnu.emacs.bug] indent-sexp looping 18.55

steve%hplsg@HPLABS.HP.COM (Steve Greenbaum) (12/22/89)

Hi,

Here is a bug in Emacs 18.55.  I'm using it on an HP 9000/370 with HPUX 6.2
and X11.

Function indent-sexp, when trying to indent things like the following
expression fragment, will sometimes get into an infinite loop:

      ( ;)

To get the looping behavior there must not be an "extra" right paren later in
the file.  For example, the following will NOT loop:

      ( ;)
      )

The problem is that forward-sexp thinks the first example is a complete expr,
but parse-partial-sexp does not.  Forward-sexp is used by indent-sexp to check
that there is a complete expression.  The first example passes this test, then
the rest of indent-sexp, using parse-partial-sexp, loops looking for
parenthesis nesting level 0, which it correctly does not find (i.e. variabe
next-depth remains greater than zero).  The second example works because the
added paren closes the expression, even though forward-sexp incorrectly thinks
the commented-out paren is the closing paren.

Of course this can happen with realalistic examples too (that's how I found
it).

A simple fix is to add a "last-point" variable to indent-sexp, initialized to
-1, and add:

	(or outer-loop-done
	    (setq outer-loop-done (= (point) last-point))
	    (setq last-point (point))
	)

to the end of the outer while loop.  A better but more complicated fix would
be to make forward-sexp smart about comments.


  Steve Greenbaum
  HP Labs
  1501 Page Mill Road
  Palo Alto, CA  94304
  (415) 857-5181
  greenbaum@hplabs.hp.com