Commit | Line | Data |
---|---|---|
14239447 | 1 | ;; allout-widgets.el --- Visually highlight allout outline structure. |
aac7a935 | 2 | |
acaf905b | 3 | ;; Copyright (C) 2005-2012 Free Software Foundation, Inc. |
aac7a935 | 4 | |
8642c216 KM |
5 | ;; Author: Ken Manheimer <ken dot manheimer at gmail...> |
6 | ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...> | |
aac7a935 KM |
7 | ;; Version: 1.0 |
8 | ;; Created: Dec 2005 | |
aac7a935 | 9 | ;; Keywords: outlines |
8642c216 | 10 | ;; Website: http://myriadicity.net/software-and-systems/craft/emacs-allout |
aac7a935 | 11 | |
66f3fe22 GM |
12 | ;; This file is part of GNU Emacs. |
13 | ||
14 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
15 | ;; it under the terms of the GNU General Public License as published by | |
16 | ;; the Free Software Foundation, either version 3 of the License, or | |
17 | ;; (at your option) any later version. | |
18 | ||
19 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ;; GNU General Public License for more details. | |
23 | ||
24 | ;; You should have received a copy of the GNU General Public License | |
25 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
26 | ||
aac7a935 KM |
27 | ;;; Commentary: |
28 | ||
29 | ;; This is an allout outline-mode add-on that highlights outline structure | |
30 | ;; with graphical widgets. | |
31 | ;; | |
32 | ;; To activate, customize `allout-widgets-auto-activation'. You can also | |
33 | ;; invoke allout-widgets-mode in a particular allout buffer. When | |
34 | ;; auto-enabled, you can inhibit widget operation in particular allout | |
35 | ;; buffers by setting the variable `allout-widgets-mode-inhibit' non-nil in | |
36 | ;; that file's buffer. Use emacs *file local variables* to generally | |
37 | ;; inhibit for a file. | |
38 | ;; | |
39 | ;; See the `allout-widgets-mode' docstring for more details. | |
40 | ;; | |
41 | ;; Info about allout and allout-widgets development are available at | |
42 | ;; http://myriadicity.net/Sundry/EmacsAllout | |
43 | ;; | |
44 | ;; The graphics include: | |
45 | ;; | |
46 | ;; - icons for item bullets, varying to distinguish whether the item either | |
47 | ;; lacks any subitems, the subitems are currently collapsed within the | |
48 | ;; item, or the item is currently expanded. | |
49 | ;; | |
50 | ;; - guide lines connecting item bullet-icons with those of their subitems. | |
51 | ;; | |
52 | ;; - cue area between the bullet-icon and the start of the body headline, | |
53 | ;; for item numbering, encryption indicator, and distinctive bullets. | |
54 | ;; | |
55 | ;; The bullet-icon and guide line graphics provide keybindings and mouse | |
56 | ;; bindings for easy outline navigation and exposure control, extending | |
57 | ;; outline hot-spot navigation (see `allout-mode' docstring for details). | |
58 | ;; | |
59 | ;; Developers note: Our use of emacs widgets is unconventional. We | |
60 | ;; decorate existing text rather than substituting for it, to | |
61 | ;; piggy-back on existing allout operation. This employs the C-coded | |
62 | ;; efficiencies of widget-apply, widget-get, and widget-put, along | |
63 | ;; with the basic object-oriented organization of widget-create, to | |
64 | ;; systematically couple overlays, graphics, and other features with | |
65 | ;; allout-governed text. | |
66 | ||
4c36be58 | 67 | ;;;_: Code (structured with comments that delineate an allout outline) |
aac7a935 KM |
68 | |
69 | ;;;_ : General Environment | |
70 | (require 'allout) | |
71 | (require 'widget) | |
72 | (require 'wid-edit) | |
73 | ||
74 | (eval-when-compile | |
75 | (progn | |
76 | (require 'overlay) | |
77 | (require 'cl) | |
78 | )) | |
79 | ||
80 | ;;;_ : internal variables needed before user-customization variables | |
81 | ;;; In order to enable activation of allout-widgets-mode via customization, | |
82 | ;;; allout-widgets-auto-activation uses a setting function. That function | |
83 | ;;; is invoked when the customization variable definition is evaluated, | |
84 | ;;; during file load, so the involved code must reside above that | |
85 | ;;; definition in the file. | |
86 | ;;;_ = allout-widgets-mode | |
87 | (defvar allout-widgets-mode nil | |
88 | "Allout mode enhanced with graphical widgets.") | |
89 | (make-variable-buffer-local 'allout-widgets-mode) | |
90 | ||
91 | ;;;_ : USER CUSTOMIZATION VARIABLES and incidental functions: | |
92 | ;;;_ > defgroup allout-widgets | |
93 | ;;;###autoload | |
94 | (defgroup allout-widgets nil | |
95 | "Allout extension that highlights outline structure graphically. | |
96 | ||
97 | Customize `allout-widgets-auto-activation' to activate allout-widgets | |
98 | with allout-mode." | |
99 | :group 'allout) | |
100 | ;;;_ > defgroup allout-widgets-developer | |
101 | (defgroup allout-widgets-developer nil | |
102 | "Settings for development of allout widgets extension." | |
103 | :group 'allout-widgets) | |
104 | ;;;_ ; some functions a bit early, for allout-auto-activation dependency: | |
105 | ;;;_ > allout-widgets-mode-enable | |
106 | (defun allout-widgets-mode-enable () | |
107 | "Enable allout-widgets-mode in allout-mode buffers. | |
108 | ||
109 | See `allout-widgets-mode-inhibit' for per-file/per-buffer | |
110 | inhibition of allout-widgets-mode." | |
111 | (add-hook 'allout-mode-off-hook 'allout-widgets-mode-off) | |
112 | (add-hook 'allout-mode-on-hook 'allout-widgets-mode-on) | |
113 | t) | |
114 | ;;;_ > allout-widgets-mode-disable | |
115 | (defun allout-widgets-mode-disable () | |
116 | "Disable allout-widgets-mode in allout-mode buffers. | |
117 | ||
118 | See `allout-widgets-mode-inhibit' for per-file/per-buffer | |
119 | inhibition of allout-widgets-mode." | |
120 | (remove-hook 'allout-mode-off-hook 'allout-widgets-mode-off) | |
121 | (remove-hook 'allout-mode-on-hook 'allout-widgets-mode-on) | |
122 | t) | |
123 | ;;;_ > allout-widgets-setup (varname value) | |
124 | ;;;###autoload | |
125 | (defun allout-widgets-setup (varname value) | |
fa463103 | 126 | "Commission or decommission allout-widgets-mode along with allout-mode. |
aac7a935 KM |
127 | |
128 | Meant to be used by customization of `allout-widgets-auto-activation'." | |
129 | (set-default varname value) | |
130 | (if allout-widgets-auto-activation | |
131 | (allout-widgets-mode-enable) | |
132 | (allout-widgets-mode-disable))) | |
133 | ;;;_ = allout-widgets-auto-activation | |
134 | ;;;###autoload | |
135 | (defcustom allout-widgets-auto-activation nil | |
136 | "Activate to enable allout icon graphics wherever allout mode is active. | |
137 | ||
138 | Also enable `allout-auto-activation' for this to take effect upon | |
139 | visiting an outline. | |
140 | ||
141 | When this is set you can disable allout widgets in select files | |
142 | by setting `allout-widgets-mode-inhibit' | |
143 | ||
144 | Instead of setting `allout-widgets-auto-activation' you can | |
145 | explicitly invoke `allout-widgets-mode' in allout buffers where | |
146 | you want allout widgets operation. | |
147 | ||
148 | See `allout-widgets-mode' for allout widgets mode features." | |
2bed3f04 | 149 | :version "24.1" |
aac7a935 KM |
150 | :type 'boolean |
151 | :group 'allout-widgets | |
152 | :set 'allout-widgets-setup | |
153 | ) | |
154 | ;; ;;;_ = allout-widgets-allow-unruly-edits | |
155 | ;; (defcustom allout-widgets-allow-unruly-edits nil | |
156 | ;; "*Control whether manual edits are restricted to maintain outline integrity. | |
157 | ||
158 | ;; When nil, manual edits must either be within an item's body or encompass | |
159 | ;; one or more items completely - eg, killing topics as entities, rather than | |
160 | ;; deleting from the middle of one to the middle of another. | |
161 | ||
162 | ;; If you only occasionally need to make unrestricted change, you can set this | |
163 | ;; variable in the specific buffer using set-variable, or just deactivate | |
164 | ;; `allout-mode' temporarily. You can customize this to always allow unruly | |
165 | ;; edits, but you will be able to create outlines that are unnavigable in | |
166 | ;; principle, and not just for allout's navigation and exposure mechanisms." | |
167 | ;; :type 'boolean | |
168 | ;; :group allout-widgets) | |
169 | ;; (make-variable-buffer-local 'allout-widgets-allow-unruly-edits) | |
170 | ;;;_ = allout-widgets-auto-activation - below, for eval-order dependencies | |
171 | ;;;_ = allout-widgets-icons-dark-subdir | |
3a00a363 | 172 | (defcustom allout-widgets-icons-dark-subdir "icons/allout-widgets/dark-bg/" |
aac7a935 | 173 | "Directory on `image-load-path' holding allout icons for dark backgrounds." |
2bed3f04 | 174 | :version "24.1" |
aac7a935 KM |
175 | :type 'string |
176 | :group 'allout-widgets) | |
177 | ;;;_ = allout-widgets-icons-light-subdir | |
3a00a363 | 178 | (defcustom allout-widgets-icons-light-subdir "icons/allout-widgets/light-bg/" |
aac7a935 | 179 | "Directory on `image-load-path' holding allout icons for light backgrounds." |
2bed3f04 | 180 | :version "24.1" |
aac7a935 KM |
181 | :type 'string |
182 | :group 'allout-widgets) | |
183 | ;;;_ = allout-widgets-icon-types | |
184 | (defcustom allout-widgets-icon-types '(xpm png) | |
185 | "File extensions for the icon graphic format types, in order of preference." | |
2bed3f04 | 186 | :version "24.1" |
aac7a935 KM |
187 | :type '(repeat symbol) |
188 | :group 'allout-widgets) | |
189 | ||
190 | ;;;_ . Decoration format | |
191 | ;;;_ = allout-widgets-theme-dark-background | |
192 | (defcustom allout-widgets-theme-dark-background "allout-dark-bg" | |
193 | "Identify the outline's icon theme to use with a dark background." | |
2bed3f04 | 194 | :version "24.1" |
aac7a935 KM |
195 | :type '(string) |
196 | :group 'allout-widgets) | |
197 | ;;;_ = allout-widgets-theme-light-background | |
198 | (defcustom allout-widgets-theme-light-background "allout-light-bg" | |
199 | "Identify the outline's icon theme to use with a light background." | |
2bed3f04 | 200 | :version "24.1" |
aac7a935 KM |
201 | :type '(string) |
202 | :group 'allout-widgets) | |
203 | ;;;_ = allout-widgets-item-image-properties-emacs | |
204 | (defcustom allout-widgets-item-image-properties-emacs | |
205 | '(:ascent center :mask (heuristic t)) | |
206 | "*Default properties item widget images in mainline Emacs." | |
2bed3f04 | 207 | :version "24.1" |
aac7a935 KM |
208 | :type 'plist |
209 | :group 'allout-widgets) | |
210 | ;;;_ = allout-widgets-item-image-properties-xemacs | |
211 | (defcustom allout-widgets-item-image-properties-xemacs | |
212 | nil | |
213 | "*Default properties item widget images in XEmacs." | |
2bed3f04 | 214 | :version "24.1" |
aac7a935 KM |
215 | :type 'plist |
216 | :group 'allout-widgets) | |
217 | ;;;_ . Developer | |
218 | ;;;_ = allout-widgets-run-unit-tests-on-load | |
219 | (defcustom allout-widgets-run-unit-tests-on-load nil | |
220 | "*When non-nil, unit tests will be run at end of loading allout-widgets. | |
221 | ||
222 | Generally, allout widgets code developers are the only ones who'll want to | |
223 | set this. | |
224 | ||
225 | \(If set, this makes it an even better practice to exercise changes by | |
226 | doing byte-compilation with a repeat count, so the file is loaded after | |
227 | compilation.) | |
228 | ||
229 | See `allout-widgets-run-unit-tests' to see what's run." | |
2bed3f04 | 230 | :version "24.1" |
aac7a935 KM |
231 | :type 'boolean |
232 | :group 'allout-widgets-developer) | |
233 | ;;;_ = allout-widgets-time-decoration-activity | |
234 | (defcustom allout-widgets-time-decoration-activity nil | |
235 | "*Retain timing info of the last cooperative redecoration. | |
236 | ||
237 | The details are retained as the value of | |
238 | `allout-widgets-last-decoration-timing'. | |
239 | ||
240 | Generally, allout widgets code developers are the only ones who'll want to | |
241 | set this." | |
2bed3f04 | 242 | :version "24.1" |
aac7a935 KM |
243 | :type 'boolean |
244 | :group 'allout-widgets-developer) | |
245 | ;;;_ = allout-widgets-hook-error-post-time 0 | |
246 | (defcustom allout-widgets-hook-error-post-time 0 | |
247 | "*Amount of time to sit showing hook error messages. | |
248 | ||
249 | 0 is minimal, or nil to not post to the message area. | |
250 | ||
251 | This is for debugging purposes." | |
2bed3f04 | 252 | :version "24.1" |
aac7a935 KM |
253 | :type 'integer |
254 | :group 'allout-widgets-developer) | |
255 | ;;;_ = allout-widgets-maintain-tally nil | |
256 | (defcustom allout-widgets-maintain-tally nil | |
257 | "*If non-nil, maintain a collection of widgets, `allout-widgets-tally'. | |
258 | ||
259 | This is for debugging purposes. | |
260 | ||
261 | The tally shows the total number of item widgets in the current | |
262 | buffer, and tracking increases as new widgets are added and | |
263 | decreases as obsolete widgets are garbage collected." | |
2bed3f04 | 264 | :version "24.1" |
aac7a935 KM |
265 | :type 'boolean |
266 | :group 'allout-widgets-developer) | |
d806ab68 | 267 | (defvar allout-widgets-tally nil |
aac7a935 KM |
268 | "Hash-table of existing allout widgets, for debugging. |
269 | ||
270 | Table is maintained iff `allout-widgets-maintain-tally' is non-nil. | |
271 | ||
272 | The table contents will be out of sync if any widgets are created | |
273 | or deleted while this variable is nil.") | |
274 | (make-variable-buffer-local 'allout-widgets-tally) | |
b8296902 | 275 | (defvar allout-widgets-mode-inhibit) ; defined below |
aac7a935 KM |
276 | ;;;_ > allout-widgets-tally-string |
277 | (defun allout-widgets-tally-string () | |
278 | "Return a string giving the number of tracked widgets, or empty string if not tracking. | |
279 | ||
280 | The string is formed for appending to the allout-mode mode-line lighter. | |
281 | ||
282 | An empty string is also returned if tracking is inhibited or | |
283 | widgets are locally inhibited. | |
284 | ||
285 | The number varies according to the evanescence of objects on a | |
286 | hash table with weak keys, so tracking of widget erasures is often delayed." | |
6b5ccddf KM |
287 | (when (and allout-widgets-maintain-tally |
288 | (not allout-widgets-mode-inhibit) | |
289 | allout-widgets-tally) | |
aac7a935 KM |
290 | (format ":%s" (hash-table-count allout-widgets-tally)))) |
291 | ;;;_ = allout-widgets-track-decoration nil | |
292 | (defcustom allout-widgets-track-decoration nil | |
293 | "*If non-nil, show cursor position of each item decoration. | |
294 | ||
295 | This is for debugging purposes, and generally set at need in a | |
296 | buffer rather than as a prevailing configuration \(but it's handy | |
297 | to publicize it by making it a customization variable\)." | |
2bed3f04 | 298 | :version "24.1" |
aac7a935 KM |
299 | :type 'boolean |
300 | :group 'allout-widgets-developer) | |
301 | (make-variable-buffer-local 'allout-widgets-track-decoration) | |
302 | ||
303 | ;;;_ : Mode context - variables, hookup, and hooks | |
304 | ;;;_ . internal mode variables | |
305 | ;;;_ , Mode activation and environment | |
306 | ;;;_ = allout-widgets-version | |
307 | (defvar allout-widgets-version "1.0" | |
308 | "Version of currently loaded allout-widgets extension.") | |
309 | ;;;_ > allout-widgets-version | |
310 | (defun allout-widgets-version (&optional here) | |
311 | "Return string describing the loaded outline version." | |
312 | (interactive "P") | |
313 | (let ((msg (concat "Allout Outline Widgets Extension v " | |
314 | allout-widgets-version))) | |
315 | (if here (insert msg)) | |
316 | (message "%s" msg) | |
317 | msg)) | |
318 | ;;;_ = allout-widgets-mode-inhibit | |
319 | (defvar allout-widgets-mode-inhibit nil | |
320 | "Inhibit `allout-widgets-mode' from activating widgets. | |
321 | ||
322 | This also inhibits automatic adjustment of widgets to track allout outline | |
323 | changes. | |
324 | ||
325 | You can use this as a file local variable setting to disable | |
326 | allout widgets enhancements in selected buffers while generally | |
327 | enabling widgets by customizing `allout-widgets-auto-activation'. | |
328 | ||
329 | In addition, you can invoked `allout-widgets-mode' allout-mode | |
330 | buffers where this is set to enable and disable widget | |
331 | enhancements, directly.") | |
332 | ;;;###autoload | |
333 | (put 'allout-widgets-mode-inhibit 'safe-local-variable | |
4f91a816 | 334 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
aac7a935 KM |
335 | (make-variable-buffer-local 'allout-widgets-mode-inhibit) |
336 | ;;;_ = allout-inhibit-body-modification-hook | |
337 | (defvar allout-inhibit-body-modification-hook nil | |
338 | "Override de-escaping of text-prefixes in item bodies during specific changes. | |
339 | ||
340 | This is used by `allout-buffer-modification-handler' to signal such changes | |
341 | to `allout-body-modification-handler', and is always reset by | |
342 | `allout-post-command-business'.") | |
343 | (make-variable-buffer-local 'allout-inhibit-body-modification-hook) | |
344 | ;;;_ = allout-widgets-icons-cache | |
345 | (defvar allout-widgets-icons-cache nil | |
346 | "Cache allout icon images, as an association list. | |
347 | ||
348 | `allout-fetch-icon-image' uses this cache transparently, keying | |
349 | images with lists containing the name of the icon directory \(as | |
350 | found on the `load-path') and the icon name. | |
351 | ||
352 | Set this variable to `nil' to empty the cache, and have it replenish from the | |
353 | filesystem.") | |
354 | ;;;_ = allout-widgets-unset-inhibit-read-only | |
355 | (defvar allout-widgets-unset-inhibit-read-only nil | |
356 | "Tell `allout-widgets-post-command-business' to unset `inhibit-read-only'. | |
357 | ||
358 | Used by `allout-graphics-modification-handler'") | |
359 | ;;;_ = allout-widgets-reenable-before-change-handler | |
360 | (defvar allout-widgets-reenable-before-change-handler nil | |
361 | "Tell `allout-widgets-post-command-business' to reequip the handler. | |
362 | ||
363 | Necessary because the handler sometimes deliberately raises an | |
364 | error, causing it to be disabled.") | |
365 | ;;;_ , State for hooks | |
366 | ;;;_ = allout-unresolved-body-mod-workroster | |
367 | (defvar allout-unresolved-body-mod-workroster (make-hash-table :size 16) | |
368 | "List of body-overlays that did before-change business but not after-change. | |
369 | ||
370 | See `allout-post-command-business' and `allout-body-modification-handler'.") | |
371 | ;;;_ = allout-structure-unruly-deletion-message | |
372 | (defvar allout-structure-unruly-deletion-message | |
373 | "Unruly edit prevented -- | |
374 | To change the bullet character: \\[allout-rebullet-current-heading] | |
375 | To promote this item: \\[allout-shift-out] | |
376 | To demote it: \\[allout-shift-in] | |
377 | To delete it and offspring: \\[allout-kill-topic] | |
378 | See \\[describe-mode] for many more options." | |
379 | "Informative message presented on improper editing of outline structure. | |
380 | ||
381 | The structure includes the guides lines, bullet, and bullet cue.") | |
382 | ;;;_ = allout-widgets-changes-record | |
383 | (defvar allout-widgets-changes-record nil | |
384 | "Record outline changes for processing by post-command hook. | |
385 | ||
386 | Entries on the list are lists whose first element is a symbol indicating | |
387 | the change type and subsequent elements are data specific to that change | |
388 | type. Specifically: | |
389 | ||
390 | 'exposure `allout-exposure-from' `allout-exposure-to' `allout-exposure-flag' | |
391 | ||
392 | The changes are recorded in reverse order, with new values pushed | |
393 | onto the front.") | |
394 | (make-variable-buffer-local 'allout-widgets-changes-record) | |
395 | ;;;_ = allout-widgets-undo-exposure-record | |
396 | (defvar allout-widgets-undo-exposure-record nil | |
397 | "Record outline undo traces for processing by post-command hook. | |
398 | ||
399 | The changes are recorded in reverse order, with new values pushed | |
400 | onto the front.") | |
401 | (make-variable-buffer-local 'allout-widgets-undo-exposure-record) | |
402 | ;;;_ = allout-widgets-last-hook-error | |
403 | (defvar allout-widgets-last-hook-error nil | |
404 | "String holding last error string, for debugging purposes.") | |
405 | ;;;_ = allout-widgets-adjust-message-length-threshold 100 | |
406 | (defvar allout-widgets-adjust-message-length-threshold 100 | |
407 | "Display \"Adjusting widgets\" message above this number of pending changes." | |
408 | ) | |
409 | ;;;_ = allout-widgets-adjust-message-size-threshold 10000 | |
410 | (defvar allout-widgets-adjust-message-size-threshold 10000 | |
411 | "Display \"Adjusting widgets\" message above this size of pending changes." | |
412 | ) | |
413 | ;;;_ = allout-doing-exposure-undo-processor nil | |
414 | (defvar allout-undo-exposure-in-progress nil | |
415 | "Maintained true during `allout-widgets-exposure-undo-processor'") | |
416 | ;;;_ , Widget-specific outline text format | |
417 | ;;;_ = allout-escaped-prefix-regexp | |
418 | (defvar allout-escaped-prefix-regexp "" | |
419 | "*Regular expression for body text that would look like an item prefix if | |
420 | not altered with an escape sequence.") | |
421 | (make-variable-buffer-local 'allout-escaped-prefix-regexp) | |
422 | ;;;_ , Widget element formatting | |
423 | ;;;_ = allout-item-icon-keymap | |
424 | (defvar allout-item-icon-keymap | |
425 | (let ((km (make-sparse-keymap))) | |
426 | (dolist (digit '("0" "1" "2" "3" | |
427 | "4" "5" "6" "7" "8" "9")) | |
428 | (define-key km digit 'digit-argument)) | |
429 | (define-key km "-" 'negative-argument) | |
430 | ;; (define-key km [(return)] 'allout-tree-expand-command) | |
431 | ;; (define-key km [(meta return)] 'allout-toggle-torso-command) | |
432 | ;; (define-key km [(down-mouse-1)] 'allout-item-button-click) | |
433 | ;; (define-key km [(down-mouse-2)] 'allout-toggle-torso-event-command) | |
434 | ;; Override underlying mouse-1 and mouse-2 bindings in icon territory: | |
435 | (define-key km [(mouse-1)] (lambda () (interactive) nil)) | |
436 | (define-key km [(mouse-2)] (lambda () (interactive) nil)) | |
437 | ||
438 | ;; Catchall, handles actual keybindings, dynamically doing keymap lookups: | |
439 | (define-key km [t] 'allout-item-icon-key-handler) | |
440 | ||
441 | km) | |
442 | "General tree-node key bindings.") | |
443 | ;;;_ = allout-item-body-keymap | |
444 | (defvar allout-item-body-keymap | |
445 | (let ((km (make-sparse-keymap)) | |
446 | (local-map (current-local-map))) | |
447 | ;; (define-key km [(control return)] 'allout-tree-expand-command) | |
448 | ;; (define-key km [(meta return)] 'allout-toggle-torso-command) | |
449 | ;; XXX We need to reset this per buffer's mode; we do so in | |
450 | ;; allout-widgets-mode. | |
451 | (if local-map | |
452 | (set-keymap-parent km local-map)) | |
453 | ||
454 | km) | |
455 | "General key bindings for the text content of outline items.") | |
456 | (make-variable-buffer-local 'allout-item-body-keymap) | |
457 | ;;;_ = allout-body-span-category | |
458 | (defvar allout-body-span-category nil | |
459 | "Symbol carrying allout body-text overlay properties.") | |
460 | ;;;_ = allout-cue-span-keymap | |
461 | (defvar allout-cue-span-keymap | |
462 | (let ((km (make-sparse-keymap))) | |
463 | (set-keymap-parent km allout-item-icon-keymap) | |
464 | km) | |
465 | "Keymap used in the item cue area - the space between the icon and headline.") | |
466 | ;;;_ = allout-escapes-category | |
467 | (defvar allout-escapes-category nil | |
468 | "Symbol for category of text property used to hide escapes of prefix-like | |
469 | text in allout item bodies.") | |
470 | ;;;_ = allout-guides-category | |
471 | (defvar allout-guides-category nil | |
472 | "Symbol carrying allout icon-guides overlay properties.") | |
473 | ;;;_ = allout-guides-span-category | |
474 | (defvar allout-guides-span-category nil | |
475 | "Symbol carrying allout icon and guide lines overlay properties.") | |
476 | ;;;_ = allout-icon-span-category | |
477 | (defvar allout-icon-span-category nil | |
478 | "Symbol carrying allout icon and guide lines overlay properties.") | |
479 | ;;;_ = allout-cue-span-category | |
480 | (defvar allout-cue-span-category nil | |
481 | "Symbol carrying common properties of the space following the outline icon. | |
482 | ||
483 | \(That space is used to convey selected cues indicating body qualities, | |
484 | including things like: | |
485 | - encryption '~' | |
486 | - numbering '#' | |
487 | - indirect reference '@' | |
488 | - distinctive bullets - see `allout-distinctive-bullets-string'.\)") | |
489 | ;;;_ = allout-span-to-category | |
490 | (defvar allout-span-to-category | |
491 | '((:guides-span . allout-guides-span-category) | |
492 | (:cue-span . allout-cue-span-category) | |
493 | (:icon-span . allout-icon-span-category) | |
494 | (:body-span . allout-body-span-category)) | |
495 | "Association list mapping span identifier to category identifier.") | |
496 | ;;;_ = allout-trailing-category | |
497 | (defvar allout-trailing-category nil | |
498 | "Symbol carrying common properties of an overlay's trailing newline.") | |
499 | ;;;_ , Developer | |
500 | (defvar allout-widgets-last-decoration-timing nil | |
501 | "Timing details for the last cooperative decoration action. | |
502 | ||
503 | This is maintained when `allout-widgets-time-decoration-activity' is set. | |
504 | ||
505 | The value is a list containing two elements: | |
506 | - the elapsed time as a number of seconds | |
507 | - the list of changes processed, a la `allout-widgets-changes-record'. | |
508 | ||
509 | When active, the value is revised each time automatic decoration activity | |
510 | happens in the buffer.") | |
511 | (make-variable-buffer-local 'allout-widgets-last-decoration-timing) | |
512 | ;;;_ . mode hookup | |
513 | ;;;_ > define-minor-mode allout-widgets-mode (arg) | |
514 | ;;;###autoload | |
515 | (define-minor-mode allout-widgets-mode | |
06e21633 CY |
516 | "Toggle Allout Widgets mode. |
517 | With a prefix argument ARG, enable Allout Widgets mode if ARG is | |
518 | positive, and disable it otherwise. If called from Lisp, enable | |
519 | the mode if ARG is omitted or nil. | |
520 | ||
521 | Allout Widgets mode is an extension of Allout mode that provides | |
522 | graphical decoration of outline structure. It is meant to | |
523 | operate along with `allout-mode', via `allout-mode-hook'. | |
aac7a935 KM |
524 | |
525 | The graphics include: | |
526 | ||
527 | - guide lines connecting item bullet-icons with those of their subitems. | |
528 | ||
529 | - icons for item bullets, varying to indicate whether or not the item | |
530 | has subitems, and if so, whether or not the item is expanded. | |
531 | ||
532 | - cue area between the bullet-icon and the start of the body headline, | |
533 | for item numbering, encryption indicator, and distinctive bullets. | |
534 | ||
535 | The bullet-icon and guide line graphics provide keybindings and mouse | |
536 | bindings for easy outline navigation and exposure control, extending | |
537 | outline hot-spot navigation \(see `allout-mode')." | |
538 | ||
539 | :lighter nil | |
540 | :keymap nil | |
541 | ||
542 | ;; define-minor-mode handles any provided argument according to emacs | |
543 | ;; minor-mode conventions - '(elisp) Minor Mode Conventions' - and sets | |
544 | ;; allout-widgets-mode accordingly *before* running the body code, so we | |
545 | ;; cue on that. | |
546 | (if allout-widgets-mode | |
547 | ;; Activating: | |
548 | (progn | |
549 | (allout-add-resumptions | |
550 | ;; XXX user may need say in line-truncation/hscrolling - an option | |
551 | ;; that abstracts mode. | |
552 | ;; truncate text lines to keep guide lines intact: | |
553 | '(truncate-lines t) | |
554 | ;; and enable autoscrolling to ease view of text | |
555 | '(auto-hscroll-mode t) | |
556 | '(line-move-ignore-fields t) | |
557 | '(widget-push-button-prefix "") | |
558 | '(widget-push-button-suffix "") | |
559 | ;; allout-escaped-prefix-regexp depends on allout-regexp: | |
560 | (list 'allout-escaped-prefix-regexp (concat "\\(\\\\\\)" | |
561 | "\\(" allout-regexp "\\)"))) | |
562 | (allout-add-resumptions | |
563 | (list 'allout-widgets-tally allout-widgets-tally) | |
564 | (list 'allout-widgets-escapes-sanitization-regexp-pair | |
565 | (list (concat "\\(\n\\|\\`\\)" | |
566 | allout-escaped-prefix-regexp | |
567 | ) | |
568 | ;; Include everything but the escape symbol. | |
569 | "\\1\\3")) | |
570 | ) | |
571 | ||
572 | (add-hook 'after-change-functions 'allout-widgets-after-change-handler | |
573 | nil t) | |
574 | ||
575 | (allout-setup-text-properties) | |
576 | (add-to-invisibility-spec '(allout-torso . t)) | |
577 | (add-to-invisibility-spec 'allout-escapes) | |
578 | ||
579 | (if (current-local-map) | |
580 | (set-keymap-parent allout-item-body-keymap (current-local-map))) | |
581 | ||
582 | (add-hook 'allout-exposure-change-hook | |
583 | 'allout-widgets-exposure-change-recorder nil 'local) | |
584 | (add-hook 'allout-structure-added-hook | |
585 | 'allout-widgets-additions-recorder nil 'local) | |
586 | (add-hook 'allout-structure-deleted-hook | |
587 | 'allout-widgets-deletions-recorder nil 'local) | |
588 | (add-hook 'allout-structure-shifted-hook | |
589 | 'allout-widgets-shifts-recorder nil 'local) | |
590 | (add-hook 'allout-after-copy-or-kill-hook | |
591 | 'allout-widgets-after-copy-or-kill-function nil 'local) | |
919d884a KM |
592 | (add-hook 'allout-post-undo-hook |
593 | 'allout-widgets-after-undo-function nil 'local) | |
aac7a935 KM |
594 | |
595 | (add-hook 'before-change-functions 'allout-widgets-before-change-handler | |
596 | nil 'local) | |
597 | (add-hook 'post-command-hook 'allout-widgets-post-command-business | |
598 | nil 'local) | |
599 | (add-hook 'pre-command-hook 'allout-widgets-pre-command-business | |
600 | nil 'local) | |
601 | ||
602 | ;; init the widgets tally for debugging: | |
603 | (if (not allout-widgets-tally) | |
604 | (setq allout-widgets-tally (make-hash-table | |
605 | :test 'eq :weakness 'key))) | |
606 | ;; add tally count display on minor-mode-alist just after | |
607 | ;; allout-mode entry. | |
608 | ;; (we use ternary condition form to keep condition simple for deletion.) | |
609 | (let* ((mode-line-entry '(allout-widgets-mode-inhibit "" | |
610 | (:eval (allout-widgets-tally-string)))) | |
611 | (associated (assoc (car mode-line-entry) minor-mode-alist)) | |
612 | ;; need location for it only if not already present: | |
613 | (after (and (not associated) | |
614 | (memq (assq 'allout-mode minor-mode-alist) minor-mode-alist)))) | |
615 | (if after | |
616 | (rplacd after (cons mode-line-entry (cdr after))))) | |
617 | (allout-widgets-prepopulate-buffer) | |
618 | t) | |
619 | ;; Deactivating: | |
620 | (let ((inhibit-read-only t) | |
621 | (was-modified (buffer-modified-p))) | |
622 | ||
623 | (allout-widgets-undecorate-region (point-min)(point-max)) | |
624 | (remove-from-invisibility-spec '(allout-torso . t)) | |
625 | (remove-from-invisibility-spec 'allout-escapes) | |
626 | ||
627 | (remove-hook 'after-change-functions | |
628 | 'allout-widgets-after-change-handler 'local) | |
629 | (remove-hook 'allout-exposure-change-hook | |
630 | 'allout-widgets-exposure-change-recorder 'local) | |
631 | (remove-hook 'allout-structure-added-hook | |
632 | 'allout-widgets-additions-recorder 'local) | |
633 | (remove-hook 'allout-structure-deleted-hook | |
634 | 'allout-widgets-deletions-recorder 'local) | |
635 | (remove-hook 'allout-structure-shifted-hook | |
636 | 'allout-widgets-shifts-recorder 'local) | |
637 | (remove-hook 'allout-after-copy-or-kill-hook | |
638 | 'allout-widgets-after-copy-or-kill-function 'local) | |
639 | (remove-hook 'before-change-functions | |
640 | 'allout-widgets-before-change-handler 'local) | |
641 | (remove-hook 'post-command-hook | |
642 | 'allout-widgets-post-command-business 'local) | |
643 | (remove-hook 'pre-command-hook | |
644 | 'allout-widgets-pre-command-business 'local) | |
645 | (assq-delete-all 'allout-widgets-mode-inhibit minor-mode-alist) | |
646 | (set-buffer-modified-p was-modified)))) | |
647 | ;;;_ > allout-widgets-mode-off | |
648 | (defun allout-widgets-mode-off () | |
649 | "Explicitly disable allout-widgets-mode." | |
650 | (allout-widgets-mode -1)) | |
651 | ;;;_ > allout-widgets-mode-off | |
652 | (defun allout-widgets-mode-on () | |
653 | "Explicitly disable allout-widgets-mode." | |
654 | (allout-widgets-mode 1)) | |
655 | ;;;_ > allout-setup-text-properties () | |
656 | (defun allout-setup-text-properties () | |
657 | "Configure category and literal text properties." | |
658 | ||
659 | ;; XXX body - before-change, entry, keymap | |
660 | ||
661 | (setplist 'allout-guides-span-category nil) | |
662 | (put 'allout-guides-span-category | |
663 | 'modification-hooks '(allout-graphics-modification-handler)) | |
664 | (put 'allout-guides-span-category 'local-map allout-item-icon-keymap) | |
665 | (put 'allout-guides-span-category 'mouse-face widget-button-face) | |
666 | (put 'allout-guides-span-category 'field 'structure) | |
667 | ;; (put 'allout-guides-span-category 'face 'widget-button) | |
668 | ||
669 | (setplist 'allout-icon-span-category | |
670 | (allout-widgets-copy-list (symbol-plist | |
671 | 'allout-guides-span-category))) | |
672 | (put 'allout-icon-span-category 'field 'structure) | |
673 | ||
674 | ;; XXX for body text we're instead going to use the buffer-wide | |
675 | ;; resources, like before/after-change-functions hooks and the | |
676 | ;; buffer's key map. that way we won't have to do painful provisions | |
677 | ;; to fixup things after edits, catch outlier interstitial | |
678 | ;; characters, like newline and empty lines after hidden subitems, | |
679 | ;; etc. | |
680 | (setplist 'allout-body-span-category nil) | |
681 | (put 'allout-body-span-category 'evaporate t) | |
682 | (put 'allout-body-span-category 'local-map allout-item-body-keymap) | |
683 | ;;(put 'allout-body-span-category | |
684 | ;; 'modification-hooks '(allout-body-modification-handler)) | |
685 | ;;(put 'allout-body-span-category 'field 'body) | |
686 | ||
687 | (setplist 'allout-cue-span-category nil) | |
688 | (put 'allout-cue-span-category 'evaporate t) | |
689 | (put 'allout-cue-span-category | |
690 | 'modification-hooks '(allout-body-modification-handler)) | |
691 | (put 'allout-cue-span-category 'local-map allout-cue-span-keymap) | |
692 | (put 'allout-cue-span-category 'mouse-face widget-button-face) | |
693 | (put 'allout-cue-span-category 'pointer 'arrow) | |
694 | (put 'allout-cue-span-category 'field 'structure) | |
695 | ||
696 | (setplist 'allout-trailing-category nil) | |
697 | (put 'allout-trailing-category 'evaporate t) | |
698 | (put 'allout-trailing-category 'local-map allout-item-body-keymap) | |
699 | ||
700 | (setplist 'allout-escapes-category nil) | |
701 | (put 'allout-escapes-category 'invisible 'allout-escapes) | |
702 | (put 'allout-escapes-category 'evaporate t)) | |
703 | ;;;_ > allout-widgets-prepopulate-buffer () | |
704 | (defun allout-widgets-prepopulate-buffer () | |
705 | "Step over the current buffers exposed items to do initial widgetizing." | |
706 | (if (not allout-widgets-mode-inhibit) | |
707 | (save-excursion | |
708 | (goto-char (point-min)) | |
709 | (while (allout-next-visible-heading 1) | |
710 | (when (not (widget-at (point))) | |
711 | (allout-get-or-create-item-widget)))))) | |
712 | ;;;_ . settings context | |
713 | ;;;_ = allout-container-item | |
714 | (defvar allout-container-item-widget nil | |
715 | "A widget for the current outline's overarching container as an item. | |
716 | ||
717 | The item has settings \(of the file/connection\) and maybe a body, but no | |
718 | icon/bullet.") | |
719 | (make-variable-buffer-local 'allout-container-item-widget) | |
720 | ;;;_ . Hooks and hook helpers | |
721 | ;;;_ , major command-loop business: | |
722 | ;;;_ > allout-widgets-pre-command-business (&optional recursing) | |
723 | (defun allout-widgets-pre-command-business (&optional recursing) | |
724 | "Handle actions pending before allout-mode activity." | |
725 | ) | |
726 | ;;;_ > allout-widgets-post-command-business (&optional recursing) | |
727 | (defun allout-widgets-post-command-business (&optional recursing) | |
728 | "Handle actions pending after any allout-mode commands. | |
729 | ||
730 | Optional RECURSING is for internal use, to limit recursion." | |
731 | ;; - check changed text for nesting discontinuities and escape anything | |
732 | ;; that's: (1) asterisks at bol or (2) excessively nested. | |
733 | (condition-case failure | |
734 | ||
735 | (when (and (boundp 'allout-mode) allout-mode) | |
736 | ||
737 | (if allout-widgets-unset-inhibit-read-only | |
738 | (setq inhibit-read-only nil | |
739 | allout-widgets-unset-inhibit-read-only nil)) | |
740 | ||
741 | (when allout-widgets-reenable-before-change-handler | |
742 | (add-hook 'before-change-functions | |
743 | 'allout-widgets-before-change-handler | |
744 | nil 'local) | |
745 | (setq allout-widgets-reenable-before-change-handler nil)) | |
746 | ||
747 | (when (or allout-widgets-undo-exposure-record | |
748 | allout-widgets-changes-record) | |
749 | (let* ((debug-on-signal t) | |
750 | (debug-on-error t) | |
751 | ;; inhibit recording new undo records when processing | |
752 | ;; effects of undo-exposure: | |
753 | (debugger 'allout-widgets-hook-error-handler) | |
754 | (adjusting-message " Adjusting widgets...") | |
755 | (replaced-message (allout-widgets-adjusting-message | |
756 | adjusting-message)) | |
757 | (start-time (current-time))) | |
758 | ||
759 | (if allout-widgets-undo-exposure-record | |
760 | ;; inhibit undo recording iff undoing exposure stuff. | |
761 | ;; XXX we might need to inhibit per respective | |
762 | ;; change-record, rather than assuming that some undo | |
763 | ;; activity during a command is all undo activity. | |
764 | (let ((buffer-undo-list t)) | |
765 | (allout-widgets-exposure-undo-processor) | |
766 | (allout-widgets-changes-dispatcher)) | |
767 | (allout-widgets-exposure-undo-processor) | |
768 | (allout-widgets-changes-dispatcher)) | |
769 | ||
770 | (if allout-widgets-time-decoration-activity | |
771 | (setq allout-widgets-last-decoration-timing | |
772 | (list (allout-elapsed-time-seconds (current-time) | |
773 | start-time) | |
774 | allout-widgets-changes-record))) | |
775 | ||
776 | (setq allout-widgets-changes-record nil) | |
777 | ||
778 | (if replaced-message | |
779 | (if (stringp replaced-message) | |
780 | (message replaced-message) | |
781 | (message ""))))) | |
782 | ||
6b5ccddf KM |
783 | ;; alas, decorated intermediate matches are not easily undecorated |
784 | ;; when they're automatically rehidden by isearch, so we're | |
785 | ;; dropping this nicety. | |
786 | ;; ;; Detect undecorated items, eg during isearch into previously | |
787 | ;; ;; unexposed topics, and decorate "economically". Some | |
788 | ;; ;; undecorated stuff is often exposed, to reduce lag, but the | |
789 | ;; ;; item containing the cursor is decorated. We constrain | |
790 | ;; ;; recursion to avoid being trapped by unexpectedly undecoratable | |
791 | ;; ;; items. | |
792 | ;; (when (and (not recursing) | |
793 | ;; (not (allout-current-decorated-p)) | |
794 | ;; (or (not (equal (allout-depth) 0)) | |
795 | ;; (not allout-container-item-widget))) | |
796 | ;; (let ((buffer-undo-list t)) | |
797 | ;; (allout-widgets-exposure-change-recorder | |
798 | ;; allout-recent-prefix-beginning allout-recent-prefix-end nil) | |
799 | ;; (allout-widgets-post-command-business 'recursing))) | |
aac7a935 KM |
800 | |
801 | ;; Detect and rectify fouled outline structure - decorated item | |
802 | ;; not at beginning of line. | |
803 | (let ((this-widget (or (widget-at (point)) | |
804 | ;; XXX we really should be checking across | |
805 | ;; edited span, not just point and point+1 | |
806 | (and (not (eq (point) (point-max))) | |
807 | (widget-at (1+ (point)))))) | |
808 | inserted-at) | |
809 | (save-excursion | |
810 | (if (and this-widget | |
811 | (goto-char (widget-get this-widget :from)) | |
812 | (not (bolp))) | |
813 | (if (not | |
814 | (condition-case err | |
815 | (yes-or-no-p | |
816 | (concat "Misplaced item won't be recognizable " | |
817 | " as part of outline - rectify? ")) | |
818 | (quit nil))) | |
819 | (progn | |
820 | (if (allout-hidden-p (max (1- (point)) 1)) | |
821 | (save-excursion | |
822 | (goto-char (max (1- (point)) 1)) | |
823 | (allout-show-to-offshoot))) | |
824 | (allout-widgets-undecorate-item this-widget)) | |
825 | ;; expose any hidden intervening items, so resulting | |
826 | ;; position is clear: | |
827 | (setq inserted-at (point)) | |
828 | (allout-unprotected (insert-before-markers "\n")) | |
829 | (forward-char -1) | |
830 | ;; ensure the inserted newline is visible: | |
831 | (allout-flag-region inserted-at (1+ inserted-at) nil) | |
832 | (allout-widgets-post-command-business 'recursing) | |
833 | (message (concat "outline structure corrected - item" | |
834 | " moved to beginning of new line")) | |
835 | ;; preserve cursor position in some cases: | |
836 | (if (and inserted-at | |
837 | (> (point) inserted-at)) | |
838 | (forward-char -1))))))) | |
839 | ||
840 | (error | |
c5e87d10 | 841 | ;; zero work list so we don't get stuck futilely retrying. |
aac7a935 KM |
842 | ;; error recording done by allout-widgets-hook-error-handler. |
843 | (setq allout-widgets-changes-record nil)))) | |
844 | ;;;_ , major change handlers: | |
845 | ;;;_ > allout-widgets-before-change-handler | |
846 | (defun allout-widgets-before-change-handler (beg end) | |
847 | "Business to be done before changes in a widgetized allout outline." | |
848 | ;; protect against unruly edits to structure: | |
849 | (cond | |
850 | (undo-in-progress (when (eq (get-text-property beg 'category) | |
851 | 'allout-icon-span-category) | |
852 | (save-excursion | |
853 | (goto-char beg) | |
854 | (let* ((item-widget (allout-get-item-widget))) | |
855 | (if item-widget | |
856 | (allout-widgets-exposure-undo-recorder | |
857 | item-widget)))))) | |
858 | (inhibit-read-only t) | |
859 | ((not (and (boundp 'allout-mode) allout-mode)) t) | |
860 | ((equal this-command 'quoted-insert) t) | |
861 | ((not (text-property-any beg (if (equal end beg) | |
862 | (min (1+ beg) (point-max)) | |
863 | end) | |
864 | 'field 'structure)) | |
865 | t) | |
866 | ((yes-or-no-p "Unruly edit of outline structure - allow? ") | |
867 | (setq allout-widgets-unset-inhibit-read-only (not inhibit-read-only) | |
868 | inhibit-read-only t)) | |
869 | (t | |
870 | ;; tell the allout-widgets-post-command-business to reestablish the hook: | |
871 | (setq allout-widgets-reenable-before-change-handler t) | |
872 | ;; and raise an error to prevent the edit (and disable the hook): | |
873 | (error | |
874 | (substitute-command-keys allout-structure-unruly-deletion-message))))) | |
875 | ;;;_ > allout-widgets-after-change-handler | |
876 | (defun allout-widgets-after-change-handler (beg end prelength) | |
877 | "Reconcile what needs to be reconciled for allout widgets after edits." | |
878 | ) | |
879 | ;;;_ > allout-current-decorated-p () | |
880 | (defun allout-current-decorated-p () | |
881 | "True if the current item is not decorated" | |
882 | (save-excursion | |
883 | (if (allout-back-to-current-heading) | |
884 | (if (> allout-recent-depth 0) | |
885 | (and (allout-get-item-widget) t) | |
886 | allout-container-item-widget)))) | |
887 | ||
888 | ;;;_ > allout-widgets-hook-error-handler | |
889 | (defun allout-widgets-hook-error-handler (mode args) | |
890 | "Process errors which occurred in the course of command hook operation. | |
891 | ||
892 | We store a backtrace of the error information in the variable, | |
893 | `allout-widgets-last-hook-error', unset the error handlers, and | |
894 | reraise the error, so that processing continues to the | |
895 | encompassing condition-case." | |
896 | ;; first deconstruct special error environment so errors here propagate | |
897 | ;; to encompassing condition-case: | |
898 | (setq debugger 'debug | |
899 | debug-on-error nil | |
900 | debug-on-signal nil) | |
901 | (let* ((bt (with-output-to-string (backtrace))) | |
902 | (this "allout-widgets-hook-error-handler") | |
903 | (header | |
904 | (format "allout-widgets-last-hook-error stored, %s/%s %s %s" | |
905 | this mode args | |
906 | (format-time-string "%e-%b-%Y %r" (current-time))))) | |
907 | ;; post to *Messages* then immediately replace with more compact notice: | |
908 | (message "%s" (setq allout-widgets-last-hook-error | |
909 | (format "%s:\n%s" header bt))) | |
910 | (message header) (sit-for allout-widgets-hook-error-post-time) | |
911 | ;; reraise the error, or one concerning this function if unexpected: | |
912 | (if (equal mode 'error) | |
913 | (apply 'signal args) | |
914 | (error "%s: unexpected mode, %s %s" this mode args)))) | |
915 | ;;;_ > allout-widgets-changes-exceed-threshold-p () | |
916 | (defun allout-widgets-adjusting-message (message) | |
917 | "Post MESSAGE when pending are likely to make a big enough delay. | |
918 | ||
919 | If posting of the MESSAGE is warranted and there already is a | |
920 | `current-message' in the minibuffer, the MESSAGE is appended to | |
921 | the current one, and the previously pending `current-message' is | |
922 | returned for later posting on completion. | |
923 | ||
924 | If posting of the MESSAGE is warranted, but no `current-message' | |
925 | is pending, then t is returned to indicate that case. | |
926 | ||
927 | If posting of the MESSAGE is not warranted, then nil is returned. | |
928 | ||
929 | See `allout-widgets-adjust-message-length-threshold', | |
930 | `allout-widgets-adjust-message-size-threshold' for message | |
931 | posting threshold criteria." | |
932 | (if (or (> (length allout-widgets-changes-record) | |
933 | allout-widgets-adjust-message-length-threshold) | |
934 | ;; for size, use distance from start of first to end of last: | |
935 | (let ((min (point-max)) | |
936 | (max 0) | |
937 | first second) | |
938 | (mapc (function (lambda (entry) | |
939 | (if (eq :undone-exposure (car entry)) | |
940 | nil | |
941 | (setq first (cadr entry) | |
942 | second (caddr entry)) | |
943 | (if (< (min first second) min) | |
944 | (setq min (min first second))) | |
945 | (if (> (max first second) max) | |
946 | (setq max (max first second)))))) | |
947 | allout-widgets-changes-record) | |
948 | (> (- max min) allout-widgets-adjust-message-size-threshold))) | |
949 | (let ((prior (current-message))) | |
950 | (message (if prior (concat prior " - " message) message)) | |
951 | (or prior t)))) | |
952 | ;;;_ > allout-widgets-changes-dispatcher () | |
953 | (defun allout-widgets-changes-dispatcher () | |
954 | "Dispatch CHANGES-RECORD items to respective widgets change processors." | |
955 | ||
956 | (if (not allout-widgets-mode-inhibit) | |
957 | (let* ((changes-record allout-widgets-changes-record) | |
958 | (changes-pending (and changes-record t)) | |
959 | entry | |
960 | exposures | |
961 | additions | |
962 | deletions | |
963 | shifts) | |
964 | ||
965 | (when changes-pending | |
966 | (while changes-record | |
967 | (setq entry (pop changes-record)) | |
968 | (case (car entry) | |
969 | (:exposed (push entry exposures)) | |
970 | (:added (push entry additions)) | |
971 | (:deleted (push entry deletions)) | |
972 | (:shifted (push entry shifts)))) | |
973 | ||
974 | (if exposures | |
975 | (allout-widgets-exposure-change-processor exposures)) | |
976 | (if additions | |
977 | (allout-widgets-additions-processor additions)) | |
978 | (if deletions | |
979 | (allout-widgets-deletions-processor deletions)) | |
980 | (if shifts | |
981 | (allout-widgets-shifts-processor shifts)))) | |
982 | (when (not (equal allout-widgets-mode-inhibit 'undecorated)) | |
983 | (allout-widgets-undecorate-region (point-min)(point-max)) | |
984 | (setq allout-widgets-mode-inhibit 'undecorated)))) | |
985 | ;;;_ > allout-widgets-exposure-change-recorder (from to flag) | |
986 | (defun allout-widgets-exposure-change-recorder (from to flag) | |
987 | "Record allout exposure changes for tracking during post-command processing. | |
988 | ||
989 | Records changes in `allout-widgets-changes-record'." | |
990 | (push (list :exposed from to flag) allout-widgets-changes-record)) | |
991 | ;;;_ > allout-widgets-exposure-change-processor (changes) | |
992 | (defun allout-widgets-exposure-change-processor (changes) | |
993 | "Widgetize and adjust item widgets tracking allout outline exposure changes. | |
994 | ||
995 | Generally invoked via `allout-exposure-change-hook'." | |
996 | ||
997 | (let ((changes (sort changes (function (lambda (this next) | |
998 | (< (cadr this) (cadr next)))))) | |
999 | ;; have to distinguish between concealing and exposing so that, eg, | |
1000 | ;; `allout-expose-topic's mix is handled properly. | |
1001 | handled-expose | |
1002 | handled-conceal | |
1003 | covered | |
1004 | deactivate-mark) | |
1005 | ||
1006 | (dolist (change changes) | |
1007 | (let (handling | |
1008 | (from (cadr change)) | |
1009 | bucket got | |
1010 | (to (caddr change)) | |
1011 | (flag (cadddr change)) | |
1012 | parent) | |
1013 | ||
1014 | ;; swap from and to: | |
1015 | (if (< to from) (setq bucket to | |
1016 | to from | |
1017 | from bucket)) | |
1018 | ||
1019 | ;; have we already handled exposure changes in this region? | |
1020 | (setq handling (if flag 'handled-conceal 'handled-expose) | |
1021 | got (allout-range-overlaps from to (symbol-value handling)) | |
1022 | covered (car got)) | |
1023 | (set handling (cadr got)) | |
1024 | ||
1025 | (when (not covered) | |
1026 | (save-excursion | |
1027 | (goto-char from) | |
1028 | (cond | |
1029 | ||
1030 | ;; collapsing: | |
1031 | (flag | |
1032 | (allout-widgets-undecorate-region from to) | |
1033 | (allout-beginning-of-current-line) | |
1034 | (let ((widget (allout-get-item-widget))) | |
1035 | (if (not widget) | |
1036 | (allout-get-or-create-item-widget) | |
1037 | (widget-apply widget :redecorate)))) | |
1038 | ||
1039 | ;; expanding: | |
1040 | (t | |
1041 | (while (< (point) to) | |
1042 | (allout-beginning-of-current-line) | |
1043 | (setq parent (allout-get-item-widget)) | |
1044 | (if (not parent) | |
1045 | (setq parent (allout-get-or-create-item-widget)) | |
1046 | (widget-apply parent :redecorate)) | |
1047 | (allout-next-visible-heading 1) | |
1048 | (if (widget-get parent :has-subitems) | |
1049 | (allout-redecorate-visible-subtree parent)) | |
1050 | (if (> (point) to) | |
1051 | ;; subtree may be well beyond to - incorporate in ranges: | |
1052 | (setq handled-expose | |
1053 | (allout-range-overlaps from (point) handled-expose) | |
1054 | covered (car handled-expose) | |
1055 | handled-expose (cadr handled-expose))) | |
1056 | (allout-next-visible-heading 1)))))))))) | |
1057 | ||
1058 | ;;;_ > allout-widgets-additions-recorder (from to) | |
1059 | (defun allout-widgets-additions-recorder (from to) | |
1060 | "Record allout item additions for tracking during post-command processing. | |
1061 | ||
1062 | Intended for use on `allout-structure-added-hook'. | |
1063 | ||
1064 | FROM point at the start of the first new item and TO is point at the start | |
1065 | of the last one. | |
1066 | ||
1067 | Records changes in `allout-widgets-changes-record'." | |
1068 | (push (list :added from to) allout-widgets-changes-record)) | |
1069 | ;;;_ > allout-widgets-additions-processor (changes) | |
1070 | (defun allout-widgets-additions-processor (changes) | |
1071 | "Widgetize and adjust items tracking allout outline structure additions. | |
1072 | ||
1073 | Dispatched by `allout-widgets-post-command-business' in response to | |
1074 | :added entries recorded by `allout-widgets-additions-recorder'." | |
1075 | (save-excursion | |
1076 | (let (handled | |
1077 | covered) | |
1078 | (dolist (change changes) | |
1079 | (let ((from (cadr change)) | |
1080 | bucket | |
1081 | (to (caddr change))) | |
1082 | (if (< to from) (setq bucket to to from from bucket)) | |
1083 | ;; have we already handled exposure changes in this region? | |
1084 | (setq handled (allout-range-overlaps from to handled) | |
1085 | covered (car handled) | |
1086 | handled (cadr handled)) | |
1087 | (when (not covered) | |
1088 | (goto-char from) | |
1089 | ;; Prior sibling and parent can both be affected. | |
1090 | (if (allout-ascend) | |
1091 | (allout-redecorate-visible-subtree | |
1092 | (allout-get-or-create-item-widget 'redecorate))) | |
1093 | (if (< (point) from) | |
1094 | (goto-char from)) | |
1095 | (while (and (< (point) to) (not (eobp))) | |
1096 | (allout-beginning-of-current-line) | |
1097 | (allout-redecorate-visible-subtree | |
1098 | (allout-get-or-create-item-widget)) | |
1099 | (allout-next-visible-heading 1)) | |
1100 | (if (> (point) to) | |
1101 | ;; subtree may be well beyond to - incorporate in ranges: | |
1102 | (setq handled (allout-range-overlaps from (point) handled) | |
1103 | covered (car handled) | |
1104 | handled (cadr handled))))))))) | |
1105 | ||
1106 | ;;;_ > allout-widgets-deletions-recorder (depth from) | |
1107 | (defun allout-widgets-deletions-recorder (depth from) | |
1108 | "Record allout item deletions for tracking during post-command processing. | |
1109 | ||
1110 | Intended for use on `allout-structure-deleted-hook'. | |
1111 | ||
1112 | DEPTH is the depth of the deleted subtree, and FROM is the point from which | |
1113 | the subtree was deleted. | |
1114 | ||
1115 | Records changes in `allout-widgets-changes-record'." | |
1116 | (push (list :deleted depth from) allout-widgets-changes-record)) | |
1117 | ;;;_ > allout-widgets-deletions-processor (changes) | |
1118 | (defun allout-widgets-deletions-processor (changes) | |
1119 | "Adjust items tracking allout outline structure deletions. | |
1120 | ||
1121 | Dispatched by `allout-widgets-post-command-business' in response to | |
1122 | :deleted entries recorded by `allout-widgets-deletions-recorder'." | |
1123 | (save-excursion | |
1124 | (dolist (change changes) | |
1125 | (let ((depth (cadr change)) | |
1126 | (from (caddr change))) | |
1127 | (goto-char from) | |
1128 | (when (allout-previous-visible-heading 1) | |
1129 | (if (> depth 1) | |
1130 | (allout-ascend-to-depth (1- depth))) | |
1131 | (allout-redecorate-visible-subtree | |
1132 | (allout-get-or-create-item-widget 'redecorate))))))) | |
1133 | ||
1134 | ;;;_ > allout-widgets-shifts-recorder (shifted-amount at) | |
1135 | (defun allout-widgets-shifts-recorder (shifted-amount at) | |
1136 | "Record outline subtree shifts for tracking during post-command processing. | |
1137 | ||
1138 | Intended for use on `allout-structure-shifted-hook'. | |
1139 | ||
1140 | SHIFTED-AMOUNT is the depth change and AT is the point at the start of the | |
1141 | subtree that's been shifted. | |
1142 | ||
1143 | Records changes in `allout-widgets-changes-record'." | |
1144 | (push (list :shifted shifted-amount at) allout-widgets-changes-record)) | |
1145 | ;;;_ > allout-widgets-shifts-processor (changes) | |
1146 | (defun allout-widgets-shifts-processor (changes) | |
1147 | "Widgetize and adjust items tracking allout outline structure additions. | |
1148 | ||
1149 | Dispatched by `allout-widgets-post-command-business' in response to | |
1150 | :shifted entries recorded by `allout-widgets-shifts-recorder'." | |
1151 | (save-excursion | |
1152 | (dolist (change changes) | |
1153 | (goto-char (caddr change)) | |
1154 | (allout-ascend) | |
1155 | (allout-redecorate-visible-subtree)))) | |
1156 | ;;;_ > allout-widgets-after-copy-or-kill-function () | |
1157 | (defun allout-widgets-after-copy-or-kill-function () | |
1158 | "Do allout-widgets processing of text just placed in the kill ring. | |
1159 | ||
1160 | Intended for use on allout-after-copy-or-kill-hook." | |
1161 | (if (car kill-ring) | |
1162 | (setcar kill-ring (allout-widgets-undecorate-text (car kill-ring))))) | |
919d884a KM |
1163 | ;;;_ > allout-widgets-after-undo-function () |
1164 | (defun allout-widgets-after-undo-function () | |
1165 | "Do allout-widgets processing of text after an undo. | |
1166 | ||
1167 | Intended for use on allout-post-undo-hook." | |
1168 | (save-excursion | |
1169 | (if (allout-goto-prefix) | |
1170 | (allout-redecorate-item (allout-get-or-create-item-widget))))) | |
aac7a935 KM |
1171 | |
1172 | ;;;_ > allout-widgets-exposure-undo-recorder (widget from-state) | |
1173 | (defun allout-widgets-exposure-undo-recorder (widget) | |
1174 | "Record outline exposure undo for tracking during post-command processing. | |
1175 | ||
1176 | Intended for use by `allout-graphics-modification-handler'. | |
1177 | ||
1178 | WIDGET is the widget being changed. | |
1179 | ||
1180 | Records changes in `allout-widgets-changes-record'." | |
1181 | ;; disregard the events if we're currently processing them. | |
1182 | (if (not allout-undo-exposure-in-progress) | |
1183 | (push widget allout-widgets-undo-exposure-record))) | |
1184 | ;;;_ > allout-widgets-exposure-undo-processor () | |
1185 | (defun allout-widgets-exposure-undo-processor () | |
1186 | "Adjust items tracking undo of allout outline structure exposure. | |
1187 | ||
1188 | Dispatched by `allout-widgets-post-command-business' in response to | |
1189 | :undone-exposure entries recorded by `allout-widgets-exposure-undo-recorder'." | |
1190 | (let* ((allout-undo-exposure-in-progress t) | |
1191 | ;; inhibit undo recording while twiddling exposure to track undo: | |
1192 | (widgets allout-widgets-undo-exposure-record) | |
1193 | widget widget-start-marker widget-end-marker | |
1194 | from-state icon-start-point to-state | |
1195 | handled covered) | |
1196 | (setq allout-widgets-undo-exposure-record nil) | |
1197 | (save-excursion | |
1198 | (dolist (widget widgets) | |
1199 | (setq widget-start-marker (widget-get widget :from) | |
1200 | widget-end-marker (widget-get widget :to) | |
1201 | from-state (widget-get widget :icon-state) | |
1202 | icon-start-point (widget-apply widget :actual-position | |
1203 | :icon-start) | |
1204 | to-state (get-text-property icon-start-point | |
1205 | :icon-state)) | |
1206 | (setq handled (allout-range-overlaps widget-start-marker | |
1207 | widget-end-marker | |
1208 | handled) | |
1209 | covered (car handled) | |
1210 | handled (cadr handled)) | |
1211 | (when (not covered) | |
1212 | (goto-char (widget-get widget :from)) | |
1213 | (when (not (allout-hidden-p)) | |
1214 | ;; adjust actual exposure to that of to-state viz from-state | |
1215 | (cond ((and (eq to-state 'closed) (eq from-state 'opened)) | |
1216 | (allout-hide-current-subtree) | |
1217 | (allout-decorate-item-and-context widget)) | |
1218 | ((and (eq to-state 'opened) (eq from-state 'closed)) | |
1219 | (save-excursion | |
1220 | (dolist | |
1221 | (expose-to (allout-chart-exposure-contour-by-icon)) | |
1222 | (goto-char expose-to) | |
1223 | (allout-show-to-offshoot))))))))))) | |
1224 | ;;;_ > allout-chart-exposure-contour-by-icon (&optional from-depth) | |
1225 | (defun allout-chart-exposure-contour-by-icon (&optional from-depth) | |
1226 | "Return points of subtree items to which exposure should be extended. | |
1227 | ||
1228 | The qualifying items are ones with a widget icon that is in the closed or | |
1229 | empty state, or items with undecorated subitems. | |
1230 | ||
1231 | The resulting list of points is in reverse order. | |
1232 | ||
1233 | Optional FROM-DEPTH is for internal use." | |
1234 | ;; During internal recursion, we return a pair: (at-end . result) | |
1235 | ;; Otherwise we just return the result. | |
1236 | (let ((from-depth from-depth) | |
1237 | start-point | |
1238 | at-end level-depth | |
1239 | this-widget | |
1240 | got subgot) | |
1241 | (if from-depth | |
1242 | (setq level-depth (allout-depth)) | |
1243 | ;; at containing item: | |
1244 | (setq start-point (point)) | |
1245 | (setq from-depth (allout-depth)) | |
1246 | (setq at-end (not (allout-next-heading)) | |
1247 | level-depth allout-recent-depth)) | |
1248 | ||
1249 | ;; traverse the level, recursing on deeper levels: | |
1250 | (while (and (not at-end) | |
1251 | (> allout-recent-depth from-depth) | |
1252 | (setq this-widget (allout-get-item-widget))) | |
1253 | (if (< level-depth allout-recent-depth) | |
1254 | ;; recurse: | |
1255 | (progn | |
1256 | (setq subgot (allout-chart-exposure-contour-by-icon level-depth) | |
1257 | at-end (car subgot) | |
1258 | subgot (cdr subgot)) | |
1259 | (if subgot (setq got (append subgot got)))) | |
1260 | ;; progress at this level: | |
1261 | (when (memq (widget-get this-widget :icon-state) '(closed empty)) | |
1262 | (push (point) got) | |
1263 | (allout-end-of-subtree)) | |
1264 | (setq at-end (not (allout-next-heading))))) | |
1265 | ||
1266 | ;; tailor result depending on whether or not we're a recursion: | |
1267 | (if (not start-point) | |
1268 | (cons at-end got) | |
1269 | (goto-char start-point) | |
1270 | got))) | |
1271 | ;;;_ > allout-range-overlaps (from to ranges) | |
1272 | (defun allout-range-overlaps (from to ranges) | |
1273 | "Return a pair indicating overlap of FROM and TO subtree range in RANGES. | |
1274 | ||
da6062e6 | 1275 | First element of result indicates whether candidate range FROM, TO |
aac7a935 KM |
1276 | overlapped any of the existing ranges. |
1277 | ||
1278 | Second element of result is a new version of RANGES incorporating the | |
1279 | candidate range with overlaps consolidated. | |
1280 | ||
1281 | FROM and TO must be in increasing order, as must be the pairs in RANGES." | |
1282 | ;; to append to the end: (rplacd next-to-last-cdr (list 'f)) | |
1283 | (let (new-ranges | |
1284 | entry | |
1285 | ;; the start of the range that includes the candidate from: | |
1286 | included-from | |
1287 | ;; the end of the range that includes the candidate to: | |
1288 | included-to | |
1289 | ;; the candidates were inserted: | |
1290 | done) | |
1291 | (while (and ranges (not done)) | |
1292 | (setq entry (car ranges) | |
1293 | ranges (cdr ranges)) | |
1294 | ||
1295 | (cond | |
1296 | ||
1297 | (included-from | |
1298 | ;; some entry included the candidate from. | |
1299 | (cond ((> (car entry) to) | |
1300 | ;; current entry exceeds end of candidate range - done. | |
1301 | (push (list included-from to) new-ranges) | |
1302 | (push entry new-ranges) | |
1303 | (setq included-to to | |
1304 | done t)) | |
1305 | ((>= (cadr entry) to) | |
1306 | ;; current entry includes end of candidate range - done. | |
1307 | (push (list included-from (cadr entry)) new-ranges) | |
1308 | (setq included-to (cadr entry) | |
1309 | done t)) | |
1310 | ;; current entry contained in candidate range - ditch, continue: | |
1311 | (t nil))) | |
1312 | ||
1313 | ((> (car entry) to) | |
1314 | ;; current entry start exceeds candidate end - done, placed as new entry | |
1315 | (push (list from to) new-ranges) | |
1316 | (push entry new-ranges) | |
1317 | (setq included-to to | |
1318 | done t)) | |
1319 | ||
1320 | ((>= (car entry) from) | |
1321 | ;; current entry start is above candidate start, but not above | |
1322 | ;; candidate end (by prior case). | |
1323 | (setq included-from from) | |
1324 | ;; now we have to check on whether this entry contains to, or continue: | |
1325 | (when (>= (cadr entry) to) | |
1326 | ;; current entry contains only candidate end - done: | |
1327 | (push (list included-from (cadr entry)) new-ranges) | |
1328 | (setq included-to (cadr entry) | |
1329 | done t)) | |
1330 | ;; otherwise, we will continue to look for placement of candidate end. | |
1331 | ) | |
1332 | ||
1333 | ((>= (cadr entry) to) | |
1334 | ;; current entry properly contains candidate range. | |
1335 | (push entry new-ranges) | |
1336 | (setq included-from (car entry) | |
1337 | included-to (cadr entry) | |
1338 | done t)) | |
1339 | ||
1340 | ((>= (cadr entry) from) | |
1341 | ;; current entry contains start of candidate range. | |
1342 | (setq included-from (car entry))) | |
1343 | ||
1344 | (t | |
1345 | ;; current entry is below the candidate range. | |
1346 | (push entry new-ranges)))) | |
1347 | ||
1348 | (cond ((and included-from included-to) | |
1349 | ;; candidates placed. | |
1350 | nil) | |
1351 | ((not (or included-from included-to)) | |
1352 | ;; candidates found no place, must be at the end: | |
1353 | (push (list from to) new-ranges)) | |
1354 | (included-from | |
1355 | ;; candidate start placed but end not: | |
1356 | (push (list included-from to) new-ranges)) | |
1357 | ;; might be included-to and not included-from, indicating new entry. | |
1358 | ) | |
1359 | (setq new-ranges (nreverse new-ranges)) | |
1360 | (if ranges (setq new-ranges (append new-ranges ranges))) | |
1361 | (list (if included-from t) new-ranges))) | |
1362 | ;;;_ > allout-test-range-overlaps () | |
1363 | (defun allout-test-range-overlaps () | |
1364 | "allout-range-overlaps unit tests." | |
1365 | (let* (ranges | |
1366 | got | |
1367 | (try (lambda (from to) | |
1368 | (setq got (allout-range-overlaps from to ranges)) | |
1369 | (setq ranges (cadr got)) | |
1370 | got))) | |
1371 | ;; ;; biggie: | |
1372 | ;; (setq ranges nil) | |
1373 | ;; ;; ~ .02 to .1 seconds for just repeated listing args instead of funcall | |
1374 | ;; ;; ~ 13 seconds for doing repeated funcall | |
1375 | ;; (message "time-trial: %s, resulting size %s" | |
1376 | ;; (time-trial | |
1377 | ;; '(let ((size 10000) | |
1378 | ;; doing) | |
1379 | ;; (random t) | |
1380 | ;; (dotimes (count size) | |
1381 | ;; (setq doing (random size)) | |
1382 | ;; (funcall try doing (+ doing (random 5))) | |
1383 | ;; ;;(list doing (+ doing (random 5))) | |
1384 | ;; ))) | |
1385 | ;; (length ranges)) | |
1386 | ;; (sit-for 2) | |
1387 | ||
1388 | ;; fresh: | |
1389 | (setq ranges nil) | |
1390 | (assert (equal (funcall try 3 5) '(nil ((3 5))))) | |
1391 | ;; add range at end: | |
1392 | (assert (equal (funcall try 10 12) '(nil ((3 5) (10 12))))) | |
1393 | ;; add range at beginning: | |
1394 | (assert (equal (funcall try 1 2) '(nil ((1 2) (3 5) (10 12))))) | |
1395 | ;; insert range somewhere in the middle: | |
1396 | (assert (equal (funcall try 7 9) '(nil ((1 2) (3 5) (7 9) (10 12))))) | |
1397 | ;; consolidate some: | |
1398 | (assert (equal (funcall try 5 8) '(t ((1 2) (3 9) (10 12))))) | |
1399 | ;; add more: | |
1400 | (assert (equal (funcall try 15 17) '(nil ((1 2) (3 9) (10 12) (15 17))))) | |
1401 | ;; add more: | |
1402 | (assert (equal (funcall try 20 22) | |
1403 | '(nil ((1 2) (3 9) (10 12) (15 17) (20 22))))) | |
1404 | ;; encompass more: | |
1405 | (assert (equal (funcall try 4 11) '(t ((1 2) (3 12) (15 17) (20 22))))) | |
1406 | ;; encompass all: | |
1407 | (assert (equal (funcall try 2 25) '(t ((1 25))))) | |
1408 | ||
1409 | ;; fresh slate: | |
1410 | (setq ranges nil) | |
1411 | (assert (equal (funcall try 20 25) '(nil ((20 25))))) | |
1412 | (assert (equal (funcall try 30 35) '(nil ((20 25) (30 35))))) | |
1413 | (assert (equal (funcall try 26 28) '(nil ((20 25) (26 28) (30 35))))) | |
1414 | (assert (equal (funcall try 15 20) '(t ((15 25) (26 28) (30 35))))) | |
1415 | (assert (equal (funcall try 10 30) '(t ((10 35))))) | |
1416 | (assert (equal (funcall try 5 6) '(nil ((5 6) (10 35))))) | |
1417 | (assert (equal (funcall try 2 100) '(t ((2 100))))) | |
1418 | ||
1419 | (setq ranges nil) | |
1420 | )) | |
1421 | ;;;_ > allout-widgetize-buffer (&optional doing) | |
1422 | (defun allout-widgetize-buffer (&optional doing) | |
1423 | "EXAMPLE FUNCTION. Widgetize items in buffer using allout-chart-subtree. | |
1424 | ||
1425 | We economize by just focusing on the first of local-maximum depth siblings. | |
1426 | ||
1427 | Optional DOING is for internal use - a chart of the current level, for | |
1428 | recursive operation." | |
1429 | ||
1430 | (interactive) | |
1431 | (if (not doing) | |
1432 | ||
1433 | (save-excursion | |
1434 | (goto-char (point-min)) | |
1435 | ;; Construct the chart by scanning the siblings: | |
1436 | (dolist (top-level-sibling (allout-chart-siblings)) | |
1437 | (goto-char top-level-sibling) | |
1438 | (let ((subchart (allout-chart-subtree))) | |
1439 | (if subchart | |
1440 | (allout-widgetize-buffer subchart))))) | |
1441 | ||
1442 | ;; save-excursion was done on recursion entry, not necessary here. | |
1443 | (let (have-sublists) | |
1444 | (dolist (sibling doing) | |
1445 | (when (listp sibling) | |
1446 | (setq have-sublists t) | |
1447 | (allout-widgetize-buffer sibling))) | |
1448 | (when (and (not have-sublists) (not (widget-at (car doing)))) | |
1449 | (goto-char (car doing)) | |
1450 | (allout-get-or-create-item-widget))))) | |
1451 | ||
1452 | ;;;_ : Item widget and constructors | |
1453 | ||
1454 | ;;;_ $ allout-item-widget | |
1455 | (define-widget 'allout-item-widget 'default | |
1456 | "A widget presenting an allout outline item." | |
1457 | ||
1458 | 'button nil | |
1459 | ;; widget-field-at respects this to get item if 'field is unused. | |
1460 | ;; we don't use field to avoid collision with end-of-line, etc, on which | |
1461 | ;; allout depends. | |
1462 | 'real-field nil | |
1463 | ||
1464 | ;; data fields: | |
1465 | ||
1466 | ||
1467 | ;; tailor the widget for a specific item | |
1468 | :create 'allout-decorate-item-and-context | |
1469 | :value-delete 'allout-widgets-undecorate-item | |
1470 | ;; Not Yet Converted (from original, tree-widget stab) | |
1471 | :expander 'allout-tree-event-dispatcher ; get children when nil :args | |
1472 | :expander-p 'identity ; always engage the :expander | |
1473 | :action 'allout-tree-widget-action | |
1474 | ;; :notify "when item changes" | |
1475 | ||
1476 | ;; force decoration of item but not context, unless already done this tick: | |
1477 | :redecorate 'allout-redecorate-item | |
1478 | :last-decorated-tick nil | |
1479 | ;; recognize the actual situation of the item's text: | |
1480 | :parse-item 'allout-parse-item-at-point | |
1481 | ;; decorate the entirety of the item, sans offspring: | |
1482 | :decorate-item-span 'allout-decorate-item-span | |
1483 | ;; decorate the various item elements: | |
1484 | :decorate-guides 'allout-decorate-item-guides | |
1485 | :decorate-icon 'allout-decorate-item-icon | |
1486 | :decorate-cue 'allout-decorate-item-cue | |
1487 | :decorate-body 'allout-decorate-item-body | |
1488 | :actual-position 'allout-item-actual-position | |
1489 | ||
1490 | ;; Layout parameters: | |
1491 | :is-container nil ; is this actually the encompassing file/connection? | |
1492 | ||
1493 | :from nil ; item beginning - marker | |
1494 | :to nil ; item end - marker | |
0b381c7e | 1495 | :span-overlay nil ; overlay by which actual position is determined |
aac7a935 KM |
1496 | |
1497 | ;; also serves as guide-end: | |
1498 | :icon-start nil | |
1499 | :icon-end nil | |
1500 | :distinctive-start nil | |
1501 | ;; also serves as cue-start: | |
1502 | :distinctive-end nil | |
1503 | ;; also serves as cue-end: | |
1504 | :body-start nil | |
1505 | :body-end nil | |
1506 | :depth nil | |
1507 | :has-subitems nil | |
1508 | :was-has-subitems 'init | |
1509 | :expanded nil | |
1510 | :was-expanded 'init | |
1511 | :brief nil | |
1512 | :was-brief 'init | |
1513 | ||
1514 | :does-encrypt nil ; pending encryption when :is-encrypted false. | |
1515 | :is-encrypted nil | |
1516 | ||
1517 | ;; the actual location of the item text: | |
1518 | :location 'allout-item-location | |
1519 | ||
1520 | :button-keymap allout-item-icon-keymap ; XEmacs | |
1521 | :keymap allout-item-icon-keymap ; Emacs | |
1522 | ||
1523 | ;; Element regions: | |
1524 | :guides-span nil | |
1525 | :icon-span nil | |
1526 | :cue-span nil | |
1527 | :bullet nil | |
1528 | :was-bullet nil | |
1529 | :body-span nil | |
1530 | ||
1531 | :body-brevity-p 'allout-body-brevity-p | |
1532 | ||
1533 | ;; :guide-column-flags indicate (in reverse order) whether or not the | |
1534 | ;; item's ancestor at the depth corresponding to the column has a | |
1535 | ;; subsequent sibling - ie, whether or not the corresponding column needs | |
1536 | ;; a descender line to connect that ancestor with its sibling. | |
1537 | :guide-column-flags nil | |
1538 | :was-guide-column-flags 'init | |
1539 | ||
1540 | ;; ie, has subitems: | |
1541 | :populous-p 'allout-item-populous-p | |
1542 | :help-echo 'allout-tree-widget-help-echo | |
1543 | ) | |
1544 | ;;;_ > allout-new-item-widget () | |
1545 | (defsubst allout-new-item-widget () | |
1546 | "create a new item widget, not yet situated anywhere." | |
1547 | (if allout-widgets-maintain-tally | |
1548 | ;; all the extra overhead is incurred only when doing the | |
1549 | ;; maintenance, except the condition, which can't be avoided. | |
1550 | (let ((widget (widget-convert 'allout-item-widget))) | |
1551 | (puthash widget nil allout-widgets-tally) | |
1552 | widget) | |
1553 | (widget-convert 'allout-item-widget))) | |
1554 | ;;;_ : Item decoration | |
1555 | ;;;_ > allout-decorate-item-and-context (item-widget &optional redecorate | |
1556 | ;;; blank-container parent) | |
1557 | (defun allout-decorate-item-and-context (item-widget &optional redecorate | |
1558 | blank-container parent) | |
1559 | "Create or adjust widget decorations for ITEM-WIDGET and neighbors at point. | |
1560 | ||
1561 | The neighbors include its siblings and parent. | |
1562 | ||
1563 | ITEM-WIDGET can be a created or converted allout-item-widget. | |
1564 | ||
1565 | If you're only trying to get or create a widget for an item, use | |
1566 | `allout-get-or-create-item-widget'. If you have the item-widget, applying | |
1567 | :redecorate will do the right thing. | |
1568 | ||
1569 | Optional BLANK-CONTAINER is for internal use. It is used to fabricate a | |
1570 | container widget for an empty-bodied container, in the course of decorating | |
1571 | a proper \(non-container\) item which starts at the beginning of the file. | |
1572 | ||
1573 | Optional REDECORATE causes redecoration of the item-widget and | |
1574 | its siblings, even if already decorated in this cycle of the command loop. | |
1575 | ||
1576 | Optional PARENT, when provided, bypasses some navigation and computation | |
1577 | necessary to obtain the parent of the items being processed. | |
1578 | ||
1579 | We return the item-widget corresponding to the item at point." | |
1580 | ||
1581 | (when (or redecorate | |
1582 | (not (equal (widget-get item-widget :last-decorated-tick) | |
1583 | allout-command-counter))) | |
1584 | (let* ((allout-inhibit-body-modification-hook t) | |
1585 | (was-modified (buffer-modified-p)) | |
1586 | (was-point (point)) | |
1587 | prefix-start | |
1588 | (is-container (or blank-container | |
1589 | (not (setq prefix-start (allout-goto-prefix))) | |
1590 | (< was-point prefix-start))) | |
1591 | ;; steady-point (set in two steps) is reliable across parent | |
1592 | ;; widget-creation. | |
1593 | (steady-point (progn (if is-container (goto-char 1)) | |
1594 | (point-marker))) | |
1595 | (steady-point (progn (set-marker-insertion-type steady-point t) | |
1596 | steady-point)) | |
1597 | (parent (and (not is-container) | |
1598 | (allout-get-or-create-parent-widget))) | |
1599 | parent-flags parent-depth | |
1600 | successor-sibling | |
1601 | body | |
1602 | doing-item | |
1603 | sub-item-widget | |
1604 | depth | |
1605 | reverse-siblings-chart | |
1606 | (buffer-undo-list t)) | |
1607 | ||
1608 | ;; At this point the parent is decorated and parent-flags indicate | |
1609 | ;; its guide lines. We will iterate over the siblings according to a | |
1610 | ;; chart we create at the start, and going from last to first so we | |
1611 | ;; don't have to worry about text displacement caused by widgetizing. | |
1612 | ||
1613 | (if is-container | |
1614 | (progn (widget-put item-widget :is-container t) | |
1615 | (setq reverse-siblings-chart (list 1))) | |
1616 | (goto-char (widget-apply parent :actual-position :from)) | |
1617 | (if (widget-get parent :is-container) | |
1618 | ;; `allout-goto-prefix' will go to first non-container item: | |
1619 | (allout-goto-prefix) | |
1620 | (allout-next-heading)) | |
1621 | (setq depth (allout-recent-depth)) | |
1622 | (setq reverse-siblings-chart (list allout-recent-prefix-beginning)) | |
1623 | (while (allout-next-sibling) | |
1624 | (push allout-recent-prefix-beginning reverse-siblings-chart))) | |
1625 | ||
1626 | (dolist (doing-at reverse-siblings-chart) | |
1627 | (goto-char doing-at) | |
1628 | (when allout-widgets-track-decoration | |
1629 | (sit-for 0)) | |
1630 | ||
1631 | (setq doing-item (if (= doing-at steady-point) | |
1632 | item-widget | |
1633 | (or (allout-get-item-widget) | |
1634 | (allout-new-item-widget)))) | |
1635 | ||
1636 | (when (or redecorate (not (equal (widget-get doing-item | |
1637 | :last-decorated-tick) | |
1638 | allout-command-counter))) | |
1639 | (widget-apply doing-item :parse-item t blank-container) | |
1640 | (widget-apply doing-item :decorate-item-span) | |
1641 | ||
1642 | (widget-apply doing-item :decorate-guides | |
1643 | parent (and successor-sibling t)) | |
1644 | (widget-apply doing-item :decorate-icon) | |
1645 | (widget-apply doing-item :decorate-cue) | |
1646 | (widget-apply doing-item :decorate-body) | |
1647 | ||
1648 | (widget-put doing-item :last-decorated-tick allout-command-counter)) | |
1649 | ||
1650 | (setq successor-sibling doing-at)) | |
1651 | ||
1652 | (set-buffer-modified-p was-modified) | |
1653 | (goto-char steady-point) | |
53964682 | 1654 | ;; must null the marker or the buffer gets clogged with impedance: |
aac7a935 KM |
1655 | (set-marker steady-point nil) |
1656 | ||
1657 | item-widget))) | |
1658 | ;;;_ > allout-redecorate-item (item) | |
1659 | (defun allout-redecorate-item (item-widget) | |
1660 | "Resituate ITEM-WIDGET decorations, disregarding context. | |
1661 | ||
09e80d9f | 1662 | Use this to redecorate only the item, when you know that its |
aac7a935 KM |
1663 | situation with respect to siblings, parent, and offspring is |
1664 | unchanged from its last decoration. Use | |
1665 | `allout-decorate-item-and-context' instead to reassess and adjust | |
9858f6c3 | 1666 | relevant context, when suitable." |
aac7a935 KM |
1667 | (if (not (equal (widget-get item-widget :last-decorated-tick) |
1668 | allout-command-counter)) | |
1669 | (let ((was-modified (buffer-modified-p)) | |
1670 | (buffer-undo-list t)) | |
1671 | (widget-apply item-widget :parse-item) | |
1672 | (widget-apply item-widget :decorate-guides) | |
1673 | (widget-apply item-widget :decorate-icon) | |
1674 | (widget-apply item-widget :decorate-cue) | |
1675 | (widget-apply item-widget :decorate-body) | |
1676 | (set-buffer-modified-p was-modified)))) | |
1677 | ;;;_ > allout-redecorate-visible-subtree (&optional parent-widget | |
1678 | ;;; depth chart) | |
1679 | (defun allout-redecorate-visible-subtree (&optional parent-widget depth chart) | |
1680 | "Redecorate all visible items in subtree at point. | |
1681 | ||
1682 | Optional PARENT-WIDGET is for optimization, when the parent | |
1683 | widget is already available. | |
1684 | ||
1685 | Optional DEPTH restricts the excursion depth of covered. | |
1686 | ||
1687 | Optional CHART is for internal recursion, to carry a chart of the | |
1688 | target items. | |
1689 | ||
1690 | Point is left at the last sibling in the visible subtree." | |
1691 | ;; using a treatment that takes care of all the siblings on a level, we | |
1692 | ;; only need apply it to the first sibling on the level, and we can | |
1693 | ;; collect and pass the parent of the lower levels to recursive calls as | |
1694 | ;; we go. | |
1695 | (let ((parent-widget | |
1696 | (if (and parent-widget (widget-apply parent-widget | |
1697 | :actual-position :from)) | |
1698 | (progn (goto-char (widget-apply parent-widget | |
1699 | :actual-position :from)) | |
1700 | parent-widget) | |
1701 | (let ((got (allout-get-item-widget))) | |
1702 | (if got | |
1703 | (allout-decorate-item-and-context got 'redecorate) | |
1704 | (allout-get-or-create-item-widget 'redecorate))))) | |
1705 | (pending-chart (or chart (allout-chart-subtree nil 'visible))) | |
1706 | item-widget | |
1707 | previous-sibling-point | |
1708 | previous-sibling | |
1709 | recent-sibling-point) | |
1710 | (setq pending-chart (nreverse pending-chart)) | |
1711 | (dolist (sibling-point pending-chart) | |
1712 | (cond ((integerp sibling-point) | |
1713 | (when (not previous-sibling-point) | |
1714 | (goto-char sibling-point) | |
1715 | (if (setq item-widget (allout-get-item-widget nil)) | |
1716 | (allout-decorate-item-and-context item-widget 'redecorate | |
1717 | nil parent-widget) | |
1718 | (allout-get-or-create-item-widget))) | |
1719 | (setq previous-sibling-point sibling-point | |
1720 | recent-sibling-point sibling-point)) | |
1721 | ((listp sibling-point) | |
1722 | (if (or (not depth) | |
1723 | (> depth 1)) | |
1724 | (allout-redecorate-visible-subtree | |
1725 | (if (not previous-sibling-point) | |
1726 | ;; containment discontinuity - sigh | |
1727 | parent-widget | |
1728 | (allout-get-or-create-item-widget 'redecorate)) | |
1729 | (if depth (1- depth)) | |
1730 | sibling-point))))) | |
1731 | (if (and recent-sibling-point (< (point) recent-sibling-point)) | |
1732 | (goto-char recent-sibling-point)))) | |
1733 | ;;;_ > allout-parse-item-at-point (item-widget &optional at-beginning | |
1734 | ;;; blank-container) | |
1735 | (defun allout-parse-item-at-point (item-widget &optional at-beginning | |
1736 | blank-container) | |
1737 | "Set widget ITEM-WIDGET layout parameters per item-at-point's actual layout. | |
1738 | ||
1739 | If optional AT-BEGINNING is t, then point is assumed to be at the start of | |
1740 | the item prefix. | |
1741 | ||
1742 | If optional BLANK-CONTAINER is true, then the parameters of a container | |
1743 | which has an empty body are set. \(Though the body is blank, the object | |
1744 | may have subitems.\)" | |
1745 | ||
1746 | ;; Uncomment this sit-for to notice where decoration is happening: | |
1747 | ;; (sit-for .1) | |
1748 | (let* ((depth (allout-depth)) | |
1749 | (depth (if blank-container 0 depth)) | |
1750 | (is-container (or blank-container (zerop depth))) | |
1751 | ||
1752 | (does-encrypt (and (not is-container) | |
1753 | (allout-encrypted-type-prefix))) | |
1754 | (is-encrypted (and does-encrypt (allout-encrypted-topic-p))) | |
1755 | (icon-end allout-recent-prefix-end) | |
1756 | (icon-start (1- icon-end)) | |
1757 | body-start | |
1758 | body-end | |
1759 | bullet | |
1760 | has-subitems | |
1761 | (contents-depth (1+ depth)) | |
1762 | ) | |
1763 | (widget-put item-widget :depth depth) | |
1764 | (if is-container | |
1765 | ||
1766 | (progn | |
1767 | (widget-put item-widget :from (allout-set-boundary-marker | |
1768 | :from (point-min) | |
1769 | (widget-get item-widget :from))) | |
1770 | (widget-put item-widget :icon-end nil) | |
1771 | (widget-put item-widget :icon-start nil) | |
1772 | (setq body-start (widget-put item-widget :body-start 1))) | |
1773 | ||
1774 | ;; not container: | |
1775 | ||
1776 | (widget-put item-widget :from (allout-set-boundary-marker | |
1777 | :from (if at-beginning | |
1778 | (point) | |
1779 | allout-recent-prefix-beginning) | |
1780 | (widget-get item-widget :from))) | |
1781 | (widget-put item-widget :icon-start icon-start) | |
1782 | (widget-put item-widget :icon-end icon-end) | |
1783 | (when does-encrypt | |
1784 | (widget-put item-widget :does-encrypt t) | |
1785 | (widget-put item-widget :is-encrypted is-encrypted)) | |
1786 | ||
1787 | ;; cue area: | |
1788 | (setq body-start icon-end) | |
1789 | (widget-put item-widget :bullet (setq bullet (allout-get-bullet))) | |
1790 | (if (equal (char-after body-start) ? ) | |
1791 | (setq body-start (1+ body-start))) | |
1792 | (widget-put item-widget :body-start body-start) | |
1793 | ) | |
1794 | ||
1795 | ;; Both container and regular items: | |
1796 | ||
1797 | ;; :body-end (doesn't include a trailing blank line, if any) - | |
1798 | (widget-put item-widget :body-end (setq body-end | |
1799 | (if blank-container | |
1800 | 1 | |
1801 | (allout-end-of-entry)))) | |
1802 | ||
1803 | (widget-put item-widget :to (allout-set-boundary-marker | |
1804 | :to (if blank-container | |
1805 | (point-min) | |
1806 | (or (allout-pre-next-prefix) | |
1807 | (goto-char (point-max)))) | |
1808 | (widget-get item-widget :to))) | |
1809 | (widget-put item-widget :has-subitems | |
1810 | (setq has-subitems | |
1811 | (and | |
1812 | ;; has a subsequent item: | |
1813 | (not (= body-end (point-max))) | |
1814 | ;; subsequent item is deeper: | |
1815 | (< depth (setq contents-depth (allout-recent-depth)))))) | |
1816 | ;; note :expanded - true if widget item's content is currently visible? | |
1817 | (widget-put item-widget :expanded | |
1818 | (and has-subitems | |
1819 | ;; subsequent item is or isn't visible: | |
1820 | (save-excursion | |
1821 | (goto-char allout-recent-prefix-beginning) | |
1822 | (not (allout-hidden-p))))))) | |
1823 | ;;;_ > allout-set-boundary-marker (boundary position &optional current-marker) | |
1824 | (defun allout-set-boundary-marker (boundary position &optional current-marker) | |
1825 | "Set or create item widget BOUNDARY type marker at POSITION. | |
1826 | ||
1827 | Optional CURRENT-MARKER is the marker currently being used for | |
1828 | the boundary, if any. | |
1829 | ||
1830 | BOUNDARY type is either :from or :to, determining the marker insertion type." | |
1831 | (if (not position) (setq position (point))) | |
1832 | (if current-marker | |
1833 | (set-marker current-marker position) | |
1834 | (let ((marker (make-marker))) | |
1835 | ;; XXX dang - would like for :from boundary to advance after inserted | |
1836 | ;; text, but that would omit new header prefixes when allout | |
1837 | ;; relevels, etc. this competes with ad-hoc edits, which would | |
1838 | ;; better be omitted | |
1839 | (set-marker-insertion-type marker nil) | |
1840 | (set-marker marker position)))) | |
1841 | ;;;_ > allout-decorate-item-span (item-widget) | |
1842 | (defun allout-decorate-item-span (item-widget) | |
1843 | "Equip the item with a span, as an entirety. | |
1844 | ||
1845 | This span is implemented so it can be used to detect displacement | |
1846 | of the widget in absolute terms, and provides an offset bias for | |
1847 | the various element spans." | |
1848 | ||
1849 | (if (and (widget-get item-widget :is-container) | |
1850 | ;; the only case where the span could be empty. | |
1851 | (eq (widget-get item-widget :from) | |
1852 | (widget-get item-widget :to))) | |
1853 | nil | |
1854 | (allout-item-span item-widget | |
1855 | (widget-get item-widget :from) | |
1856 | (widget-get item-widget :to)))) | |
1857 | ;;;_ > allout-decorate-item-guides (item-widget | |
1858 | ;;; &optional parent-widget has-successor) | |
1859 | (defun allout-decorate-item-guides (item-widget | |
1860 | &optional parent-widget has-successor) | |
1861 | "Add ITEM-WIDGET guide icon-prefix descender and connector text properties. | |
1862 | ||
1863 | Optional arguments provide context for deriving the guides. In | |
1864 | their absence, the current guide column flags are used. | |
1865 | ||
1866 | Optional PARENT-WIDGET is the widget for the item's parent item. | |
1867 | ||
1868 | Optional HAS-SUCCESSOR is true iff the item is followed by a sibling. | |
1869 | ||
1870 | We also hide the header-prefix string. | |
1871 | ||
1872 | Guides are established according to the item-widget's :guide-column-flags, | |
1873 | when different than :was-guide-column-flags. Changing that property and | |
1874 | reapplying this method will rectify the glyphs." | |
1875 | ||
1876 | (when (not (widget-get item-widget :is-container)) | |
1877 | (let* ((depth (widget-get item-widget :depth)) | |
1878 | (parent-depth (and parent-widget | |
1879 | (widget-get parent-widget :depth))) | |
1880 | (parent-flags (and parent-widget | |
1881 | (widget-get parent-widget :guide-column-flags))) | |
1882 | (parent-flags-depth (length parent-flags)) | |
1883 | (extender-length (- depth (+ parent-flags-depth 2))) | |
1884 | (flags (or (and (> depth 1) | |
1885 | parent-widget | |
1886 | (widget-put item-widget :guide-column-flags | |
1887 | (append (list has-successor) | |
1888 | (if (< 0 extender-length) | |
1889 | (make-list extender-length | |
1890 | '-)) | |
1891 | parent-flags))) | |
1892 | (widget-get item-widget :guide-column-flags))) | |
1893 | (was-flags (widget-get item-widget :was-guide-column-flags)) | |
1894 | (guides-start (widget-get item-widget :from)) | |
1895 | (guides-end (widget-get item-widget :icon-start)) | |
1896 | (position guides-start) | |
1897 | (increment (length allout-header-prefix)) | |
1898 | reverse-flags | |
1899 | guide-name | |
1900 | extenders paint-extenders | |
1901 | (inhibit-read-only t)) | |
1902 | ||
1903 | (when (not (equal was-flags flags)) | |
1904 | ||
1905 | (setq reverse-flags (reverse flags)) | |
1906 | (while reverse-flags | |
1907 | (setq guide-name | |
1908 | (cond ((null (cdr reverse-flags)) | |
1909 | (if (car reverse-flags) | |
1910 | 'mid-connector | |
1911 | 'end-connector)) | |
1912 | ((eq (car reverse-flags) '-) | |
1913 | ;; accumulate extenders tally, to be painted on next | |
1914 | ;; non-extender flag, according to the flag type. | |
1915 | (setq extenders (1+ (or extenders 0))) | |
1916 | nil) | |
1917 | ((car reverse-flags) | |
1918 | 'through-descender) | |
1919 | (t 'skip-descender))) | |
1920 | (when guide-name | |
1921 | (put-text-property position (setq position (+ position increment)) | |
1922 | 'display (allout-fetch-icon-image guide-name)) | |
1923 | (if (> increment 1) (setq increment 1)) | |
1924 | (when extenders | |
1925 | ;; paint extenders after a connector, else leave spaces. | |
1926 | (dotimes (i extenders) | |
1927 | (put-text-property | |
1928 | position (setq position (1+ position)) | |
1929 | 'display (allout-fetch-icon-image | |
1930 | (if (memq guide-name '(mid-connector end-connector)) | |
1931 | 'extender-connector | |
1932 | 'skip-descender)))) | |
1933 | (setq extenders nil))) | |
1934 | (setq reverse-flags (cdr reverse-flags))) | |
1935 | (widget-put item-widget :was-guide-column-flags flags)) | |
1936 | ||
1937 | (allout-item-element-span-is item-widget :guides-span | |
1938 | guides-start guides-end)))) | |
1939 | ;;;_ > allout-decorate-item-icon (item-widget) | |
1940 | (defun allout-decorate-item-icon (item-widget) | |
1941 | "Add item icon glyph and distinctive bullet text properties to ITEM-WIDGET." | |
1942 | ||
1943 | (when (not (widget-get item-widget :is-container)) | |
1944 | (let* ((icon-start (widget-get item-widget :icon-start)) | |
1945 | (icon-end (widget-get item-widget :icon-end)) | |
1946 | (bullet (widget-get item-widget :bullet)) | |
1947 | (use-bullet bullet) | |
1948 | (was-bullet (widget-get item-widget :was-bullet)) | |
1949 | (distinctive (allout-distinctive-bullet bullet)) | |
1950 | (distinctive-start (widget-get item-widget :distinctive-start)) | |
1951 | (distinctive-end (widget-get item-widget :distinctive-end)) | |
1952 | (does-encrypt (widget-get item-widget :does-encrypt)) | |
1953 | (is-encrypted (and does-encrypt (widget-get item-widget | |
1954 | :is-encrypted))) | |
1955 | (expanded (widget-get item-widget :expanded)) | |
1956 | (has-subitems (widget-get item-widget :has-subitems)) | |
1957 | (inhibit-read-only t) | |
1958 | icon-state) | |
1959 | ||
1960 | (when (not (and (equal (widget-get item-widget :was-expanded) expanded) | |
1961 | (equal (widget-get item-widget :was-has-subitems) | |
1962 | has-subitems) | |
1963 | (equal (widget-get item-widget :was-does-encrypt) | |
1964 | does-encrypt) | |
1965 | (equal (widget-get item-widget :was-is-encrypted) | |
1966 | is-encrypted))) | |
1967 | ||
1968 | (setq icon-state | |
1969 | (cond (does-encrypt (if is-encrypted | |
3a00a363 KM |
1970 | 'locked-encrypted |
1971 | 'unlocked-encrypted)) | |
aac7a935 KM |
1972 | (expanded 'opened) |
1973 | (has-subitems 'closed) | |
1974 | (t 'empty))) | |
1975 | (put-text-property icon-start (1+ icon-start) | |
1976 | 'display (allout-fetch-icon-image icon-state)) | |
1977 | (widget-put item-widget :was-expanded expanded) | |
1978 | (widget-put item-widget :was-has-subitems has-subitems) | |
1979 | (widget-put item-widget :was-does-encrypt does-encrypt) | |
1980 | (widget-put item-widget :was-is-encrypted is-encrypted) | |
1981 | ;; preserve as a widget property to track last known: | |
1982 | (widget-put item-widget :icon-state icon-state) | |
1983 | ;; preserve as a text property to track undo: | |
1984 | (put-text-property icon-start icon-end :icon-state icon-state)) | |
1985 | (allout-item-element-span-is item-widget :icon-span | |
1986 | icon-start icon-end) | |
1987 | (when (not (string= was-bullet bullet)) | |
1988 | (cond ((not distinctive) | |
1989 | ;; XXX we strip the prior properties without even checking if | |
1990 | ;; the prior bullet was distinctive, because the widget | |
1991 | ;; provisions to convey that info is disappearing, sigh. | |
1992 | (remove-text-properties icon-end (1+ icon-end) '(display)) | |
1993 | (setq distinctive-start icon-end distinctive-end icon-end) | |
1994 | (widget-put item-widget :distinctive-start distinctive-start) | |
1995 | (widget-put item-widget :distinctive-end distinctive-end)) | |
1996 | ||
1997 | ((not (string= bullet allout-numbered-bullet)) | |
1998 | (setq distinctive-start icon-end distinctive-end (+ icon-end 1))) | |
1999 | ||
2000 | (does-encrypt | |
2001 | (setq distinctive-start icon-end distinctive-end (+ icon-end 1))) | |
2002 | ||
2003 | (t | |
2004 | (goto-char icon-end) | |
2005 | (looking-at "[0-9]+") | |
2006 | (setq use-bullet (buffer-substring icon-end (match-end 0))) | |
2007 | (setq distinctive-start icon-end | |
2008 | distinctive-end (match-end 0)))) | |
2009 | (put-text-property distinctive-start distinctive-end 'display | |
2010 | use-bullet) | |
2011 | (widget-put item-widget :was-bullet bullet) | |
2012 | (widget-put item-widget :distinctive-start distinctive-start) | |
2013 | (widget-put item-widget :distinctive-end distinctive-end))))) | |
2014 | ;;;_ > allout-decorate-item-cue (item-widget) | |
2015 | (defun allout-decorate-item-cue (item-widget) | |
2016 | "Incorporate space between bullet icon and body to the ITEM-WIDGET." | |
2017 | ;; NOTE: most of the cue-area | |
2018 | ||
2019 | (when (not (widget-get item-widget :is-container)) | |
2020 | (let* ((cue-start (or (widget-get item-widget :distinctive-end) | |
2021 | (widget-get item-widget :icon-end))) | |
2022 | (body-start (widget-get item-widget :body-start)) | |
2023 | (expanded (widget-get item-widget :expanded)) | |
2024 | (has-subitems (widget-get item-widget :has-subitems)) | |
2025 | (inhibit-read-only t)) | |
2026 | ||
2027 | (allout-item-element-span-is item-widget :cue-span cue-start body-start) | |
2028 | (put-text-property (1- body-start) body-start 'rear-nonsticky t)))) | |
2029 | ;;;_ > allout-decorate-item-body (item-widget &optional force) | |
2030 | (defun allout-decorate-item-body (item-widget &optional force) | |
2031 | "Incorporate item body text as part the ITEM-WIDGET. | |
2032 | ||
2033 | Optional FORCE means force reassignment of the region property." | |
2034 | ||
2035 | (let* ((allout-inhibit-body-modification-hook t) | |
2036 | (body-start (widget-get item-widget :body-start)) | |
2037 | (body-end (widget-get item-widget :body-end)) | |
2038 | (body-text-end body-end) | |
2039 | (inhibit-read-only t)) | |
2040 | ||
2041 | (allout-item-element-span-is item-widget :body-span | |
2042 | body-start (min (1+ body-end) (point-max)) | |
2043 | force))) | |
2044 | ;;;_ > allout-item-actual-position (item-widget field) | |
2045 | (defun allout-item-actual-position (item-widget field) | |
2046 | "Return ITEM-WIDGET FIELD position taking item displacement into account." | |
2047 | ||
2048 | ;; The item's sub-element positions (:icon-end, :body-start, etc) are | |
2049 | ;; accurate when the item is parsed, but some offsets from the start | |
2050 | ;; drift with text added in the body. | |
2051 | ;; | |
2052 | ;; Rather than reparse an item with every change (inefficient), or derive | |
2053 | ;; every position from a distinct field marker/overlay (prohibitive as | |
2054 | ;; the number of items grows), we use the displacement tracking of the | |
2055 | ;; :span-overlay's markers, against the registered :from or :body-end | |
2056 | ;; (depending on whether the requested field value is before or after the | |
2057 | ;; item body), to bias the registered values. | |
2058 | ;; | |
2059 | ;; This is not necessary/useful when the item is being decorated, because | |
0d327994 | 2060 | ;; that always must be preceded by a fresh item parse. |
aac7a935 KM |
2061 | |
2062 | (if (not (eq field :body-end)) | |
2063 | (widget-get item-widget :from) | |
2064 | ||
2065 | (let* ((span-overlay (widget-get item-widget :span-overlay)) | |
2066 | (body-end-position (widget-get item-widget :body-end)) | |
2067 | (ref-marker-position (and span-overlay | |
2068 | (overlay-end span-overlay))) | |
2069 | (offset (and body-end-position span-overlay | |
2070 | (- (or ref-marker-position 0) | |
2071 | body-end-position)))) | |
2072 | (+ (widget-get item-widget field) (or offset 0))))) | |
2073 | ;;;_ : Item undecoration | |
2074 | ;;;_ > allout-widgets-undecorate-region (start end) | |
2075 | (defun allout-widgets-undecorate-region (start end) | |
2076 | "Eliminate widgets and decorations for all items in region from START to END." | |
2077 | (let ((next start) | |
2078 | widget) | |
2079 | (save-excursion | |
2080 | (goto-char start) | |
2081 | (while (< (setq next (next-single-char-property-change next | |
2082 | 'display | |
2083 | (current-buffer) | |
2084 | end)) | |
2085 | end) | |
2086 | (goto-char next) | |
2087 | (when (setq widget (allout-get-item-widget)) | |
2088 | ;; if the next-property/overly progression got us to a widget: | |
2089 | (allout-widgets-undecorate-item widget t)))))) | |
2090 | ;;;_ > allout-widgets-undecorate-text (text) | |
2091 | (defun allout-widgets-undecorate-text (text) | |
2092 | "Eliminate widgets and decorations for all items in TEXT." | |
2093 | (remove-text-properties 0 (length text) | |
2094 | '(display nil :icon-state nil rear-nonsticky nil | |
2095 | category nil button nil field nil) | |
2096 | text) | |
2097 | text) | |
2098 | ;;;_ > allout-widgets-undecorate-item (item-widget &optional no-expose) | |
2099 | (defun allout-widgets-undecorate-item (item-widget &optional no-expose) | |
2100 | "Remove widget decorations from ITEM-WIDGET. | |
2101 | ||
2102 | Any concealed content head lines and item body is exposed, unless | |
2103 | optional NO-EXPOSE is non-nil." | |
2104 | (let ((from (widget-get item-widget :from)) | |
2105 | (to (widget-get item-widget :to)) | |
2106 | (text-properties-to-remove '(display nil | |
2107 | :icon-state nil | |
2108 | rear-nonsticky nil | |
2109 | category nil | |
2110 | button nil | |
2111 | field nil)) | |
2112 | (span-overlay (widget-get item-widget :span-overlay)) | |
2113 | (button-overlay (widget-get item-widget :button)) | |
2114 | (was-modified (buffer-modified-p)) | |
2115 | (buffer-undo-list t) | |
2116 | (inhibit-read-only t)) | |
2117 | (if (not no-expose) | |
2118 | (allout-flag-region from to nil)) | |
2119 | (allout-unprotected | |
2120 | (remove-text-properties from to text-properties-to-remove)) | |
2121 | (when span-overlay | |
2122 | (delete-overlay span-overlay) (widget-put item-widget :span-overlay nil)) | |
2123 | (when button-overlay | |
2124 | (delete-overlay button-overlay) (widget-put item-widget :button nil)) | |
2125 | (set-marker from nil) | |
2126 | (set-marker to nil) | |
2127 | (if (not was-modified) | |
2128 | (set-buffer-modified-p nil)))) | |
2129 | ||
2130 | ;;;_ : Item decoration support | |
2131 | ;;;_ > allout-item-span (item-widget &optional start end) | |
2132 | (defun allout-item-span (item-widget &optional start end) | |
2133 | "Return or register the location of an ITEM-WIDGET's actual START and END. | |
2134 | ||
2135 | If START and END are not passed in, return either a dotted pair | |
2136 | of the current span, if established, or nil if not yet set. | |
2137 | ||
2138 | When the START and END are passed, return the distance that the | |
2139 | start of the item moved. We return 0 if the span was not | |
2140 | previously established or is not moved." | |
2141 | (let ((overlay (widget-get item-widget :span-overlay)) | |
2142 | was-start was-end | |
2143 | changed) | |
2144 | (cond ((not overlay) (when start | |
2145 | (setq overlay (make-overlay start end nil t nil)) | |
2146 | (overlay-put overlay 'button item-widget) | |
d806ab68 | 2147 | (overlay-put overlay 'evaporate t) |
aac7a935 KM |
2148 | (widget-put item-widget :span-overlay overlay) |
2149 | t)) | |
2150 | ;; report: | |
2151 | ((not start) (cons (overlay-start overlay) (overlay-end overlay))) | |
2152 | ;; move: | |
2153 | ((or (not (equal (overlay-start overlay) start)) | |
2154 | (not (equal (overlay-end overlay) end))) | |
2155 | (move-overlay overlay start end) | |
2156 | t) | |
2157 | ;; specified span already set: | |
2158 | (t nil)))) | |
2159 | ;;;_ > allout-item-element-span-is (item-widget element | |
2160 | ;;; &optional start end force) | |
2161 | (defun allout-item-element-span-is (item-widget element | |
2162 | &optional start end force) | |
2163 | "Return or register the location of the indicated ITEM-WIDGET ELEMENT. | |
2164 | ||
2165 | ELEMENT is one of :guides-span, :icon-span, :cue-span, or :body-span. | |
2166 | ||
2167 | When optional START is specified, optional END must also be. | |
2168 | ||
2169 | START and END are the actual bounds of the region, if provided. | |
2170 | ||
2171 | If START and END are not passed in, we return either a dotted | |
2172 | pair of the current span, if established, or nil if not yet set. | |
2173 | ||
2174 | When the START and END are passed, we return t if the region | |
2175 | changed or nil if not. | |
2176 | ||
2177 | Optional FORCE means force assignment of the region's text | |
2178 | property, even if it's already set." | |
2179 | (let ((span (widget-get item-widget element))) | |
2180 | (cond ((or (not span) force) | |
2181 | (when start | |
2182 | (widget-put item-widget element (cons start end)) | |
2183 | (put-text-property start end 'category | |
2184 | (cdr (assoc element | |
2185 | allout-span-to-category))) | |
2186 | t)) | |
2187 | ;; report: | |
2188 | ((not start) span) | |
2189 | ;; move if necessary: | |
2190 | ((not (and (eq (car span) start) | |
2191 | (eq (cdr span) end))) | |
2192 | (widget-put item-widget element span) | |
2193 | t) | |
2194 | ;; specified span already set: | |
2195 | (t nil)))) | |
2196 | ;;;_ : Item widget retrieval (/ high-level creation): | |
2197 | ;;;_ > allout-get-item-widget (&optional container) | |
2198 | (defun allout-get-item-widget (&optional container) | |
2199 | "Return the widget for the item at point, or nil if no widget yet exists. | |
2200 | ||
2201 | Point must be situated *before* the start of the target item's | |
2202 | body, so we don't get an existing containing item when we're in | |
2203 | the process of creating an item in the middle of another. | |
2204 | ||
2205 | Optional CONTAINER is used to obtain the container item." | |
2206 | (if (or container (zerop (allout-depth))) | |
2207 | allout-container-item-widget | |
2208 | ;; allout-recent-* are calibrated by (allout-depth) if we got here. | |
2209 | (let ((got (widget-at allout-recent-prefix-beginning))) | |
2210 | (if (and got (listp got)) | |
2211 | (if (marker-position (widget-get got :from)) | |
2212 | (and | |
2213 | (>= (point) (widget-apply got :actual-position :from)) | |
2214 | (<= (point) (widget-apply got :actual-position :body-start)) | |
2215 | got) | |
2216 | ;; a wacky residual item - undecorate and disregard: | |
2217 | (allout-widgets-undecorate-item got) | |
2218 | nil))))) | |
2219 | ;;;_ > allout-get-or-create-item-widget (&optional redecorate blank-container) | |
2220 | (defun allout-get-or-create-item-widget (&optional redecorate blank-container) | |
2221 | "Return a widget for the item at point, creating the widget if necessary. | |
2222 | ||
2223 | When creating a widget, we assume there has been a context change | |
2224 | and decorate its siblings and parent, as well. | |
2225 | ||
2226 | Optional BLANK-CONTAINER is for internal use, to fabricate a | |
2227 | meta-container item with an empty body when the first proper | |
2228 | \(non-container\) item starts at the beginning of the file. | |
2229 | ||
2230 | Optional REDECORATE, if non-nil, means to redecorate the widget | |
2231 | if it already exists." | |
2232 | (let ((widget (allout-get-item-widget blank-container)) | |
2233 | (buffer-undo-list t)) | |
2234 | (cond (widget (if redecorate | |
2235 | (allout-redecorate-item widget)) | |
2236 | widget) | |
2237 | ((or blank-container (zerop (allout-depth))) | |
2238 | (or allout-container-item-widget | |
2239 | (setq allout-container-item-widget | |
2240 | (allout-decorate-item-and-context | |
2241 | (widget-convert 'allout-item-widget) | |
2242 | nil blank-container)))) | |
2243 | ;; create a widget for a regular/non-container item: | |
2244 | (t (allout-decorate-item-and-context (widget-convert | |
2245 | 'allout-item-widget)))))) | |
2246 | ;;;_ > allout-get-or-create-parent-widget (&optional redecorate) | |
2247 | (defun allout-get-or-create-parent-widget (&optional redecorate) | |
2248 | "Return widget for parent of item at point, decorating it if necessary. | |
2249 | ||
2250 | We return the container widget if we're above the first proper item in the | |
2251 | file. | |
2252 | ||
2253 | Optional REDECORATE, if non-nil, means to redecorate the widget if it | |
2254 | already exists. | |
2255 | ||
2256 | Point will wind up positioned on the beginning of the parent or beginning | |
2257 | of the buffer." | |
2258 | ;; use existing widget, if there, else establish it | |
2259 | (if (or (bobp) (and (not (allout-ascend)) | |
2260 | (looking-at allout-regexp))) | |
2261 | (allout-get-or-create-item-widget redecorate 'blank-container) | |
2262 | (allout-get-or-create-item-widget redecorate))) | |
2263 | ;;;_ : X- Item ancillaries | |
2264 | ;;;_ >X allout-body-modification-handler (beg end) | |
2265 | (defun allout-body-modification-handler (beg end) | |
2266 | "Do routine processing of body text before and after modification. | |
2267 | ||
2268 | Operation is inhibited by `allout-inhibit-body-modification-handler'." | |
2269 | ||
2270 | ;; The primary duties are: | |
2271 | ;; | |
2272 | ;; - marking of escaped prefix-like text for delayed cleanup of escapes | |
2273 | ;; - removal and replacement of the settings | |
2274 | ;; - maintenance of beginning-of-line guide lines | |
2275 | ;; | |
2276 | ;; ?? Escapes removal \(before changes\) is not done when edits span multiple | |
2277 | ;; items, recognizing that item structure is being preserved, including | |
2278 | ;; escaping of item-prefix-like text within bodies. See | |
2279 | ;; `allout-before-modification-handler' and | |
2280 | ;; `allout-inhibit-body-modification-handler'. | |
2281 | ;; | |
2282 | ;; Adds the overlay to the `allout-unresolved-body-mod-workhash' during | |
2283 | ;; before-change operation, and removes from that list during after-change | |
2284 | ;; operation. | |
2285 | (cond (allout-inhibit-body-modification-hook nil))) | |
2286 | ;;;_ >X allout-graphics-modification-handler (beg end) | |
2287 | (defun allout-graphics-modification-handler (beg end) | |
2288 | "Protect against incoherent deletion of decoration graphics. | |
2289 | ||
2290 | Deletes allowed only when inhibit-read-only is t." | |
2291 | (cond | |
2292 | (undo-in-progress (when (eq (get-text-property beg 'category) | |
2293 | 'allout-icon-span-category) | |
2294 | (save-excursion | |
2295 | (goto-char beg) | |
2296 | (let* ((item-widget (allout-get-item-widget))) | |
2297 | (if item-widget | |
2298 | (allout-widgets-exposure-undo-recorder | |
2299 | item-widget)))))) | |
2300 | (inhibit-read-only t) | |
2301 | ((not (and (boundp 'allout-mode) allout-mode)) t) | |
2302 | ((equal this-command 'quoted-insert) t) | |
2303 | ((yes-or-no-p "Unruly edit of outline structure - allow? ") | |
2304 | (setq allout-widgets-unset-inhibit-read-only (not inhibit-read-only) | |
2305 | inhibit-read-only t)) | |
2306 | (t (error | |
2307 | (substitute-command-keys allout-structure-unruly-deletion-message))))) | |
2308 | ;;;_ > allout-item-icon-key-handler () | |
2309 | (defun allout-item-icon-key-handler () | |
2310 | "Catchall handling of key bindings in item icon/cue hot-spots. | |
2311 | ||
2312 | Applies `allout-hotspot-key-handler' and calls the result, if any, as an | |
2313 | interactive command." | |
2314 | ||
2315 | (interactive) | |
2316 | (let* ((mapped-binding (allout-hotspot-key-handler))) | |
2317 | (when mapped-binding | |
2318 | (call-interactively mapped-binding)))) | |
2319 | ||
2320 | ;;;_ : Status | |
2321 | ;;;_ . allout-item-location (item-widget) | |
2322 | (defun allout-item-location (item-widget) | |
2323 | "Location of the start of the item's text." | |
2324 | (overlay-start (widget-get item-widget :span-overlay))) | |
2325 | ||
2326 | ;;;_ : Icon management | |
2327 | ;;;_ > allout-fetch-icon-image (name) | |
2328 | (defun allout-fetch-icon-image (name) | |
2329 | "Fetch allout icon for symbol NAME. | |
2330 | ||
2331 | We use a caching strategy, so the caller doesn't need to do so." | |
2332 | (let* ((types allout-widgets-icon-types) | |
2333 | (use-dir (if (equal (allout-frame-property nil 'background-mode) | |
2334 | 'light) | |
2335 | allout-widgets-icons-light-subdir | |
2336 | allout-widgets-icons-dark-subdir)) | |
2337 | (key (list name use-dir)) | |
2338 | (got (assoc key allout-widgets-icons-cache))) | |
2339 | (if got | |
2340 | ;; display system shows only first of subsequent adjacent | |
2341 | ;; `eq'-identical repeats - use copies to avoid this problem. | |
2342 | (allout-widgets-copy-list (cadr got)) | |
2343 | (while (and types (not got)) | |
2344 | (setq got | |
2345 | (allout-find-image | |
2346 | (list (append (list :type (car types) | |
2347 | :file (concat use-dir | |
2348 | (symbol-name name) | |
2349 | "." (symbol-name | |
2350 | (car types)))) | |
2351 | (if (featurep 'xemacs) | |
2352 | allout-widgets-item-image-properties-xemacs | |
2353 | allout-widgets-item-image-properties-emacs) | |
2354 | )))) | |
2355 | (setq types (cdr types))) | |
2356 | (if got | |
2357 | (push (list key got) allout-widgets-icons-cache)) | |
2358 | got))) | |
2359 | ||
2360 | ;;;_ : Miscellaneous | |
2361 | ;;;_ > allout-elapsed-time-seconds (triple) | |
2362 | (defun allout-elapsed-time-seconds (end start) | |
2363 | "Return seconds between `current-time' style time START/END triples." | |
2364 | (let ((elapsed (time-subtract end start))) | |
35837f51 | 2365 | (float-time elapsed))) |
aac7a935 KM |
2366 | ;;;_ > allout-frame-property (frame property) |
2367 | (defalias 'allout-frame-property | |
2368 | (cond ((fboundp 'frame-parameter) | |
2369 | 'frame-parameter) | |
2370 | ((fboundp 'frame-property) | |
2371 | 'frame-property) | |
2372 | (t nil))) | |
2373 | ;;;_ > allout-find-image (specs) | |
2374 | (defalias 'allout-find-image | |
2375 | (if (fboundp 'find-image) | |
2376 | 'find-image | |
2377 | nil) ; aka, not-yet-implemented for xemacs. | |
2378 | ) | |
2379 | ;;;_ > allout-widgets-copy-list (list) | |
2380 | (defun allout-widgets-copy-list (list) | |
2381 | ;; duplicated from cl.el 'copy-list' as of 2008-08-17 | |
2382 | "Return a copy of LIST, which may be a dotted list. | |
2383 | The elements of LIST are not copied, just the list structure itself." | |
2384 | (if (consp list) | |
2385 | (let ((res nil)) | |
2386 | (while (consp list) (push (pop list) res)) | |
2387 | (prog1 (nreverse res) (setcdr res list))) | |
2388 | (car list))) | |
d806ab68 KM |
2389 | ;;;_ . allout-widgets-count-buttons-in-region (start end) |
2390 | (defun allout-widgets-count-buttons-in-region (start end) | |
2391 | "Debugging/diagnostic tool - count overlays with 'button' property in region." | |
2392 | (interactive "r") | |
2393 | (setq start (or start (point-min)) | |
2394 | end (or end (point-max))) | |
2395 | (if (> start end) (let ((interim start)) (setq start end end interim))) | |
2396 | (let ((button-overlays (delq nil | |
2397 | (mapcar (function (lambda (o) | |
2398 | (if (overlay-get o 'button) | |
2399 | o))) | |
2400 | (overlays-in start end))))) | |
2401 | (length button-overlays))) | |
aac7a935 KM |
2402 | |
2403 | ;;;_ : Run unit tests: | |
2404 | (defun allout-widgets-run-unit-tests () | |
2405 | (message "Running allout-widget tests...") | |
2406 | ||
2407 | (allout-test-range-overlaps) | |
2408 | ||
2409 | (message "Running allout-widget tests... Done.") | |
2410 | (sit-for .5)) | |
2411 | ||
2412 | (when allout-widgets-run-unit-tests-on-load | |
2413 | (allout-widgets-run-unit-tests)) | |
2414 | ||
2415 | ;;;_ : provide | |
2416 | (provide 'allout-widgets) | |
2417 | ||
2418 | ;;;_. Local emacs vars. | |
2419 | ;;;_ , Local variables: | |
2420 | ;;;_ , allout-layout: (-1 : 0) | |
2421 | ;;;_ , End: |