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: Sat, 30 Dec 2017 15:43:05 +0000 Message-ID: <20171230154305.GF10623@ACM> References: <834lo8fqyi.fsf@gnu.org> <20171230103432.GB10623@ACM> <20171230120136.GD10623@ACM> <83shbse5rs.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1514648682 10324 195.159.176.226 (30 Dec 2017 15:44:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Dec 2017 15:44:42 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: ccsmile2008@outlook.com, npostavs@gmail.com, Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 30 16:44:38 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 1eVJJM-0002Gz-3r for ged-emacs-devel@m.gmane.org; Sat, 30 Dec 2017 16:44:36 +0100 Original-Received: from localhost ([::1]:58314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVJLK-0005z2-TN for ged-emacs-devel@m.gmane.org; Sat, 30 Dec 2017 10:46:38 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVJLA-0005yl-JH for emacs-devel@gnu.org; Sat, 30 Dec 2017 10:46:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVJL8-0003ui-7j for emacs-devel@gnu.org; Sat, 30 Dec 2017 10:46:28 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:13331 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1eVJL7-0003uO-U9 for emacs-devel@gnu.org; Sat, 30 Dec 2017 10:46:26 -0500 Original-Received: (qmail 83542 invoked by uid 3782); 30 Dec 2017 15:46:25 -0000 Original-Received: from acm.muc.de (p548C69B7.dip0.t-ipconnect.de [84.140.105.183]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 30 Dec 2017 16:46:23 +0100 Original-Received: (qmail 13159 invoked by uid 1000); 30 Dec 2017 15:43:05 -0000 Content-Disposition: inline In-Reply-To: <83shbse5rs.fsf@gnu.org> 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:221473 Archived-At: Hello, Eli. On Sat, Dec 30, 2017 at 14:53:27 +0200, Eli Zaretskii wrote: > > Date: Sat, 30 Dec 2017 12:01:36 +0000 > > Cc: emacs-devel@gnu.org, zhang cc , > > Noam Postavsky > > From: Alan Mackenzie > > > I see the error, with point anywhere in the body of the second function. > > > Critical seems to be there being no blank line between the functions. > > > I think there's a bug in beginning-of-defun-comments, which I'm in the > > > middle of edebugging. It moves point into the first function. > > beginning-of-defun-comments has a bug. On doing M-x > > beginning-of-defun-comments from the inside of a function, when there's > > no blank lines between it and the previous function, point ends up > > inside that previous function, not at the comments which may separate > > them. > > Perhaps this bug should be fixed before the next Emacs-26 pretest. > How old is this problem? It looks like it's new in Emacs 26? If so, > we should try fixing it on the release branch. OK. I've hacked together the following, which seems to work, but I'm not altogether happy with it. non-syntactic-ws-in-line should not be so hard to write; ideally, it should be available directly from parse-partial-sexp, possibly by enhancing the meaning of argument STOPBEFORE. Also, non-syntactic-ws-in-line doesn't really seem to belong in this file. Possibly it should be in syntax.el. I also think somebody else should eyeball non-syntactic-ws-in-line to try and catch some wierd case I've missed. The following is based on the emacs-26 branch. diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 6952ef4cf4..251db2cb08 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -412,6 +412,35 @@ beginning-of-defun--in-emptyish-line-p (forward-comment (point-max)) (point))))) +(defun non-syntactic-ws-in-line () + "Is there a non-whitespace, non-comment character in the current line? +If so, return the position of the first such character, otherwise return + nil." + (save-excursion + (forward-line 0) ; to BOL. + (let ((ppss (syntax-ppss)) + (eol (save-excursion (end-of-line) (point))) + (start (point)) + end + ) + (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)))))))) + (defun beginning-of-defun-comments (&optional arg) "Move to the beginning of ARGth defun, including comments." (interactive "^p") @@ -428,10 +457,7 @@ beginning-of-defun-comments (progn (skip-syntax-backward "-" (line-beginning-position)) (not (bolp))) ; Check for blank line. - (progn (parse-partial-sexp - (line-beginning-position) (line-end-position) - nil t (syntax-ppss (line-beginning-position))) - (eolp))))) ; Check for non-comment text. + (not (non-syntactic-ws-in-line))))) ; Check for non-comment text. (forward-line (if first-line-p 0 1)))) (defvar end-of-defun-function -- Alan Mackenzie (Nuremberg, Germany).