unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Eli Zaretskii <eliz@gnu.org>,
	ccsmile2008@outlook.com, npostavs@gmail.com, emacs-devel@gnu.org
Subject: Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode]
Date: Wed, 3 Jan 2018 16:24:03 +0000	[thread overview]
Message-ID: <20180103162403.GB5435@ACM> (raw)
In-Reply-To: <87incjh7ef.fsf@mbork.pl>

Hello, Marcin.

On Wed, Jan 03, 2018 at 05:51:35 +0100, Marcin Borkowski wrote:

> On 2017-12-30, at 14:05, Alan Mackenzie <acm@muc.de> wrote:
> > 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 <ccsmile2008@outlook.com>,
> >> >   Noam Postavsky <npostavs@gmail.com>
> >> > From: Alan Mackenzie <acm@muc.de>

> >> > > 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.

> > beginning-of-defun-comments came into existence on 2017-03-31, so this
> > problem is definitely new in Emacs 26.

> Yep, it was committed by me.  Sorry for the mess.  And I thought I had
> tested that thoroughly...

These things are tricky to test properly.  ;-)

> > I've diagnosed the bug.  At one place, it is necessary to scan a line of
> > text from BOL to detect any non-comment/non-space character.  The
> > current code tries to do this by using parse-partial-sexp with the
> > fourth argument STOPBEFORE non-nil.

> > This STOPBEFORE causes the scanning to stop at any character which
> > begins a sexp.  A closing brace doesn't fit into this category.  The
> > scan therefore reaches EOL, and the code therefore falsely assumes there
> > are no non-syntactic-ws characters on that line.

> > I'm sure I can fix this today.

> Any success?  If not, can I help in any way?  (At the very least,
> I could write some more tests to cover this case.)

Sorry, I got distracted by the turn of the year, and one or two other
things.  Please try this:



diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 6952ef4cf4..28605cd35c 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -405,12 +405,13 @@ beginning-of-defun--in-emptyish-line-p
 ;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html
   (save-excursion
     (forward-line 0)
-    (< (line-end-position)
-       (let ((ppss (syntax-ppss)))
-         (when (nth 4 ppss)
-           (goto-char (nth 8 ppss)))
-         (forward-comment (point-max))
-         (point)))))
+    (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)))))))
 
 (defun beginning-of-defun-comments (&optional arg)
   "Move to the beginning of ARGth defun, including comments."
@@ -428,10 +429,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.
+                  (beginning-of-defun--in-emptyish-line-p)))) ; Check for non-comment text.
     (forward-line (if first-line-p 0 1))))
 
 (defvar end-of-defun-function


> Best,

> -- 
> Marcin Borkowski

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2018-01-03 16:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-30  9:49 26.0.90: mark-defun problem in c-mode zhang cc
2017-12-30 10:30 ` Eli Zaretskii
2017-12-30 10:34   ` Alan Mackenzie
2017-12-30 12:01     ` beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Alan Mackenzie
2017-12-30 12:53       ` Eli Zaretskii
2017-12-30 13:05         ` Alan Mackenzie
2018-01-03  4:51           ` Marcin Borkowski
2018-01-03 16:24             ` Alan Mackenzie [this message]
2018-01-05 14:55               ` zhang cc
2018-01-06 12:00                 ` Alan Mackenzie
2018-01-06 13:54                   ` zhang cc
2018-01-07  6:25                   ` Marcin Borkowski
2018-03-26  6:57               ` Marcin Borkowski
2017-12-30 15:43         ` Alan Mackenzie
2017-12-30 18:43           ` Stephen Leake
2017-12-31 10:55             ` Alan Mackenzie
2017-12-31  4:26           ` Stefan Monnier
2017-12-31 10:50             ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180103162403.GB5435@ACM \
    --to=acm@muc.de \
    --cc=ccsmile2008@outlook.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mbork@mbork.pl \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).