From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp Date: Thu, 11 May 2017 18:35:21 -0400 Message-ID: <87d1bfja3a.fsf@users.sourceforge.net> References: <87k25n60h2.fsf@firefly> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1494542058 7540 195.159.176.226 (11 May 2017 22:34:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 11 May 2017 22:34:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 26878@debbugs.gnu.org To: Oleh Krehel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 12 00:34:13 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 1d8wey-0001o8-HM for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 May 2017 00:34:12 +0200 Original-Received: from localhost ([::1]:50532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8wf2-0007vT-Fn for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 May 2017 18:34:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8wet-0007vC-Mg for bug-gnu-emacs@gnu.org; Thu, 11 May 2017 18:34:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8weo-0001i3-Ps for bug-gnu-emacs@gnu.org; Thu, 11 May 2017 18:34:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36669) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8weo-0001hy-MD for bug-gnu-emacs@gnu.org; Thu, 11 May 2017 18:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d8weo-0004N4-Ba; Thu, 11 May 2017 18:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, Noam Postavsky Resent-Date: Thu, 11 May 2017 22:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26878 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26878-submit@debbugs.gnu.org id=B26878.149454203716789 (code B ref 26878); Thu, 11 May 2017 22:34:02 +0000 Original-Received: (at 26878) by debbugs.gnu.org; 11 May 2017 22:33:57 +0000 Original-Received: from localhost ([127.0.0.1]:39346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8wei-0004Me-R1 for submit@debbugs.gnu.org; Thu, 11 May 2017 18:33:57 -0400 Original-Received: from mail-it0-f45.google.com ([209.85.214.45]:37721) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8weg-0004ML-P4; Thu, 11 May 2017 18:33:55 -0400 Original-Received: by mail-it0-f45.google.com with SMTP id g126so28323405ith.0; Thu, 11 May 2017 15:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=GHJUs3CYHZ1emZ0ng0k+TRd643yJBD6SnAjAIApq74w=; b=ladI/Wwcy9OlNQhRnrxVgT3SdqyUSKhn+4nC8NN63Gu+cXDenFguuZxLwk8AD2RId/ 2uJm/zk14a8btnaE5rS3suOOIPUGzpZ2GDNt4Dcrvtb0HpC8ctG72XQdG/0V2Zk9mQiz CHdiCXsewwBfjW5r3MUmfpt14wNgBvP53csP/EIgYfPnev5yCLhV6EUvazwT1LJpRSYB lIVPgeSGnv0SYFfpoC+R50R7ycLfQM52YAJ1AruNheR10Rz771SvOOrwuTIN40tSaIm/ x11Mxwah6FxUazFYSxqnLnAfd2oZXXr3uiXiPdh2rZrCHgrdFVkTRbe+PA8BpgISrvHl mypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=GHJUs3CYHZ1emZ0ng0k+TRd643yJBD6SnAjAIApq74w=; b=iWq4o1cb06zFNigrWgiMy0+YHgPKOHZWNnc79lOR9YCeADVQpwdVhHV5fgHG7FAEro xzhVYizvTIkuQP720H0ZJT7TaHAV4IWRllCfa49xkSG4IeKk7mSfbCAOIGQFzTmqkXgE +fLeXD4GewkLe3iMYvtcrY3JwVSLFrnVk0bNNXyNyFI8MrmGMW/0qajI4VdSItJyPr6R QnWnKN8nJUiLsMIcZnT33MwPuKTNaGboWPUh4DKoNfbTKfIbg5KXRl1svw+/m9t6ZZRa V1KU5td6g9T1sKjcixMGIq2ZtpCGr5emkFtY5rjOfEkD1GtskiWVZwkAVlUIQ+mBpMAl ylqQ== X-Gm-Message-State: AODbwcDqaMn3zodzH6EaoO3iP3/PpxU/MfWUzWA8ZsxqepadJvNJp0CO T9uwtoJHyO3pTw== X-Received: by 10.36.34.135 with SMTP id o129mr432216ito.70.1494542029075; Thu, 11 May 2017 15:33:49 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id h76sm844146ith.24.2017.05.11.15.33.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 May 2017 15:33:48 -0700 (PDT) In-Reply-To: <87k25n60h2.fsf@firefly> (Oleh Krehel's message of "Thu, 11 May 2017 14:29:13 +0200") 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:132448 Archived-At: --=-=-= Content-Type: text/plain severity 26878 minor tags 26878 patch quit Oleh Krehel writes: > Example code for *scratch*, place the point at | > > (a |() > ) > > Call `indent-sexp' to end up with: > > (a |() > ) > > In stable Emacs, `indent-sexp' would produce no change, since it applies > only to the current sexp, the empty list in this case. Oops, here's a patch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Make-sure-indent-sexp-stops-at-end-of-sexp-Bug-26.patch Content-Description: patch >From 0c2ec7c634d9426d435bf783240eba2073140ef0 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 11 May 2017 18:12:40 -0400 Subject: [PATCH v1] Make sure indent-sexp stops at end of sexp (Bug#26878) * lisp/emacs-lisp/lisp-mode.el (indent-sexp): Check endpos before indenting. * test/lisp/emacs-lisp/lisp-mode-tests.el (indent-sexp-stop): New test. --- lisp/emacs-lisp/lisp-mode.el | 33 ++++++++++++++++++--------------- test/lisp/emacs-lisp/lisp-mode-tests.el | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 2131597758..0b1ca3f2f9 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -1185,21 +1185,24 @@ indent-sexp ;; after point. (save-excursion (forward-sexp 1) (point))))) (save-excursion - (while (< (point) endpos) - (let ((indent (lisp-indent-calc-next parse-state))) - ;; If the line contains a comment indent it now with - ;; `indent-for-comment'. - (when (nth 4 (lisp-indent-state-ppss parse-state)) - (save-excursion - (goto-char (lisp-indent-state-ppss-point parse-state)) - (indent-for-comment) - (setf (lisp-indent-state-ppss-point parse-state) - (line-end-position)))) - ;; But not if the line is blank, or just a comment (we - ;; already called `indent-for-comment' above). - (skip-chars-forward " \t") - (unless (or (eolp) (eq (char-syntax (char-after)) ?<) (not indent)) - (indent-line-to indent))))) + (while (let ((indent (lisp-indent-calc-next parse-state)) + (ppss (lisp-indent-state-ppss parse-state))) + ;; If the line contains a comment indent it now with + ;; `indent-for-comment'. + (when (and (nth 4 ppss) (<= (nth 8 ppss) endpos)) + (save-excursion + (goto-char (lisp-indent-state-ppss-point parse-state)) + (indent-for-comment) + (setf (lisp-indent-state-ppss-point parse-state) + (line-end-position)))) + (when (< (point) endpos) + ;; Indent the next line, unless it's blank, or just a + ;; comment (we will `indent-for-comment' the latter). + (skip-chars-forward " \t") + (unless (or (eolp) (not indent) + (eq (char-syntax (char-after)) ?<)) + (indent-line-to indent)) + t)))) (move-marker endpos nil))) (defun indent-pp-sexp (&optional arg) diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index 1f78eb3010..f2fe7a6cf4 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el @@ -99,6 +99,20 @@ lisp-mode-tests--correctly-indented-sexp (indent-sexp) (should (equal (buffer-string) correct))))) +(ert-deftest indent-sexp-stop () + "Make sure `indent-sexp' stops at the end of the sexp." + ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26878. + (with-temp-buffer + (emacs-lisp-mode) + (insert "(a ()\n)") + (let ((original (buffer-string))) + (search-backward "a ") + (goto-char (match-end 0)) + (indent-sexp) + ;; The final paren should not be indented, because the sexp + ;; we're indenting ends on the previous line. + (should (equal (buffer-string) original))))) + (ert-deftest lisp-indent-region () "Test basics of `lisp-indent-region'." (with-temp-buffer -- 2.11.1 --=-=-=--