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: Wed, 15 May 2013 18:13:47 +0200 Message-ID: <5193B43B.8070007@easy-emacs.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1368634360 29982 80.91.229.3 (15 May 2013 16:12:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 May 2013 16:12:40 +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 18:12:38 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 1UceJi-0006Ih-HY for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2013 18:12:38 +0200 Original-Received: from localhost ([::1]:57039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceJh-0006F4-Mz for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2013 12:12:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceJ8-000508-7W for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:12:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UceJ3-0007vL-Gp for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:12:02 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57826) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceJ3-0007v3-CG for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:11:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UceJ8-00017p-7V for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:12: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: Wed, 15 May 2013 16:12: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: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13686343134310 (code B ref -1); Wed, 15 May 2013 16:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 May 2013 16:11:53 +0000 Original-Received: from localhost ([127.0.0.1]:46182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UceIy-00017S-F2 for submit@debbugs.gnu.org; Wed, 15 May 2013 12:11:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41282) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UceIv-00017E-8C for submit@debbugs.gnu.org; Wed, 15 May 2013 12:11:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UceIf-0007qW-Kv for submit@debbugs.gnu.org; Wed, 15 May 2013 12:11:38 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:36001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceIf-0007qQ-HZ for submit@debbugs.gnu.org; Wed, 15 May 2013 12:11:33 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceIa-0003WY-Mv for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:11:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UceIU-0007oL-VJ for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:11:28 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.171]:58118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UceIU-0007nz-Mc for bug-gnu-emacs@gnu.org; Wed, 15 May 2013 12:11:22 -0400 Original-Received: from [192.168.178.21] (brln-4db9f307.pool.mediaWays.net [77.185.243.7]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0Mbo1J-1Uv93N0rcz-00J4eo; Wed, 15 May 2013 18:11:20 +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:eDOCsN2reG5FiZ9mhl66tJdCqejkY/KABDj/J8gMzuH HZ0SRgyrKy1swbWnBBSl1eObPkEOVdRnNV6Y3WDSu1aoUJVr/r oeYhbdZ3UN0jKGky/obFfG2fNfo9MSTkdpWMFgUbcnadGextpF qLAXKzANjTuMaYP/3YVB4L990d3+Gb/ffVIPh+k0peqxcmxvya ibAzPRVjQ3ab0rhNWfsz5977VzdfWcdk1wp7O1UIMUxulPqX/s kjlmQiV9APQJkvd1C27Sa7Axgzy0LTfPa0ZjrFFYnr+8vEei4v 0diZXQb4/w1fS8vlvKcff7yeMkNgQsObnnUrVw4h5iQ4CM2dvP jgAyN//feHNNDIcPmR9nfALfXetrpbUJwmXizRl8t X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:74298 Archived-At: Am 15.05.2013 13:33, schrieb Leo Liu: > 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. > > > > syntax-ppss is reliable, while re-search-backward comment-start-skip might stop inside a string etc. backward-line, end-of-line if nt4 and nth8, goto char nth8 that's nearly all as done consider limit of search, sure. Watching with interest, Andreas