From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Date: Sun, 31 Dec 2017 10:50:05 +0000 Message-ID: <20171231105005.GA7569@ACM> References: <834lo8fqyi.fsf@gnu.org> <20171230103432.GB10623@ACM> <20171230120136.GD10623@ACM> <83shbse5rs.fsf@gnu.org> <20171230154305.GF10623@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1514717516 14456 195.159.176.226 (31 Dec 2017 10:51:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 31 Dec 2017 10:51:56 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: Eli Zaretskii , emacs-devel@gnu.org, npostavs@gmail.com, ccsmile2008@outlook.com To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 31 11:51:52 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVbDX-0003Ar-71 for ged-emacs-devel@m.gmane.org; Sun, 31 Dec 2017 11:51:47 +0100 Original-Received: from localhost ([::1]:35225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVbFU-0000KJ-Lg for ged-emacs-devel@m.gmane.org; Sun, 31 Dec 2017 05:53:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVbFJ-0000K8-JH for emacs-devel@gnu.org; Sun, 31 Dec 2017 05:53:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVbFG-0000nC-DT for emacs-devel@gnu.org; Sun, 31 Dec 2017 05:53:37 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:58413 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1eVbFG-0000kR-1m for emacs-devel@gnu.org; Sun, 31 Dec 2017 05:53:34 -0500 Original-Received: (qmail 57296 invoked by uid 3782); 31 Dec 2017 10:53:31 -0000 Original-Received: from acm.muc.de (p548C76FB.dip0.t-ipconnect.de [84.140.118.251]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 31 Dec 2017 11:53:29 +0100 Original-Received: (qmail 7669 invoked by uid 1000); 31 Dec 2017 10:50:05 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221483 Archived-At: Hello, Stefan. On Sat, Dec 30, 2017 at 23:26:24 -0500, Stefan Monnier wrote: > > + (if (nth 3 ppss) ; in a string > > + start > > + (when (nth 4 ppss) ; in a comment > > + (setq ppss > > + (parse-partial-sexp (point) eol nil nil ppss 'syntax-table))) > > + (catch 'got-it > > + (while (< (point) eol) > > + (setq start (point)) > > + (setq ppss (parse-partial-sexp (point) eol nil nil ppss t)) > > + (setq end (if (nth 4 ppss) (nth 8 ppss) eol)) > > + (goto-char start) > > + (skip-syntax-forward "-" end) > > + (when (< (point) end) > > + (throw 'got-it (point))) > > + (unless (forward-comment 1) ; comment straddles line break. > > + (throw 'got-it nil)) > > + (setq ppss (syntax-ppss)))))))) > Why not use something like > (>= (forward-comment (point-max)) (line-end-position)) > ? Indeed. Why not just use beginning-of-defun--in-emptyish-line-p, which is in the same file, in the same place as I coded non-syntactic-ws-in-line, yet I failed to notice it? It is also somewhat more elegantly coded than my new function. However, beginning-of-defun--in-emptyish-line-p isn't quite right, in that it fails to check whether BOL is inside a string. Something like the following (untested) should fix it: (defun beginning-of-defun--in-emptyish-line-p () "Return non-nil if the point is in an \"emptyish\" line. This means a line that consists entirely of comments and/or whitespace." ;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html (save-excursion (forward-line 0) (let ((ppss (syntax-ppss))) (and (null (nth 3 ppss)) (< (line-end-position) (progn (when (nth 4 ppss) (goto-char (nth 8 ppss))) (forward-comment (point-max)) (point))))))) Happy New Year! > Stefan -- Alan Mackenzie (Nuremberg, Germany).