GNU bug report logs - #31984
26.1; indent-sexp doesn't indent expressions starting with #

Previous Next

Package: emacs;

Reported by: Gemini Lasswell <gazally <at> runbox.com>

Date: Tue, 26 Jun 2018 19:44:01 UTC

Severity: minor

Tags: confirmed, fixed, patch

Found in versions 26.1, 26.1.50

Fixed in version 26.2

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 31984 in the body.
You can then email your comments to 31984 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Tue, 26 Jun 2018 19:44:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gemini Lasswell <gazally <at> runbox.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Jun 2018 19:44:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gemini Lasswell <gazally <at> runbox.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1.50; IELM doesn't indent results printed with #
Date: Tue, 26 Jun 2018 12:42:36 -0700
When the result of evaluation in IELM is something with a printed
representation beginning with #, such as a record or char-table,
it is pretty-printed without indentation.

To reproduce, M-x ielm RET and then evaluate this:

(require 'cl-lib)
(cl-defstruct (foo) a)
(make-foo :a (lambda (x) (- 1 x)))

Result:

#s(foo :a
(lambda
(x)
(- 1 x)))

If you do the same thing in Emacs 25, this is the result:

[cl-struct-foo
 (lambda
   (x)
   (- 1 x))]

Here are two other examples which when evaluated in IELM print
results without indentation in Emacs 26 and with indentation in Emacs 25:

char-acronym-table

(let ((ht (make-hash-table)))
  (puthash 1 '(a b c) ht)
  ht)

Oddly, Emacs 26's IELM does indent the result of this one:

(symbol-function 'ielm-process)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Thu, 28 Jun 2018 02:02:02 GMT) Full text and rfc822 format available.

Message #8 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Gemini Lasswell <gazally <at> runbox.com>
Cc: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Wed, 27 Jun 2018 22:01:34 -0400
retitle 31984 26.1; indent-sexp doesn't indent expressions starting with #
found 31984 26.1
tags 31984 + confirmed
quit

Gemini Lasswell <gazally <at> runbox.com> writes:

> When the result of evaluation in IELM is something with a printed
> representation beginning with #, such as a record or char-table,
> it is pretty-printed without indentation.
>
> To reproduce, M-x ielm RET and then evaluate this:
>
> (require 'cl-lib)
> (cl-defstruct (foo) a)
> (make-foo :a (lambda (x) (- 1 x)))
>
> Result:
>
> #s(foo :a
> (lambda
> (x)
> (- 1 x)))

Which is because pp-buffer doesn't indent this, which is because
indent-sexp doesn't indent it, which is because indent-sexp now relies
on forward-sexp to find the end, and forward-sexp only goes over the
"#s".

Another example:

With point before the (foo), Emacs 25 indent-sexp turns this

(foo) (blah
etc)

into this

(foo) (blah
       etc)

Emacs 26 indent-sexp doesn't do anything from that position.  It's less
clear which is correct in that case, but restoring to the Emacs 25
behaviour would fix the #s(...) case as well.  Alternatively, we could
fix elisp sexp movement to handle such expressions, which we should
probably do anyway (see also Bug#15998).




Changed bug title to '26.1; indent-sexp doesn't indent expressions starting with #' from '26.1.50; IELM doesn't indent results printed with #' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 28 Jun 2018 02:02:02 GMT) Full text and rfc822 format available.

bug Marked as found in versions 26.1. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 28 Jun 2018 02:02:02 GMT) Full text and rfc822 format available.

Added tag(s) confirmed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 28 Jun 2018 02:02:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Thu, 19 Jul 2018 11:18:02 GMT) Full text and rfc822 format available.

Message #17 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Gemini Lasswell <gazally <at> runbox.com>
Cc: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Thu, 19 Jul 2018 07:16:52 -0400
[Message part 1 (text/plain, inline)]
tags 31984 + patch
quit

Noam Postavsky <npostavs <at> gmail.com> writes:

> With point before the (foo), Emacs 25 indent-sexp turns this
>
> (foo) (blah
> etc)
>
> into this
>
> (foo) (blah
>        etc)
>
> Emacs 26 indent-sexp doesn't do anything from that position.  It's less
> clear which is correct in that case, but restoring to the Emacs 25
> behaviour would fix the #s(...) case as well.  Alternatively, we could
> fix elisp sexp movement to handle such expressions, which we should
> probably do anyway (see also Bug#15998).

Probably Bug#15998 won't be fixed in Emacs 26, so here's a patch to make
indent-sexp indent the sexp spanning the end of line, like Emacs 25
does.

[0001-Fix-indent-sexp-of-s-.-Bug-31984.patch (text/x-diff, inline)]
From 3e206ed6c2c82ef3d147b3dece6dc65ffe1625a2 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Thu, 19 Jul 2018 06:40:54 -0400
Subject: [PATCH] Fix indent-sexp of #s(...) (Bug#31984)

* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Look for a sexp that
ends after the current line.
* test/lisp/emacs-lisp/lisp-mode-tests.el (indent-sexp-go): New test.
---
 lisp/emacs-lisp/lisp-mode.el            | 10 ++++++++--
 test/lisp/emacs-lisp/lisp-mode-tests.el | 12 ++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 3a03b56313..44b27236a9 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1199,8 +1199,14 @@ indent-sexp
     (setq endpos (copy-marker
                   (if endpos endpos
                     ;; Get error now if we don't have a complete sexp
-                    ;; after point.
-                    (save-excursion (forward-sexp 1) (point)))))
+                    ;; after point.  We actually look for a sexp which
+                    ;; ends after the current line so that we properly
+                    ;; indent things like #s(...).  This might not be
+                    ;; needed if Bug#15998 is fixed.
+                    (let ((eol (line-end-position)))
+                      (save-excursion (while (and (< (point) eol) (not (eobp)))
+                                        (forward-sexp 1))
+                                      (point))))))
     (save-excursion
       (while (let ((indent (lisp-indent-calc-next parse-state))
                    (ppss (lisp-indent-state-ppss parse-state)))
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index 8598d41978..0b052e9fc3 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -113,6 +113,18 @@ lisp-mode-tests--correctly-indented-sexp
       ;; we're indenting ends on the previous line.
       (should (equal (buffer-string) original)))))
 
+(ert-deftest indent-sexp-go ()
+  "Make sure `indent-sexp' doesn't stop after #s."
+  ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31984.
+  (with-temp-buffer
+    (emacs-lisp-mode)
+    (insert "#s(foo\nbar)\n")
+    (goto-char (point-min))
+    (indent-sexp)
+    (should (equal (buffer-string) "\
+#s(foo
+   bar)\n"))))
+
 (ert-deftest lisp-indent-region ()
   "Test basics of `lisp-indent-region'."
   (with-temp-buffer
-- 
2.11.0


Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 19 Jul 2018 11:18:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Thu, 19 Jul 2018 19:02:01 GMT) Full text and rfc822 format available.

Message #22 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Gemini Lasswell <gazally <at> runbox.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Thu, 19 Jul 2018 12:01:10 -0700
Noam Postavsky <npostavs <at> gmail.com> writes:

> Probably Bug#15998 won't be fixed in Emacs 26, so here's a patch to make
> indent-sexp indent the sexp spanning the end of line, like Emacs 25
> does.

I gave this patch a try and it worked well with everything I tried it
on, both in IELM and my new backtrace-mode.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Sun, 22 Jul 2018 01:31:01 GMT) Full text and rfc822 format available.

Message #25 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Gemini Lasswell <gazally <at> runbox.com>
Cc: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Sat, 21 Jul 2018 21:30:39 -0400
tags 31984 fixed
close 31984 26.2
quit

Gemini Lasswell <gazally <at> runbox.com> writes:

> Noam Postavsky <npostavs <at> gmail.com> writes:
>
>> Probably Bug#15998 won't be fixed in Emacs 26, so here's a patch to make
>> indent-sexp indent the sexp spanning the end of line, like Emacs 25
>> does.
>
> I gave this patch a try and it worked well with everything I tried it
> on, both in IELM and my new backtrace-mode.

Thanks for testing, I pushed to emacs-26.

[1: 1b4b96597c]: 2018-07-21 21:07:07 -0400
  Fix indent-sexp of #s(...) (Bug#31984)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1b4b96597c7868d9c24389d83089097a521206a5




Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 22 Jul 2018 01:31:03 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.2, send any further explanations to 31984 <at> debbugs.gnu.org and Gemini Lasswell <gazally <at> runbox.com> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 22 Jul 2018 01:31:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Thu, 26 Jul 2018 11:50:01 GMT) Full text and rfc822 format available.

Message #32 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Davor Rotim <rotim.davor <at> gmail.com>
To: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Thu, 26 Jul 2018 13:49:33 +0200
[Message part 1 (text/plain, inline)]
Hello,

this change seems to have broken Paredit, a quick recipe with Paredit
installed:

emacs -Q
M-x package-initialize
M-x enable-paredit-mode

Now just press ( repeatedly, it errors out on the 2nd inserted pair and any
other after that:

forward-sexp: Scan error: "Containing expression ends prematurely", 4, 5
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31984; Package emacs. (Sat, 28 Jul 2018 00:16:01 GMT) Full text and rfc822 format available.

Message #35 received at 31984 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Davor Rotim <rotim.davor <at> gmail.com>
Cc: 31984 <at> debbugs.gnu.org
Subject: Re: bug#31984: 26.1.50; IELM doesn't indent results printed with #
Date: Fri, 27 Jul 2018 20:15:30 -0400
Davor Rotim <rotim.davor <at> gmail.com> writes:

> emacs -Q
> M-x package-initialize
> M-x enable-paredit-mode
>
> Now just press ( repeatedly, it errors out on the 2nd inserted pair and any
> other after that:
>
> forward-sexp: Scan error: "Containing expression ends prematurely", 4, 5

Right, thanks for catching that, should be fixed now.

[1: 8579105393]: 2018-07-27 19:41:39 -0400
  Don't fail to indent-sexp before a full sexp (Bug#31984)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=857910539313c0f2d89fe5626a41f1abe6c33ca7




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 25 Aug 2018 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 296 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.