From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Honesty with parse-partial-sexp Date: 12 Dec 2006 20:01:34 +0100 Message-ID: <20061212201200.GA1118@muc.de> References: <20061207185738.GA1607@muc.de> <457A8620.9090602@gmx.at> NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1165950164 19627 80.91.229.10 (12 Dec 2006 19:02:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 12 Dec 2006 19:02:44 +0000 (UTC) Cc: rudalics@gmx.at, rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 12 20:02:41 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1GuCtf-0006On-Kg for ged-emacs-devel@m.gmane.org; Tue, 12 Dec 2006 20:02:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GuCtf-0000qZ-A0 for ged-emacs-devel@m.gmane.org; Tue, 12 Dec 2006 14:02:35 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GuCtI-0000pN-Df for emacs-devel@gnu.org; Tue, 12 Dec 2006 14:02:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GuCtF-0000nV-8S for emacs-devel@gnu.org; Tue, 12 Dec 2006 14:02:11 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GuCtF-0000nR-4G for emacs-devel@gnu.org; Tue, 12 Dec 2006 14:02:09 -0500 Original-Received: from [193.149.48.1] (helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GuCsr-0001Y3-8j for emacs-devel@gnu.org; Tue, 12 Dec 2006 14:01:45 -0500 Original-Received: (qmail 77141 invoked by uid 3782); 12 Dec 2006 19:01:34 -0000 Original-Received: from acm.muc.de (p54A3E7A8.dip.t-dialin.net [84.163.231.168]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Tue, 12 Dec 2006 20:01:32 +0100 (CET) Original-Received: (qmail 2304 invoked by uid 1000); 12 Dec 2006 20:12:00 -0000 Original-Date: Tue, 12 Dec 2006 20:12:00 +0000 Original-To: Stefan Monnier Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.0.3 (Seattle Slew) X-Primary-Address: acm@muc.de X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:63641 Archived-At: 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.