(goto-char before)
(condition-case-unless-debug ()
(indent-according-to-mode)
- (error (throw 'indent-error nil)))
- ;; The goal here will be to remove the trailing
- ;; whitespace after reindentation of the previous line
- ;; because that may have (re)introduced it.
+ (error (throw 'indent-error nil))))
+ (unless (eq electric-indent-inhibit 'electric-layout-mode)
+ ;; Unless we're operating under
+ ;; `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)
;; We were at EOL in marker `before' before the call
;; to `indent-according-to-mode' but after we may
;; really wants to reindent, then
;; `last-command-event' should be in
;; `electric-indent-chars'.
- (let ((electric-indent-inhibit t))
+ (let ((electric-indent-inhibit 'electric-layout-mode))
(funcall nl-after)))))))
(pcase sym
('before (funcall nl-before))
(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)