comparison lisp/fast-lock.el @ 13301:0cbf58edd87f

Updated to 3.08; don't use `let' var from caller.
author Simon Marshall <simon@gnu.org>
date Thu, 26 Oct 1995 13:34:28 +0000
parents 0e165bcd43a2
children 83f275dcd93a
comparison
equal deleted inserted replaced
13300:73b7a6396cbe 13301:0cbf58edd87f
2 2
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 4
5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu> 5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu>
6 ;; Keywords: faces files 6 ;; Keywords: faces files
7 ;; Version: 3.07 7 ;; Version: 3.08
8 8
9 ;;; This file is part of GNU Emacs. 9 ;;; This file is part of GNU Emacs.
10 10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
146 ;; - XEmacs: Made `font-lock-compile-keywords' `defalias'. 146 ;; - XEmacs: Made `font-lock-compile-keywords' `defalias'.
147 ;; 3.06--3.07: 147 ;; 3.06--3.07:
148 ;; - XEmacs: Add `fast-lock-after-fontify-buffer' to the Font Lock hook. 148 ;; - XEmacs: Add `fast-lock-after-fontify-buffer' to the Font Lock hook.
149 ;; - Made `fast-lock-cache-name' explain the use of `directory-abbrev-alist'. 149 ;; - Made `fast-lock-cache-name' explain the use of `directory-abbrev-alist'.
150 ;; - Made `fast-lock-mode' use `buffer-file-truename' not `buffer-file-name'. 150 ;; - Made `fast-lock-mode' use `buffer-file-truename' not `buffer-file-name'.
151 ;; 3.07--3.08:
152 ;; - Made `fast-lock-read-cache' set `fast-lock-cache-filename'.
151 153
152 (require 'font-lock) 154 (require 'font-lock)
153 155
154 (eval-when-compile 156 (eval-when-compile
155 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users). 157 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users).
157 159
158 (defun fast-lock-submit-bug-report () 160 (defun fast-lock-submit-bug-report ()
159 "Submit via mail a bug report on fast-lock.el." 161 "Submit via mail a bug report on fast-lock.el."
160 (interactive) 162 (interactive)
161 (let ((reporter-prompt-for-summary-p t)) 163 (let ((reporter-prompt-for-summary-p t))
162 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.07" 164 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.08"
163 '(fast-lock-cache-directories fast-lock-minimum-size 165 '(fast-lock-cache-directories fast-lock-minimum-size
164 fast-lock-save-others fast-lock-save-events fast-lock-save-faces) 166 fast-lock-save-others fast-lock-save-events fast-lock-save-faces)
165 nil nil 167 nil nil
166 (concat "Hi Si., 168 (concat "Hi Si.,
167 169
254 For saving, see variables `fast-lock-minimum-size', `fast-lock-save-events', 256 For saving, see variables `fast-lock-minimum-size', `fast-lock-save-events',
255 `fast-lock-save-others' and `fast-lock-save-faces'. 257 `fast-lock-save-others' and `fast-lock-save-faces'.
256 258
257 Use \\[fast-lock-submit-bug-report] to send bug reports or feedback." 259 Use \\[fast-lock-submit-bug-report] to send bug reports or feedback."
258 (interactive "P") 260 (interactive "P")
261 ;; Only turn on if we are visiting a file. We could use `buffer-file-name',
262 ;; but many packages temporarily wrap that to nil when doing their own thing.
259 (set (make-local-variable 'fast-lock-mode) 263 (set (make-local-variable 'fast-lock-mode)
260 (and buffer-file-truename 264 (and buffer-file-truename
261 (if arg (> (prefix-numeric-value arg) 0) (not fast-lock-mode)))) 265 (if arg (> (prefix-numeric-value arg) 0) (not fast-lock-mode))))
262 (if (and fast-lock-mode (not font-lock-mode)) 266 (if (and fast-lock-mode (not font-lock-mode))
263 ;; Turned on `fast-lock-mode' rather than using `font-lock-mode-hook'. 267 ;; Turned on `fast-lock-mode' rather than using `font-lock-mode-hook'.
283 See `fast-lock-mode'." 287 See `fast-lock-mode'."
284 (interactive) 288 (interactive)
285 (let ((directories fast-lock-cache-directories) 289 (let ((directories fast-lock-cache-directories)
286 (modified (buffer-modified-p)) (inhibit-read-only t) 290 (modified (buffer-modified-p)) (inhibit-read-only t)
287 (fontified font-lock-fontified)) 291 (fontified font-lock-fontified))
288 (setq fast-lock-cache-filename nil)
289 (set (make-local-variable 'font-lock-fontified) nil) 292 (set (make-local-variable 'font-lock-fontified) nil)
290 ;; Keep trying directories until fontification is turned off. 293 ;; Keep trying directories until fontification is turned off.
291 (while (and directories (not font-lock-fontified)) 294 (while (and directories (not font-lock-fontified))
292 (let* ((directory (fast-lock-cache-directory (car directories) nil)) 295 (let ((directory (fast-lock-cache-directory (car directories) nil)))
293 (file (and directory (fast-lock-cache-name directory)))) 296 (if (not directory)
294 (condition-case nil 297 nil
295 (and file (file-readable-p file) (load file t t t)) 298 (setq fast-lock-cache-filename (fast-lock-cache-name directory))
296 (error nil) (quit nil)) 299 (condition-case nil
300 (if (file-readable-p fast-lock-cache-filename)
301 (load fast-lock-cache-filename t t t))
302 (error nil) (quit nil)))
297 (setq directories (cdr directories)))) 303 (setq directories (cdr directories))))
304 ;; Unset `fast-lock-cache-filename', and restore `font-lock-fontified', if
305 ;; we don't use a cache. (Note that `fast-lock-cache-data' sets the value
306 ;; of `fast-lock-cache-timestamp'.)
298 (set-buffer-modified-p modified) 307 (set-buffer-modified-p modified)
299 (or font-lock-fontified (setq font-lock-fontified fontified)))) 308 (if (not font-lock-fontified)
309 (setq fast-lock-cache-filename nil font-lock-fontified fontified))))
300 310
301 (defun fast-lock-save-cache (&optional buffer) 311 (defun fast-lock-save-cache (&optional buffer)
302 "Save the Font Lock cache of BUFFER or the current buffer. 312 "Save the Font Lock cache of BUFFER or the current buffer.
303 313
304 The following criteria must be met for a Font Lock cache file to be saved: 314 The following criteria must be met for a Font Lock cache file to be saved:
497 (error (setq loaded 'error)) (quit (setq loaded 'quit))) 507 (error (setq loaded 'error)) (quit (setq loaded 'quit)))
498 (message "Loading %s font lock cache... %s." buname 508 (message "Loading %s font lock cache... %s." buname
499 (cond ((eq loaded 'error) "failed") 509 (cond ((eq loaded 'error) "failed")
500 ((eq loaded 'quit) "aborted") 510 ((eq loaded 'quit) "aborted")
501 (t "done")))) 511 (t "done"))))
502 ;; If we used the text properties, stop fontification and keep timestamp.
503 ;; Kludge warning: `file' comes from sole caller `fast-lock-read-cache'.
504 (setq font-lock-fontified (eq loaded t) 512 (setq font-lock-fontified (eq loaded t)
505 fast-lock-cache-timestamp (and (eq loaded t) timestamp) 513 fast-lock-cache-timestamp (and (eq loaded t) timestamp))))
506 fast-lock-cache-filename (and (eq loaded t) file))))
507 514
508 ;; Text Properties Processing Functions: 515 ;; Text Properties Processing Functions:
509 516
510 ;; This is faster, but fails if adjacent characters have different `face' text 517 ;; This is faster, but fails if adjacent characters have different `face' text
511 ;; properties. Maybe that's why I dropped it in the first place? 518 ;; properties. Maybe that's why I dropped it in the first place?