From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#14303: 24.3; Bug in comment-search-backward Date: Fri, 17 May 2013 13:14:58 +0200 Message-ID: <51961132.1040703@easy-emacs.de> 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; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1368789176 3253 80.91.229.3 (17 May 2013 11:12:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 May 2013 11:12:56 +0000 (UTC) Cc: 14303@debbugs.gnu.org To: Leo Liu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 17 13:12:55 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 1UdIak-0006ov-1o for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2013 13:12:54 +0200 Original-Received: from localhost ([::1]:56246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIaj-000129-Im for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2013 07:12:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIaf-0000ze-16 for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 07:12:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdIad-0000Wc-GY for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 07:12:48 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdIad-0000WT-Ds for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 07:12:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UdIas-0000Zk-41 for bug-gnu-emacs@gnu.org; Fri, 17 May 2013 07:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 May 2013 11:13: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.13687891702194 (code B ref 14303); Fri, 17 May 2013 11:13:02 +0000 Original-Received: (at 14303) by debbugs.gnu.org; 17 May 2013 11:12:50 +0000 Original-Received: from localhost ([127.0.0.1]:48510 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UdIag-0000ZL-4d for submit@debbugs.gnu.org; Fri, 17 May 2013 07:12:50 -0400 Original-Received: from moutng.kundenserver.de ([212.227.17.8]:54653) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UdIac-0000Z6-TX for 14303@debbugs.gnu.org; Fri, 17 May 2013 07:12:48 -0400 Original-Received: from [192.168.178.21] (brln-4dbc7c0d.pool.mediaWays.net [77.188.124.13]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0M5xcn-1UJyPe2uGf-00xw42; Fri, 17 May 2013 13:12:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 In-Reply-To: X-Provags-ID: V02:K0:mEuSJVAZDf0lZh6vKnPcKzZD5hLMyPdclrUDz+oAlZS ToFXsPbF2OzM+7EISBm34/omZGnNBcQYd1ZkvYxz9C429X9tyy qp6ULFdf6xF0JoYegohLzn2fusEWJrDfOefwYlqWiRabYFf52S ybx3pM1aWLsp+65s0l5zoj7TQyrfFzgfHn5Ax8hpma3ep5rPcG QdXJZNQQbHyfhOIiwvRs6q0EUeH2SooGJpl3K57VqmYgNBN+qW urRAQ7d5eMchI6u+22cfiBHaUiiGsLUG8269wbE/1d4mTVUKd0 YUshrWbBLQO7Ctro2eW6x0NgWm3orpIN6PHRWs/zspqhlaLmx7 CqqXDFVoDqlXRG9eqTah2x9kbsB2vG1wKt/YvQGSm 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:74360 Archived-At: Am 17.05.2013 12:47, schrieb Leo Liu: > 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. > The succession of things doesn't look right yet. if (eq comment-use-syntax nil) re-search-backward based solution which is very seldom. Grep shows 4 cases. Otherwise syntax-ppss - , prog1 and nth 4 goto char nth 8 - or so. Make sure wrong regexp isn't called then/no wrong matches. Andreas