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 08:35:35 +0800 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1368751021 11331 80.91.229.3 (17 May 2013 00:37:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 May 2013 00:37:01 +0000 (UTC) Cc: 14303@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 17 02:36: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 1Ud8fG-00021w-Tw for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2013 02:36:55 +0200 Original-Received: from localhost ([::1]:54124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ud8fG-0007Hk-E7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 May 2013 20:36:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ud8fC-0007Hb-MX for bug-gnu-emacs@gnu.org; Thu, 16 May 2013 20:36:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ud8fB-0007Ro-J9 for bug-gnu-emacs@gnu.org; Thu, 16 May 2013 20:36:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ud8fB-0007Ri-EP for bug-gnu-emacs@gnu.org; Thu, 16 May 2013 20:36:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Ud8fO-000503-4a for bug-gnu-emacs@gnu.org; Thu, 16 May 2013 20:37: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 00:37: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.136875096819069 (code B ref 14303); Fri, 17 May 2013 00:37:02 +0000 Original-Received: (at 14303) by debbugs.gnu.org; 17 May 2013 00:36:08 +0000 Original-Received: from localhost ([127.0.0.1]:48042 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ud8eV-0004xW-Q1 for submit@debbugs.gnu.org; Thu, 16 May 2013 20:36:08 -0400 Original-Received: from mail-pa0-f48.google.com ([209.85.220.48]:39939) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ud8eS-0004wo-Kl for 14303@debbugs.gnu.org; Thu, 16 May 2013 20:36:06 -0400 Original-Received: by mail-pa0-f48.google.com with SMTP id kp6so3025151pab.35 for <14303@debbugs.gnu.org>; Thu, 16 May 2013 17:35:45 -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; bh=dv1uRhPFJdOos9JPYq2Bas6h4pj4cWwAqKkE17ggkI8=; b=ORWTwqw9oY5xzy9yYedIDVDjHaEi/0P6lgtPnLY773b8jYapqMiVp9KYx+bPq6za7S KUL8aJm4kgz6dht/7oUD8zJ5Nsa0nBGVoARO5xzf3cVYKMDacCSeph8pkDt5DVUYGfS3 lnWz95JIhVIG8fdb0XAkiMUhVu7Qo4CJ/Y/ocS1qhe7F2AKdiFd7tCGROhxt16P5nBVg e4bIRS4c04tss25lnPKHpHg/j/cMNpT/jmNGhKGFx6UP+YfOZgJZRnpT4f4YPqbMk64f SyqbSZRH6iMYM/kGExuAuuJ5hm0HKB4h0souxtarv8e5tPCf64hsVx6cd5Hpjk6uYWYm 5kaA== X-Received: by 10.68.197.195 with SMTP id iw3mr45226605pbc.177.1368750945664; Thu, 16 May 2013 17:35:45 -0700 (PDT) Original-Received: from Zeuss-MacBook.local (li511-224.members.linode.com. [66.175.216.224]) by mx.google.com with ESMTPSA id r6sm9582798pae.18.2013.05.16.17.35.41 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 16 May 2013 17:35:44 -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: (Stefan Monnier's message of "Thu, 16 May 2013 13:38:29 -0400") 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:74348 Archived-At: On 2013-05-17 01:38 +0800, Stefan Monnier wrote: > Right, that makes sense. > > > Stefan In that case I plan to install the patch as attached. I have found that it is very easy for people who provide customised comment-start-skip to introduce bugs. For example octave mode used to have "\\s<+\\s-*" as comment start skip and was lucky to work in the buggy comment-search-backward. I wonder what to do here. Better documentation on comment-start-skip to inform people that it is used both in re-search-forward/backward and better be anchored properly? diff --git a/lisp/newcomment.el b/lisp/newcomment.el index d55feaa3..db07e6a9 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -485,27 +485,26 @@ (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) + (while (and (not found) (re-search-backward comment-start-skip limit t)) + (setq end (match-end 0)) + (unless (and comment-use-syntax (nth 8 (syntax-ppss))) + (setq found t))) + (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. -- 1.8.2