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