aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-01-20 20:34:33 +0000
committerAlan Mackenzie2019-01-22 14:30:30 +0000
commitf97b734ffb2b70f3d94e46453a236b46e0704901 (patch)
tree15ec915608d4917259bb7470db6455c5dbfeb8d4
parent6038fdb2f9eac3225c0651fee18e1e75e63f2409 (diff)
downloademacs-f97b734ffb2b70f3d94e46453a236b46e0704901.tar.gz
emacs-f97b734ffb2b70f3d94e46453a236b46e0704901.zip
Revert "Fix electric-pair-tests by disabling bug#33794's fix with a variable"
This reverts commit be505726b68d407a44fdcd9c7ac1ef722398532d.
-rw-r--r--lisp/progmodes/cc-cmds.el96
-rw-r--r--test/lisp/electric-tests.el6
2 files changed, 40 insertions, 62 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 6b0d9617667..78677fefadb 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -485,20 +485,6 @@ 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
502(defun c-electric-pound (arg) 488(defun c-electric-pound (arg)
503 "Insert a \"#\". 489 "Insert a \"#\".
504If `c-electric-flag' is set, handle it specially according to the variable 490If `c-electric-flag' is set, handle it specially according to the variable
@@ -518,7 +504,7 @@ inside a literal or a macro, nothing special happens."
518 (eq (char-before) ?\\)))) 504 (eq (char-before) ?\\))))
519 (c-in-literal))) 505 (c-in-literal)))
520 ;; do nothing special 506 ;; do nothing special
521 (c--with-post-self-insert-hook-maybe 507 (let (post-self-insert-hook) ; Disable random functionality.
522 (self-insert-command (prefix-numeric-value arg))) 508 (self-insert-command (prefix-numeric-value arg)))
523 ;; place the pound character at the left edge 509 ;; place the pound character at the left edge
524 (let ((pos (- (point-max) (point))) 510 (let ((pos (- (point-max) (point)))
@@ -871,38 +857,36 @@ settings of `c-cleanup-list' are done."
871 857
872 ;; Insert the brace. Note that expand-abbrev might reindent 858 ;; Insert the brace. Note that expand-abbrev might reindent
873 ;; the line here if there's a preceding "else" or something. 859 ;; the line here if there's a preceding "else" or something.
874 (c--with-post-self-insert-hook-maybe 860 (let (post-self-insert-hook) ; the only way to get defined functionality
875 (self-insert-command (prefix-numeric-value arg))) 861 ; from `self-insert-command'.
862 (self-insert-command (prefix-numeric-value arg)))
876 863
877 ;; Emulate `electric-pair-mode'. 864 ;; Emulate `electric-pair-mode'.
878 (unless c--disable-fix-of-bug-33794 865 (when (and (boundp 'electric-pair-mode)
879 (when (and (boundp 'electric-pair-mode) 866 electric-pair-mode)
880 electric-pair-mode) 867 (let ((size (buffer-size))
881 (let ((size (buffer-size)) 868 (c-in-electric-pair-functionality t)
882 (c-in-electric-pair-functionality t) 869 post-self-insert-hook)
883 post-self-insert-hook) 870 (electric-pair-post-self-insert-function)
884 (electric-pair-post-self-insert-function) 871 (setq got-pair-} (and at-eol
885 (setq got-pair-} (and at-eol 872 (eq (c-last-command-char) ?{)
886 (eq (c-last-command-char) ?{) 873 (eq (char-after) ?}))
887 (eq (char-after) ?})) 874 electric-pair-deletion (< (buffer-size) size))))
888 electric-pair-deletion (< (buffer-size) size)))) 875
889 876 ;; Perform any required CC Mode electric actions.
890 ;; Perform any required CC Mode electric actions. 877 (cond
891 (cond 878 ((or literal arg (not c-electric-flag) active-region))
892 ((or literal arg (not c-electric-flag) active-region)) 879 ((not at-eol)
893 ((not at-eol) 880 (c-indent-line))
894 (c-indent-line)) 881 (electric-pair-deletion
895 (electric-pair-deletion 882 (c-indent-line)
896 (c-indent-line) 883 (c-do-brace-electrics 'ignore nil))
897 (c-do-brace-electrics 'ignore nil)) 884 (t (c-do-brace-electrics nil nil)
898 (t (c-do-brace-electrics nil nil) 885 (when got-pair-}
899 (when got-pair-} 886 (save-excursion
900 (save-excursion 887 (forward-char)
901 (forward-char) 888 (c-do-brace-electrics 'assume 'ignore))
902 (c-do-brace-electrics 'assume 'ignore)) 889 (c-indent-line))))
903 (c-indent-line)))))
904
905
906 890
907 ;; blink the paren 891 ;; blink the paren
908 (and (eq (c-last-command-char) ?\}) 892 (and (eq (c-last-command-char) ?\})
@@ -960,7 +944,7 @@ is inhibited."
960 c-electric-flag 944 c-electric-flag
961 (eq (c-last-command-char) ?/) 945 (eq (c-last-command-char) ?/)
962 (eq (char-before) (if literal ?* ?/)))) 946 (eq (char-before) (if literal ?* ?/))))
963 (c--with-post-self-insert-hook-maybe 947 (let (post-self-insert-hook) ; Disable random functionality.
964 (self-insert-command (prefix-numeric-value arg))) 948 (self-insert-command (prefix-numeric-value arg)))
965 (if indentp 949 (if indentp
966 (indent-according-to-mode)))) 950 (indent-according-to-mode))))
@@ -974,7 +958,7 @@ supplied, point is inside a literal, or `c-syntactic-indentation' is nil,
974this indentation is inhibited." 958this indentation is inhibited."
975 959
976 (interactive "*P") 960 (interactive "*P")
977 (c--with-post-self-insert-hook-maybe 961 (let (post-self-insert-hook) ; Disable random functionality.
978 (self-insert-command (prefix-numeric-value arg))) 962 (self-insert-command (prefix-numeric-value arg)))
979 ;; if we are in a literal, or if arg is given do not reindent the 963 ;; 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. 964 ;; current line, unless this star introduces a comment-only line.
@@ -1022,7 +1006,7 @@ settings of `c-cleanup-list'."
1022 (setq lim (c-most-enclosing-brace (c-parse-state)) 1006 (setq lim (c-most-enclosing-brace (c-parse-state))
1023 literal (c-in-literal lim))) 1007 literal (c-in-literal lim)))
1024 1008
1025 (c--with-post-self-insert-hook-maybe 1009 (let (post-self-insert-hook) ; Disable random functionality.
1026 (self-insert-command (prefix-numeric-value arg))) 1010 (self-insert-command (prefix-numeric-value arg)))
1027 1011
1028 (if (and c-electric-flag (not literal) (not arg)) 1012 (if (and c-electric-flag (not literal) (not arg))
@@ -1092,7 +1076,7 @@ reindented unless `c-syntactic-indentation' is nil.
1092 newlines is-scope-op 1076 newlines is-scope-op
1093 ;; shut this up 1077 ;; shut this up
1094 (c-echo-syntactic-information-p nil)) 1078 (c-echo-syntactic-information-p nil))
1095 (c--with-post-self-insert-hook-maybe 1079 (let (post-self-insert-hook) ; Disable random functionality.
1096 (self-insert-command (prefix-numeric-value arg))) 1080 (self-insert-command (prefix-numeric-value arg)))
1097 ;; Any electric action? 1081 ;; Any electric action?
1098 (if (and c-electric-flag (not literal) (not arg)) 1082 (if (and c-electric-flag (not literal) (not arg))
@@ -1186,7 +1170,7 @@ numeric argument is supplied, or the point is inside a literal."
1186 (let ((c-echo-syntactic-information-p nil) 1170 (let ((c-echo-syntactic-information-p nil)
1187 final-pos found-delim case-fold-search) 1171 final-pos found-delim case-fold-search)
1188 1172
1189 (c--with-post-self-insert-hook-maybe 1173 (let (post-self-insert-hook) ; Disable random functionality.
1190 (self-insert-command (prefix-numeric-value arg))) 1174 (self-insert-command (prefix-numeric-value arg)))
1191 (setq final-pos (point)) 1175 (setq final-pos (point))
1192 1176
@@ -1252,7 +1236,8 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
1252 ;; shut this up 1236 ;; shut this up
1253 (c-echo-syntactic-information-p nil) 1237 (c-echo-syntactic-information-p nil)
1254 case-fold-search) 1238 case-fold-search)
1255 (c--with-post-self-insert-hook-maybe 1239 (let (post-self-insert-hook) ; The only way to get defined functionality
1240 ; from `self-insert-command'.
1256 (self-insert-command (prefix-numeric-value arg))) 1241 (self-insert-command (prefix-numeric-value arg)))
1257 1242
1258 (if (and (not arg) (not literal)) 1243 (if (and (not arg) (not literal))
@@ -1303,11 +1288,10 @@ 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 (boundp 'electric-pair-mode)
1307 (when (and (boundp 'electric-pair-mode) 1292 electric-pair-mode)
1308 electric-pair-mode) 1293 (let (post-self-insert-hook)
1309 (let (post-self-insert-hook) 1294 (electric-pair-post-self-insert-function)))
1310 (electric-pair-post-self-insert-function))))
1311 1295
1312 ;; Check for clean-ups at function calls. These two DON'T need 1296 ;; Check for clean-ups at function calls. These two DON'T need
1313 ;; `c-electric-flag' or `c-syntactic-indentation' set. 1297 ;; `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 () ")