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.
This commit is contained in:
parent
3988e93d4b
commit
93912baefd
2 changed files with 42 additions and 8 deletions
|
@ -1205,19 +1205,25 @@ ENDPOS is encountered."
|
||||||
;; Get error now if we don't have a complete sexp
|
;; Get error now if we don't have a complete sexp
|
||||||
;; after point.
|
;; after point.
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
(forward-sexp 1)
|
||||||
(let ((eol (line-end-position)))
|
(let ((eol (line-end-position)))
|
||||||
(forward-sexp 1)
|
|
||||||
;; We actually look for a sexp which ends
|
;; We actually look for a sexp which ends
|
||||||
;; after the current line so that we properly
|
;; after the current line so that we properly
|
||||||
;; indent things like #s(...). This might not
|
;; indent things like #s(...). This might not
|
||||||
;; be needed if Bug#15998 is fixed.
|
;; be needed if Bug#15998 is fixed.
|
||||||
(condition-case ()
|
(when (and (< (point) eol)
|
||||||
(while (and (< (point) eol) (not (eobp)))
|
;; Check if eol is within a sexp.
|
||||||
(forward-sexp 1))
|
(> (nth 0 (save-excursion
|
||||||
;; But don't signal an error for incomplete
|
(parse-partial-sexp
|
||||||
;; sexps following the first complete sexp
|
(point) eol)))
|
||||||
;; after point.
|
0))
|
||||||
(scan-error nil)))
|
(condition-case ()
|
||||||
|
(while (< (point) eol)
|
||||||
|
(forward-sexp 1))
|
||||||
|
;; But don't signal an error for incomplete
|
||||||
|
;; sexps following the first complete sexp
|
||||||
|
;; after point.
|
||||||
|
(scan-error nil))))
|
||||||
(point)))))
|
(point)))))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(while (let ((indent (lisp-indent-calc-next parse-state))
|
(while (let ((indent (lisp-indent-calc-next parse-state))
|
||||||
|
|
|
@ -136,6 +136,34 @@ noindent\" 3
|
||||||
(indent-sexp)
|
(indent-sexp)
|
||||||
(should (equal (buffer-string) "(())"))))
|
(should (equal (buffer-string) "(())"))))
|
||||||
|
|
||||||
|
(ert-deftest indent-sexp-stop-before-eol-comment ()
|
||||||
|
"`indent-sexp' shouldn't look for more sexps after an eol comment."
|
||||||
|
;; See https://debbugs.gnu.org/35286.
|
||||||
|
(with-temp-buffer
|
||||||
|
(emacs-lisp-mode)
|
||||||
|
(let ((str "() ;;\n x"))
|
||||||
|
(insert str)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(indent-sexp)
|
||||||
|
;; The "x" is in the next sexp, so it shouldn't get indented.
|
||||||
|
(should (equal (buffer-string) str)))))
|
||||||
|
|
||||||
|
(ert-deftest indent-sexp-stop-before-eol-non-lisp ()
|
||||||
|
"`indent-sexp' shouldn't be too agressive in non-Lisp modes."
|
||||||
|
;; See https://debbugs.gnu.org/35286#13.
|
||||||
|
(with-temp-buffer
|
||||||
|
(prolog-mode)
|
||||||
|
(let ((str "\
|
||||||
|
x(H) -->
|
||||||
|
{y(H)}.
|
||||||
|
a(A) -->
|
||||||
|
b(A)."))
|
||||||
|
(insert str)
|
||||||
|
(search-backward "{")
|
||||||
|
(indent-sexp)
|
||||||
|
;; There's no line-spanning sexp, so nothing should be indented.
|
||||||
|
(should (equal (buffer-string) str)))))
|
||||||
|
|
||||||
(ert-deftest lisp-indent-region ()
|
(ert-deftest lisp-indent-region ()
|
||||||
"Test basics of `lisp-indent-region'."
|
"Test basics of `lisp-indent-region'."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue