From 5e88b50d542b6d1c4ff43f8ae0fabe8a647d842e Mon Sep 17 00:00:00 2001 From: João Távora Date: Wed, 15 May 2019 13:10:22 +0100 Subject: 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. --- test/lisp/electric-tests.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/lisp/electric-tests.el') diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 4f1e5729be1..86c9eff9cda 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -876,6 +876,25 @@ baz\"\"" (call-interactively (key-binding `[,last-command-event]))) (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" "A plainer/saner C-mode with no internal electric machinery." (c-toggle-electric-state -1) -- cgit v1.2.3