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
|
203
|
50 (defgroup lazy-shot nil
|
|
51 "Lazy-shot customizations"
|
|
52 :group 'tools
|
|
53 :prefix "lazy-shot-")
|
|
54
|
|
55 (defcustom lazy-shot-step-size 1024 ; Please test diffent sizes
|
|
56 "Minimum size of each fontification shot."
|
|
57 :type 'integer
|
|
58 :group 'lazy-shot)
|
193
|
59
|
|
60 ;;;###autoload
|
|
61 (defun lazy-shot-mode (&optional arg)
|
|
62 "Toggle Lazy Lock mode.
|
|
63 With arg, turn Lazy Lock mode on if and only if arg is positive."
|
|
64 (interactive "P")
|
|
65 (set (make-local-variable 'lazy-shot-mode)
|
|
66 (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-shot-mode))))
|
|
67 (cond ((and lazy-shot-mode (not font-lock-mode))
|
|
68 ;; Turned on `lazy-shot-mode' rather than `font-lock-mode'.
|
|
69 (let ((font-lock-support-mode 'lazy-shot-mode))
|
|
70 (font-lock-mode t)))
|
|
71 (lazy-shot-mode
|
|
72 ;; Turn ourselves on.
|
|
73 (lazy-shot-install))
|
|
74 (t
|
|
75 ;; Turn ourselves off.
|
|
76 (lazy-shot-unstall))))
|
|
77
|
|
78 ;;;###autoload
|
|
79 (defun turn-on-lazy-shot ()
|
|
80 "Unconditionally turn on Lazy Lock mode."
|
|
81 (lazy-shot-mode t))
|
|
82
|
|
83
|
|
84 (defun lazy-shot-shot-function (extent)
|
|
85 "Lazy lock the extent when it has become visisble"
|
|
86 (let ((start (extent-start-position extent))
|
|
87 (end (extent-end-position extent))
|
195
|
88 (buffer (extent-object extent)))
|
193
|
89 (delete-extent extent)
|
195
|
90 (with-current-buffer buffer
|
|
91 (save-excursion
|
|
92 ;; This magic should really go into font-lock-fonity-region
|
|
93 (goto-char start)
|
|
94 (unless (bolp)
|
|
95 (beginning-of-line)
|
|
96 (setq start (point)))
|
|
97 (goto-char end)
|
|
98 (unless (bolp)
|
|
99 (forward-line)
|
|
100 (setq end (point)))
|
|
101 (display-message 'progress
|
|
102 (format "Lazy-shot fontifying from %s to %s in %s"
|
|
103 start end buffer))
|
|
104 (save-match-data
|
|
105 (font-lock-fontify-region start end))))))
|
193
|
106
|
|
107 (defun lazy-shot-install-extent (spos epos &optional buffer)
|
|
108 "Make an extent that will lazy-shot if it is displayed"
|
|
109 (let ((extent (make-extent spos epos buffer)))
|
|
110 (when extent
|
|
111 (set-extent-one-shot-function extent
|
|
112 'lazy-shot-shot-function))
|
|
113 extent))
|
|
114
|
203
|
115 (defun lazy-shot-next-line (pos &optional buffer)
|
|
116 "Return the next end-of-line from POS in BUFFER."
|
|
117 (save-excursion
|
|
118 (goto-char pos buffer)
|
|
119 (forward-line 1 buffer)
|
|
120 (point buffer)))
|
|
121
|
193
|
122 (defun lazy-shot-install-extents (fontifying)
|
|
123 ;;
|
|
124 ;; Add hook if lazy-shot.el is deferring or is fontifying on scrolling.
|
203
|
125 (when fontifying
|
|
126 (let ((max (point-max)))
|
|
127 (do* ((start (point-min) end)
|
|
128 (end (min max (lazy-shot-next-line (+ start lazy-shot-step-size)))
|
|
129 (min max (lazy-shot-next-line (+ start lazy-shot-step-size)))))
|
|
130 ((>= start max))
|
|
131 (lazy-shot-install-extent start end)))))
|
193
|
132
|
|
133 (defun lazy-shot-install ()
|
|
134 (make-local-variable 'font-lock-fontified)
|
|
135 (setq font-lock-fontified t)
|
|
136 (lazy-shot-install-extents font-lock-fontified))
|
|
137
|
|
138 (defun lazy-shot-unstall ()
|
|
139 ;;
|
|
140 ;; Remove the extents.
|
|
141 (map-extents
|
|
142 (lambda (e arg) (delete-extent e) nil)
|
|
143 nil nil nil nil nil 'one-shot-function 'lazy-shot-shot-function)
|
|
144 ;;
|
|
145 ;; Remove the fontification hooks.
|
|
146 (remove-hook 'after-change-functions 'lazy-shot-defer-after-change t)
|
|
147 ;;
|
|
148 ;; If Font Lock mode is still enabled, reinstall its hook.
|
|
149 (when font-lock-mode
|
|
150 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))
|
|
151
|
|
152
|
|
153 (provide 'lazy-shot)
|
|
154
|
|
155 ;;; lazy-shot.el ends here
|