From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#14303: 24.3; Bug in comment-search-backward Date: Fri, 17 May 2013 18:47:48 +0800 Message-ID: References: <5193B43B.8070007@easy-emacs.de> <519486DD.1040505@easy-emacs.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1368787739 20947 80.91.229.3 (17 May 2013 10:48:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 May 2013 10:48:59 +0000 (UTC) Cc: 14303@debbugs.gnu.org To: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 17 12:48:56 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UdIDU-0003H9-NI for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2013 12:48:52 +0200 Original-Received: from localhost ([::1]:51000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIDU-0004hp-Af for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2013 06:48:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIDQ-0004hX-SJ for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 06:48:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdIDP-0001QC-LH for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 06:48:48 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIDP-0001Q4-Gz for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 06:48:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UdIDe-0008P2-BE for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 06:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 May 2013 10:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14303 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14303-submit@debbugs.gnu.org id=B14303.136878770132236 (code B ref 14303); Fri, 17 May 2013 10:49:02 +0000 Original-Received: (at 14303) by debbugs.gnu.org; 17 May 2013 10:48:21 +0000 Original-Received: from localhost ([127.0.0.1]:48485 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UdICy-0008Nt-UY for submit@debbugs.gnu.org; Fri, 17 May 2013 06:48:21 -0400 Original-Received: from mail-pb0-f51.google.com ([209.85.160.51]:59963) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UdICv-0008Nf-NI for 14303@debbugs.gnu.org; Fri, 17 May 2013 06:48:18 -0400 Original-Received: by mail-pb0-f51.google.com with SMTP id jt11so2132376pbb.10 for <14303@debbugs.gnu.org>; Fri, 17 May 2013 03:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:references:face:date:in-reply-to :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=QS4MDv/HNy0W4wqf0cfaGeQptM0Gu/1NEVtjI2cUTZ4=; b=GnoWYqtL9SItGnu7/JG9AMtXjAxD18yb9SaeH0fW+KlvqZbbP8eVHEf7vSo3iJF8BV 6daZ0rIwYI0dEEp5HjLiygAps1d6i3kW2n1HVUizEkSxNEvbq8HAeA65gg4EyGd9D5wZ NHB53RF+pZ1QYWGj6Hyq11Y43yR/OtXnmkW6O2puBhO/K/UxqaXp1XMON0CQ5VH7bkar ezilyhgJ1I+YdyTivK222x3dHcXNBC0D8/bbHMwuzlTWn9wgpAUioVW4fbZ8N3n9tkeJ 3J3Mn379DpzLWjpJjrcf3hX07PzQzJATPK2WE9eXQ5TTtaJ/kW9muYIF1wHSu08Q/TEE ageQ== X-Received: by 10.66.151.46 with SMTP id un14mr49080456pab.14.1368787676036; Fri, 17 May 2013 03:47:56 -0700 (PDT) Original-Received: from localhost (li511-224.members.linode.com. [66.175.216.224]) by mx.google.com with ESMTPSA id gc5sm10782660pbb.19.2013.05.17.03.47.53 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 May 2013 03:47:55 -0700 (PDT) Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAG1BMVEUAAAA9Cgm3Hx1WWFWA gn+WmJWsrqv4+vcCAwCRl2MkAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAYoA AAGKATOXMFgAAAAHdElNRQfXAQwDNR+ZJmElAAABIklEQVQoz22SPW+DQAyGWUq65qasd9PNUSX4 AZHK2C1rJy5jpDS4IwRVup9dn7GNafpKIPPgzztXFSujqq1eM2n8h22oMkvxI/i9C97kRfMRUN55 dS3BrsAwBXUtMLAO4lryh8kTjOxKpQNniNxAgZOEe4bZwsDTFhKdqZRLNII4OQNHhEuq/RMkm6Cj TnnEA/fk0BorcYn5qA3oaeAxbaBOLrX+9G48NZ2Fzc2tzDM8Q+tMypEOqYHh8mAWaaK3U/cDMOT5 aMZMABgPXc7zPMs1A8DXO756GFJ/4fMEq47hTsAdn5avoxZ4ywl0c2w4Flu2Ybeyb3S+EqxX2DYA H8veJGEDTnHnrXvRaPyt+2kSfK6rfBZ2tUtfP/mR+pR6sX8BUZ/cDV7tvkoAAAAASUVORK5CYII= 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") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (OS X 10.8.3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74359 Archived-At: On 2013-05-16 15:12 +0800, Andreas R=F6hler 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 noerr= or) 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))))) =20 (defun comment-beginning () "Find the beginning of the enclosing comment.