annotate lisp/modes/lazy-shot.el @ 209:41ff10fd062f r20-4b3

Import from CVS: tag r20-4b3
author cvs
date Mon, 13 Aug 2007 10:04:58 +0200
parents e45d5e7c476e
children 78478c60bfcd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
1 ;;; lazy-shot.el --- Lazy font locking for XEmacs
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
2
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Jan Vroonhof
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
4
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
5 ;; Author: Jan Vroonhof <vroonhof@math.ethz.ch>
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
6 ;; Keywords: languages, faces
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
7
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
9
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
13 ;; any later version.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
14
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
18 ;; General Public License for more details.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
19
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
24
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
25 ;;; Synched up with: Not in FSF (mostly equivalent to lazy-lock 2.09
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
26 ;;; in FSF 20.2).
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
27
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
28 ;;; Commentary:
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
29
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
30 ;;; This is an experimental demand based font-lock implemenation. It
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
31 ;;; is almost equal in functionality and interface to lazy-lock 2.09
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
32 ;;; Does somebody really need defer-locking?
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
33 ;;;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
34 ;;; To use: put
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
35 ;;; (add-hook 'font-lock-mode-hook 'turn-on-lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
36 ;;; in .emacs (.xemacs/init.el). Do not use in combination with
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
37 ;;; lazy-lock.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
38
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
39 ;;; It is exprimental in the sense that it relies on C support from
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
40 ;;; the redisplay engine, that is experimental. The code in this file
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
41 ;;; is more or less finished. The C code support experimental because
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
42 ;;; the current design is rumoured to be ugly. Secondly because
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
43 ;;; XEmacs does actually display the "un-font-locked" parts of the
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
44 ;;; buffer first, the user notices flashing as the buffer is repainted
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
45 ;;; with color/fonts.
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
46
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
47 ;;; Code:
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
48
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
49 (require 'font-lock)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
50 (require 'itimer)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
51
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
52 (defvar lazy-shot-mode nil)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
53
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
54
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
55 (defgroup lazy-shot nil
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
56 "Lazy-shot customizations"
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
57 :group 'tools
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
58 :group 'faces
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
59 :prefix "lazy-shot-")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
60
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
61 (defcustom lazy-shot-minimum-size 0
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
62 "*Minimum size of a buffer for demand-driven fontification.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
63 On-demand fontification occurs if the buffer size is greater than this value.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
64 If nil, means demand-driven fontification is never performed."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
65 :type '(choice (const :tag "Off" nil)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
66 (integer :tag "Size"))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
67 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
68
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
69
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
70 (defcustom lazy-shot-step-size 1024 ; Please test diffent sizes
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
71 "Minimum size of each fontification shot."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
72 :type 'integer
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
73 :group 'lazy-shot)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
74
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
75 (defcustom lazy-shot-stealth-time 30
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
76 "*Time in seconds to delay before beginning stealth fontification.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
77 Stealth fontification occurs if there is no input within this time.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
78 If nil, means stealth fontification is never performed.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
79
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
80 The value of this variable is used when Lazy Shot mode is turned on."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
81 :type '(choice (const :tag "Off" nil)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
82 (number :tag "Time"))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
83 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
84
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
85 (defcustom lazy-shot-stealth-lines (if font-lock-maximum-decoration 100 250)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
86 "*Maximum size of a chunk of stealth fontification.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
87 Each iteration of stealth fontification can fontify this number of lines.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
88 To speed up input response during stealth fontification, at the cost of stealth
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
89 taking longer to fontify, you could reduce the value of this variable."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
90 :type 'integer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
91 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
92
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
93 (defcustom lazy-shot-stealth-nice
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
94 (/ (float 1) (float 8))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
95 "*Time in seconds to pause between chunks of stealth fontification.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
96 Each iteration of stealth fontification is separated by this amount of time.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
97 To reduce machine load during stealth fontification, at the cost of stealth
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
98 taking longer to fontify, you could increase the value of this variable."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
99 :type 'number
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
100 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
101
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
102 (defcustom lazy-shot-verbose (not (null font-lock-verbose))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
103 "*If non-nil, means demand fontification should show status messages."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
104 :type 'boolean
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
105 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
106
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
107 (defcustom lazy-shot-stealth-verbose (not (null lazy-shot-verbose))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
108 "*If non-nil, means stealth fontification should show status messages."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
109 :type 'boolean
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
110 :group 'lazy-shot)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
111
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
112
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
113
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
114 ;;;###autoload
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
115 (defun lazy-shot-mode (&optional arg)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
116 "Toggle Lazy Lock mode.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
117 With arg, turn Lazy Lock mode on if and only if arg is positive."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
118 (interactive "P")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
119 (let ((was-on lazy-shot-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
120 (set (make-local-variable 'lazy-shot-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
121 (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-shot-mode))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
122 (cond ((and lazy-shot-mode (not font-lock-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
123 ;; Turned on `lazy-shot-mode' rather than `font-lock-mode'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
124 (let ((font-lock-support-mode 'lazy-shot-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
125 (font-lock-mode t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
126 (lazy-shot-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
127 ;; Turn ourselves on.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
128 (lazy-shot-install))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
129 (was-on
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
130 ;; Turn ourselves off.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
131 (lazy-shot-unstall)))))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
132
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
133 (custom-add-option 'font-lock-mode-hook 'turn-on-lazy-lock)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
134
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
135 ;;;###autoload
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
136 (defun turn-on-lazy-shot ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
137 "Unconditionally turn on Lazy Lock mode."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
138 (lazy-shot-mode t))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
139
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
140 ;; Can we do something intelligent here?
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
141 ;; I would want to set-extent-end-position start on extents that
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
142 ;; only partially overlap!
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
143 (defun lazy-shot-clean-up-extents (start end)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
144 "Make sure there are no lazy-shot-extens betweeen START and END.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
145 This improves efficiency and C-g behavior."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
146 ;; Be carefull this function is typically called with inhibit-quit!
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
147 (map-extents (lambda (e b) (delete-extent e))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
148 nil start end nil 'start-and-end-in-region 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
149 'lazy-shot-redisplay-function))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
150
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
151 (defun lazy-shot-redisplay-function (extent)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
152 "Lazy lock the EXTENT when it has become visisble."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
153 (lazy-shot-lock-extent extent nil))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
154
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
155
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
156 (defun lazy-shot-lock-extent (extent stealth)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
157 "Font-lock the EXTENT. Called from redisplay-trigger functions and
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
158 stealth locking functions"
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
159 (when (extent-live-p extent)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
160 (let ((start (extent-start-position extent))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
161 (end (extent-end-position extent))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
162 (buffer (extent-object extent)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
163 (delete-extent extent)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
164 (lazy-shot-fontify-internal buffer start end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
165 (or lazy-shot-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
166 (and stealth
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
167 lazy-shot-stealth-verbose))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
168 (if stealth "stealthy " "")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
169
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
170 (defun lazy-shot-fontify-internal (buffer start end verbose message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
171 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
172 ;; Should inhibit quit here
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
173 (set-buffer buffer) ;; with-current-buffer is silly here
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
174 ;; This magic should really go into font-lock-fonity-region
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
175 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
176 (setq start (point-at-bol))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
177 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
178 (setq end (point-at-bol 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
179 (lazy-shot-clean-up-extents start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
180 ;; and a allow quit here
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
181 (if verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
182 (display-message 'progress
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
183 (format "Lazy-shot fontifying %sfrom %s to %s in %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
184 message start end buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
185 (save-match-data
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
186 (font-lock-fontify-region start end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
187
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
188 ;; Note this is suboptimal but works for now. It is not called that often.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
189 (defun lazy-shot-fontify-region (start end &optional buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
190 (lazy-shot-fontify-internal (or buffer (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
191 start end lazy-shot-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
192 "on request "))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
193
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
194 (defun lazy-shot-stealth-lock (buffer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
195 "Find an extent to lazy lock in buffer."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
196 (if (buffer-live-p buffer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
197 (with-current-buffer buffer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
198 (let ((extent t))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
199 (while (and extent (sit-for lazy-shot-stealth-nice))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
200 (setq extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
201 (or ;; First after point
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
202 (map-extents (lambda (e n) e) nil (point) nil nil nil
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
203 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
204 'lazy-shot-redisplay-function)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
205 ;; Then before it
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
206 (map-extents (lambda (e n) e) nil nil (point) nil nil
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
207 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
208 'lazy-shot-redisplay-function)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
209 (if extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
210 (lazy-shot-lock-extent extent t)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
211 (delete-itimer current-itimer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
212 (setq lazy-shot-stealth-timer nil)))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
213 (delete-itimer current-itimer)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
214
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
215 (defun lazy-shot-install-extent (spos epos &optional buffer)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
216 "Make an extent that will lazy-shot if it is displayed."
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
217 (let ((extent (make-extent spos epos buffer)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
218 (when extent
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
219 (set-extent-initial-redisplay-function extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
220 'lazy-shot-redisplay-function))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
221 extent))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
222
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
223
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
224 (defun lazy-shot-install-extents (fontifying)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
225 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
226 ;; Add hook if lazy-shot.el is deferring or is fontifying on scrolling.
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
227 (when fontifying
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
228 (let ((max (point-max))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
229 start)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
230 (save-excursion
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
231 (goto-char (point-min))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
232 (while (not (eobp))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
233 (setq start (point))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
234 (goto-char (min max (+ start lazy-shot-step-size)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
235 (forward-line 1)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
236 (lazy-shot-install-extent start (point)))))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
237
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
238 (defun lazy-shot-install-timer (fontifying)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
239 (when (and lazy-shot-stealth-time fontifying)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
240 (make-variable-buffer-local 'lazy-shot-stealth-timer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
241 (setq lazy-shot-stealth-timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
242 (start-itimer (format "lazy shot for %s" (current-buffer))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
243 'lazy-shot-stealth-lock lazy-shot-stealth-time
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
244 lazy-shot-stealth-time
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
245 t t (current-buffer)))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
246
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
247
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
248 (defun lazy-shot-install ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
249 (make-local-variable 'font-lock-fontified)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
250 (setq font-lock-fontified (and lazy-shot-minimum-size
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
251 (>= (buffer-size) lazy-shot-minimum-size)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
252 (lazy-shot-install-extents font-lock-fontified)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
253 (lazy-shot-install-timer font-lock-fontified)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
254 (add-hook 'font-lock-after-fontify-buffer-hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
255 'lazy-shot-unstall-after-fontify))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
256
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
257 ;; Kludge needed untill lazy-lock-fontify-region is more intelligent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
258 (defun lazy-shot-unstall-after-fontify ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
259 (lazy-shot-unstall 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
260
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
261 (defun lazy-shot-unstall (&optional no-fontify)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
262 ;; Stop the timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
263 (when lazy-shot-stealth-timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
264 (delete-itimer lazy-shot-stealth-timer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
265 (setq lazy-shot-stealth-timer nil))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
266 ;; Remove the extents.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
267 (map-extents
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
268 (lambda (e arg) (delete-extent e) nil)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
269 nil nil nil nil nil 'initial-redisplay-function 'lazy-shot-redisplay-function)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
270 (when (and font-lock-mode (not no-fontify))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
271 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
272 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
273 (lazy-shot-fontify-region (point-min) (point-max)))))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
274
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
275 (provide 'lazy-shot)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
276
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
277 ;;; lazy-shot.el ends here