mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-24 10:38:38 +00:00
Correctly reindent previous line in electric-indent-mode
Fixes: bug#35254 Do this even when electric-indent-inhibit is t, except when the newline insertion is being performed by electric-layout-mode. * lisp/electric.el (electric-indent-post-self-insert-function): Reindent previous line unless operating under electric-layout-mode. (electric-layout-post-self-insert-function-1): Bind electric-indent-inhibit to 'electric-layout-mode. * test/lisp/electric-tests.el (electric-layout-control-reindentation): New test.
This commit is contained in:
parent
2a2a1bdb8f
commit
5e88b50d54
@ -270,10 +270,13 @@ or comment."
|
|||||||
(goto-char before)
|
(goto-char before)
|
||||||
(condition-case-unless-debug ()
|
(condition-case-unless-debug ()
|
||||||
(indent-according-to-mode)
|
(indent-according-to-mode)
|
||||||
(error (throw 'indent-error nil)))
|
(error (throw 'indent-error nil))))
|
||||||
;; The goal here will be to remove the trailing
|
(unless (eq electric-indent-inhibit 'electric-layout-mode)
|
||||||
;; whitespace after reindentation of the previous line
|
;; Unless we're operating under
|
||||||
;; because that may have (re)introduced it.
|
;; `electric-layout-mode' (Bug#35254), the goal here
|
||||||
|
;; will be to remove the trailing whitespace after
|
||||||
|
;; reindentation of the previous line because that
|
||||||
|
;; may have (re)introduced it.
|
||||||
(goto-char before)
|
(goto-char before)
|
||||||
;; We were at EOL in marker `before' before the call
|
;; We were at EOL in marker `before' before the call
|
||||||
;; to `indent-according-to-mode' but after we may
|
;; to `indent-according-to-mode' but after we may
|
||||||
@ -451,7 +454,7 @@ If multiple rules match, only first one is executed.")
|
|||||||
;; really wants to reindent, then
|
;; really wants to reindent, then
|
||||||
;; `last-command-event' should be in
|
;; `last-command-event' should be in
|
||||||
;; `electric-indent-chars'.
|
;; `electric-indent-chars'.
|
||||||
(let ((electric-indent-inhibit t))
|
(let ((electric-indent-inhibit 'electric-layout-mode))
|
||||||
(funcall nl-after)))))))
|
(funcall nl-after)))))))
|
||||||
(pcase sym
|
(pcase sym
|
||||||
('before (funcall nl-before))
|
('before (funcall nl-before))
|
||||||
|
@ -876,6 +876,25 @@ baz\"\""
|
|||||||
(call-interactively (key-binding `[,last-command-event])))
|
(call-interactively (key-binding `[,last-command-event])))
|
||||||
(should (equal (buffer-string) "int main () {\n \n}"))))
|
(should (equal (buffer-string) "int main () {\n \n}"))))
|
||||||
|
|
||||||
|
(ert-deftest electric-layout-control-reindentation ()
|
||||||
|
"Same as `e-l-int-main-kernel-style', but checking Bug#35254."
|
||||||
|
(ert-with-test-buffer ()
|
||||||
|
(plainer-c-mode)
|
||||||
|
(electric-layout-local-mode 1)
|
||||||
|
(electric-pair-local-mode 1)
|
||||||
|
(electric-indent-local-mode 1)
|
||||||
|
(setq-local electric-layout-rules
|
||||||
|
'((?\{ . (after))
|
||||||
|
(?\} . (before))))
|
||||||
|
(insert "int main () ")
|
||||||
|
(let ((last-command-event ?\{))
|
||||||
|
(call-interactively (key-binding `[,last-command-event])))
|
||||||
|
(should (equal (buffer-string) "int main () {\n \n}"))
|
||||||
|
;; insert an additional newline and check indentation and
|
||||||
|
;; reindentation
|
||||||
|
(call-interactively 'newline)
|
||||||
|
(should (equal (buffer-string) "int main () {\n\n \n}"))))
|
||||||
|
|
||||||
(define-derived-mode plainer-c-mode c-mode "pC"
|
(define-derived-mode plainer-c-mode c-mode "pC"
|
||||||
"A plainer/saner C-mode with no internal electric machinery."
|
"A plainer/saner C-mode with no internal electric machinery."
|
||||||
(c-toggle-electric-state -1)
|
(c-toggle-electric-state -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user