Mercurial > emacs
comparison lisp/fast-lock.el @ 17498:5ea11c278a57
Customise.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Thu, 17 Apr 1997 07:35:54 +0000 |
parents | de68258fef5f |
children | fd87760f20cd |
comparison
equal
deleted
inserted
replaced
17497:3ee027d263c6 | 17498:5ea11c278a57 |
---|---|
1 ;;; fast-lock.el --- Automagic text properties caching for fast Font Lock mode. | 1 ;;; fast-lock.el --- Automagic text properties caching for fast Font Lock mode. |
2 | 2 |
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1996, 1997 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.11 | 7 ;; Version: 3.12 |
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 |
158 ;; 3.10--3.11: | 158 ;; 3.10--3.11: |
159 ;; - Made `fast-lock-get-face-properties' cope with face lists | 159 ;; - Made `fast-lock-get-face-properties' cope with face lists |
160 ;; - Added `fast-lock-verbose' | 160 ;; - Added `fast-lock-verbose' |
161 ;; - XEmacs: Add `font-lock-value-in-major-mode' if necessary | 161 ;; - XEmacs: Add `font-lock-value-in-major-mode' if necessary |
162 ;; - Removed `fast-lock-submit-bug-report' and bade farewell | 162 ;; - Removed `fast-lock-submit-bug-report' and bade farewell |
163 ;; 3.11--3.12: | |
164 ;; - Added Custom support (Hrvoje Niksic help) | |
165 ;; - Made `fast-lock-cache-data' simplify calls of `font-lock-compile-keywords' | |
163 | 166 |
164 ;;; Code: | 167 ;;; Code: |
165 | 168 |
166 (require 'font-lock) | 169 (require 'font-lock) |
167 | 170 |
181 ;; | 184 ;; |
182 ;; We use this to preserve or protect things when modifying text properties. | 185 ;; We use this to preserve or protect things when modifying text properties. |
183 (defmacro save-buffer-state (varlist &rest body) | 186 (defmacro save-buffer-state (varlist &rest body) |
184 "Bind variables according to VARLIST and eval BODY restoring buffer state." | 187 "Bind variables according to VARLIST and eval BODY restoring buffer state." |
185 (` (let* ((,@ (append varlist | 188 (` (let* ((,@ (append varlist |
186 '((modified (buffer-modified-p)) | 189 '((modified (buffer-modified-p)) (buffer-undo-list t) |
187 (inhibit-read-only t) (buffer-undo-list t) | 190 (inhibit-read-only t) (inhibit-point-motion-hooks t) |
188 before-change-functions after-change-functions | 191 before-change-functions after-change-functions |
189 deactivate-mark buffer-file-name buffer-file-truename)))) | 192 deactivate-mark buffer-file-name buffer-file-truename)))) |
190 (,@ body) | 193 (,@ body) |
191 (when (and (not modified) (buffer-modified-p)) | 194 (when (and (not modified) (buffer-modified-p)) |
192 (set-buffer-modified-p nil))))) | 195 (set-buffer-modified-p nil))))) |
205 | 208 |
206 ;(defun fast-lock-submit-bug-report () | 209 ;(defun fast-lock-submit-bug-report () |
207 ; "Submit via mail a bug report on fast-lock.el." | 210 ; "Submit via mail a bug report on fast-lock.el." |
208 ; (interactive) | 211 ; (interactive) |
209 ; (let ((reporter-prompt-for-summary-p t)) | 212 ; (let ((reporter-prompt-for-summary-p t)) |
210 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.11" | 213 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.12" |
211 ; '(fast-lock-cache-directories fast-lock-minimum-size | 214 ; '(fast-lock-cache-directories fast-lock-minimum-size |
212 ; fast-lock-save-others fast-lock-save-events fast-lock-save-faces | 215 ; fast-lock-save-others fast-lock-save-events fast-lock-save-faces |
213 ; fast-lock-verbose) | 216 ; fast-lock-verbose) |
214 ; nil nil | 217 ; nil nil |
215 ; (concat "Hi Si., | 218 ; (concat "Hi Si., |
218 ;know how to make a clear and unambiguous report. To reproduce the bug: | 221 ;know how to make a clear and unambiguous report. To reproduce the bug: |
219 ; | 222 ; |
220 ;Start a fresh editor via `" invocation-name " -no-init-file -no-site-file'. | 223 ;Start a fresh editor via `" invocation-name " -no-init-file -no-site-file'. |
221 ;In the `*scratch*' buffer, evaluate:")))) | 224 ;In the `*scratch*' buffer, evaluate:")))) |
222 | 225 |
223 (defvar fast-lock-mode nil) | 226 (defvar fast-lock-mode nil) ; Whether we are turned on. |
224 (defvar fast-lock-cache-timestamp nil) ; for saving/reading | 227 (defvar fast-lock-cache-timestamp nil) ; For saving/reading. |
225 (defvar fast-lock-cache-filename nil) ; for deleting | 228 (defvar fast-lock-cache-filename nil) ; For deleting. |
226 | 229 |
227 ;; User Variables: | 230 ;; User Variables: |
228 | 231 |
229 (defgroup fast-lock nil | 232 (defgroup fast-lock nil |
230 "Automagic text properties caching for fast Font Lock mode" | 233 "Font Lock support mode to cache fontification." |
231 :group 'faces) | 234 :link '(custom-manual "(emacs)Support Modes") |
232 | 235 :group 'font-lock) |
233 | 236 |
234 (defcustom fast-lock-cache-directories '("." "~/.emacs-flc") | 237 (defcustom fast-lock-cache-directories '("." "~/.emacs-flc") |
235 ; - `internal', keep each file's Font Lock cache file in the same file. | 238 ; - `internal', keep each file's Font Lock cache file in the same file. |
236 ; - `external', keep each file's Font Lock cache file in the same directory. | 239 ; - `external', keep each file's Font Lock cache file in the same directory. |
237 "*Directories in which Font Lock cache files are saved and read. | 240 "*Directories in which Font Lock cache files are saved and read. |
248 => | 251 => |
249 ((\"^/your/true/home/directory/\" . \".\") \"~/.emacs-flc\") | 252 ((\"^/your/true/home/directory/\" . \".\") \"~/.emacs-flc\") |
250 | 253 |
251 would cause a file's current directory to be used if the file is under your | 254 would cause a file's current directory to be used if the file is under your |
252 home directory hierarchy, or otherwise the absolute directory `~/.emacs-flc'." | 255 home directory hierarchy, or otherwise the absolute directory `~/.emacs-flc'." |
253 :type '(repeat (choice (cons regexp directory) directory)) | 256 :type '(repeat (radio (cons regexp directory) directory)) |
254 :group 'fast-lock) | 257 :group 'fast-lock) |
255 | 258 |
256 (defcustom fast-lock-minimum-size (* 25 1024) | 259 (defcustom fast-lock-minimum-size (* 25 1024) |
257 "*Minimum size of a buffer for cached fontification. | 260 "*Minimum size of a buffer for cached fontification. |
258 Only buffers more than this can have associated Font Lock cache files saved. | 261 Only buffers more than this can have associated Font Lock cache files saved. |
260 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), | 263 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), |
261 where MAJOR-MODE is a symbol or t (meaning the default). For example: | 264 where MAJOR-MODE is a symbol or t (meaning the default). For example: |
262 ((c-mode . 25600) (c++-mode . 25600) (rmail-mode . 1048576)) | 265 ((c-mode . 25600) (c++-mode . 25600) (rmail-mode . 1048576)) |
263 means that the minimum size is 25K for buffers in C or C++ modes, one megabyte | 266 means that the minimum size is 25K for buffers in C or C++ modes, one megabyte |
264 for buffers in Rmail mode, and size is irrelevant otherwise." | 267 for buffers in Rmail mode, and size is irrelevant otherwise." |
265 :type '(choice (integer :tag "Size") (repeat (cons (symbol :tag "Major Mode") | 268 :type '(radio (const :tag "None" nil) |
266 (integer :tag "Size")))) | 269 (integer :tag "Size") |
270 (repeat (cons (symbol :tag "Major Mode") | |
271 (integer :tag "Size")))) | |
267 :group 'fast-lock) | 272 :group 'fast-lock) |
268 | 273 |
269 (defcustom fast-lock-save-events '(kill-buffer kill-emacs) | 274 (defcustom fast-lock-save-events '(kill-buffer kill-emacs) |
270 "*Events under which caches will be saved. | 275 "*Events under which caches will be saved. |
271 Valid events are `save-buffer', `kill-buffer' and `kill-emacs'. | 276 Valid events are `save-buffer', `kill-buffer' and `kill-emacs'. |
279 If nil, means only buffer files known to be owned by you can have associated | 284 If nil, means only buffer files known to be owned by you can have associated |
280 Font Lock cache files saved. Ownership may be unknown for networked files." | 285 Font Lock cache files saved. Ownership may be unknown for networked files." |
281 :type 'boolean | 286 :type 'boolean |
282 :group 'fast-lock) | 287 :group 'fast-lock) |
283 | 288 |
289 (defcustom fast-lock-verbose font-lock-verbose | |
290 "*If non-nil, means show status messages for cache processing. | |
291 If a number, only buffers greater than this size have processing messages." | |
292 :type '(radio (const :tag "Never" nil) | |
293 (const :tag "Always" t) | |
294 (integer :tag "Size")) | |
295 :group 'fast-lock) | |
296 | |
284 (defvar fast-lock-save-faces | 297 (defvar fast-lock-save-faces |
285 (when (save-match-data (string-match "XEmacs" (emacs-version))) | 298 (when (save-match-data (string-match "XEmacs" (emacs-version))) |
286 ;; XEmacs uses extents for everything, so we have to pick the right ones. | 299 ;; XEmacs uses extents for everything, so we have to pick the right ones. |
287 font-lock-face-list) | 300 font-lock-face-list) |
288 "Faces that will be saved in a Font Lock cache file. | 301 "Faces that will be saved in a Font Lock cache file. |
289 If nil, means information for all faces will be saved.") | 302 If nil, means information for all faces will be saved.") |
290 | |
291 (defcustom fast-lock-verbose font-lock-verbose | |
292 "*If non-nil, means show status messages for cache processing. | |
293 If a number, only buffers greater than this size have processing messages." | |
294 :type '(choice integer boolean) | |
295 :group 'fast-lock) | |
296 | 303 |
297 ;; User Functions: | 304 ;; User Functions: |
298 | 305 |
299 ;;;###autoload | 306 ;;;###autoload |
300 (defun fast-lock-mode (&optional arg) | 307 (defun fast-lock-mode (&optional arg) |
557 (defun fast-lock-cache-data (version timestamp keywords properties | 564 (defun fast-lock-cache-data (version timestamp keywords properties |
558 &rest ignored) | 565 &rest ignored) |
559 ;; Change from (HIGH LOW) for back compatibility. Remove for version 3! | 566 ;; Change from (HIGH LOW) for back compatibility. Remove for version 3! |
560 (when (consp (cdr-safe timestamp)) | 567 (when (consp (cdr-safe timestamp)) |
561 (setcdr timestamp (nth 1 timestamp))) | 568 (setcdr timestamp (nth 1 timestamp))) |
562 ;; Compile KEYWORDS and `font-lock-keywords' in case one is and one isn't. | 569 ;; Compile `font-lock-keywords' and KEYWORDS in case one is and one isn't. |
563 (let ((current font-lock-keywords)) | 570 (setq font-lock-keywords (font-lock-compile-keywords font-lock-keywords) |
564 (setq keywords (font-lock-compile-keywords keywords) | 571 keywords (font-lock-compile-keywords keywords)) |
565 font-lock-keywords (font-lock-compile-keywords current))) | |
566 ;; Use the Font Lock cache PROPERTIES if we're using cache VERSION format 2, | 572 ;; Use the Font Lock cache PROPERTIES if we're using cache VERSION format 2, |
567 ;; the current buffer's file timestamp matches the TIMESTAMP, and the current | 573 ;; the current buffer's file timestamp matches the TIMESTAMP, and the current |
568 ;; buffer's font-lock-keywords are the same as KEYWORDS. | 574 ;; buffer's font-lock-keywords are the same as KEYWORDS. |
569 (let ((buf-timestamp (visited-file-modtime)) | 575 (let ((buf-timestamp (visited-file-modtime)) |
570 (verbose (if (numberp fast-lock-verbose) | 576 (verbose (if (numberp fast-lock-verbose) |
737 (add-hook 'after-save-hook 'fast-lock-save-cache-after-save-file) | 743 (add-hook 'after-save-hook 'fast-lock-save-cache-after-save-file) |
738 (add-hook 'kill-buffer-hook 'fast-lock-save-cache-before-kill-buffer) | 744 (add-hook 'kill-buffer-hook 'fast-lock-save-cache-before-kill-buffer) |
739 (add-hook 'kill-emacs-hook 'fast-lock-save-caches-before-kill-emacs) | 745 (add-hook 'kill-emacs-hook 'fast-lock-save-caches-before-kill-emacs) |
740 | 746 |
741 ;;;###autoload | 747 ;;;###autoload |
742 (if (fboundp 'add-minor-mode) (add-minor-mode 'fast-lock-mode nil)) | 748 (when (fboundp 'add-minor-mode) |
749 (defvar fast-lock-mode nil) | |
750 (add-minor-mode 'fast-lock-mode nil)) | |
743 ;;;###dont-autoload | 751 ;;;###dont-autoload |
744 (unless (assq 'fast-lock-mode minor-mode-alist) | 752 (unless (assq 'fast-lock-mode minor-mode-alist) |
745 (setq minor-mode-alist (append minor-mode-alist '((fast-lock-mode nil))))) | 753 (setq minor-mode-alist (append minor-mode-alist '((fast-lock-mode nil))))) |
746 | 754 |
747 ;; Provide ourselves: | 755 ;; Provide ourselves: |