Function: c-maybe-font-lock-wrong-style-comments

c-maybe-font-lock-wrong-style-comments is a byte-compiled function defined in cc-fonts.el.gz.

Signature

(c-maybe-font-lock-wrong-style-comments LIMIT)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-fonts.el.gz
(defun c-maybe-font-lock-wrong-style-comments (limit)
  ;; 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
  ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
  ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
  ;; Fontification".
  ;;
  ;; This function fontifies "invalid" comment delimiters with
  ;; `font-lock-warning-face'.  A delimiter is "invalid" when
  ;; `c-mark-wrong-style-of-comment' is non-nil, and the delimiter style is
  ;; not the default specified by `c-block-comment-flag'.
  (when c-mark-wrong-style-of-comment
    (let* ((lit (c-semi-pp-to-literal (point)))
	   (s (car lit))		; parse-partial-sexp state.
	   )
      ;; First, deal with and move out of any literal we start in.
      (cond
       ((null (cadr lit)))		; Not in a literal
       ((eq (cadr lit) 'string)
	(setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table)))
       ((and (not c-block-comment-flag) ; In an "invalid" block comment
	     (eq (cadr lit) 'c))
	(setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table))
	;; Font lock the block comment ender with warning face.
	(when (not (nth 4 s))
	  (c-put-font-lock-face (- (point) (length c-block-comment-ender))
				(point) 'font-lock-warning-face)))
       (t ; In a line comment, or a "valid" block comment
	(setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table))))

      (while (< (point) limit)
	(setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table))
	(cond
	 ((or (nth 3 s)			; In a string
	      (and (nth 4 s)		; In a comment
		   (eq (nth 7 s)	; Comment style
		       (if c-block-comment-flag
			   nil		; Block comment
			 1))))	; Line comment
	    ;; Move over a "valid" literal.
	  (setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table)))
	 ((nth 4 s)			; In an invalid comment
	 ;; Fontify the invalid comment opener.
	  (c-put-font-lock-face (nth 8 s) (point) 'font-lock-warning-face)
	  ;; Move to end of comment or LIMIT.
	  (setq s (parse-partial-sexp (point) limit nil nil s 'syntax-table))
	  ;; Fontify an invalid block comment ender, if that's what we have.
	  (when (and (not c-block-comment-flag)
		     (not (nth 4 s)))	; We're outside the comment
	    (c-put-font-lock-face (- (point) (length c-block-comment-ender))
				  (point) 'font-lock-warning-face)))))))
  nil)