emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 750f0e2 1/2: Make sure indent-sexp stops at end of


From: Noam Postavsky
Subject: [Emacs-diffs] master 750f0e2 1/2: Make sure indent-sexp stops at end of sexp (Bug#26878)
Date: Mon, 15 May 2017 23:01:59 -0400 (EDT)

branch: master
commit 750f0e2e79e1bdc3246b07aa3219cab34ebde6e7
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    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 6287f27..3334471 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1184,21 +1184,24 @@ ENDPOS is encountered."
                     ;; 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 1f78eb3..f2fe7a6 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -99,6 +99,20 @@ noindent\" 3
       (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]