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: Wed, 15 May 2013 19:33:23 +0800 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1368617648 1569 80.91.229.3 (15 May 2013 11:34:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 May 2013 11:34:08 +0000 (UTC) To: 14303@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 15 13:34:07 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 1UcZyA-0006LP-Ps for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2013 13:34:07 +0200 Original-Received: from localhost ([::1]:47580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcZy7-0006pG-3i for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2013 07:34:03 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcZy3-0006pB-Gs for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 07:34:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcZy2-00005g-8K for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 07:33:59 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcZy2-00005T-4r for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 07:33:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UcZy5-00076x-Qm for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 07:34:01 -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: Wed, 15 May 2013 11:34:01 +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.136861764027327 (code B ref 14303); Wed, 15 May 2013 11:34:01 +0000 Original-Received: (at 14303) by debbugs.gnu.org; 15 May 2013 11:34:00 +0000 Original-Received: from localhost ([127.0.0.1]:45425 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UcZy3-00076g-Fo for submit@debbugs.gnu.org; Wed, 15 May 2013 07:33:59 -0400 Original-Received: from mail-pa0-f54.google.com ([209.85.220.54]:50807) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UcZy1-00076L-0B for 14303@debbugs.gnu.org; Wed, 15 May 2013 07:33:58 -0400 Original-Received: by mail-pa0-f54.google.com with SMTP id kx1so1417485pab.41 for <14303@debbugs.gnu.org>; Wed, 15 May 2013 04:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:in-reply-to:references:user-agent :face:date:message-id:mime-version:content-type; bh=5EuVG8fCJjJXbshF72HfLEjynGl3y3X3APu2/LJb9SI=; b=D0r/sejCFjVzC2vpJK8M619JtsfGBM70IaY8QxmG4FdqLEI9usPT7k4Ql/tzruD2UU v5ksfocmOTtDGYy3jta3DSSupvyJrCArz7yJjjyjOYUJa8nPN3JbLoY3P1/xnq3i09eo c3z1gLWiCsENM8NeQnBod+idLTKv18EJHoOO8QueUkFC++LNCm6WNbWXnXC4nW00qrVh TIep+xZrmRbBJbL/swqGGFR+yt/q8uWdl4v7TfvGb5+jOmDiene2uKseTMyRpBF03NKr g7+9cOthkcXCA7dbj1nYAyzTaZieqhEAYCLCadioI0Xmhjz6mvU62WNjMS8oI3s1i8rj dXBw== X-Received: by 10.68.226.106 with SMTP id rr10mr37996607pbc.127.1368617626653; Wed, 15 May 2013 04:33:46 -0700 (PDT) Original-Received: from Zeuss-MacBook.local ([119.161.133.157]) by mx.google.com with ESMTPSA id xu10sm3071379pab.3.2013.05.15.04.33.41 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 15 May 2013 04:33:46 -0700 (PDT) In-Reply-To: (Leo Liu's message of "Mon, 29 Apr 2013 21:27:35 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (OS X 10.8.3) 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= 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:74294 Archived-At: On 2013-04-29 21:27 +0800, Leo Liu wrote: > Open a new buffer in octave-mode and insert the following line: > > x="#abc" > > Move point to the end of the inserted line and > > M-: (comment-search-backward) > > this moves point inside the string. So it is no longer fine for comment-search-backward to end up in a comment or string any more. How about something like this? diff --git a/lisp/newcomment.el b/lisp/newcomment.el index d55feaa3..65182c1b 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -485,27 +485,25 @@ (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)) + (or (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.