1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Amend CC Mode so that the test suite in XEmacs runs error free

* lisp/progmodes/cc-awk.el (awk-font-lock-keywords):
Reformulate this using backquote and ,@.  Only include the
entry for _" in Emacs.

* lisp/progmodes/cc-defs.el (c--mapcan, c--set-difference)
c--intersection, c--macroexpand-all, c--delete-duplicates): No
longer use the existence of cl-lib.el as the criterion for
what to expand to.
(c-min-property-position): Use c-next-single-property-change
rather than next-single-property-change.  This now works in
XEmacs.

* lisp/progmodes/cc-engine.el
(c-invalidate-sws-region-after-del)
(c-invalidate-sws-region-after-ins, c-forward-sws)
(c-backward-sws, c-find-decl-spots): Replace
next/previous-single-property-change by
c-next/previous-single-property-change to ensure functionality
in XEmacs.
(c-forward-sws, c-backward-sws): Handle NO-BREAKING-SPACE as
whitespace.  This corrects the error in hardspace.c in the test
suite.

* lisp/progmodes/cc-fonts.el (c-font-lock-ml-strings): Refactor
some nested `if's into a cond form.  Don't fontify multiline
string delimiters in XEmacs, in keeping with its string
conventions.

* lisp/progmodes/cc-langs.el (c-populate-syntax-table): Set the
syntax of NO-BREAKING-SPACE to whitespace rather than
punctuation.

* lisp/progmodes/cc-mode.el (c-before-change): Use
c-previous-single-property-change rather than
previous-single-property-change to ensure functionality in
XEmacs.
This commit is contained in:
Alan Mackenzie 2025-06-11 13:43:50 +00:00
parent bf418cd836
commit 1468daf1d1
6 changed files with 114 additions and 105 deletions

View file

@ -962,9 +962,9 @@
;; in XEmacs 21.4.4. acm 2002/9/19.
(defconst awk-font-lock-keywords
(eval-when-compile
(list
;; Function declarations.
`(,(c-make-font-lock-search-function
`(
;; Function declarations.
(,(c-make-font-lock-search-function
"^\\s *\\(func\\(tion\\)?\\)\\s +\\(\\(\\sw+\\(::\\sw+\\)?\\)\\s *\\)?\\(([^()]*)\\)?"
'(1 'font-lock-keyword-face t)
;; We can't use LAXMATCH in `c-make-font-lock-search-function', so....
@ -983,15 +983,15 @@
nil))))
;; Variable names.
(cons
(concat "\\<"
(regexp-opt
'("ARGC" "ARGIND" "ARGV" "BINMODE" "CONVFMT" "ENVIRON"
"ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FPAT" "FS" "FUNCTAB"
"IGNORECASE" "LINT" "NF" "NR" "OFMT" "OFS" "ORS" "PREC"
"PROCINFO" "RLENGTH" "ROUNDMODE" "RS" "RSTART" "RT" "SUBSEP"
"SYMTAB" "TEXTDOMAIN") t) "\\>")
'font-lock-variable-name-face)
,(cons
(concat "\\<"
(regexp-opt
'("ARGC" "ARGIND" "ARGV" "BINMODE" "CONVFMT" "ENVIRON"
"ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FPAT" "FS" "FUNCTAB"
"IGNORECASE" "LINT" "NF" "NR" "OFMT" "OFS" "ORS" "PREC"
"PROCINFO" "RLENGTH" "ROUNDMODE" "RS" "RSTART" "RT" "SUBSEP"
"SYMTAB" "TEXTDOMAIN") t) "\\>")
'font-lock-variable-name-face)
;; Special file names. (acm, 2002/7/22)
;; The following regexp was created by first evaluating this in GNU Emacs 21.1:
@ -1003,7 +1003,7 @@
;; regexp so that a " must come before, and either a " or heuristic stuff after.
;; The surrounding quotes are fontified along with the filename, since, semantically,
;; they are an indivisible unit.
'("\\(\"/dev/\\(fd/[0-9]+\\|p\\(\\(\\(gr\\)?p\\)?id\\)\\|\
("\\(\"/dev/\\(fd/[0-9]+\\|p\\(\\(\\(gr\\)?p\\)?id\\)\\|\
std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\
\\(\\(\"\\)\\|\\([^\"/\n\r][^\"\n\r]*\\)?$\\)"
(1 font-lock-variable-name-face t)
@ -1015,22 +1015,22 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\
;; , replacing "lport", "rhost", and "rport" with "[[:alnum:]]+".
;; This cannot be combined with the above pattern, because the match number
;; for the (optional) closing \" would then exceed 9.
'("\\(\"/inet[46]?/\\(\\(raw\\|\\(tc\\|ud\\)p\\)/[[:alnum:]]+/[[:alnum:]]+/[[:alnum:]]+\\)\\)\\>\
("\\(\"/inet[46]?/\\(\\(raw\\|\\(tc\\|ud\\)p\\)/[[:alnum:]]+/[[:alnum:]]+/[[:alnum:]]+\\)\\)\\>\
\\(\\(\"\\)\\|\\([^\"/\n\r][^\"\n\r]*\\)?$\\)"
(1 font-lock-variable-name-face t)
(6 font-lock-variable-name-face t t))
;; Keywords.
(concat "\\<"
(regexp-opt
'("BEGIN" "BEGINFILE" "END" "ENDFILE"
"break" "case" "continue" "default" "delete"
"do" "else" "exit" "for" "getline" "if" "in" "next"
"nextfile" "return" "switch" "while")
t) "\\>")
,(concat "\\<"
(regexp-opt
'("BEGIN" "BEGINFILE" "END" "ENDFILE"
"break" "case" "continue" "default" "delete"
"do" "else" "exit" "for" "getline" "if" "in" "next"
"nextfile" "return" "switch" "while")
t) "\\>")
;; Builtins.
`(eval . (list
(eval . (list
,(concat
"\\<"
(regexp-opt
@ -1045,32 +1045,33 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\
"\\>")
0 c-preprocessor-face-name))
;; Directives
`(eval . '("@\\(include\\|load\\|namespace\\)\\>" 0 ,c-preprocessor-face-name))
;; Directives
(eval . '("@\\(include\\|load\\|namespace\\)\\>" 0 ,c-preprocessor-face-name))
;; gawk debugging keywords. (acm, 2002/7/21)
;; (Removed, 2003/6/6. These functions are now fontified as built-ins)
;; (list (concat "\\<" (regexp-opt '("adump" "stopme") t) "\\>")
;; 0 'font-lock-warning-face)
;; gawk debugging keywords. (acm, 2002/7/21)
;; (Removed, 2003/6/6. These functions are now fontified as built-ins)
;; (list (concat "\\<" (regexp-opt '("adump" "stopme") t) "\\>")
;; 0 'font-lock-warning-face)
;; User defined functions with an apparent spurious space before the
;; opening parenthesis. acm, 2002/5/30.
`(,(concat "\\(\\w\\|_\\)" c-awk-escaped-nls* "\\s "
;; User defined functions with an apparent spurious space before the
;; opening parenthesis. acm, 2002/5/30.
(,(concat "\\(\\w\\|_\\)" c-awk-escaped-nls* "\\s "
c-awk-escaped-nls*-with-space* "(")
(0 'font-lock-warning-face))
;; Double :: tokens, or the same with space(s) around them.
#'c-awk-font-lock-invalid-namespace-separators
;; Double :: tokens, or the same with space(s) around them.
c-awk-font-lock-invalid-namespace-separators
;; Space after \ in what looks like an escaped newline. 2002/5/31
'("\\\\\\s +$" 0 font-lock-warning-face t)
;; Space after \ in what looks like an escaped newline. 2002/5/31
("\\\\\\s +$" 0 font-lock-warning-face t)
;; Unbalanced string (") or regexp (/) delimiters. 2002/02/16.
'("\\s|" 0 font-lock-warning-face t nil)
;; gawk 3.1 localizable strings ( _"translate me!"). 2002/5/21
'("\\(_\\)\\s|" 1 font-lock-warning-face)
'("\\(_\\)\\s\"" 1 font-lock-string-face) ; FIXME! not for XEmacs. 2002/10/6
))
;; Unbalanced string (") or regexp (/) delimiters. 2002/02/16.
("\\s|" 0 font-lock-warning-face t nil)
;; gawk 3.1 localizable strings ( _"translate me!"). 2002/5/21
("\\(_\\)\\s|" 1 font-lock-warning-face)
,@(unless (featurep 'xemacs)
'(("\\(_\\)\\s\"" 1 font-lock-string-face)))
))
"Default expressions to highlight in AWK mode.")
;; ACM 2002/9/29. Movement functions, e.g. for C-M-a and C-M-e

View file

@ -188,9 +188,12 @@ This variant works around bugs in `eval-when-compile' in various
(subrp (symbol-function 'mapcan)))
;; XEmacs and Emacs >= 26.
`(mapcan ,fun ,liszt))
((eq c--cl-library 'cl-lib)
;; Emacs >= 24.3, < 26.
`(cl-mapcan ,fun ,liszt))
;; The following was commented out on 2025-06-02. cl-mapcan fails in an
;; obscure fashion in c-keywords-obarray. See that c-lang-defvar for
;; details.
;; ((eq c--cl-library 'cl-lib)
;; ;; Emacs >= 24.3, < 26.
;; `(cl-mapcan ,fun ,liszt))
(t
;; Emacs <= 24.2. It would be nice to be able to distinguish between
;; compile-time and run-time use here.
@ -199,16 +202,16 @@ This variant works around bugs in `eval-when-compile' in various
(defmacro c--set-difference (liszt1 liszt2 &rest other-args)
;; Macro to smooth out the renaming of `set-difference' in Emacs 24.3.
(declare (debug (form form &rest [symbolp form])))
(if (eq c--cl-library 'cl-lib)
`(cl-set-difference ,liszt1 ,liszt2 ,@other-args)
`(set-difference ,liszt1 ,liszt2 ,@other-args)))
(if (fboundp 'set-difference)
`(set-difference ,liszt1 ,liszt2 ,@other-args)
`(cl-set-difference ,liszt1 ,liszt2 ,@other-args)))
(defmacro c--intersection (liszt1 liszt2 &rest other-args)
;; Macro to smooth out the renaming of `intersection' in Emacs 24.3.
(declare (debug (form form &rest [symbolp form])))
(if (eq c--cl-library 'cl-lib)
`(cl-intersection ,liszt1 ,liszt2 ,@other-args)
`(intersection ,liszt1 ,liszt2 ,@other-args)))
(if (fboundp 'intersection)
`(intersection ,liszt1 ,liszt2 ,@other-args)
`(cl-intersection ,liszt1 ,liszt2 ,@other-args)))
(eval-and-compile
(defmacro c--macroexpand-all (form &optional environment)
@ -221,9 +224,9 @@ This variant works around bugs in `eval-when-compile' in various
(defmacro c--delete-duplicates (cl-seq &rest cl-keys)
;; Macro to smooth out the renaming of `delete-duplicates' in Emacs 24.3.
(declare (debug (form &rest [symbolp form])))
(if (eq c--cl-library 'cl-lib)
`(cl-delete-duplicates ,cl-seq ,@cl-keys)
`(delete-duplicates ,cl-seq ,@cl-keys))))
(if (fboundp 'delete-duplicates)
`(delete-duplicates ,cl-seq ,@cl-keys)
`(cl-delete-duplicates ,cl-seq ,@cl-keys))))
(defmacro c-font-lock-flush (beg end)
"Declare the region BEG...END's fontification as out-of-date.
@ -1367,7 +1370,7 @@ MODE is either a mode symbol or a list of mode symbols."
((and (< -from- -to-)
(get-text-property -from- ,property))
-from-)
((< (setq pos (next-single-property-change -from- ,property nil -to-))
((< (setq pos (c-next-single-property-change -from- ,property nil -to-))
-to-)
pos)
(most-positive-fixnum))))

View file

@ -2033,11 +2033,11 @@ comment at the start of cc-engine.el for more info."
; comment delimiters are 2
; chars long.
(or (get-text-property end 'c-in-sws)
(next-single-property-change end 'c-in-sws nil
(cdr c-sws-lit-limits))
(c-next-single-property-change end 'c-in-sws nil
(cdr c-sws-lit-limits))
(get-text-property end 'c-is-sws)
(next-single-property-change end 'c-is-sws nil
(cdr c-sws-lit-limits))))
(c-next-single-property-change end 'c-is-sws nil
(cdr c-sws-lit-limits))))
(cdr c-sws-lit-limits))))
(defun c-invalidate-sws-region-after-ins (end)
@ -2055,10 +2055,10 @@ comment at the start of cc-engine.el for more info."
limits (cons (point)
(progn (c-end-of-macro) (point)))))
(when (memq lit-type '(c c++ pound))
(let ((next-in (next-single-property-change (car limits) 'c-in-sws
nil (cdr limits)))
(next-is (next-single-property-change (car limits) 'c-is-sws
nil (cdr limits))))
(let ((next-in (c-next-single-property-change (car limits) 'c-in-sws
nil (cdr limits)))
(next-is (c-next-single-property-change (car limits) 'c-is-sws
nil (cdr limits))))
(and (or next-in next-is)
(cdr limits)))))))
@ -2141,7 +2141,7 @@ comment at the start of cc-engine.el for more info."
;; Skip simple ws and do a quick check on the following character to see
;; if it's anything that can't start syntactic ws, so we can bail out
;; early in the majority of cases when there just are a few ws chars.
(c-skip-ws-chars-forward " \t\n\r\f\v")
(c-skip-ws-chars-forward " \t\n\r\f\v ")
(when (or (looking-at c-syntactic-ws-start)
(and c-opt-cpp-prefix
(looking-at c-noise-macro-name-re))
@ -2154,7 +2154,7 @@ comment at the start of cc-engine.el for more info."
'c-is-sws t))
;; Find the last rung position to avoid setting properties in all
;; the cases when the marked rung is complete.
;; (`next-single-property-change' is certain to move at least one
;; (`c-next-single-property-change' is certain to move at least one
;; step forward.)
(setq rung-pos (1- (c-next-single-property-change
rung-is-marked 'c-is-sws nil rung-end-pos)))
@ -2182,7 +2182,7 @@ comment at the start of cc-engine.el for more info."
;; If the `c-in-sws' region extended past the last
;; `c-is-sws' char we have to go back a bit.
(or (get-text-property (1- (point)) 'c-is-sws)
(goto-char (previous-single-property-change
(goto-char (c-previous-single-property-change
(point) 'c-is-sws)))
(backward-char))
@ -2191,7 +2191,7 @@ comment at the start of cc-engine.el for more info."
rung-pos (point) (point-max))
(setq rung-pos (point))
(and (> (c-skip-ws-chars-forward " \t\n\r\f\v") 0)
(and (> (c-skip-ws-chars-forward " \t\n\r\f\v ") 0)
(not (eobp))))
;; We'll loop here if there is simple ws after the last rung.
@ -2258,7 +2258,7 @@ comment at the start of cc-engine.el for more info."
(and c-opt-cpp-prefix
(looking-at c-opt-cpp-start)
(setq macro-start (point))
(progn (c-skip-ws-chars-backward " \t")
(progn (c-skip-ws-chars-backward " \t ")
(bolp))
(or (bobp)
(progn (backward-char)
@ -2298,7 +2298,7 @@ comment at the start of cc-engine.el for more info."
;; We've searched over a piece of non-white syntactic ws. See if this
;; can be cached.
(setq next-rung-pos (point))
(c-skip-ws-chars-forward " \t\n\r\f\v")
(c-skip-ws-chars-forward " \t\n\r\f\v ")
(setq rung-end-pos (min (1+ (point)) (point-max)))
(if (or
@ -2395,7 +2395,7 @@ comment at the start of cc-engine.el for more info."
;; bail out early in the majority of cases when there just are a few ws
;; chars. Newlines are complicated in the backward direction, so we can't
;; skip over them.
(c-skip-ws-chars-backward " \t\f")
(c-skip-ws-chars-backward " \t\f ")
(when (and (not (bobp))
(save-excursion
(or (and
@ -2423,7 +2423,7 @@ comment at the start of cc-engine.el for more info."
(setq simple-ws-beg (or attr-end ; After attribute.
(match-end 1) ; Noise macro, etc.
(match-end 0))) ; c-syntactic-ws-end
(c-skip-ws-chars-backward " \t\n\r\f\v")
(c-skip-ws-chars-backward " \t\n\r\f\v ")
(if (setq rung-is-marked (text-property-any
(point) (min (1+ rung-pos) (point-max))
'c-is-sws t))
@ -2447,7 +2447,7 @@ comment at the start of cc-engine.el for more info."
;; The following search is the main reason that `c-in-sws'
;; and `c-is-sws' aren't combined to one property.
(goto-char (previous-single-property-change
(goto-char (c-previous-single-property-change
(point) 'c-in-sws nil (point-min)))
(unless (get-text-property (point) 'c-is-sws)
;; If the `c-in-sws' region extended past the first
@ -2460,10 +2460,10 @@ comment at the start of cc-engine.el for more info."
(point) rung-pos (point-min))
(setq rung-pos (point))
(if (and (< (min (c-skip-ws-chars-backward " \t\f\v")
(if (and (< (min (c-skip-ws-chars-backward " \t\f\v ")
(progn
(setq simple-ws-beg (point))
(c-skip-ws-chars-backward " \t\n\r\f\v")))
(c-skip-ws-chars-backward " \t\n\r\f\v ")))
0)
(setq rung-is-marked
(text-property-any (point) rung-pos
@ -2543,7 +2543,7 @@ comment at the start of cc-engine.el for more info."
;; the macro, and then `simple-ws-beg' must be kept on the
;; same side of those comments.
(goto-char simple-ws-beg)
(c-skip-ws-chars-backward " \t\n\r\f\v")
(c-skip-ws-chars-backward " \t\n\r\f\v ")
(if (eq (char-before) ?\\)
(forward-char))
(forward-line 1)
@ -2556,7 +2556,7 @@ comment at the start of cc-engine.el for more info."
t)))
((/= (save-excursion
(c-skip-ws-chars-forward " \t\n\r\f\v" simple-ws-beg)
(c-skip-ws-chars-forward " \t\n\r\f\v " simple-ws-beg)
(setq next-rung-pos (point)))
simple-ws-beg)
;; Skipped over comments. Must put point at the end of
@ -2593,8 +2593,8 @@ comment at the start of cc-engine.el for more info."
;; We've searched over a piece of non-white syntactic ws. See if this
;; can be cached.
(setq next-rung-pos (point))
(c-skip-ws-chars-backward " \t\f\v")
(c-skip-ws-chars-backward " \t\f\v ")
(if (or
;; Cache if we started either from a marked rung or from a
;; completely uncached position.
@ -2603,7 +2603,7 @@ comment at the start of cc-engine.el for more info."
;; Cache if there's a marked rung in the encountered simple ws.
(save-excursion
(c-skip-ws-chars-backward " \t\n\r\f\v")
(c-skip-ws-chars-backward " \t\n\r\f\v ")
(text-property-any (point) (min (1+ next-rung-pos) (point-max))
'c-is-sws t)))
@ -6548,7 +6548,7 @@ comment at the start of cc-engine.el for more info."
;; inside a comment?
(while (and (not (bobp))
(c-got-face-at (1- (point)) c-literal-faces))
(goto-char (previous-single-property-change
(goto-char (c-previous-single-property-change
(point) 'face nil (point-min)))) ; No limit. FIXME, perhaps? 2020-12-07.
;; XEmacs doesn't fontify the quotes surrounding string
@ -6718,7 +6718,7 @@ comment at the start of cc-engine.el for more info."
(goto-char start-in-literal)
(goto-char cfd-start-pos)
(while (progn
(goto-char (previous-single-property-change
(goto-char (c-previous-single-property-change
(point) 'c-type nil start-in-literal))
(and (> (point) start-in-literal)
(not (eq (c-get-char-property (point) 'c-type)

View file

@ -1989,19 +1989,19 @@ casts and declarations are fontified. Used on level 2 and higher."
(>= (point) (cadar string-delims))
(or (not (cdr string-delims))
(< (point) (cadr string-delims))))
(if (cdr string-delims)
(goto-char (cadr string-delims))
(if (equal (c-get-char-property (1- (cadar string-delims))
'syntax-table)
'(15)) ; "Always" the case.
;; The next search should be successful for an unterminated ml
;; string inside a macro, but not for any other unterminated
;; string.
(progn
(or (c-search-forward-char-property 'syntax-table '(15) limit)
(goto-char limit))
(setq string-delims nil))
(c-benign-error "Missing '(15) syntax-table property at %d"
(cond
((cdr string-delims)
(goto-char (cadr string-delims)))
((equal (c-get-char-property (1- (cadar string-delims))
'syntax-table)
'(15)) ; "Always" the case.
;; The next search should be successful for an unterminated ml
;; string inside a macro, but not for any other unterminated
;; string.
(or (c-search-forward-char-property 'syntax-table '(15) limit)
(goto-char limit))
(setq string-delims nil))
(t (c-benign-error "Messing '(15) syntax-table property at %d"
(1- (cadar string-delims)))
(setq string-delims nil))))
@ -2009,10 +2009,14 @@ casts and declarations are fontified. Used on level 2 and higher."
((and string-delims
(cdr string-delims)
(>= (point) (cadr string-delims)))
(c-put-font-lock-face (cadr string-delims) (1+ (cadr string-delims))
'font-lock-string-face)
(c-remove-font-lock-face (1+ (cadr string-delims))
(caddr string-delims))
(unless (featurep 'xemacs)
(c-put-font-lock-face (cadr string-delims) (1+ (cadr string-delims))
'font-lock-string-face))
(c-remove-font-lock-face
(if (featurep 'xemacs)
(cadr string-delims)
(1+ (cadr string-delims)))
(caddr string-delims))
(goto-char (caddr string-delims))
(setq string-delims nil))
@ -2021,10 +2025,11 @@ casts and declarations are fontified. Used on level 2 and higher."
(if (cdr string-delims)
(progn
(c-remove-font-lock-face (caar string-delims)
(1- (cadar string-delims)))
(c-put-font-lock-face (1- (cadar string-delims))
(cadar string-delims)
'font-lock-string-face))
(cadar string-delims))
(unless (featurep 'xemacs)
(c-put-font-lock-face (1- (cadar string-delims))
(cadar string-delims)
'font-lock-string-face)))
(c-put-font-lock-face (caar string-delims) (cadar string-delims)
'font-lock-warning-face))
(goto-char (cadar string-delims)))))

View file

@ -346,7 +346,7 @@ the comment syntax to handle both line style \"//\" and block style
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?| "." table)
(modify-syntax-entry ?\' "\"" table)
(modify-syntax-entry ?\240 "." table)
(modify-syntax-entry ?\240 " " table)
;; Set up block and line oriented comments. The new C
;; standard mandates both comment styles even in C, so since

View file

@ -2291,7 +2291,7 @@ with // and /*, not more generic line and block comments."
(end1
(or (and (eq (get-text-property end 'face)
'font-lock-comment-face)
(previous-single-property-change end 'face))
(c-previous-single-property-change end 'face))
end)))
(when (>= end1 beg) ; Don't hassle about changes entirely in
; comments.
@ -2311,8 +2311,8 @@ with // and /*, not more generic line and block comments."
(setq type-pos
(if (get-text-property (1- end1) 'c-type)
end1
(previous-single-property-change end1 'c-type
nil lim))))
(c-previous-single-property-change end1 'c-type
nil lim))))
(setq type (get-text-property (max (1- type-pos) lim) 'c-type))
(when (memq type '(c-decl-id-start c-decl-type-start))