aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorAlan Mackenzie2010-04-13 09:15:14 +0000
committerAlan Mackenzie2010-04-13 09:15:14 +0000
commit34d203ef47b9c1064d34b939d6c29ef9e257815d (patch)
treed5bb2cb82cb15fb0976aec2de085d3be2fd2ca17 /lisp
parent79353a53a004be686d7358fde4f1c2dbb25406ab (diff)
parente42a330165c80c3024d730c6075ed59a94b4db46 (diff)
downloademacs-34d203ef47b9c1064d34b939d6c29ef9e257815d.tar.gz
emacs-34d203ef47b9c1064d34b939d6c29ef9e257815d.zip
Revert 2009-12-03T16:02:10Z!acm@muc.de (enhance c-parse-state) and 2010-02-04T21:15:37Z!acm@muc.de (< and > handling).
[These enhancements were not sufficiently stable at the time of releasing a pretest.]
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog52
-rw-r--r--lisp/progmodes/cc-cmds.el152
-rw-r--r--lisp/progmodes/cc-defs.el146
-rw-r--r--lisp/progmodes/cc-engine.el1522
-rw-r--r--lisp/progmodes/cc-fonts.el3
-rw-r--r--lisp/progmodes/cc-langs.el57
-rw-r--r--lisp/progmodes/cc-mode.el84
7 files changed, 431 insertions, 1585 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fe1e4b25878..35198619654 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -134,11 +134,6 @@
134 134
135 * indent.el (indent-for-tab-command): Doc fix. 135 * indent.el (indent-for-tab-command): Doc fix.
136 136
1372010-03-22 Alan Mackenzie <acm@muc.de>
138
139 * progmodes/cc-engine.el (c-remove-stale-state-cache):
140 Fix off-by-one error. Fixes bug #5747.
141
1422010-03-22 Juanma Barranquero <lekktu@gmail.com> 1372010-03-22 Juanma Barranquero <lekktu@gmail.com>
143 138
144 * image-dired.el (image-dired-display-thumbs): Fix typo in docstring. 139 * image-dired.el (image-dired-display-thumbs): Fix typo in docstring.
@@ -287,11 +282,6 @@
287 * calendar/cal-hebrew.el (holiday-hebrew-passover): Fix date 282 * calendar/cal-hebrew.el (holiday-hebrew-passover): Fix date
288 of Yom HaAtzma'ut when it falls on a Monday (rule changed in 2004). 283 of Yom HaAtzma'ut when it falls on a Monday (rule changed in 2004).
289 284
2902010-03-01 Alan Mackenzie <acm@muc.de>
291
292 * progmodes/cc-engine.el (c-remove-stale-state-cache):
293 Correct previous patch.
294
2952010-03-01 Kenichi Handa <handa@m17n.org> 2852010-03-01 Kenichi Handa <handa@m17n.org>
296 286
297 * language/burmese.el (burmese-composable-pattern): Rename from 287 * language/burmese.el (burmese-composable-pattern): Rename from
@@ -303,11 +293,6 @@
303 (otf-script-alist): Likewise. 293 (otf-script-alist): Likewise.
304 (setup-default-fontset): Likewise. Re-fix :otf spec. 294 (setup-default-fontset): Likewise. Re-fix :otf spec.
305 295
3062010-03-01 Alan Mackenzie <bug-cc-mode@gnu.org>
307
308 * cc-engine.el (c-remove-stale-state-cache): Take account of when
309 `good-pos' is in the same macro as `here'. Fixes bug#5649.
310
3112010-02-28 Katsumi Yamaoka <yamaoka@jpl.org> 2962010-02-28 Katsumi Yamaoka <yamaoka@jpl.org>
312 297
313 * menu-bar.el (menu-bar-manuals-menu): Fix typo. 298 * menu-bar.el (menu-bar-manuals-menu): Fix typo.
@@ -373,16 +358,6 @@
373 * mail/sendmail.el (send-mail-function): Autoload the call 358 * mail/sendmail.el (send-mail-function): Autoload the call
374 to custom-initialize-delay, not otherwise preserved in loaddefs.el. 359 to custom-initialize-delay, not otherwise preserved in loaddefs.el.
375 360
3762010-02-25 Alan Mackenzie <acm@muc.de>
377
378 * progmodes/cc-engine.el (c-clear-<-pair-props)
379 (c-clear->-pair-props): Correct to wipe category text props, not
380 syntax-table ones.
381
382 * progmodes/cc-mode.el (c-after-change): Remove any hard
383 syntax-table properties for <, > which, e.g., C-y has
384 inopportunely converted from category properties.
385
3862010-02-24 Chong Yidong <cyd@stupidchicken.com> 3612010-02-24 Chong Yidong <cyd@stupidchicken.com>
387 362
388 * files.el (hack-local-variables-filter): For eval forms, also 363 * files.el (hack-local-variables-filter): For eval forms, also
@@ -720,33 +695,6 @@
720 (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
721 windows that are not yet showing images. 696 windows that are not yet showing images.
722 697
7232010-02-04 Alan Mackenzie <acm@muc.de>
724
725 Change strategy for marking < and > as template delimiters: mark
726 them strictly in matching pairs.
727
728 * cc-mode.el (c-before-change):
729 Use c-get-state-before-change-functions.
730 (c-common-init): Adapt to use
731 c-get-state-before-change-functions (note plural).
732
733 * cc-langs.el (c-no-parens-syntax-table): New syntax table, used
734 for searching syntactically for matching <s and >s.
735 (c-get-state-before-change-functions): New language variable (note
736 the plural) which supersedes c-get-state-before-change-function.
737
738 * cc-engine.el (c-clear-<-pair-props, c-clear->-pair-props)
739 (c-clear-<>-pair-props, c-clear-<-pair-props-if-match-after)
740 (c-clear->-pair-props-if-match-before)
741 (c-before-change-check-<>-operators): New functions.
742 (c-after-change-check-<>-operators): Use macro
743 c-unmark-<->-as-paren.
744
745 * cc-defs.el (c-search-backward-char-property): New macro.
746
747 * cc-cmds.el (c-electric-lt-gt): Do not set text properties on <
748 and > any more. (These will be handled by font locking.)
749
7502010-02-04 Michael Albinus <michael.albinus@gmx.de> 6982010-02-04 Michael Albinus <michael.albinus@gmx.de>
751 699
752 * 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..39036b743c6 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.
1034LIMIT bounds the search. The comparison is done with `equal'.
1035
1036Leave point just after the character, and set the match data on
1037this character, and return point. If VALUE isn't found, Return
1038nil; 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.
1053LIMIT bounds the search. The comparison is done with `equal'.
1054
1055Leave point just before the character, set the match data on this
1056character, and return point. If VALUE isn't found, Return nil;
1057point 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)
1072which have the value VALUE, as tested by `equal'. These 1034which have the value VALUE, as tested by `equal'. These
@@ -1183,117 +1145,23 @@ been put there by c-put-char-property. POINT remains unchanged."
1183 (goto-char (point-max))))) 1145 (goto-char (point-max)))))
1184 1146
1185(defconst c-<-as-paren-syntax '(4 . ?>)) 1147(defconst c-<-as-paren-syntax '(4 . ?>))
1186(put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax)
1187 1148
1188(defsubst c-mark-<-as-paren (pos) 1149(defsubst c-mark-<-as-paren (pos)
1189 ;; Mark the "<" character at POS as a template opener using the 1150 ;; Mark the "<" character at POS as an sexp list opener using the
1190 ;; `syntax-table' property via the `category' property. 1151 ;; syntax-table property.
1191 ;; 1152 ;;
1192 ;; This function does a hidden buffer change. Note that we use 1153 ;; This function does a hidden buffer change.
1193 ;; indirection through the `category' text property. This allows us to 1154 (c-put-char-property pos 'syntax-table c-<-as-paren-syntax))
1194 ;; toggle the property in all template brackets simultaneously and
1195 ;; cheaply. We use this, for instance, in `c-parse-state'.
1196 (c-put-char-property pos 'category 'c-<-as-paren-syntax))
1197 1155
1198(defconst c->-as-paren-syntax '(5 . ?<)) 1156(defconst c->-as-paren-syntax '(5 . ?<))
1199(put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax)
1200 1157
1201(defsubst c-mark->-as-paren (pos) 1158(defsubst c-mark->-as-paren (pos)
1202 ;; Mark the ">" character at POS as an sexp list closer using the 1159 ;; Mark the ">" character at POS as an sexp list closer using the
1203 ;; syntax-table property. 1160 ;; syntax-table property.
1204 ;; 1161 ;;
1205 ;; This function does a hidden buffer change. Note that we use 1162 ;; This function does a hidden buffer change.
1206 ;; indirection through the `category' text property. This allows us to 1163 (c-put-char-property pos 'syntax-table c->-as-paren-syntax))
1207 ;; toggle the property in all template brackets simultaneously and 1164
1208 ;; cheaply. We use this, for instance, in `c-parse-state'.
1209 (c-put-char-property pos 'category 'c->-as-paren-syntax))
1210
1211(defsubst c-unmark-<->-as-paren (pos)
1212 ;; Unmark the "<" or "<" character at POS as an sexp list opener using
1213 ;; the syntax-table property indirectly through the `category' text
1214 ;; property.
1215 ;;
1216 ;; This function does a hidden buffer change. Note that we use
1217 ;; indirection through the `category' text property. This allows us to
1218 ;; toggle the property in all template brackets simultaneously and
1219 ;; cheaply. We use this, for instance, in `c-parse-state'.
1220 (c-clear-char-property pos 'category))
1221
1222(defsubst c-suppress-<->-as-parens ()
1223 ;; Suppress the syntactic effect of all marked < and > as parens. Note
1224 ;; that this effect is NOT buffer local. You should probably not use
1225 ;; this directly, but only through the macro
1226 ;; `c-with-<->-as-parens-suppressed'
1227 (put 'c-<-as-paren-syntax 'syntax-table nil)
1228 (put 'c->-as-paren-syntax 'syntax-table nil))
1229
1230(defsubst c-restore-<->-as-parens ()
1231 ;; Restore the syntactic effect of all marked <s and >s as parens. This
1232 ;; has no effect on unmarked <s and >s
1233 (put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax)
1234 (put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax))
1235
1236(defmacro c-with-<->-as-parens-suppressed (&rest forms)
1237 ;; Like progn, except that the paren property is suppressed on all
1238 ;; template brackets whilst they are running. This macro does a hidden
1239 ;; buffer change.
1240 `(unwind-protect
1241 (progn
1242 (c-suppress-<->-as-parens)
1243 ,@forms)
1244 (c-restore-<->-as-parens)))
1245
1246;;;;;;;;;;;;;;;
1247
1248(defconst c-cpp-delimiter '(14)) ; generic comment syntax
1249;; This is the value of the `category' text property placed on every #
1250;; which introduces a CPP construct and every EOL (or EOB, or character
1251;; preceding //, etc.) which terminates it. We can instantly "comment
1252;; out" all CPP constructs by giving `c-cpp-delimiter' a syntax-table
1253;; propery '(14) (generic comment delimiter).
1254(defmacro c-set-cpp-delimiters (beg end)
1255 ;; This macro does a hidden buffer change.
1256 `(progn
1257 (c-put-char-property ,beg 'category 'c-cpp-delimiter)
1258 (if (< ,end (point-max))
1259 (c-put-char-property ,end 'category 'c-cpp-delimiter))))
1260(defmacro c-clear-cpp-delimiters (beg end)
1261 ;; This macro does a hidden buffer change.
1262 `(progn
1263 (c-clear-char-property ,beg 'category)
1264 (if (< ,end (point-max))
1265 (c-clear-char-property ,end 'category))))
1266
1267(defsubst c-comment-out-cpps ()
1268 ;; Render all preprocessor constructs syntactically commented out.
1269 (put 'c-cpp-delimiter 'syntax-table c-cpp-delimiter))
1270(defsubst c-uncomment-out-cpps ()
1271 ;; Restore the syntactic visibility of preprocessor constructs.
1272 (put 'c-cpp-delimiter 'syntax-table nil))
1273
1274(defmacro c-with-cpps-commented-out (&rest forms)
1275 ;; Execute FORMS... whilst the syntactic effect of all characters in
1276 ;; all CPP regions is suppressed. In particular, this is to suppress
1277 ;; the syntactic significance of parens/braces/brackets to functions
1278 ;; such as `scan-lists' and `parse-partial-sexp'.
1279 `(unwind-protect
1280 (c-save-buffer-state ()
1281 (c-comment-out-cpps)
1282 ,@forms)
1283 (c-save-buffer-state ()
1284 (c-uncomment-out-cpps))))
1285
1286(defmacro c-with-all-but-one-cpps-commented-out (beg end &rest forms)
1287 ;; Execute FORMS... whilst the syntactic effect of all characters in
1288 ;; every CPP region APART FROM THE ONE BETWEEN BEG and END is
1289 ;; suppressed.
1290 `(unwind-protect
1291 (c-save-buffer-state ()
1292 (c-clear-cpp-delimiters ,beg ,end)
1293 ,`(c-with-cpps-commented-out ,@forms))
1294 (c-save-buffer-state ()
1295 (c-set-cpp-delimiters ,beg ,end))))
1296
1297(defsubst c-intersect-lists (list alist) 1165(defsubst c-intersect-lists (list alist)
1298 ;; return the element of ALIST that matches the first element found 1166 ;; return the element of ALIST that matches the first element found
1299 ;; in LIST. Uses assq. 1167 ;; in LIST. Uses assq.
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 2d28d003fd5..9c04920a208 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -79,10 +79,6 @@
79;; Note: This doc is for internal use only. Other packages should not 79;; Note: This doc is for internal use only. Other packages should not
80;; assume that these text properties are used as described here. 80;; assume that these text properties are used as described here.
81;; 81;;
82;; 'category
83;; Used for "indirection". With its help, some other property can
84;; be cheaply and easily switched on or off everywhere it occurs.
85;;
86;; 'syntax-table 82;; 'syntax-table
87;; Used to modify the syntax of some characters. It is used to 83;; Used to modify the syntax of some characters. It is used to
88;; mark the "<" and ">" of angle bracket parens with paren syntax, and 84;; mark the "<" and ">" of angle bracket parens with paren syntax, and
@@ -260,27 +256,6 @@ comment at the start of cc-engine.el for more info."
260 (forward-char) 256 (forward-char)
261 t)))) 257 t))))
262 258
263(defun c-syntactic-end-of-macro ()
264 ;; Go to the end of a CPP directive, or a "safe" pos just before.
265 ;;
266 ;; This is normally the end of the next non-escaped line. A "safe"
267 ;; position is one not within a string or comment. (The EOL on a line
268 ;; comment is NOT "safe").
269 ;;
270 ;; This function must only be called from the beginning of a CPP construct.
271 ;;
272 ;; Note that this function might do hidden buffer changes. See the comment
273 ;; at the start of cc-engine.el for more info.
274 (let* ((here (point))
275 (there (progn (c-end-of-macro) (point)))
276 (s (parse-partial-sexp here there)))
277 (while (and (or (nth 3 s) ; in a string
278 (nth 4 s)) ; in a comment (maybe at end of line comment)
279 (> there here)) ; No infinite loops, please.
280 (setq there (1- (nth 8 s)))
281 (setq s (parse-partial-sexp here there)))
282 (point)))
283
284(defun c-forward-over-cpp-define-id () 259(defun c-forward-over-cpp-define-id ()
285 ;; Assuming point is at the "#" that introduces a preprocessor 260 ;; Assuming point is at the "#" that introduces a preprocessor
286 ;; directive, it's moved forward to the end of the identifier which is 261 ;; directive, it's moved forward to the end of the identifier which is
@@ -1972,18 +1947,10 @@ comment at the start of cc-engine.el for more info."
1972 1947
1973;; A system for finding noteworthy parens before the point. 1948;; A system for finding noteworthy parens before the point.
1974 1949
1975(defconst c-state-cache-too-far 5000)
1976;; A maximum comfortable scanning distance, e.g. between
1977;; `c-state-cache-good-pos' and "HERE" (where we call c-parse-state). When
1978;; this distance is exceeded, we take "emergency meausures", e.g. by clearing
1979;; the cache and starting again from point-min or a beginning of defun. This
1980;; value can be tuned for efficiency or set to a lower value for testing.
1981
1982(defvar c-state-cache nil) 1950(defvar c-state-cache nil)
1983(make-variable-buffer-local 'c-state-cache) 1951(make-variable-buffer-local 'c-state-cache)
1984;; The state cache used by `c-parse-state' to cut down the amount of 1952;; The state cache used by `c-parse-state' to cut down the amount of
1985;; searching. It's the result from some earlier `c-parse-state' call. See 1953;; searching. It's the result from some earlier `c-parse-state' call.
1986;; `c-parse-state''s doc string for details of its structure.
1987;; 1954;;
1988;; The use of the cached info is more effective if the next 1955;; The use of the cached info is more effective if the next
1989;; `c-parse-state' call is on a line close by the one the cached state 1956;; `c-parse-state' call is on a line close by the one the cached state
@@ -1992,12 +1959,18 @@ comment at the start of cc-engine.el for more info."
1992;; most effective if `c-parse-state' is used on each line while moving 1959;; most effective if `c-parse-state' is used on each line while moving
1993;; forward. 1960;; forward.
1994 1961
1962(defvar c-state-cache-start 1)
1963(make-variable-buffer-local 'c-state-cache-start)
1964;; This is (point-min) when `c-state-cache' was calculated, since a
1965;; change of narrowing is likely to affect the parens that are visible
1966;; before the point.
1967
1995(defvar c-state-cache-good-pos 1) 1968(defvar c-state-cache-good-pos 1)
1996(make-variable-buffer-local 'c-state-cache-good-pos) 1969(make-variable-buffer-local 'c-state-cache-good-pos)
1997;; This is a position where `c-state-cache' is known to be correct, or 1970;; This is a position where `c-state-cache' is known to be correct.
1998;; nil (see below). It's a position inside one of the recorded unclosed 1971;; It's a position inside one of the recorded unclosed parens or the
1999;; parens or the top level, but not further nested inside any literal or 1972;; top level, but not further nested inside any literal or subparen
2000;; subparen that is closed before the last recorded position. 1973;; that is closed before the last recorded position.
2001;; 1974;;
2002;; The exact position is chosen to try to be close to yet earlier than 1975;; The exact position is chosen to try to be close to yet earlier than
2003;; the position where `c-state-cache' will be called next. Right now 1976;; the position where `c-state-cache' will be called next. Right now
@@ -2005,1057 +1978,313 @@ comment at the start of cc-engine.el for more info."
2005;; closing paren (of any type) before the line on which 1978;; closing paren (of any type) before the line on which
2006;; `c-parse-state' was called. That is chosen primarily to work well 1979;; `c-parse-state' was called. That is chosen primarily to work well
2007;; with refontification of the current line. 1980;; with refontification of the current line.
2008;;
2009;; 2009-07-28: When `c-state-point-min' and the last position where
2010;; `c-parse-state' or for which `c-invalidate-state-cache' was called, are
2011;; both in the same literal, there is no such "good position", and
2012;; c-state-cache-good-pos is then nil. This is the ONLY circumstance in which
2013;; it can be nil. In this case, `c-state-point-min-literal' will be non-nil.
2014;;
2015;; 2009-06-12: In a brace desert, c-state-cache-good-pos may also be in
2016;; the middle of the desert, as long as it is not within a brace pair
2017;; recorded in `c-state-cache' or a paren/bracket pair.
2018
2019
2020;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2021;; We maintain a simple cache of positions which aren't in a literal, so as to
2022;; speed up testing for non-literality.
2023(defconst c-state-nonlit-pos-interval 10000)
2024;; The approximate interval between entries in `c-state-nonlit-pos-cache'.
2025
2026(defvar c-state-nonlit-pos-cache nil)
2027(make-variable-buffer-local 'c-state-nonlit-pos-cache)
2028;; A list of buffer positions which are known not to be in a literal. This is
2029;; ordered with higher positions at the front of the list. Only those which
2030;; are less than `c-state-nonlit-pos-cache-limit' are valid.
2031
2032(defvar c-state-nonlit-pos-cache-limit 1)
2033(make-variable-buffer-local 'c-state-nonlit-pos-cache-limit)
2034;; An upper limit on valid entries in `c-state-nonlit-pos-cache'. This is
2035;; reduced by buffer changes, and increased by invocations of
2036;; `c-state-literal-at'.
2037
2038(defsubst c-state-pp-to-literal (from to)
2039 ;; Do a parse-partial-sexp from FROM to TO, returning the bounds of any
2040 ;; literal at TO as a cons, otherwise NIL.
2041 ;; FROM must not be in a literal, and the buffer should already be wide
2042 ;; enough.
2043 (save-excursion
2044 (let ((s (parse-partial-sexp from to)))
2045 (when (or (nth 3 s) (nth 4 s)) ; in a string or comment
2046 (parse-partial-sexp (point) (point-max)
2047 nil ; TARGETDEPTH
2048 nil ; STOPBEFORE
2049 s ; OLDSTATE
2050 'syntax-table) ; stop at end of literal
2051 (cons (nth 8 s) (point))))))
2052
2053(defun c-state-literal-at (here)
2054 ;; If position HERE is inside a literal, return (START . END), the
2055 ;; boundaries of the literal (which may be outside the accessible bit of the
2056 ;; buffer). Otherwise, return nil.
2057 ;;
2058 ;; This function is almost the same as `c-literal-limits'. It differs in
2059 ;; that it is a lower level function, and that it rigourously follows the
2060 ;; syntax from BOB, whereas `c-literal-limits' uses a "local" safe position.
2061 (save-restriction
2062 (widen)
2063 (save-excursion
2064 (let ((c c-state-nonlit-pos-cache)
2065 pos npos lit)
2066 ;; Trim the cache to take account of buffer changes.
2067 (while (and c (> (car c) c-state-nonlit-pos-cache-limit))
2068 (setq c (cdr c)))
2069 (setq c-state-nonlit-pos-cache c)
2070
2071 (while (and c (> (car c) here))
2072 (setq c (cdr c)))
2073 (setq pos (or (car c) (point-min)))
2074
2075 (while (<= (setq npos (+ pos c-state-nonlit-pos-interval))
2076 here)
2077 (setq lit (c-state-pp-to-literal pos npos))
2078 (setq pos (or (cdr lit) npos)) ; end of literal containing npos.
2079 (setq c-state-nonlit-pos-cache (cons pos c-state-nonlit-pos-cache)))
2080
2081 (if (> pos c-state-nonlit-pos-cache-limit)
2082 (setq c-state-nonlit-pos-cache-limit pos))
2083 (if (< pos here)
2084 (setq lit (c-state-pp-to-literal pos here)))
2085 lit))))
2086
2087(defsubst c-state-lit-beg (pos)
2088 ;; Return the start of the literal containing POS, or POS itself.
2089 (or (car (c-state-literal-at pos))
2090 pos))
2091
2092(defsubst c-state-cache-non-literal-place (pos state)
2093 ;; Return a position outside of a string/comment at or before POS.
2094 ;; STATE is the parse-partial-sexp state at POS.
2095 (if (or (nth 3 state) ; in a string?
2096 (nth 4 state)) ; in a comment?
2097 (nth 8 state)
2098 pos))
2099 1981
2100 1982(defsubst c-invalidate-state-cache (pos)
2101;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1983 ;; Invalidate all info on `c-state-cache' that applies to the buffer
2102;; Stuff to do with point-min, and coping with any literal there. 1984 ;; at POS or higher. This is much like `c-whack-state-after', but
2103(defvar c-state-point-min 1) 1985 ;; it never changes a paren pair element into an open paren element.
2104(make-variable-buffer-local 'c-state-point-min) 1986 ;; Doing that would mean that the new open paren wouldn't have the
2105;; This is (point-min) when `c-state-cache' was last calculated. A change of 1987 ;; required preceding paren pair element.
2106;; narrowing is likely to affect the parens that are visible before the point. 1988 (while (and (or c-state-cache
2107 1989 (when (< pos c-state-cache-good-pos)
2108(defvar c-state-point-min-lit-type nil) 1990 (setq c-state-cache-good-pos 1)
2109(make-variable-buffer-local 'c-state-point-min-lit-type) 1991 nil))
2110(defvar c-state-point-min-lit-start nil) 1992 (let ((elem (car c-state-cache)))
2111(make-variable-buffer-local 'c-state-point-min-lit-start) 1993 (if (consp elem)
2112;; These two variables define the literal, if any, containing point-min. 1994 (or (< pos (cdr elem))
2113;; Their values are, respectively, 'string, c, or c++, and the start of the 1995 (when (< pos c-state-cache-good-pos)
2114;; literal. If there's no literal there, they're both nil. 1996 (setq c-state-cache-good-pos (cdr elem))
2115 1997 nil))
2116(defvar c-state-min-scan-pos 1) 1998 (or (<= pos elem)
2117(make-variable-buffer-local 'c-state-min-scan-pos) 1999 (when (< pos c-state-cache-good-pos)
2118;; This is the earliest buffer-pos from which scanning can be done. It is 2000 (setq c-state-cache-good-pos (1+ elem))
2119;; either the end of the literal containing point-min, or point-min itself. 2001 nil)))))
2120;; It becomes nil if the buffer is changed earlier than this point. 2002 (setq c-state-cache (cdr c-state-cache))))
2121(defun c-state-get-min-scan-pos () 2003
2122 ;; Return the lowest valid scanning pos. This will be the end of the 2004(defun c-get-fallback-start-pos (here)
2123 ;; literal enclosing point-min, or point-min itself. 2005 ;; Return the start position for building `c-state-cache' from
2124 (or c-state-min-scan-pos 2006 ;; scratch.
2125 (save-restriction
2126 (save-excursion
2127 (widen)
2128 (goto-char c-state-point-min-lit-start)
2129 (if (eq c-state-point-min-lit-type 'string)
2130 (forward-sexp)
2131 (forward-comment 1))
2132 (setq c-state-min-scan-pos (point))))))
2133
2134(defun c-state-mark-point-min-literal ()
2135 ;; Determine the properties of any literal containing POINT-MIN, setting the
2136 ;; variables `c-state-point-min-lit-type', `c-state-point-min-lit-start',
2137 ;; and `c-state-min-scan-pos' accordingly. The return value is meaningless.
2138 (let ((p-min (point-min))
2139 lit)
2140 (save-restriction
2141 (widen)
2142 (setq lit (c-state-literal-at p-min))
2143 (if lit
2144 (setq c-state-point-min-lit-type
2145 (save-excursion
2146 (goto-char (car lit))
2147 (cond
2148 ((looking-at c-block-comment-start-regexp) 'c)
2149 ((looking-at c-line-comment-starter) 'c++)
2150 (t 'string)))
2151 c-state-point-min-lit-start (car lit)
2152 c-state-min-scan-pos (cdr lit))
2153 (setq c-state-point-min-lit-type nil
2154 c-state-point-min-lit-start nil
2155 c-state-min-scan-pos p-min)))))
2156
2157
2158;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2159;; A variable which signals a brace dessert - helpful for reducing the number
2160;; of fruitless backward scans.
2161(defvar c-state-brace-pair-desert nil)
2162(make-variable-buffer-local 'c-state-brace-pair-desert)
2163;; Used only in `c-append-lower-brace-pair-to-state-cache'. It is set when an
2164;; that defun has searched backwards for a brace pair and not found one. Its
2165;; value is either nil or a cons (PA . FROM), where PA is the position of the
2166;; enclosing opening paren/brace/bracket which bounds the backwards search (or
2167;; nil when at top level) and FROM is where the backward search started. It
2168;; is reset to nil in `c-invalidate-state-cache'.
2169
2170
2171;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2172;; Lowish level functions/macros which work directly on `c-state-cache', or a
2173;; list of like structure.
2174(defmacro c-state-cache-top-lparen (&optional cache)
2175 ;; Return the address of the top left brace/bracket/paren recorded in CACHE
2176 ;; (default `c-state-cache') (or nil).
2177 (let ((cash (or cache 'c-state-cache)))
2178 `(if (consp (car ,cash))
2179 (caar ,cash)
2180 (car ,cash))))
2181
2182(defmacro c-state-cache-top-paren (&optional cache)
2183 ;; Return the address of the latest brace/bracket/paren (whether left or
2184 ;; right) recorded in CACHE (default `c-state-cache') or nil.
2185 (let ((cash (or cache 'c-state-cache)))
2186 `(if (consp (car ,cash))
2187 (cdar ,cash)
2188 (car ,cash))))
2189
2190(defmacro c-state-cache-after-top-paren (&optional cache)
2191 ;; Return the position just after the latest brace/bracket/paren (whether
2192 ;; left or right) recorded in CACHE (default `c-state-cache') or nil.
2193 (let ((cash (or cache 'c-state-cache)))
2194 `(if (consp (car ,cash))
2195 (cdar ,cash)
2196 (and (car ,cash)
2197 (1+ (car ,cash))))))
2198
2199(defun c-get-cache-scan-pos (here)
2200 ;; From the state-cache, determine the buffer position from which we might
2201 ;; scan forward to HERE to update this cache. This position will be just
2202 ;; after a paren/brace/bracket recorded in the cache, if possible, otherwise
2203 ;; return the earliest position in the accessible region which isn't within
2204 ;; a literal. If the visible portion of the buffer is entirely within a
2205 ;; literal, return NIL.
2206 (let ((c c-state-cache) elt)
2207 ;(while (>= (or (c-state-cache-top-lparen c) 1) here)
2208 (while (and c
2209 (>= (c-state-cache-top-lparen c) here))
2210 (setq c (cdr c)))
2211
2212 (setq elt (car c))
2213 (cond
2214 ((consp elt)
2215 (if (> (cdr elt) here)
2216 (1+ (car elt))
2217 (cdr elt)))
2218 (elt (1+ elt))
2219 ((<= (c-state-get-min-scan-pos) here)
2220 (c-state-get-min-scan-pos))
2221 (t nil))))
2222
2223;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2224;; Variables which keep track of preprocessor constructs.
2225(defvar c-state-old-cpp-beg nil)
2226(make-variable-buffer-local 'c-state-old-cpp-beg)
2227(defvar c-state-old-cpp-end nil)
2228(make-variable-buffer-local 'c-state-old-cpp-end)
2229;; These are the limits of the macro containing point at the previous call of
2230;; `c-parse-state', or nil.
2231
2232;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2233;; Defuns which analyse the buffer, yet don't change `c-state-cache'.
2234(defun c-get-fallback-scan-pos (here)
2235 ;; Return a start position for building `c-state-cache' from
2236 ;; scratch. This will be at the top level, 2 defuns back.
2237 (save-excursion 2007 (save-excursion
2238 ;; Go back 2 bods, but ignore any bogus positions returned by 2008 ;; Go back 2 bods, but ignore any bogus positions returned by
2239 ;; beginning-of-defun (i.e. open paren in column zero). 2009 ;; beginning-of-defun (i.e. open paren in column zero).
2240 (goto-char here) 2010 (goto-char here)
2241 (let ((cnt 2)) 2011 (let ((cnt 2))
2242 (while (not (or (bobp) (zerop cnt))) 2012 (while (not (or (bobp) (zerop cnt)))
2243 (c-beginning-of-defun-1) ; Pure elisp BOD. 2013 (c-beginning-of-defun-1)
2244 (if (eq (char-after) ?\{) 2014 (if (eq (char-after) ?\{)
2245 (setq cnt (1- cnt))))) 2015 (setq cnt (1- cnt)))))
2246 (point))) 2016 (point)))
2247 2017
2248(defun c-state-balance-parens-backwards (here top) 2018(defun c-parse-state ()
2249 ;; Return the position of the opening paren/brace/bracket before HERE which 2019 ;; Find and record all noteworthy parens between some good point
2250 ;; matches the outermost close p/b/b between HERE and TOP, like this: 2020 ;; earlier in the file and point. That good point is at least the
2251 ;; 2021 ;; beginning of the top-level construct we are in, or the beginning
2252 ;; ...................................... 2022 ;; of the preceding top-level construct if we aren't in one.
2253 ;; | | 2023 ;;
2254 ;; ( [ ( ........... ) ( ) ] ) 2024 ;; The returned value is a list of the noteworthy parens with the
2255 ;; ^ ^ ^ 2025 ;; last one first. If an element in the list is an integer, it's
2256 ;; | | | 2026 ;; the position of an open paren which has not been closed before
2257 ;; return HERE TOP 2027 ;; the point. If an element is a cons, it gives the position of a
2258 ;; 2028 ;; closed brace paren pair; the car is the start paren position and
2259 ;; If there aren't enough opening paren/brace/brackets, return the position 2029 ;; the cdr is the position following the closing paren. Only the
2260 ;; of the outermost one found, or HERE it there are none. If there are no 2030 ;; last closed brace paren pair before each open paren and before
2261 ;; closeing p/b/bs between HERE and TOP, return HERE. HERE and TOP must not 2031 ;; the point is recorded, and thus the state never contains two cons
2262 ;; be inside literals. Only the accessible portion of the buffer will be 2032 ;; elements in succession.
2263 ;; scanned.
2264
2265 ;; PART 1: scan from `here' up to `top', accumulating ")"s which enclose
2266 ;; `here'. Go round the next loop each time we pass over such a ")". These
2267 ;; probably match "("s before `here'.
2268 (let (pos pa ren+1 lonely-rens)
2269 (save-excursion
2270 (save-restriction
2271 (narrow-to-region (point-min) top) ; This can move point, sometimes.
2272 (setq pos here)
2273 (c-safe
2274 (while
2275 (setq ren+1 (scan-lists pos 1 1)) ; might signal
2276 (setq lonely-rens (cons ren+1 lonely-rens)
2277 pos ren+1)))))
2278
2279 ;; PART 2: Scan back before `here' searching for the "("s
2280 ;; matching/mismatching the ")"s found above. We only need to direct the
2281 ;; caller to scan when we've encountered unmatched right parens.
2282 (when lonely-rens
2283 (setq pos here)
2284 (c-safe
2285 (while
2286 (and lonely-rens ; actual values aren't used.
2287 (setq pa (scan-lists pos -1 1)))
2288 (setq pos pa)
2289 (setq lonely-rens (cdr lonely-rens)))) ;)
2290 )
2291 pos))
2292
2293(defun c-parse-state-get-strategy (here good-pos)
2294 ;; Determine the scanning strategy for adjusting `c-parse-state', attempting
2295 ;; to minimise the amount of scanning. HERE is the pertinent position in
2296 ;; the buffer, GOOD-POS is a position where `c-state-cache' (possibly with
2297 ;; its head trimmed) is known to be good, or nil if there is no such
2298 ;; position.
2299 ;;
2300 ;; The return value is a list, one of the following:
2301 ;;
2302 ;; o - ('forward CACHE-POS START-POINT) - scan forward from START-POINT,
2303 ;; which is not less than CACHE-POS.
2304 ;; o - ('backward CACHE-POS nil) - scan backwards (from HERE).
2305 ;; o - ('BOD nil START-POINT) - scan forwards from START-POINT, which is at the
2306 ;; top level.
2307 ;; o - ('IN-LIT nil nil) - point is inside the literal containing point-min.
2308 ;; , where CACHE-POS is the highest position recorded in `c-state-cache' at
2309 ;; or below HERE.
2310 (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1)
2311 BOD-pos ; position of 2nd BOD before HERE.
2312 strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT.
2313 start-point
2314 how-far) ; putative scanning distance.
2315 (setq good-pos (or good-pos (c-state-get-min-scan-pos)))
2316 (cond
2317 ((< here (c-state-get-min-scan-pos))
2318 (setq strategy 'IN-LIT
2319 start-point nil
2320 cache-pos nil
2321 how-far 0))
2322 ((<= good-pos here)
2323 (setq strategy 'forward
2324 start-point (max good-pos cache-pos)
2325 how-far (- here start-point)))
2326 ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting.
2327 (setq strategy 'backward
2328 how-far (- good-pos here)))
2329 (t
2330 (setq strategy 'forward
2331 how-far (- here cache-pos)
2332 start-point cache-pos)))
2333
2334 ;; Might we be better off starting from the top level, two defuns back,
2335 ;; instead?
2336 (when (> how-far c-state-cache-too-far)
2337 (setq BOD-pos (c-get-fallback-scan-pos here)) ; somewhat EXPENSIVE!!!
2338 (if (< (- here BOD-pos) how-far)
2339 (setq strategy 'BOD
2340 start-point BOD-pos)))
2341
2342 (list
2343 strategy
2344 (and (memq strategy '(forward backward)) cache-pos)
2345 (and (memq strategy '(forward BOD)) start-point))))
2346
2347
2348;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2349;; Routines which change `c-state-cache' and associated values.
2350(defun c-renarrow-state-cache ()
2351 ;; The region (more precisely, point-min) has changed since we
2352 ;; calculated `c-state-cache'. Amend `c-state-cache' accordingly.
2353 (if (< (point-min) c-state-point-min)
2354 ;; If point-min has MOVED BACKWARDS then we drop the state completely.
2355 ;; It would be possible to do a better job here and recalculate the top
2356 ;; only.
2357 (progn
2358 (c-state-mark-point-min-literal)
2359 (setq c-state-cache nil
2360 c-state-cache-good-pos c-state-min-scan-pos
2361 c-state-brace-pair-desert nil))
2362
2363 ;; point-min has MOVED FORWARD.
2364
2365 ;; Is the new point-min inside a (different) literal?
2366 (unless (and c-state-point-min-lit-start ; at prev. point-min
2367 (< (point-min) (c-state-get-min-scan-pos)))
2368 (c-state-mark-point-min-literal))
2369
2370 ;; Cut off a bit of the tail from `c-state-cache'.
2371 (let ((ptr (cons nil c-state-cache))
2372 pa)
2373 (while (and (setq pa (c-state-cache-top-lparen (cdr ptr)))
2374 (>= pa (point-min)))
2375 (setq ptr (cdr ptr)))
2376
2377 (when (consp ptr)
2378 (if (eq (cdr ptr) c-state-cache)
2379 (setq c-state-cache nil
2380 c-state-cache-good-pos c-state-min-scan-pos)
2381 (setcdr ptr nil)
2382 (setq c-state-cache-good-pos (1+ (c-state-cache-top-lparen))))
2383 )))
2384
2385 (setq c-state-point-min (point-min)))
2386
2387(defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim)
2388 ;; If there is a brace pair preceding FROM in the buffer (not necessarily
2389 ;; immediately preceding), push a cons onto `c-state-cache' to represent it.
2390 ;; FROM must not be inside a literal. If UPPER-LIM is non-nil, we append
2391 ;; the highest brace pair whose "}" is below UPPER-LIM.
2392 ;;
2393 ;; Return non-nil when this has been done.
2394 ;;
2395 ;; This routine should be fast. Since it can get called a LOT, we maintain
2396 ;; `c-state-brace-pair-desert', a small cache of "failures", such that we
2397 ;; reduce the time wasted in repeated fruitless searches in brace deserts.
2398 (save-excursion
2399 (save-restriction
2400 (let ((bra from) ce ; Positions of "{" and "}".
2401 new-cons
2402 (cache-pos (c-state-cache-top-lparen)) ; might be nil.
2403 (macro-start-or-from
2404 (progn (goto-char from)
2405 (c-beginning-of-macro)
2406 (point))))
2407 (or upper-lim (setq upper-lim from))
2408
2409 ;; If we're essentially repeating a fruitless search, just give up.
2410 (unless (and c-state-brace-pair-desert
2411 (eq cache-pos (car c-state-brace-pair-desert))
2412 (<= from (cdr c-state-brace-pair-desert)))
2413 ;; Only search what we absolutely need to:
2414 (if (and c-state-brace-pair-desert
2415 (> from (cdr c-state-brace-pair-desert)))
2416 (narrow-to-region (cdr c-state-brace-pair-desert) (point-max)))
2417
2418 ;; In the next pair of nested loops, the inner one moves back past a
2419 ;; pair of (mis-)matching parens or brackets; the outer one moves
2420 ;; back over a sequence of unmatched close brace/paren/bracket each
2421 ;; time round.
2422 (while
2423 (progn
2424 (c-safe
2425 (while
2426 (and (setq ce (scan-lists bra -1 -1)) ; back past )/]/}; might signal
2427 (setq bra (scan-lists ce -1 1)) ; back past (/[/{; might signal
2428 (or (> ce upper-lim)
2429 (not (eq (char-after bra) ?\{))
2430 (and (goto-char bra)
2431 (c-beginning-of-macro)
2432 (< (point) macro-start-or-from))))))
2433 (and ce (< ce bra)))
2434 (setq bra ce)) ; If we just backed over an unbalanced closing
2435 ; brace, ignore it.
2436
2437 (if (and ce (< bra ce) (eq (char-after bra) ?\{))
2438 ;; We've found the desired brace-pair.
2439 (progn
2440 (setq new-cons (cons bra (1+ ce)))
2441 (cond
2442 ((consp (car c-state-cache))
2443 (setcar c-state-cache new-cons))
2444 ((and (numberp (car c-state-cache)) ; probably never happens
2445 (< ce (car c-state-cache)))
2446 (setcdr c-state-cache
2447 (cons new-cons (cdr c-state-cache))))
2448 (t (setq c-state-cache (cons new-cons c-state-cache)))))
2449
2450 ;; We haven't found a brace pair. Record this.
2451 (setq c-state-brace-pair-desert (cons cache-pos from))))))))
2452
2453(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here)
2454 ;; If BRA+1 is nil, do nothing. Otherwise, BRA+1 is the buffer position
2455 ;; following a {, and that brace has a (mis-)matching } (or ]), and we
2456 ;; "push" "a" brace pair onto `c-state-cache'.
2457 ;;
2458 ;; Here "push" means overwrite the top element if it's itself a brace-pair,
2459 ;; otherwise push it normally.
2460 ;;
2461 ;; The brace pair we push is normally the one surrounding BRA+1, but if the
2462 ;; latter is inside a macro, not being a macro containing
2463 ;; MACRO-START-OR-HERE, we scan backwards through the buffer for a non-macro
2464 ;; base pair. This latter case is assumed to be rare.
2465 ;;
2466 ;; Note: POINT is not preserved in this routine.
2467 (if bra+1
2468 (if (or (> bra+1 macro-start-or-here)
2469 (progn (goto-char bra+1)
2470 (not (c-beginning-of-macro))))
2471 (setq c-state-cache
2472 (cons (cons (1- bra+1)
2473 (scan-lists bra+1 1 1))
2474 (if (consp (car c-state-cache))
2475 (cdr c-state-cache)
2476 c-state-cache)))
2477 ;; N.B. This defsubst codes one method for the simple, normal case,
2478 ;; and a more sophisticated, slower way for the general case. Don't
2479 ;; eliminate this defsubst - it's a speed optimisation.
2480 (c-append-lower-brace-pair-to-state-cache (1- bra+1)))))
2481
2482(defun c-append-to-state-cache (from)
2483 ;; Scan the buffer from FROM to (point-max), adding elements into
2484 ;; `c-state-cache' for braces etc. Return a candidate for
2485 ;; `c-state-cache-good-pos'.
2486 ;;
2487 ;; FROM must be after the latest brace/paren/bracket in `c-state-cache', if
2488 ;; any. Typically, it is immediately after it. It must not be inside a
2489 ;; literal.
2490 (let ((here-bol (c-point 'bol (point-max)))
2491 (macro-start-or-here
2492 (save-excursion (goto-char (point-max))
2493 (if (c-beginning-of-macro)
2494 (point)
2495 (point-max))))
2496 pa+1 ; pos just after an opening PAren (or brace).
2497 (ren+1 from) ; usually a pos just after an closing paREN etc.
2498 ; Is actually the pos. to scan for a (/{/[ from,
2499 ; which sometimes is after a silly )/}/].
2500 paren+1 ; Pos after some opening or closing paren.
2501 paren+1s ; A list of `paren+1's; used to determine a
2502 ; good-pos.
2503 bra+1 ce+1 ; just after L/R bra-ces.
2504 bra+1s ; list of OLD values of bra+1.
2505 mstart) ; start of a macro.
2506
2507 (save-excursion
2508 ;; Each time round the following loop, we enter a succesively deeper
2509 ;; level of brace/paren nesting. (Except sometimes we "continue at
2510 ;; the existing level".) `pa+1' is a pos inside an opening
2511 ;; brace/paren/bracket, usually just after it.
2512 (while
2513 (progn
2514 ;; Each time round the next loop moves forward over an opening then
2515 ;; a closing brace/bracket/paren. This loop is white hot, so it
2516 ;; plays ugly tricks to go fast. DON'T PUT ANYTHING INTO THIS
2517 ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!! It terminates when a
2518 ;; call of `scan-lists' signals an error, which happens when there
2519 ;; are no more b/b/p's to scan.
2520 (c-safe
2521 (while t
2522 (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal
2523 paren+1s (cons pa+1 paren+1s))
2524 (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal
2525 (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later.
2526 (setq bra+1 pa+1))
2527 (setcar paren+1s ren+1)))
2528
2529 (if (and pa+1 (> pa+1 ren+1))
2530 ;; We've just entered a deeper nesting level.
2531 (progn
2532 ;; Insert the brace pair (if present) and the single open
2533 ;; paren/brace/bracket into `c-state-cache' It cannot be
2534 ;; inside a macro, except one around point, because of what
2535 ;; `c-neutralize-syntax-in-CPP' has done.
2536 (c-state-push-any-brace-pair bra+1 macro-start-or-here)
2537 ;; Insert the opening brace/bracket/paren position.
2538 (setq c-state-cache (cons (1- pa+1) c-state-cache))
2539 ;; Clear admin stuff for the next more nested part of the scan.
2540 (setq ren+1 pa+1 pa+1 nil bra+1 nil bra+1s nil)
2541 t) ; Carry on the loop
2542
2543 ;; All open p/b/b's at this nesting level, if any, have probably
2544 ;; been closed by matching/mismatching ones. We're probably
2545 ;; finished - we just need to check for having found an
2546 ;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a
2547 ;; macro, due the action of `c-neutralize-syntax-in-CPP'.
2548 (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop control.
2549
2550 ;; Record the final, innermost, brace-pair if there is one.
2551 (c-state-push-any-brace-pair bra+1 macro-start-or-here)
2552
2553 ;; Determine a good pos
2554 (while (and (setq paren+1 (car paren+1s))
2555 (> (if (> paren+1 macro-start-or-here)
2556 paren+1
2557 (goto-char paren+1)
2558 (setq mstart (and (c-beginning-of-macro)
2559 (point)))
2560 (or mstart paren+1))
2561 here-bol))
2562 (setq paren+1s (cdr paren+1s)))
2563 (cond
2564 ((and paren+1 mstart)
2565 (min paren+1 mstart))
2566 (paren+1)
2567 (t from)))))
2568
2569(defun c-remove-stale-state-cache (good-pos pps-point)
2570 ;; Remove stale entries from the `c-cache-state', i.e. those which will
2571 ;; not be in it when it is amended for position (point-max).
2572 ;; Additionally, the "outermost" open-brace entry before (point-max)
2573 ;; will be converted to a cons if the matching close-brace is scanned.
2574 ;;
2575 ;; GOOD-POS is a "maximal" "safe position" - there must be no open
2576 ;; parens/braces/brackets between GOOD-POS and (point-max).
2577 ;;
2578 ;; As a second thing, calculate the result of parse-partial-sexp at
2579 ;; PPS-POINT, w.r.t. GOOD-POS. The motivation here is that
2580 ;; `c-state-cache-good-pos' may become PPS-POINT, but the caller may need to
2581 ;; adjust it to get outside a string/comment. (Sorry about this! The code
2582 ;; needs to be FAST).
2583 ;;
2584 ;; Return a list (GOOD-POS SCAN-BACK-POS PPS-STATE), where
2585 ;; o - GOOD-POS is a position where the new value `c-state-cache' is known
2586 ;; to be good (we aim for this to be as high as possible);
2587 ;; o - SCAN-BACK-POS, if not nil, indicates there may be a brace pair
2588 ;; preceding POS which needs to be recorded in `c-state-cache'. It is a
2589 ;; position to scan backwards from.
2590 ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT.
2591 (save-restriction
2592 (narrow-to-region 1 (point-max))
2593 (save-excursion
2594 (let* ((in-macro-start ; start of macro containing (point-max) or nil.
2595 (save-excursion
2596 (goto-char (point-max))
2597 (and (c-beginning-of-macro)
2598 (point))))
2599 (good-pos-actual-macro-start ; Start of macro containing good-pos
2600 ; or nil
2601 (and (< good-pos (point-max))
2602 (save-excursion
2603 (goto-char good-pos)
2604 (and (c-beginning-of-macro)
2605 (point)))))
2606 (good-pos-actual-macro-end ; End of this macro, (maybe
2607 ; (point-max)), or nil.
2608 (and good-pos-actual-macro-start
2609 (save-excursion
2610 (goto-char good-pos-actual-macro-start)
2611 (c-end-of-macro)
2612 (point))))
2613 pps-state ; Will be 9 or 10 elements long.
2614 pos
2615 upper-lim ; ,beyond which `c-state-cache' entries are removed
2616 scan-back-pos
2617 pair-beg pps-point-state target-depth)
2618
2619 ;; Remove entries beyond (point-max). Also remove any entries inside
2620 ;; a macro, unless (point-max) is in the same macro.
2621 (setq upper-lim
2622 (if (or (null c-state-old-cpp-beg)
2623 (and (> (point-max) c-state-old-cpp-beg)
2624 (< (point-max) c-state-old-cpp-end)))
2625 (point-max)
2626 (min (point-max) c-state-old-cpp-beg)))
2627 (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim))
2628 (setq c-state-cache (cdr c-state-cache)))
2629 ;; If `upper-lim' is inside the last recorded brace pair, remove its
2630 ;; RBrace and indicate we'll need to search backwards for a previous
2631 ;; brace pair.
2632 (when (and c-state-cache
2633 (consp (car c-state-cache))
2634 (> (cdar c-state-cache) upper-lim))
2635 (setcar c-state-cache (caar c-state-cache))
2636 (setq scan-back-pos (car c-state-cache)))
2637
2638 ;; The next loop jumps forward out of a nested level of parens each
2639 ;; time round; the corresponding elements in `c-state-cache' are
2640 ;; removed. `pos' is just after the brace-pair or the open paren at
2641 ;; (car c-state-cache). There can be no open parens/braces/brackets
2642 ;; between `good-pos'/`good-pos-actual-macro-start' and (point-max),
2643 ;; due to the interface spec to this function.
2644 (setq pos (if (and good-pos-actual-macro-end
2645 (not (eq good-pos-actual-macro-start
2646 in-macro-start)))
2647 (1+ good-pos-actual-macro-end) ; get outside the macro as
2648 ; marked by a `category' text property.
2649 good-pos))
2650 (goto-char pos)
2651 (while (and c-state-cache
2652 (< (point) (point-max)))
2653 (cond
2654 ((null pps-state) ; first time through
2655 (setq target-depth -1))
2656 ((eq (car pps-state) target-depth) ; found closing ),},]
2657 (setq target-depth (1- (car pps-state))))
2658 ;; Do nothing when we've merely reached pps-point.
2659 )
2660
2661 ;; Scan!
2662 (setq pps-state
2663 (parse-partial-sexp
2664 (point) (if (< (point) pps-point) pps-point (point-max))
2665 target-depth
2666 nil pps-state))
2667
2668 (if (= (point) pps-point)
2669 (setq pps-point-state pps-state))
2670
2671 (when (eq (car pps-state) target-depth)
2672 (setq pos (point)) ; POS is now just after an R-paren/brace.
2673 (cond
2674 ((and (consp (car c-state-cache))
2675 (eq (point) (cdar c-state-cache)))
2676 ;; We've just moved out of the paren pair containing the brace-pair
2677 ;; at (car c-state-cache). `pair-beg' is where the open paren is,
2678 ;; and is potentially where the open brace of a cons in
2679 ;; c-state-cache will be.
2680 (setq pair-beg (car-safe (cdr c-state-cache))
2681 c-state-cache (cdr-safe (cdr c-state-cache)))) ; remove {}pair + containing Lparen.
2682 ((numberp (car c-state-cache))
2683 (setq pair-beg (car c-state-cache)
2684 c-state-cache (cdr c-state-cache))) ; remove this
2685 ; containing Lparen
2686 ((numberp (cadr c-state-cache))
2687 (setq pair-beg (cadr c-state-cache)
2688 c-state-cache (cddr c-state-cache))) ; Remove a paren pair
2689 ; together with enclosed brace pair.
2690 ;; (t nil) ; Ignore an unmated Rparen.
2691 )))
2692
2693 (if (< (point) pps-point)
2694 (setq pps-state (parse-partial-sexp (point) pps-point
2695 nil nil ; TARGETDEPTH, STOPBEFORE
2696 pps-state)))
2697
2698 ;; If the last paren pair we moved out of was actually a brace pair,
2699 ;; insert it into `c-state-cache'.
2700 (when (and pair-beg (eq (char-after pair-beg) ?{))
2701 (if (consp (car-safe c-state-cache))
2702 (setq c-state-cache (cdr c-state-cache)))
2703 (setq c-state-cache (cons (cons pair-beg pos)
2704 c-state-cache)))
2705
2706 (list pos scan-back-pos pps-state)))))
2707
2708(defun c-remove-stale-state-cache-backwards (here cache-pos)
2709 ;; Strip stale elements of `c-state-cache' by moving backwards through the
2710 ;; buffer, and inform the caller of the scenario detected.
2711 ;;
2712 ;; HERE is the position we're setting `c-state-cache' for.
2713 ;; CACHE-POS is just after the latest recorded position in `c-state-cache'
2714 ;; before HERE, or a position at or near point-min which isn't in a
2715 ;; literal.
2716 ;;
2717 ;; This function must only be called only when (> `c-state-cache-good-pos'
2718 ;; HERE). Usually the gap between CACHE-POS and HERE is large. It is thus
2719 ;; optimised to eliminate (or minimise) scanning between these two
2720 ;; positions.
2721 ;;
2722 ;; Return a three element list (GOOD-POS SCAN-BACK-POS FWD-FLAG), where:
2723 ;; o - GOOD-POS is a "good position", where `c-state-cache' is valid, or
2724 ;; could become so after missing elements are inserted into
2725 ;; `c-state-cache'. This is JUST AFTER an opening or closing
2726 ;; brace/paren/bracket which is already in `c-state-cache' or just before
2727 ;; one otherwise. exceptionally (when there's no such b/p/b handy) the BOL
2728 ;; before `here''s line, or the start of the literal containing it.
2729 ;; o - SCAN-BACK-POS, if non-nil, indicates there may be a brace pair
2730 ;; preceding POS which isn't recorded in `c-state-cache'. It is a position
2731 ;; to scan backwards from.
2732 ;; o - FWD-FLAG, if non-nil, indicates there may be parens/braces between
2733 ;; POS and HERE which aren't recorded in `c-state-cache'.
2734 ;;
2735 ;; The comments in this defun use "paren" to mean parenthesis or square
2736 ;; bracket (as contrasted with a brace), and "(" and ")" likewise.
2737 ;;
2738 ;; . {..} (..) (..) ( .. { } ) (...) ( .... . ..)
2739 ;; | | | | | |
2740 ;; CP E here D C good
2741 (let ((pos c-state-cache-good-pos)
2742 pa ren ; positions of "(" and ")"
2743 dropped-cons ; whether the last element dropped from `c-state-cache'
2744 ; was a cons (representing a brace-pair)
2745 good-pos ; see above.
2746 lit ; (START . END) of a literal containing some point.
2747 here-lit-start here-lit-end ; bounds of literal containing `here'
2748 ; or `here' itself.
2749 (here-bol (c-point 'bol here))
2750 (too-far-back (max (- here c-state-cache-too-far) 1)))
2751
2752 ;; Remove completely irrelevant entries from `c-state-cache'.
2753 (while (and c-state-cache
2754 (>= (setq pa (c-state-cache-top-lparen)) here))
2755 (setq dropped-cons (consp (car c-state-cache)))
2756 (setq c-state-cache (cdr c-state-cache))
2757 (setq pos pa))
2758 ;; At this stage, (> pos here);
2759 ;; (< (c-state-cache-top-lparen) here) (or is nil).
2760
2761 ;; CASE 1: The top of the cache is a brace pair which now encloses `here'.
2762 ;; As good-pos, return the address. of the "{".
2763 (if (and (consp (car c-state-cache))
2764 (> (cdar c-state-cache) here))
2765 ;; Since we've no knowledge of what's inside these braces, we have no
2766 ;; alternative but to direct the caller to scan the buffer from the
2767 ;; opening brace.
2768 (progn
2769 (setq pos (caar c-state-cache))
2770 (setcar c-state-cache pos)
2771 (list (1+ pos) pos t)) ; return value. We've just converted a brace
2772 ; pair entry into a { entry, so the caller
2773 ; needs to search for a brace pair before the
2774 ; {.
2775
2776 ;; ;; `here' might be inside a literal. Check for this.
2777 (setq lit (c-state-literal-at here)
2778 here-lit-start (or (car lit) here)
2779 here-lit-end (or (cdr lit) here))
2780
2781 ;; `here' might be nested inside any depth of parens (or brackets but
2782 ;; not braces). Scan backwards to find the outermost such opening
2783 ;; paren, if there is one. This will be the scan position to return.
2784 (save-restriction
2785 (narrow-to-region cache-pos (point-max))
2786 (setq pos (c-state-balance-parens-backwards here-lit-end pos)))
2787
2788 (if (< pos here-lit-start)
2789 ;; CASE 2: Address of outermost ( or [ which now encloses `here',
2790 ;; but didn't enclose the (previous) `c-state-cache-good-pos'. If
2791 ;; there is a brace pair preceding this, it will already be in
2792 ;; `c-state-cache', unless there was a brace pair after it,
2793 ;; i.e. there'll only be one to scan for if we've just deleted one.
2794 (list pos (and dropped-cons pos) t) ; Return value.
2795
2796 ;; `here' isn't enclosed in a (previously unrecorded) bracket/paren.
2797 ;; Further forward scanning isn't needed, but we still need to find a
2798 ;; GOOD-POS. Step out of all enclosing "("s on HERE's line.
2799 (save-restriction
2800 (narrow-to-region here-bol (point-max))
2801 (setq pos here-lit-start)
2802 (c-safe (while (setq pa (scan-lists pos -1 1))
2803 (setq pos pa)))) ; might signal
2804 (if (setq ren (c-safe-scan-lists pos -1 -1 too-far-back))
2805 ;; CASE 3: After a }/)/] before `here''s BOL.
2806 (list (1+ ren) (and dropped-cons pos) nil) ; Return value
2807
2808 ;; CASE 4; Best of a bad job: BOL before `here-bol', or beginning of
2809 ;; literal containing it.
2810 (setq good-pos (c-state-lit-beg (c-point 'bopl here-bol)))
2811 (list good-pos (and dropped-cons good-pos) nil))))))
2812
2813
2814;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2815;; Externally visible routines.
2816
2817(defun c-state-cache-init ()
2818 (setq c-state-cache nil
2819 c-state-cache-good-pos 1
2820 c-state-nonlit-pos-cache nil
2821 c-state-nonlit-pos-cache-limit 1
2822 c-state-brace-pair-desert nil
2823 c-state-point-min 1
2824 c-state-point-min-lit-type nil
2825 c-state-point-min-lit-start nil
2826 c-state-min-scan-pos 1
2827 c-state-old-cpp-beg nil
2828 c-state-old-cpp-end nil)
2829 (c-state-mark-point-min-literal))
2830
2831(defun c-invalidate-state-cache-1 (here)
2832 ;; Invalidate all info on `c-state-cache' that applies to the buffer at HERE
2833 ;; or higher and set `c-state-cache-good-pos' accordingly. The cache is
2834 ;; left in a consistent state.
2835 ;;
2836 ;; This is much like `c-whack-state-after', but it never changes a paren
2837 ;; pair element into an open paren element. Doing that would mean that the
2838 ;; new open paren wouldn't have the required preceding paren pair element.
2839 ;;
2840 ;; This function is called from c-after-change.
2841
2842 ;; The cache of non-literals:
2843 (if (< here c-state-nonlit-pos-cache-limit)
2844 (setq c-state-nonlit-pos-cache-limit here))
2845
2846 ;; `c-state-cache':
2847 ;; Case 1: if `here' is in a literal containing point-min, everything
2848 ;; becomes (or is already) nil.
2849 (if (or (null c-state-cache-good-pos)
2850 (< here (c-state-get-min-scan-pos)))
2851 (setq c-state-cache nil
2852 c-state-cache-good-pos nil
2853 c-state-min-scan-pos nil)
2854
2855;;; Truncate `c-state-cache' and set `c-state-cache-good-pos' to a value below
2856;;; `here'. To maintain its consistency, we may need to insert a new brace
2857;;; pair.
2858 (let ((here-bol (c-point 'bol here))
2859 too-high-pa ; recorded {/(/[ next above here, or nil.
2860 dropped-cons ; was the last removed element a brace pair?
2861 pa)
2862 ;; The easy bit - knock over-the-top bits off `c-state-cache'.
2863 (while (and c-state-cache
2864 (>= (setq pa (c-state-cache-top-paren)) here))
2865 (setq dropped-cons (consp (car c-state-cache))
2866 too-high-pa (c-state-cache-top-lparen)
2867 c-state-cache (cdr c-state-cache)))
2868
2869 ;; Do we need to add in an earlier brace pair, having lopped one off?
2870 (if (and dropped-cons
2871 (< too-high-pa (+ here c-state-cache-too-far)))
2872 (c-append-lower-brace-pair-to-state-cache too-high-pa here-bol))
2873 (setq c-state-cache-good-pos (or (c-state-cache-after-top-paren)
2874 (c-state-get-min-scan-pos)))))
2875
2876 ;; The brace-pair desert marker:
2877 (when (car c-state-brace-pair-desert)
2878 (if (< here (car c-state-brace-pair-desert))
2879 (setq c-state-brace-pair-desert nil)
2880 (if (< here (cdr c-state-brace-pair-desert))
2881 (setcdr c-state-brace-pair-desert here)))))
2882
2883(defun c-parse-state-1 ()
2884 ;; Find and record all noteworthy parens between some good point earlier in
2885 ;; the file and point. That good point is at least the beginning of the
2886 ;; top-level construct we are in, or the beginning of the preceding
2887 ;; top-level construct if we aren't in one.
2888 ;;
2889 ;; The returned value is a list of the noteworthy parens with the last one
2890 ;; first. If an element in the list is an integer, it's the position of an
2891 ;; open paren (of any type) which has not been closed before the point. If
2892 ;; an element is a cons, it gives the position of a closed BRACE paren
2893 ;; pair[*]; the car is the start brace position and the cdr is the position
2894 ;; following the closing brace. Only the last closed brace paren pair
2895 ;; before each open paren and before the point is recorded, and thus the
2896 ;; state never contains two cons elements in succession. When a close brace
2897 ;; has no matching open brace (e.g., the matching brace is outside the
2898 ;; visible region), it is not represented in the returned value.
2899 ;;
2900 ;; [*] N.B. The close "brace" might be a mismatching close bracket or paren.
2901 ;; This defun explicitly treats mismatching parens/braces/brackets as
2902 ;; matching. It is the open brace which makes it a "brace" pair.
2903 ;;
2904 ;; If POINT is within a macro, open parens and brace pairs within
2905 ;; THIS macro MIGHT be recorded. This depends on whether their
2906 ;; syntactic properties have been suppressed by
2907 ;; `c-neutralize-syntax-in-CPP'. This might need fixing (2008-12-11).
2908 ;; 2033 ;;
2909 ;; Currently no characters which are given paren syntax with the 2034 ;; Currently no characters which are given paren syntax with the
2910 ;; syntax-table property are recorded, i.e. angle bracket arglist 2035 ;; syntax-table property are recorded, i.e. angle bracket arglist
2911 ;; parens are never present here. Note that this might change. 2036 ;; parens are never present here. Note that this might change.
2912 ;; 2037 ;;
2913 ;; BUG: This function doesn't cope entirely well with unbalanced 2038 ;; BUG: This function doesn't cope entirely well with unbalanced
2914 ;; parens in macros. (2008-12-11: this has probably been resolved 2039 ;; parens in macros. E.g. in the following case the brace before
2915 ;; by the function `c-neutralize-syntax-in-CPP'.) E.g. in the 2040 ;; the macro isn't balanced with the one after it:
2916 ;; following case the brace before the macro isn't balanced with the
2917 ;; one after it:
2918 ;; 2041 ;;
2919 ;; { 2042 ;; {
2920 ;; #define X { 2043 ;; #define X {
2921 ;; } 2044 ;; }
2922 ;; 2045 ;;
2923 ;; Note to maintainers: this function DOES get called with point
2924 ;; within comments and strings, so don't assume it doesn't!
2925 ;;
2926 ;; This function might do hidden buffer changes. 2046 ;; This function might do hidden buffer changes.
2927 (let* ((here (point))
2928 (here-bopl (c-point 'bopl))
2929 strategy ; 'forward, 'backward etc..
2930 ;; Candidate positions to start scanning from:
2931 cache-pos ; highest position below HERE already existing in
2932 ; cache (or 1).
2933 good-pos
2934 start-point
2935 bopl-state
2936 res
2937 scan-backward-pos scan-forward-p) ; used for 'backward.
2938 ;; If POINT-MIN has changed, adjust the cache
2939 (unless (= (point-min) c-state-point-min)
2940 (c-renarrow-state-cache))
2941
2942 ;; Strategy?
2943 (setq res (c-parse-state-get-strategy here c-state-cache-good-pos)
2944 strategy (car res)
2945 cache-pos (cadr res)
2946 start-point (nth 2 res))
2947
2948 (when (eq strategy 'BOD)
2949 (setq c-state-cache nil
2950 c-state-cache-good-pos start-point))
2951
2952 ;; SCAN!
2953 (save-restriction
2954 (cond
2955 ((memq strategy '(forward BOD))
2956 (narrow-to-region (point-min) here)
2957 (setq res (c-remove-stale-state-cache start-point here-bopl))
2958 (setq cache-pos (car res)
2959 scan-backward-pos (cadr res)
2960 bopl-state (car (cddr res))) ; will be nil if (< here-bopl
2961 ; start-point)
2962 (if scan-backward-pos
2963 (c-append-lower-brace-pair-to-state-cache scan-backward-pos))
2964 (setq good-pos
2965 (c-append-to-state-cache cache-pos))
2966 (setq c-state-cache-good-pos
2967 (if (and bopl-state
2968 (< good-pos (- here c-state-cache-too-far)))
2969 (c-state-cache-non-literal-place here-bopl bopl-state)
2970 good-pos)))
2971
2972 ((eq strategy 'backward)
2973 (setq res (c-remove-stale-state-cache-backwards here cache-pos)
2974 good-pos (car res)
2975 scan-backward-pos (cadr res)
2976 scan-forward-p (car (cddr res)))
2977 (if scan-backward-pos
2978 (c-append-lower-brace-pair-to-state-cache
2979 scan-backward-pos))
2980 (setq c-state-cache-good-pos
2981 (if scan-forward-p
2982 (progn (narrow-to-region (point-min) here)
2983 (c-append-to-state-cache good-pos))
2984
2985 (c-get-cache-scan-pos good-pos))))
2986
2987 (t ; (eq strategy 'IN-LIT)
2988 (setq c-state-cache nil
2989 c-state-cache-good-pos nil)))))
2990
2991 c-state-cache)
2992
2993(defun c-invalidate-state-cache (here)
2994 ;; This is a wrapper over `c-invalidate-state-cache-1'.
2995 ;;
2996 ;; It suppresses the syntactic effect of the < and > (template) brackets and
2997 ;; of all parens in preprocessor constructs, except for any such construct
2998 ;; containing point. We can then call `c-invalidate-state-cache-1' without
2999 ;; worrying further about macros and template delimiters.
3000 (c-with-<->-as-parens-suppressed
3001 (if (and c-state-old-cpp-beg
3002 (< c-state-old-cpp-beg here))
3003 (c-with-all-but-one-cpps-commented-out
3004 c-state-old-cpp-beg
3005 (min c-state-old-cpp-end here)
3006 (c-invalidate-state-cache-1 here))
3007 (c-with-cpps-commented-out
3008 (c-invalidate-state-cache-1 here)))))
3009 2047
3010(defun c-parse-state () 2048 (save-restriction
3011 ;; This is a wrapper over `c-parse-state-1'. See that function for a 2049 (let* ((here (point))
3012 ;; description of the functionality and return value. 2050 (here-bol (c-point 'bol))
3013 ;; 2051 (c-macro-start (c-query-macro-start))
3014 ;; It suppresses the syntactic effect of the < and > (template) brackets and 2052 (in-macro-start (or c-macro-start (point)))
3015 ;; of all parens in preprocessor constructs, except for any such construct 2053 old-state last-pos brace-pair-open brace-pair-close
3016 ;; containing point. We can then call `c-parse-state-1' without worrying 2054 pos save-pos)
3017 ;; further about macros and template delimiters. 2055 (c-invalidate-state-cache here)
3018 (let (here-cpp-beg here-cpp-end) 2056
3019 (save-excursion 2057 ;; If the minimum position has changed due to narrowing then we
3020 (when (c-beginning-of-macro) 2058 ;; have to fix the tail of `c-state-cache' accordingly.
3021 (setq here-cpp-beg (point)) 2059 (unless (= c-state-cache-start (point-min))
3022 (unless 2060 (if (> (point-min) c-state-cache-start)
3023 (> (setq here-cpp-end (c-syntactic-end-of-macro)) 2061 ;; If point-min has moved forward then we just need to cut
3024 here-cpp-beg) 2062 ;; off a bit of the tail.
3025 (setq here-cpp-beg nil here-cpp-end nil)))) 2063 (let ((ptr (cons nil c-state-cache)) elem)
3026 ;; FIXME!!! Put in a `condition-case' here to protect the integrity of the 2064 (while (and (setq elem (car-safe (cdr ptr)))
3027 ;; subsystem. 2065 (>= (if (consp elem) (car elem) elem)
3028 (prog1 2066 (point-min)))
3029 (c-with-<->-as-parens-suppressed 2067 (setq ptr (cdr ptr)))
3030 (if (and here-cpp-beg (> here-cpp-end here-cpp-beg)) 2068 (when (consp ptr)
3031 (c-with-all-but-one-cpps-commented-out 2069 (if (eq (cdr ptr) c-state-cache)
3032 here-cpp-beg here-cpp-end 2070 (setq c-state-cache nil
3033 (c-parse-state-1)) 2071 c-state-cache-good-pos 1)
3034 (c-with-cpps-commented-out 2072 (setcdr ptr nil))))
3035 (c-parse-state-1)))) 2073 ;; If point-min has moved backward then we drop the state
3036 (setq c-state-old-cpp-beg (and here-cpp-beg (copy-marker here-cpp-beg t)) 2074 ;; completely. It's possible to do a better job here and
3037 c-state-old-cpp-end (and here-cpp-end (copy-marker here-cpp-end t))) 2075 ;; recalculate the top only.
3038 ))) 2076 (setq c-state-cache nil
2077 c-state-cache-good-pos 1))
2078 (setq c-state-cache-start (point-min)))
2079
2080 ;; Get the latest position we know are directly inside the
2081 ;; closest containing paren of the cached state.
2082 (setq last-pos (and c-state-cache
2083 (if (consp (car c-state-cache))
2084 (cdr (car c-state-cache))
2085 (1+ (car c-state-cache)))))
2086 (if (or (not last-pos)
2087 (< last-pos c-state-cache-good-pos))
2088 (setq last-pos c-state-cache-good-pos)
2089 ;; Take the opportunity to move the cached good position
2090 ;; further down.
2091 (if (< last-pos here-bol)
2092 (setq c-state-cache-good-pos last-pos)))
3039 2093
3040;; Debug tool to catch cache inconsistencies. This is called from 2094 ;; Check if `last-pos' is in a macro. If it is, and we're not
3041;; 000tests.el. 2095 ;; in the same macro, we must discard everything on
2096 ;; `c-state-cache' that is inside the macro before using it.
2097 (save-excursion
2098 (goto-char last-pos)
2099 (when (and (c-beginning-of-macro)
2100 (/= (point) in-macro-start))
2101 (c-invalidate-state-cache (point))
2102 ;; Set `last-pos' again just like above except that there's
2103 ;; no use looking at `c-state-cache-good-pos' here.
2104 (setq last-pos (if c-state-cache
2105 (if (consp (car c-state-cache))
2106 (cdr (car c-state-cache))
2107 (1+ (car c-state-cache)))
2108 1))))
2109
2110 ;; If we've moved very far from the last cached position then
2111 ;; it's probably better to redo it from scratch, otherwise we
2112 ;; might spend a lot of time searching from `last-pos' down to
2113 ;; here.
2114 (when (< last-pos (- here 20000))
2115 ;; First get the fallback start position. If it turns out
2116 ;; that it's so far back that the cached state is closer then
2117 ;; we'll keep it afterall.
2118 (setq pos (c-get-fallback-start-pos here))
2119 (if (<= pos last-pos)
2120 (setq pos nil)
2121 (setq last-pos nil
2122 c-state-cache nil
2123 c-state-cache-good-pos 1)))
2124
2125 ;; Find the start position for the forward search. (Can't
2126 ;; search in the backward direction since the point might be in
2127 ;; some kind of literal.)
2128
2129 (unless pos
2130 (setq old-state c-state-cache)
2131
2132 ;; There's a cached state with a containing paren. Pop off
2133 ;; the stale containing sexps from it by going forward out of
2134 ;; parens as far as possible.
2135 (narrow-to-region (point-min) here)
2136 (let (placeholder pair-beg)
2137 (while (and c-state-cache
2138 (setq placeholder
2139 (c-up-list-forward last-pos)))
2140 (setq last-pos placeholder)
2141 (if (consp (car c-state-cache))
2142 (setq pair-beg (car-safe (cdr c-state-cache))
2143 c-state-cache (cdr-safe (cdr c-state-cache)))
2144 (setq pair-beg (car c-state-cache)
2145 c-state-cache (cdr c-state-cache))))
2146
2147 (when (and pair-beg (eq (char-after pair-beg) ?{))
2148 ;; The last paren pair we moved out from was a brace
2149 ;; pair. Modify the state to record this as a closed
2150 ;; pair now.
2151 (if (consp (car-safe c-state-cache))
2152 (setq c-state-cache (cdr c-state-cache)))
2153 (setq c-state-cache (cons (cons pair-beg last-pos)
2154 c-state-cache))))
2155
2156 ;; Check if the preceding balanced paren is within a
2157 ;; macro; it should be ignored if we're outside the
2158 ;; macro. There's no need to check any further upwards;
2159 ;; if the macro contains an unbalanced opening paren then
2160 ;; we're smoked anyway.
2161 (when (and (<= (point) in-macro-start)
2162 (consp (car c-state-cache)))
2163 (save-excursion
2164 (goto-char (car (car c-state-cache)))
2165 (when (c-beginning-of-macro)
2166 (setq here (point)
2167 c-state-cache (cdr c-state-cache)))))
2168
2169 (unless (eq c-state-cache old-state)
2170 ;; Have to adjust the cached good position if state has been
2171 ;; popped off.
2172 (setq c-state-cache-good-pos
2173 (if c-state-cache
2174 (if (consp (car c-state-cache))
2175 (cdr (car c-state-cache))
2176 (1+ (car c-state-cache)))
2177 1)
2178 old-state c-state-cache))
2179
2180 (when c-state-cache
2181 (setq pos last-pos)))
2182
2183 ;; Get the fallback start position.
2184 (unless pos
2185 (setq pos (c-get-fallback-start-pos here)
2186 c-state-cache nil
2187 c-state-cache-good-pos 1))
2188
2189 (narrow-to-region (point-min) here)
2190
2191 (while pos
2192 (setq save-pos pos
2193 brace-pair-open nil)
2194
2195 ;; Find the balanced brace pairs. This loop is hot, so it
2196 ;; does ugly tricks to go faster.
2197 (c-safe
2198 (let (set-good-pos set-brace-pair)
2199 (while t
2200 (setq last-pos nil
2201 last-pos (scan-lists pos 1 -1)) ; Might signal.
2202 (setq pos (scan-lists last-pos 1 1) ; Might signal.
2203 set-good-pos (< pos here-bol)
2204 set-brace-pair (eq (char-before last-pos) ?{))
2205
2206 ;; Update the cached good position and record the brace
2207 ;; pair, whichever is applicable for the paren we've
2208 ;; just jumped over. But first check that it isn't
2209 ;; inside a macro and the point isn't inside the same
2210 ;; one.
2211 (when (and (or set-good-pos set-brace-pair)
2212 (or (>= pos in-macro-start)
2213 (save-excursion
2214 (goto-char pos)
2215 (not (c-beginning-of-macro)))))
2216 (if set-good-pos
2217 (setq c-state-cache-good-pos pos))
2218 (if set-brace-pair
2219 (setq brace-pair-open last-pos
2220 brace-pair-close pos))))))
2221
2222 ;; Record the last brace pair.
2223 (when brace-pair-open
2224 (let ((head (car-safe c-state-cache)))
2225 (if (consp head)
2226 (progn
2227 (setcar head (1- brace-pair-open))
2228 (setcdr head brace-pair-close))
2229 (setq c-state-cache (cons (cons (1- brace-pair-open)
2230 brace-pair-close)
2231 c-state-cache)))))
2232
2233 (if last-pos
2234 ;; Prepare to loop, but record the open paren only if it's
2235 ;; outside a macro or within the same macro as point, and
2236 ;; if it is a legitimate open paren and not some character
2237 ;; that got an open paren syntax-table property.
2238 (progn
2239 (setq pos last-pos)
2240 (when (and (or (>= last-pos in-macro-start)
2241 (save-excursion
2242 (goto-char last-pos)
2243 (not (c-beginning-of-macro))))
2244 ;; Check for known types of parens that we
2245 ;; want to record. The syntax table is not to
2246 ;; be trusted here since the caller might be
2247 ;; using e.g. `c++-template-syntax-table'.
2248 (memq (char-before last-pos) '(?{ ?\( ?\[)))
2249 (if (< last-pos here-bol)
2250 (setq c-state-cache-good-pos last-pos))
2251 (setq c-state-cache (cons (1- last-pos) c-state-cache))))
2252
2253 (if (setq last-pos (c-up-list-forward pos))
2254 ;; Found a close paren without a corresponding opening
2255 ;; one. Maybe we didn't go back far enough, so try to
2256 ;; scan backward for the start paren and then start over.
2257 (progn
2258 (setq pos (c-up-list-backward pos)
2259 c-state-cache nil
2260 c-state-cache-good-pos c-state-cache-start)
2261 (when (or (not pos)
2262 ;; Emacs (up to at least 21.2) can get confused by
2263 ;; open parens in column zero inside comments: The
2264 ;; sexp functions can then misbehave and bring us
2265 ;; back to the same point again. Check this so that
2266 ;; we don't get an infinite loop.
2267 (>= pos save-pos))
2268 (setq pos last-pos
2269 c-parsing-error
2270 (format "Unbalanced close paren at line %d"
2271 (1+ (count-lines (point-min)
2272 (c-point 'bol last-pos)))))))
2273 (setq pos nil))))
2274
2275 ;;(message "c-parse-state: %S end: %S" c-state-cache c-state-cache-good-pos)
2276 c-state-cache)))
2277
2278;; Debug tool to catch cache inconsistencies.
3042(defvar c-debug-parse-state nil) 2279(defvar c-debug-parse-state nil)
3043(unless (fboundp 'c-real-parse-state) 2280(unless (fboundp 'c-real-parse-state)
3044 (fset 'c-real-parse-state (symbol-function 'c-parse-state))) 2281 (fset 'c-real-parse-state (symbol-function 'c-parse-state)))
3045(cc-bytecomp-defun c-real-parse-state) 2282(cc-bytecomp-defun c-real-parse-state)
3046(defun c-debug-parse-state () 2283(defun c-debug-parse-state ()
3047 (let ((here (point)) (res1 (c-real-parse-state)) res2) 2284 (let ((res1 (c-real-parse-state)) res2)
3048 (let ((c-state-cache nil) 2285 (let ((c-state-cache nil)
3049 (c-state-cache-good-pos 1) 2286 (c-state-cache-start 1)
3050 (c-state-nonlit-pos-cache nil) 2287 (c-state-cache-good-pos 1))
3051 (c-state-nonlit-pos-cache-limit 1)
3052 (c-state-brace-pair-desert nil)
3053 (c-state-point-min 1)
3054 (c-state-point-min-lit-type nil)
3055 (c-state-point-min-lit-start nil)
3056 (c-state-min-scan-pos 1)
3057 (c-state-old-cpp-beg nil)
3058 (c-state-old-cpp-end nil))
3059 (setq res2 (c-real-parse-state))) 2288 (setq res2 (c-real-parse-state)))
3060 (unless (equal res1 res2) 2289 (unless (equal res1 res2)
3061 ;; The cache can actually go further back due to the ad-hoc way 2290 ;; The cache can actually go further back due to the ad-hoc way
@@ -3067,11 +2296,10 @@ comment at the start of cc-engine.el for more info."
3067 (while (not (or (bobp) (eq (char-after) ?{))) 2296 (while (not (or (bobp) (eq (char-after) ?{)))
3068 (c-beginning-of-defun-1)) 2297 (c-beginning-of-defun-1))
3069 (unless (equal (c-whack-state-before (point) res1) res2) 2298 (unless (equal (c-whack-state-before (point) res1) res2)
3070 (message (concat "c-parse-state inconsistency at %s: " 2299 (message (concat "c-parse-state inconsistency: "
3071 "using cache: %s, from scratch: %s") 2300 "using cache: %s, from scratch: %s")
3072 here res1 res2)))) 2301 res1 res2))))
3073 res1)) 2302 res1))
3074
3075(defun c-toggle-parse-state-debug (&optional arg) 2303(defun c-toggle-parse-state-debug (&optional arg)
3076 (interactive "P") 2304 (interactive "P")
3077 (setq c-debug-parse-state (c-calculate-state arg c-debug-parse-state)) 2305 (setq c-debug-parse-state (c-calculate-state arg c-debug-parse-state))
@@ -3082,7 +2310,6 @@ comment at the start of cc-engine.el for more info."
3082(when c-debug-parse-state 2310(when c-debug-parse-state
3083 (c-toggle-parse-state-debug 1)) 2311 (c-toggle-parse-state-debug 1))
3084 2312
3085
3086(defun c-whack-state-before (bufpos paren-state) 2313(defun c-whack-state-before (bufpos paren-state)
3087 ;; Whack off any state information from PAREN-STATE which lies 2314 ;; Whack off any state information from PAREN-STATE which lies
3088 ;; before BUFPOS. Not destructive on PAREN-STATE. 2315 ;; before BUFPOS. Not destructive on PAREN-STATE.
@@ -4882,168 +4109,7 @@ comment at the start of cc-engine.el for more info."
4882 ))) 4109 )))
4883 4110
4884 4111
4885;; Setting and removing syntax properties on < and > in languages (C++ 4112;; Handling of small scale constructs like types and names.
4886;; and Java) where they can be template/generic delimiters as well as
4887;; their normal meaning of "less/greater than".
4888
4889;; Normally, < and > have syntax 'punctuation'. When they are found to
4890;; be delimiters, they are marked as such with the category properties
4891;; c-<-as-paren-syntax, c->-as-paren-syntax respectively.
4892
4893;; STRATEGY:
4894;;
4895;; It is impossible to determine with certainty whether a <..> pair in
4896;; C++ is two comparison operators or is template delimiters, unless
4897;; one duplicates a lot of a C++ compiler. For example, the following
4898;; code fragment:
4899;;
4900;; foo (a < b, c > d) ;
4901;;
4902;; could be a function call with two integer parameters (each a
4903;; relational expression), or it could be a constructor for class foo
4904;; taking one parameter d of templated type "a < b, c >". They are
4905;; somewhat easier to distinguish in Java.
4906;;
4907;; The strategy now (2010-01) adopted is to mark and unmark < and
4908;; > IN MATCHING PAIRS ONLY. [Previously, they were marked
4909;; individually when their context so indicated. This gave rise to
4910;; intractible problems when one of a matching pair was deleted, or
4911;; pulled into a literal.]
4912;;
4913;; At each buffer change, the syntax-table properties are removed in a
4914;; before-change function and reapplied, when needed, in an
4915;; after-change function. It is far more important that the
4916;; properties get removed when they they are spurious than that they
4917;; be present when wanted.
4918;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4919(defun c-clear-<-pair-props (&optional pos)
4920 ;; POS (default point) is at a < character. If it is marked with
4921 ;; open paren syntax-table text property, remove the property,
4922 ;; together with the close paren property on the matching > (if
4923 ;; any).
4924 (save-excursion
4925 (if pos
4926 (goto-char pos)
4927 (setq pos (point)))
4928 (when (equal (c-get-char-property (point) 'syntax-table)
4929 c-<-as-paren-syntax)
4930 (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,..
4931 (c-go-list-forward))
4932 (when (equal (c-get-char-property (1- (point)) 'syntax-table)
4933 c->-as-paren-syntax) ; should always be true.
4934 (c-clear-char-property (1- (point)) 'category))
4935 (c-clear-char-property pos 'category))))
4936
4937(defun c-clear->-pair-props (&optional pos)
4938 ;; POS (default point) is at a > character. If it is marked with
4939 ;; close paren syntax-table property, remove the property, together
4940 ;; with the open paren property on the matching < (if any).
4941 (save-excursion
4942 (if pos
4943 (goto-char pos)
4944 (setq pos (point)))
4945 (when (equal (c-get-char-property (point) 'syntax-table)
4946 c->-as-paren-syntax)
4947 (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,..
4948 (c-go-up-list-backward))
4949 (when (equal (c-get-char-property (point) 'syntax-table)
4950 c-<-as-paren-syntax) ; should always be true.
4951 (c-clear-char-property (point) 'category))
4952 (c-clear-char-property pos 'category))))
4953
4954(defun c-clear-<>-pair-props (&optional pos)
4955 ;; POS (default point) is at a < or > character. If it has an
4956 ;; open/close paren syntax-table property, remove this property both
4957 ;; from the current character and its partner (which will also be
4958 ;; thusly marked).
4959 (cond
4960 ((eq (char-after) ?\<)
4961 (c-clear-<-pair-props pos))
4962 ((eq (char-after) ?\>)
4963 (c-clear->-pair-props pos))
4964 (t (c-benign-error
4965 "c-clear-<>-pair-props called from wrong position"))))
4966
4967(defun c-clear-<-pair-props-if-match-after (lim &optional pos)
4968 ;; POS (default point) is at a < character. If it is both marked
4969 ;; with open/close paren syntax-table property, and has a matching >
4970 ;; (also marked) which is after LIM, remove the property both from
4971 ;; the current > and its partner.
4972 (save-excursion
4973 (if pos
4974 (goto-char pos)
4975 (setq pos (point)))
4976 (when (equal (c-get-char-property (point) 'syntax-table)
4977 c-<-as-paren-syntax)
4978 (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,..
4979 (c-go-list-forward))
4980 (when (and (>= (point) lim)
4981 (equal (c-get-char-property (1- (point)) 'syntax-table)
4982 c->-as-paren-syntax)) ; should always be true.
4983 (c-unmark-<->-as-paren (1- (point)))
4984 (c-unmark-<->-as-paren pos)))))
4985
4986(defun c-clear->-pair-props-if-match-before (lim &optional pos)
4987 ;; POS (default point) is at a > character. If it is both marked
4988 ;; with open/close paren syntax-table property, and has a matching <
4989 ;; (also marked) which is before LIM, remove the property both from
4990 ;; the current < and its partner.
4991 (save-excursion
4992 (if pos
4993 (goto-char pos)
4994 (setq pos (point)))
4995 (when (equal (c-get-char-property (point) 'syntax-table)
4996 c->-as-paren-syntax)
4997 (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,..
4998 (c-go-up-list-backward))
4999 (when (and (<= (point) lim)
5000 (equal (c-get-char-property (point) 'syntax-table)
5001 c-<-as-paren-syntax)) ; should always be true.
5002 (c-unmark-<->-as-paren (point))
5003 (c-unmark-<->-as-paren pos)))))
5004
5005(defun c-before-change-check-<>-operators (beg end)
5006 ;; Unmark certain pairs of "< .... >" which are currently marked as
5007 ;; template/generic delimiters. (This marking is via syntax-table
5008 ;; text properties).
5009 ;;
5010 ;; These pairs are those which are in the current "statement" (i.e.,
5011 ;; the region between the {, }, or ; before BEG and the one after
5012 ;; END), and which enclose any part of the interval (BEG END).
5013 ;;
5014 ;; Note that in C++ (?and Java), template/generic parens cannot
5015 ;; enclose a brace or semicolon, so we use these as bounds on the
5016 ;; region we must work on.
5017 ;;
5018 ;; This function is called from before-change-functions (via
5019 ;; c-get-state-before-change-functions). Thus the buffer is widened,
5020 ;; and point is undefined, both at entry and exit.
5021 ;;
5022 ;; FIXME!!! This routine ignores the possibility of macros entirely.
5023 ;; 2010-01-29.
5024 (save-excursion
5025 (let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits)))
5026 (end-lit-limits (progn (goto-char end) (c-literal-limits))))
5027 ;; Locate the barrier before the changed region
5028 (goto-char (if beg-lit-limits (car beg-lit-limits) beg))
5029 (c-syntactic-skip-backward "^;{}" (max (- beg 2048) (point-min)))
5030
5031 ;; Remove the syntax-table properties from each pertinent <...> pair.
5032 ;; Firsly, the ones with the < before beg and > after beg.
5033 (while (c-search-forward-char-property 'category 'c-<-as-paren-syntax beg)
5034 (c-clear-<-pair-props-if-match-after beg (1- (point))))
5035
5036 ;; Locate the barrier after END.
5037 (goto-char (if end-lit-limits (cdr end-lit-limits) end))
5038 (c-syntactic-re-search-forward "[;{}]"
5039 (min (+ end 2048) (point-max)) 'end)
5040
5041 ;; Remove syntax-table properties from the remaining pertinent <...>
5042 ;; pairs, those with a > after end and < before end.
5043 (while (c-search-backward-char-property 'category 'c->-as-paren-syntax end)
5044 (c-clear->-pair-props-if-match-before end)))))
5045
5046
5047 4113
5048(defun c-after-change-check-<>-operators (beg end) 4114(defun c-after-change-check-<>-operators (beg end)
5049 ;; This is called from `after-change-functions' when 4115 ;; This is called from `after-change-functions' when
@@ -5065,7 +4131,7 @@ comment at the start of cc-engine.el for more info."
5065 (< beg (setq beg (match-end 0)))) 4131 (< beg (setq beg (match-end 0))))
5066 (while (progn (skip-chars-forward "^<>" beg) 4132 (while (progn (skip-chars-forward "^<>" beg)
5067 (< (point) beg)) 4133 (< (point) beg))
5068 (c-clear-<>-pair-props) 4134 (c-clear-char-property (point) 'syntax-table)
5069 (forward-char)))) 4135 (forward-char))))
5070 4136
5071 (when (< beg end) 4137 (when (< beg end)
@@ -5080,13 +4146,9 @@ comment at the start of cc-engine.el for more info."
5080 (< end (setq end (match-end 0)))) 4146 (< end (setq end (match-end 0))))
5081 (while (progn (skip-chars-forward "^<>" end) 4147 (while (progn (skip-chars-forward "^<>" end)
5082 (< (point) end)) 4148 (< (point) end))
5083 (c-clear-<>-pair-props) 4149 (c-clear-char-property (point) 'syntax-table)
5084 (forward-char))))))) 4150 (forward-char)))))))
5085 4151
5086
5087
5088;; Handling of small scale constructs like types and names.
5089
5090;; Dynamically bound variable that instructs `c-forward-type' to also 4152;; Dynamically bound variable that instructs `c-forward-type' to also
5091;; treat possible types (i.e. those that it normally returns 'maybe or 4153;; treat possible types (i.e. those that it normally returns 'maybe or
5092;; 'found for) as actual types (and always return 'found for them). 4154;; 'found for) as actual types (and always return 'found for them).
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 907c308daca..80783670f66 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -426,8 +426,7 @@ stuff. Used on level 1 and higher."
426 (progn 426 (progn
427 (c-mark-<-as-paren beg) 427 (c-mark-<-as-paren beg)
428 (c-mark->-as-paren end)) 428 (c-mark->-as-paren end))
429 ;; (c-clear-char-property beg 'syntax-table) 429 (c-clear-char-property beg 'syntax-table)))
430 (c-clear-char-property beg 'category)))
431 nil))))))) 430 nil)))))))
432 431
433 ;; #define. 432 ;; #define.
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index d3669f259de..ac6ff40b4c0 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
417mode syntax table to get a syntax table that matches all identifiers 396mode syntax table to get a syntax table that matches all identifiers
@@ -444,36 +423,26 @@ the new syntax, as accepted by `modify-syntax-entry'."
444classifies symbol constituents like '_' and '$' as word constituents, 423classifies symbol constituents like '_' and '$' as word constituents,
445so that all identifiers are recognized as words.") 424so 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. 428Typically 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.
461Typically 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,
463and may do such things as removing text-properties which must be 430and may do such things as removing text-properties which must be
464recalculated. 431recalculated.
465 432
466These functions will be run in the order given. Each of them 433It takes 2 parameters, the BEG and END supplied to every
467takes 2 parameters, the BEG and END supplied to every
468before-change function; on entry, the buffer will have been 434before-change function; on entry, the buffer will have been
469widened and match-data will have been saved; point is undefined 435widened and match-data will have been saved; point is undefined
470on both entry and exit; the return value is ignored. 436on both entry and exit; the return value is ignored.
471 437
472The functions are called even when font locking isn't enabled. 438When the mode is initialized, this function is called with
473 439parameters \(point-min) and \(point-max)."
474When the mode is initialized, the functions are called with 440 t nil
475parameters \(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.
479Typically it will extend the region about to be fontified \(see 448Typically it will extend the region about to be fontified \(see
@@ -492,7 +461,7 @@ The function is called even when font locking is disabled.
492When the mode is initialized, this function is called with 461When the mode is initialized, this function is called with
493parameters \(point-min), \(point-max) and <buffer size>." 462parameters \(point-min), \(point-max) and <buffer size>."
494 t nil 463 t nil
495 (c c++ objc) 'c-neutralize-syntax-in-and-mark-CPP 464 (c c++ objc) 'c-extend-and-neutralize-syntax-in-CPP
496 awk 'c-awk-extend-and-syntax-tablify-region) 465 awk 'c-awk-extend-and-syntax-tablify-region)
497(c-lang-defvar c-before-font-lock-function 466(c-lang-defvar c-before-font-lock-function
498 (c-lang-const c-before-font-lock-function)) 467 (c-lang-const c-before-font-lock-function))
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 7f9ed6436f4..2bfa2b7df9b 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -410,7 +410,7 @@ preferably use the `c-mode-menu' language constant directly."
410;; temporary changes in some font lock support modes, causing extra 410;; temporary changes in some font lock support modes, causing extra
411;; unnecessary work and font lock glitches due to interactions between 411;; unnecessary work and font lock glitches due to interactions between
412;; various text properties. 412;; various text properties.
413;; 413;;
414;; (2007-02-12): The macro `combine-after-change-calls' ISN'T used any 414;; (2007-02-12): The macro `combine-after-change-calls' ISN'T used any
415;; more. 415;; more.
416 416
@@ -451,18 +451,18 @@ preferably use the `c-mode-menu' language constant directly."
451 end (point)))))))) 451 end (point))))))))
452 452
453;; c-maybe-stale-found-type records a place near the region being 453;; c-maybe-stale-found-type records a place near the region being
454;; changed where an element of `found-types' might become stale. It 454;; changed where an element of `found-types' might become stale. It
455;; is set in c-before-change and is either nil, or has the form: 455;; is set in c-before-change and is either nil, or has the form:
456;; 456;;
457;; (c-decl-id-start "foo" 97 107 " (* ooka) " "o"), where 457;; (c-decl-id-start "foo" 97 107 " (* ooka) " "o"), where
458;; 458;;
459;; o - `c-decl-id-start' is the c-type text property value at buffer 459;; o - `c-decl-id-start' is the c-type text property value at buffer
460;; pos 96. 460;; pos 96.
461;; 461;;
462;; o - 97 107 is the region potentially containing the stale type - 462;; o - 97 107 is the region potentially containing the stale type -
463;; this is delimited by a non-nil c-type text property at 96 and 463;; this is delimited by a non-nil c-type text property at 96 and
464;; either another one or a ";", "{", or "}" at 107. 464;; either another one or a ";", "{", or "}" at 107.
465;; 465;;
466;; o - " (* ooka) " is the (before change) buffer portion containing 466;; o - " (* ooka) " is the (before change) buffer portion containing
467;; the suspect type (here "ooka"). 467;; the suspect type (here "ooka").
468;; 468;;
@@ -517,9 +517,6 @@ that requires a literal mode spec at compile time."
517 (make-local-variable 'fill-paragraph-function) 517 (make-local-variable 'fill-paragraph-function)
518 (setq fill-paragraph-function 'c-fill-paragraph) 518 (setq fill-paragraph-function 'c-fill-paragraph)
519 519
520 ;; Initialise the cache of brace pairs, and opening braces/brackets/parens.
521 (c-state-cache-init)
522
523 (when (or c-recognize-<>-arglists 520 (when (or c-recognize-<>-arglists
524 (c-major-mode-is 'awk-mode) 521 (c-major-mode-is 'awk-mode)
525 (c-major-mode-is '(c-mode c++-mode objc-mode))) 522 (c-major-mode-is '(c-mode c++-mode objc-mode)))
@@ -641,10 +638,8 @@ compatible with old code; callers should always specify it."
641 (save-restriction 638 (save-restriction
642 (widen) 639 (widen)
643 (save-excursion 640 (save-excursion
644 (if c-get-state-before-change-functions 641 (if c-get-state-before-change-function
645 (mapc (lambda (fn) 642 (funcall c-get-state-before-change-function (point-min) (point-max)))
646 (funcall fn (point-min) (point-max)))
647 c-get-state-before-change-functions))
648 (if c-before-font-lock-function 643 (if c-before-font-lock-function
649 (funcall c-before-font-lock-function (point-min) (point-max) 644 (funcall c-before-font-lock-function (point-min) (point-max)
650 (- (point-max) (point-min)))))) 645 (- (point-max) (point-min))))))
@@ -777,7 +772,7 @@ Note that the style variables are always made local to the buffer."
777 772
778(defmacro c-run-mode-hooks (&rest hooks) 773(defmacro c-run-mode-hooks (&rest hooks)
779 ;; Emacs 21.1 has introduced a system with delayed mode hooks that 774 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
780 ;; requires the use of the new function `run-mode-hooks'. 775 ;; require the use of the new function `run-mode-hooks'.
781 (if (cc-bytecomp-fboundp 'run-mode-hooks) 776 (if (cc-bytecomp-fboundp 'run-mode-hooks)
782 `(run-mode-hooks ,@hooks) 777 `(run-mode-hooks ,@hooks)
783 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) 778 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
@@ -810,8 +805,8 @@ Note that the style variables are always made local to the buffer."
810 ;; has already been widened, and match-data saved. The return value is 805 ;; has already been widened, and match-data saved. The return value is
811 ;; meaningless. 806 ;; meaningless.
812 ;; 807 ;;
813 ;; This function is in the C/C++/ObjC values of 808 ;; This function is the C/C++/ObjC value of
814 ;; `c-get-state-before-change-functions' and is called exclusively as a 809 ;; `c-get-state-before-change-function' and is called exclusively as a
815 ;; before change function. 810 ;; before change function.
816 (goto-char beg) 811 (goto-char beg)
817 (c-beginning-of-macro) 812 (c-beginning-of-macro)
@@ -848,7 +843,7 @@ Note that the style variables are always made local to the buffer."
848 t) 843 t)
849 (t nil))))))) 844 (t nil)))))))
850 845
851(defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len) 846(defun c-extend-and-neutralize-syntax-in-CPP (begg endd old-len)
852 ;; (i) Extend the font lock region to cover all changed preprocessor 847 ;; (i) Extend the font lock region to cover all changed preprocessor
853 ;; regions; it does this by setting the variables `c-new-BEG' and 848 ;; regions; it does this by setting the variables `c-new-BEG' and
854 ;; `c-new-END' to the new boundaries. 849 ;; `c-new-END' to the new boundaries.
@@ -857,15 +852,10 @@ Note that the style variables are always made local to the buffer."
857 ;; extended changed region. "Restore" lines which were CPP lines before the 852 ;; extended changed region. "Restore" lines which were CPP lines before the
858 ;; change and are no longer so; these can be located from the Buffer local 853 ;; change and are no longer so; these can be located from the Buffer local
859 ;; variables `c-old-BOM' and `c-old-EOM'. 854 ;; variables `c-old-BOM' and `c-old-EOM'.
860 ;; 855 ;;
861 ;; (iii) Mark every CPP construct by placing a `category' property value
862 ;; `c-cpp-delimiter' at its start and end. The marked characters are the
863 ;; opening # and usually the terminating EOL, but sometimes the character
864 ;; before a comment/string delimiter.
865 ;;
866 ;; That is, set syntax-table properties on characters that would otherwise 856 ;; That is, set syntax-table properties on characters that would otherwise
867 ;; interact syntactically with those outside the CPP line(s). 857 ;; interact syntactically with those outside the CPP line(s).
868 ;; 858 ;;
869 ;; This function is called from an after-change function, BEGG ENDD and 859 ;; This function is called from an after-change function, BEGG ENDD and
870 ;; OLD-LEN being the standard parameters. It prepares the buffer for font 860 ;; OLD-LEN being the standard parameters. It prepares the buffer for font
871 ;; locking, hence must get called before `font-lock-after-change-function'. 861 ;; locking, hence must get called before `font-lock-after-change-function'.
@@ -876,34 +866,32 @@ Note that the style variables are always made local to the buffer."
876 ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'. 866 ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'.
877 ;; 867 ;;
878 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!! 868 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
879 ;; 869 ;;
880 ;; This function might make hidden buffer changes. 870 ;; This function might make hidden buffer changes.
881 (c-save-buffer-state (limits) 871 (c-save-buffer-state (limits mbeg+1)
882 ;; First determine the region, (c-new-BEG c-new-END), which will get font 872 ;; First determine the region, (c-new-BEG c-new-END), which will get font
883 ;; locked. It might need "neutralizing". This region may not start 873 ;; locked. It might need "neutralizing". This region may not start
884 ;; inside a string, comment, or macro. 874 ;; inside a string, comment, or macro.
885 (goto-char c-old-BOM) ; already set to old start of macro or begg. 875 (goto-char c-old-BOM) ; already set to old start of macro or begg.
886 (setq c-new-BEG 876 (setq c-new-BEG
887 (if (setq limits (c-state-literal-at (point))) 877 (if (setq limits (c-literal-limits))
888 (cdr limits) ; go forward out of any string or comment. 878 (cdr limits) ; go forward out of any string or comment.
889 (point))) 879 (point)))
890 880
891 (goto-char endd) 881 (goto-char endd)
892 (if (setq limits (c-state-literal-at (point))) 882 (if (setq limits (c-literal-limits))
893 (goto-char (car limits))) ; go backward out of any string or comment. 883 (goto-char (car limits))) ; go backward out of any string or comment.
894 (if (c-beginning-of-macro) 884 (if (c-beginning-of-macro)
895 (c-end-of-macro)) 885 (c-end-of-macro))
896 (setq c-new-END (max (+ (- c-old-EOM old-len) (- endd begg)) 886 (setq c-new-END (max (+ (- c-old-EOM old-len) (- endd begg))
897 (point))) 887 (point)))
898 888
899 ;; Clear all old relevant properties. 889 ;; Clear any existing punctuation properties.
900 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1)) 890 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
901 (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
902 ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
903 891
904 ;; Add needed properties to each CPP construct in the region. 892 ;; Add needed properties to each CPP construct in the region.
905 (goto-char c-new-BEG) 893 (goto-char c-new-BEG)
906 (let ((pps-position c-new-BEG) pps-state mbeg) 894 (let ((pps-position c-new-BEG) pps-state)
907 (while (and (< (point) c-new-END) 895 (while (and (< (point) c-new-END)
908 (search-forward-regexp c-anchored-cpp-prefix c-new-END t)) 896 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
909 ;; If we've found a "#" inside a string/comment, ignore it. 897 ;; If we've found a "#" inside a string/comment, ignore it.
@@ -912,24 +900,18 @@ Note that the style variables are always made local to the buffer."
912 pps-position (point)) 900 pps-position (point))
913 (unless (or (nth 3 pps-state) ; in a string? 901 (unless (or (nth 3 pps-state) ; in a string?
914 (nth 4 pps-state)) ; in a comment? 902 (nth 4 pps-state)) ; in a comment?
915 (goto-char (match-beginning 0)) 903 (setq mbeg+1 (point))
916 (setq mbeg (point)) 904 (c-end-of-macro) ; Do we need to go forward 1 char here? No!
917 (if (> (c-syntactic-end-of-macro) mbeg) 905 (c-neutralize-CPP-line mbeg+1 (point))
918 (progn 906 (setq pps-position (point))))))) ; no need to update pps-state.
919 (c-neutralize-CPP-line mbeg (point))
920 (c-set-cpp-delimiters mbeg (point))
921 ;(setq pps-position (point))
922 )
923 (forward-line)) ; no infinite loop with, e.g., "#//"
924 )))))
925 907
926(defun c-before-change (beg end) 908(defun c-before-change (beg end)
927 ;; Function to be put on `before-change-functions'. Primarily, this calls 909 ;; Function to be put on `before-change-function'. Primarily, this calls
928 ;; the language dependent `c-get-state-before-change-functions'. It is 910 ;; the language dependent `c-get-state-before-change-function'. It is
929 ;; otherwise used only to remove stale entries from the `c-found-types' 911 ;; otherwise used only to remove stale entries from the `c-found-types'
930 ;; cache, and to record entries which a `c-after-change' function might 912 ;; cache, and to record entries which a `c-after-change' function might
931 ;; confirm as stale. 913 ;; confirm as stale.
932 ;; 914 ;;
933 ;; Note that this function must be FAST rather than accurate. Note 915 ;; Note that this function must be FAST rather than accurate. Note
934 ;; also that it only has any effect when font locking is enabled. 916 ;; also that it only has any effect when font locking is enabled.
935 ;; We exploit this by checking for font-lock-*-face instead of doing 917 ;; We exploit this by checking for font-lock-*-face instead of doing
@@ -1003,10 +985,8 @@ Note that the style variables are always made local to the buffer."
1003 ;; larger than (beg end). 985 ;; larger than (beg end).
1004 (setq c-new-BEG beg 986 (setq c-new-BEG beg
1005 c-new-END end) 987 c-new-END end)
1006 (if c-get-state-before-change-functions 988 (if c-get-state-before-change-function
1007 (mapc (lambda (fn) 989 (funcall c-get-state-before-change-function beg end))
1008 (funcall fn beg end))
1009 c-get-state-before-change-functions))
1010 )))) 990 ))))
1011 991
1012(defun c-after-change (beg end old-len) 992(defun c-after-change (beg end old-len)
@@ -1040,14 +1020,6 @@ Note that the style variables are always made local to the buffer."
1040 (when (> beg end) 1020 (when (> beg end)
1041 (setq beg end))) 1021 (setq beg end)))
1042 1022
1043 ;; C-y is capable of spuriously converting category properties
1044 ;; c-</>-as-paren-syntax into hard syntax-table properties. Remove
1045 ;; these when it happens.
1046 (c-clear-char-property-with-value beg end 'syntax-table
1047 c-<-as-paren-syntax)
1048 (c-clear-char-property-with-value beg end 'syntax-table
1049 c->-as-paren-syntax)
1050
1051 (c-trim-found-types beg end old-len) ; maybe we don't need all of these. 1023 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1052 (c-invalidate-sws-region-after beg end) 1024 (c-invalidate-sws-region-after beg end)
1053 (c-invalidate-state-cache beg) 1025 (c-invalidate-state-cache beg)