aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2017-05-11 18:12:40 -0400
committerNoam Postavsky2017-05-15 22:58:17 -0400
commit750f0e2e79e1bdc3246b07aa3219cab34ebde6e7 (patch)
tree9dbb72248eb3843359cc1ad6d475d53112ddf3c2
parent24d06313c4f205061fb74c9665d5819a05362636 (diff)
downloademacs-750f0e2e79e1bdc3246b07aa3219cab34ebde6e7.tar.gz
emacs-750f0e2e79e1bdc3246b07aa3219cab34ebde6e7.zip
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.
-rw-r--r--lisp/emacs-lisp/lisp-mode.el33
-rw-r--r--test/lisp/emacs-lisp/lisp-mode-tests.el14
2 files changed, 32 insertions, 15 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 6287f27b139..3334471d251 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1184,21 +1184,24 @@ ENDPOS is encountered."
1184 ;; after point. 1184 ;; after point.
1185 (save-excursion (forward-sexp 1) (point))))) 1185 (save-excursion (forward-sexp 1) (point)))))
1186 (save-excursion 1186 (save-excursion
1187 (while (< (point) endpos) 1187 (while (let ((indent (lisp-indent-calc-next parse-state))
1188 (let ((indent (lisp-indent-calc-next parse-state))) 1188 (ppss (lisp-indent-state-ppss parse-state)))
1189 ;; If the line contains a comment indent it now with 1189 ;; If the line contains a comment indent it now with
1190 ;; `indent-for-comment'. 1190 ;; `indent-for-comment'.
1191 (when (nth 4 (lisp-indent-state-ppss parse-state)) 1191 (when (and (nth 4 ppss) (<= (nth 8 ppss) endpos))
1192 (save-excursion 1192 (save-excursion
1193 (goto-char (lisp-indent-state-ppss-point parse-state)) 1193 (goto-char (lisp-indent-state-ppss-point parse-state))
1194 (indent-for-comment) 1194 (indent-for-comment)
1195 (setf (lisp-indent-state-ppss-point parse-state) 1195 (setf (lisp-indent-state-ppss-point parse-state)
1196 (line-end-position)))) 1196 (line-end-position))))
1197 ;; But not if the line is blank, or just a comment (we 1197 (when (< (point) endpos)
1198 ;; already called `indent-for-comment' above). 1198 ;; Indent the next line, unless it's blank, or just a
1199 (skip-chars-forward " \t") 1199 ;; comment (we will `indent-for-comment' the latter).
1200 (unless (or (eolp) (eq (char-syntax (char-after)) ?<) (not indent)) 1200 (skip-chars-forward " \t")
1201 (indent-line-to indent))))) 1201 (unless (or (eolp) (not indent)
1202 (eq (char-syntax (char-after)) ?<))
1203 (indent-line-to indent))
1204 t))))
1202 (move-marker endpos nil))) 1205 (move-marker endpos nil)))
1203 1206
1204(defun indent-pp-sexp (&optional arg) 1207(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 1f78eb30105..f2fe7a6cf41 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
99 (indent-sexp) 99 (indent-sexp)
100 (should (equal (buffer-string) correct))))) 100 (should (equal (buffer-string) correct)))))
101 101
102(ert-deftest indent-sexp-stop ()
103 "Make sure `indent-sexp' stops at the end of the sexp."
104 ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26878.
105 (with-temp-buffer
106 (emacs-lisp-mode)
107 (insert "(a ()\n)")
108 (let ((original (buffer-string)))
109 (search-backward "a ")
110 (goto-char (match-end 0))
111 (indent-sexp)
112 ;; The final paren should not be indented, because the sexp
113 ;; we're indenting ends on the previous line.
114 (should (equal (buffer-string) original)))))
115
102(ert-deftest lisp-indent-region () 116(ert-deftest lisp-indent-region ()
103 "Test basics of `lisp-indent-region'." 117 "Test basics of `lisp-indent-region'."
104 (with-temp-buffer 118 (with-temp-buffer