comparison lisp/font-lock.el @ 4219:24f3ca095be9

(perl-font-lock-keywords): Add a `(... . 1)' to the first element of the list. (font-lock-hack-keywords, font-lock-unfontify-region) (font-lock-fontify-region): Bind buffer-read-only to nil, and don't alter buffer-modified-p. (font-lock-fontify-region): Use comment-start-skip, not comment-start. (font-lock-function-name-face): defvar renamed. (font-lock-hack-keywords): Evaluate face specs from keyword list.
author Richard M. Stallman <rms@gnu.org>
date Thu, 22 Jul 1993 06:12:37 +0000
parents 074035743fc9
children e8cf7a7d0102
comparison
equal deleted inserted replaced
4218:8e42b7df5c4f 4219:24f3ca095be9
68 68
69 (defvar font-lock-string-face 69 (defvar font-lock-string-face
70 'underline 70 'underline
71 "Face to use for string constants.") 71 "Face to use for string constants.")
72 72
73 (defvar font-lock-function-face 73 (defvar font-lock-function-name-face
74 'bold-italic 74 'bold-italic
75 "Face to use for function names.") 75 "Face to use for function names.")
76 76
77 (defvar font-lock-keyword-face 77 (defvar font-lock-keyword-face
78 'bold 78 'bold
125 "Put proper face on each string and comment between START and END." 125 "Put proper face on each string and comment between START and END."
126 (save-excursion 126 (save-excursion
127 (goto-char start) 127 (goto-char start)
128 (beginning-of-line) 128 (beginning-of-line)
129 (setq end (min end (point-max))) 129 (setq end (min end (point-max)))
130 (let (state startline prev prevstate) 130 (let ((buffer-read-only nil)
131 state startline prev prevstate
132 (modified (buffer-modified-p)))
131 ;; Find the state at the line-beginning before START. 133 ;; Find the state at the line-beginning before START.
132 (setq startline (point)) 134 (setq startline (point))
133 (if (eq (point) font-lock-cache-position) 135 (if (eq (point) font-lock-cache-position)
134 (setq state font-lock-cache-state) 136 (setq state font-lock-cache-state)
135 ;; Find outermost containing sexp. 137 ;; Find outermost containing sexp.
162 (put-text-property beg (point) 'face font-lock-comment-face) 164 (put-text-property beg (point) 'face font-lock-comment-face)
163 (setq state (parse-partial-sexp beg (point) nil nil state)))) 165 (setq state (parse-partial-sexp beg (point) nil nil state))))
164 ;; Find each interesting place between here and END. 166 ;; Find each interesting place between here and END.
165 (while (and (< (point) end) 167 (while (and (< (point) end)
166 (setq prev (point) prevstate state) 168 (setq prev (point) prevstate state)
167 (re-search-forward (concat "\\s\"\\|" (regexp-quote comment-start)) end t) 169 (re-search-forward (concat "\\s\"\\|" comment-start-skip) end t)
168 ;; Clear out the fonts of what we skip over. 170 ;; Clear out the fonts of what we skip over.
169 (progn (remove-text-properties prev (point) '(face nil)) t) 171 (progn (remove-text-properties prev (point) '(face nil)) t)
170 ;; Verify the state at that place 172 ;; Verify the state at that place
171 ;; so we don't get fooled by \" or \;. 173 ;; so we don't get fooled by \" or \;.
172 (setq state (parse-partial-sexp prev (point) 174 (setq state (parse-partial-sexp prev (point)
197 )) 199 ))
198 ;; Make sure PREV is non-nil after the loop 200 ;; Make sure PREV is non-nil after the loop
199 ;; only if it was set on the very last iteration. 201 ;; only if it was set on the very last iteration.
200 (setq prev nil)) 202 (setq prev nil))
201 (and prev 203 (and prev
202 (remove-text-properties prev end '(face nil)))))) 204 (remove-text-properties prev end '(face nil)))
205 (set-buffer-modified-p modified))))
203 206
204 ;; This code used to be used to show a string on reaching the end of it. 207 ;; This code used to be used to show a string on reaching the end of it.
205 ;; It is probably not needed due to later changes to handle strings 208 ;; It is probably not needed due to later changes to handle strings
206 ;; starting before the region in question. 209 ;; starting before the region in question.
207 ;; (if (and (null (nth 3 state)) 210 ;; (if (and (null (nth 3 state))
222 ;; (if (= (car state) 1) 225 ;; (if (= (car state) 1)
223 ;; font-lock-doc-string-face 226 ;; font-lock-doc-string-face
224 ;; font-lock-string-face))))) 227 ;; font-lock-string-face)))))
225 228
226 (defun font-lock-unfontify-region (beg end) 229 (defun font-lock-unfontify-region (beg end)
227 (remove-text-properties beg end '(face nil))) 230 (let ((modified (buffer-modified-p))
231 (buffer-read-only nil))
232 (remove-text-properties beg end '(face nil))
233 (set-buffer-modified-p modified)))
228 234
229 ;; Called when any modification is made to buffer text. 235 ;; Called when any modification is made to buffer text.
230 (defun font-lock-after-change-function (beg end old-len) 236 (defun font-lock-after-change-function (beg end old-len)
231 (save-excursion 237 (save-excursion
232 (save-match-data 238 (save-match-data
257 (defun font-lock-hack-keywords (start end &optional loudly) 263 (defun font-lock-hack-keywords (start end &optional loudly)
258 (goto-char start) 264 (goto-char start)
259 (let ((case-fold-search font-lock-keywords-case-fold-search) 265 (let ((case-fold-search font-lock-keywords-case-fold-search)
260 (rest font-lock-keywords) 266 (rest font-lock-keywords)
261 (count 0) 267 (count 0)
268 (buffer-read-only nil)
269 (modified (buffer-modified-p))
262 first str match face s e allow-overlap-p) 270 first str match face s e allow-overlap-p)
263 (while rest 271 (while rest
264 (setq first (car rest) rest (cdr rest)) 272 (setq first (car rest) rest (cdr rest))
265 (goto-char start) 273 (goto-char start)
266 (cond ((consp first) 274 (cond ((consp first)
267 (setq str (car first)) 275 (setq str (car first))
268 (cond ((consp (cdr first)) 276 (cond ((consp (cdr first))
269 (setq match (nth 1 first) 277 (setq match (nth 1 first)
270 face (nth 2 first) 278 face (eval (nth 2 first))
271 allow-overlap-p (nth 3 first))) 279 allow-overlap-p (nth 3 first)))
272 ((symbolp (cdr first)) 280 ((symbolp (cdr first))
273 (setq match 0 allow-overlap-p nil 281 (setq match 0 allow-overlap-p nil
274 face (cdr first))) 282 face (eval (cdr first))))
275 (t 283 (t
276 (setq match (cdr first) 284 (setq match (cdr first)
277 allow-overlap-p nil 285 allow-overlap-p nil
278 face font-lock-keyword-face)))) 286 face font-lock-keyword-face))))
279 (t 287 (t
288 (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) 296 (or (if allow-overlap-p nil (font-lock-any-properties-p s e))
289 (progn 297 (progn
290 (put-text-property s e 'face face)))) 298 (put-text-property s e 'face face))))
291 (if loudly (message "Fontifying %s... (regexps...%s)" 299 (if loudly (message "Fontifying %s... (regexps...%s)"
292 (buffer-name) 300 (buffer-name)
293 (make-string (setq count (1+ count)) ?.)))))) 301 (make-string (setq count (1+ count)) ?.))))
294 302 (set-buffer-modified-p modified)))
295 303
296 ;; The user level functions 304 ;; The user level functions
297 305
298 (defvar font-lock-mode nil) ; for modeline 306 (defvar font-lock-mode nil) ; for modeline
299 (or (assq 'font-lock-mode minor-mode-alist) 307 (or (assq 'font-lock-mode minor-mode-alist)
538 "Additional expressions to highlight in C++ mode.") 546 "Additional expressions to highlight in C++ mode.")
539 547
540 548
541 (defvar perl-font-lock-keywords 549 (defvar perl-font-lock-keywords
542 (list 550 (list
543 (concat "[ \n\t{]*\\(" 551 (cons (concat "[ \n\t{]*\\("
544 (mapconcat 'identity 552 (mapconcat 'identity
545 '("if" "until" "while" "elsif" "else" "unless" "for" 553 '("if" "until" "while" "elsif" "else" "unless" "for"
546 "foreach" "continue" "exit" "die" "last" "goto" "next" 554 "foreach" "continue" "exit" "die" "last" "goto" "next"
547 "redo" "return" "local" "exec") 555 "redo" "return" "local" "exec")
548 "\\|") 556 "\\|")
549 "\\)[ \n\t;(]") 557 "\\)[ \n\t;(]") 1)
550 (mapconcat 'identity 558 (mapconcat 'identity
551 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" 559 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include"
552 "#define" "#undef") 560 "#define" "#undef")
553 "\\|") 561 "\\|")
554 '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)\\{" . font-lock-function-name-face) 562 '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)\\{" . font-lock-function-name-face)