aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2019-01-17 18:47:00 +0000
committerJoão Távora2019-01-17 18:49:10 +0000
commitbe505726b68d407a44fdcd9c7ac1ef722398532d (patch)
tree5e9255f212aceadaa64a9bb3a431a26776cb9353
parent4bdc03746915c36313b33b6998b855eef514cdd1 (diff)
downloademacs-be505726b68d407a44fdcd9c7ac1ef722398532d.tar.gz
emacs-be505726b68d407a44fdcd9c7ac1ef722398532d.zip
Fix electric-pair-tests by disabling bug#33794's fix with a variable
The variable c--disable-fix-of-bug-33794, which should be removed in the short term in favor of a permanent solution, is introduced. It is bound to nil by default. This means that breakage is still happening in actual c-mode and c++-mode usage, though the tests no longer show it. To get around this breakage, put (setq c--disable-fix-of-bug-33794 t) In your init file. Evidently, you will lose the fix for bug#33794, but that only affects a small corner case of c-toggle-auto-newline, which is not turned on by default. See https://lists.gnu.org/archive/html/emacs-devel/2019-01/msg00360.html for more information. * lisp/progmodes/cc-cmds.el (c--disable-fix-of-bug-33794): New variable. (c--with-post-self-insert-hook-maybe): New macro. (c-electric-pound, c-electric-brace, c-electric-slash) (c-electric-star, c-electric-semi&comma, c-electric-colon) (c-electric-lt-gt, c-electric-paren): Use it. (c-electric-paren, c-electric-brace): Check c--disable-fix-of-bug-33794. * test/lisp/electric-tests.el (c--disable-fix-of-bug-33794): Forward declare. (electric-pair-test-for) (electric-layout-int-main-kernel-style) (electric-modes-in-c-mode-with-self-insert-command): Use it.
-rw-r--r--lisp/progmodes/cc-cmds.el96
-rw-r--r--test/lisp/electric-tests.el6
2 files changed, 62 insertions, 40 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 78677fefadb..6b0d9617667 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -485,6 +485,20 @@ 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
489 "If non-nil disable alans controversional fix of 33794.
490This fix breaks most features of `electric-pair-mode' by
491incompletely reimplementing in in this mode.")
492
493(defmacro c--with-post-self-insert-hook-maybe (&rest body)
494 `(let ((post-self-insert-hook
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
488(defun c-electric-pound (arg) 502(defun c-electric-pound (arg)
489 "Insert a \"#\". 503 "Insert a \"#\".
490If `c-electric-flag' is set, handle it specially according to the variable 504If `c-electric-flag' is set, handle it specially according to the variable
@@ -504,7 +518,7 @@ inside a literal or a macro, nothing special happens."
504 (eq (char-before) ?\\)))) 518 (eq (char-before) ?\\))))
505 (c-in-literal))) 519 (c-in-literal)))
506 ;; do nothing special 520 ;; do nothing special
507 (let (post-self-insert-hook) ; Disable random functionality. 521 (c--with-post-self-insert-hook-maybe
508 (self-insert-command (prefix-numeric-value arg))) 522 (self-insert-command (prefix-numeric-value arg)))
509 ;; place the pound character at the left edge 523 ;; place the pound character at the left edge
510 (let ((pos (- (point-max) (point))) 524 (let ((pos (- (point-max) (point)))
@@ -857,36 +871,38 @@ settings of `c-cleanup-list' are done."
857 871
858 ;; Insert the brace. Note that expand-abbrev might reindent 872 ;; Insert the brace. Note that expand-abbrev might reindent
859 ;; the line here if there's a preceding "else" or something. 873 ;; the line here if there's a preceding "else" or something.
860 (let (post-self-insert-hook) ; the only way to get defined functionality 874 (c--with-post-self-insert-hook-maybe
861 ; from `self-insert-command'. 875 (self-insert-command (prefix-numeric-value arg)))
862 (self-insert-command (prefix-numeric-value arg)))
863 876
864 ;; Emulate `electric-pair-mode'. 877 ;; Emulate `electric-pair-mode'.
865 (when (and (boundp 'electric-pair-mode) 878 (unless c--disable-fix-of-bug-33794
866 electric-pair-mode) 879 (when (and (boundp 'electric-pair-mode)
867 (let ((size (buffer-size)) 880 electric-pair-mode)
868 (c-in-electric-pair-functionality t) 881 (let ((size (buffer-size))
869 post-self-insert-hook) 882 (c-in-electric-pair-functionality t)
870 (electric-pair-post-self-insert-function) 883 post-self-insert-hook)
871 (setq got-pair-} (and at-eol 884 (electric-pair-post-self-insert-function)
872 (eq (c-last-command-char) ?{) 885 (setq got-pair-} (and at-eol
873 (eq (char-after) ?})) 886 (eq (c-last-command-char) ?{)
874 electric-pair-deletion (< (buffer-size) size)))) 887 (eq (char-after) ?}))
875 888 electric-pair-deletion (< (buffer-size) size))))
876 ;; Perform any required CC Mode electric actions. 889
877 (cond 890 ;; Perform any required CC Mode electric actions.
878 ((or literal arg (not c-electric-flag) active-region)) 891 (cond
879 ((not at-eol) 892 ((or literal arg (not c-electric-flag) active-region))
880 (c-indent-line)) 893 ((not at-eol)
881 (electric-pair-deletion 894 (c-indent-line))
882 (c-indent-line) 895 (electric-pair-deletion
883 (c-do-brace-electrics 'ignore nil)) 896 (c-indent-line)
884 (t (c-do-brace-electrics nil nil) 897 (c-do-brace-electrics 'ignore nil))
885 (when got-pair-} 898 (t (c-do-brace-electrics nil nil)
886 (save-excursion 899 (when got-pair-}
887 (forward-char) 900 (save-excursion
888 (c-do-brace-electrics 'assume 'ignore)) 901 (forward-char)
889 (c-indent-line)))) 902 (c-do-brace-electrics 'assume 'ignore))
903 (c-indent-line)))))
904
905
890 906
891 ;; blink the paren 907 ;; blink the paren
892 (and (eq (c-last-command-char) ?\}) 908 (and (eq (c-last-command-char) ?\})
@@ -944,7 +960,7 @@ is inhibited."
944 c-electric-flag 960 c-electric-flag
945 (eq (c-last-command-char) ?/) 961 (eq (c-last-command-char) ?/)
946 (eq (char-before) (if literal ?* ?/)))) 962 (eq (char-before) (if literal ?* ?/))))
947 (let (post-self-insert-hook) ; Disable random functionality. 963 (c--with-post-self-insert-hook-maybe
948 (self-insert-command (prefix-numeric-value arg))) 964 (self-insert-command (prefix-numeric-value arg)))
949 (if indentp 965 (if indentp
950 (indent-according-to-mode)))) 966 (indent-according-to-mode))))
@@ -958,7 +974,7 @@ supplied, point is inside a literal, or `c-syntactic-indentation' is nil,
958this indentation is inhibited." 974this indentation is inhibited."
959 975
960 (interactive "*P") 976 (interactive "*P")
961 (let (post-self-insert-hook) ; Disable random functionality. 977 (c--with-post-self-insert-hook-maybe
962 (self-insert-command (prefix-numeric-value arg))) 978 (self-insert-command (prefix-numeric-value arg)))
963 ;; if we are in a literal, or if arg is given do not reindent the 979 ;; if we are in a literal, or if arg is given do not reindent the
964 ;; current line, unless this star introduces a comment-only line. 980 ;; current line, unless this star introduces a comment-only line.
@@ -1006,7 +1022,7 @@ settings of `c-cleanup-list'."
1006 (setq lim (c-most-enclosing-brace (c-parse-state)) 1022 (setq lim (c-most-enclosing-brace (c-parse-state))
1007 literal (c-in-literal lim))) 1023 literal (c-in-literal lim)))
1008 1024
1009 (let (post-self-insert-hook) ; Disable random functionality. 1025 (c--with-post-self-insert-hook-maybe
1010 (self-insert-command (prefix-numeric-value arg))) 1026 (self-insert-command (prefix-numeric-value arg)))
1011 1027
1012 (if (and c-electric-flag (not literal) (not arg)) 1028 (if (and c-electric-flag (not literal) (not arg))
@@ -1076,7 +1092,7 @@ reindented unless `c-syntactic-indentation' is nil.
1076 newlines is-scope-op 1092 newlines is-scope-op
1077 ;; shut this up 1093 ;; shut this up
1078 (c-echo-syntactic-information-p nil)) 1094 (c-echo-syntactic-information-p nil))
1079 (let (post-self-insert-hook) ; Disable random functionality. 1095 (c--with-post-self-insert-hook-maybe
1080 (self-insert-command (prefix-numeric-value arg))) 1096 (self-insert-command (prefix-numeric-value arg)))
1081 ;; Any electric action? 1097 ;; Any electric action?
1082 (if (and c-electric-flag (not literal) (not arg)) 1098 (if (and c-electric-flag (not literal) (not arg))
@@ -1170,7 +1186,7 @@ numeric argument is supplied, or the point is inside a literal."
1170 (let ((c-echo-syntactic-information-p nil) 1186 (let ((c-echo-syntactic-information-p nil)
1171 final-pos found-delim case-fold-search) 1187 final-pos found-delim case-fold-search)
1172 1188
1173 (let (post-self-insert-hook) ; Disable random functionality. 1189 (c--with-post-self-insert-hook-maybe
1174 (self-insert-command (prefix-numeric-value arg))) 1190 (self-insert-command (prefix-numeric-value arg)))
1175 (setq final-pos (point)) 1191 (setq final-pos (point))
1176 1192
@@ -1236,8 +1252,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
1236 ;; shut this up 1252 ;; shut this up
1237 (c-echo-syntactic-information-p nil) 1253 (c-echo-syntactic-information-p nil)
1238 case-fold-search) 1254 case-fold-search)
1239 (let (post-self-insert-hook) ; The only way to get defined functionality 1255 (c--with-post-self-insert-hook-maybe
1240 ; from `self-insert-command'.
1241 (self-insert-command (prefix-numeric-value arg))) 1256 (self-insert-command (prefix-numeric-value arg)))
1242 1257
1243 (if (and (not arg) (not literal)) 1258 (if (and (not arg) (not literal))
@@ -1288,10 +1303,11 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
1288 (insert-and-inherit "} catch ("))) 1303 (insert-and-inherit "} catch (")))
1289 1304
1290 ;; Apply `electric-pair-mode' stuff. 1305 ;; Apply `electric-pair-mode' stuff.
1291 (when (and (boundp 'electric-pair-mode) 1306 (unless c--disable-fix-of-bug-33794
1292 electric-pair-mode) 1307 (when (and (boundp 'electric-pair-mode)
1293 (let (post-self-insert-hook) 1308 electric-pair-mode)
1294 (electric-pair-post-self-insert-function))) 1309 (let (post-self-insert-hook)
1310 (electric-pair-post-self-insert-function))))
1295 1311
1296 ;; Check for clean-ups at function calls. These two DON'T need 1312 ;; Check for clean-ups at function calls. These two DON'T need
1297 ;; `c-electric-flag' or `c-syntactic-indentation' set. 1313 ;; `c-electric-flag' or `c-syntactic-indentation' set.
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 5a4b20ed04e..b55d889f0b5 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -47,10 +47,14 @@
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
50(defun electric-pair-test-for (fixture where char expected-string 53(defun electric-pair-test-for (fixture where char expected-string
51 expected-point mode bindings fixture-fn) 54 expected-point mode bindings fixture-fn)
52 (with-temp-buffer 55 (with-temp-buffer
53 (funcall mode) 56 (funcall mode)
57 (setq-local c--disable-fix-of-bug-33794 t)
54 (insert fixture) 58 (insert fixture)
55 (save-electric-modes 59 (save-electric-modes
56 (let ((last-command-event char) 60 (let ((last-command-event char)
@@ -821,6 +825,7 @@ baz\"\""
821 (electric-layout-local-mode 1) 825 (electric-layout-local-mode 1)
822 (electric-pair-local-mode 1) 826 (electric-pair-local-mode 1)
823 (electric-indent-local-mode 1) 827 (electric-indent-local-mode 1)
828 (setq-local c--disable-fix-of-bug-33794 t)
824 (setq-local electric-layout-rules 829 (setq-local electric-layout-rules
825 '((?\{ . (after-stay after)))) 830 '((?\{ . (after-stay after))))
826 (insert "int main () ") 831 (insert "int main () ")
@@ -834,6 +839,7 @@ baz\"\""
834 (electric-layout-local-mode 1) 839 (electric-layout-local-mode 1)
835 (electric-pair-local-mode 1) 840 (electric-pair-local-mode 1)
836 (electric-indent-local-mode 1) 841 (electric-indent-local-mode 1)
842 (setq-local c--disable-fix-of-bug-33794 t)
837 (setq-local electric-layout-rules 843 (setq-local electric-layout-rules
838 '((?\{ . (before after-stay after)))) 844 '((?\{ . (before after-stay after))))
839 (insert "int main () ") 845 (insert "int main () ")