comparison lisp/fast-lock.el @ 12909:0e165bcd43a2

New version 3.07. Made fast-lock-mode use buffer-file-truename, not buffer-file-name.
author Simon Marshall <simon@gnu.org>
date Mon, 21 Aug 1995 12:02:23 +0000
parents 8e3d4f515bbb
children 0cbf58edd87f
comparison
equal deleted inserted replaced
12908:2aa3e1b05567 12909:0e165bcd43a2
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.06 7 ;; Version: 3.07
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
58 ;; Feedback is welcome. 58 ;; Feedback is welcome.
59 ;; To submit a bug report (or make comments) please use the mechanism provided: 59 ;; To submit a bug report (or make comments) please use the mechanism provided:
60 ;; 60 ;;
61 ;; M-x fast-lock-submit-bug-report RET 61 ;; M-x fast-lock-submit-bug-report RET
62 62
63 ;; History:
64 ;;
65 ;; 0.02--1.00:
66 ;; - Changed name from turbo-prop to fast-lock. Automagic for font-lock only.
67 ;; - Made `fast-lock-mode' a minor mode, like G. Dinesh Dutt's fss-mode.
68 ;; 1.00--1.01:
69 ;; - Turn on `fast-lock-mode' only if `buffer-file-name' or `interactive-p'.
70 ;; - Made `fast-lock-file-name' use `buffer-name' if `buffer-file-name' is nil.
71 ;; - Moved save-all conditions to `fast-lock-save-cache'.
72 ;; - Added `fast-lock-save-text-properties' to `kill-buffer-hook'.
73 ;; 1.01--2.00: complete rewrite---not worth the space to document.
74 ;; - Changed structure of text properties cache and threw out file mod checks.
75 ;; 2.00--2.01:
76 ;; - Made `condition-case' forms understand `quit'.
77 ;; - Made `fast-lock' require `font-lock'.
78 ;; - Made `fast-lock-cache-name' chase links (from Ben Liblit).
79 ;; 2.01--3.00:
80 ;; - Changed structure of cache to include `font-lock-keywords' (from rms).
81 ;; - Changed `fast-lock-cache-mechanisms' to `fast-lock-cache-directories'.
82 ;; - Removed `fast-lock-read-others'.
83 ;; - Made `fast-lock-read-cache' ignore cache owner.
84 ;; - Made `fast-lock-save-cache-external' create cache directory.
85 ;; - Made `fast-lock-save-cache-external' save `font-lock-keywords'.
86 ;; - Made `fast-lock-cache-data' check `font-lock-keywords'.
87 ;; 3.00--3.01: incorporated port of 2.00 to Lucid, made by Barry Warsaw.
88 ;; - Package now provides itself.
89 ;; - Lucid: Use `font-lock-any-extents-p' for `font-lock-any-properties-p'.
90 ;; - Lucid: Use `list-faces' for `face-list'.
91 ;; - Lucid: Added `set-text-properties'.
92 ;; - Lucid: Made `turn-on-fast-lock' pass 1 not t to `fast-lock-mode'.
93 ;; - Removed test for `fast-lock-mode' from `fast-lock-read-cache'.
94 ;; - Lucid: Added Lucid-specific `fast-lock-get-face-properties'.
95 ;; 3.01--3.02: now works with Lucid Emacs, thanks to Barry Warsaw.
96 ;; - Made `fast-lock-cache-name' map ":" to ";" for OS/2 (from Serganova Vera).
97 ;; - Made `fast-lock-cache-name' use abbreviated file name (from Barry Warsaw).
98 ;; - Lucid: Separated handlers for `error' and `quit' for `condition-case'.
99 ;; 3.02--3.03:
100 ;; - Changed `fast-lock-save-cache-external' to `fast-lock-save-cache-data'.
101 ;; - Lucid: Added Lucid-specific `fast-lock-set-face-properties'.
102 ;; 3.03--3.04:
103 ;; - Corrected `subrp' test of Lucid code.
104 ;; - Replaced `font-lock-any-properties-p' with `text-property-not-all'.
105 ;; - Lucid: Made `fast-lock-set-face-properties' put `text-prop' on extents.
106 ;; - Made `fast-lock-cache-directories' a regexp alist (from Colin Rafferty).
107 ;; - Made `fast-lock-cache-directory' to return a usable cache file directory.
108 ;; 3.04--3.05:
109 ;; - Lucid: Fix for XEmacs 19.11 `text-property-not-all'.
110 ;; - Replaced `subrp' test of Lucid code with `emacs-version' `string-match'.
111 ;; - Made `byte-compile-warnings' omit `unresolved' on compilation.
112 ;; - Made `fast-lock-save-cache-data' use a buffer (from Rick Sladkey).
113 ;; - Reverted to old `fast-lock-get-face-properties' (from Rick Sladkey).
114 ;; 3.05--3.06: incorporated hack of 3.03, made by Jonathan Stigelman (Stig).
115 ;; - Reverted to 3.04 version of `fast-lock-get-face-properties'.
116 ;; - XEmacs: Removed `list-faces' `defalias'.
117 ;; - Made `fast-lock-mode' and `turn-on-fast-lock' succeed `autoload' cookies.
118 ;; - Added `lazy-lock-submit-bug-report'.
119 ;; - Renamed `fast-lock-save-size' to `fast-lock-minimum-size'.
120 ;; - Made `fast-lock-save-cache' output a message if no save ever attempted.
121 ;; - Made `fast-lock-save-cache-data' output a message if save attempted.
122 ;; - Made `fast-lock-cache-data' output a message if load attempted.
123 ;; - Made `fast-lock-save-cache-data' do `condition-case' not `unwind-protect'.
124 ;; - Made `fast-lock-save-cache' and `fast-lock-read-cache' return nothing.
125 ;; - Made `fast-lock-save-cache' check `buffer-modified-p' (Stig).
126 ;; - Added `fast-lock-save-events'.
127 ;; - Added `fast-lock-after-save-hook' to `after-save-hook' (Stig).
128 ;; - Added `fast-lock-kill-buffer-hook' to `kill-buffer-hook'.
129 ;; - Changed `fast-lock-save-caches' to `fast-lock-kill-emacs-hook'.
130 ;; - Added `fast-lock-kill-emacs-hook' to `kill-emacs-hook'.
131 ;; - Made `fast-lock-save-cache' check `verify-visited-file-modtime' (Stig).
132 ;; - Made `visited-file-modtime' be the basis of the timestamp (Stig).
133 ;; - Made `fast-lock-save-cache-1' and `fast-lock-cache-data' use/reformat it.
134 ;; - Added `fast-lock-cache-filename' to keep track of the cache file name.
135 ;; - Added `fast-lock-after-fontify-buffer'.
136 ;; - Added `fast-lock-save-faces' list of faces to save (idea from Stig/Tibor).
137 ;; - Made `fast-lock-get-face-properties' functions use it.
138 ;; - XEmacs: Made `fast-lock-set-face-properties' do extents the Font Lock way.
139 ;; - XEmacs: Removed fix for `text-property-not-all' (19.11 support dropped).
140 ;; - Made `fast-lock-mode' ensure `font-lock-mode' is on.
141 ;; - Made `fast-lock-save-cache' do `cdr-safe' not `cdr' (from Dave Foster).
142 ;; - Made `fast-lock-save-cache' do `set-buffer' first (from Dave Foster).
143 ;; - Made `fast-lock-save-cache' loop until saved or quit (from Georg Nikodym).
144 ;; - Made `fast-lock-cache-data' check `buffer-modified-p'.
145 ;; - Made `fast-lock-cache-data' do `font-lock-compile-keywords' if necessary.
146 ;; - XEmacs: Made `font-lock-compile-keywords' `defalias'.
147 ;; 3.06--3.07:
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'.
150 ;; - Made `fast-lock-mode' use `buffer-file-truename' not `buffer-file-name'.
151
63 (require 'font-lock) 152 (require 'font-lock)
64 153
65 (eval-when-compile 154 (eval-when-compile
66 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users). 155 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users).
67 (setq byte-compile-warnings '(free-vars callargs redefine))) 156 (setq byte-compile-warnings '(free-vars callargs redefine)))
68 157
69 (defun fast-lock-submit-bug-report () 158 (defun fast-lock-submit-bug-report ()
70 "Submit via mail a bug report on fast-lock.el." 159 "Submit via mail a bug report on fast-lock.el."
71 (interactive) 160 (interactive)
72 (let ((reporter-prompt-for-summary-p t)) 161 (let ((reporter-prompt-for-summary-p t))
73 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.06" 162 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.07"
74 '(fast-lock-cache-directories fast-lock-minimum-size 163 '(fast-lock-cache-directories fast-lock-minimum-size
75 fast-lock-save-others fast-lock-save-events fast-lock-save-faces) 164 fast-lock-save-others fast-lock-save-events fast-lock-save-faces)
76 nil nil 165 nil nil
77 (concat "Hi Si., 166 (concat "Hi Si.,
78 167
99 An attempt will be made to save or read Font Lock cache files using these items 188 An attempt will be made to save or read Font Lock cache files using these items
100 until one succeeds (i.e., until a readable or writable one is found). If an 189 until one succeeds (i.e., until a readable or writable one is found). If an
101 item contains REGEXP, DIR is used only if the buffer file name matches REGEXP. 190 item contains REGEXP, DIR is used only if the buffer file name matches REGEXP.
102 For example: 191 For example:
103 192
104 (list (cons (concat \"^\" (regexp-quote (expand-file-name \"~\"))) \".\") 193 (let ((home (expand-file-name (abbreviate-file-name (file-truename \"~/\")))))
105 \"~/.emacs-flc\") 194 (list (cons (concat \"^\" (regexp-quote home)) \".\") \"~/.emacs-flc\"))
195 =>
196 ((\"^/your/true/home/directory/\" . \".\") \"~/.emacs-flc\")
106 197
107 would cause a file's current directory to be used if the file is under your 198 would cause a file's current directory to be used if the file is under your
108 home directory hierarchy, or otherwise the absolute directory `~/.emacs-flc'.") 199 home directory hierarchy, or otherwise the absolute directory `~/.emacs-flc'.")
109 200
110 (defvar fast-lock-minimum-size (* 25 1024) 201 (defvar fast-lock-minimum-size (* 25 1024)
123 If nil, means only buffer files known to be owned by you can have associated 214 If nil, means only buffer files known to be owned by you can have associated
124 Font Lock cache files saved. Ownership may be unknown for networked files.") 215 Font Lock cache files saved. Ownership may be unknown for networked files.")
125 216
126 (defvar fast-lock-save-faces 217 (defvar fast-lock-save-faces
127 ;; Since XEmacs uses extents for everything, we have to pick the right ones. 218 ;; Since XEmacs uses extents for everything, we have to pick the right ones.
128 ;; In XEmacs 19.12 we can't identify which text properties are font-lock's. 219 ;; In XEmacs 19.13 we can't identify which text properties are Font Lock's.
129 (if (save-match-data (string-match "XEmacs" (emacs-version))) 220 (if (save-match-data (string-match "XEmacs" (emacs-version)))
130 '(font-lock-string-face font-lock-doc-string-face font-lock-type-face 221 '(font-lock-string-face font-lock-doc-string-face font-lock-type-face
131 font-lock-function-name-face font-lock-comment-face 222 font-lock-function-name-face font-lock-comment-face
132 font-lock-keyword-face) 223 font-lock-keyword-face font-lock-preprocessor-face)
133 ;; For Emacs 19.29 I don't think this is generally necessary. 224 ;; For Emacs 19.30 I don't think this is generally necessary.
134 ;(mapcar 'eval (mapcar 'car font-lock-face-attributes)) 225 nil)
135 )
136 "A list of faces that will be saved in a Font Lock cache file. 226 "A list of faces that will be saved in a Font Lock cache file.
137 If nil, means information for all faces will be saved.") 227 If nil, means information for all faces will be saved.")
138 228
139 ;; User Functions: 229 ;; User Functions:
140 230
165 `fast-lock-save-others' and `fast-lock-save-faces'. 255 `fast-lock-save-others' and `fast-lock-save-faces'.
166 256
167 Use \\[fast-lock-submit-bug-report] to send bug reports or feedback." 257 Use \\[fast-lock-submit-bug-report] to send bug reports or feedback."
168 (interactive "P") 258 (interactive "P")
169 (set (make-local-variable 'fast-lock-mode) 259 (set (make-local-variable 'fast-lock-mode)
170 (and (buffer-file-name) 260 (and buffer-file-truename
171 (if arg (> (prefix-numeric-value arg) 0) (not fast-lock-mode)))) 261 (if arg (> (prefix-numeric-value arg) 0) (not fast-lock-mode))))
172 (if (and fast-lock-mode (not font-lock-mode)) 262 (if (and fast-lock-mode (not font-lock-mode))
173 ;; Turned on `fast-lock-mode' rather than using `font-lock-mode-hook'. 263 ;; Turned on `fast-lock-mode' rather than using `font-lock-mode-hook'.
174 (progn 264 (progn
175 (add-hook 'font-lock-mode-hook 'turn-on-fast-lock) 265 (add-hook 'font-lock-mode-hook 'turn-on-fast-lock)
176 (font-lock-mode 1)) 266 (font-lock-mode t))
177 ;; Let's get down to business. 267 ;; Let's get down to business.
178 (set (make-local-variable 'fast-lock-cache-timestamp) nil) 268 (set (make-local-variable 'fast-lock-cache-timestamp) nil)
179 (set (make-local-variable 'fast-lock-cache-filename) nil) 269 (set (make-local-variable 'fast-lock-cache-filename) nil)
180 (if (and fast-lock-mode (not font-lock-fontified)) 270 (if (and fast-lock-mode (not font-lock-fontified))
181 (fast-lock-read-cache)))) 271 (fast-lock-read-cache))))
260 (setq directories (cdr directories))))))))) 350 (setq directories (cdr directories)))))))))
261 351
262 ;;;###autoload 352 ;;;###autoload
263 (defun turn-on-fast-lock () 353 (defun turn-on-fast-lock ()
264 "Unconditionally turn on Fast Lock mode." 354 "Unconditionally turn on Fast Lock mode."
265 (fast-lock-mode 1)) 355 (fast-lock-mode t))
266 356
267 ;;; API Functions: 357 ;;; API Functions:
268 358
269 (defun fast-lock-after-fontify-buffer () 359 (defun fast-lock-after-fontify-buffer ()
270 ;; Delete the Font Lock cache file used to restore fontification, if any. 360 ;; Delete the Font Lock cache file used to restore fontification, if any.
317 (create 407 (create
318 (condition-case nil 408 (condition-case nil
319 (progn (make-directory dir t) dir) 409 (progn (make-directory dir t) dir)
320 (error nil)))))) 410 (error nil))))))
321 411
412 ;; If you are wondering why we only hash if the directory is not ".", rather
413 ;; than if `file-name-absolute-p', it is because if we just appended ".flc" for
414 ;; relative cache directories (that are not ".") then it is possible that more
415 ;; than one file would have the same cache name in that directory, if the luser
416 ;; made a link from one relative cache directory to another. (Phew!)
322 (defun fast-lock-cache-name (directory) 417 (defun fast-lock-cache-name (directory)
323 "Return full cache path name using caching DIRECTORY. 418 "Return full cache path name using caching DIRECTORY.
324 If DIRECTORY is `.', the path is the buffer file name appended with `.flc'. 419 If DIRECTORY is `.', the path is the buffer file name appended with `.flc'.
325 Otherwise, the path name is constructed from DIRECTORY and the buffer's true 420 Otherwise, the path name is constructed from DIRECTORY and the buffer's true
326 abbreviated file name, with all `/' characters in the name replaced with `#' 421 abbreviated file name, with all `/' characters in the name replaced with `#'
327 characters, and appended with `.flc'. 422 characters, and appended with `.flc'.
328 423
329 See `fast-lock-mode'." 424 If the same file has different cache path names when edited on different
425 machines, e.g., on one machine the cache file name has the prefix `#home',
426 perhaps due to automount, try putting in your `~/.emacs' something like:
427
428 (setq directory-abbrev-alist (cons '(\"^/home/\" . \"/\") directory-abbrev-alist))
429
430 Emacs automagically removes the common `/tmp_mnt' automount prefix by default.
431
432 See `fast-lock-cache-directory'."
330 (if (string-equal directory ".") 433 (if (string-equal directory ".")
331 (concat buffer-file-name ".flc") 434 (concat buffer-file-name ".flc")
332 (let* ((bufile (expand-file-name buffer-file-truename)) 435 (let* ((bufile (expand-file-name buffer-file-truename))
333 (chars-alist 436 (chars-alist
334 (if (eq system-type 'emx) 437 (if (eq system-type 'emx)
507 (while regions 610 (while regions
508 (font-lock-set-face (nth 0 regions) (nth 1 regions) face) 611 (font-lock-set-face (nth 0 regions) (nth 1 regions) face)
509 (setq regions (nthcdr 2 regions))) 612 (setq regions (nthcdr 2 regions)))
510 (setq properties (cdr properties))))))) 613 (setq properties (cdr properties)))))))
511 614
615 (if (save-match-data (string-match "XEmacs" (emacs-version)))
616 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook.
617 (add-hook 'font-lock-after-fontify-buffer-hook
618 'fast-lock-after-fontify-buffer))
619
512 (or (fboundp 'font-lock-compile-keywords) 620 (or (fboundp 'font-lock-compile-keywords)
513 (defalias 'font-lock-compile-keywords 'identity)) 621 (defalias 'font-lock-compile-keywords 'identity))
514 622
515 ;; Install ourselves: 623 ;; Install ourselves:
516 624
517 ;; We don't install ourselves on `font-lock-mode-hook' as packages with similar 625 ;; We don't install ourselves on `font-lock-mode-hook' as packages with similar
518 ;; functionality exist, and fast-lock.el should be dumpable. 626 ;; functionality exist, and fast-lock.el should be dumpable without forcing
627 ;; people to use caches or making it difficult for people to use alternatives.
519 (add-hook 'after-save-hook 'fast-lock-after-save-hook) 628 (add-hook 'after-save-hook 'fast-lock-after-save-hook)
520 (add-hook 'kill-buffer-hook 'fast-lock-kill-buffer-hook) 629 (add-hook 'kill-buffer-hook 'fast-lock-kill-buffer-hook)
521 (add-hook 'kill-emacs-hook 'fast-lock-kill-emacs-hook) 630 (add-hook 'kill-emacs-hook 'fast-lock-kill-emacs-hook)
522 631
523 ;; Maybe save on the modeline? 632 ;; Maybe save on the modeline?