(defvar font-lock-warning-face 'font-lock-warning-face
"Face name to use for things that should stand out.")
-(defvar font-lock-reference-face 'font-lock-constant-face
- "This variable is obsolete. Use `font-lock-constant-face'.")
+(defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
+ "Face name to use for preprocessor directives.")
+
+(defvar font-lock-reference-face 'font-lock-constant-face)
+(make-obsolete-variable 'font-lock-reference-face 'font-lock-constant-face)
;; Fontification variables:
Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
`lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
+(defvar font-lock-multiline nil
+ "Whether font-lock should cater to multiline keywords.
+If nil, don't try to handle multiline patterns.
+If t, always handle multiline patterns.
+If `undecided', don't try to handle multiline patterns until you see one.
+Major/minor modes can set this variable if they know which option applies.")
+
+(defvar font-lock-fontified nil) ; Whether we have fontified the buffer.
\f
;; Font Lock mode.
;; Shut up the byte compiler.
(defvar font-lock-face-attributes)) ; Obsolete but respected if set.
+;;;###autoload
+(defun font-lock-mode-internal (arg)
+ ;; Turn on Font Lock mode.
+ (when arg
+ (add-hook 'after-change-functions 'font-lock-after-change-function t t)
+ (font-lock-set-defaults)
+ (font-lock-turn-on-thing-lock)
+ ;; Fontify the buffer if we have to.
+ (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
+ (cond (font-lock-fontified
+ nil)
+ ((or (null max-size) (> max-size (buffer-size)))
+ (font-lock-fontify-buffer))
+ (font-lock-verbose
+ (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
+ (buffer-name))))))
+ ;; Turn off Font Lock mode.
+ (unless font-lock-mode
+ (remove-hook 'after-change-functions 'font-lock-after-change-function t)
+ (font-lock-unfontify-buffer)
+ (font-lock-turn-off-thing-lock)))
+
;;;###autoload
(defun font-lock-add-keywords (mode keywords &optional append)
"Add highlighting KEYWORDS for MODE.
to use nil for MODE (and place the call in a loop or on a hook) to avoid
subtle problems due to details of the implementation.
-Note that some modes have specialised support for additional patterns, e.g.,
+Note that some modes have specialized support for additional patterns, e.g.,
see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
`objc-font-lock-extra-types' and `java-font-lock-extra-types'."
(cond (mode
:version "21.1"
:group 'font-lock)
-(defvar fast-lock-mode nil)
-(defvar lazy-lock-mode nil)
-(defvar jit-lock-mode nil)
+(defvar fast-lock-mode)
+(defvar lazy-lock-mode)
+(defvar jit-lock-mode)
(defun font-lock-turn-on-thing-lock ()
(let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
(not font-lock-keywords-only))))))
(defun font-lock-turn-off-thing-lock ()
- (cond (fast-lock-mode
+ (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
(fast-lock-mode -1))
- (jit-lock-mode
+ ((and (boundp 'jit-lock-mode) jit-lock-mode)
(jit-lock-unregister 'font-lock-fontify-region)
;; Reset local vars to the non-jit-lock case.
(kill-local-variable 'font-lock-fontify-buffer-function))
- (lazy-lock-mode
+ ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
(lazy-lock-mode -1))))
(defun font-lock-after-fontify-buffer ()
- (cond (fast-lock-mode
+ (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
(fast-lock-after-fontify-buffer))
;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
;; (jit-lock-mode
;; (jit-lock-after-fontify-buffer))
- (lazy-lock-mode
+ ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
(lazy-lock-after-fontify-buffer))))
(defun font-lock-after-unfontify-buffer ()
- (cond (fast-lock-mode
+ (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
(fast-lock-after-unfontify-buffer))
;; Useless as well. It's only called when:
;; - turning off font-lock: it does not matter if we leave spurious
;;
;; (jit-lock-mode
;; (jit-lock-after-unfontify-buffer))
- (lazy-lock-mode
+ ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
(lazy-lock-after-unfontify-buffer))))
;;; End of Font Lock Support mode.
(font-lock-after-unfontify-buffer)
(setq font-lock-fontified nil)))
+(defvar font-lock-dont-widen nil
+ "If non-nil, font-lock will work on the non-widened buffer.
+Useful for things like RMAIL and Info where the whole buffer is not
+a very meaningful entity to highlight.")
+
(defun font-lock-default-fontify-region (beg end loudly)
(save-buffer-state
((parse-sexp-lookup-properties font-lock-syntactic-keywords)
(old-syntax-table (syntax-table)))
(unwind-protect
(save-restriction
- (widen)
+ (unless font-lock-dont-widen (widen))
;; Use the fontification syntax table, if any.
(when font-lock-syntax-table
(set-syntax-table font-lock-syntax-table))
(font-lock-fontify-region (point) (mark)))
((error quit) (message "Fontifying block...%s" error-data)))))))
-(define-key facemenu-keymap "\M-g" 'font-lock-fontify-block)
+(if (boundp 'facemenu-keymap)
+ (define-key facemenu-keymap "\M-g" 'font-lock-fontify-block))
;;; End of Fontification functions.
\f
(defun font-lock-fontify-keywords-region (start end &optional loudly)
"Fontify according to `font-lock-keywords' between START and END.
-START should be at the beginning of a line."
+START should be at the beginning of a line.
+LOUDLY, if non-nil, allows progress-meter bar."
(unless (eq (car font-lock-keywords) t)
(setq font-lock-keywords
(font-lock-compile-keywords font-lock-keywords t)))
(t
(car keywords))))
-(defun font-lock-set-defaults-1 ()
- (let* ((defaults (or font-lock-defaults
- (cdr (assq major-mode font-lock-defaults-alist))))
- (keywords
- (font-lock-choose-keywords (nth 0 defaults)
- (font-lock-value-in-major-mode font-lock-maximum-decoration)))
- (local (cdr (assq major-mode font-lock-keywords-alist)))
- (removed-keywords
- (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
- (set (make-local-variable 'font-lock-defaults) defaults)
- ;; Syntactic fontification?
- (when (nth 1 defaults)
- (set (make-local-variable 'font-lock-keywords-only) t))
- ;; Case fold during regexp fontification?
- (when (nth 2 defaults)
- (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
- ;; Syntax table for regexp and syntactic fontification?
- (when (nth 3 defaults)
- (set (make-local-variable 'font-lock-syntax-table)
- (copy-syntax-table (syntax-table)))
- (dolist (selem (nth 3 defaults))
- ;; The character to modify may be a single CHAR or a STRING.
- (let ((syntax (cdr selem)))
- (dolist (char (if (numberp (car selem))
- (list (car selem))
- (mapcar 'identity (car selem))))
- (modify-syntax-entry char syntax font-lock-syntax-table)))))
- ;; Syntax function for syntactic fontification?
- (when (nth 4 defaults)
- (set (make-local-variable 'font-lock-beginning-of-syntax-function)
- (nth 4 defaults)))
- ;; Variable alist?
- (dolist (x (nthcdr 5 defaults))
- (set (make-local-variable (car x)) (cdr x)))
- ;; Setup `font-lock-keywords' last because its value might depend
- ;; on other settings (e.g. font-lock-compile-keywords uses
- ;; font-lock-beginning-of-syntax-function).
- (set (make-local-variable 'font-lock-keywords)
- (font-lock-compile-keywords (font-lock-eval-keywords keywords) t))
- ;; Local fontification?
- (while local
- (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
- (setq local (cdr local)))
- (when removed-keywords
- (font-lock-remove-keywords nil removed-keywords))))
+(defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
+
+(defun font-lock-set-defaults ()
+ "Set fontification defaults appropriately for this mode.
+Sets various variables using `font-lock-defaults' (or, if nil, using
+`font-lock-defaults-alist') and `font-lock-maximum-decoration'."
+ ;; Set fontification defaults iff not previously set.
+ (unless font-lock-set-defaults
+ (set (make-local-variable 'font-lock-set-defaults) t)
+ (make-local-variable 'font-lock-fontified)
+ (make-local-variable 'font-lock-multiline)
+ (let* ((defaults (or font-lock-defaults
+ (cdr (assq major-mode font-lock-defaults-alist))))
+ (keywords
+ (font-lock-choose-keywords (nth 0 defaults)
+ (font-lock-value-in-major-mode font-lock-maximum-decoration)))
+ (local (cdr (assq major-mode font-lock-keywords-alist)))
+ (removed-keywords
+ (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
+ (set (make-local-variable 'font-lock-defaults) defaults)
+ ;; Syntactic fontification?
+ (when (nth 1 defaults)
+ (set (make-local-variable 'font-lock-keywords-only) t))
+ ;; Case fold during regexp fontification?
+ (when (nth 2 defaults)
+ (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
+ ;; Syntax table for regexp and syntactic fontification?
+ (when (nth 3 defaults)
+ (set (make-local-variable 'font-lock-syntax-table)
+ (copy-syntax-table (syntax-table)))
+ (dolist (selem (nth 3 defaults))
+ ;; The character to modify may be a single CHAR or a STRING.
+ (let ((syntax (cdr selem)))
+ (dolist (char (if (numberp (car selem))
+ (list (car selem))
+ (mapcar 'identity (car selem))))
+ (modify-syntax-entry char syntax font-lock-syntax-table)))))
+ ;; Syntax function for syntactic fontification?
+ (when (nth 4 defaults)
+ (set (make-local-variable 'font-lock-beginning-of-syntax-function)
+ (nth 4 defaults)))
+ ;; Variable alist?
+ (dolist (x (nthcdr 5 defaults))
+ (set (make-local-variable (car x)) (cdr x)))
+ ;; Setup `font-lock-keywords' last because its value might depend
+ ;; on other settings (e.g. font-lock-compile-keywords uses
+ ;; font-lock-beginning-of-syntax-function).
+ (set (make-local-variable 'font-lock-keywords)
+ (font-lock-compile-keywords (font-lock-eval-keywords keywords) t))
+ ;; Local fontification?
+ (while local
+ (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
+ (setq local (cdr local)))
+ (when removed-keywords
+ (font-lock-remove-keywords nil removed-keywords)))))
\f
;;; Colour etc. support.
"Font Lock mode face used to highlight warnings."
:group 'font-lock-highlighting-faces)
+(defface font-lock-preprocessor-face
+ '((t :inherit 'font-lock-builtin-face))
+ "Font Lock mode face used to highlight preprocessor directives."
+ :group 'font-lock-highlighting-faces)
+
;;; End of Colour etc. support.
\f
;;; Menu support.
The expected syntax of a declaration/definition item is `word' (preceded by
optional whitespace and `*' characters and proceeded by optional whitespace)
optionally followed by a `('. Everything following the item (but belonging to
-it) is expected to by skip-able by `scan-sexps', and items are expected to be
+it) is expected to be skip-able by `scan-sexps', and items are expected to be
separated with a `,' and to be terminated with a `;'.
Thus the regexp matches after point: word (
(let ((pos (point)))
(skip-chars-backward " \t\n")
(skip-syntax-backward "w")
- (unless (looking-at "\\(\\sw+\\)[ \t\n]*\\sw*_\\sw*[ \t\n]*\\((\\)?")
+ (unless (looking-at "\\(\\sw+\\)[ \t\n]*\\sw+[ \t\n]*\\(((?\\)?")
;; Looks like it was something else, so go back to where we
;; were and reset the match data by rematching.
(goto-char pos)
;; Variable declarations.
"\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|"
;; Structure declarations.
- "\\(class\\|group\\|package\\|struct\\|type\\)"
+ "\\(class\\|group\\|theme\\|package\\|struct\\|type\\)"
"\\)\\)\\>"
;; Any whitespace and defined object.
"[ \t'\(]*"
(defcustom c++-font-lock-extra-types
'("\\sw+_t"
- "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios"
+
"string" "rope"
+
"list" "slist"
"deque" "vector" "bit_vector"
+
"set" "multiset"
"map" "multimap"
- "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?"
"stack" "queue" "priority_queue"
"type_info"
- "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
- "reference" "const_reference")
+
+ ;; (regexp-opt '("ios_base" "ios" "istream" "ostream" "istringstream" "ifstream" "iostream" "ofstream" "ostringstream" "fstream" "stringstream"))
+ "fstream\\|i\\(?:fstream\\|os\\(?:_base\\|tream\\)?\\|str\\(?:\\(?:ingstr\\)?eam\\)\\)\\|\\(?:o\\(?:f\\|string\\)?\\|string\\)stream"
+
+ ;; (regexp-opt '("hash" "hash_set" "hash_map" "hash_multiset" "hash_multimap"))
+ "hash\\(?:_\\(?:m\\(?:ap\\|ulti\\(?:map\\|set\\)\\)\\|set\\)\\)?"
+
+ ;; (regexp-opt '("pointer" "const_pointer" "reference" "const_reference" "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator" "size_type" "difference_type" "allocator_type"))
+ "allocator_type\\|const_\\(?:iterator\\|pointer\\|re\\(?:ference\\|verse_iterator\\)\\)\\|difference_type\\|iterator\\|pointer\\|re\\(?:ference\\|verse_iterator\\)\\|size_type"
+ )
"*List of extra types to fontify in C++ mode.
Each list item should be a regexp not containing word-delimiters.
For example, a value of (\"string\") means the word string is treated as a type
"ifndef" "include" "line" "pragma" "undef"))))
(c-preprocessor-directives-depth
(regexp-opt-depth c-preprocessor-directives)))
+
(defconst c-font-lock-keywords-1
(list
;;
"typeid"
;; Branko Cibej <branko.cibej@hermes.si> says this is new.
"export"
+ ;; Copied from C. wsnyder@wsnyder.org says C++ needs it too.
+ "restrict"
;; Mark Mitchell <mmitchell@usa.net> says these are new.
"mutable" "explicit"
;; Alain Picard <ap@abelard.apana.org.au> suggests treating these