diff options
Diffstat (limited to 'lisp/progmodes/cc-fonts.el')
-rw-r--r-- | lisp/progmodes/cc-fonts.el | 173 |
1 files changed, 94 insertions, 79 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 4e283764ceb..7e7053b98e1 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1,4 +1,4 @@ -;;; cc-fonts.el --- font lock support for CC Mode +;;; cc-fonts.el --- font lock support for CC Mode -*- lexical-binding: t -*- ;; Copyright (C) 2002-2021 Free Software Foundation, Inc. @@ -218,6 +218,7 @@ ;; incorrectly. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (fboundp 'font-lock-set-face) ;; Note: This function has no docstring in XEmacs so it might be ;; considered internal. @@ -228,6 +229,7 @@ ;; This is the inverse of `c-put-font-lock-face'. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (fboundp 'font-lock-remove-face) `(font-lock-remove-face ,from ,to) `(remove-text-properties ,from ,to '(face nil)))) @@ -238,11 +240,13 @@ ;; region should include them. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (featurep 'xemacs) `(c-put-font-lock-face (1+ ,from) (1- ,to) 'font-lock-string-face) `(c-put-font-lock-face ,from ,to 'font-lock-string-face))) (defmacro c-fontify-types-and-refs (varlist &rest body) + (declare (indent 1) (debug let*)) ;; Like `let', but additionally activates `c-record-type-identifiers' ;; and `c-record-ref-identifiers', and fontifies the recorded ranges ;; accordingly on exit. @@ -253,7 +257,6 @@ ,@varlist) (prog1 (progn ,@body) (c-fontify-recorded-types-and-refs)))) - (put 'c-fontify-types-and-refs 'lisp-indent-function 1) (defun c-skip-comments-and-strings (limit) ;; If the point is within a region fontified as a comment or @@ -482,20 +485,7 @@ ;; In the next form, check that point hasn't been moved beyond ;; `limit' in any of the above stanzas. ,(c-make-font-lock-search-form (car normal) (cdr normal) t) - nil)))) - -; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el. -; '(progn -(def-edebug-spec c-put-font-lock-face t) -(def-edebug-spec c-remove-font-lock-face t) -(def-edebug-spec c-put-font-lock-string-face t) - (def-edebug-spec c-fontify-types-and-refs let*) - (def-edebug-spec c-make-syntactic-matcher t) - ;; If there are literal quoted or backquoted highlight specs in - ;; the call to `c-make-font-lock-search-function' then let's - ;; instrument the forms in them. - (def-edebug-spec c-make-font-lock-search-function - (form &rest &or ("quote" (&rest form)) ("`" (&rest form)) form)));)) + nil))))) (defun c-fontify-recorded-types-and-refs () ;; Convert the ranges recorded on `c-record-type-identifiers' and @@ -791,9 +781,9 @@ casts and declarations are fontified. Used on level 2 and higher." ;; Invalid single quotes. c-font-lock-invalid-single-quotes - ;; Fontify C++ raw strings. - ,@(when (c-major-mode-is 'c++-mode) - '(c-font-lock-raw-strings)) + ;; Fontify multiline strings. + ,@(when (c-lang-const c-ml-string-opener-re) + '(c-font-lock-ml-strings)) ;; Fontify keyword constants. ,@(when (c-lang-const c-constant-kwds) @@ -1679,9 +1669,7 @@ casts and declarations are fontified. Used on level 2 and higher." c-recognize-knr-p) ; Strictly speaking, bogus, but it ; speeds up lisp.h tremendously. (save-excursion - (when (not (c-back-over-member-initializers - (max (- (point) 2000) (point-min)))) ; c-determine-limit - ; is too slow, here. + (when (not (c-back-over-member-initializers decl-search-lim)) (unless (or (eobp) (looking-at "\\s(\\|\\s)")) (forward-char)) @@ -1749,8 +1737,8 @@ casts and declarations are fontified. Used on level 2 and higher." (c-font-lock-declarators limit t in-typedef (not (c-bs-at-toplevel-p (point))))))))))) -(defun c-font-lock-raw-strings (limit) - ;; Fontify C++ raw strings. +(defun c-font-lock-ml-strings (limit) + ;; Fontify multi-line strings. ;; ;; This function will be called from font-lock for a region bounded by POINT ;; and LIMIT, as though it were to identify a keyword for @@ -1760,52 +1748,75 @@ casts and declarations are fontified. Used on level 2 and higher." (let* ((state (c-semi-pp-to-literal (point))) (string-start (and (eq (cadr state) 'string) (car (cddr state)))) - (raw-id (and string-start - (c-at-c++-raw-string-opener string-start) - (match-string-no-properties 1))) - (content-start (and raw-id (point)))) + (open-delim (and string-start + (save-excursion + (goto-char (1+ string-start)) + (c-ml-string-opener-around-point)))) + (string-delims (and open-delim + (cons open-delim (c-get-ml-closer open-delim)))) + found) ;; We go round the next loop twice per raw string, once for each "end". (while (< (point) limit) - (if raw-id - ;; Search for the raw string end delimiter - (progn - (when (search-forward-regexp (concat ")\\(" (regexp-quote raw-id) "\\)\"") - limit 'limit) - (c-put-font-lock-face content-start (match-beginning 1) - 'font-lock-string-face) - (c-remove-font-lock-face (match-beginning 1) (point))) - (setq raw-id nil)) - ;; Search for the start of a raw string. - (when (search-forward-regexp - "R\\(\"\\)\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" limit 'limit) - (when - ;; Make sure we're not in a comment or string. - (and - (not (memq (c-get-char-property (match-beginning 0) 'face) - '(font-lock-comment-face font-lock-comment-delimiter-face - font-lock-string-face))) - (or (and (eobp) - (eq (c-get-char-property (1- (point)) 'face) - 'font-lock-warning-face)) - (not (eq (c-get-char-property (point) 'face) 'font-lock-comment-face)) - ;; (eq (c-get-char-property (point) 'face) 'font-lock-string-face) - (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1)) - (equal (c-get-char-property (match-beginning 1) 'syntax-table) - '(1))))) - (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table))) - (if paren-prop - (progn - (c-put-font-lock-face (match-beginning 0) (match-end 0) - 'font-lock-warning-face) - (when - (and - (equal paren-prop '(15)) - (not (c-search-forward-char-property 'syntax-table '(15) limit))) - (goto-char limit))) - (c-remove-font-lock-face (match-beginning 0) (match-end 2)) - (setq raw-id (match-string-no-properties 2)) - (setq content-start (match-end 0))))))))) - nil) + (cond + ;; Point is not in an ml string + ((not string-delims) + (while (and (setq found (re-search-forward c-ml-string-opener-re + limit 'limit)) + (> (match-beginning 0) (point-min)) + (memq (c-get-char-property (1- (match-beginning 0)) 'face) + '(font-lock-comment-face font-lock-string-face + font-lock-comment-delimiter-face)))) + (when found + (setq open-delim (cons (match-beginning 1) + (cons (match-end 1) (match-beginning 2))) + string-delims (cons open-delim (c-get-ml-closer open-delim))) + (goto-char (caar string-delims)))) + + ;; Point is in the body of an ml string. + ((and string-delims + (>= (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" + (1- (cadar string-delims))) + (setq string-delims nil)))) + + ;; Point is at or in a closing delimiter + ((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)) + (goto-char (caddr string-delims)) + (setq string-delims nil)) + + ;; point is at or in an opening delimiter. + (t + (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)) + (c-put-font-lock-face (caar string-delims) (cadar string-delims) + 'font-lock-warning-face)) + (goto-char (cadar string-delims))))) + nil)) (defun c-font-lock-c++-lambda-captures (limit) ;; Fontify the lambda capture component of C++ lambda declarations. @@ -2287,7 +2298,7 @@ need for `c-font-lock-extra-types'.") ;; font-lock-keyword-face. It always returns NIL to inhibit this and ;; prevent a repeat invocation. See elisp/lispref page "Search-based ;; fontification". - (let (pos after-name) + (let (pos) (while (c-syntactic-re-search-forward c-using-key limit 'end) (while ; Do one declarator of a comma separated list, each time around. (progn @@ -2295,7 +2306,6 @@ need for `c-font-lock-extra-types'.") (setq pos (point)) ; token after "using". (when (and (c-on-identifier) (c-forward-name)) - (setq after-name (point)) (cond ((eq (char-after) ?=) ; using foo = <type-id>; (goto-char pos) @@ -2305,7 +2315,8 @@ need for `c-font-lock-extra-types'.") (c-go-up-list-backward) (eq (char-after) ?{) (eq (car (c-beginning-of-decl-1 - (c-determine-limit 1000))) 'same) + (c-determine-limit 1000))) + 'same) (looking-at c-colon-type-list-re))) ;; Inherited protected member: leave unfontified ) @@ -2712,6 +2723,7 @@ need for `pike-font-lock-extra-types'.") (defmacro c-set-doc-comment-re-element (suffix) ;; Set the variable `c-doc-line-join-re' to a buffer local value suitable ;; for the current doc comment style, or kill the local value. + (declare (debug t)) (let ((var (intern (concat "c-doc" suffix)))) `(let* ((styles (c-get-doc-comment-style)) elts) @@ -2738,6 +2750,7 @@ need for `pike-font-lock-extra-types'.") (defmacro c-set-doc-comment-char-list (suffix) ;; Set the variable 'c-doc-<suffix>' to the list of *-<suffix>, which must ;; be characters, and * represents the doc comment style. + (declare (debug t)) (let ((var (intern (concat "c-doc" suffix)))) `(let* ((styles (c-get-doc-comment-style)) elts) @@ -2783,14 +2796,15 @@ need for `pike-font-lock-extra-types'.") ;; is used as a flag in other code to skip comments. ;; ;; This function might do hidden buffer changes. - - (let (comment-beg region-beg) + (declare (indent 2)) + (let (comment-beg region-beg comment-mid) (if (memq (get-text-property (point) 'face) '(font-lock-comment-face font-lock-comment-delimiter-face)) ;; Handle the case when the fontified region starts inside a ;; comment. (let ((start (c-literal-start))) - (setq region-beg (point)) + (setq region-beg (point) + comment-mid (point)) (when start (goto-char start)) (when (looking-at prefix) @@ -2816,7 +2830,8 @@ need for `pike-font-lock-extra-types'.") (goto-char comment-beg) (c-in-literal))))) (setq comment-beg nil)) - (setq region-beg comment-beg)) + (setq region-beg comment-beg + comment-mid comment-beg)) (if (elt (parse-partial-sexp comment-beg (+ comment-beg 2)) 7) ;; Collect a sequence of doc style line comments. @@ -2824,15 +2839,16 @@ need for `pike-font-lock-extra-types'.") (goto-char comment-beg) (while (and (progn (c-forward-single-comment) - (c-put-font-lock-face comment-beg (point) + (c-put-font-lock-face comment-mid (point) c-doc-face-name) (skip-syntax-forward " ") - (setq comment-beg (point)) + (setq comment-beg (point) + comment-mid (point)) (< (point) limit)) (looking-at prefix)))) (goto-char comment-beg) (c-forward-single-comment) - (c-put-font-lock-face comment-beg (point) c-doc-face-name)) + (c-put-font-lock-face region-beg (point) c-doc-face-name)) (if (> (point) limit) (goto-char limit)) (setq comment-beg nil) @@ -2866,7 +2882,6 @@ need for `pike-font-lock-extra-types'.") (goto-char region-end))))) nil) -(put 'c-font-lock-doc-comments 'lisp-indent-function 2) (defun c-find-invalid-doc-markup (regexp limit) ;; Used to fontify invalid markup in doc comments after the correct |