From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#35286: 26.2; indent-sexp broken Date: Mon, 15 Apr 2019 19:57:55 -0400 Message-ID: <87sguizurg.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="105483"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 35286@debbugs.gnu.org To: Leo Liu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 16 02:00:04 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGBW7-000RJY-Lc for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Apr 2019 02:00:03 +0200 Original-Received: from localhost ([127.0.0.1]:56962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGBW6-00014K-Mq for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Apr 2019 20:00:02 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGBV9-0000VO-Ia for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2019 19:59:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGBV8-00051N-DC for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2019 19:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50518) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hGBV8-00050u-4B for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2019 19:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hGBV7-0000kM-S9 for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2019 19:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Apr 2019 23:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35286 X-GNU-PR-Package: emacs Original-Received: via spool by 35286-submit@debbugs.gnu.org id=B35286.15553726862806 (code B ref 35286); Mon, 15 Apr 2019 23:59:01 +0000 Original-Received: (at 35286) by debbugs.gnu.org; 15 Apr 2019 23:58:06 +0000 Original-Received: from localhost ([127.0.0.1]:35829 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGBUD-0000j7-V7 for submit@debbugs.gnu.org; Mon, 15 Apr 2019 19:58:06 -0400 Original-Received: from mail-qt1-f178.google.com ([209.85.160.178]:38008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGBUC-0000iY-93; Mon, 15 Apr 2019 19:58:04 -0400 Original-Received: by mail-qt1-f178.google.com with SMTP id d13so21366201qth.5; Mon, 15 Apr 2019 16:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=NMp6jvEYNJlGYF4K4dCMLNepFe84Wxq4aWnV7ZVlcDc=; b=qENlCFAldTRwq9QITEXCtE5U6zUAiFS2b96UqZVvi+Ismelliq7PYxANS03Z3dbS/w OzP+80qqLWUh5OYT5HJdTpfyVEbuaOzH6a5NtIzfKCkeAXEh54KJ35FvQ9Z8g51Ar/aU pQ0Zy/5z3t4GC+xCZOm8VqcDyEWllnpr5DgYpNGRMEI2ZcXqKw/YbxPogOBrPJk0pJ7T GdvK8UNuZ4vC/XFFMRx/vVhjZfV6g67Q75qpfDc9TtE3uE+kDr8UeTsDgu9e7y6H7oRf IytA8XGQOyTa/7/3lP9gzTEEg5yMTaPq4T4QqLnJ7BERyMXgkZ+Gikavdw4kpfDqqBF0 1z0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=NMp6jvEYNJlGYF4K4dCMLNepFe84Wxq4aWnV7ZVlcDc=; b=NxedKsXlnHXcAtsAy/lB8Chy89JFIY3ATiRm8i2yL3i08slTZncLqhAm5c94UfjUec R7wo0ASAoL7vpK+xwHYGIRjoR/FBFQyF4Yvk7XAlGOMqtbINvbzFnqEbkhN5VPAvh/ws K/t7nICfMJyx7msdNUCYSiQpqyA2qbtfZJpqaK4uhQwzZ00TqJ3emLfHxDnFF6Q6y8Gi J/Txrr+TxsoljYk+p9Mh16n21GCAIvDPhG46rCgdoT/GUFRgrVCgDgEILFiHGtcFQUka ZJw6J4bQ5uQFKujMiNb/nMazo/P1ieFrgFMY8pV7sryfXvfiZ2RXO7Gicde8PWXiSYLf K8qA== X-Gm-Message-State: APjAAAWA9WkRJ1eslhpGTkrqeRn3NOcsi5jbVHCOao+ww9HTD44Okjjs ua9UxFLGAKb62QRNUPC7E0i9rMZ2 X-Google-Smtp-Source: APXvYqwClhPpck3OdQ0DZz7C0E3MDeW7oPJse+WNHv8fOxo6g6mjARAdbm4uqMZvJ4ipLRoIqHhMWQ== X-Received: by 2002:a0c:af62:: with SMTP id j31mr65222890qvc.150.1555372678364; Mon, 15 Apr 2019 16:57:58 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id d34sm36135847qta.18.2019.04.15.16.57.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 16:57:56 -0700 (PDT) In-Reply-To: (Leo Liu's message of "Mon, 15 Apr 2019 20:14:58 +0800") 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: 209.51.188.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:157685 Archived-At: --=-=-= Content-Type: text/plain tags 35286 + patch quit Leo Liu writes: > The bug is caused by the following unsafe part of indent-sexp introduced > in 26.2: > > (save-excursion > (let ((eol (line-end-position))) > (forward-sexp 1) > (condition-case () > (while (and (< (point) eol) (not (eobp))) > (forward-sexp 1)) > (scan-error nil))) > (point)) > > which can easily include two or more sexps after point. This looks like > a major breakage. I put that code there because Emacs 25 and earlier also indents more than one sexps after point in some cases. The regression is that the Emacs 26 code gets confused by comments at the end of line. Here's a patch for emacs-26 to fix this: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-indent-sexp-confusion-over-eol-comments-Bug-3528.patch Content-Description: patch >From 7678458e5431e3b5a365343ec172cc75cc41ffb7 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Mon, 15 Apr 2019 18:49:57 -0400 Subject: [PATCH] Fix indent-sexp confusion over eol comments (Bug#35286) * lisp/emacs-lisp/lisp-mode.el (indent-sexp): Skip over comments before checking for end of line. --- lisp/emacs-lisp/lisp-mode.el | 6 +++++- test/lisp/emacs-lisp/lisp-mode-tests.el | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 57f57175c5..a0caaf7475 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -1212,7 +1212,11 @@ (defun indent-sexp (&optional endpos) ;; indent things like #s(...). This might not ;; be needed if Bug#15998 is fixed. (condition-case () - (while (and (< (point) eol) (not (eobp))) + (while (progn (while (and (forward-comment 1) + (if (< (point) eol) t + (goto-char eol) + nil))) + (and (< (point) eol) (not (eobp)))) (forward-sexp 1)) ;; But don't signal an error for incomplete ;; sexps following the first complete sexp diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index a6370742ab..3782bad315 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el @@ -136,6 +136,18 @@ (ert-deftest indent-sexp-cant-go () (indent-sexp) (should (equal (buffer-string) "(())")))) +(ert-deftest indent-sexp-stop-before-eol-comment () + "`indent-sexp' shouldn't look for more sexps after an eol comment." + ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35286. + (with-temp-buffer + (emacs-lisp-mode) + (let ((str "() ;;\n x")) + (insert str) + (goto-char (point-min)) + (indent-sexp) + ;; The "x" is in the next sexp, so it shouldn't get indented. + (should (equal (buffer-string) str))))) + (ert-deftest lisp-indent-region () "Test basics of `lisp-indent-region'." (with-temp-buffer -- 2.11.0 --=-=-=--