summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-defs.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/cc-defs.el')
-rw-r--r--lisp/progmodes/cc-defs.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index a1270243550..9edaf465346 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -1563,6 +1563,28 @@ with value CHAR in the region [FROM to)."
(forward-char)))))
+;; Miscellaneous macro(s)
+(defvar c-string-fences-set-flag nil)
+;; Non-nil when we have set string fences with `c-restore-string-fences'.
+(defmacro c-with-string-fences (&rest forms)
+ ;; Restore the string fences, evaluate FORMS, then remove them again. It
+ ;; should only be used at the top level of "boundary" functions in CC Mode,
+ ;; i.e. those called from outside CC Mode which directly or indirectly need
+ ;; unbalanced string markers to have their string-fence syntax-table text
+ ;; properties. This includes all calls to `c-parse-state'. This macro will
+ ;; be invoked recursively; however the `c-string-fences-set-flag' mechanism
+ ;; should ensure consistency, when this happens.
+ (declare (debug t))
+ `(unwind-protect
+ (progn
+ (unless c-string-fences-set-flag
+ (c-restore-string-fences))
+ (let ((c-string-fences-set-flag t))
+ ,@forms))
+ (unless c-string-fences-set-flag
+ (c-clear-string-fences))))
+
+
;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text.
;; For our purposes, these are characterized by being possible to
;; remove again without affecting the other text properties in the