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:01:34 +0100
Date: Tue, 12 Dec 2006 20:12:00 +0000
User-agent: Mutt/1.5.9i

Hi, Stefan and Emacs!

On Mon, Dec 11, 2006 at 09:41:12PM -0500, Stefan Monnier wrote:
> > Please install this.  Then I will try to document it in the manual.

> Installed.  Please people (I guess I mean Alan ;-) tell me if it provides
> the right feature for you.

I think it's almost right, but not quite.  Sorry I didn't reply earlier
before you committed it.  Here, for reference, is the current version:

> (defun syntax-ppss-toplevel-pos (ppss)
>   "Return the last preceding position at toplevel.
> \"At toplevel\" means that it is outside of any syntactic entity:
> outside of any parentheses, or comments, or strings.
> Returns nil iff PPSS itself corresponds to a toplevel position."
>   (or (car (nth 9 ppss))
>       (nth 8 ppss)))

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)))
                       
Also the doc-string is suboptimal; It doesn't say what PPSS is, and
isn't quite accurate about "toplevel": If we start a (parse-partial-sexp
..) when we're already inside an open paren, we'll (probably) get a
position at this nested level, not the top level.  Won't we?

How about this amended version?  I know the first line of the
doc-string's a bit long, but maybe that's OK, or somebody handier with
words (Richard?) could shorten it.

(defun syntax-ppss-toplevel-pos (ppss)
  "Get the last position at outermost syntactic level found in a syntactic scan.
PPSS is \(or looks like) the return value of the scanning function
`partial-parse-sexp' \(or `syntactic-ppss').

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

Other than those small points, I thing the function is bang on target.

Thanks!

> I'll update syntax.el later to use this,
 
>         Stefan

-- 
Alan.




reply via email to

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