annotate lisp/modes/lazy-shot.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 850242ba4a81
children 41ff10fd062f
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
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
25 ;;; Synched up with: Not in FSF (mostly equivalent to lazy-lock 2.06
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
26 ;;; in FSF 19.34).
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
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
31 ;;; is almost equal in functionality and interface to lazy-lock 2.06
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")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
119 (set (make-local-variable 'lazy-shot-mode)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
120 (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-shot-mode))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
121 (cond ((and lazy-shot-mode (not font-lock-mode))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
122 ;; Turned on `lazy-shot-mode' rather than `font-lock-mode'.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
123 (let ((font-lock-support-mode 'lazy-shot-mode))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
124 (font-lock-mode t)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
125 (lazy-shot-mode
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
126 ;; Turn ourselves on.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
127 (lazy-shot-install))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
128 (t
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
129 ;; Turn ourselves off.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
130 (lazy-shot-unstall))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
131
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
132 (custom-add-option 'font-lock-mode-hook 'turn-on-lazy-lock)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
133
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
134 ;;;###autoload
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
135 (defun turn-on-lazy-shot ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
136 "Unconditionally turn on Lazy Lock mode."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
137 (lazy-shot-mode t))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
138
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
139 ;; Can we do something intelligent here?
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
140 ;; I would want to set-extent-end-position start on extents that
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
141 ;; only partially overlap!
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
142 (defun lazy-shot-clean-up-extents (start end)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
143 "Make sure there are no lazy-shot-extens betweeen START and END.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
144 This improves efficiency and C-g behavior."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
145 ;; Be carefull this function is typically called with inhibit-quit!
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
146 (map-extents (lambda (e b) (delete-extent e))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
147 nil start end nil 'start-and-end-in-region 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
148 'lazy-shot-redisplay-function))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
149
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
150 (defun lazy-shot-redisplay-function (extent)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
151 "Lazy lock the EXTENT when it has become visisble."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
152 (lazy-shot-lock-extent extent nil))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
153
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
154 (defun lazy-shot-lock-extent (extent stealth)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
155 "Font-lock the EXTENT. Called from redisplay-trigger functions and
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
156 stealth locking functions"
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
157 (when (extent-live-p extent)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
158 (let ((start (extent-start-position extent))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
159 (end (extent-end-position extent))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
160 (buffer (extent-object extent)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
161 (delete-extent extent)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
162 (save-excursion
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
163 ;; Should inhibit quit here
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
164 (set-buffer buffer) ;; with-current-buffer is silly here
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
165 ;; This magic should really go into font-lock-fonity-region
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
166 (goto-char start)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
167 (setq start (point-at-bol))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
168 (goto-char end)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
169 (setq end (point-at-bol 2))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
170 (lazy-shot-clean-up-extents start end)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
171 (if (or lazy-shot-verbose (and stealth lazy-shot-stealth-verbose))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
172 (display-message 'progress
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
173 (format "Lazy-shot fontifying %sfrom %s to %s in %s"
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
174 (if stealth "stealthy " "") start end buffer)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
175 ;; and a allow quit here
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
176 (save-match-data
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
177 (font-lock-fontify-region start end))))))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
178
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
179 (defun lazy-shot-stealth-lock (buffer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
180 "Find an extent to lazy lock in buffer."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
181 (if (buffer-live-p buffer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
182 (with-current-buffer buffer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
183 (let ((extent t))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
184 (while (and extent (sit-for lazy-shot-stealth-nice))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
185 (setq extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
186 (or ;; First after point
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
187 (map-extents (lambda (e n) e) nil (point) nil nil nil
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
188 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
189 'lazy-shot-redisplay-function)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
190 ;; Then before it
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
191 (map-extents (lambda (e n) e) nil nil (point) nil nil
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
192 'initial-redisplay-function
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
193 'lazy-shot-redisplay-function)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
194 (if extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
195 (lazy-shot-lock-extent extent t)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
196 (delete-itimer current-itimer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
197 (setq lazy-shot-stealth-timer nil)))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
198 (delete-itimer current-itimer)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
199
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
200 (defun lazy-shot-install-extent (spos epos &optional buffer)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
201 "Make an extent that will lazy-shot if it is displayed."
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
202 (let ((extent (make-extent spos epos buffer)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
203 (when extent
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
204 (set-extent-initial-redisplay-function extent
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
205 'lazy-shot-redisplay-function))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
206 extent))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
207
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 195
diff changeset
208
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
209 (defun lazy-shot-install-extents (fontifying)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
210 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
211 ;; 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
212 (when fontifying
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
213 (let ((max (point-max))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
214 start)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
215 (save-excursion
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
216 (goto-char (point-min))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
217 (while (not (eobp))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
218 (setq start (point))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
219 (goto-char (min max (+ start lazy-shot-step-size)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
220 (forward-line 1)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
221 (lazy-shot-install-extent start (point)))))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
222
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
223 (defun lazy-shot-install-timer (fontifying)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
224 (when (and lazy-shot-stealth-time fontifying)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
225 (make-variable-buffer-local 'lazy-shot-stealth-timer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
226 (setq lazy-shot-stealth-timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
227 (start-itimer (format "lazy shot for %s" (current-buffer))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
228 'lazy-shot-stealth-lock lazy-shot-stealth-time
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
229 lazy-shot-stealth-time
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
230 t t (current-buffer)))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
231
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
232
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
233 (defun lazy-shot-install ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
234 (make-local-variable 'font-lock-fontified)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
235 (setq font-lock-fontified (and lazy-shot-minimum-size
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
236 (>= (buffer-size) lazy-shot-minimum-size)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
237 (lazy-shot-install-extents font-lock-fontified)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
238 (lazy-shot-install-timer font-lock-fontified))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
239
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
240 (defun lazy-shot-unstall ()
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
241 ;; Stop the timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
242 (when lazy-shot-stealth-timer
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
243 (delete-itimer lazy-shot-stealth-timer)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
244 (setq lazy-shot-stealth-timer nil))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
245 ;; Remove the extents.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
246 (map-extents
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
247 (lambda (e arg) (delete-extent e) nil)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
248 nil nil nil nil nil 'initial-redisplay-function 'lazy-shot-redisplay-function)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
249 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
250 ;; Remove the fontification hooks.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
251 (remove-hook 'after-change-functions 'lazy-shot-defer-after-change t)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
252 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
253 ;; If Font Lock mode is still enabled, reinstall its hook.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
254 (when font-lock-mode
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
255 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
256
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
257
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
258 (provide 'lazy-shot)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
259
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
260 ;;; lazy-shot.el ends here