[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master f0bf0d0: Maintain c-syntax-table-hwm when changing
From: |
Alan Mackenzie |
Subject: |
[Emacs-diffs] master f0bf0d0: Maintain c-syntax-table-hwm when changing syntax-table text properties |
Date: |
Sun, 16 Jun 2019 07:53:39 -0400 (EDT) |
branch: master
commit f0bf0d0779d6a8430b95ce55d66ee836611ef44f
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>
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.
---
lisp/progmodes/cc-defs.el | 51 +++++++++++++++++++++++++++++++++++++++++----
lisp/progmodes/cc-engine.el | 9 +-------
lisp/progmodes/cc-mode.el | 7 -------
3 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index d20e3ef..7321f16 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -107,6 +107,13 @@ not known.")
;; survives the initialization of the derived mode.
(put 'c-buffer-is-cc-mode 'permanent-local t)
+(defvar c-syntax-table-hwm most-positive-fixnum)
+;; A workaround for `syntax-ppss''s failure to take account of changes in
+;; syntax-table text properties. This variable gets set to the lowest
+;; position where the syntax-table text property is changed, and that value
+;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is
+;; due to take place.
+
;; The following is used below during compilation.
(eval-and-compile
@@ -1089,6 +1096,9 @@ MODE is either a mode symbol or a list of mode symbols."
;; In Emacs 21 we got the `rear-nonsticky' property covered
;; by `text-property-default-nonsticky'.
`(let ((-pos- ,pos))
+ ,@(when (and (fboundp 'syntax-ppss)
+ (eq `,property 'syntax-table))
+ `((setq c-syntax-table-hwm (min c-syntax-table-hwm -pos-))))
(put-text-property -pos- (1+ -pos-) ',property ,value))))
(defmacro c-get-char-property (pos property)
@@ -1134,12 +1144,29 @@ MODE is either a mode symbol or a list of mode symbols."
;; In Emacs 21 we got the `rear-nonsticky' property covered
;; by `text-property-default-nonsticky'.
`(let ((pos ,pos))
+ ,@(when (and (fboundp 'syntax-ppss)
+ (eq `,property 'syntax-table))
+ `((setq c-syntax-table-hwm (min c-syntax-table-hwm pos))))
(remove-text-properties pos (1+ pos)
'(,property nil))))
(t
;; Emacs < 21.
`(c-clear-char-property-fun ,pos ',property))))
+(defmacro c-min-property-position (from to property)
+ ;; Return the first position in the range [FROM to) where the text property
+ ;; PROPERTY is set, or `most-positive-fixnum' if there is no such position.
+ ;; PROPERTY should be a quoted constant.
+ `(let ((-from- ,from) (-to- ,to) pos)
+ (cond
+ ((and (< -from- -to-)
+ (get-text-property -from- ,property))
+ -from-)
+ ((< (setq pos (next-single-property-change -from- ,property nil -to-))
+ -to-)
+ pos)
+ (most-positive-fixnum))))
+
(defmacro c-clear-char-properties (from to property)
;; Remove all the occurrences of the given property in the given
;; 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."
(delete-extent ext))
nil ,from ,to nil nil ',property)
;; Emacs.
- `(remove-text-properties ,from ,to '(,property nil))))
+ (if (and (fboundp 'syntax-ppss)
+ (eq `,property 'syntax-table))
+ `(let ((-from- ,from) (-to- ,to))
+ (setq c-syntax-table-hwm
+ (min c-syntax-table-hwm
+ (c-min-property-position -from- -to- ',property)))
+ (remove-text-properties -from- -to- '(,property nil)))
+ `(remove-text-properties ,from ,to '(,property nil)))))
(defmacro c-search-forward-char-property (property value &optional limit)
"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."
(not (equal (get-text-property place property) value)))
(setq place (c-next-single-property-change place property nil to)))
(< place to))
+ (when (and (fboundp 'syntax-ppss) (eq property 'syntax-table))
+ (setq c-syntax-table-hwm (min c-syntax-table-hwm place)))
(setq end-place (c-next-single-property-change place property nil to))
(remove-text-properties place end-place (cons property nil))
;; Do we have to do anything with stickiness here?
@@ -1303,7 +1339,10 @@ property, or nil."
(< place to))
(when (eq (char-after place) char)
(remove-text-properties place (1+ place) (cons property nil))
- (or first (setq first place)))
+ (or first
+ (progn (setq first place)
+ (when (eq property 'syntax-table)
+ (setq c-syntax-table-hwm (min c-syntax-table-hwm
place))))))
;; Do we have to do anything with stickiness here?
(setq place (1+ place)))
first))
@@ -1344,8 +1383,11 @@ with value CHAR in the region [FROM to)."
(goto-char ,from)
(while (progn (skip-chars-forward skip-string -to-)
(< (point) -to-))
- (c-put-char-property (point) ,property ,value)
- (forward-char)))))
+ ,@(when (and (fboundp 'syntax-ppss)
+ (eq (eval property) 'syntax-table))
+ `((setq c-syntax-table-hwm (min c-syntax-table-hwm (point)))))
+ (c-put-char-property (point) ,property ,value)
+ (forward-char)))))
;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text.
;; For our purposes, these are characterized by being possible to
@@ -1423,6 +1465,7 @@ with value CHAR in the region [FROM to)."
(def-edebug-spec c-put-char-property t)
(def-edebug-spec c-get-char-property t)
(def-edebug-spec c-clear-char-property t)
+(def-edebug-spec c-min-property-position nil) ; invoked only by macros
(def-edebug-spec c-clear-char-property-with-value t)
(def-edebug-spec c-clear-char-property-with-value-on-char t)
(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 eeb7100..6598cc6 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -155,7 +155,6 @@
(defvar c-doc-line-join-re)
(defvar c-doc-bright-comment-start-re)
(defvar c-doc-line-join-end-ch)
-(defvar c-syntax-table-hwm)
;; 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."
;; higher than that position.
(setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos)
c-semi-near-cache-limit (min c-semi-near-cache-limit pos)
- c-full-near-cache-limit (min c-full-near-cache-limit pos))
- (when (fboundp 'syntax-ppss)
- ;; Also keep track of where we need to truncate `syntax-ppss''s cache to.
- ;; Actually we shouldn't have to touch this thing (which we do not use),
- ;; but its design forces us to. Hopefully this will be fixed in a future
- ;; version of Emacs.
- (setq c-syntax-table-hwm (min c-syntax-table-hwm pos))))
+ c-full-near-cache-limit (min c-full-near-cache-limit pos)))
;; A system for finding noteworthy parens before the point.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 830dfca..5d0fda3 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."
;; and `after-change-functions'. Note that this variable is not set when
;; `c-before-change' is invoked by a change to text properties.
-(defvar c-syntax-table-hwm most-positive-fixnum)
-;; A workaround for `syntax-ppss''s failure to take account of changes in
-;; syntax-table text properties. This variable gets set to the lowest
-;; position where the syntax-table text property is changed, and that value
-;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is
-;; due to take place.
-
(defun c-basic-common-init (mode default-style)
"Do the necessary initialization for the syntax handling routines
and the line breaking/filling code. Intended to be used by other
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master f0bf0d0: Maintain c-syntax-table-hwm when changing syntax-table text properties,
Alan Mackenzie <=