diff options
| author | Noam Postavsky | 2019-04-15 18:49:57 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-04-22 12:49:36 -0400 |
| commit | 93912baefd10ccb3e6e2e9696cda3b813c056c87 (patch) | |
| tree | 0b0557ff122a4fe6138ab564bd5ada5d73876b10 | |
| parent | 3988e93d4b0f2bf677efd9f560373dd526097609 (diff) | |
| download | emacs-93912baefd10ccb3e6e2e9696cda3b813c056c87.tar.gz emacs-93912baefd10ccb3e6e2e9696cda3b813c056c87.zip | |
Be more careful about indent-sexp going over eol (Bug#35286)
* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Only go over multiple
sexps if the end of line is within a sexp.
* test/lisp/emacs-lisp/lisp-mode-tests.el
(indent-sexp-stop-before-eol-comment)
(indent-sexp-stop-before-eol-non-lisp): New tests.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 22 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-mode-tests.el | 28 |
2 files changed, 42 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 57f57175c51..74bf0c87c53 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -1205,19 +1205,25 @@ ENDPOS is encountered." | |||
| 1205 | ;; Get error now if we don't have a complete sexp | 1205 | ;; Get error now if we don't have a complete sexp |
| 1206 | ;; after point. | 1206 | ;; after point. |
| 1207 | (save-excursion | 1207 | (save-excursion |
| 1208 | (forward-sexp 1) | ||
| 1208 | (let ((eol (line-end-position))) | 1209 | (let ((eol (line-end-position))) |
| 1209 | (forward-sexp 1) | ||
| 1210 | ;; We actually look for a sexp which ends | 1210 | ;; We actually look for a sexp which ends |
| 1211 | ;; after the current line so that we properly | 1211 | ;; after the current line so that we properly |
| 1212 | ;; indent things like #s(...). This might not | 1212 | ;; indent things like #s(...). This might not |
| 1213 | ;; be needed if Bug#15998 is fixed. | 1213 | ;; be needed if Bug#15998 is fixed. |
| 1214 | (condition-case () | 1214 | (when (and (< (point) eol) |
| 1215 | (while (and (< (point) eol) (not (eobp))) | 1215 | ;; Check if eol is within a sexp. |
| 1216 | (forward-sexp 1)) | 1216 | (> (nth 0 (save-excursion |
| 1217 | ;; But don't signal an error for incomplete | 1217 | (parse-partial-sexp |
| 1218 | ;; sexps following the first complete sexp | 1218 | (point) eol))) |
| 1219 | ;; after point. | 1219 | 0)) |
| 1220 | (scan-error nil))) | 1220 | (condition-case () |
| 1221 | (while (< (point) eol) | ||
| 1222 | (forward-sexp 1)) | ||
| 1223 | ;; But don't signal an error for incomplete | ||
| 1224 | ;; sexps following the first complete sexp | ||
| 1225 | ;; after point. | ||
| 1226 | (scan-error nil)))) | ||
| 1221 | (point))))) | 1227 | (point))))) |
| 1222 | (save-excursion | 1228 | (save-excursion |
| 1223 | (while (let ((indent (lisp-indent-calc-next parse-state)) | 1229 | (while (let ((indent (lisp-indent-calc-next parse-state)) |
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index a6370742ab4..63632449ca5 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el | |||
| @@ -136,6 +136,34 @@ noindent\" 3 | |||
| 136 | (indent-sexp) | 136 | (indent-sexp) |
| 137 | (should (equal (buffer-string) "(())")))) | 137 | (should (equal (buffer-string) "(())")))) |
| 138 | 138 | ||
| 139 | (ert-deftest indent-sexp-stop-before-eol-comment () | ||
| 140 | "`indent-sexp' shouldn't look for more sexps after an eol comment." | ||
| 141 | ;; See https://debbugs.gnu.org/35286. | ||
| 142 | (with-temp-buffer | ||
| 143 | (emacs-lisp-mode) | ||
| 144 | (let ((str "() ;;\n x")) | ||
| 145 | (insert str) | ||
| 146 | (goto-char (point-min)) | ||
| 147 | (indent-sexp) | ||
| 148 | ;; The "x" is in the next sexp, so it shouldn't get indented. | ||
| 149 | (should (equal (buffer-string) str))))) | ||
| 150 | |||
| 151 | (ert-deftest indent-sexp-stop-before-eol-non-lisp () | ||
| 152 | "`indent-sexp' shouldn't be too agressive in non-Lisp modes." | ||
| 153 | ;; See https://debbugs.gnu.org/35286#13. | ||
| 154 | (with-temp-buffer | ||
| 155 | (prolog-mode) | ||
| 156 | (let ((str "\ | ||
| 157 | x(H) --> | ||
| 158 | {y(H)}. | ||
| 159 | a(A) --> | ||
| 160 | b(A).")) | ||
| 161 | (insert str) | ||
| 162 | (search-backward "{") | ||
| 163 | (indent-sexp) | ||
| 164 | ;; There's no line-spanning sexp, so nothing should be indented. | ||
| 165 | (should (equal (buffer-string) str))))) | ||
| 166 | |||
| 139 | (ert-deftest lisp-indent-region () | 167 | (ert-deftest lisp-indent-region () |
| 140 | "Test basics of `lisp-indent-region'." | 168 | "Test basics of `lisp-indent-region'." |
| 141 | (with-temp-buffer | 169 | (with-temp-buffer |