Commit 7c0d312b authored by João Távora's avatar João Távora

Properly solve incompatibility between e-p-m, e-l-m and cc-mode

* lisp/progmodes/cc-cmds.el (c--disable-fix-of-bug-33794): Remove.
(c--with-post-self-insert-hook-maybe): Remove.
(c-self-insert-command): New function.
(c-electric-pound, c-electric-brace, c-electric-slash)
(c-electric-star, c-electric-lt-gt, c-electric-paren): Use it.

* test/lisp/electric-tests.el (c--disable-fix-of-bug-33794):
Remove.
(electric-layout-int-main-kernel-style)
(electric-layout-int-main-allman-style): Don't set
c--disable-fix-of-bug-33794.
parent 6bac9ea1
Pipeline #582 passed with stage
in 47 minutes and 17 seconds
...@@ -485,19 +485,13 @@ function to control that." ...@@ -485,19 +485,13 @@ function to control that."
(c-hungry-delete-forward) (c-hungry-delete-forward)
(c-hungry-delete-backwards))) (c-hungry-delete-backwards)))
(defvar c--disable-fix-of-bug-33794 nil (defun c-self-insert-command (arg)
"If non-nil disable alans controversional fix of 33794. ;; If `c-auto-newline' is on we use our own implementation of
This fix breaks most features of `electric-pair-mode' by ;; `electric-pair-mode' and `electric-layout-mode' doesn't make
incompletely reimplementing in in this mode.") ;; sense.
(let ((electric-layout-mode (not c-auto-newline))
(defmacro c--with-post-self-insert-hook-maybe (&rest body) (electric-pair-mode (not c-auto-newline)))
`(let ((post-self-insert-hook (self-insert-command arg)))
(if c--disable-fix-of-bug-33794
post-self-insert-hook
;; Acording to AM: Disable random functionality to get
;; defined functionality from `self-insert-command'
nil)))
,@body))
(defun c-electric-pound (arg) (defun c-electric-pound (arg)
"Insert a \"#\". "Insert a \"#\".
...@@ -518,8 +512,7 @@ inside a literal or a macro, nothing special happens." ...@@ -518,8 +512,7 @@ inside a literal or a macro, nothing special happens."
(eq (char-before) ?\\)))) (eq (char-before) ?\\))))
(c-in-literal))) (c-in-literal)))
;; do nothing special ;; do nothing special
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
;; place the pound character at the left edge ;; place the pound character at the left edge
(let ((pos (- (point-max) (point))) (let ((pos (- (point-max) (point)))
(bolp (bolp))) (bolp (bolp)))
...@@ -871,37 +864,35 @@ settings of `c-cleanup-list' are done." ...@@ -871,37 +864,35 @@ settings of `c-cleanup-list' are done."
;; Insert the brace. Note that expand-abbrev might reindent ;; Insert the brace. Note that expand-abbrev might reindent
;; the line here if there's a preceding "else" or something. ;; the line here if there's a preceding "else" or something.
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
;; Emulate `electric-pair-mode'. ;; Emulate `electric-pair-mode'.
(unless c--disable-fix-of-bug-33794 (when (and (boundp 'electric-pair-mode)
(when (and (boundp 'electric-pair-mode) electric-pair-mode
electric-pair-mode) c-auto-newline)
(let ((size (buffer-size)) (let ((size (buffer-size))
(c-in-electric-pair-functionality t) (c-in-electric-pair-functionality t)
post-self-insert-hook) post-self-insert-hook)
(electric-pair-post-self-insert-function) (electric-pair-post-self-insert-function)
(setq got-pair-} (and at-eol (setq got-pair-} (and at-eol
(eq (c-last-command-char) ?{) (eq (c-last-command-char) ?{)
(eq (char-after) ?})) (eq (char-after) ?}))
electric-pair-deletion (< (buffer-size) size)))) electric-pair-deletion (< (buffer-size) size))))
;; Perform any required CC Mode electric actions. ;; Perform any required CC Mode electric actions.
(cond (cond
((or literal arg (not c-electric-flag) active-region)) ((or literal arg (not c-electric-flag) active-region))
((not at-eol) ((not at-eol)
(c-indent-line)) (c-indent-line))
(electric-pair-deletion (electric-pair-deletion
(c-indent-line) (c-indent-line)
(c-do-brace-electrics 'ignore nil)) (c-do-brace-electrics 'ignore nil))
(t (c-do-brace-electrics nil nil) (t (c-do-brace-electrics nil nil)
(when got-pair-} (when got-pair-}
(save-excursion (save-excursion
(forward-char) (forward-char)
(c-do-brace-electrics 'assume 'ignore)) (c-do-brace-electrics 'assume 'ignore))
(c-indent-line))))) (c-indent-line))))
;; blink the paren ;; blink the paren
...@@ -960,8 +951,7 @@ is inhibited." ...@@ -960,8 +951,7 @@ is inhibited."
c-electric-flag c-electric-flag
(eq (c-last-command-char) ?/) (eq (c-last-command-char) ?/)
(eq (char-before) (if literal ?* ?/)))) (eq (char-before) (if literal ?* ?/))))
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
(if indentp (if indentp
(indent-according-to-mode)))) (indent-according-to-mode))))
...@@ -974,8 +964,7 @@ supplied, point is inside a literal, or `c-syntactic-indentation' is nil, ...@@ -974,8 +964,7 @@ supplied, point is inside a literal, or `c-syntactic-indentation' is nil,
this indentation is inhibited." this indentation is inhibited."
(interactive "*P") (interactive "*P")
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
;; if we are in a literal, or if arg is given do not reindent the ;; if we are in a literal, or if arg is given do not reindent the
;; current line, unless this star introduces a comment-only line. ;; current line, unless this star introduces a comment-only line.
(if (c-save-buffer-state () (if (c-save-buffer-state ()
...@@ -1022,8 +1011,7 @@ settings of `c-cleanup-list'." ...@@ -1022,8 +1011,7 @@ settings of `c-cleanup-list'."
(setq lim (c-most-enclosing-brace (c-parse-state)) (setq lim (c-most-enclosing-brace (c-parse-state))
literal (c-in-literal lim))) literal (c-in-literal lim)))
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
(if (and c-electric-flag (not literal) (not arg)) (if (and c-electric-flag (not literal) (not arg))
;; do all cleanups and newline insertions if c-auto-newline is on. ;; do all cleanups and newline insertions if c-auto-newline is on.
...@@ -1092,8 +1080,7 @@ reindented unless `c-syntactic-indentation' is nil. ...@@ -1092,8 +1080,7 @@ reindented unless `c-syntactic-indentation' is nil.
newlines is-scope-op newlines is-scope-op
;; shut this up ;; shut this up
(c-echo-syntactic-information-p nil)) (c-echo-syntactic-information-p nil))
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
;; Any electric action? ;; Any electric action?
(if (and c-electric-flag (not literal) (not arg)) (if (and c-electric-flag (not literal) (not arg))
;; Unless we're at EOL, only re-indentation happens. ;; Unless we're at EOL, only re-indentation happens.
...@@ -1186,8 +1173,7 @@ numeric argument is supplied, or the point is inside a literal." ...@@ -1186,8 +1173,7 @@ numeric argument is supplied, or the point is inside a literal."
(let ((c-echo-syntactic-information-p nil) (let ((c-echo-syntactic-information-p nil)
final-pos found-delim case-fold-search) final-pos found-delim case-fold-search)
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
(setq final-pos (point)) (setq final-pos (point))
;;;; 2010-01-31: There used to be code here to put a syntax-table text ;;;; 2010-01-31: There used to be code here to put a syntax-table text
...@@ -1252,8 +1238,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'." ...@@ -1252,8 +1238,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
;; shut this up ;; shut this up
(c-echo-syntactic-information-p nil) (c-echo-syntactic-information-p nil)
case-fold-search) case-fold-search)
(c--with-post-self-insert-hook-maybe (c-self-insert-command (prefix-numeric-value arg))
(self-insert-command (prefix-numeric-value arg)))
(if (and (not arg) (not literal)) (if (and (not arg) (not literal))
(let* ( ;; We want to inhibit blinking the paren since this will (let* ( ;; We want to inhibit blinking the paren since this will
...@@ -1303,11 +1288,11 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'." ...@@ -1303,11 +1288,11 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
(insert-and-inherit "} catch ("))) (insert-and-inherit "} catch (")))
;; Apply `electric-pair-mode' stuff. ;; Apply `electric-pair-mode' stuff.
(unless c--disable-fix-of-bug-33794 (when (and c-auto-newline
(when (and (boundp 'electric-pair-mode) (boundp 'electric-pair-mode)
electric-pair-mode) electric-pair-mode)
(let (post-self-insert-hook) (let (post-self-insert-hook)
(electric-pair-post-self-insert-function)))) (electric-pair-post-self-insert-function)))
;; Check for clean-ups at function calls. These two DON'T need ;; Check for clean-ups at function calls. These two DON'T need
;; `c-electric-flag' or `c-syntactic-indentation' set. ;; `c-electric-flag' or `c-syntactic-indentation' set.
......
...@@ -47,14 +47,10 @@ ...@@ -47,14 +47,10 @@
(declare (indent defun) (debug t)) (declare (indent defun) (debug t))
`(call-with-saved-electric-modes #'(lambda () ,@body))) `(call-with-saved-electric-modes #'(lambda () ,@body)))
;; Defined in lisp/progmodes/cc-cmds.el
(defvar c--disable-fix-of-bug-33794 t)
(defun electric-pair-test-for (fixture where char expected-string (defun electric-pair-test-for (fixture where char expected-string
expected-point mode bindings fixture-fn) expected-point mode bindings fixture-fn)
(with-temp-buffer (with-temp-buffer
(funcall mode) (funcall mode)
(setq-local c--disable-fix-of-bug-33794 t)
(insert fixture) (insert fixture)
(save-electric-modes (save-electric-modes
(let ((last-command-event char) (let ((last-command-event char)
...@@ -825,7 +821,6 @@ baz\"\"" ...@@ -825,7 +821,6 @@ baz\"\""
(electric-layout-local-mode 1) (electric-layout-local-mode 1)
(electric-pair-local-mode 1) (electric-pair-local-mode 1)
(electric-indent-local-mode 1) (electric-indent-local-mode 1)
(setq-local c--disable-fix-of-bug-33794 t)
(setq-local electric-layout-rules (setq-local electric-layout-rules
'((?\{ . (after-stay after)))) '((?\{ . (after-stay after))))
(insert "int main () ") (insert "int main () ")
...@@ -839,7 +834,6 @@ baz\"\"" ...@@ -839,7 +834,6 @@ baz\"\""
(electric-layout-local-mode 1) (electric-layout-local-mode 1)
(electric-pair-local-mode 1) (electric-pair-local-mode 1)
(electric-indent-local-mode 1) (electric-indent-local-mode 1)
(setq-local c--disable-fix-of-bug-33794 t)
(setq-local electric-layout-rules (setq-local electric-layout-rules
'((?\{ . (before after-stay after)))) '((?\{ . (before after-stay after))))
(insert "int main () ") (insert "int main () ")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment