aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-06-16 11:52:01 +0000
committerAlan Mackenzie2019-06-16 11:52:01 +0000
commitf0bf0d0779d6a8430b95ce55d66ee836611ef44f (patch)
tree59490c884fa108aa4dcb19ef1584042f6722aa44
parentb2fb3dc58ceef543951e39b137a21d3e74e042cd (diff)
downloademacs-f0bf0d0779d6a8430b95ce55d66ee836611ef44f.tar.gz
emacs-f0bf0d0779d6a8430b95ce55d66ee836611ef44f.zip
Maintain c-syntax-table-hwm when changing syntax-table text properties
* lisp/progmodes/cc-defs.el: (c-syntax-table-hwm): Move the defvar to here from cc-mode.el, since the variable is needed at compile time in c-emacs-features. (c-min-property-position): New macro. (c-put-char-property, c-clear-char-property, c-clear-char-properties) (c-clear-char-property-with-value-function) (c-clear-char-property-with-value-on-char-function) (c-put-char-properties-on-char): Adjust c-syntax-table-hwm appropriately when syntax-table text properties are changed. * lisp/progmodes/cc-engine.el (c-truncate-lit-pos-cache): Remove the now unneeded setting of c-syntax-table-hwm, and the unneeded declaration of c-syntax-table-hwm.
-rw-r--r--lisp/progmodes/cc-defs.el51
-rw-r--r--lisp/progmodes/cc-engine.el9
-rw-r--r--lisp/progmodes/cc-mode.el7
3 files changed, 48 insertions, 19 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index d20e3ef32d9..7321f166c16 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -107,6 +107,13 @@ not known.")
107;; survives the initialization of the derived mode. 107;; survives the initialization of the derived mode.
108(put 'c-buffer-is-cc-mode 'permanent-local t) 108(put 'c-buffer-is-cc-mode 'permanent-local t)
109 109
110(defvar c-syntax-table-hwm most-positive-fixnum)
111;; A workaround for `syntax-ppss''s failure to take account of changes in
112;; syntax-table text properties. This variable gets set to the lowest
113;; position where the syntax-table text property is changed, and that value
114;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is
115;; due to take place.
116
110 117
111;; The following is used below during compilation. 118;; The following is used below during compilation.
112(eval-and-compile 119(eval-and-compile
@@ -1089,6 +1096,9 @@ MODE is either a mode symbol or a list of mode symbols."
1089 ;; In Emacs 21 we got the `rear-nonsticky' property covered 1096 ;; In Emacs 21 we got the `rear-nonsticky' property covered
1090 ;; by `text-property-default-nonsticky'. 1097 ;; by `text-property-default-nonsticky'.
1091 `(let ((-pos- ,pos)) 1098 `(let ((-pos- ,pos))
1099 ,@(when (and (fboundp 'syntax-ppss)
1100 (eq `,property 'syntax-table))
1101 `((setq c-syntax-table-hwm (min c-syntax-table-hwm -pos-))))
1092 (put-text-property -pos- (1+ -pos-) ',property ,value)))) 1102 (put-text-property -pos- (1+ -pos-) ',property ,value))))
1093 1103
1094(defmacro c-get-char-property (pos property) 1104(defmacro c-get-char-property (pos property)
@@ -1134,12 +1144,29 @@ MODE is either a mode symbol or a list of mode symbols."
1134 ;; In Emacs 21 we got the `rear-nonsticky' property covered 1144 ;; In Emacs 21 we got the `rear-nonsticky' property covered
1135 ;; by `text-property-default-nonsticky'. 1145 ;; by `text-property-default-nonsticky'.
1136 `(let ((pos ,pos)) 1146 `(let ((pos ,pos))
1147 ,@(when (and (fboundp 'syntax-ppss)
1148 (eq `,property 'syntax-table))
1149 `((setq c-syntax-table-hwm (min c-syntax-table-hwm pos))))
1137 (remove-text-properties pos (1+ pos) 1150 (remove-text-properties pos (1+ pos)
1138 '(,property nil)))) 1151 '(,property nil))))
1139 (t 1152 (t
1140 ;; Emacs < 21. 1153 ;; Emacs < 21.
1141 `(c-clear-char-property-fun ,pos ',property)))) 1154 `(c-clear-char-property-fun ,pos ',property))))
1142 1155
1156(defmacro c-min-property-position (from to property)
1157 ;; Return the first position in the range [FROM to) where the text property
1158 ;; PROPERTY is set, or `most-positive-fixnum' if there is no such position.
1159 ;; PROPERTY should be a quoted constant.
1160 `(let ((-from- ,from) (-to- ,to) pos)
1161 (cond
1162 ((and (< -from- -to-)
1163 (get-text-property -from- ,property))
1164 -from-)
1165 ((< (setq pos (next-single-property-change -from- ,property nil -to-))
1166 -to-)
1167 pos)
1168 (most-positive-fixnum))))
1169
1143(defmacro c-clear-char-properties (from to property) 1170(defmacro c-clear-char-properties (from to property)
1144 ;; Remove all the occurrences of the given property in the given 1171 ;; Remove all the occurrences of the given property in the given
1145 ;; region that has been put with `c-put-char-property'. PROPERTY is 1172 ;; region that has been put with `c-put-char-property'. PROPERTY is
@@ -1158,7 +1185,14 @@ MODE is either a mode symbol or a list of mode symbols."
1158 (delete-extent ext)) 1185 (delete-extent ext))
1159 nil ,from ,to nil nil ',property) 1186 nil ,from ,to nil nil ',property)
1160 ;; Emacs. 1187 ;; Emacs.
1161 `(remove-text-properties ,from ,to '(,property nil)))) 1188 (if (and (fboundp 'syntax-ppss)
1189 (eq `,property 'syntax-table))
1190 `(let ((-from- ,from) (-to- ,to))
1191 (setq c-syntax-table-hwm
1192 (min c-syntax-table-hwm
1193 (c-min-property-position -from- -to- ',property)))
1194 (remove-text-properties -from- -to- '(,property nil)))
1195 `(remove-text-properties ,from ,to '(,property nil)))))
1162 1196
1163(defmacro c-search-forward-char-property (property value &optional limit) 1197(defmacro c-search-forward-char-property (property value &optional limit)
1164 "Search forward for a text-property PROPERTY having value VALUE. 1198 "Search forward for a text-property PROPERTY having value VALUE.
@@ -1217,6 +1251,8 @@ been put there by c-put-char-property. POINT remains unchanged."
1217 (not (equal (get-text-property place property) value))) 1251 (not (equal (get-text-property place property) value)))
1218 (setq place (c-next-single-property-change place property nil to))) 1252 (setq place (c-next-single-property-change place property nil to)))
1219 (< place to)) 1253 (< place to))
1254 (when (and (fboundp 'syntax-ppss) (eq property 'syntax-table))
1255 (setq c-syntax-table-hwm (min c-syntax-table-hwm place)))
1220 (setq end-place (c-next-single-property-change place property nil to)) 1256 (setq end-place (c-next-single-property-change place property nil to))
1221 (remove-text-properties place end-place (cons property nil)) 1257 (remove-text-properties place end-place (cons property nil))
1222 ;; Do we have to do anything with stickiness here? 1258 ;; Do we have to do anything with stickiness here?
@@ -1303,7 +1339,10 @@ property, or nil."
1303 (< place to)) 1339 (< place to))
1304 (when (eq (char-after place) char) 1340 (when (eq (char-after place) char)
1305 (remove-text-properties place (1+ place) (cons property nil)) 1341 (remove-text-properties place (1+ place) (cons property nil))
1306 (or first (setq first place))) 1342 (or first
1343 (progn (setq first place)
1344 (when (eq property 'syntax-table)
1345 (setq c-syntax-table-hwm (min c-syntax-table-hwm place))))))
1307 ;; Do we have to do anything with stickiness here? 1346 ;; Do we have to do anything with stickiness here?
1308 (setq place (1+ place))) 1347 (setq place (1+ place)))
1309 first)) 1348 first))
@@ -1344,8 +1383,11 @@ with value CHAR in the region [FROM to)."
1344 (goto-char ,from) 1383 (goto-char ,from)
1345 (while (progn (skip-chars-forward skip-string -to-) 1384 (while (progn (skip-chars-forward skip-string -to-)
1346 (< (point) -to-)) 1385 (< (point) -to-))
1347 (c-put-char-property (point) ,property ,value) 1386 ,@(when (and (fboundp 'syntax-ppss)
1348 (forward-char))))) 1387 (eq (eval property) 'syntax-table))
1388 `((setq c-syntax-table-hwm (min c-syntax-table-hwm (point)))))
1389 (c-put-char-property (point) ,property ,value)
1390 (forward-char)))))
1349 1391
1350;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text. 1392;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text.
1351;; For our purposes, these are characterized by being possible to 1393;; For our purposes, these are characterized by being possible to
@@ -1423,6 +1465,7 @@ with value CHAR in the region [FROM to)."
1423(def-edebug-spec c-put-char-property t) 1465(def-edebug-spec c-put-char-property t)
1424(def-edebug-spec c-get-char-property t) 1466(def-edebug-spec c-get-char-property t)
1425(def-edebug-spec c-clear-char-property t) 1467(def-edebug-spec c-clear-char-property t)
1468(def-edebug-spec c-min-property-position nil) ; invoked only by macros
1426(def-edebug-spec c-clear-char-property-with-value t) 1469(def-edebug-spec c-clear-char-property-with-value t)
1427(def-edebug-spec c-clear-char-property-with-value-on-char t) 1470(def-edebug-spec c-clear-char-property-with-value-on-char t)
1428(def-edebug-spec c-put-char-properties-on-char t) 1471(def-edebug-spec c-put-char-properties-on-char t)
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index eeb71002673..6598cc62c20 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -155,7 +155,6 @@
155(defvar c-doc-line-join-re) 155(defvar c-doc-line-join-re)
156(defvar c-doc-bright-comment-start-re) 156(defvar c-doc-bright-comment-start-re)
157(defvar c-doc-line-join-end-ch) 157(defvar c-doc-line-join-end-ch)
158(defvar c-syntax-table-hwm)
159 158
160 159
161;; Make declarations for all the `c-lang-defvar' variables in cc-langs. 160;; Make declarations for all the `c-lang-defvar' variables in cc-langs.
@@ -3006,13 +3005,7 @@ comment at the start of cc-engine.el for more info."
3006 ;; higher than that position. 3005 ;; higher than that position.
3007 (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos) 3006 (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos)
3008 c-semi-near-cache-limit (min c-semi-near-cache-limit pos) 3007 c-semi-near-cache-limit (min c-semi-near-cache-limit pos)
3009 c-full-near-cache-limit (min c-full-near-cache-limit pos)) 3008 c-full-near-cache-limit (min c-full-near-cache-limit pos)))
3010 (when (fboundp 'syntax-ppss)
3011 ;; Also keep track of where we need to truncate `syntax-ppss''s cache to.
3012 ;; Actually we shouldn't have to touch this thing (which we do not use),
3013 ;; but its design forces us to. Hopefully this will be fixed in a future
3014 ;; version of Emacs.
3015 (setq c-syntax-table-hwm (min c-syntax-table-hwm pos))))
3016 3009
3017 3010
3018;; A system for finding noteworthy parens before the point. 3011;; A system for finding noteworthy parens before the point.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 830dfcae27d..5d0fda389ca 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -506,13 +506,6 @@ preferably use the `c-mode-menu' language constant directly."
506;; and `after-change-functions'. Note that this variable is not set when 506;; and `after-change-functions'. Note that this variable is not set when
507;; `c-before-change' is invoked by a change to text properties. 507;; `c-before-change' is invoked by a change to text properties.
508 508
509(defvar c-syntax-table-hwm most-positive-fixnum)
510;; A workaround for `syntax-ppss''s failure to take account of changes in
511;; syntax-table text properties. This variable gets set to the lowest
512;; position where the syntax-table text property is changed, and that value
513;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is
514;; due to take place.
515
516(defun c-basic-common-init (mode default-style) 509(defun c-basic-common-init (mode default-style)
517 "Do the necessary initialization for the syntax handling routines 510 "Do the necessary initialization for the syntax handling routines
518and the line breaking/filling code. Intended to be used by other 511and the line breaking/filling code. Intended to be used by other