emacs-devel
[Top][All Lists]
Advanced

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

Re: Honesty with parse-partial-sexp


From: Alan Mackenzie
Subject: Re: Honesty with parse-partial-sexp
Date: 12 Dec 2006 20:53:05 +0100
Date: Tue, 12 Dec 2006 21:03:31 +0000
User-agent: Mutt/1.5.9i

Hi, Stephan,

That was quick!

On Tue, Dec 12, 2006 at 02:29:44PM -0500, Stefan Monnier wrote:
> > I don't think a special case should be made for point already being at
> > top level:  It's surely more consistent just to return (point) in this
> > case.  To return nil would make callers of the function have to take
> > evasive action, such as:

> >    (let ((base-pos (or (syntax-ppss-toplevel-pos ppss)
> >                        (point))))

> > instead of the more natural

> >    (let ((base-pos (syntax-ppss-toplevel-pos ppss)))

> But there can be other uses.  E.g. testing "toplevel-p" becomes just
> (null (syntax-ppss-toplevel-pos (syntax-ppss))) rather than having to check
> equality with (point).

I would argue for a coherent definition rather than optimising it for
particular uses.  However, ....

[ snippety snip ]

> Of course, the other problem with this code is that there's no guarantee
> that (point) is the position of the end of the scan (we may even have
> switched to some other buffer in the mean time).

This is the bit that I missed - ppss doesn't record the stopping point at
all.  So I now agree with you.  How about this:

(defun syntax-ppss-toplevel-pos (ppss)
  "Get the latest syntactically outermost position found in a syntactic scan.

PPSS is a record of the scan; it is \(or looks like) the return
value of the function `partial-parse-sexp' \(or
`syntactic-ppss').  If no such position is recorded in PPSS
\(because the end of the scan was itself at the outermost level),
return NIL.

An \"outermost position\" means one that it is outside of any
syntactic entity: outside of any parentheses encountered in the
scan, or comments, or strings."
  (or (car (nth 9 ppss))
      (nth 8 ppss)))

?

>         Stefan

-- 
Alan.




reply via email to

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