unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Leo Liu <sdl.web@gmail.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: 14303@debbugs.gnu.org
Subject: bug#14303: 24.3; Bug in comment-search-backward
Date: Fri, 17 May 2013 18:47:48 +0800	[thread overview]
Message-ID: <m1sj1lg9wr.fsf@gmail.com> (raw)
In-Reply-To: <519486DD.1040505@easy-emacs.de> ("Andreas \=\?iso-8859-1\?Q\?R\?\= \=\?iso-8859-1\?Q\?\=F6hler\=22's\?\= message of "Thu, 16 May 2013 09:12:29 +0200")

On 2013-05-16 15:12 +0800, Andreas Röhler wrote:
> Yes, same thing as with beg-of-defun discussed elsewhere.
>
> + (while (and (not found) (re-search-backward comment-start-skip limit t))
> +      (setq end (match-end 0))
> +      (or (nth 8 (syntax-ppss)) (setq found t)))
>
> This might find a comment-start inside a string.
>
> Rely at (syntax-ppss)
>
> if nt4 and nth8, goto char nth8

There is possibility of ending up in a string. How about something along
these lines? Thanks. Leo

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index d55feaa3..79cdc393 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -485,27 +485,30 @@ (defun comment-search-backward (&optional limit noerror)
 Moves point to inside the comment and returns the position of the
 comment-starter.  If no comment is found, moves point to LIMIT
 and raises an error or returns nil if NOERROR is non-nil."
-  ;; FIXME: If a comment-start appears inside a comment, we may erroneously
-  ;; stop there.  This can be rather bad in general, but since
-  ;; comment-search-backward is only used to find the comment-column (in
-  ;; comment-set-column) and to find the comment-start string (via
-  ;; comment-beginning) in indent-new-comment-line, it should be harmless.
-  (if (not (re-search-backward comment-start-skip limit t))
-      (unless noerror (error "No comment"))
-    (beginning-of-line)
-    (let* ((end (match-end 0))
-	   (cs (comment-search-forward end t))
-	   (pt (point)))
-      (if (not cs)
-	  (progn (beginning-of-line)
-		 (comment-search-backward limit noerror))
-	(while (progn (goto-char cs)
-		      (comment-forward)
-		      (and (< (point) end)
-			   (setq cs (comment-search-forward end t))))
-	  (setq pt (point)))
-	(goto-char pt)
-	cs))))
+  (let (found end beg)
+    (while (and (not found) (re-search-backward comment-start-skip limit t))
+      (setq beg (or (match-end 1) (match-beginning 0))
+	    end (match-end 0))
+      (when (or (not comment-use-syntax)
+		(and (not (nth 8 (syntax-ppss beg)))
+		     (nth 4 (syntax-ppss end))))
+	(setq found t))
+      (goto-char beg))
+    (if (not found)
+	(unless noerror (error "No comment"))
+      (beginning-of-line)
+      (let ((cs (comment-search-forward end t))
+	    (pt (point)))
+	(if (not cs)
+	    (progn (beginning-of-line)
+		   (comment-search-backward limit noerror))
+	  (while (progn (goto-char cs)
+			(comment-forward)
+			(and (< (point) end)
+			     (setq cs (comment-search-forward end t))))
+	    (setq pt (point)))
+	  (goto-char pt)
+	  cs)))))
 
 (defun comment-beginning ()
   "Find the beginning of the enclosing comment.





  reply	other threads:[~2013-05-17 10:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-29 13:27 bug#14303: 24.3; Bug in comment-search-backward Leo Liu
2013-05-15 11:33 ` Leo Liu
2013-05-15 16:13   ` Andreas Röhler
2013-05-16  4:02     ` Leo Liu
2013-05-16  7:12       ` Andreas Röhler
2013-05-17 10:47         ` Leo Liu [this message]
2013-05-17 11:14           ` Andreas Röhler
2013-05-17 11:34             ` Leo Liu
2013-05-17 12:39               ` Andreas Röhler
2013-05-17 13:18                 ` Leo Liu
2013-05-17 13:28           ` Stefan Monnier
2013-05-17 13:37             ` Leo Liu
2013-05-17 14:27               ` Andreas Röhler
2013-05-17 22:52                 ` Leo Liu
2013-05-18  5:23                   ` Andreas Röhler
2013-05-21  1:55                     ` Stefan Monnier
2013-05-22 10:58                       ` Andreas Röhler
2013-05-22 15:58                         ` Stefan Monnier
2013-05-22 16:53                           ` Andreas Röhler
2013-05-17 15:52               ` Stefan Monnier
2013-05-17 22:54                 ` Leo Liu
2013-05-16 13:28   ` Stefan Monnier
2013-05-16 15:50     ` Leo Liu
2013-05-16 17:38       ` Stefan Monnier
2013-05-17  0:35         ` Leo Liu
2013-05-17 13:26           ` Stefan Monnier
2013-05-17 22:51             ` Leo Liu

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=m1sj1lg9wr.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=14303@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    /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).