unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp
@ 2017-05-11 12:29 Oleh Krehel
  2017-05-11 22:35 ` npostavs
  0 siblings, 1 reply; 4+ messages in thread
From: Oleh Krehel @ 2017-05-11 12:29 UTC (permalink / raw)
  To: 26878

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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp
  2017-05-11 12:29 bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp Oleh Krehel
@ 2017-05-11 22:35 ` npostavs
  2017-05-15 12:26   ` Oleh Krehel
  0 siblings, 1 reply; 4+ messages in thread
From: npostavs @ 2017-05-11 22:35 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 26878

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

severity 26878 minor
tags 26878 patch
quit

Oleh Krehel <oleh@oremacs.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3746 bytes --]

From 0c2ec7c634d9426d435bf783240eba2073140ef0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp
  2017-05-11 22:35 ` npostavs
@ 2017-05-15 12:26   ` Oleh Krehel
  2017-05-16  3:05     ` npostavs
  0 siblings, 1 reply; 4+ messages in thread
From: Oleh Krehel @ 2017-05-15 12:26 UTC (permalink / raw)
  To: npostavs; +Cc: 26878

npostavs@users.sourceforge.net writes:

> Oops, here's a patch.

Thanks, I confirm the patch works. Please apply when you can.

Also, try to keep the bug issuer in CC when replying to a bug. I had to
check debbugs-gnu to see if there was a reply.

regards,
Oleh





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp
  2017-05-15 12:26   ` Oleh Krehel
@ 2017-05-16  3:05     ` npostavs
  0 siblings, 0 replies; 4+ messages in thread
From: npostavs @ 2017-05-16  3:05 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 26878

tags 26878 fixed
close 26878 
quit

Oleh Krehel <oleh@oremacs.com> writes:

> Thanks, I confirm the patch works. Please apply when you can.

Pushed to master [1: 750f0e2e79].

[1: 750f0e2e79]: 2017-05-15 22:58:17 -0400
  Make sure indent-sexp stops at end of sexp (Bug#26878)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=750f0e2e79e1bdc3246b07aa3219cab34ebde6e7

> Also, try to keep the bug issuer in CC when replying to a bug. I had to
> check debbugs-gnu to see if there was a reply.

Hmm, actually you were on CC, but your mail bounced.  Let's see if it
works this time...

    ** Message not delivered **

    Your message couldn't be delivered to oleh@oremacs.com because the remote server is misconfigured. See technical details below for more information.

    The response from the remote server was:
    550 5.7.1 <oleh@oremacs.com>: Relay access denied

    Final-Recipient: rfc822; oleh@oremacs.com
    Action: failed
    Status: 5.7.1
    Remote-MTA: dns; eforward1.registrar-servers.com. (162.255.118.61, the server
     for the domain oremacs.com.)
    Diagnostic-Code: smtp; 550 5.7.1 <oleh@oremacs.com>: Relay access denied
    Last-Attempt-Date: Thu, 11 May 2017 15:33:50 -0700 (PDT)





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-16  3:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 12:29 bug#26878: 26.0.50; indent-sexp regression: applies beyond the current sexp Oleh Krehel
2017-05-11 22:35 ` npostavs
2017-05-15 12:26   ` Oleh Krehel
2017-05-16  3:05     ` npostavs

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).