comparison lisp/fast-lock.el @ 23752:001e0e875d56

* fast-lock.el (fast-lock-save-cache-1): (fast-lock-cache-data): Rewritten to use with-temp-message.
author Simon Marshall <simon@gnu.org>
date Mon, 23 Nov 1998 11:13:33 +0000
parents 2f420ea7b3d4
children c78112715e6c
comparison
equal deleted inserted replaced
23751:3fdde7281f9b 23752:001e0e875d56
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, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998 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.13 7 ;; Version: 3.14
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
170 ;; - Made `fast-lock-save-cache-1' save syntactic fontification data 170 ;; - Made `fast-lock-save-cache-1' save syntactic fontification data
171 ;; - Made `fast-lock-cache-data' take syntactic fontification data 171 ;; - Made `fast-lock-cache-data' take syntactic fontification data
172 ;; - Added `fast-lock-get-syntactic-properties' 172 ;; - Added `fast-lock-get-syntactic-properties'
173 ;; - Renamed `fast-lock-set-face-properties' to `fast-lock-add-properties' 173 ;; - Renamed `fast-lock-set-face-properties' to `fast-lock-add-properties'
174 ;; - Made `fast-lock-add-properties' add syntactic and face fontification data 174 ;; - Made `fast-lock-add-properties' add syntactic and face fontification data
175 ;; 3.13--3.14:
176 ;; - Made `fast-lock-cache-name' cope with `windowsnt' (Geoff Voelker fix)
177 ;; - Made `fast-lock-verbose' use `other' widget (Andreas Schwab fix)
178 ;; - Used `with-temp-message' where possible to make messages temporary.
175 179
176 ;;; Code: 180 ;;; Code:
177 181
178 (require 'font-lock) 182 (require 'font-lock)
179 183
209 (while (unless (memq (car faces) fast-lock-save-faces) 213 (while (unless (memq (car faces) fast-lock-save-faces)
210 (setq faces (cdr faces)))) 214 (setq faces (cdr faces))))
211 faces))))) 215 faces)))))
212 ;; 216 ;;
213 ;; We use this for compatibility with a future Emacs. 217 ;; We use this for compatibility with a future Emacs.
218 (or (fboundp 'with-temp-message)
219 (defmacro with-temp-message (message &rest body)
220 (` (let ((current-message (current-message)))
221 (unwind-protect
222 (progn (message (, message)) (,@ body))
223 (message current-message))))))
224 ;;
225 ;; We use this for compatibility with a future Emacs.
214 (or (fboundp 'defcustom) 226 (or (fboundp 'defcustom)
215 (defmacro defcustom (symbol value doc &rest args) 227 (defmacro defcustom (symbol value doc &rest args)
216 (` (defvar (, symbol) (, value) (, doc)))))) 228 (` (defvar (, symbol) (, value) (, doc))))))
217 229
218 ;(defun fast-lock-submit-bug-report () 230 ;(defun fast-lock-submit-bug-report ()
219 ; "Submit via mail a bug report on fast-lock.el." 231 ; "Submit via mail a bug report on fast-lock.el."
220 ; (interactive) 232 ; (interactive)
221 ; (let ((reporter-prompt-for-summary-p t)) 233 ; (let ((reporter-prompt-for-summary-p t))
222 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.13" 234 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "fast-lock 3.14"
223 ; '(fast-lock-cache-directories fast-lock-minimum-size 235 ; '(fast-lock-cache-directories fast-lock-minimum-size
224 ; fast-lock-save-others fast-lock-save-events fast-lock-save-faces 236 ; fast-lock-save-others fast-lock-save-events fast-lock-save-faces
225 ; fast-lock-verbose) 237 ; fast-lock-verbose)
226 ; nil nil 238 ; nil nil
227 ; (concat "Hi Si., 239 ; (concat "Hi Si.,
236 (defvar fast-lock-cache-timestamp nil) ; For saving/reading. 248 (defvar fast-lock-cache-timestamp nil) ; For saving/reading.
237 (defvar fast-lock-cache-filename nil) ; For deleting. 249 (defvar fast-lock-cache-filename nil) ; For deleting.
238 250
239 ;; User Variables: 251 ;; User Variables:
240 252
241 (defcustom fast-lock-minimum-size (* 25 1024) 253 (defcustom fast-lock-minimum-size 25600
242 "*Minimum size of a buffer for cached fontification. 254 "*Minimum size of a buffer for cached fontification.
243 Only buffers more than this can have associated Font Lock cache files saved. 255 Only buffers more than this can have associated Font Lock cache files saved.
244 If nil, means cache files are never created. 256 If nil, means cache files are never created.
245 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), 257 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
246 where MAJOR-MODE is a symbol or t (meaning the default). For example: 258 where MAJOR-MODE is a symbol or t (meaning the default). For example:
304 316
305 (defcustom fast-lock-verbose font-lock-verbose 317 (defcustom fast-lock-verbose font-lock-verbose
306 "*If non-nil, means show status messages for cache processing. 318 "*If non-nil, means show status messages for cache processing.
307 If a number, only buffers greater than this size have processing messages." 319 If a number, only buffers greater than this size have processing messages."
308 :type '(choice (const :tag "never" nil) 320 :type '(choice (const :tag "never" nil)
309 (integer :tag "size") 321 (other :tag "always" t)
310 (other :tag "always" t)) 322 (integer :tag "size"))
311 :group 'fast-lock) 323 :group 'fast-lock)
312 324
313 (defvar fast-lock-save-faces 325 (defvar fast-lock-save-faces
314 (when (save-match-data (string-match "XEmacs" (emacs-version))) 326 (when (save-match-data (string-match "XEmacs" (emacs-version)))
315 ;; XEmacs uses extents for everything, so we have to pick the right ones. 327 ;; XEmacs uses extents for everything, so we have to pick the right ones.
559 (let ((tpbuf (generate-new-buffer " *fast-lock*")) 571 (let ((tpbuf (generate-new-buffer " *fast-lock*"))
560 (verbose (if (numberp fast-lock-verbose) 572 (verbose (if (numberp fast-lock-verbose)
561 (> (buffer-size) fast-lock-verbose) 573 (> (buffer-size) fast-lock-verbose)
562 fast-lock-verbose)) 574 fast-lock-verbose))
563 (saved t)) 575 (saved t))
564 (if verbose (message "Saving %s font lock cache..." (buffer-name))) 576 (with-temp-message
565 (condition-case nil 577 (if verbose
566 (save-excursion 578 (format "Saving %s font lock cache..." (buffer-name))
567 (print (list 'fast-lock-cache-data 3 579 (current-message))
568 (list 'quote timestamp) 580 (condition-case nil
569 (list 'quote font-lock-syntactic-keywords) 581 (save-excursion
570 (list 'quote (fast-lock-get-syntactic-properties)) 582 (print (list 'fast-lock-cache-data 3
571 (list 'quote font-lock-keywords) 583 (list 'quote timestamp)
572 (list 'quote (fast-lock-get-face-properties))) 584 (list 'quote font-lock-syntactic-keywords)
573 tpbuf) 585 (list 'quote (fast-lock-get-syntactic-properties))
574 (set-buffer tpbuf) 586 (list 'quote font-lock-keywords)
575 (write-region (point-min) (point-max) file nil 'quietly) 587 (list 'quote (fast-lock-get-face-properties)))
576 (setq fast-lock-cache-timestamp timestamp 588 tpbuf)
577 fast-lock-cache-filename file)) 589 (set-buffer tpbuf)
578 (error (setq saved 'error)) (quit (setq saved 'quit))) 590 (write-region (point-min) (point-max) file nil 'quietly)
579 (kill-buffer tpbuf) 591 (setq fast-lock-cache-timestamp timestamp
580 (if verbose (message "Saving %s font lock cache...%s" (buffer-name) 592 fast-lock-cache-filename file))
581 (cond ((eq saved 'error) "failed") 593 (error (setq saved 'error)) (quit (setq saved 'quit)))
582 ((eq saved 'quit) "aborted") 594 (kill-buffer tpbuf))
583 (t "done")))) 595 (cond ((eq saved 'quit)
596 (message "Saving %s font lock cache...quit" (buffer-name)))
597 ((eq saved 'error)
598 (message "Saving %s font lock cache...failed" (buffer-name))))
584 ;; We return non-nil regardless of whether a failure occurred. 599 ;; We return non-nil regardless of whether a failure occurred.
585 saved)) 600 saved))
586 601
587 (defun fast-lock-cache-data (version timestamp 602 (defun fast-lock-cache-data (version timestamp
588 syntactic-keywords syntactic-properties 603 syntactic-keywords syntactic-properties
613 (buffer-modified-p) 628 (buffer-modified-p)
614 (not (equal timestamp buf-timestamp)) 629 (not (equal timestamp buf-timestamp))
615 (not (equal syntactic-keywords font-lock-syntactic-keywords)) 630 (not (equal syntactic-keywords font-lock-syntactic-keywords))
616 (not (equal keywords font-lock-keywords))) 631 (not (equal keywords font-lock-keywords)))
617 (setq loaded nil) 632 (setq loaded nil)
618 (if verbose (message "Loading %s font lock cache..." (buffer-name))) 633 (with-temp-message
619 (condition-case nil 634 (if verbose
620 (fast-lock-add-properties syntactic-properties face-properties) 635 (format "Loading %s font lock cache..." (buffer-name))
621 (error (setq loaded 'error)) (quit (setq loaded 'quit))) 636 (current-message))
622 (if verbose (message "Loading %s font lock cache...%s" (buffer-name) 637 (condition-case nil
623 (cond ((eq loaded 'error) "failed") 638 (fast-lock-add-properties syntactic-properties face-properties)
624 ((eq loaded 'quit) "aborted") 639 (error (setq loaded 'error)) (quit (setq loaded 'quit))))
625 (t "done"))))) 640 (cond ((eq loaded 'quit)
641 (message "Loading %s font lock cache...quit" (buffer-name)))
642 ((eq loaded 'error)
643 (message "Loading %s font lock cache...failed" (buffer-name)))))
626 (setq font-lock-fontified (eq loaded t) 644 (setq font-lock-fontified (eq loaded t)
627 fast-lock-cache-timestamp (and (eq loaded t) timestamp)))) 645 fast-lock-cache-timestamp (and (eq loaded t) timestamp))))
628 646
629 ;; Text Properties Processing Functions: 647 ;; Text Properties Processing Functions:
630 648
812 (unless (fboundp 'font-lock-value-in-major-mode) 830 (unless (fboundp 'font-lock-value-in-major-mode)
813 (defun font-lock-value-in-major-mode (alist) 831 (defun font-lock-value-in-major-mode (alist)
814 (if (consp alist) 832 (if (consp alist)
815 (cdr (or (assq major-mode alist) (assq t alist))) 833 (cdr (or (assq major-mode alist) (assq t alist)))
816 alist))) 834 alist)))
835
836 (unless (fboundp 'current-message)
837 (defun current-message ()
838 ""))
817 839
818 ;; Install ourselves: 840 ;; Install ourselves:
819 841
820 (add-hook 'after-save-hook 'fast-lock-save-cache-after-save-file) 842 (add-hook 'after-save-hook 'fast-lock-save-cache-after-save-file)
821 (add-hook 'kill-buffer-hook 'fast-lock-save-cache-before-kill-buffer) 843 (add-hook 'kill-buffer-hook 'fast-lock-save-cache-before-kill-buffer)