From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "N. Raghavendra" Newsgroups: gmane.emacs.bugs Subject: bug#28428: comment-search-backward with no comments Date: Tue, 12 Sep 2017 04:07:35 +0530 Message-ID: <87377seua8.fsf@ailuros> Reply-To: "N. Raghavendra" NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1505169505 7343 195.159.176.226 (11 Sep 2017 22:38:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Sep 2017 22:38:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: 28428@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 12 00:38:17 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drXLB-0000z9-Jt for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Sep 2017 00:38:05 +0200 Original-Received: from localhost ([::1]:60914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drXLI-0002XV-PP for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Sep 2017 18:38:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drXLC-0002Tt-19 for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:38:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drXL8-00032e-U3 for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:38:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53818) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1drXL8-00032S-Pf for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1drXL8-0001hW-J8 for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "N. Raghavendra" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Sep 2017 22:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28428 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.15051694786526 (code B ref -1); Mon, 11 Sep 2017 22:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Sep 2017 22:37:58 +0000 Original-Received: from localhost ([127.0.0.1]:34266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drXL3-0001hB-TO for submit@debbugs.gnu.org; Mon, 11 Sep 2017 18:37:58 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43928) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drXL1-0001gu-M4 for submit@debbugs.gnu.org; Mon, 11 Sep 2017 18:37:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drXKv-0002zJ-Dz for submit@debbugs.gnu.org; Mon, 11 Sep 2017 18:37:50 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:44937) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drXKv-0002zF-AD for submit@debbugs.gnu.org; Mon, 11 Sep 2017 18:37:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drXKt-0002Ny-Sj for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:37:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drXKq-0002y9-Pf for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:37:47 -0400 Original-Received: from sub5.mail.dreamhost.com ([208.113.200.129]:56113 helo=homiemail-a83.g.dreamhost.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drXKq-0002xG-Fg for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 18:37:44 -0400 Original-Received: from homiemail-a83.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a83.g.dreamhost.com (Postfix) with ESMTP id 872A68018C37 for ; Mon, 11 Sep 2017 15:37:41 -0700 (PDT) Original-Received: from retrotexts.net (www.hri.res.in [220.227.103.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: raghu@retrotexts.net) by homiemail-a83.g.dreamhost.com (Postfix) with ESMTPSA id 330B48018C2E for ; Mon, 11 Sep 2017 15:37:41 -0700 (PDT) Original-Received: by retrotexts.net (Postfix, from userid 1000) id 8416924025AB; Tue, 12 Sep 2017 04:07:35 +0530 (IST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] 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.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:136815 Archived-At: --=-=-= Content-Type: text/plain I am using Emacs 26.0.50. In the cases that I tried, when there is no comment in the portion of the buffer between the search limit and point, `comment-search-backward' does not move point to the search limit before raising an error. This behaviour contradicts its docstring. My message to emacs-devel about this is at http://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00193.html Attached are a patch that seems to fix the problem, and a file containing a test. Running the test without the change in the patch fails, and passes with the change: $ git checkout master $ emacs -Q -batch -l lisp/newcomment.el -l /tmp/test.el \ -f ert-run-tests-batch-and-exit ---------------------------------------------------------------------- (ert-test-failed ((should (= (point) limit)) :form (= 70 41) :value nil)) FAILED 1/1 test-comment-search-backward-absent ---------------------------------------------------------------------- $ git checkout test-comment-search-forward-absent $ emacs -Q -batch -l lisp/newcomment.el -l /tmp/test.el \ -f ert-run-tests-batch-and-exit ---------------------------------------------------------------------- Running 1 tests (2017-09-12 03:31:48+0530) passed 1/1 test-comment-search-backward-absent ---------------------------------------------------------------------- Raghu. -- N. Raghavendra , http://www.retrotexts.net/ Harish-Chandra Research Institute, http://www.hri.res.in/ --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-comment-search-backword-move-point-when-there-is-no-comment.patch >From eb8e32c6fe4a3d08be8b856b3ff4a300a2e69d4b Mon Sep 17 00:00:00 2001 From: "N. Raghavendra" Date: Tue, 12 Sep 2017 01:41:16 +0530 Subject: [PATCH] comment-search-backword: move point when there is no comment * lisp/newcomment.el (comment-search-backward): Move point to LIMIT when there is no comment between LIMIT and point. --- lisp/newcomment.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 8772b523..d849fc1 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -525,7 +525,9 @@ comment-search-backward ;; 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")) + (progn + (goto-char limit) + (unless noerror (error "No comment"))) (beginning-of-line) (let* ((end (match-end 0)) (cs (comment-search-forward end t)) -- 2.7.4 --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=test.el Content-Transfer-Encoding: quoted-printable (ert-deftest test-comment-search-backward-absent () "Test `comment-search-backward' when there is no comment in context. Check that when there is no comment in the portion of the buffer between the search limit and point, it moves point to the search limit and raises an error." (with-temp-buffer (emacs-lisp-mode) (comment-normalize-vars) (insert "(require 'foo) \(bar) ; first comment ;; second comment \(provide 'baz)") (let ((limit (save-excursion (search-backward "second")))) (should (equal (should-error (comment-search-backward limit)) '(error "No comment"))) (should (=3D (point) limit))))) --=-=-=--