diff options
| author | Alan Mackenzie | 2010-04-12 15:15:07 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2010-04-12 15:15:07 +0000 |
| commit | 7af4bf3aea19289d47e46d9007e786ac1956bcb7 (patch) | |
| tree | c9420c3fded77359f838757c4940390fc4e1cace | |
| parent | e2387bdba28af0022a4d63d024a8f16546001612 (diff) | |
| download | emacs-7af4bf3aea19289d47e46d9007e786ac1956bcb7.tar.gz emacs-7af4bf3aea19289d47e46d9007e786ac1956bcb7.zip | |
Reverse change 2010-02-04T21:15:37Z!acm@muc.de: "Change strategy for marking < and > as template
delimiters: mark them strictly in matching pairs."
| -rw-r--r-- | lisp/ChangeLog | 27 | ||||
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 152 | ||||
| -rw-r--r-- | lisp/progmodes/cc-defs.el | 38 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 171 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 55 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 24 |
6 files changed, 114 insertions, 353 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f155bbee4fc..35198619654 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -695,33 +695,6 @@ | |||
| 695 | (doc-view-pdf->png): Don't rely on doc-view-pdf/ps->png for the few | 695 | (doc-view-pdf->png): Don't rely on doc-view-pdf/ps->png for the few |
| 696 | windows that are not yet showing images. | 696 | windows that are not yet showing images. |
| 697 | 697 | ||
| 698 | 2010-02-04 Alan Mackenzie <acm@muc.de> | ||
| 699 | |||
| 700 | Change strategy for marking < and > as template delimiters: mark | ||
| 701 | them strictly in matching pairs. | ||
| 702 | |||
| 703 | * cc-mode.el (c-before-change): | ||
| 704 | Use c-get-state-before-change-functions. | ||
| 705 | (c-common-init): Adapt to use | ||
| 706 | c-get-state-before-change-functions (note plural). | ||
| 707 | |||
| 708 | * cc-langs.el (c-no-parens-syntax-table): New syntax table, used | ||
| 709 | for searching syntactically for matching <s and >s. | ||
| 710 | (c-get-state-before-change-functions): New language variable (note | ||
| 711 | the plural) which supersedes c-get-state-before-change-function. | ||
| 712 | |||
| 713 | * cc-engine.el (c-clear-<-pair-props, c-clear->-pair-props) | ||
| 714 | (c-clear-<>-pair-props, c-clear-<-pair-props-if-match-after) | ||
| 715 | (c-clear->-pair-props-if-match-before) | ||
| 716 | (c-before-change-check-<>-operators): New functions. | ||
| 717 | (c-after-change-check-<>-operators): Use macro | ||
| 718 | c-unmark-<->-as-paren. | ||
| 719 | |||
| 720 | * cc-defs.el (c-search-backward-char-property): New macro. | ||
| 721 | |||
| 722 | * cc-cmds.el (c-electric-lt-gt): Do not set text properties on < | ||
| 723 | and > any more. (These will be handled by font locking.) | ||
| 724 | |||
| 725 | 2010-02-04 Michael Albinus <michael.albinus@gmx.de> | 698 | 2010-02-04 Michael Albinus <michael.albinus@gmx.de> |
| 726 | 699 | ||
| 727 | * dired.el (dired-revert): If DIRED-DIRECTORY is a cons cell, call | 700 | * dired.el (dired-revert): If DIRED-DIRECTORY is a cons cell, call |
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 56fc8032541..4eade6edf58 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -1086,76 +1086,104 @@ numeric argument is supplied, or the point is inside a literal." | |||
| 1086 | 1086 | ||
| 1087 | (interactive "*P") | 1087 | (interactive "*P") |
| 1088 | (let ((c-echo-syntactic-information-p nil) | 1088 | (let ((c-echo-syntactic-information-p nil) |
| 1089 | final-pos close-paren-inserted found-delim) | 1089 | final-pos close-paren-inserted) |
| 1090 | 1090 | ||
| 1091 | (self-insert-command (prefix-numeric-value arg)) | 1091 | (self-insert-command (prefix-numeric-value arg)) |
| 1092 | (setq final-pos (point)) | 1092 | (setq final-pos (point)) |
| 1093 | 1093 | ||
| 1094 | ;;;; 2010-01-31: There used to be code here to put a syntax-table text | 1094 | (c-save-buffer-state (c-parse-and-markup-<>-arglists |
| 1095 | ;;;; property on the new < or > and its mate (if any) when they are template | 1095 | c-restricted-<>-arglists |
| 1096 | ;;;; parens. This is now done in an after-change function. | 1096 | <-pos) |
| 1097 | 1097 | ||
| 1098 | ;; Indent the line if appropriate. | 1098 | (when c-recognize-<>-arglists |
| 1099 | (when (and c-electric-flag c-syntactic-indentation c-recognize-<>-arglists) | 1099 | (if (eq last-command-event ?<) |
| 1100 | (setq found-delim | 1100 | (when (and (progn |
| 1101 | (if (eq last-command-event ?<) | 1101 | (backward-char) |
| 1102 | ;; If a <, basically see if it's got "template" before it ..... | 1102 | (= (point) |
| 1103 | (or (and (progn | 1103 | (progn |
| 1104 | (backward-char) | 1104 | (c-beginning-of-current-token) |
| 1105 | (= (point) | 1105 | (point)))) |
| 1106 | (progn (c-beginning-of-current-token) (point)))) | ||
| 1107 | (progn | ||
| 1108 | (c-backward-token-2) | ||
| 1109 | (looking-at c-opt-<>-sexp-key))) | ||
| 1110 | ;; ..... or is a C++ << operator. | ||
| 1111 | (and (c-major-mode-is 'c++-mode) | ||
| 1112 | (progn | ||
| 1113 | (goto-char (1- final-pos)) | ||
| 1114 | (c-beginning-of-current-token) | ||
| 1115 | (looking-at "<<")) | ||
| 1116 | (>= (match-end 0) final-pos))) | ||
| 1117 | |||
| 1118 | ;; It's a >. Either a C++ >> operator. ...... | ||
| 1119 | (or (and (c-major-mode-is 'c++-mode) | ||
| 1120 | (progn | 1106 | (progn |
| 1121 | (goto-char (1- final-pos)) | 1107 | (c-backward-token-2) |
| 1122 | (c-beginning-of-current-token) | 1108 | (looking-at c-opt-<>-sexp-key))) |
| 1123 | (looking-at ">>")) | 1109 | (c-mark-<-as-paren (1- final-pos))) |
| 1124 | (>= (match-end 0) final-pos)) | 1110 | |
| 1125 | ;; ...., or search back for a < which isn't already marked as an | 1111 | ;; It's a ">". Check if there's an earlier "<" which either has |
| 1126 | ;; opening template delimiter. | 1112 | ;; open paren syntax already or that can be recognized as an arglist |
| 1127 | (save-restriction | 1113 | ;; together with this ">". Note that this won't work in cases like |
| 1128 | (widen) | 1114 | ;; "template <x, a < b, y>" but they ought to be rare. |
| 1129 | ;; Narrow to avoid `c-forward-<>-arglist' below searching past | 1115 | |
| 1130 | ;; our position. | 1116 | (save-restriction |
| 1131 | (narrow-to-region (point-min) final-pos) | 1117 | ;; Narrow to avoid that `c-forward-<>-arglist' below searches past |
| 1132 | (goto-char final-pos) | 1118 | ;; our position. |
| 1133 | (while | 1119 | (narrow-to-region (point-min) final-pos) |
| 1134 | (and | 1120 | |
| 1135 | (progn | 1121 | (while (and |
| 1136 | (c-syntactic-skip-backward "^<;}" nil t) | 1122 | (progn |
| 1137 | (eq (char-before) ?<)) | 1123 | (goto-char final-pos) |
| 1138 | (progn | 1124 | (c-syntactic-skip-backward "^<;}" nil t) |
| 1139 | (backward-char) | 1125 | (eq (char-before) ?<)) |
| 1140 | (looking-at "\\s\(")))) | 1126 | (progn |
| 1141 | (and (eq (char-after) ?<) | 1127 | (backward-char) |
| 1142 | (not (looking-at "\\s\(")) | 1128 | ;; If the "<" already got open paren syntax we know we |
| 1143 | (progn (c-backward-syntactic-ws) | 1129 | ;; have the matching closer. Handle it and exit the |
| 1144 | (c-simple-skip-symbol-backward)) | 1130 | ;; loop. |
| 1145 | (or (looking-at c-opt-<>-sexp-key) | 1131 | (if (looking-at "\\s\(") |
| 1146 | (not (looking-at c-keywords-regexp))))))))) | 1132 | (progn |
| 1133 | (c-mark->-as-paren (1- final-pos)) | ||
| 1134 | (setq close-paren-inserted t) | ||
| 1135 | nil) | ||
| 1136 | t)) | ||
| 1147 | 1137 | ||
| 1138 | (progn | ||
| 1139 | (setq <-pos (point)) | ||
| 1140 | (c-backward-syntactic-ws) | ||
| 1141 | (c-simple-skip-symbol-backward)) | ||
| 1142 | (or (looking-at c-opt-<>-sexp-key) | ||
| 1143 | (not (looking-at c-keywords-regexp))) | ||
| 1144 | |||
| 1145 | (let ((c-parse-and-markup-<>-arglists t) | ||
| 1146 | c-restricted-<>-arglists | ||
| 1147 | (containing-sexp | ||
| 1148 | (c-most-enclosing-brace (c-parse-state)))) | ||
| 1149 | (when (and containing-sexp | ||
| 1150 | (progn (goto-char containing-sexp) | ||
| 1151 | (eq (char-after) ?\()) | ||
| 1152 | (not (eq (get-text-property (point) 'c-type) | ||
| 1153 | 'c-decl-arg-start))) | ||
| 1154 | (setq c-restricted-<>-arglists t)) | ||
| 1155 | (goto-char <-pos) | ||
| 1156 | (c-forward-<>-arglist nil)) | ||
| 1157 | |||
| 1158 | ;; Loop here if the "<" we found above belongs to a nested | ||
| 1159 | ;; angle bracket sexp. When we start over we'll find the | ||
| 1160 | ;; previous or surrounding sexp. | ||
| 1161 | (if (< (point) final-pos) | ||
| 1162 | t | ||
| 1163 | (setq close-paren-inserted t) | ||
| 1164 | nil))))))) | ||
| 1148 | (goto-char final-pos) | 1165 | (goto-char final-pos) |
| 1149 | (when found-delim | 1166 | |
| 1150 | (indent-according-to-mode) | 1167 | ;; Indent the line if appropriate. |
| 1151 | (when (and (eq (char-before) ?>) | 1168 | (when (and c-electric-flag c-syntactic-indentation) |
| 1152 | (not executing-kbd-macro) | 1169 | (backward-char) |
| 1153 | blink-paren-function) | 1170 | (when (prog1 (or (looking-at "\\s\(\\|\\s\)") |
| 1154 | ;; Note: Most paren blink functions, such as the standard | 1171 | (and (c-major-mode-is 'c++-mode) |
| 1155 | ;; `blink-matching-open', currently doesn't handle paren chars | 1172 | (progn |
| 1156 | ;; marked with text properties very well. Maybe we should avoid | 1173 | (c-beginning-of-current-token) |
| 1157 | ;; this call for the time being? | 1174 | (looking-at "<<\\|>>")) |
| 1158 | (funcall blink-paren-function))))) | 1175 | (= (match-end 0) final-pos))) |
| 1176 | (goto-char final-pos)) | ||
| 1177 | (indent-according-to-mode))) | ||
| 1178 | |||
| 1179 | (when (and close-paren-inserted | ||
| 1180 | (not executing-kbd-macro) | ||
| 1181 | blink-paren-function) | ||
| 1182 | ;; Note: Most paren blink functions, such as the standard | ||
| 1183 | ;; `blink-matching-open', currently doesn't handle paren chars | ||
| 1184 | ;; marked with text properties very well. Maybe we should avoid | ||
| 1185 | ;; this call for the time being? | ||
| 1186 | (funcall blink-paren-function)))) | ||
| 1159 | 1187 | ||
| 1160 | (defun c-electric-paren (arg) | 1188 | (defun c-electric-paren (arg) |
| 1161 | "Insert a parenthesis. | 1189 | "Insert a parenthesis. |
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index 7eb0016ff43..bb91dee6ce8 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el | |||
| @@ -1029,44 +1029,6 @@ MODE is either a mode symbol or a list of mode symbols." | |||
| 1029 | ;; Emacs. | 1029 | ;; Emacs. |
| 1030 | `(remove-text-properties ,from ,to '(,property nil)))) | 1030 | `(remove-text-properties ,from ,to '(,property nil)))) |
| 1031 | 1031 | ||
| 1032 | (defmacro c-search-forward-char-property (property value &optional limit) | ||
| 1033 | "Search forward for a text-property PROPERTY having value VALUE. | ||
| 1034 | LIMIT bounds the search. The comparison is done with `equal'. | ||
| 1035 | |||
| 1036 | Leave point just after the character, and set the match data on | ||
| 1037 | this character, and return point. If VALUE isn't found, Return | ||
| 1038 | nil; point is then left undefined." | ||
| 1039 | `(let ((place (point))) | ||
| 1040 | (while | ||
| 1041 | (and | ||
| 1042 | (< place ,(or limit '(point-max))) | ||
| 1043 | (not (equal (get-text-property place ,property) ,value))) | ||
| 1044 | (setq place (next-single-property-change | ||
| 1045 | place ,property nil ,(or limit '(point-max))))) | ||
| 1046 | (when (< place ,(or limit '(point-max))) | ||
| 1047 | (goto-char place) | ||
| 1048 | (search-forward-regexp ".") ; to set the match-data. | ||
| 1049 | (point)))) | ||
| 1050 | |||
| 1051 | (defmacro c-search-backward-char-property (property value &optional limit) | ||
| 1052 | "Search backward for a text-property PROPERTY having value VALUE. | ||
| 1053 | LIMIT bounds the search. The comparison is done with `equal'. | ||
| 1054 | |||
| 1055 | Leave point just before the character, set the match data on this | ||
| 1056 | character, and return point. If VALUE isn't found, Return nil; | ||
| 1057 | point is then left undefined." | ||
| 1058 | `(let ((place (point))) | ||
| 1059 | (while | ||
| 1060 | (and | ||
| 1061 | (> place ,(or limit '(point-min))) | ||
| 1062 | (not (equal (get-text-property (1- place) ,property) ,value))) | ||
| 1063 | (setq place (previous-single-property-change | ||
| 1064 | place ,property nil ,(or limit '(point-min))))) | ||
| 1065 | (when (> place ,(or limit '(point-max))) | ||
| 1066 | (goto-char place) | ||
| 1067 | (search-backward-regexp ".") ; to set the match-data. | ||
| 1068 | (point)))) | ||
| 1069 | |||
| 1070 | (defun c-clear-char-property-with-value-function (from to property value) | 1032 | (defun c-clear-char-property-with-value-function (from to property value) |
| 1071 | "Remove all text-properties PROPERTY from the region (FROM, TO) | 1033 | "Remove all text-properties PROPERTY from the region (FROM, TO) |
| 1072 | which have the value VALUE, as tested by `equal'. These | 1034 | which have the value VALUE, as tested by `equal'. These |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 3b7f6e4ea0a..9d0af1d53ce 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -4880,168 +4880,7 @@ comment at the start of cc-engine.el for more info." | |||
| 4880 | ))) | 4880 | ))) |
| 4881 | 4881 | ||
| 4882 | 4882 | ||
| 4883 | ;; Setting and removing syntax properties on < and > in languages (C++ | 4883 | ;; Handling of small scale constructs like types and names. |
| 4884 | ;; and Java) where they can be template/generic delimiters as well as | ||
| 4885 | ;; their normal meaning of "less/greater than". | ||
| 4886 | |||
| 4887 | ;; Normally, < and > have syntax 'punctuation'. When they are found to | ||
| 4888 | ;; be delimiters, they are marked as such with the category properties | ||
| 4889 | ;; c-<-as-paren-syntax, c->-as-paren-syntax respectively. | ||
| 4890 | |||
| 4891 | ;; STRATEGY: | ||
| 4892 | ;; | ||
| 4893 | ;; It is impossible to determine with certainty whether a <..> pair in | ||
| 4894 | ;; C++ is two comparison operators or is template delimiters, unless | ||
| 4895 | ;; one duplicates a lot of a C++ compiler. For example, the following | ||
| 4896 | ;; code fragment: | ||
| 4897 | ;; | ||
| 4898 | ;; foo (a < b, c > d) ; | ||
| 4899 | ;; | ||
| 4900 | ;; could be a function call with two integer parameters (each a | ||
| 4901 | ;; relational expression), or it could be a constructor for class foo | ||
| 4902 | ;; taking one parameter d of templated type "a < b, c >". They are | ||
| 4903 | ;; somewhat easier to distinguish in Java. | ||
| 4904 | ;; | ||
| 4905 | ;; The strategy now (2010-01) adopted is to mark and unmark < and | ||
| 4906 | ;; > IN MATCHING PAIRS ONLY. [Previously, they were marked | ||
| 4907 | ;; individually when their context so indicated. This gave rise to | ||
| 4908 | ;; intractible problems when one of a matching pair was deleted, or | ||
| 4909 | ;; pulled into a literal.] | ||
| 4910 | ;; | ||
| 4911 | ;; At each buffer change, the syntax-table properties are removed in a | ||
| 4912 | ;; before-change function and reapplied, when needed, in an | ||
| 4913 | ;; after-change function. It is far more important that the | ||
| 4914 | ;; properties get removed when they they are spurious than that they | ||
| 4915 | ;; be present when wanted. | ||
| 4916 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 4917 | (defun c-clear-<-pair-props (&optional pos) | ||
| 4918 | ;; POS (default point) is at a < character. If it is marked with | ||
| 4919 | ;; open paren syntax-table text property, remove the property, | ||
| 4920 | ;; together with the close paren property on the matching > (if | ||
| 4921 | ;; any). | ||
| 4922 | (save-excursion | ||
| 4923 | (if pos | ||
| 4924 | (goto-char pos) | ||
| 4925 | (setq pos (point))) | ||
| 4926 | (when (equal (c-get-char-property (point) 'syntax-table) | ||
| 4927 | c-<-as-paren-syntax) | ||
| 4928 | (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,.. | ||
| 4929 | (c-go-list-forward)) | ||
| 4930 | (when (equal (c-get-char-property (1- (point)) 'syntax-table) | ||
| 4931 | c->-as-paren-syntax) ; should always be true. | ||
| 4932 | (c-clear-char-property (1- (point)) 'syntax-table)) | ||
| 4933 | (c-clear-char-property pos 'syntax-table)))) | ||
| 4934 | |||
| 4935 | (defun c-clear->-pair-props (&optional pos) | ||
| 4936 | ;; POS (default point) is at a > character. If it is marked with | ||
| 4937 | ;; close paren syntax-table property, remove the property, together | ||
| 4938 | ;; with the open paren property on the matching < (if any). | ||
| 4939 | (save-excursion | ||
| 4940 | (if pos | ||
| 4941 | (goto-char pos) | ||
| 4942 | (setq pos (point))) | ||
| 4943 | (when (equal (c-get-char-property (point) 'syntax-table) | ||
| 4944 | c->-as-paren-syntax) | ||
| 4945 | (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,.. | ||
| 4946 | (c-go-up-list-backward)) | ||
| 4947 | (when (equal (c-get-char-property (point) 'syntax-table) | ||
| 4948 | c-<-as-paren-syntax) ; should always be true. | ||
| 4949 | (c-clear-char-property (point) 'syntax-table)) | ||
| 4950 | (c-clear-char-property pos 'syntax-table)))) | ||
| 4951 | |||
| 4952 | (defun c-clear-<>-pair-props (&optional pos) | ||
| 4953 | ;; POS (default point) is at a < or > character. If it has an | ||
| 4954 | ;; open/close paren syntax-table property, remove this property both | ||
| 4955 | ;; from the current character and its partner (which will also be | ||
| 4956 | ;; thusly marked). | ||
| 4957 | (cond | ||
| 4958 | ((eq (char-after) ?\<) | ||
| 4959 | (c-clear-<-pair-props pos)) | ||
| 4960 | ((eq (char-after) ?\>) | ||
| 4961 | (c-clear->-pair-props pos)) | ||
| 4962 | (t (c-benign-error | ||
| 4963 | "c-clear-<>-pair-props called from wrong position")))) | ||
| 4964 | |||
| 4965 | (defun c-clear-<-pair-props-if-match-after (lim &optional pos) | ||
| 4966 | ;; POS (default point) is at a < character. If it is both marked | ||
| 4967 | ;; with open/close paren syntax-table property, and has a matching > | ||
| 4968 | ;; (also marked) which is after LIM, remove the property both from | ||
| 4969 | ;; the current > and its partner. | ||
| 4970 | (save-excursion | ||
| 4971 | (if pos | ||
| 4972 | (goto-char pos) | ||
| 4973 | (setq pos (point))) | ||
| 4974 | (when (equal (c-get-char-property (point) 'syntax-table) | ||
| 4975 | c-<-as-paren-syntax) | ||
| 4976 | (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,.. | ||
| 4977 | (c-go-list-forward)) | ||
| 4978 | (when (and (>= (point) lim) | ||
| 4979 | (equal (c-get-char-property (1- (point)) 'syntax-table) | ||
| 4980 | c->-as-paren-syntax)) ; should always be true. | ||
| 4981 | (c-unmark-<->-as-paren (1- (point))) | ||
| 4982 | (c-unmark-<->-as-paren pos))))) | ||
| 4983 | |||
| 4984 | (defun c-clear->-pair-props-if-match-before (lim &optional pos) | ||
| 4985 | ;; POS (default point) is at a > character. If it is both marked | ||
| 4986 | ;; with open/close paren syntax-table property, and has a matching < | ||
| 4987 | ;; (also marked) which is before LIM, remove the property both from | ||
| 4988 | ;; the current < and its partner. | ||
| 4989 | (save-excursion | ||
| 4990 | (if pos | ||
| 4991 | (goto-char pos) | ||
| 4992 | (setq pos (point))) | ||
| 4993 | (when (equal (c-get-char-property (point) 'syntax-table) | ||
| 4994 | c->-as-paren-syntax) | ||
| 4995 | (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,.. | ||
| 4996 | (c-go-up-list-backward)) | ||
| 4997 | (when (and (<= (point) lim) | ||
| 4998 | (equal (c-get-char-property (point) 'syntax-table) | ||
| 4999 | c-<-as-paren-syntax)) ; should always be true. | ||
| 5000 | (c-unmark-<->-as-paren (point)) | ||
| 5001 | (c-unmark-<->-as-paren pos))))) | ||
| 5002 | |||
| 5003 | (defun c-before-change-check-<>-operators (beg end) | ||
| 5004 | ;; Unmark certain pairs of "< .... >" which are currently marked as | ||
| 5005 | ;; template/generic delimiters. (This marking is via syntax-table | ||
| 5006 | ;; text properties). | ||
| 5007 | ;; | ||
| 5008 | ;; These pairs are those which are in the current "statement" (i.e., | ||
| 5009 | ;; the region between the {, }, or ; before BEG and the one after | ||
| 5010 | ;; END), and which enclose any part of the interval (BEG END). | ||
| 5011 | ;; | ||
| 5012 | ;; Note that in C++ (?and Java), template/generic parens cannot | ||
| 5013 | ;; enclose a brace or semicolon, so we use these as bounds on the | ||
| 5014 | ;; region we must work on. | ||
| 5015 | ;; | ||
| 5016 | ;; This function is called from before-change-functions (via | ||
| 5017 | ;; c-get-state-before-change-functions). Thus the buffer is widened, | ||
| 5018 | ;; and point is undefined, both at entry and exit. | ||
| 5019 | ;; | ||
| 5020 | ;; FIXME!!! This routine ignores the possibility of macros entirely. | ||
| 5021 | ;; 2010-01-29. | ||
| 5022 | (save-excursion | ||
| 5023 | (let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits))) | ||
| 5024 | (end-lit-limits (progn (goto-char end) (c-literal-limits)))) | ||
| 5025 | ;; Locate the barrier before the changed region | ||
| 5026 | (goto-char (if beg-lit-limits (car beg-lit-limits) beg)) | ||
| 5027 | (c-syntactic-skip-backward "^;{}" (max (- beg 2048) (point-min))) | ||
| 5028 | |||
| 5029 | ;; Remove the syntax-table properties from each pertinent <...> pair. | ||
| 5030 | ;; Firsly, the ones with the < before beg and > after beg. | ||
| 5031 | (while (c-search-forward-char-property 'category 'c-<-as-paren-syntax beg) | ||
| 5032 | (c-clear-<-pair-props-if-match-after beg (1- (point)))) | ||
| 5033 | |||
| 5034 | ;; Locate the barrier after END. | ||
| 5035 | (goto-char (if end-lit-limits (cdr end-lit-limits) end)) | ||
| 5036 | (c-syntactic-re-search-forward "[;{}]" | ||
| 5037 | (min (+ end 2048) (point-max)) 'end) | ||
| 5038 | |||
| 5039 | ;; Remove syntax-table properties from the remaining pertinent <...> | ||
| 5040 | ;; pairs, those with a > after end and < before end. | ||
| 5041 | (while (c-search-backward-char-property 'category 'c->-as-paren-syntax end) | ||
| 5042 | (c-clear->-pair-props-if-match-before end))))) | ||
| 5043 | |||
| 5044 | |||
| 5045 | 4884 | ||
| 5046 | (defun c-after-change-check-<>-operators (beg end) | 4885 | (defun c-after-change-check-<>-operators (beg end) |
| 5047 | ;; This is called from `after-change-functions' when | 4886 | ;; This is called from `after-change-functions' when |
| @@ -5063,7 +4902,7 @@ comment at the start of cc-engine.el for more info." | |||
| 5063 | (< beg (setq beg (match-end 0)))) | 4902 | (< beg (setq beg (match-end 0)))) |
| 5064 | (while (progn (skip-chars-forward "^<>" beg) | 4903 | (while (progn (skip-chars-forward "^<>" beg) |
| 5065 | (< (point) beg)) | 4904 | (< (point) beg)) |
| 5066 | (c-clear-<>-pair-props) | 4905 | (c-clear-char-property (point) 'syntax-table) |
| 5067 | (forward-char)))) | 4906 | (forward-char)))) |
| 5068 | 4907 | ||
| 5069 | (when (< beg end) | 4908 | (when (< beg end) |
| @@ -5078,13 +4917,9 @@ comment at the start of cc-engine.el for more info." | |||
| 5078 | (< end (setq end (match-end 0)))) | 4917 | (< end (setq end (match-end 0)))) |
| 5079 | (while (progn (skip-chars-forward "^<>" end) | 4918 | (while (progn (skip-chars-forward "^<>" end) |
| 5080 | (< (point) end)) | 4919 | (< (point) end)) |
| 5081 | (c-clear-<>-pair-props) | 4920 | (c-clear-char-property (point) 'syntax-table) |
| 5082 | (forward-char))))))) | 4921 | (forward-char))))))) |
| 5083 | 4922 | ||
| 5084 | |||
| 5085 | |||
| 5086 | ;; Handling of small scale constructs like types and names. | ||
| 5087 | |||
| 5088 | ;; Dynamically bound variable that instructs `c-forward-type' to also | 4923 | ;; Dynamically bound variable that instructs `c-forward-type' to also |
| 5089 | ;; treat possible types (i.e. those that it normally returns 'maybe or | 4924 | ;; treat possible types (i.e. those that it normally returns 'maybe or |
| 5090 | ;; 'found for) as actual types (and always return 'found for them). | 4925 | ;; 'found for) as actual types (and always return 'found for them). |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index d3669f259de..e4c61b32a25 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -391,27 +391,6 @@ The syntax tables aren't stored directly since they're quite large." | |||
| 391 | (and (c-lang-const c++-make-template-syntax-table) | 391 | (and (c-lang-const c++-make-template-syntax-table) |
| 392 | (funcall (c-lang-const c++-make-template-syntax-table)))) | 392 | (funcall (c-lang-const c++-make-template-syntax-table)))) |
| 393 | 393 | ||
| 394 | (c-lang-defconst c-no-parens-syntax-table | ||
| 395 | ;; A variant of the standard syntax table which is used to find matching | ||
| 396 | ;; "<"s and ">"s which have been marked as parens using syntax table | ||
| 397 | ;; properties. The other paren characters (e.g. "{", ")" "]") are given a | ||
| 398 | ;; non-paren syntax here. so that the list commands will work on "< ... >" | ||
| 399 | ;; even when there's unbalanced other parens inside them. | ||
| 400 | ;; | ||
| 401 | ;; This variable is nil for languages which don't have template stuff. | ||
| 402 | t `(lambda () | ||
| 403 | (if (c-lang-const c-recognize-<>-arglists) | ||
| 404 | (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table)))) | ||
| 405 | (modify-syntax-entry ?\( "." table) | ||
| 406 | (modify-syntax-entry ?\) "." table) | ||
| 407 | (modify-syntax-entry ?\[ "." table) | ||
| 408 | (modify-syntax-entry ?\] "." table) | ||
| 409 | (modify-syntax-entry ?\{ "." table) | ||
| 410 | (modify-syntax-entry ?\} "." table) | ||
| 411 | table)))) | ||
| 412 | (c-lang-defvar c-no-parens-syntax-table | ||
| 413 | (funcall (c-lang-const c-no-parens-syntax-table))) | ||
| 414 | |||
| 415 | (c-lang-defconst c-identifier-syntax-modifications | 394 | (c-lang-defconst c-identifier-syntax-modifications |
| 416 | "A list that describes the modifications that should be done to the | 395 | "A list that describes the modifications that should be done to the |
| 417 | mode syntax table to get a syntax table that matches all identifiers | 396 | mode syntax table to get a syntax table that matches all identifiers |
| @@ -444,36 +423,26 @@ the new syntax, as accepted by `modify-syntax-entry'." | |||
| 444 | classifies symbol constituents like '_' and '$' as word constituents, | 423 | classifies symbol constituents like '_' and '$' as word constituents, |
| 445 | so that all identifiers are recognized as words.") | 424 | so that all identifiers are recognized as words.") |
| 446 | 425 | ||
| 447 | (c-lang-defconst c-get-state-before-change-functions | 426 | (c-lang-defconst c-get-state-before-change-function |
| 448 | ;; For documentation see the following c-lang-defvar of the same name. | 427 | "If non-nil, a function called from c-before-change-hook. |
| 449 | ;; The value here may be a list of functions or a single function. | 428 | Typically it will record enough state to allow |
| 450 | t nil | ||
| 451 | c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators) | ||
| 452 | (c objc) 'c-extend-region-for-CPP | ||
| 453 | ;; java 'c-before-change-check-<>-operators | ||
| 454 | awk 'c-awk-record-region-clear-NL) | ||
| 455 | (c-lang-defvar c-get-state-before-change-functions | ||
| 456 | (let ((fs (c-lang-const c-get-state-before-change-functions))) | ||
| 457 | (if (listp fs) | ||
| 458 | fs | ||
| 459 | (list fs))) | ||
| 460 | "If non-nil, a list of functions called from c-before-change-hook. | ||
| 461 | Typically these will record enough state to allow | ||
| 462 | `c-before-font-lock-function' to extend the region to fontify, | 429 | `c-before-font-lock-function' to extend the region to fontify, |
| 463 | and may do such things as removing text-properties which must be | 430 | and may do such things as removing text-properties which must be |
| 464 | recalculated. | 431 | recalculated. |
| 465 | 432 | ||
| 466 | These functions will be run in the order given. Each of them | 433 | It takes 2 parameters, the BEG and END supplied to every |
| 467 | takes 2 parameters, the BEG and END supplied to every | ||
| 468 | before-change function; on entry, the buffer will have been | 434 | before-change function; on entry, the buffer will have been |
| 469 | widened and match-data will have been saved; point is undefined | 435 | widened and match-data will have been saved; point is undefined |
| 470 | on both entry and exit; the return value is ignored. | 436 | on both entry and exit; the return value is ignored. |
| 471 | 437 | ||
| 472 | The functions are called even when font locking isn't enabled. | 438 | When the mode is initialized, this function is called with |
| 473 | 439 | parameters \(point-min) and \(point-max)." | |
| 474 | When the mode is initialized, the functions are called with | 440 | t nil |
| 475 | parameters \(point-min) and \(point-max).") | 441 | (c c++ objc) 'c-extend-region-for-CPP |
| 476 | 442 | awk 'c-awk-record-region-clear-NL) | |
| 443 | (c-lang-defvar c-get-state-before-change-function | ||
| 444 | (c-lang-const c-get-state-before-change-function)) | ||
| 445 | |||
| 477 | (c-lang-defconst c-before-font-lock-function | 446 | (c-lang-defconst c-before-font-lock-function |
| 478 | "If non-nil, a function called just before font locking. | 447 | "If non-nil, a function called just before font locking. |
| 479 | Typically it will extend the region about to be fontified \(see | 448 | Typically it will extend the region about to be fontified \(see |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 57f87c04b88..91fc29cdfa8 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -641,12 +641,8 @@ compatible with old code; callers should always specify it." | |||
| 641 | (save-restriction | 641 | (save-restriction |
| 642 | (widen) | 642 | (widen) |
| 643 | (save-excursion | 643 | (save-excursion |
| 644 | (if c-get-state-before-change-functions | 644 | (if c-get-state-before-change-function |
| 645 | (let ((beg (point-min)) | 645 | (funcall c-get-state-before-change-function (point-min) (point-max))) |
| 646 | (end (point-max))) | ||
| 647 | (mapc (lambda (fn) | ||
| 648 | (funcall fn beg end)) | ||
| 649 | c-get-state-before-change-functions))) | ||
| 650 | (if c-before-font-lock-function | 646 | (if c-before-font-lock-function |
| 651 | (funcall c-before-font-lock-function (point-min) (point-max) | 647 | (funcall c-before-font-lock-function (point-min) (point-max) |
| 652 | (- (point-max) (point-min)))))) | 648 | (- (point-max) (point-min)))))) |
| @@ -779,7 +775,7 @@ Note that the style variables are always made local to the buffer." | |||
| 779 | 775 | ||
| 780 | (defmacro c-run-mode-hooks (&rest hooks) | 776 | (defmacro c-run-mode-hooks (&rest hooks) |
| 781 | ;; Emacs 21.1 has introduced a system with delayed mode hooks that | 777 | ;; Emacs 21.1 has introduced a system with delayed mode hooks that |
| 782 | ;; requires the use of the new function `run-mode-hooks'. | 778 | ;; require the use of the new function `run-mode-hooks'. |
| 783 | (if (cc-bytecomp-fboundp 'run-mode-hooks) | 779 | (if (cc-bytecomp-fboundp 'run-mode-hooks) |
| 784 | `(run-mode-hooks ,@hooks) | 780 | `(run-mode-hooks ,@hooks) |
| 785 | `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) | 781 | `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) |
| @@ -812,8 +808,8 @@ Note that the style variables are always made local to the buffer." | |||
| 812 | ;; has already been widened, and match-data saved. The return value is | 808 | ;; has already been widened, and match-data saved. The return value is |
| 813 | ;; meaningless. | 809 | ;; meaningless. |
| 814 | ;; | 810 | ;; |
| 815 | ;; This function is in the C/C++/ObjC values of | 811 | ;; This function is the C/C++/ObjC value of |
| 816 | ;; `c-get-state-before-change-functions' and is called exclusively as a | 812 | ;; `c-get-state-before-change-function' and is called exclusively as a |
| 817 | ;; before change function. | 813 | ;; before change function. |
| 818 | (goto-char beg) | 814 | (goto-char beg) |
| 819 | (c-beginning-of-macro) | 815 | (c-beginning-of-macro) |
| @@ -926,8 +922,8 @@ Note that the style variables are always made local to the buffer." | |||
| 926 | ))))) | 922 | ))))) |
| 927 | 923 | ||
| 928 | (defun c-before-change (beg end) | 924 | (defun c-before-change (beg end) |
| 929 | ;; Function to be put on `before-change-functions'. Primarily, this calls | 925 | ;; Function to be put on `before-change-function'. Primarily, this calls |
| 930 | ;; the language dependent `c-get-state-before-change-functions'. It is | 926 | ;; the language dependent `c-get-state-before-change-function'. It is |
| 931 | ;; otherwise used only to remove stale entries from the `c-found-types' | 927 | ;; otherwise used only to remove stale entries from the `c-found-types' |
| 932 | ;; cache, and to record entries which a `c-after-change' function might | 928 | ;; cache, and to record entries which a `c-after-change' function might |
| 933 | ;; confirm as stale. | 929 | ;; confirm as stale. |
| @@ -1005,10 +1001,8 @@ Note that the style variables are always made local to the buffer." | |||
| 1005 | ;; larger than (beg end). | 1001 | ;; larger than (beg end). |
| 1006 | (setq c-new-BEG beg | 1002 | (setq c-new-BEG beg |
| 1007 | c-new-END end) | 1003 | c-new-END end) |
| 1008 | (if c-get-state-before-change-functions | 1004 | (if c-get-state-before-change-function |
| 1009 | (mapc (lambda (fn) | 1005 | (funcall c-get-state-before-change-function beg end)) |
| 1010 | (funcall fn beg end)) | ||
| 1011 | c-get-state-before-change-functions)) | ||
| 1012 | )))) | 1006 | )))) |
| 1013 | 1007 | ||
| 1014 | (defun c-after-change (beg end old-len) | 1008 | (defun c-after-change (beg end old-len) |