GNU bug report logs - #27306
Regression: Emacs Lisp Indentation

Previous Next

Package: emacs;

Reported by: Alexander Shukaev <emacs <at> Alexander.Shukaev.name>

Date: Sat, 10 Jun 2017 13:00:02 UTC

Severity: normal

Tags: fixed, patch

Done: npostavs <at> users.sourceforge.net

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 27306 in the body.
You can then email your comments to 27306 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#27306; Package emacs. (Sat, 10 Jun 2017 13:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alexander Shukaev <emacs <at> Alexander.Shukaev.name>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 10 Jun 2017 13:00:02 GMT) Full text and rfc822 format available.

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

From: Alexander Shukaev <emacs <at> Alexander.Shukaev.name>
To: bug-gnu-emacs <at> gnu.org
Subject: Regression: Emacs Lisp Indentation
Date: Sat, 10 Jun 2017 14:59:01 +0200
Hey,

In Emacs 25 series, the following snippet is indented as follows

  (user-error "Unexpected initialization file: `%s'
Expected initialization file: `%s'"
              (abbreviate-file-name user-init-file)
              (abbreviate-file-name this-init-file))

In Emacs 26 series, a call to `indent-region' changes the above 
indentation to

  (user-error "Unexpected initialization file: `%s'
Expected initialization file: `%s'"
   (abbreviate-file-name user-init-file)
   (abbreviate-file-name this-init-file))

which appears wrong to me.  Please, take a look at this.  Thank you.

Kind regards,
Alexander




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27306; Package emacs. (Sat, 10 Jun 2017 15:33:02 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Alexander Shukaev <emacs <at> Alexander.Shukaev.name>
Cc: 27306 <at> debbugs.gnu.org
Subject: Re: bug#27306: Regression: Emacs Lisp Indentation
Date: Sat, 10 Jun 2017 11:33:44 -0400
[Message part 1 (text/plain, inline)]
tags 27306 patch
quit

Alexander Shukaev <emacs <at> Alexander.Shukaev.name> writes:

> In Emacs 26 series, a call to `indent-region' changes the above
> indentation to
>
>   (user-error "Unexpected initialization file: `%s'
> Expected initialization file: `%s'"
>    (abbreviate-file-name user-init-file)
>    (abbreviate-file-name this-init-file))
>
> which appears wrong to me.  Please, take a look at this.  Thank you.

Thanks for reporting, here's a patch:

[v1-0001-Fix-wrong-indentation-after-string-literal-Bug-27.patch (text/x-diff, inline)]
From 9e5c05a5cff6ab4eea5667792cf277c020b95426 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sat, 10 Jun 2017 09:50:48 -0400
Subject: [PATCH v1] Fix wrong indentation after string literal (Bug#27306)

* lisp/emacs-lisp/lisp-mode.el (lisp-indent-state)
(lisp-indent-calc-next): Remove `depth' field, use (car ppss) instead.
* test/lisp/emacs-lisp/lisp-mode-tests.el
(lisp-indent-region-after-string-literal): New test.
---
 lisp/emacs-lisp/lisp-mode.el            | 27 +++++++++++++--------------
 test/lisp/emacs-lisp/lisp-mode-tests.el | 13 +++++++++++++
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 1e38d44e1b..59db00d5f9 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -773,11 +773,9 @@ (cl-defstruct (lisp-indent-state
                (:constructor lisp-indent-initial-state
                              (&aux (ppss (lisp-ppss))
                                    (ppss-point (point))
-                                   (depth (car ppss))
-                                   (stack (make-list (1+ depth) nil)))))
+                                   (stack (make-list (1+ (car ppss)) nil)))))
   stack ;; Cached indentation, per depth.
   ppss
-  depth
   ppss-point)
 
 (defun lisp-indent-calc-next (state)
@@ -785,9 +783,11 @@ (defun lisp-indent-calc-next (state)
 STATE is updated by side effect, the first state should be
 created by `lisp-indent-initial-state'.  This function may move
 by more than one line to cross a string literal."
-  (pcase-let (((cl-struct lisp-indent-state
-                          (stack indent-stack) ppss depth ppss-point)
-               state))
+  (pcase-let* (((cl-struct lisp-indent-state
+                           (stack indent-stack) ppss ppss-point)
+                state)
+               (indent-depth (car ppss)) ; Corresponding to indent-stack.
+               (depth indent-depth))
     ;; Parse this line so we can learn the state to indent the
     ;; next line.
     (while (let ((last-sexp (nth 2 ppss)))
@@ -799,22 +799,22 @@ (defun lisp-indent-calc-next (state)
              (if (and (not (nth 2 ppss)) (= depth (car ppss)))
                  (setf (nth 2 ppss) last-sexp)
                (setq last-sexp (nth 2 ppss)))
+             (setq depth (car ppss))
              ;; Skip over newlines within strings.
              (nth 3 ppss))
       (let ((string-start (nth 8 ppss)))
-       (setq ppss (parse-partial-sexp (point) (point-max)
-                                      nil nil ppss 'syntax-table))
-       (setf (nth 2 ppss) string-start)) ; Finished a complete string.
+        (setq ppss (parse-partial-sexp (point) (point-max)
+                                       nil nil ppss 'syntax-table))
+        (setf (nth 2 ppss) string-start) ; Finished a complete string.
+        (setq depth (car ppss)))
       (setq ppss-point (point)))
     (setq ppss-point (point))
-    (let* ((next-depth (car ppss))
-           (depth-delta (- next-depth depth)))
+    (let* ((depth-delta (- depth indent-depth)))
       (cond ((< depth-delta 0)
              (setq indent-stack (nthcdr (- depth-delta) indent-stack)))
             ((> depth-delta 0)
              (setq indent-stack (nconc (make-list depth-delta nil)
-                                       indent-stack))))
-      (setq depth next-depth))
+                                       indent-stack)))))
     (prog1
         (let (indent)
           (cond ((= (forward-line 1) 1) nil)
@@ -826,7 +826,6 @@ (defun lisp-indent-calc-next (state)
                 ;; This only happens if we're in a string.
                 (t (error "This shouldn't happen"))))
       (setf (lisp-indent-state-stack state) indent-stack)
-      (setf (lisp-indent-state-depth state) depth)
       (setf (lisp-indent-state-ppss-point state) ppss-point)
       (setf (lisp-indent-state-ppss state) ppss))))
 
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index f2fe7a6cf4..582041cfc2 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -185,6 +185,19 @@ (ert-deftest lisp-indent-region-in-sexp ()
       (indent-region (point) (point-max))
       (should (equal (buffer-string) correct)))))
 
+(ert-deftest lisp-indent-region-after-string-literal ()
+  (with-temp-buffer
+    (insert "\
+\(user-error \"Unexpected initialization file: `%s'
+Expected initialization file: `%s'\"
+            (abbreviate-file-name user-init-file)
+            (abbreviate-file-name this-init-file))")
+    (let ((indent-tabs-mode nil)
+          (correct (buffer-string)))
+      (emacs-lisp-mode)
+      (indent-region (point-min) (point-max))
+      (should (equal (buffer-string) correct)))))
+
 
 (provide 'lisp-mode-tests)
 ;;; lisp-mode-tests.el ends here
-- 
2.11.1


Added tag(s) patch. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 10 Jun 2017 15:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27306; Package emacs. (Tue, 13 Jun 2017 11:27:02 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Alexander Shukaev <emacs <at> Alexander.Shukaev.name>
Cc: 27306 <at> debbugs.gnu.org
Subject: Re: bug#27306: Regression: Emacs Lisp Indentation
Date: Tue, 13 Jun 2017 07:27:39 -0400
tags 27306 fixed
close 27306 
quit

npostavs <at> users.sourceforge.net writes:

> Thanks for reporting, here's a patch:

Pushed to master [1: cc8aa484cd].

[1: cc8aa484cd]: 2017-06-13 07:19:12 -0400
  Fix wrong indentation after string literal (Bug#27306)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=cc8aa484cdab6b2f33a8c95a5778193c762412b9




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 13 Jun 2017 11:27:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 27306 <at> debbugs.gnu.org and Alexander Shukaev <emacs <at> Alexander.Shukaev.name> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 13 Jun 2017 11:27:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27306; Package emacs. (Fri, 16 Jun 2017 07:40:01 GMT) Full text and rfc822 format available.

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

From: Alexander Shukaev <emacs <at> Alexander.Shukaev.name>
To: npostavs <at> users.sourceforge.net
Cc: 27306 <at> debbugs.gnu.org
Subject: Re: bug#27306: Regression: Emacs Lisp Indentation
Date: Fri, 16 Jun 2017 09:39:23 +0200
On 06/13/2017 01:27 PM, npostavs <at> users.sourceforge.net wrote:
> tags 27306 fixed
> close 27306
> quit
> 
> npostavs <at> users.sourceforge.net writes:
> 
>> Thanks for reporting, here's a patch:
> 
> Pushed to master [1: cc8aa484cd].
> 
> [1: cc8aa484cd]: 2017-06-13 07:19:12 -0400
>    Fix wrong indentation after string literal (Bug#27306)
>    http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=cc8aa484cdab6b2f33a8c95a5778193c762412b9
> 

Hi Noam,

Works as expected.  Thank you.

Regards,
Alexander




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 14 Jul 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 335 days ago.

Previous Next


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