-;;; lazy-lock.el --- Lazy demand-driven fontification for fast Font Lock mode.
+;;; lazy-lock.el --- lazy demand-driven fontification for fast Font Lock mode
-;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2001
+;; Free Software Foundation, Inc.
;; Author: Simon Marshall <simon@gnu.org>
;; Maintainer: FSF
;; Keywords: faces files
;; Version: 2.11
-;;; This file is part of GNU Emacs.
+;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
(require 'font-lock)
(eval-when-compile
- ;; We don't do this at the top-level as we only use non-autoloaded macros.
- (require 'cl)
- ;;
- ;; We use this to preserve or protect things when modifying text properties.
- (defmacro save-buffer-state (varlist &rest body)
- "Bind variables according to VARLIST and eval BODY restoring buffer state."
- (` (let* ((,@ (append varlist
- '((modified (buffer-modified-p)) (buffer-undo-list t)
- (inhibit-read-only t) (inhibit-point-motion-hooks t)
- before-change-functions after-change-functions
- deactivate-mark buffer-file-name buffer-file-truename))))
- (,@ body)
- (when (and (not modified) (buffer-modified-p))
- (set-buffer-modified-p nil)))))
- (put 'save-buffer-state 'lisp-indent-function 1)
- ;;
- ;; We use this for clarity and speed. Naughty but nice.
- (defmacro do-while (test &rest body)
- "(do-while TEST BODY...): eval BODY... and repeat if TEST yields non-nil.
+ ;; We don't do this at the top-level as we only use non-autoloaded macros.
+ (require 'cl)
+ ;;
+ ;; We use this to preserve or protect things when modifying text properties.
+ (defmacro save-buffer-state (varlist &rest body)
+ "Bind variables according to VARLIST and eval BODY restoring buffer state."
+ `(let* (,@(append varlist
+ '((modified (buffer-modified-p))
+ (buffer-undo-list t)
+ (inhibit-read-only t)
+ (inhibit-point-motion-hooks t)
+ (inhibit-modification-hooks t)
+ deactivate-mark
+ buffer-file-name
+ buffer-file-truename)))
+ ,@body
+ (when (and (not modified) (buffer-modified-p))
+ (restore-buffer-modified-p nil))))
+ (put 'save-buffer-state 'lisp-indent-function 1)
+ ;;
+ ;; We use this for clarity and speed. Naughty but nice.
+ (defmacro do-while (test &rest body)
+ "(do-while TEST BODY...): eval BODY... and repeat if TEST yields non-nil.
The order of execution is thus BODY, TEST, BODY, TEST and so on
until TEST returns nil."
- (` (while (progn (,@ body) (, test)))))
- (put 'do-while 'lisp-indent-function (get 'while 'lisp-indent-function)))
+ `(while (progn ,@body ,test)))
+ (put 'do-while 'lisp-indent-function (get 'while 'lisp-indent-function)))
(defvar lazy-lock-mode nil) ; Whether we are turned on.
(defvar lazy-lock-buffers nil) ; For deferral.
(setq font-lock-support-mode 'lazy-lock-mode)
+For a newer font-lock support mode with similar functionality, see
+`jit-lock-mode'. Eventually, Lazy Lock mode will be deprecated in
+JIT Lock's favor.
+
When Lazy Lock mode is enabled, fontification can be lazy in a number of ways:
- Demand-driven buffer fontification if `lazy-lock-minimum-size' is non-nil.
;;
;; Add hook if lazy-lock.el is fontifying on scrolling or is deferring.
(when (or fontifying defer-change defer-scroll defer-context)
- (make-local-hook 'window-scroll-functions)
(add-hook 'window-scroll-functions (if defer-scroll
'lazy-lock-defer-after-scroll
'lazy-lock-fontify-after-scroll)
;;
;; Add hook if lazy-lock.el is fontifying and is not deferring changes.
(when (and fontifying (not defer-change) (not defer-context))
- (make-local-hook 'before-change-functions)
(add-hook 'before-change-functions 'lazy-lock-arrange-before-change nil t))
;;
;; Replace Font Lock mode hook.
nil t)
;;
;; Add package-specific hook.
- (make-local-hook 'outline-view-change-hook)
(add-hook 'outline-view-change-hook 'lazy-lock-fontify-after-visage nil t)
- (make-local-hook 'hs-hide-hook)
(add-hook 'hs-hide-hook 'lazy-lock-fontify-after-visage nil t))
(defun lazy-lock-install-timers (dtime stime)
(lazy-lock-percent-fontified) (buffer-name))
(message "Fontifying stealthily...")
(setq message t)))
+ ;; Current buffer may have changed during `sit-for'.
+ (set-buffer (car buffers))
(lazy-lock-fontify-chunk)
(setq continue (sit-for (or lazy-lock-stealth-nice 0)))))))
(setq buffers (cdr buffers)))))))
;; should use this function. For an example, see ps-print.el.
(defun lazy-lock-fontify-region (beg end)
;; Fontify between BEG and END, where necessary, in the current buffer.
- (when (setq beg (text-property-any beg end 'lazy-lock nil))
- (save-excursion
- (save-match-data
- (save-buffer-state
- ;; Ensure syntactic fontification is always correct.
- (font-lock-beginning-of-syntax-function next)
- ;; Find successive unfontified regions between BEG and END.
- (condition-case data
- (do-while beg
- (setq next (or (text-property-any beg end 'lazy-lock t) end))
- ;; Make sure the region end points are at beginning of line.
- (goto-char beg)
- (unless (bolp)
- (beginning-of-line)
- (setq beg (point)))
- (goto-char next)
- (unless (bolp)
- (forward-line)
- (setq next (point)))
- ;; Fontify the region, then flag it as fontified.
- (font-lock-fontify-region beg next)
- (add-text-properties beg next '(lazy-lock t))
- (setq beg (text-property-any next end 'lazy-lock nil)))
- ((error quit) (message "Fontifying region...%s" data))))))))
+ (save-restriction
+ (widen)
+ (when (setq beg (text-property-any beg end 'lazy-lock nil))
+ (save-excursion
+ (save-match-data
+ (save-buffer-state
+ ;; Ensure syntactic fontification is always correct.
+ (font-lock-beginning-of-syntax-function next)
+ ;; Find successive unfontified regions between BEG and END.
+ (condition-case data
+ (do-while beg
+ (setq next (or (text-property-any beg end 'lazy-lock t) end))
+ ;; Make sure the region end points are at beginning of line.
+ (goto-char beg)
+ (unless (bolp)
+ (beginning-of-line)
+ (setq beg (point)))
+ (goto-char next)
+ (unless (bolp)
+ (forward-line)
+ (setq next (point)))
+ ;; Fontify the region, then flag it as fontified.
+ (font-lock-fontify-region beg next)
+ (add-text-properties beg next '(lazy-lock t))
+ (setq beg (text-property-any next end 'lazy-lock nil)))
+ ((error quit) (message "Fontifying region...%s" data)))))))))
(defun lazy-lock-fontify-chunk ()
;; Fontify the nearest chunk, for stealth, in the current buffer.