aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNoam Postavsky2017-04-23 10:43:05 -0400
committerNoam Postavsky2017-05-09 20:50:19 -0400
commite7b6751c0a74f24c14cd207d57a4e1a95f409256 (patch)
tree14f60933c9d78aabf42ba79abd911f9ef3e3d373 /test
parent17e540aa428c5392f7a9b4c1f7495bac8a8fe5da (diff)
downloademacs-e7b6751c0a74f24c14cd207d57a4e1a95f409256.tar.gz
emacs-e7b6751c0a74f24c14cd207d57a4e1a95f409256.zip
Fix lisp-indent-region and indent-sexp (Bug#26619)
The new lisp-indent-region introduced in 2017-04-22 "Add new `lisp-indent-region' that doesn't reparse the code." is broken because it doesn't save the calculated indent amounts for already seen sexp depths. Fix this by unifying the indent-sexp and lisp-indent-region code. Furthermore, only preserve position 2 of the running parse when the depth doesn't change. * lisp/emacs-lisp/lisp-mode.el (lisp-ppss): Use an OLDSTATE that corresponds with the start point when calling parse-partial-sexp. (lisp-indent-state): New struct. (lisp-indent-calc-next): New function, extracted from indent-sexp. (indent-sexp, lisp-indent-region): Use it. (lisp-indent-line): Take indentation, instead of parse state. * test/lisp/emacs-lisp/lisp-mode-tests.el (lisp-mode-tests--correctly-indented-sexp): New constant. (lisp-indent-region, lisp-indent-region-defun-with-docstring): (lisp-indent-region-open-paren, lisp-indent-region-in-sexp): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/lisp-mode-tests.el85
1 files changed, 80 insertions, 5 deletions
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index 27f0bb5ec13..1f78eb30105 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -21,10 +21,7 @@
21(require 'cl-lib) 21(require 'cl-lib)
22(require 'lisp-mode) 22(require 'lisp-mode)
23 23
24(ert-deftest indent-sexp () 24(defconst lisp-mode-tests--correctly-indented-sexp "\
25 "Test basics of \\[indent-sexp]."
26 (with-temp-buffer
27 (insert "\
28\(a 25\(a
29 (prog1 26 (prog1
30 (prog1 27 (prog1
@@ -42,9 +39,14 @@ noindent\" 3
42 2) ; comment 39 2) ; comment
43 ;; comment 40 ;; comment
44 b)") 41 b)")
42
43(ert-deftest indent-sexp ()
44 "Test basics of \\[indent-sexp]."
45 (with-temp-buffer
46 (insert lisp-mode-tests--correctly-indented-sexp)
45 (goto-char (point-min)) 47 (goto-char (point-min))
46 (let ((indent-tabs-mode nil) 48 (let ((indent-tabs-mode nil)
47 (correct (buffer-string))) 49 (correct lisp-mode-tests--correctly-indented-sexp))
48 (dolist (mode '(fundamental-mode emacs-lisp-mode)) 50 (dolist (mode '(fundamental-mode emacs-lisp-mode))
49 (funcall mode) 51 (funcall mode)
50 (indent-sexp) 52 (indent-sexp)
@@ -97,5 +99,78 @@ noindent\" 3
97 (indent-sexp) 99 (indent-sexp)
98 (should (equal (buffer-string) correct))))) 100 (should (equal (buffer-string) correct)))))
99 101
102(ert-deftest lisp-indent-region ()
103 "Test basics of `lisp-indent-region'."
104 (with-temp-buffer
105 (insert lisp-mode-tests--correctly-indented-sexp)
106 (goto-char (point-min))
107 (let ((indent-tabs-mode nil)
108 (correct lisp-mode-tests--correctly-indented-sexp))
109 (emacs-lisp-mode)
110 (indent-region (point-min) (point-max))
111 ;; Don't mess up correctly indented code.
112 (should (string= (buffer-string) correct))
113 ;; Correctly add indentation.
114 (save-excursion
115 (while (not (eobp))
116 (delete-horizontal-space)
117 (forward-line)))
118 (indent-region (point-min) (point-max))
119 (should (equal (buffer-string) correct))
120 ;; Correctly remove indentation.
121 (save-excursion
122 (let ((n 0))
123 (while (not (eobp))
124 (unless (looking-at "noindent\\|^[[:blank:]]*$")
125 (insert (make-string n ?\s)))
126 (cl-incf n)
127 (forward-line))))
128 (indent-region (point-min) (point-max))
129 (should (equal (buffer-string) correct)))))
130
131
132(ert-deftest lisp-indent-region-defun-with-docstring ()
133 "Test Bug#26619."
134 (with-temp-buffer
135 (insert "\
136\(defun test ()
137 \"This is a test.
138Test indentation in emacs-lisp-mode\"
139 (message \"Hi!\"))")
140 (let ((indent-tabs-mode nil)
141 (correct (buffer-string)))
142 (emacs-lisp-mode)
143 (indent-region (point-min) (point-max))
144 (should (equal (buffer-string) correct)))))
145
146(ert-deftest lisp-indent-region-open-paren ()
147 (with-temp-buffer
148 (insert "\
149\(with-eval-after-load 'foo
150 (setq bar `(
151 baz)))")
152 (let ((indent-tabs-mode nil)
153 (correct (buffer-string)))
154 (emacs-lisp-mode)
155 (indent-region (point-min) (point-max))
156 (should (equal (buffer-string) correct)))))
157
158(ert-deftest lisp-indent-region-in-sexp ()
159 (with-temp-buffer
160 (insert "\
161\(when t
162 (when t
163 (list 1 2 3)
164 'etc)
165 (quote etc)
166 (quote etc))")
167 (let ((indent-tabs-mode nil)
168 (correct (buffer-string)))
169 (emacs-lisp-mode)
170 (search-backward "1")
171 (indent-region (point) (point-max))
172 (should (equal (buffer-string) correct)))))
173
174
100(provide 'lisp-mode-tests) 175(provide 'lisp-mode-tests)
101;;; lisp-mode-tests.el ends here 176;;; lisp-mode-tests.el ends here