diff options
| author | João Távora | 2019-05-15 13:10:22 +0100 |
|---|---|---|
| committer | João Távora | 2019-07-02 16:10:45 +0100 |
| commit | 5e88b50d542b6d1c4ff43f8ae0fabe8a647d842e (patch) | |
| tree | 46c5c7e22127d8e6aad017f925514a0fb62c19ca | |
| parent | 2a2a1bdb8f0f149aaf736a61685feec9380be1b1 (diff) | |
| download | emacs-5e88b50d542b6d1c4ff43f8ae0fabe8a647d842e.tar.gz emacs-5e88b50d542b6d1c4ff43f8ae0fabe8a647d842e.zip | |
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.
| -rw-r--r-- | lisp/electric.el | 13 | ||||
| -rw-r--r-- | test/lisp/electric-tests.el | 19 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lisp/electric.el b/lisp/electric.el index 53e53bd975c..a14deb71afb 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -270,10 +270,13 @@ or comment." | |||
| 270 | (goto-char before) | 270 | (goto-char before) |
| 271 | (condition-case-unless-debug () | 271 | (condition-case-unless-debug () |
| 272 | (indent-according-to-mode) | 272 | (indent-according-to-mode) |
| 273 | (error (throw 'indent-error nil))) | 273 | (error (throw 'indent-error nil)))) |
| 274 | ;; The goal here will be to remove the trailing | 274 | (unless (eq electric-indent-inhibit 'electric-layout-mode) |
| 275 | ;; whitespace after reindentation of the previous line | 275 | ;; Unless we're operating under |
| 276 | ;; because that may have (re)introduced it. | 276 | ;; `electric-layout-mode' (Bug#35254), the goal here |
| 277 | ;; will be to remove the trailing whitespace after | ||
| 278 | ;; reindentation of the previous line because that | ||
| 279 | ;; may have (re)introduced it. | ||
| 277 | (goto-char before) | 280 | (goto-char before) |
| 278 | ;; We were at EOL in marker `before' before the call | 281 | ;; We were at EOL in marker `before' before the call |
| 279 | ;; to `indent-according-to-mode' but after we may | 282 | ;; to `indent-according-to-mode' but after we may |
| @@ -451,7 +454,7 @@ If multiple rules match, only first one is executed.") | |||
| 451 | ;; really wants to reindent, then | 454 | ;; really wants to reindent, then |
| 452 | ;; `last-command-event' should be in | 455 | ;; `last-command-event' should be in |
| 453 | ;; `electric-indent-chars'. | 456 | ;; `electric-indent-chars'. |
| 454 | (let ((electric-indent-inhibit t)) | 457 | (let ((electric-indent-inhibit 'electric-layout-mode)) |
| 455 | (funcall nl-after))))))) | 458 | (funcall nl-after))))))) |
| 456 | (pcase sym | 459 | (pcase sym |
| 457 | ('before (funcall nl-before)) | 460 | ('before (funcall nl-before)) |
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\"\"" | |||
| 876 | (call-interactively (key-binding `[,last-command-event]))) | 876 | (call-interactively (key-binding `[,last-command-event]))) |
| 877 | (should (equal (buffer-string) "int main () {\n \n}")))) | 877 | (should (equal (buffer-string) "int main () {\n \n}")))) |
| 878 | 878 | ||
| 879 | (ert-deftest electric-layout-control-reindentation () | ||
| 880 | "Same as `e-l-int-main-kernel-style', but checking Bug#35254." | ||
| 881 | (ert-with-test-buffer () | ||
| 882 | (plainer-c-mode) | ||
| 883 | (electric-layout-local-mode 1) | ||
| 884 | (electric-pair-local-mode 1) | ||
| 885 | (electric-indent-local-mode 1) | ||
| 886 | (setq-local electric-layout-rules | ||
| 887 | '((?\{ . (after)) | ||
| 888 | (?\} . (before)))) | ||
| 889 | (insert "int main () ") | ||
| 890 | (let ((last-command-event ?\{)) | ||
| 891 | (call-interactively (key-binding `[,last-command-event]))) | ||
| 892 | (should (equal (buffer-string) "int main () {\n \n}")) | ||
| 893 | ;; insert an additional newline and check indentation and | ||
| 894 | ;; reindentation | ||
| 895 | (call-interactively 'newline) | ||
| 896 | (should (equal (buffer-string) "int main () {\n\n \n}")))) | ||
| 897 | |||
| 879 | (define-derived-mode plainer-c-mode c-mode "pC" | 898 | (define-derived-mode plainer-c-mode c-mode "pC" |
| 880 | "A plainer/saner C-mode with no internal electric machinery." | 899 | "A plainer/saner C-mode with no internal electric machinery." |
| 881 | (c-toggle-electric-state -1) | 900 | (c-toggle-electric-state -1) |