all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: ccsmile2008@outlook.com, npostavs@gmail.com,
	Stefan Monnier <monnier@IRO.UMontreal.CA>,
	emacs-devel@gnu.org
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	[thread overview]
Message-ID: <20171230154305.GF10623@ACM> (raw)
In-Reply-To: <83shbse5rs.fsf@gnu.org>

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

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



  parent reply	other threads:[~2017-12-30 15:43 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
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 [this message]
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

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

  git send-email \
    --in-reply-to=20171230154305.GF10623@ACM \
    --to=acm@muc.de \
    --cc=ccsmile2008@outlook.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.