annotate lisp/font-lock.el @ 6743:77349221ca81

(hscroll-window-column): New function. (hscroll-point-visible): Do the right thing in the hard cases.
author Karl Heuer <kwzh@gnu.org>
date Fri, 08 Apr 1994 03:23:08 +0000
parents de72ddd5a3c0
children aa83a7152b11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Electric Font Lock Mode
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Author: jwz, then rms
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Maintainer: FSF
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: languages, faces
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Font-lock-mode is a minor mode that causes your comments to be
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; displayed in one face, strings in another, reserved words in another,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; documentation strings in another, and so on.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; Comments will be displayed in `font-lock-comment-face'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Strings will be displayed in `font-lock-string-face'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Doc strings will be displayed in `font-lock-doc-string-face'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Function and variable names (in their defining forms) will be
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; displayed in `font-lock-function-name-face'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Reserved words will be displayed in `font-lock-keyword-face'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; To make the text you type be fontified, use M-x font-lock-mode.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; When this minor mode is on, the fonts of the current line are
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; updated with every insertion or deletion.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; To define new reserved words or other patterns to highlight, use
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; the `font-lock-keywords' variable. This should be mode-local.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; To turn this on automatically, add this to your .emacs file:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; file of C code, using the default configuration. You can speed this up
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; substantially by removing some of the patterns that are highlighted by
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; default. Fontifying Lisp code is significantly faster, because Lisp has a
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; more regular syntax than C, so the expressions don't have to be as hairy.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; Code:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
6578
de72ddd5a3c0 Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents: 6219
diff changeset
57 (or window-system
de72ddd5a3c0 Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents: 6219
diff changeset
58 (error "Can't fontify on an ASCII terminal"))
de72ddd5a3c0 Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents: 6219
diff changeset
59
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (or (internal-find-face 'underline)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (copy-face 'default 'underline))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (set-face-underline-p 'underline t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defvar font-lock-comment-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 'italic
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "Face to use for comments.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (defvar font-lock-doc-string-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 'italic
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 "Face to use for documentation strings.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defvar font-lock-string-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 'underline
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 "Face to use for string constants.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
76 (defvar font-lock-function-name-face
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 'bold-italic
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "Face to use for function names.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (defvar font-lock-keyword-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 'bold
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 "Face to use for keywords.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (defvar font-lock-type-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 'italic
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Face to use for data types.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (make-variable-buffer-local 'font-lock-keywords)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defvar font-lock-keywords nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "*The keywords to highlight.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 If this is a list, then elements may be of the forms:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
93 \"string\" ; A regexp to highlight in the
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ; `font-lock-keyword-face'.
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
95 (\"string\" . N) ; Highlight subexpression N of the regexp.
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
96 (\"string\" . face-name) ; Use the named face
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
97 (\"string\" N face-name) ; Both of the above
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
98 (\"string\" N face-name t) ; This allows highlighting to override
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
99 ; already-highlighted regions.
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
100 (\"string\" N face-name keep) ; This allows highlighting to occur
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
101 ; even if some parts of what STRING matches
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
102 ; are already highlighted--but does not alter
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
103 ; the existing highlighting of those parts.
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 These regular expressions should not match text which spans lines.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 While \\[font-lock-fontify-buffer] handles multi-line patterns correctly,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 updating when you edit the buffer does not,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 since it considers text one line at a time.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 Be careful composing regexps for this list; the wrong pattern can dramatically
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 slow things down!")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defvar font-lock-keywords-case-fold-search nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (defvar font-lock-verbose t
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 "*Non-nil means `font-lock-fontify-buffer' should print status messages.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
4054
074035743fc9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4053
diff changeset
119 ;;;###autoload
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (defvar font-lock-mode-hook nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "Function or functions to run on entry to Font Lock mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;;; These variables record, for each buffer,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;;; the parse state at a particular position, always the start of a line.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;;; This is used to make font-lock-fontify-region faster.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defvar font-lock-cache-position nil)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defvar font-lock-cache-state nil)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (make-variable-buffer-local 'font-lock-cache-position)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (make-variable-buffer-local 'font-lock-cache-state)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defun font-lock-fontify-region (start end)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "Put proper face on each string and comment between START and END."
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (save-excursion
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (goto-char start)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (beginning-of-line)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (setq end (min end (point-max)))
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
137 (let ((buffer-read-only nil)
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
138 state startline prev prevstate
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
139 (modified (buffer-modified-p)))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; Find the state at the line-beginning before START.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (setq startline (point))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (if (eq (point) font-lock-cache-position)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq state font-lock-cache-state)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; Find outermost containing sexp.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (beginning-of-defun)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;; Find the state at STARTLINE.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (while (< (point) startline)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (setq state (parse-partial-sexp (point) startline 0)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (setq font-lock-cache-state state
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 font-lock-cache-position (point)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; Now find the state precisely at START.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (setq state (parse-partial-sexp (point) start nil nil state))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;; If the region starts inside a string, show the extent of it.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (if (nth 3 state)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (let ((beg (point)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (while (and (re-search-forward "\\s\"" end 'move)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (nth 3 (parse-partial-sexp beg (point)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (put-text-property beg (point) 'face font-lock-string-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (setq state (parse-partial-sexp beg (point) nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; Likewise for a comment.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (if (or (nth 4 state) (nth 7 state))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (let ((beg (point)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (while (and (re-search-forward (if comment-end
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (concat "\\s>\\|"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (regexp-quote comment-end))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 "\\s>")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 end 'move)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (nth 3 (parse-partial-sexp beg (point)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (put-text-property beg (point) 'face font-lock-comment-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (setq state (parse-partial-sexp beg (point) nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; Find each interesting place between here and END.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (while (and (< (point) end)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (setq prev (point) prevstate state)
4459
2d8f7239f2ca (font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents: 4239
diff changeset
176 (re-search-forward (if comment-start-skip
2d8f7239f2ca (font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents: 4239
diff changeset
177 (concat "\\s\"\\|" comment-start-skip)
2d8f7239f2ca (font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents: 4239
diff changeset
178 "\\s\"")
2d8f7239f2ca (font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents: 4239
diff changeset
179 end t)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; Clear out the fonts of what we skip over.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (progn (remove-text-properties prev (point) '(face nil)) t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; Verify the state at that place
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; so we don't get fooled by \" or \;.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setq state (parse-partial-sexp prev (point)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 nil nil state)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (let ((here (point)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (if (or (nth 4 state) (nth 7 state))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;; We found a real comment start.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let ((beg (match-beginning 0)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (goto-char beg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (save-restriction
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (narrow-to-region (point-min) end)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (condition-case nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (progn
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (forward-comment 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ;; forward-comment skips all whitespace,
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; so go back to the real end of the comment.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (skip-chars-backward " \t"))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (error (goto-char end))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (put-text-property beg (point) 'face font-lock-comment-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (setq state (parse-partial-sexp here (point) nil nil state)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (if (nth 3 state)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (let ((beg (match-beginning 0)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (while (and (re-search-forward "\\s\"" end 'move)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (nth 3 (parse-partial-sexp here (point)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (put-text-property beg (point) 'face font-lock-string-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (setq state (parse-partial-sexp here (point) nil nil state))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; Make sure PREV is non-nil after the loop
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; only if it was set on the very last iteration.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (setq prev nil))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (and prev
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
214 (remove-text-properties prev end '(face nil)))
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
215 (set-buffer-modified-p modified))))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; This code used to be used to show a string on reaching the end of it.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; It is probably not needed due to later changes to handle strings
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; starting before the region in question.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; (if (and (null (nth 3 state))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; (eq (char-syntax (preceding-char)) ?\")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; (save-excursion
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; (nth 3 (parse-partial-sexp prev (1- (point))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; nil nil prevstate))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ;; ;; We found the end of a string.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ;; (save-excursion
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; (setq foo2 (point))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;; (let ((ept (point)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; (forward-sexp -1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; ;; Highlight the string when we see the end.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;; ;; Doing it at the start leads to trouble:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;; ;; either it fails to handle multiline strings
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ;; ;; or it can run away when an unmatched " is inserted.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ;; (put-text-property (point) ept 'face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 ;; (if (= (car state) 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; font-lock-doc-string-face
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; font-lock-string-face)))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun font-lock-unfontify-region (beg end)
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
240 (let ((modified (buffer-modified-p))
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
241 (buffer-read-only nil))
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
242 (remove-text-properties beg end '(face nil))
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
243 (set-buffer-modified-p modified)))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;; Called when any modification is made to buffer text.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (defun font-lock-after-change-function (beg end old-len)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (save-excursion
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (save-match-data
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (goto-char beg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;; Discard the cache info if text before it has changed.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (and font-lock-cache-position
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (> font-lock-cache-position beg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setq font-lock-cache-position nil))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 ;; Rescan till end of line. yes!
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (goto-char end)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (end-of-line)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (setq end (point))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (goto-char beg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (beginning-of-line)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (setq beg (point))
4239
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
261 ;; First scan for strings and comments.
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
262 ;; Must scan from line start in case of
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
263 ;; inserting space into `intfoo () {}'.
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
264 (font-lock-fontify-region beg (1+ end))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ;; Now scan for keywords.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (font-lock-hack-keywords beg end))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;;; Fontifying arbitrary patterns
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (defsubst font-lock-any-properties-p (start end)
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
271 (or (get-text-property start 'face)
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
272 (let ((next (next-single-property-change start 'face)))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (and next (< next end)))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (defun font-lock-hack-keywords (start end &optional loudly)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (goto-char start)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (let ((case-fold-search font-lock-keywords-case-fold-search)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (rest font-lock-keywords)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (count 0)
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
280 (buffer-read-only nil)
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
281 (modified (buffer-modified-p))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 first str match face s e allow-overlap-p)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (while rest
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (setq first (car rest) rest (cdr rest))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (goto-char start)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (cond ((consp first)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (setq str (car first))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (cond ((consp (cdr first))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (setq match (nth 1 first)
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
290 face (eval (nth 2 first))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 allow-overlap-p (nth 3 first)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ((symbolp (cdr first))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (setq match 0 allow-overlap-p nil
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
294 face (eval (cdr first))))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (t
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (setq match (cdr first)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 allow-overlap-p nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 face font-lock-keyword-face))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (t
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (setq str first match 0 allow-overlap-p nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 face font-lock-keyword-face)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;(message "regexp: %s" str)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (while (re-search-forward str end t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (setq s (match-beginning match)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 e (match-end match))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (or s (error "expression did not match subexpression %d" match))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; don't fontify this keyword if we're already in some other context.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (or (if allow-overlap-p nil (font-lock-any-properties-p s e))
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
309 (if (not (memq allow-overlap-p '(t nil)))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
310 (save-excursion
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
311 (goto-char s)
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
312 (save-restriction
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
313 (narrow-to-region s e)
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
314 (while (not (eobp))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
315 (let ((next (next-single-property-change (point) 'face)))
5056
64211dda414c (font-lock-hack-keywords):
Richard M. Stallman <rms@gnu.org>
parents: 4897
diff changeset
316 (if (or (null next) (> next (point-max)))
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
317 (setq next (point-max)))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
318 (if (not (get-text-property (point) 'face))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
319 (put-text-property (point) next 'face face))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
320 (goto-char next)))))
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
321 (put-text-property s e 'face face))))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (if loudly (message "Fontifying %s... (regexps...%s)"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (buffer-name)
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
324 (make-string (setq count (1+ count)) ?.))))
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
325 (set-buffer-modified-p modified)))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; The user level functions
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (defvar font-lock-mode nil) ; for modeline
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (or (assq 'font-lock-mode minor-mode-alist)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (setq minor-mode-alist
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (append minor-mode-alist
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 '((font-lock-mode " Font")))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (defvar font-lock-fontified nil) ; whether we have hacked this buffer
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (put 'font-lock-fontified 'permanent-local t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ;;;###autoload
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (defun font-lock-mode (&optional arg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 "Toggle Font Lock mode.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 With arg, turn Font Lock mode on if and only if arg is positive.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 When Font Lock mode is enabled, text is fontified as you type it:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 - comments are displayed in `font-lock-comment-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (That is a variable whose value should be a face name.)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 - strings are displayed in `font-lock-string-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 - documentation strings are displayed in `font-lock-doc-string-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 - function and variable names in their defining forms are displayed
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 in `font-lock-function-name-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 - and certain other expressions are displayed in other faces
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 according to the value of the variable `font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 When you turn Font Lock mode on/off, the buffer is fontified/defontified.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 To fontify a buffer without having newly typed text become fontified, you
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 can use \\[font-lock-fontify-buffer]."
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (interactive "P")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (let ((on-p (if (null arg)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (not font-lock-mode)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (> (prefix-numeric-value arg) 0))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp...
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (setq on-p nil))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (or (memq after-change-function
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 '(nil font-lock-after-change-function))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (error "after-change-function is %s" after-change-function))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (set (make-local-variable 'after-change-function)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (if on-p 'font-lock-after-change-function nil))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (set (make-local-variable 'font-lock-mode) on-p)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (cond (on-p
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (font-lock-set-defaults)
5717
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
371 (make-local-variable 'before-revert-hook)
5625
24f92f49a07f (font-lock-mode): Set after-revert-hook
Richard M. Stallman <rms@gnu.org>
parents: 5360
diff changeset
372 (make-local-variable 'after-revert-hook)
5717
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
373 ;; If buffer is reverted, must clean up the state.
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
374 (add-hook 'before-revert-hook 'font-lock-revert-setup)
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
375 (add-hook 'after-revert-hook 'font-lock-revert-cleanup)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (run-hooks 'font-lock-mode-hook)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (or font-lock-fontified (font-lock-fontify-buffer)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (font-lock-fontified
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (setq font-lock-fontified nil)
5717
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
380 (remove-hook 'before-revert-hook 'font-lock-revert-setup)
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
381 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (font-lock-unfontify-region (point-min) (point-max))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (force-mode-line-update)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
5717
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
385 ;; If the buffer is about to be reverted, it won't be fontified.
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
386 (defun font-lock-revert-setup ()
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
387 (setq font-lock-fontified nil))
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
388
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
389 ;; If the buffer has just been reverted, we might not even be in font-lock
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
390 ;; mode anymore, and if we are, the buffer may or may not have already been
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
391 ;; refontified. Refontify here if it looks like we need to.
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
392 (defun font-lock-revert-cleanup ()
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
393 (and font-lock-mode
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
394 (not font-lock-fontified)
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
395 (font-lock-mode 1)))
24e1180b507d (font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents: 5625
diff changeset
396
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (defun font-lock-fontify-buffer ()
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 "Fontify the current buffer the way `font-lock-mode' would:
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 - comments are displayed in `font-lock-comment-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 - strings are displayed in `font-lock-string-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 - documentation strings are displayed in `font-lock-doc-string-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 - function and variable names in their defining forms are displayed
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 in `font-lock-function-name-face';
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 - and certain other expressions are displayed in other faces
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 according to the value of the variable `font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 This can take a while for large buffers."
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (interactive)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (let ((was-on font-lock-mode)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (font-lock-verbose (or font-lock-verbose (interactive-p))))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 ;; Turn it on to run hooks and get the right font-lock-keywords.
4897
c3db6fd69f1f (font-lock-fontify-buffer): Don't turn
Richard M. Stallman <rms@gnu.org>
parents: 4727
diff changeset
414 (or was-on (font-lock-set-defaults))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (font-lock-unfontify-region (point-min) (point-max))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (buffer-name)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ;; (buffer-syntactic-context-flush-cache)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (save-excursion
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (font-lock-fontify-region (point-min) (point-max))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (if font-lock-verbose (message "Fontifying %s... (regexps...)"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (buffer-name)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (set (make-local-variable 'font-lock-fontified) t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 ;;; Various mode-specific information.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (defun font-lock-set-defaults ()
4727
ca337641008d (font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents: 4700
diff changeset
432 "Set `font-lock-keywords' to something appropriate for this mode."
5294
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
433 (if (not font-lock-keywords) ; if not already set.
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
434 (setq font-lock-keywords
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
435 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
436 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
437 ((eq major-mode 'c-mode) c-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
438 ((eq major-mode 'c++-c-mode) c-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
439 ((eq major-mode 'c++-mode) c++-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
440 ((eq major-mode 'perl-mode) perl-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
441 ((eq major-mode 'tex-mode) tex-font-lock-keywords)
f5fdaf66b013 (font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents: 5056
diff changeset
442 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords)
5726
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
443 ((eq major-mode 'shell-mode) shell-font-lock-keywords)
5752
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
444 ((eq major-mode 'dired-mode) dired-font-lock-keywords)
5360
7e5fce72b793 (font-lock-set-defaults): Add missing paren.
Richard M. Stallman <rms@gnu.org>
parents: 5294
diff changeset
445 (t nil)))))
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (defconst lisp-font-lock-keywords-1
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 '(;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; highlight defining forms. This doesn't work too nicely for
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 ;; (defun (setf foo) ...) but it does work for (defvar foo) which
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 ;; is more important.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 ;; highlight CL keywords
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 ;; this is highlights things like (def* (setf foo) (bar baz)), but may
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ;; be slower (I haven't really thought about it)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 ; 1 font-lock-function-name-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 )
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 "For consideration as a value of `lisp-font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 This does fairly subdued highlighting.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (defconst lisp-font-lock-keywords-2
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (append
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 lisp-font-lock-keywords-1
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 '(;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 ;; Highlight control structures
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
5878
044cb853edbd (lisp-font-lock-keywords-2): Quote the * in let*.
Richard M. Stallman <rms@gnu.org>
parents: 5752
diff changeset
471 ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 ;; highlight function names in emacs-lisp docstrings (in the syntax
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 ;; that substitute-command-keys understands.)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 ;;
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 ;; highlight words inside `' which tend to be function names
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 1 font-lock-keyword-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 ))
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 "For consideration as a value of `lisp-font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 This does a lot more highlighting.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 ;; default to the gaudier variety?
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 ; "Additional expressions to highlight in Lisp modes.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 "Additional expressions to highlight in Lisp modes.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (defconst c-font-lock-keywords-1 nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 "For consideration as a value of `c-font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 This does fairly subdued highlighting.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (defconst c-font-lock-keywords-2 nil
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "For consideration as a value of `c-font-lock-keywords'.
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 This does a lot more highlighting.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501
6219
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
502 (defconst c++-font-lock-keywords-1 nil
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
503 "For consideration as a value of `c++-font-lock-keywords'.
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
504 This does fairly subdued highlighting.")
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
505
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
506 (defconst c++-font-lock-keywords-2 nil
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
507 "For consideration as a value of `c++-font-lock-keywords'.
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
508 This does a lot more highlighting.")
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
509
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
510 (let* ((storage "auto\\|extern\\|register\\|static\\|typedef")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
511 (struct "struct\\|union\\|enum")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
512 (prefixes "signed\\|unsigned\\|short\\|long")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
513 (types (concat prefixes "\\|int\\|char\\|float\\|double\\|void"))
6219
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
514 (ctoken "[a-zA-Z0-9_:~*]+")
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
515 (c++-things (concat
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
516 "const\\|class\\|protected:\\|private:\\|public:\\|inline\\|"
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
517 "new\\|delete")))
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
518 (setq c-font-lock-keywords-1
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
519 (list
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
520 ;; fontify preprocessor directives as comments.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
521 '("^#[ \t]*[a-z]+" . font-lock-comment-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
522 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
523 ;; fontify names being defined.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
524 '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
525 font-lock-function-name-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
526 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
527 ;; fontify other preprocessor lines.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
528 '("^#[ \t]*\\(if\\|elif\\|else\\|endif\\)[ \t]+\\([^\n]+\\)"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
529 2 font-lock-function-name-face keep)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
530 '("^#[ \t]*\\(ifn?def\\)[ \t]+\\([^ \t\n]+\\)"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
531 2 font-lock-function-name-face t)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
532 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
533 ;; fontify the filename in #include <...>
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
534 ;; don't need to do this for #include "..." because those were
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
535 ;; already fontified as strings by the syntactic pass.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
536 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
537 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
538 ;; fontify the names of functions being defined.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
539 (list (concat
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
540 "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
541 "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right?
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
542 "\\(" ctoken "[ \t]+\\)?"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
543 "\\([*&]+[ \t]*\\)?" ; pointer
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
544 "\\(" ctoken "\\)[ \t]*(") ; name
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
545 5 'font-lock-function-name-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
546 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
547 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
548 ;; Fontify structure names (in structure definition form).
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
549 (list (concat "^\\(" storage "\\)?[ \t]*\\<\\(" struct "\\)"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
550 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
551 3 'font-lock-function-name-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
552 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
553 ;; Fontify declarations of simple identifiers (including typedefs).
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
554 ;; (Should this be in c-font-lock-keywords-2 instead?)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
555 (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(\\(\\(" prefixes
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
556 "\\)\\>[ \t]*\\)*\\(" types "\\)\\)[ \t]+\\(" ctoken
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
557 "\\)[ \t]*[=;]")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
558 7 'font-lock-function-name-face 'keep)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
559 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
560 ;; And likewise for structs
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
561 (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(" struct
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
562 "\\)[ \t]+" ctoken "[ \t]+\\(" ctoken "\\);")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
563 4 'font-lock-function-name-face 'keep)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
564 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
565 ;; Fontify case clauses. This is fast because its anchored on the left.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
566 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
567 '("\\<\\(default\\):". 1)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
568 ))
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
569
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
570 (setq c-font-lock-keywords-2
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
571 (append c-font-lock-keywords-1
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (list
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 ;;
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
574 ;; fontify all storage classes and type specifiers
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
575 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
6219
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
576 (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face)
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
577 (cons (concat "\\<\\(\\(\\(" prefixes "\\)\\>[ \t]*\\)*\\(" types
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
578 "\\)\\)\\>")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
579 'font-lock-type-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
580 (list (concat "\\<\\(" struct "\\)[ \t]+" ctoken)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
581 0 'font-lock-type-face 'keep)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 ;;
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
583 ;; fontify all builtin tokens
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
584 (cons (concat
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
585 "[ \t]\\("
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
586 (mapconcat 'identity
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
587 '("for" "while" "do" "return" "goto" "case" "break" "switch"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
588 "if" "else" "default" "continue" "default")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
589 "\\|")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
590 "\\)[ \t\n(){};,]")
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
591 1)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
592 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
593 ;; fontify case targets and goto-tags. This is slow because the
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
594 ;; expression is anchored on the right.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
595 "\\(\\(\\sw\\|\\s_\\)+\\):"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
596 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
597 ;; Fontify variables declared with structures, or typedef names.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
598 '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]"
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
599 1 font-lock-function-name-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
600 ;;
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
601 ;; Fontify global variables without a type.
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
602 ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face)
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
603 )))
6219
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
604
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
605 (setq c++-font-lock-keywords-1
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
606 (cons
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
607 (concat "\\(" c++-things "\\)[ \t\n]")
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
608 c-font-lock-keywords-1))
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
609 (setq c++-font-lock-keywords-2
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
610 (cons
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
611 (cons (concat "\\<\\(" c++-things "\\)\\>") 'font-lock-type-face)
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
612 c-font-lock-keywords-2))
6093
00cee8387866 Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents: 5878
diff changeset
613 )
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 ; default to the gaudier variety?
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (defvar c-font-lock-keywords c-font-lock-keywords-1
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 "Additional expressions to highlight in C mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618
6219
d960f0463014 (c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 6093
diff changeset
619 (defvar c++-font-lock-keywords c++-font-lock-keywords-1
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 "Additional expressions to highlight in C++ mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (defvar perl-font-lock-keywords
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (list
4219
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
625 (cons (concat "[ \n\t{]*\\("
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
626 (mapconcat 'identity
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
627 '("if" "until" "while" "elsif" "else" "unless" "for"
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
628 "foreach" "continue" "exit" "die" "last" "goto" "next"
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
629 "redo" "return" "local" "exec")
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
630 "\\|")
24f3ca095be9 (perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents: 4054
diff changeset
631 "\\)[ \n\t;(]") 1)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (mapconcat 'identity
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 "#define" "#undef")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 "\\|")
4239
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
636 '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)[ \t]*[{]" 1 font-lock-function-name-face)
e8cf7a7d0102 (font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents: 4219
diff changeset
637 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face)
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 )
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 "Additional expressions to highlight in Perl mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (defvar tex-font-lock-keywords
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 (list
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}"
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 2 font-lock-function-name-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 )
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 "Additional expressions to highlight in TeX mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 (defvar texi-font-lock-keywords
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (list
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 "@\\(@\\|[^}\t \n{]+\\)" ;commands
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 )
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 "Additional expressions to highlight in TeXinfo mode.")
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
5726
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
670 (defvar shell-font-lock-keywords
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
671 (list (cons shell-prompt-pattern 'font-lock-keyword-face)
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
672 (list (concat shell-prompt-pattern "\\([^ \t]+\\)")
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
673 1 'font-lock-function-name-face)
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
674 '("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face)
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
675 '("^[^ \t]+:.*$" . font-lock-string-face)
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
676 '("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
5744
c870cde64544 (shell-font-lock-keywords): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5726
diff changeset
677 "Additional expressions to highlight in Shell mode.")
5726
781af712e68c (font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents: 5717
diff changeset
678
5752
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
679 (defvar dired-font-lock-keywords
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
680 '(;; Put directory headers in italics.
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
681 ("^ \\(/.+\\)$" 1 font-lock-type-face)
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
682 ;; Put symlinks in bold italics.
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
683 ("\\([^ ]+\\) -> [^ ]+$" . font-lock-function-name-face)
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
684 ;; Put marks in bold.
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
685 ("^\\([^ ]\\).*$" 1 font-lock-keyword-face t)
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
686 ;; Put files that are subdirectories in bold.
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
687 ("^..d.* \\([^ ]+\\)$" 1 font-lock-keyword-face))
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
688 "Additional expressions to highlight in Dired mode.")
412ac1a01f46 (dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5744
diff changeset
689
4053
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (provide 'font-lock)
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691
c142db721726 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 ;;; font-lock.el ends here