emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 004ee6b046: CC Mode: correct the calculation and handling of c-us


From: Alan Mackenzie
Subject: master 004ee6b046: CC Mode: correct the calculation and handling of c-use-category.
Date: Tue, 26 Jul 2022 15:46:00 -0400 (EDT)

branch: master
commit 004ee6b0460c450308c83dffc567fb1b8672777c
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    CC Mode: correct the calculation and handling of c-use-category.
    
    This fixes bug #56629.  The use of c-use-category was inconsistent, with the
    result that it would be nil at compilation time, but t at run time.  This
    resulted in wrongly writing syntax-table text properties to <s and >s, yet
    testing for category properties on them.
    
    * lisp/progmodes/cc-defs.el (c-use-category): Move to after the definition 
of
    c-<-as-paren-syntax and c->-as-paren-syntax so as correctly to be able to 
use
    their values.  Put an eval-when-compile around the calculation of its value,
    to reduce the chances of future failure.
    (c-mark-<-as-paren, c-mark->-as-paren, c-unmark-<->-as-paren, 
c-sc-scan-lists)
    (c-sc-parse-partial-sexp): Wrap c-use-category in (eval-when-compile ...) as
    an optimization, preventing the XEmacs code also being generated.
---
 lisp/progmodes/cc-defs.el | 59 ++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 26 deletions(-)

diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 9edaf46534..04f519dd0a 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -425,23 +425,6 @@ to it is returned.  This function does not modify the 
point or the mark."
 
 (defvar lookup-syntax-properties)       ;XEmacs.
 
-(eval-and-compile
-  ;; Constant to decide at compilation time whether to use category
-  ;; properties.  Currently (2010-03) they're available only on GNU Emacs.
-  (defconst c-use-category
-    (with-temp-buffer
-      (let ((parse-sexp-lookup-properties t)
-           (lookup-syntax-properties t))
-        (set-syntax-table (make-syntax-table))
-        (insert "<()>")
-        (put-text-property (point-min) (1+ (point-min))
-                          'category 'c-<-as-paren-syntax)
-        (put-text-property (+ 3 (point-min)) (+ 4 (point-min))
-                          'category 'c->-as-paren-syntax)
-        (goto-char (point-min))
-        (forward-sexp)
-        (= (point) (+ 4 (point-min)))))))
-
 (defmacro c-is-escaped (pos)
   ;; Are there an odd number of backslashes before POS?
   (declare (debug t))
@@ -1147,11 +1130,13 @@ MODE is either a mode symbol or a list of mode symbols."
                               (cc-bytecomp-fboundp 'delete-extent)
                               (cc-bytecomp-fboundp 'map-extents))))
 
-(defconst c-<-as-paren-syntax '(4 . ?>))
-(put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax)
+(eval-and-compile
+  (defconst c-<-as-paren-syntax '(4 . ?>))
+  (put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax))
 
-(defconst c->-as-paren-syntax '(5 . ?<))
-(put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax)
+(eval-and-compile
+  (defconst c->-as-paren-syntax '(5 . ?<))
+  (put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax))
 
 ;; `c-put-char-property' is complex enough in XEmacs and Emacs < 21 to
 ;; make it a function.
@@ -1210,6 +1195,26 @@ MODE is either a mode symbol or a list of mode symbols."
           `((setq c-syntax-table-hwm (min c-syntax-table-hwm -pos-))))
        (put-text-property -pos- (1+ -pos-) ',property ,value))))
 
+(eval-and-compile
+  ;; Constant to decide at compilation time whether to use category
+  ;; properties.  Currently (2010-03) they're available only on GNU
+  ;; Emacs.  This defconst must follow the declarations of
+  ;; `c-<-as-paren-syntax' and `c->-as-paren-syntax'.
+  (defconst c-use-category
+    (eval-when-compile
+      (with-temp-buffer
+       (let ((parse-sexp-lookup-properties t)
+             (lookup-syntax-properties t))
+          (set-syntax-table (make-syntax-table))
+          (insert "<()>")
+          (put-text-property (point-min) (1+ (point-min))
+                            'category 'c-<-as-paren-syntax)
+          (put-text-property (+ 3 (point-min)) (+ 4 (point-min))
+                            'category 'c->-as-paren-syntax)
+          (goto-char (point-min))
+          (forward-sexp)
+          (= (point) (+ 4 (point-min))))))))
+
 (defmacro c-get-char-property (pos property)
   ;; Get the value of the given property on the character at POS if
   ;; it's been put there by `c-put-char-property'.  PROPERTY is
@@ -1646,7 +1651,7 @@ with value CHAR in the region [FROM to)."
   ;; toggle the property in all template brackets simultaneously and
   ;; cheaply.  We use this, for instance, in `c-parse-state'.
   (declare (debug t))
-  (if c-use-category
+  (if (eval-when-compile c-use-category)
       `(c-put-char-property ,pos 'category 'c-<-as-paren-syntax)
     `(c-put-char-property ,pos 'syntax-table c-<-as-paren-syntax)))
 
@@ -1661,7 +1666,7 @@ with value CHAR in the region [FROM to)."
   ;; toggle the property in all template brackets simultaneously and
   ;; cheaply.  We use this, for instance, in `c-parse-state'.
   (declare (debug t))
-  (if c-use-category
+  (if (eval-when-compile c-use-category)
       `(c-put-char-property ,pos 'category 'c->-as-paren-syntax)
     `(c-put-char-property ,pos 'syntax-table c->-as-paren-syntax)))
 
@@ -1675,7 +1680,9 @@ with value CHAR in the region [FROM to)."
   ;; toggle the property in all template brackets simultaneously and
   ;; cheaply.  We use this, for instance, in `c-parse-state'.
   (declare (debug t))
-  `(c-clear-char-property ,pos ,(if c-use-category ''category ''syntax-table)))
+  `(c-clear-char-property ,pos ,(if (eval-when-compile c-use-category)
+                                   ''category
+                                 ''syntax-table)))
 
 (defsubst c-suppress-<->-as-parens ()
   ;; Suppress the syntactic effect of all marked < and > as parens.  Note
@@ -1755,7 +1762,7 @@ with value CHAR in the region [FROM to)."
 
 (defmacro c-sc-scan-lists (from count depth)
   (declare (debug t))
-  (if c-use-category
+  (if (eval-when-compile c-use-category)
       `(scan-lists ,from ,count ,depth)
     (cond
      ((and (eq count 1) (eq depth 1))
@@ -1803,7 +1810,7 @@ with value CHAR in the region [FROM to)."
 (defmacro c-sc-parse-partial-sexp (from to &optional targetdepth stopbefore
                                        oldstate)
   (declare (debug t))
-  (if c-use-category
+  (if (eval-when-compile c-use-category)
       `(parse-partial-sexp ,from ,to ,targetdepth ,stopbefore ,oldstate)
     `(c-sc-parse-partial-sexp-no-category ,from ,to ,targetdepth ,stopbefore
                                          ,oldstate)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]