annotate lisp/modes/lazy-shot.el @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents f53b5ca2e663
children 850242ba4a81
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
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
25 ;;; Synched up with: Not synched.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
26
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
27 ;;; Commentary:
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
28
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
29 ;; This versions has basic demand lock functionality. Somebody please
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
30 ;; sync further with lazy-lock v2 from FSF, customize etc.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
31 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
32 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
33 ;; Idea for the stealth lock function:
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
34 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
35 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
36 ;; On an Idle itimer
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
37 ;; Loop over all buffers with lazy-lock set
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
38 ;; mapcar-extent in the region (point) point-max for
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
39 ;; one-shot-function property
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
40 ;; If not found do the same for [point-min,point]
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
41 ;; font-lock the found region and delete the extent
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
42
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
43 ;;; Code:
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
44
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
45 (require 'font-lock)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
46
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
47 (defvar lazy-shot-mode nil)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
48
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
49
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
50 (defvar lazy-shot-step-size (* 1 124)) ;; Please test diffent sizes
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
51
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
52 ;;;###autoload
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
53 (defun lazy-shot-mode (&optional arg)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
54 "Toggle Lazy Lock mode.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
55 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
56 (interactive "P")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
57 (set (make-local-variable 'lazy-shot-mode)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
58 (and (if arg (> (prefix-numeric-value arg) 0) (not lazy-shot-mode))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
59 (cond ((and lazy-shot-mode (not font-lock-mode))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
60 ;; Turned on `lazy-shot-mode' rather than `font-lock-mode'.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
61 (let ((font-lock-support-mode 'lazy-shot-mode))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
62 (font-lock-mode t)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
63 (lazy-shot-mode
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
64 ;; Turn ourselves on.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
65 (lazy-shot-install))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
66 (t
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
67 ;; Turn ourselves off.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
68 (lazy-shot-unstall))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
69
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
70 ;;;###autoload
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
71 (defun turn-on-lazy-shot ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
72 "Unconditionally turn on Lazy Lock mode."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
73 (lazy-shot-mode t))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
74
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
75
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
76 (defun lazy-shot-shot-function (extent)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
77 "Lazy lock the extent when it has become visisble"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
78 (let ((start (extent-start-position extent))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
79 (end (extent-end-position extent))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
80 (buffer (extent-object extent)))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
81 (delete-extent extent)
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
82 (with-current-buffer buffer
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
83 (save-excursion
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
84 ;; This magic should really go into font-lock-fonity-region
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
85 (goto-char start)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
86 (unless (bolp)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
87 (beginning-of-line)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
88 (setq start (point)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
89 (goto-char end)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
90 (unless (bolp)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
91 (forward-line)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
92 (setq end (point)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
93 (display-message 'progress
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
94 (format "Lazy-shot fontifying from %s to %s in %s"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
95 start end buffer))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
96 (save-match-data
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
97 (font-lock-fontify-region start end))))))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
98
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
99 (defun lazy-shot-install-extent (spos epos &optional buffer)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
100 "Make an extent that will lazy-shot if it is displayed"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
101 (let ((extent (make-extent spos epos buffer)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
102 (when extent
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
103 (set-extent-one-shot-function extent
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
104 'lazy-shot-shot-function))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
105 extent))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
106
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
107 (defun lazy-shot-install-extents (fontifying)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
108 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
109 ;; Add hook if lazy-shot.el is deferring or is fontifying on scrolling.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
110 (when fontifying
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
111 (let ((start (point-min)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
112 (while (< start (point-max))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
113 (lazy-shot-install-extent start
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
114 (min (point-max) (+ start lazy-shot-step-size)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
115 (setq start (+ start lazy-shot-step-size))))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
116
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
117 (defun lazy-shot-install ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
118 (make-local-variable 'font-lock-fontified)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
119 (setq font-lock-fontified t)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
120 (lazy-shot-install-extents font-lock-fontified))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
121
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
122 (defun lazy-shot-unstall ()
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
123 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
124 ;; Remove the extents.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
125 (map-extents
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
126 (lambda (e arg) (delete-extent e) nil)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
127 nil nil nil nil nil 'one-shot-function 'lazy-shot-shot-function)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
128 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
129 ;; Remove the fontification hooks.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
130 (remove-hook 'after-change-functions 'lazy-shot-defer-after-change t)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
131 ;;
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
132 ;; If Font Lock mode is still enabled, reinstall its hook.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
133 (when font-lock-mode
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
134 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
135
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
136
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
137 (provide 'lazy-shot)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
138
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents:
diff changeset
139 ;;; lazy-shot.el ends here