193
|
1 ;;; lazy-shot.el --- Lazy font locking for XEmacs
|
|
2
|
|
3 ;; Copyright (C) 1997 Jan Vroonhof
|
|
4
|
|
5 ;; Author: Jan Vroonhof <vroonhof@math.ethz.ch>
|
|
6 ;; Keywords: languages, faces
|
|
7
|
|
8 ;; This file is part of XEmacs
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: Not synched.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This versions has basic demand lock functionality. Somebody please
|
|
30 ;; sync further with lazy-lock v2 from FSF, customize etc.
|
|
31 ;;
|
|
32 ;;
|
|
33 ;; Idea for the stealth lock function:
|
|
34 ;;
|
|
35 ;;
|
|
36 ;; On an Idle itimer
|
|
37 ;; Loop over all buffers with lazy-lock set
|
|
38 ;; mapcar-extent in the region (point) point-max for
|
|
39 ;; one-shot-function property
|
|
40 ;; If not found do the same for [point-min,point]
|
|
41 ;; font-lock the found region and delete the extent
|
|
42
|
|
43 ;;; Code:
|
|
44
|
|
45 (require 'font-lock)
|
|
46
|
|
47 (defvar lazy-shot-mode nil)
|
|
48
|
|
49
|
|
50 (defvar lazy-shot-step-size (* 1 124)) ;; Please test diffent sizes
|
|
51
|
|
52 ;;;###autoload
|
|
53 (defun lazy-shot-mode (&optional arg)
|
|
54 "Toggle Lazy Lock mode.
|
|
55 With arg, turn Lazy Lock mode on if and only if arg is positive."
|
|
56 (interactive "P")
|
|
57 (set (make-local-variable 'lazy-shot-mode)
|
|
58 (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-shot-mode))))
|
|
59 (cond ((and lazy-shot-mode (not font-lock-mode))
|
|
60 ;; Turned on `lazy-shot-mode' rather than `font-lock-mode'.
|
|
61 (let ((font-lock-support-mode 'lazy-shot-mode))
|
|
62 (font-lock-mode t)))
|
|
63 (lazy-shot-mode
|
|
64 ;; Turn ourselves on.
|
|
65 (lazy-shot-install))
|
|
66 (t
|
|
67 ;; Turn ourselves off.
|
|
68 (lazy-shot-unstall))))
|
|
69
|
|
70 ;;;###autoload
|
|
71 (defun turn-on-lazy-shot ()
|
|
72 "Unconditionally turn on Lazy Lock mode."
|
|
73 (lazy-shot-mode t))
|
|
74
|
|
75
|
|
76 (defun lazy-shot-shot-function (extent)
|
|
77 "Lazy lock the extent when it has become visisble"
|
|
78 (let ((start (extent-start-position extent))
|
|
79 (end (extent-end-position extent))
|
|
80 (buffer (extent-buffer extent)))
|
|
81 (delete-extent extent)
|
|
82 (save-excursion
|
|
83 ;; This magic should really go into font-lock-fonity-region
|
|
84 (goto-char start)
|
|
85 (unless (bolp)
|
|
86 (beginning-of-line)
|
|
87 (setq start (point)))
|
|
88 (goto-char end)
|
|
89 (unless (bolp)
|
|
90 (forward-line)
|
|
91 (setq end (point)))
|
|
92 (message "Lazy-shot fontifying from %s to %s in %s" start end buffer)
|
|
93 (save-match-data
|
|
94 (font-lock-fontify-region start end)))))
|
|
95
|
|
96 (defun lazy-shot-install-extent (spos epos &optional buffer)
|
|
97 "Make an extent that will lazy-shot if it is displayed"
|
|
98 (let ((extent (make-extent spos epos buffer)))
|
|
99 (when extent
|
|
100 (set-extent-one-shot-function extent
|
|
101 'lazy-shot-shot-function))
|
|
102 extent))
|
|
103
|
|
104 (defun lazy-shot-install-extents (fontifying)
|
|
105 ;;
|
|
106 ;; Add hook if lazy-shot.el is deferring or is fontifying on scrolling.
|
|
107 (when fontifying
|
|
108 (let ((start (point-min)))
|
|
109 (while (< start (point-max))
|
|
110 (lazy-shot-install-extent start
|
|
111 (min (point-max) (+ start lazy-shot-step-size)))
|
|
112 (setq start (+ start lazy-shot-step-size))))))
|
|
113
|
|
114 (defun lazy-shot-install ()
|
|
115 (make-local-variable 'font-lock-fontified)
|
|
116 (setq font-lock-fontified t)
|
|
117 (lazy-shot-install-extents font-lock-fontified))
|
|
118
|
|
119 (defun lazy-shot-unstall ()
|
|
120 ;;
|
|
121 ;; Remove the extents.
|
|
122 (map-extents
|
|
123 (lambda (e arg) (delete-extent e) nil)
|
|
124 nil nil nil nil nil 'one-shot-function 'lazy-shot-shot-function)
|
|
125 ;;
|
|
126 ;; Remove the fontification hooks.
|
|
127 (remove-hook 'after-change-functions 'lazy-shot-defer-after-change t)
|
|
128 ;;
|
|
129 ;; If Font Lock mode is still enabled, reinstall its hook.
|
|
130 (when font-lock-mode
|
|
131 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))
|
|
132
|
|
133
|
|
134 (provide 'lazy-shot)
|
|
135
|
|
136 ;;; lazy-shot.el ends here
|