aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/cc-cmds.el107
-rw-r--r--test/lisp/electric-tests.el6
2 files changed, 46 insertions, 67 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 6b0d9617667..c54d3894709 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -485,19 +485,13 @@ function to control that."
485 (c-hungry-delete-forward) 485 (c-hungry-delete-forward)
486 (c-hungry-delete-backwards))) 486 (c-hungry-delete-backwards)))
487 487
488(defvar c--disable-fix-of-bug-33794 nil 488(defun c-self-insert-command (arg)
489 "If non-nil disable alans controversional fix of 33794. 489 ;; If `c-auto-newline' is on we use our own implementation of
490This fix breaks most features of `electric-pair-mode' by 490 ;; `electric-pair-mode' and `electric-layout-mode' doesn't make
491incompletely reimplementing in in this mode.") 491 ;; sense.
492 492 (let ((electric-layout-mode (not c-auto-newline))
493(defmacro c--with-post-self-insert-hook-maybe (&rest body) 493 (electric-pair-mode (not c-auto-newline)))
494 `(let ((post-self-insert-hook 494 (self-insert-command arg)))
495 (if c--disable-fix-of-bug-33794
496 post-self-insert-hook
497 ;; Acording to AM: Disable random functionality to get
498 ;; defined functionality from `self-insert-command'
499 nil)))
500 ,@body))
501 495
502(defun c-electric-pound (arg) 496(defun c-electric-pound (arg)
503 "Insert a \"#\". 497 "Insert a \"#\".
@@ -518,8 +512,7 @@ inside a literal or a macro, nothing special happens."
518 (eq (char-before) ?\\)))) 512 (eq (char-before) ?\\))))
519 (c-in-literal))) 513 (c-in-literal)))
520 ;; do nothing special 514 ;; do nothing special
521 (c--with-post-self-insert-hook-maybe 515 (c-self-insert-command (prefix-numeric-value arg))
522 (self-insert-command (prefix-numeric-value arg)))
523 ;; place the pound character at the left edge 516 ;; place the pound character at the left edge
524 (let ((pos (- (point-max) (point))) 517 (let ((pos (- (point-max) (point)))
525 (bolp (bolp))) 518 (bolp (bolp)))
@@ -871,37 +864,35 @@ settings of `c-cleanup-list' are done."
871 864
872 ;; Insert the brace. Note that expand-abbrev might reindent 865 ;; Insert the brace. Note that expand-abbrev might reindent
873 ;; the line here if there's a preceding "else" or something. 866 ;; the line here if there's a preceding "else" or something.
874 (c--with-post-self-insert-hook-maybe 867 (c-self-insert-command (prefix-numeric-value arg))
875 (self-insert-command (prefix-numeric-value arg)))
876 868
877 ;; Emulate `electric-pair-mode'. 869 ;; Emulate `electric-pair-mode'.
878 (unless c--disable-fix-of-bug-33794 870 (when (and (boundp 'electric-pair-mode)
879 (when (and (boundp 'electric-pair-mode) 871 electric-pair-mode
880 electric-pair-mode) 872 c-auto-newline)
881 (let ((size (buffer-size)) 873 (let ((size (buffer-size))
882 (c-in-electric-pair-functionality t) 874 (c-in-electric-pair-functionality t)
883 post-self-insert-hook) 875 post-self-insert-hook)
884 (electric-pair-post-self-insert-function) 876 (electric-pair-post-self-insert-function)
885 (setq got-pair-} (and at-eol 877 (setq got-pair-} (and at-eol
886 (eq (c-last-command-char) ?{) 878 (eq (c-last-command-char) ?{)
887 (eq (char-after) ?})) 879 (eq (char-after) ?}))
888 electric-pair-deletion (< (buffer-size) size)))) 880 electric-pair-deletion (< (buffer-size) size))))
889 881
890 ;; Perform any required CC Mode electric actions. 882 ;; Perform any required CC Mode electric actions.
891 (cond 883 (cond
892 ((or literal arg (not c-electric-flag) active-region)) 884 ((or literal arg (not c-electric-flag) active-region))
893 ((not at-eol) 885 ((not at-eol)
894 (c-indent-line)) 886 (c-indent-line))
895 (electric-pair-deletion 887 (electric-pair-deletion
896 (c-indent-line) 888 (c-indent-line)
897 (c-do-brace-electrics 'ignore nil)) 889 (c-do-brace-electrics 'ignore nil))
898 (t (c-do-brace-electrics nil nil) 890 (t (c-do-brace-electrics nil nil)
899 (when got-pair-} 891 (when got-pair-}
900 (save-excursion 892 (save-excursion
901 (forward-char) 893 (forward-char)
902 (c-do-brace-electrics 'assume 'ignore)) 894 (c-do-brace-electrics 'assume 'ignore))
903 (c-indent-line))))) 895 (c-indent-line))))
904
905 896
906 897
907 ;; blink the paren 898 ;; blink the paren
@@ -960,8 +951,7 @@ is inhibited."
960 c-electric-flag 951 c-electric-flag
961 (eq (c-last-command-char) ?/) 952 (eq (c-last-command-char) ?/)
962 (eq (char-before) (if literal ?* ?/)))) 953 (eq (char-before) (if literal ?* ?/))))
963 (c--with-post-self-insert-hook-maybe 954 (c-self-insert-command (prefix-numeric-value arg))
964 (self-insert-command (prefix-numeric-value arg)))
965 (if indentp 955 (if indentp
966 (indent-according-to-mode)))) 956 (indent-according-to-mode))))
967 957
@@ -974,8 +964,7 @@ supplied, point is inside a literal, or `c-syntactic-indentation' is nil,
974this indentation is inhibited." 964this indentation is inhibited."
975 965
976 (interactive "*P") 966 (interactive "*P")
977 (c--with-post-self-insert-hook-maybe 967 (c-self-insert-command (prefix-numeric-value arg))
978 (self-insert-command (prefix-numeric-value arg)))
979 ;; if we are in a literal, or if arg is given do not reindent the 968 ;; if we are in a literal, or if arg is given do not reindent the
980 ;; current line, unless this star introduces a comment-only line. 969 ;; current line, unless this star introduces a comment-only line.
981 (if (c-save-buffer-state () 970 (if (c-save-buffer-state ()
@@ -1022,8 +1011,7 @@ settings of `c-cleanup-list'."
1022 (setq lim (c-most-enclosing-brace (c-parse-state)) 1011 (setq lim (c-most-enclosing-brace (c-parse-state))
1023 literal (c-in-literal lim))) 1012 literal (c-in-literal lim)))
1024 1013
1025 (c--with-post-self-insert-hook-maybe 1014 (c-self-insert-command (prefix-numeric-value arg))
1026 (self-insert-command (prefix-numeric-value arg)))
1027 1015
1028 (if (and c-electric-flag (not literal) (not arg)) 1016 (if (and c-electric-flag (not literal) (not arg))
1029 ;; do all cleanups and newline insertions if c-auto-newline is on. 1017 ;; do all cleanups and newline insertions if c-auto-newline is on.
@@ -1092,8 +1080,7 @@ reindented unless `c-syntactic-indentation' is nil.
1092 newlines is-scope-op 1080 newlines is-scope-op
1093 ;; shut this up 1081 ;; shut this up
1094 (c-echo-syntactic-information-p nil)) 1082 (c-echo-syntactic-information-p nil))
1095 (c--with-post-self-insert-hook-maybe 1083 (c-self-insert-command (prefix-numeric-value arg))
1096 (self-insert-command (prefix-numeric-value arg)))
1097 ;; Any electric action? 1084 ;; Any electric action?
1098 (if (and c-electric-flag (not literal) (not arg)) 1085 (if (and c-electric-flag (not literal) (not arg))
1099 ;; Unless we're at EOL, only re-indentation happens. 1086 ;; 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 (let ((c-echo-syntactic-information-p nil) 1173 (let ((c-echo-syntactic-information-p nil)
1187 final-pos found-delim case-fold-search) 1174 final-pos found-delim case-fold-search)
1188 1175
1189 (c--with-post-self-insert-hook-maybe 1176 (c-self-insert-command (prefix-numeric-value arg))
1190 (self-insert-command (prefix-numeric-value arg)))
1191 (setq final-pos (point)) 1177 (setq final-pos (point))
1192 1178
1193;;;; 2010-01-31: There used to be code here to put a syntax-table text 1179;;;; 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 ;; shut this up 1238 ;; shut this up
1253 (c-echo-syntactic-information-p nil) 1239 (c-echo-syntactic-information-p nil)
1254 case-fold-search) 1240 case-fold-search)
1255 (c--with-post-self-insert-hook-maybe 1241 (c-self-insert-command (prefix-numeric-value arg))
1256 (self-insert-command (prefix-numeric-value arg)))
1257 1242
1258 (if (and (not arg) (not literal)) 1243 (if (and (not arg) (not literal))
1259 (let* ( ;; We want to inhibit blinking the paren since this will 1244 (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 (insert-and-inherit "} catch ("))) 1288 (insert-and-inherit "} catch (")))
1304 1289
1305 ;; Apply `electric-pair-mode' stuff. 1290 ;; Apply `electric-pair-mode' stuff.
1306 (unless c--disable-fix-of-bug-33794 1291 (when (and c-auto-newline
1307 (when (and (boundp 'electric-pair-mode) 1292 (boundp 'electric-pair-mode)
1308 electric-pair-mode) 1293 electric-pair-mode)
1309 (let (post-self-insert-hook) 1294 (let (post-self-insert-hook)
1310 (electric-pair-post-self-insert-function)))) 1295 (electric-pair-post-self-insert-function)))
1311 1296
1312 ;; Check for clean-ups at function calls. These two DON'T need 1297 ;; Check for clean-ups at function calls. These two DON'T need
1313 ;; `c-electric-flag' or `c-syntactic-indentation' set. 1298 ;; `c-electric-flag' or `c-syntactic-indentation' set.
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index b55d889f0b5..5a4b20ed04e 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -47,14 +47,10 @@
47 (declare (indent defun) (debug t)) 47 (declare (indent defun) (debug t))
48 `(call-with-saved-electric-modes #'(lambda () ,@body))) 48 `(call-with-saved-electric-modes #'(lambda () ,@body)))
49 49
50;; Defined in lisp/progmodes/cc-cmds.el
51(defvar c--disable-fix-of-bug-33794 t)
52
53(defun electric-pair-test-for (fixture where char expected-string 50(defun electric-pair-test-for (fixture where char expected-string
54 expected-point mode bindings fixture-fn) 51 expected-point mode bindings fixture-fn)
55 (with-temp-buffer 52 (with-temp-buffer
56 (funcall mode) 53 (funcall mode)
57 (setq-local c--disable-fix-of-bug-33794 t)
58 (insert fixture) 54 (insert fixture)
59 (save-electric-modes 55 (save-electric-modes
60 (let ((last-command-event char) 56 (let ((last-command-event char)
@@ -825,7 +821,6 @@ baz\"\""
825 (electric-layout-local-mode 1) 821 (electric-layout-local-mode 1)
826 (electric-pair-local-mode 1) 822 (electric-pair-local-mode 1)
827 (electric-indent-local-mode 1) 823 (electric-indent-local-mode 1)
828 (setq-local c--disable-fix-of-bug-33794 t)
829 (setq-local electric-layout-rules 824 (setq-local electric-layout-rules
830 '((?\{ . (after-stay after)))) 825 '((?\{ . (after-stay after))))
831 (insert "int main () ") 826 (insert "int main () ")
@@ -839,7 +834,6 @@ baz\"\""
839 (electric-layout-local-mode 1) 834 (electric-layout-local-mode 1)
840 (electric-pair-local-mode 1) 835 (electric-pair-local-mode 1)
841 (electric-indent-local-mode 1) 836 (electric-indent-local-mode 1)
842 (setq-local c--disable-fix-of-bug-33794 t)
843 (setq-local electric-layout-rules 837 (setq-local electric-layout-rules
844 '((?\{ . (before after-stay after)))) 838 '((?\{ . (before after-stay after))))
845 (insert "int main () ") 839 (insert "int main () ")