Mercurial > emacs
annotate lisp/font-core.el @ 45483:81cb13e7ce4f
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Thu, 23 May 2002 10:20:12 +0000 |
parents | d78e68782e6e |
children | 25d73d0e2b98 |
rev | line source |
---|---|
45440
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
1 ;;; font-core.el --- Core interface to font-lock |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
2 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 2002 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
5 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
6 ;; Maintainer: FSF |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
7 ;; Keywords: languages, faces |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
8 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
10 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
14 ;; any later version. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
15 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
20 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
24 ;; Boston, MA 02111-1307, USA. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
25 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
26 ;;; Code: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
27 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
28 ;; This variable is used by mode packages that support Font Lock mode by |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
29 ;; defining their own keywords to use for `font-lock-keywords'. (The mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
30 ;; command should make it buffer-local and set it to provide the set up.) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
31 (defvar font-lock-defaults nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
32 "Defaults for Font Lock mode specified by the major mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
33 Defaults should be of the form: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
34 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
35 (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN ...) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
36 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
37 KEYWORDS may be a symbol (a variable or function whose value is the keywords to |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
38 use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
39 syntactic fontification (strings and comments) is not performed. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
40 If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
41 If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
42 \(CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
43 keyword and syntactic fontification (see `modify-syntax-entry'). |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
44 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
45 If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
46 backwards outside any enclosing syntactic block, for syntactic fontification. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
47 Typical values are `beginning-of-line' (i.e., the start of the line is known to |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
48 be outside a syntactic block), or `beginning-of-defun' for programming modes or |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
49 `backward-paragraph' for textual modes (i.e., the mode-dependent function is |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
50 known to move outside a syntactic block). If nil, the beginning of the buffer |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
51 is used as a position outside of a syntactic block, in the worst case. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
52 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
53 These item elements are used by Font Lock mode to set the variables |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
54 `font-lock-keywords', `font-lock-keywords-only', |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
55 `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
56 `font-lock-beginning-of-syntax-function', respectively. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
57 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
58 Further item elements are alists of the form (VARIABLE . VALUE) and are in no |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
59 particular order. Each VARIABLE is made buffer-local before set to VALUE. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
60 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
61 Currently, appropriate variables include `font-lock-mark-block-function'. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
62 If this is non-nil, it should be a function with no args used to mark any |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
63 enclosing block of text, for fontification via \\[font-lock-fontify-block]. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
64 Typical values are `mark-defun' for programming modes or `mark-paragraph' for |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
65 textual modes (i.e., the mode-dependent function is known to put point and mark |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
66 around a text block relevant to that mode). |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
67 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
68 Other variables include that for syntactic keyword fontification, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
69 `font-lock-syntactic-keywords' |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
70 and those for buffer-specialised fontification functions, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
71 `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function', |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
72 `font-lock-fontify-region-function', `font-lock-unfontify-region-function', |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
73 `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.") |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
74 (make-variable-buffer-local 'font-lock-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
75 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
76 ;; This variable is used where font-lock.el itself supplies the |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
77 ;; keywords. Really, this shouldn't need to be in font-core.el, but |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
78 ;; we can't avoid it. In the future, this stuff will hopefully be |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
79 ;; moved to cc-mode itself. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
80 (defvar font-lock-defaults-alist |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
81 (let (;; We use `beginning-of-defun', rather than nil, for SYNTAX-BEGIN. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
82 ;; Thus the calculation of the cache is usually faster but not |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
83 ;; infallible, so we risk mis-fontification. sm. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
84 (c-mode-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
85 '((c-font-lock-keywords c-font-lock-keywords-1 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
86 c-font-lock-keywords-2 c-font-lock-keywords-3) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
87 nil nil ((?_ . "w")) beginning-of-defun |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
88 (font-lock-syntactic-face-function |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
89 . c-font-lock-syntactic-face-function) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
90 (font-lock-mark-block-function . mark-defun))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
91 (c++-mode-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
92 '((c++-font-lock-keywords c++-font-lock-keywords-1 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
93 c++-font-lock-keywords-2 c++-font-lock-keywords-3) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
94 nil nil ((?_ . "w")) beginning-of-defun |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
95 (font-lock-syntactic-face-function |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
96 . c-font-lock-syntactic-face-function) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
97 (font-lock-mark-block-function . mark-defun))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
98 (objc-mode-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
99 '((objc-font-lock-keywords objc-font-lock-keywords-1 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
100 objc-font-lock-keywords-2 objc-font-lock-keywords-3) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
101 nil nil ((?_ . "w") (?$ . "w")) nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
102 (font-lock-syntactic-face-function |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
103 . c-font-lock-syntactic-face-function) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
104 (font-lock-mark-block-function . mark-defun))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
105 (java-mode-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
106 '((java-font-lock-keywords java-font-lock-keywords-1 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
107 java-font-lock-keywords-2 java-font-lock-keywords-3) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
108 nil nil ((?_ . "w") (?$ . "w")) nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
109 (font-lock-syntactic-face-function |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
110 . java-font-lock-syntactic-face-function) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
111 (font-lock-mark-block-function . mark-defun)))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
112 (list |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
113 (cons 'c-mode c-mode-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
114 (cons 'c++-mode c++-mode-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
115 (cons 'objc-mode objc-mode-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
116 (cons 'java-mode java-mode-defaults))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
117 "Alist of fall-back Font Lock defaults for major modes. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
118 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
119 This variable should not be used any more. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
120 Set the buffer-local `font-lock-keywords' in the major mode instead. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
121 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
122 Each item should be a list of the form: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
123 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
124 (MAJOR-MODE . FONT-LOCK-DEFAULTS) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
125 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
126 where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
127 settings. See the variable `font-lock-defaults', which takes precedence.") |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
128 (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
129 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
130 (defvar font-lock-multiline nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
131 "Whether font-lock should cater to multiline keywords. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
132 If nil, don't try to handle multiline patterns. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
133 If t, always handle multiline patterns. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
134 If `undecided', don't try to handle multiline patterns until you see one. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
135 Major/minor modes can set this variable if they know which option applies.") |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
136 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
137 (defvar font-lock-fontified nil) ; Whether we have fontified the buffer. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
138 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
139 (defvar font-lock-category-alist nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
140 "An alist of (CATEGORY-SYMBOL . FACE-PROP) controlled by Font Lock. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
141 This variable is intended to be used by special modes which construct |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
142 buffer text for display to the user (i.e. buffer-menu, occur), but |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
143 wish to have fontification turned on and off by Font Lock. If this |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
144 variable is non-nil, then calling `font-lock-mode' will simply toggle |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
145 the symbol property `face' of CATEGORY-SYMBOL.") |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
146 |
45481
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
147 (defvar font-lock-symbol-category-alist nil |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
148 "An alist of (SYMBOL . CATEGORY-SYMBOL) to help maintain categories. |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
149 This variable is not directly used by font-lock; instead it is |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
150 intended to be used by modes which use `font-lock-category-alist'. |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
151 Normally, you want category symbols to be uninterned, so that their |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
152 properties can be local to a buffer. This variable helps you maintain |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
153 a mapping between normal category names (i.e. interned symbols) and |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
154 their local uninterned versions.") |
d78e68782e6e
(font-lock-symbol-category-alist): New variable.
Colin Walters <walters@gnu.org>
parents:
45476
diff
changeset
|
155 |
45476
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
156 (defvar font-lock-function 'font-lock-default-function |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
157 "A function which is called when `font-lock-mode' is toggled. |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
158 It will be passed one argument, which is the current value of |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
159 `font-lock-mode'.") |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
160 (make-variable-buffer-local 'font-lock-default-function) |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
161 |
45440
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
162 (define-minor-mode font-lock-mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
163 "Toggle Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
164 With arg, turn Font Lock mode off if and only if arg is a non-positive |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
165 number; if arg is nil, toggle Font Lock mode; anything else turns Font |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
166 Lock on. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
167 \(Font Lock is also known as \"syntax highlighting\".) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
168 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
169 When Font Lock mode is enabled, text is fontified as you type it: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
170 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
171 - Comments are displayed in `font-lock-comment-face'; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
172 - Strings are displayed in `font-lock-string-face'; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
173 - Certain other expressions are displayed in other faces according to the |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
174 value of the variable `font-lock-keywords'. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
175 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
176 To customize the faces (colors, fonts, etc.) used by Font Lock for |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
177 fontifying different parts of buffer text, use \\[customize-face]. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
178 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
179 You can enable Font Lock mode in any major mode automatically by turning on in |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
180 the major mode's hook. For example, put in your ~/.emacs: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
181 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
182 (add-hook 'c-mode-hook 'turn-on-font-lock) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
183 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
184 Alternatively, you can use Global Font Lock mode to automagically turn on Font |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
185 Lock mode in buffers whose major mode supports it and whose major mode is one |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
186 of `font-lock-global-modes'. For example, put in your ~/.emacs: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
187 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
188 (global-font-lock-mode t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
189 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
190 There are a number of support modes that may be used to speed up Font Lock mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
191 in various ways, specified via the variable `font-lock-support-mode'. Where |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
192 major modes support different levels of fontification, you can use the variable |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
193 `font-lock-maximum-decoration' to specify which level you generally prefer. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
194 When you turn Font Lock mode on/off the buffer is fontified/defontified, though |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
195 fontification occurs only if the buffer is less than `font-lock-maximum-size'. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
196 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
197 For example, to specify that Font Lock mode use use Lazy Lock mode as a support |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
198 mode and use maximum levels of fontification, put in your ~/.emacs: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
199 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
200 (setq font-lock-support-mode 'lazy-lock-mode) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
201 (setq font-lock-maximum-decoration t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
202 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
203 To add your own highlighting for some major mode, and modify the highlighting |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
204 selected automatically via the variable `font-lock-maximum-decoration', you can |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
205 use `font-lock-add-keywords'. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
206 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
207 To fontify a buffer, without turning on Font Lock mode and regardless of buffer |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
208 size, you can use \\[font-lock-fontify-buffer]. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
209 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
210 To fontify a block (the function or paragraph containing point, or a number of |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
211 lines around point), perhaps because modification on the current line caused |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
212 syntactic change on other lines, you can use \\[font-lock-fontify-block]. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
213 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
214 See the variable `font-lock-defaults-alist' for the Font Lock mode default |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
215 settings. You can set your own default settings for some mode, by setting a |
45476
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
216 buffer local value for `font-lock-defaults', via its mode hook. |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
217 |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
218 The above is the default behavior of `font-lock-mode'; you may specify |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
219 your own function which is called when `font-lock-mode' is toggled via |
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
220 `font-lock-function'. " |
45440
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
221 nil nil nil |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
222 ;; Don't turn on Font Lock mode if we don't have a display (we're running a |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
223 ;; batch job) or if the buffer is invisible (the name starts with a space). |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
224 (when (or noninteractive (eq (aref (buffer-name) 0) ?\ )) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
225 (setq font-lock-mode nil)) |
45476
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
226 (funcall font-lock-function font-lock-mode)) |
45440
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
227 |
45476
e1671f561407
(font-lock-function): New variable.
Colin Walters <walters@gnu.org>
parents:
45440
diff
changeset
|
228 (defun font-lock-default-function (font-lock-mode) |
45440
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
229 ;; Turn on Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
230 (when font-lock-mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
231 (font-lock-set-defaults) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
232 (dolist (elt font-lock-category-alist) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
233 (put (car elt) 'face (cdr elt))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
234 (when font-lock-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
235 (add-hook 'after-change-functions 'font-lock-after-change-function t t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
236 (font-lock-turn-on-thing-lock) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
237 ;; Fontify the buffer if we have to. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
238 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
239 (cond (font-lock-fontified |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
240 nil) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
241 ((or (null max-size) (> max-size (buffer-size))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
242 (font-lock-fontify-buffer)) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
243 (font-lock-verbose |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
244 (message "Fontifying %s...buffer size greater than font-lock-maximum-size" |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
245 (buffer-name))))))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
246 ;; Turn off Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
247 (unless font-lock-mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
248 (dolist (elt font-lock-category-alist) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
249 (put (car elt) 'face nil)) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
250 (when font-lock-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
251 (remove-hook 'after-change-functions 'font-lock-after-change-function t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
252 (font-lock-unfontify-buffer) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
253 (font-lock-turn-off-thing-lock)))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
254 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
255 (defun turn-on-font-lock () |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
256 "Turn on Font Lock mode (only if the terminal can display it)." |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
257 (unless font-lock-mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
258 (font-lock-mode))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
259 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
260 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
261 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
262 (defun font-lock-set-defaults () |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
263 "Set fontification defaults appropriately for this mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
264 Sets various variables using `font-lock-defaults' (or, if nil, using |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
265 `font-lock-defaults-alist') and `font-lock-maximum-decoration'." |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
266 (unless font-lock-set-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
267 (set (make-local-variable 'font-lock-set-defaults) t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
268 (make-local-variable 'font-lock-fontified) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
269 (make-local-variable 'font-lock-multiline) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
270 ;; Detect if this is a simple mode, which doesn't use any |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
271 ;; syntactic fontification functions. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
272 (when (or font-lock-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
273 (assq major-mode font-lock-defaults-alist)) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
274 (require 'font-lock) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
275 (font-lock-set-defaults-1)))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
276 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
277 ;;; Global Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
278 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
279 ;; A few people have hassled in the past for a way to make it easier to turn on |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
280 ;; Font Lock mode, without the user needing to know for which modes s/he has to |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
281 ;; turn it on, perhaps the same way hilit19.el/hl319.el does. I've always |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
282 ;; balked at that way, as I see it as just re-moulding the same problem in |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
283 ;; another form. That is; some person would still have to keep track of which |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
284 ;; modes (which may not even be distributed with Emacs) support Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
285 ;; The list would always be out of date. And that person might have to be me. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
286 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
287 ;; Implementation. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
288 ;; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
289 ;; In a previous discussion the following hack came to mind. It is a gross |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
290 ;; hack, but it generally works. We use the convention that major modes start |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
291 ;; by calling the function `kill-all-local-variables', which in turn runs |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
292 ;; functions on the hook variable `change-major-mode-hook'. We attach our |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
293 ;; function `font-lock-change-major-mode' to that hook. Of course, when this |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
294 ;; hook is run, the major mode is in the process of being changed and we do not |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
295 ;; know what the final major mode will be. So, `font-lock-change-major-mode' |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
296 ;; only (a) notes the name of the current buffer, and (b) adds our function |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
297 ;; `turn-on-font-lock-if-enabled' to the hook variables `find-file-hooks' and |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
298 ;; `post-command-hook' (for buffers that are not visiting files). By the time |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
299 ;; the functions on the first of these hooks to be run are run, the new major |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
300 ;; mode is assumed to be in place. This way we get a Font Lock function run |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
301 ;; when a major mode is turned on, without knowing major modes or their hooks. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
302 ;; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
303 ;; Naturally this requires that (a) major modes run `kill-all-local-variables', |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
304 ;; as they are supposed to do, and (b) the major mode is in place after the |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
305 ;; file is visited or the command that ran `kill-all-local-variables' has |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
306 ;; finished, whichever the sooner. Arguably, any major mode that does not |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
307 ;; follow the convension (a) is broken, and I can't think of any reason why (b) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
308 ;; would not be met (except `gnudoit' on non-files). However, it is not clean. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
309 ;; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
310 ;; Probably the cleanest solution is to have each major mode function run some |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
311 ;; hook, e.g., `major-mode-hook', but maybe implementing that change is |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
312 ;; impractical. I am personally against making `setq' a macro or be advised, |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
313 ;; or have a special function such as `set-major-mode', but maybe someone can |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
314 ;; come up with another solution? |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
315 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
316 ;; User interface. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
317 ;; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
318 ;; Although Global Font Lock mode is a pseudo-mode, I think that the user |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
319 ;; interface should conform to the usual Emacs convention for modes, i.e., a |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
320 ;; command to toggle the feature (`global-font-lock-mode') with a variable for |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
321 ;; finer control of the mode's behaviour (`font-lock-global-modes'). |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
322 ;; |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
323 ;; The feature should not be enabled by loading font-lock.el, since other |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
324 ;; mechanisms for turning on Font Lock mode, such as M-x font-lock-mode RET or |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
325 ;; (add-hook 'c-mode-hook 'turn-on-font-lock), would cause Font Lock mode to be |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
326 ;; turned on everywhere. That would not be intuitive or informative because |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
327 ;; loading a file tells you nothing about the feature or how to control it. It |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
328 ;; would also be contrary to the Principle of Least Surprise. sm. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
329 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
330 (defcustom font-lock-global-modes t |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
331 "*Modes for which Font Lock mode is automagically turned on. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
332 Global Font Lock mode is controlled by the command `global-font-lock-mode'. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
333 If nil, means no modes have Font Lock mode automatically turned on. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
334 If t, all modes that support Font Lock mode have it automatically turned on. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
335 If a list, it should be a list of `major-mode' symbol names for which Font Lock |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
336 mode should be automatically turned on. The sense of the list is negated if it |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
337 begins with `not'. For example: |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
338 (c-mode c++-mode) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
339 means that Font Lock mode is turned on for buffers in C and C++ modes only." |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
340 :type '(choice (const :tag "none" nil) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
341 (const :tag "all" t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
342 (set :menu-tag "mode specific" :tag "modes" |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
343 :value (not) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
344 (const :tag "Except" not) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
345 (repeat :inline t (symbol :tag "mode")))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
346 :group 'font-lock) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
347 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
348 (defun turn-on-font-lock-if-enabled () |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
349 (when (and (or font-lock-defaults |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
350 font-lock-category-alist |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
351 (assq major-mode font-lock-defaults-alist)) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
352 (or (eq font-lock-global-modes t) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
353 (if (eq (car-safe font-lock-global-modes) 'not) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
354 (not (memq major-mode (cdr font-lock-global-modes))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
355 (memq major-mode font-lock-global-modes)))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
356 (let (inhibit-quit) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
357 (turn-on-font-lock)))) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
358 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
359 (easy-mmode-define-global-mode |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
360 global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
361 :extra-args (dummy)) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
362 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
363 ;;; End of Global Font Lock mode. |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
364 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
365 (provide 'font-core) |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
366 |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
367 ;;; font-core.el ends here |
e879dd65b980
New file, broken out from font-lock.el.
Colin Walters <walters@gnu.org>
parents:
diff
changeset
|
368 |