* admin/gitmerge.el (gitmerge-missing):
[emacs.git] / lisp / allout-widgets.el
blob9fa927ddcb30c0b5f680e8d5a5bbf147028306df
1 ;; allout-widgets.el --- Visually highlight allout outline structure.
3 ;; Copyright (C) 2005-2017 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.
516 With a prefix argument ARG, enable Allout Widgets mode if ARG is
517 positive, and disable it otherwise. If called from Lisp, enable
518 the mode if ARG is omitted or nil.
520 Allout Widgets mode is an extension of Allout mode that provides
521 graphical decoration of outline structure. It is meant to
522 operate along with `allout-mode', via `allout-mode-hook'.
524 The graphics include:
526 - guide lines connecting item bullet-icons with those of their subitems.
528 - icons for item bullets, varying to indicate whether or not the item
529 has subitems, and if so, whether or not the item is expanded.
531 - cue area between the bullet-icon and the start of the body headline,
532 for item numbering, encryption indicator, and distinctive bullets.
534 The bullet-icon and guide line graphics provide keybindings and mouse
535 bindings for easy outline navigation and exposure control, extending
536 outline hot-spot navigation (see `allout-mode')."
538 :lighter nil
539 :keymap nil
541 ;; define-minor-mode handles any provided argument according to emacs
542 ;; minor-mode conventions - '(elisp) Minor Mode Conventions' - and sets
543 ;; allout-widgets-mode accordingly *before* running the body code, so we
544 ;; cue on that.
545 (if allout-widgets-mode
546 ;; Activating:
547 (progn
548 (allout-add-resumptions
549 ;; XXX user may need say in line-truncation/hscrolling - an option
550 ;; that abstracts mode.
551 ;; truncate text lines to keep guide lines intact:
552 '(truncate-lines t)
553 ;; and enable autoscrolling to ease view of text
554 '(auto-hscroll-mode t)
555 '(line-move-ignore-fields t)
556 '(widget-push-button-prefix "")
557 '(widget-push-button-suffix "")
558 ;; allout-escaped-prefix-regexp depends on allout-regexp:
559 (list 'allout-escaped-prefix-regexp (concat "\\(\\\\\\)"
560 "\\(" allout-regexp "\\)")))
561 (allout-add-resumptions
562 (list 'allout-widgets-tally allout-widgets-tally)
563 (list 'allout-widgets-escapes-sanitization-regexp-pair
564 (list (concat "\\(\n\\|\\`\\)"
565 allout-escaped-prefix-regexp
567 ;; Include everything but the escape symbol.
568 "\\1\\3"))
571 (add-hook 'after-change-functions 'allout-widgets-after-change-handler
572 nil t)
574 (allout-setup-text-properties)
575 (add-to-invisibility-spec '(allout-torso . t))
576 (add-to-invisibility-spec 'allout-escapes)
578 (if (current-local-map)
579 (set-keymap-parent allout-item-body-keymap (current-local-map)))
581 (add-hook 'allout-exposure-change-functions
582 'allout-widgets-exposure-change-recorder nil 'local)
583 (add-hook 'allout-structure-added-functions
584 'allout-widgets-additions-recorder nil 'local)
585 (add-hook 'allout-structure-deleted-functions
586 'allout-widgets-deletions-recorder nil 'local)
587 (add-hook 'allout-structure-shifted-functions
588 'allout-widgets-shifts-recorder nil 'local)
589 (add-hook 'allout-after-copy-or-kill-hook
590 'allout-widgets-after-copy-or-kill-function nil 'local)
591 (add-hook 'allout-post-undo-hook
592 'allout-widgets-after-undo-function nil 'local)
594 (add-hook 'before-change-functions 'allout-widgets-before-change-handler
595 nil 'local)
596 (add-hook 'post-command-hook 'allout-widgets-post-command-business
597 nil 'local)
598 (add-hook 'pre-command-hook 'allout-widgets-pre-command-business
599 nil 'local)
601 ;; init the widgets tally for debugging:
602 (if (not allout-widgets-tally)
603 (setq allout-widgets-tally (make-hash-table
604 :test 'eq :weakness 'key)))
605 ;; add tally count display on minor-mode-alist just after
606 ;; allout-mode entry.
607 ;; (we use ternary condition form to keep condition simple for deletion.)
608 (let* ((mode-line-entry '(allout-widgets-mode-inhibit ""
609 (:eval (allout-widgets-tally-string))))
610 (associated (assoc (car mode-line-entry) minor-mode-alist))
611 ;; need location for it only if not already present:
612 (after (and (not associated)
613 (memq (assq 'allout-mode minor-mode-alist) minor-mode-alist))))
614 (if after
615 (rplacd after (cons mode-line-entry (cdr after)))))
616 (allout-widgets-prepopulate-buffer)
618 ;; Deactivating:
619 (let ((inhibit-read-only t)
620 (was-modified (buffer-modified-p)))
622 (allout-widgets-undecorate-region (point-min)(point-max))
623 (remove-from-invisibility-spec '(allout-torso . t))
624 (remove-from-invisibility-spec 'allout-escapes)
626 (remove-hook 'after-change-functions
627 'allout-widgets-after-change-handler 'local)
628 (remove-hook 'allout-exposure-change-functions
629 'allout-widgets-exposure-change-recorder 'local)
630 (remove-hook 'allout-structure-added-functions
631 'allout-widgets-additions-recorder 'local)
632 (remove-hook 'allout-structure-deleted-functions
633 'allout-widgets-deletions-recorder 'local)
634 (remove-hook 'allout-structure-shifted-functions
635 'allout-widgets-shifts-recorder 'local)
636 (remove-hook 'allout-after-copy-or-kill-hook
637 'allout-widgets-after-copy-or-kill-function 'local)
638 (remove-hook 'before-change-functions
639 'allout-widgets-before-change-handler 'local)
640 (remove-hook 'post-command-hook
641 'allout-widgets-post-command-business 'local)
642 (remove-hook 'pre-command-hook
643 'allout-widgets-pre-command-business 'local)
644 (assq-delete-all 'allout-widgets-mode-inhibit minor-mode-alist)
645 (set-buffer-modified-p was-modified))))
646 ;;;_ > allout-widgets-mode-off
647 (defun allout-widgets-mode-off ()
648 "Explicitly disable `allout-widgets-mode'."
649 (allout-widgets-mode -1))
650 ;;;_ > allout-widgets-mode-off
651 (defun allout-widgets-mode-on ()
652 "Explicitly enable `allout-widgets-mode'."
653 (allout-widgets-mode 1))
654 ;;;_ > allout-setup-text-properties ()
655 (defun allout-setup-text-properties ()
656 "Configure category and literal text properties."
658 ;; XXX body - before-change, entry, keymap
660 (setplist 'allout-guides-span-category nil)
661 (put 'allout-guides-span-category
662 'modification-hooks '(allout-graphics-modification-handler))
663 (put 'allout-guides-span-category 'local-map allout-item-icon-keymap)
664 (put 'allout-guides-span-category 'mouse-face widget-button-face)
665 (put 'allout-guides-span-category 'field 'structure)
666 ;; (put 'allout-guides-span-category 'face 'widget-button)
668 (setplist 'allout-icon-span-category
669 (allout-widgets-copy-list (symbol-plist
670 'allout-guides-span-category)))
671 (put 'allout-icon-span-category 'field 'structure)
673 ;; XXX for body text we're instead going to use the buffer-wide
674 ;; resources, like before/after-change-functions hooks and the
675 ;; buffer's key map. that way we won't have to do painful provisions
676 ;; to fixup things after edits, catch outlier interstitial
677 ;; characters, like newline and empty lines after hidden subitems,
678 ;; etc.
679 (setplist 'allout-body-span-category nil)
680 (put 'allout-body-span-category 'evaporate t)
681 (put 'allout-body-span-category 'local-map allout-item-body-keymap)
682 ;;(put 'allout-body-span-category
683 ;; 'modification-hooks '(allout-body-modification-handler))
684 ;;(put 'allout-body-span-category 'field 'body)
686 (setplist 'allout-cue-span-category nil)
687 (put 'allout-cue-span-category 'evaporate t)
688 (put 'allout-cue-span-category
689 'modification-hooks '(allout-body-modification-handler))
690 (put 'allout-cue-span-category 'local-map allout-cue-span-keymap)
691 (put 'allout-cue-span-category 'mouse-face widget-button-face)
692 (put 'allout-cue-span-category 'pointer 'arrow)
693 (put 'allout-cue-span-category 'field 'structure)
695 (setplist 'allout-trailing-category nil)
696 (put 'allout-trailing-category 'evaporate t)
697 (put 'allout-trailing-category 'local-map allout-item-body-keymap)
699 (setplist 'allout-escapes-category nil)
700 (put 'allout-escapes-category 'invisible 'allout-escapes)
701 (put 'allout-escapes-category 'evaporate t))
702 ;;;_ > allout-widgets-prepopulate-buffer ()
703 (defun allout-widgets-prepopulate-buffer ()
704 "Step over the current buffers exposed items to do initial widgetizing."
705 (if (not allout-widgets-mode-inhibit)
706 (save-excursion
707 (goto-char (point-min))
708 (while (allout-next-visible-heading 1)
709 (when (not (widget-at (point)))
710 (allout-get-or-create-item-widget))))))
711 ;;;_ . settings context
712 ;;;_ = allout-container-item
713 (defvar allout-container-item-widget nil
714 "A widget for the current outline's overarching container as an item.
716 The item has settings (of the file/connection) and maybe a body, but no
717 icon/bullet.")
718 (make-variable-buffer-local 'allout-container-item-widget)
719 ;;;_ . Hooks and hook helpers
720 ;;;_ , major command-loop business:
721 ;;;_ > allout-widgets-pre-command-business (&optional recursing)
722 (defun allout-widgets-pre-command-business (&optional _recursing)
723 "Handle actions pending before `allout-mode' activity."
725 ;;;_ > allout-widgets-post-command-business (&optional recursing)
726 (defun allout-widgets-post-command-business (&optional _recursing)
727 "Handle actions pending after any `allout-mode' commands.
729 Optional RECURSING is for internal use, to limit recursion."
730 ;; - check changed text for nesting discontinuities and escape anything
731 ;; that's: (1) asterisks at bol or (2) excessively nested.
732 (condition-case nil
734 (when (and (boundp 'allout-mode) allout-mode)
736 (if allout-widgets-unset-inhibit-read-only
737 (setq inhibit-read-only nil
738 allout-widgets-unset-inhibit-read-only nil))
740 (when allout-widgets-reenable-before-change-handler
741 (add-hook 'before-change-functions
742 'allout-widgets-before-change-handler
743 nil 'local)
744 (setq allout-widgets-reenable-before-change-handler nil))
746 (when (or allout-widgets-undo-exposure-record
747 allout-widgets-changes-record)
748 (let* ((debug-on-signal t)
749 (debug-on-error t)
750 ;; inhibit recording new undo records when processing
751 ;; effects of undo-exposure:
752 (debugger 'allout-widgets-hook-error-handler)
753 (adjusting-message " Adjusting widgets...")
754 (replaced-message (allout-widgets-adjusting-message
755 adjusting-message))
756 (start-time (current-time)))
758 (if allout-widgets-undo-exposure-record
759 ;; inhibit undo recording iff undoing exposure stuff.
760 ;; XXX we might need to inhibit per respective
761 ;; change-record, rather than assuming that some undo
762 ;; activity during a command is all undo activity.
763 (let ((buffer-undo-list t))
764 (allout-widgets-exposure-undo-processor)
765 (allout-widgets-changes-dispatcher))
766 (allout-widgets-exposure-undo-processor)
767 (allout-widgets-changes-dispatcher))
769 (if allout-widgets-time-decoration-activity
770 (setq allout-widgets-last-decoration-timing
771 (list (allout-elapsed-time-seconds nil start-time)
772 allout-widgets-changes-record)))
774 (setq allout-widgets-changes-record nil)
776 (if replaced-message
777 (if (stringp replaced-message)
778 (message replaced-message)
779 (message "")))))
781 ;; alas, decorated intermediate matches are not easily undecorated
782 ;; when they're automatically rehidden by isearch, so we're
783 ;; dropping this nicety.
784 ;; ;; Detect undecorated items, eg during isearch into previously
785 ;; ;; unexposed topics, and decorate "economically". Some
786 ;; ;; undecorated stuff is often exposed, to reduce lag, but the
787 ;; ;; item containing the cursor is decorated. We constrain
788 ;; ;; recursion to avoid being trapped by unexpectedly undecoratable
789 ;; ;; items.
790 ;; (when (and (not recursing)
791 ;; (not (allout-current-decorated-p))
792 ;; (or (not (equal (allout-depth) 0))
793 ;; (not allout-container-item-widget)))
794 ;; (let ((buffer-undo-list t))
795 ;; (allout-widgets-exposure-change-recorder
796 ;; allout-recent-prefix-beginning allout-recent-prefix-end nil)
797 ;; (allout-widgets-post-command-business 'recursing)))
799 ;; Detect and rectify fouled outline structure - decorated item
800 ;; not at beginning of line.
801 (let ((this-widget (or (widget-at (point))
802 ;; XXX we really should be checking across
803 ;; edited span, not just point and point+1
804 (and (not (eq (point) (point-max)))
805 (widget-at (1+ (point))))))
806 inserted-at)
807 (save-excursion
808 (if (and this-widget
809 (goto-char (widget-get this-widget :from))
810 (not (bolp)))
811 (if (not
812 (condition-case nil
813 (yes-or-no-p
814 (concat "Misplaced item won't be recognizable "
815 " as part of outline - rectify? "))
816 (quit nil)))
817 (progn
818 (if (allout-hidden-p (max (1- (point)) 1))
819 (save-excursion
820 (goto-char (max (1- (point)) 1))
821 (allout-show-to-offshoot)))
822 (allout-widgets-undecorate-item this-widget))
823 ;; expose any hidden intervening items, so resulting
824 ;; position is clear:
825 (setq inserted-at (point))
826 (allout-unprotected (insert-before-markers "\n"))
827 (forward-char -1)
828 ;; ensure the inserted newline is visible:
829 (allout-flag-region inserted-at (1+ inserted-at) nil)
830 (allout-widgets-post-command-business 'recursing)
831 (message (concat "outline structure corrected - item"
832 " moved to beginning of new line"))
833 ;; preserve cursor position in some cases:
834 (if (and inserted-at
835 (> (point) inserted-at))
836 (forward-char -1)))))))
838 (error
839 ;; zero work list so we don't get stuck futilely retrying.
840 ;; error recording done by allout-widgets-hook-error-handler.
841 (setq allout-widgets-changes-record nil))))
842 ;;;_ , major change handlers:
843 ;;;_ > allout-widgets-before-change-handler
844 (defun allout-widgets-before-change-handler (beg end)
845 "Business to be done before changes in a widgetized allout outline."
846 ;; protect against unruly edits to structure:
847 (cond
848 (undo-in-progress (when (eq (get-text-property beg 'category)
849 'allout-icon-span-category)
850 (save-excursion
851 (goto-char beg)
852 (let* ((item-widget (allout-get-item-widget)))
853 (if item-widget
854 (allout-widgets-exposure-undo-recorder
855 item-widget))))))
856 (inhibit-read-only t)
857 ((not (and (boundp 'allout-mode) allout-mode)) t)
858 ((equal this-command 'quoted-insert) t)
859 ((not (text-property-any beg (if (equal end beg)
860 (min (1+ beg) (point-max))
861 end)
862 'field 'structure))
864 ((yes-or-no-p "Unruly edit of outline structure - allow? ")
865 (setq allout-widgets-unset-inhibit-read-only (not inhibit-read-only)
866 inhibit-read-only t))
868 ;; tell the allout-widgets-post-command-business to reestablish the hook:
869 (setq allout-widgets-reenable-before-change-handler t)
870 ;; and raise an error to prevent the edit (and disable the hook):
871 (error "%s"
872 (substitute-command-keys allout-structure-unruly-deletion-message)))))
873 ;;;_ > allout-widgets-after-change-handler
874 (defun allout-widgets-after-change-handler (_beg _end _prelength)
875 "Reconcile what needs to be reconciled for allout widgets after edits."
877 ;;;_ > allout-current-decorated-p ()
878 (defun allout-current-decorated-p ()
879 "True if the current item is not decorated"
880 (save-excursion
881 (if (allout-back-to-current-heading)
882 (if (> allout-recent-depth 0)
883 (and (allout-get-item-widget) t)
884 allout-container-item-widget))))
886 ;;;_ > allout-widgets-hook-error-handler
887 (defun allout-widgets-hook-error-handler (mode args)
888 "Process errors which occurred in the course of command hook operation.
890 We store a backtrace of the error information in the variable,
891 `allout-widgets-last-hook-error', unset the error handlers, and
892 reraise the error, so that processing continues to the
893 encompassing condition-case."
894 ;; first deconstruct special error environment so errors here propagate
895 ;; to encompassing condition-case:
896 (setq debugger 'debug
897 debug-on-error nil
898 debug-on-signal nil)
899 (let* ((bt (with-output-to-string (backtrace)))
900 (this "allout-widgets-hook-error-handler")
901 (header
902 (format "allout-widgets-last-hook-error stored, %s/%s %s %s"
903 this mode args
904 (format-time-string "%e-%b-%Y %r"))))
905 ;; post to *Messages* then immediately replace with more compact notice:
906 (message "%s" (setq allout-widgets-last-hook-error
907 (format "%s:\n%s" header bt)))
908 (message header) (sit-for allout-widgets-hook-error-post-time)
909 ;; reraise the error, or one concerning this function if unexpected:
910 (if (equal mode 'error)
911 (apply 'signal args)
912 (error "%s: unexpected mode, %s %s" this mode args))))
913 ;;;_ > allout-widgets-changes-exceed-threshold-p ()
914 (defun allout-widgets-adjusting-message (message)
915 "Post MESSAGE when pending are likely to make a big enough delay.
917 If posting of the MESSAGE is warranted and there already is a
918 `current-message' in the minibuffer, the MESSAGE is appended to
919 the current one, and the previously pending `current-message' is
920 returned for later posting on completion.
922 If posting of the MESSAGE is warranted, but no `current-message'
923 is pending, then t is returned to indicate that case.
925 If posting of the MESSAGE is not warranted, then nil is returned.
927 See `allout-widgets-adjust-message-length-threshold',
928 `allout-widgets-adjust-message-size-threshold' for message
929 posting threshold criteria."
930 (if (or (> (length allout-widgets-changes-record)
931 allout-widgets-adjust-message-length-threshold)
932 ;; for size, use distance from start of first to end of last:
933 (let ((min (point-max))
934 (max 0)
935 first second)
936 (mapc (function (lambda (entry)
937 (if (eq :undone-exposure (car entry))
939 (setq first (cadr entry)
940 second (caddr entry))
941 (if (< (min first second) min)
942 (setq min (min first second)))
943 (if (> (max first second) max)
944 (setq max (max first second))))))
945 allout-widgets-changes-record)
946 (> (- max min) allout-widgets-adjust-message-size-threshold)))
947 (let ((prior (current-message)))
948 (message (if prior (concat prior " - " message) message))
949 (or prior t))))
950 ;;;_ > allout-widgets-changes-dispatcher ()
951 (defun allout-widgets-changes-dispatcher ()
952 "Dispatch CHANGES-RECORD items to respective widgets change processors."
954 (if (not allout-widgets-mode-inhibit)
955 (let* ((changes-record allout-widgets-changes-record)
956 (changes-pending (and changes-record t))
957 entry
958 exposures
959 additions
960 deletions
961 shifts)
963 (when changes-pending
964 (while changes-record
965 (setq entry (pop changes-record))
966 (case (car entry)
967 (:exposed (push entry exposures))
968 (:added (push entry additions))
969 (:deleted (push entry deletions))
970 (:shifted (push entry shifts))))
972 (if exposures
973 (allout-widgets-exposure-change-processor exposures))
974 (if additions
975 (allout-widgets-additions-processor additions))
976 (if deletions
977 (allout-widgets-deletions-processor deletions))
978 (if shifts
979 (allout-widgets-shifts-processor shifts))))
980 (when (not (equal allout-widgets-mode-inhibit 'undecorated))
981 (allout-widgets-undecorate-region (point-min)(point-max))
982 (setq allout-widgets-mode-inhibit 'undecorated))))
983 ;;;_ > allout-widgets-exposure-change-recorder (from to flag)
984 (defun allout-widgets-exposure-change-recorder (from to flag)
985 "Record allout exposure changes for tracking during post-command processing.
987 Records changes in `allout-widgets-changes-record'."
988 (push (list :exposed from to flag) allout-widgets-changes-record))
989 ;;;_ > allout-widgets-exposure-change-processor (changes)
990 (defun allout-widgets-exposure-change-processor (changes)
991 "Widgetize and adjust item widgets tracking allout outline exposure changes.
993 Generally invoked via `allout-exposure-change-functions'."
995 (let ((changes (sort changes (function (lambda (this next)
996 (< (cadr this) (cadr next))))))
997 ;; have to distinguish between concealing and exposing so that, eg,
998 ;; `allout-expose-topic's mix is handled properly.
999 handled-expose
1000 covered
1001 deactivate-mark)
1003 (dolist (change changes)
1004 (let (handling
1005 (from (cadr change))
1006 bucket got
1007 (to (caddr change))
1008 (flag (cadddr change))
1009 parent)
1011 ;; swap from and to:
1012 (if (< to from) (setq bucket to
1013 to from
1014 from bucket))
1016 ;; have we already handled exposure changes in this region?
1017 (setq handling (if flag 'handled-conceal 'handled-expose)
1018 got (allout-range-overlaps from to (symbol-value handling))
1019 covered (car got))
1020 (set handling (cadr got))
1022 (when (not covered)
1023 (save-excursion
1024 (goto-char from)
1025 (cond
1027 ;; collapsing:
1028 (flag
1029 (allout-widgets-undecorate-region from to)
1030 (allout-beginning-of-current-line)
1031 (let ((widget (allout-get-item-widget)))
1032 (if (not widget)
1033 (allout-get-or-create-item-widget)
1034 (widget-apply widget :redecorate))))
1036 ;; expanding:
1038 (while (< (point) to)
1039 (allout-beginning-of-current-line)
1040 (setq parent (allout-get-item-widget))
1041 (if (not parent)
1042 (setq parent (allout-get-or-create-item-widget))
1043 (widget-apply parent :redecorate))
1044 (allout-next-visible-heading 1)
1045 (if (widget-get parent :has-subitems)
1046 (allout-redecorate-visible-subtree parent))
1047 (if (> (point) to)
1048 ;; subtree may be well beyond to - incorporate in ranges:
1049 (setq handled-expose
1050 (allout-range-overlaps from (point) handled-expose)
1051 covered (car handled-expose)
1052 handled-expose (cadr handled-expose)))
1053 (allout-next-visible-heading 1))))))))))
1055 ;;;_ > allout-widgets-additions-recorder (from to)
1056 (defun allout-widgets-additions-recorder (from to)
1057 "Record allout item additions for tracking during post-command processing.
1059 Intended for use on `allout-structure-added-functions'.
1061 FROM point at the start of the first new item and TO is point at the start
1062 of the last one.
1064 Records changes in `allout-widgets-changes-record'."
1065 (push (list :added from to) allout-widgets-changes-record))
1066 ;;;_ > allout-widgets-additions-processor (changes)
1067 (defun allout-widgets-additions-processor (changes)
1068 "Widgetize and adjust items tracking allout outline structure additions.
1070 Dispatched by `allout-widgets-post-command-business' in response to
1071 :added entries recorded by `allout-widgets-additions-recorder'."
1072 (save-excursion
1073 (let (handled
1074 covered)
1075 (dolist (change changes)
1076 (let ((from (cadr change))
1077 bucket
1078 (to (caddr change)))
1079 (if (< to from) (setq bucket to to from from bucket))
1080 ;; have we already handled exposure changes in this region?
1081 (setq handled (allout-range-overlaps from to handled)
1082 covered (car handled)
1083 handled (cadr handled))
1084 (when (not covered)
1085 (goto-char from)
1086 ;; Prior sibling and parent can both be affected.
1087 (if (allout-ascend)
1088 (allout-redecorate-visible-subtree
1089 (allout-get-or-create-item-widget 'redecorate)))
1090 (if (< (point) from)
1091 (goto-char from))
1092 (while (and (< (point) to) (not (eobp)))
1093 (allout-beginning-of-current-line)
1094 (allout-redecorate-visible-subtree
1095 (allout-get-or-create-item-widget))
1096 (allout-next-visible-heading 1))
1097 (if (> (point) to)
1098 ;; subtree may be well beyond to - incorporate in ranges:
1099 (setq handled (allout-range-overlaps from (point) handled)
1100 covered (car handled)
1101 handled (cadr handled)))))))))
1103 ;;;_ > allout-widgets-deletions-recorder (depth from)
1104 (defun allout-widgets-deletions-recorder (depth from)
1105 "Record allout item deletions for tracking during post-command processing.
1106 Intended for use on `allout-structure-deleted-functions'.
1108 DEPTH is the depth of the deleted subtree, and FROM is the point from which
1109 the subtree was deleted.
1111 Records changes in `allout-widgets-changes-record'."
1112 (push (list :deleted depth from) allout-widgets-changes-record))
1113 ;;;_ > allout-widgets-deletions-processor (changes)
1114 (defun allout-widgets-deletions-processor (changes)
1115 "Adjust items tracking allout outline structure deletions.
1117 Dispatched by `allout-widgets-post-command-business' in response to
1118 :deleted entries recorded by `allout-widgets-deletions-recorder'."
1119 (save-excursion
1120 (dolist (change changes)
1121 (let ((depth (cadr change))
1122 (from (caddr change)))
1123 (goto-char from)
1124 (when (allout-previous-visible-heading 1)
1125 (if (> depth 1)
1126 (allout-ascend-to-depth (1- depth)))
1127 (allout-redecorate-visible-subtree
1128 (allout-get-or-create-item-widget 'redecorate)))))))
1130 ;;;_ > allout-widgets-shifts-recorder (shifted-amount at)
1131 (defun allout-widgets-shifts-recorder (shifted-amount at)
1132 "Record outline subtree shifts for tracking during post-command processing.
1133 Intended for use on `allout-structure-shifted-functions'.
1135 SHIFTED-AMOUNT is the depth change and AT is the point at the start of the
1136 subtree that's been shifted.
1138 Records changes in `allout-widgets-changes-record'."
1139 (push (list :shifted shifted-amount at) allout-widgets-changes-record))
1140 ;;;_ > allout-widgets-shifts-processor (changes)
1141 (defun allout-widgets-shifts-processor (changes)
1142 "Widgetize and adjust items tracking allout outline structure additions.
1144 Dispatched by `allout-widgets-post-command-business' in response to
1145 :shifted entries recorded by `allout-widgets-shifts-recorder'."
1146 (save-excursion
1147 (dolist (change changes)
1148 (goto-char (caddr change))
1149 (allout-ascend)
1150 (allout-redecorate-visible-subtree))))
1151 ;;;_ > allout-widgets-after-copy-or-kill-function ()
1152 (defun allout-widgets-after-copy-or-kill-function ()
1153 "Do allout-widgets processing of text just placed in the kill ring.
1155 Intended for use on `allout-after-copy-or-kill-hook'."
1156 (if (car kill-ring)
1157 (setcar kill-ring (allout-widgets-undecorate-text (car kill-ring)))))
1158 ;;;_ > allout-widgets-after-undo-function ()
1159 (defun allout-widgets-after-undo-function ()
1160 "Do allout-widgets processing of text after an undo.
1162 Intended for use on `allout-post-undo-hook'."
1163 (save-excursion
1164 (if (allout-goto-prefix)
1165 (allout-redecorate-item (allout-get-or-create-item-widget)))))
1167 ;;;_ > allout-widgets-exposure-undo-recorder (widget from-state)
1168 (defun allout-widgets-exposure-undo-recorder (widget)
1169 "Record outline exposure undo for tracking during post-command processing.
1171 Intended for use by `allout-graphics-modification-handler'.
1173 WIDGET is the widget being changed.
1175 Records changes in `allout-widgets-changes-record'."
1176 ;; disregard the events if we're currently processing them.
1177 (if (not allout-undo-exposure-in-progress)
1178 (push widget allout-widgets-undo-exposure-record)))
1179 ;;;_ > allout-widgets-exposure-undo-processor ()
1180 (defun allout-widgets-exposure-undo-processor ()
1181 "Adjust items tracking undo of allout outline structure exposure.
1183 Dispatched by `allout-widgets-post-command-business' in response to
1184 :undone-exposure entries recorded by `allout-widgets-exposure-undo-recorder'."
1185 (let* ((allout-undo-exposure-in-progress t)
1186 ;; inhibit undo recording while twiddling exposure to track undo:
1187 (widgets allout-widgets-undo-exposure-record)
1188 widget-start-marker widget-end-marker
1189 from-state icon-start-point to-state
1190 handled covered)
1191 (setq allout-widgets-undo-exposure-record nil)
1192 (save-excursion
1193 (dolist (widget widgets)
1194 (setq widget-start-marker (widget-get widget :from)
1195 widget-end-marker (widget-get widget :to)
1196 from-state (widget-get widget :icon-state)
1197 icon-start-point (widget-apply widget :actual-position
1198 :icon-start)
1199 to-state (get-text-property icon-start-point
1200 :icon-state))
1201 (setq handled (allout-range-overlaps widget-start-marker
1202 widget-end-marker
1203 handled)
1204 covered (car handled)
1205 handled (cadr handled))
1206 (when (not covered)
1207 (goto-char (widget-get widget :from))
1208 (when (not (allout-hidden-p))
1209 ;; adjust actual exposure to that of to-state viz from-state
1210 (cond ((and (eq to-state 'closed) (eq from-state 'opened))
1211 (allout-hide-current-subtree)
1212 (allout-decorate-item-and-context widget))
1213 ((and (eq to-state 'opened) (eq from-state 'closed))
1214 (save-excursion
1215 (dolist
1216 (expose-to (allout-chart-exposure-contour-by-icon))
1217 (goto-char expose-to)
1218 (allout-show-to-offshoot)))))))))))
1219 ;;;_ > allout-chart-exposure-contour-by-icon (&optional from-depth)
1220 (defun allout-chart-exposure-contour-by-icon (&optional from-depth)
1221 "Return points of subtree items to which exposure should be extended.
1223 The qualifying items are ones with a widget icon that is in the closed or
1224 empty state, or items with undecorated subitems.
1226 The resulting list of points is in reverse order.
1228 Optional FROM-DEPTH is for internal use."
1229 ;; During internal recursion, we return a pair: (at-end . result)
1230 ;; Otherwise we just return the result.
1231 (let ((from-depth from-depth)
1232 start-point
1233 at-end level-depth
1234 this-widget
1235 got subgot)
1236 (if from-depth
1237 (setq level-depth (allout-depth))
1238 ;; at containing item:
1239 (setq start-point (point))
1240 (setq from-depth (allout-depth))
1241 (setq at-end (not (allout-next-heading))
1242 level-depth allout-recent-depth))
1244 ;; traverse the level, recursing on deeper levels:
1245 (while (and (not at-end)
1246 (> allout-recent-depth from-depth)
1247 (setq this-widget (allout-get-item-widget)))
1248 (if (< level-depth allout-recent-depth)
1249 ;; recurse:
1250 (progn
1251 (setq subgot (allout-chart-exposure-contour-by-icon level-depth)
1252 at-end (car subgot)
1253 subgot (cdr subgot))
1254 (if subgot (setq got (append subgot got))))
1255 ;; progress at this level:
1256 (when (memq (widget-get this-widget :icon-state) '(closed empty))
1257 (push (point) got)
1258 (allout-end-of-subtree))
1259 (setq at-end (not (allout-next-heading)))))
1261 ;; tailor result depending on whether or not we're a recursion:
1262 (if (not start-point)
1263 (cons at-end got)
1264 (goto-char start-point)
1265 got)))
1266 ;;;_ > allout-range-overlaps (from to ranges)
1267 (defun allout-range-overlaps (from to ranges)
1268 "Return a pair indicating overlap of FROM and TO subtree range in RANGES.
1270 First element of result indicates whether candidate range FROM, TO
1271 overlapped any of the existing ranges.
1273 Second element of result is a new version of RANGES incorporating the
1274 candidate range with overlaps consolidated.
1276 FROM and TO must be in increasing order, as must be the pairs in RANGES."
1277 ;; to append to the end: (rplacd next-to-last-cdr (list 'f))
1278 (let (new-ranges
1279 entry
1280 ;; the start of the range that includes the candidate from:
1281 included-from
1282 ;; the end of the range that includes the candidate to:
1283 included-to
1284 ;; the candidates were inserted:
1285 done)
1286 (while (and ranges (not done))
1287 (setq entry (car ranges)
1288 ranges (cdr ranges))
1290 (cond
1292 (included-from
1293 ;; some entry included the candidate from.
1294 (cond ((> (car entry) to)
1295 ;; current entry exceeds end of candidate range - done.
1296 (push (list included-from to) new-ranges)
1297 (push entry new-ranges)
1298 (setq included-to to
1299 done t))
1300 ((>= (cadr entry) to)
1301 ;; current entry includes end of candidate range - done.
1302 (push (list included-from (cadr entry)) new-ranges)
1303 (setq included-to (cadr entry)
1304 done t))
1305 ;; current entry contained in candidate range - ditch, continue:
1306 (t nil)))
1308 ((> (car entry) to)
1309 ;; current entry start exceeds candidate end - done, placed as new entry
1310 (push (list from to) new-ranges)
1311 (push entry new-ranges)
1312 (setq included-to to
1313 done t))
1315 ((>= (car entry) from)
1316 ;; current entry start is above candidate start, but not above
1317 ;; candidate end (by prior case).
1318 (setq included-from from)
1319 ;; now we have to check on whether this entry contains to, or continue:
1320 (when (>= (cadr entry) to)
1321 ;; current entry contains only candidate end - done:
1322 (push (list included-from (cadr entry)) new-ranges)
1323 (setq included-to (cadr entry)
1324 done t))
1325 ;; otherwise, we will continue to look for placement of candidate end.
1328 ((>= (cadr entry) to)
1329 ;; current entry properly contains candidate range.
1330 (push entry new-ranges)
1331 (setq included-from (car entry)
1332 included-to (cadr entry)
1333 done t))
1335 ((>= (cadr entry) from)
1336 ;; current entry contains start of candidate range.
1337 (setq included-from (car entry)))
1340 ;; current entry is below the candidate range.
1341 (push entry new-ranges))))
1343 (cond ((and included-from included-to)
1344 ;; candidates placed.
1345 nil)
1346 ((not (or included-from included-to))
1347 ;; candidates found no place, must be at the end:
1348 (push (list from to) new-ranges))
1349 (included-from
1350 ;; candidate start placed but end not:
1351 (push (list included-from to) new-ranges))
1352 ;; might be included-to and not included-from, indicating new entry.
1354 (setq new-ranges (nreverse new-ranges))
1355 (if ranges (setq new-ranges (append new-ranges ranges)))
1356 (list (if included-from t) new-ranges)))
1357 ;;;_ > allout-test-range-overlaps ()
1358 (defun allout-test-range-overlaps ()
1359 "`allout-range-overlaps' unit tests."
1360 (let* (ranges
1362 (try (lambda (from to)
1363 (setq got (allout-range-overlaps from to ranges))
1364 (setq ranges (cadr got))
1365 got)))
1366 ;; ;; biggie:
1367 ;; (setq ranges nil)
1368 ;; ;; ~ .02 to .1 seconds for just repeated listing args instead of funcall
1369 ;; ;; ~ 13 seconds for doing repeated funcall
1370 ;; (message "time-trial: %s, resulting size %s"
1371 ;; (time-trial
1372 ;; '(let ((size 10000)
1373 ;; doing)
1374 ;; (dotimes (count size)
1375 ;; (setq doing (random size))
1376 ;; (funcall try doing (+ doing (random 5)))
1377 ;; ;;(list doing (+ doing (random 5)))
1378 ;; )))
1379 ;; (length ranges))
1380 ;; (sit-for 2)
1382 ;; fresh:
1383 (setq ranges nil)
1384 (assert (equal (funcall try 3 5) '(nil ((3 5)))))
1385 ;; add range at end:
1386 (assert (equal (funcall try 10 12) '(nil ((3 5) (10 12)))))
1387 ;; add range at beginning:
1388 (assert (equal (funcall try 1 2) '(nil ((1 2) (3 5) (10 12)))))
1389 ;; insert range somewhere in the middle:
1390 (assert (equal (funcall try 7 9) '(nil ((1 2) (3 5) (7 9) (10 12)))))
1391 ;; consolidate some:
1392 (assert (equal (funcall try 5 8) '(t ((1 2) (3 9) (10 12)))))
1393 ;; add more:
1394 (assert (equal (funcall try 15 17) '(nil ((1 2) (3 9) (10 12) (15 17)))))
1395 ;; add more:
1396 (assert (equal (funcall try 20 22)
1397 '(nil ((1 2) (3 9) (10 12) (15 17) (20 22)))))
1398 ;; encompass more:
1399 (assert (equal (funcall try 4 11) '(t ((1 2) (3 12) (15 17) (20 22)))))
1400 ;; encompass all:
1401 (assert (equal (funcall try 2 25) '(t ((1 25)))))
1403 ;; fresh slate:
1404 (setq ranges nil)
1405 (assert (equal (funcall try 20 25) '(nil ((20 25)))))
1406 (assert (equal (funcall try 30 35) '(nil ((20 25) (30 35)))))
1407 (assert (equal (funcall try 26 28) '(nil ((20 25) (26 28) (30 35)))))
1408 (assert (equal (funcall try 15 20) '(t ((15 25) (26 28) (30 35)))))
1409 (assert (equal (funcall try 10 30) '(t ((10 35)))))
1410 (assert (equal (funcall try 5 6) '(nil ((5 6) (10 35)))))
1411 (assert (equal (funcall try 2 100) '(t ((2 100)))))
1413 (setq ranges nil)
1415 ;;;_ > allout-widgetize-buffer (&optional doing)
1416 (defun allout-widgetize-buffer (&optional doing)
1417 "EXAMPLE FUNCTION. Widgetize items in buffer using allout-chart-subtree.
1419 We economize by just focusing on the first of local-maximum depth siblings.
1421 Optional DOING is for internal use - a chart of the current level, for
1422 recursive operation."
1424 (interactive)
1425 (if (not doing)
1427 (save-excursion
1428 (goto-char (point-min))
1429 ;; Construct the chart by scanning the siblings:
1430 (dolist (top-level-sibling (allout-chart-siblings))
1431 (goto-char top-level-sibling)
1432 (let ((subchart (allout-chart-subtree)))
1433 (if subchart
1434 (allout-widgetize-buffer subchart)))))
1436 ;; save-excursion was done on recursion entry, not necessary here.
1437 (let (have-sublists)
1438 (dolist (sibling doing)
1439 (when (listp sibling)
1440 (setq have-sublists t)
1441 (allout-widgetize-buffer sibling)))
1442 (when (and (not have-sublists) (not (widget-at (car doing))))
1443 (goto-char (car doing))
1444 (allout-get-or-create-item-widget)))))
1446 ;;;_ : Item widget and constructors
1448 ;;;_ $ allout-item-widget
1449 (define-widget 'allout-item-widget 'default
1450 "A widget presenting an allout outline item."
1452 'button nil
1453 ;; widget-field-at respects this to get item if 'field is unused.
1454 ;; we don't use field to avoid collision with end-of-line, etc, on which
1455 ;; allout depends.
1456 'real-field nil
1458 ;; data fields:
1461 ;; tailor the widget for a specific item
1462 :create 'allout-decorate-item-and-context
1463 :value-delete 'allout-widgets-undecorate-item
1464 ;; Not Yet Converted (from original, tree-widget stab)
1465 :expander 'allout-tree-event-dispatcher ; get children when nil :args
1466 :expander-p 'identity ; always engage the :expander
1467 :action 'allout-tree-widget-action
1468 ;; :notify "when item changes"
1470 ;; force decoration of item but not context, unless already done this tick:
1471 :redecorate 'allout-redecorate-item
1472 :last-decorated-tick nil
1473 ;; recognize the actual situation of the item's text:
1474 :parse-item 'allout-parse-item-at-point
1475 ;; decorate the entirety of the item, sans offspring:
1476 :decorate-item-span 'allout-decorate-item-span
1477 ;; decorate the various item elements:
1478 :decorate-guides 'allout-decorate-item-guides
1479 :decorate-icon 'allout-decorate-item-icon
1480 :decorate-cue 'allout-decorate-item-cue
1481 :decorate-body 'allout-decorate-item-body
1482 :actual-position 'allout-item-actual-position
1484 ;; Layout parameters:
1485 :is-container nil ; is this actually the encompassing file/connection?
1487 :from nil ; item beginning - marker
1488 :to nil ; item end - marker
1489 :span-overlay nil ; overlay by which actual position is determined
1491 ;; also serves as guide-end:
1492 :icon-start nil
1493 :icon-end nil
1494 :distinctive-start nil
1495 ;; also serves as cue-start:
1496 :distinctive-end nil
1497 ;; also serves as cue-end:
1498 :body-start nil
1499 :body-end nil
1500 :depth nil
1501 :has-subitems nil
1502 :was-has-subitems 'init
1503 :expanded nil
1504 :was-expanded 'init
1505 :brief nil
1506 :was-brief 'init
1508 :does-encrypt nil ; pending encryption when :is-encrypted false.
1509 :is-encrypted nil
1511 ;; the actual location of the item text:
1512 :location 'allout-item-location
1514 :button-keymap allout-item-icon-keymap ; XEmacs
1515 :keymap allout-item-icon-keymap ; Emacs
1517 ;; Element regions:
1518 :guides-span nil
1519 :icon-span nil
1520 :cue-span nil
1521 :bullet nil
1522 :was-bullet nil
1523 :body-span nil
1525 :body-brevity-p 'allout-body-brevity-p
1527 ;; :guide-column-flags indicate (in reverse order) whether or not the
1528 ;; item's ancestor at the depth corresponding to the column has a
1529 ;; subsequent sibling - ie, whether or not the corresponding column needs
1530 ;; a descender line to connect that ancestor with its sibling.
1531 :guide-column-flags nil
1532 :was-guide-column-flags 'init
1534 ;; ie, has subitems:
1535 :populous-p 'allout-item-populous-p
1536 :help-echo 'allout-tree-widget-help-echo
1538 ;;;_ > allout-new-item-widget ()
1539 (defsubst allout-new-item-widget ()
1540 "create a new item widget, not yet situated anywhere."
1541 (if allout-widgets-maintain-tally
1542 ;; all the extra overhead is incurred only when doing the
1543 ;; maintenance, except the condition, which can't be avoided.
1544 (let ((widget (widget-convert 'allout-item-widget)))
1545 (puthash widget nil allout-widgets-tally)
1546 widget)
1547 (widget-convert 'allout-item-widget)))
1548 ;;;_ : Item decoration
1549 ;;;_ > allout-decorate-item-and-context (item-widget &optional redecorate
1550 ;;; blank-container parent)
1551 (defun allout-decorate-item-and-context (item-widget &optional redecorate
1552 blank-container _parent)
1553 "Create or adjust widget decorations for ITEM-WIDGET and neighbors at point.
1555 The neighbors include its siblings and parent.
1557 ITEM-WIDGET can be a created or converted `allout-item-widget'.
1559 If you're only trying to get or create a widget for an item, use
1560 `allout-get-or-create-item-widget'. If you have the item-widget, applying
1561 :redecorate will do the right thing.
1563 Optional BLANK-CONTAINER is for internal use. It is used to fabricate a
1564 container widget for an empty-bodied container, in the course of decorating
1565 a proper (non-container) item which starts at the beginning of the file.
1567 Optional REDECORATE causes redecoration of the item-widget and
1568 its siblings, even if already decorated in this cycle of the command loop.
1570 Optional PARENT, when provided, bypasses some navigation and computation
1571 necessary to obtain the parent of the items being processed.
1573 We return the item-widget corresponding to the item at point."
1575 (when (or redecorate
1576 (not (equal (widget-get item-widget :last-decorated-tick)
1577 allout-command-counter)))
1578 (let* ((allout-inhibit-body-modification-hook t)
1579 (was-modified (buffer-modified-p))
1580 (was-point (point))
1581 prefix-start
1582 (is-container (or blank-container
1583 (not (setq prefix-start (allout-goto-prefix)))
1584 (< was-point prefix-start)))
1585 ;; steady-point (set in two steps) is reliable across parent
1586 ;; widget-creation.
1587 (steady-point (progn (if is-container (goto-char 1))
1588 (point-marker)))
1589 (steady-point (progn (set-marker-insertion-type steady-point t)
1590 steady-point))
1591 (parent (and (not is-container)
1592 (allout-get-or-create-parent-widget)))
1593 successor-sibling
1594 doing-item
1595 reverse-siblings-chart
1596 (buffer-undo-list t))
1598 ;; At this point the parent is decorated and parent-flags indicate
1599 ;; its guide lines. We will iterate over the siblings according to a
1600 ;; chart we create at the start, and going from last to first so we
1601 ;; don't have to worry about text displacement caused by widgetizing.
1603 (if is-container
1604 (progn (widget-put item-widget :is-container t)
1605 (setq reverse-siblings-chart (list 1)))
1606 (goto-char (widget-apply parent :actual-position :from))
1607 (if (widget-get parent :is-container)
1608 ;; `allout-goto-prefix' will go to first non-container item:
1609 (allout-goto-prefix)
1610 (allout-next-heading))
1611 (setq reverse-siblings-chart (list allout-recent-prefix-beginning))
1612 (while (allout-next-sibling)
1613 (push allout-recent-prefix-beginning reverse-siblings-chart)))
1615 (dolist (doing-at reverse-siblings-chart)
1616 (goto-char doing-at)
1617 (when allout-widgets-track-decoration
1618 (sit-for 0))
1620 (setq doing-item (if (= doing-at steady-point)
1621 item-widget
1622 (or (allout-get-item-widget)
1623 (allout-new-item-widget))))
1625 (when (or redecorate (not (equal (widget-get doing-item
1626 :last-decorated-tick)
1627 allout-command-counter)))
1628 (widget-apply doing-item :parse-item t blank-container)
1629 (widget-apply doing-item :decorate-item-span)
1631 (widget-apply doing-item :decorate-guides
1632 parent (and successor-sibling t))
1633 (widget-apply doing-item :decorate-icon)
1634 (widget-apply doing-item :decorate-cue)
1635 (widget-apply doing-item :decorate-body)
1637 (widget-put doing-item :last-decorated-tick allout-command-counter))
1639 (setq successor-sibling doing-at))
1641 (set-buffer-modified-p was-modified)
1642 (goto-char steady-point)
1643 ;; must null the marker or the buffer gets clogged with impedance:
1644 (set-marker steady-point nil)
1646 item-widget)))
1647 ;;;_ > allout-redecorate-item (item)
1648 (defun allout-redecorate-item (item-widget)
1649 "Resituate ITEM-WIDGET decorations, disregarding context.
1651 Use this to redecorate only the item, when you know that its
1652 situation with respect to siblings, parent, and offspring is
1653 unchanged from its last decoration. Use
1654 `allout-decorate-item-and-context' instead to reassess and adjust
1655 relevant context, when suitable."
1656 (if (not (equal (widget-get item-widget :last-decorated-tick)
1657 allout-command-counter))
1658 (let ((was-modified (buffer-modified-p))
1659 (buffer-undo-list t))
1660 (widget-apply item-widget :parse-item)
1661 (widget-apply item-widget :decorate-guides)
1662 (widget-apply item-widget :decorate-icon)
1663 (widget-apply item-widget :decorate-cue)
1664 (widget-apply item-widget :decorate-body)
1665 (set-buffer-modified-p was-modified))))
1666 ;;;_ > allout-redecorate-visible-subtree (&optional parent-widget
1667 ;;; depth chart)
1668 (defun allout-redecorate-visible-subtree (&optional parent-widget depth chart)
1669 "Redecorate all visible items in subtree at point.
1671 Optional PARENT-WIDGET is for optimization, when the parent
1672 widget is already available.
1674 Optional DEPTH restricts the excursion depth of covered.
1676 Optional CHART is for internal recursion, to carry a chart of the
1677 target items.
1679 Point is left at the last sibling in the visible subtree."
1680 ;; using a treatment that takes care of all the siblings on a level, we
1681 ;; only need apply it to the first sibling on the level, and we can
1682 ;; collect and pass the parent of the lower levels to recursive calls as
1683 ;; we go.
1684 (let ((parent-widget
1685 (if (and parent-widget (widget-apply parent-widget
1686 :actual-position :from))
1687 (progn (goto-char (widget-apply parent-widget
1688 :actual-position :from))
1689 parent-widget)
1690 (let ((got (allout-get-item-widget)))
1691 (if got
1692 (allout-decorate-item-and-context got 'redecorate)
1693 (allout-get-or-create-item-widget 'redecorate)))))
1694 (pending-chart (or chart (allout-chart-subtree nil 'visible)))
1695 item-widget
1696 previous-sibling-point
1697 recent-sibling-point)
1698 (setq pending-chart (nreverse pending-chart))
1699 (dolist (sibling-point pending-chart)
1700 (cond ((integerp sibling-point)
1701 (when (not previous-sibling-point)
1702 (goto-char sibling-point)
1703 (if (setq item-widget (allout-get-item-widget nil))
1704 (allout-decorate-item-and-context item-widget 'redecorate
1705 nil parent-widget)
1706 (allout-get-or-create-item-widget)))
1707 (setq previous-sibling-point sibling-point
1708 recent-sibling-point sibling-point))
1709 ((listp sibling-point)
1710 (if (or (not depth)
1711 (> depth 1))
1712 (allout-redecorate-visible-subtree
1713 (if (not previous-sibling-point)
1714 ;; containment discontinuity - sigh
1715 parent-widget
1716 (allout-get-or-create-item-widget 'redecorate))
1717 (if depth (1- depth))
1718 sibling-point)))))
1719 (if (and recent-sibling-point (< (point) recent-sibling-point))
1720 (goto-char recent-sibling-point))))
1721 ;;;_ > allout-parse-item-at-point (item-widget &optional at-beginning
1722 ;;; blank-container)
1723 (defun allout-parse-item-at-point (item-widget &optional at-beginning
1724 blank-container)
1725 "Set widget ITEM-WIDGET layout parameters per item-at-point's actual layout.
1727 If optional AT-BEGINNING is t, then point is assumed to be at the start of
1728 the item prefix.
1730 If optional BLANK-CONTAINER is true, then the parameters of a container
1731 which has an empty body are set. (Though the body is blank, the object
1732 may have subitems.)"
1734 ;; Uncomment this sit-for to notice where decoration is happening:
1735 ;; (sit-for .1)
1736 (let* ((depth (allout-depth))
1737 (depth (if blank-container 0 depth))
1738 (is-container (or blank-container (zerop depth)))
1740 (does-encrypt (and (not is-container)
1741 (allout-encrypted-type-prefix)))
1742 (is-encrypted (and does-encrypt (allout-encrypted-topic-p)))
1743 (icon-end allout-recent-prefix-end)
1744 (icon-start (1- icon-end))
1745 body-start
1746 body-end
1747 has-subitems
1749 (widget-put item-widget :depth depth)
1750 (if is-container
1752 (progn
1753 (widget-put item-widget :from (allout-set-boundary-marker
1754 :from (point-min)
1755 (widget-get item-widget :from)))
1756 (widget-put item-widget :icon-end nil)
1757 (widget-put item-widget :icon-start nil)
1758 (setq body-start (widget-put item-widget :body-start 1)))
1760 ;; not container:
1762 (widget-put item-widget :from (allout-set-boundary-marker
1763 :from (if at-beginning
1764 (point)
1765 allout-recent-prefix-beginning)
1766 (widget-get item-widget :from)))
1767 (widget-put item-widget :icon-start icon-start)
1768 (widget-put item-widget :icon-end icon-end)
1769 (when does-encrypt
1770 (widget-put item-widget :does-encrypt t)
1771 (widget-put item-widget :is-encrypted is-encrypted))
1773 ;; cue area:
1774 (setq body-start icon-end)
1775 (widget-put item-widget :bullet (allout-get-bullet))
1776 (if (equal (char-after body-start) ? )
1777 (setq body-start (1+ body-start)))
1778 (widget-put item-widget :body-start body-start)
1781 ;; Both container and regular items:
1783 ;; :body-end (doesn't include a trailing blank line, if any) -
1784 (widget-put item-widget :body-end (setq body-end
1785 (if blank-container
1787 (allout-end-of-entry))))
1789 (widget-put item-widget :to (allout-set-boundary-marker
1790 :to (if blank-container
1791 (point-min)
1792 (or (allout-pre-next-prefix)
1793 (goto-char (point-max))))
1794 (widget-get item-widget :to)))
1795 (widget-put item-widget :has-subitems
1796 (setq has-subitems
1797 (and
1798 ;; has a subsequent item:
1799 (not (= body-end (point-max)))
1800 ;; subsequent item is deeper:
1801 (< depth (allout-recent-depth)))))
1802 ;; note :expanded - true if widget item's content is currently visible?
1803 (widget-put item-widget :expanded
1804 (and has-subitems
1805 ;; subsequent item is or isn't visible:
1806 (save-excursion
1807 (goto-char allout-recent-prefix-beginning)
1808 (not (allout-hidden-p)))))))
1809 ;;;_ > allout-set-boundary-marker (boundary position &optional current-marker)
1810 (defun allout-set-boundary-marker (_boundary position &optional current-marker)
1811 "Set or create item widget BOUNDARY type marker at POSITION.
1813 Optional CURRENT-MARKER is the marker currently being used for
1814 the boundary, if any.
1816 BOUNDARY type is either :from or :to, determining the marker insertion type."
1817 (if (not position) (setq position (point)))
1818 (if current-marker
1819 (set-marker current-marker position)
1820 (let ((marker (make-marker)))
1821 ;; XXX dang - would like for :from boundary to advance after inserted
1822 ;; text, but that would omit new header prefixes when allout
1823 ;; relevels, etc. this competes with ad-hoc edits, which would
1824 ;; better be omitted
1825 (set-marker-insertion-type marker nil)
1826 (set-marker marker position))))
1827 ;;;_ > allout-decorate-item-span (item-widget)
1828 (defun allout-decorate-item-span (item-widget)
1829 "Equip the item with a span, as an entirety.
1831 This span is implemented so it can be used to detect displacement
1832 of the widget in absolute terms, and provides an offset bias for
1833 the various element spans."
1835 (if (and (widget-get item-widget :is-container)
1836 ;; the only case where the span could be empty.
1837 (eq (widget-get item-widget :from)
1838 (widget-get item-widget :to)))
1840 (allout-item-span item-widget
1841 (widget-get item-widget :from)
1842 (widget-get item-widget :to))))
1843 ;;;_ > allout-decorate-item-guides (item-widget
1844 ;;; &optional parent-widget has-successor)
1845 (defun allout-decorate-item-guides (item-widget
1846 &optional parent-widget has-successor)
1847 "Add ITEM-WIDGET guide icon-prefix descender and connector text properties.
1849 Optional arguments provide context for deriving the guides.
1850 In their absence, the current guide column flags are used.
1852 Optional PARENT-WIDGET is the widget for the item's parent item.
1854 Optional HAS-SUCCESSOR is true if the item is followed by a sibling.
1856 We also hide the header-prefix string.
1858 Guides are established according to the item-widget's :guide-column-flags,
1859 when different than :was-guide-column-flags. Changing that property and
1860 reapplying this method will rectify the glyphs."
1862 (when (not (widget-get item-widget :is-container))
1863 (let* ((depth (widget-get item-widget :depth))
1864 ;; (parent-depth (and parent-widget
1865 ;; (widget-get parent-widget :depth)))
1866 (parent-flags (and parent-widget
1867 (widget-get parent-widget :guide-column-flags)))
1868 (parent-flags-depth (length parent-flags))
1869 (extender-length (- depth (+ parent-flags-depth 2)))
1870 (flags (or (and (> depth 1)
1871 parent-widget
1872 (widget-put item-widget :guide-column-flags
1873 (append (list has-successor)
1874 (if (< 0 extender-length)
1875 (make-list extender-length
1876 '-))
1877 parent-flags)))
1878 (widget-get item-widget :guide-column-flags)))
1879 (was-flags (widget-get item-widget :was-guide-column-flags))
1880 (guides-start (widget-get item-widget :from))
1881 (guides-end (widget-get item-widget :icon-start))
1882 (position guides-start)
1883 (increment (length allout-header-prefix))
1884 reverse-flags
1885 guide-name
1886 extenders
1887 (inhibit-read-only t))
1889 (when (not (equal was-flags flags))
1891 (setq reverse-flags (reverse flags))
1892 (while reverse-flags
1893 (setq guide-name
1894 (cond ((null (cdr reverse-flags))
1895 (if (car reverse-flags)
1896 'mid-connector
1897 'end-connector))
1898 ((eq (car reverse-flags) '-)
1899 ;; accumulate extenders tally, to be painted on next
1900 ;; non-extender flag, according to the flag type.
1901 (setq extenders (1+ (or extenders 0)))
1902 nil)
1903 ((car reverse-flags)
1904 'through-descender)
1905 (t 'skip-descender)))
1906 (when guide-name
1907 (put-text-property position (setq position (+ position increment))
1908 'display (allout-fetch-icon-image guide-name))
1909 (if (> increment 1) (setq increment 1))
1910 (when extenders
1911 ;; paint extenders after a connector, else leave spaces.
1912 (dotimes (i extenders)
1913 (put-text-property
1914 position (setq position (1+ position))
1915 'display (allout-fetch-icon-image
1916 (if (memq guide-name '(mid-connector end-connector))
1917 'extender-connector
1918 'skip-descender))))
1919 (setq extenders nil)))
1920 (setq reverse-flags (cdr reverse-flags)))
1921 (widget-put item-widget :was-guide-column-flags flags))
1923 (allout-item-element-span-is item-widget :guides-span
1924 guides-start guides-end))))
1925 ;;;_ > allout-decorate-item-icon (item-widget)
1926 (defun allout-decorate-item-icon (item-widget)
1927 "Add item icon glyph and distinctive bullet text properties to ITEM-WIDGET."
1929 (when (not (widget-get item-widget :is-container))
1930 (let* ((icon-start (widget-get item-widget :icon-start))
1931 (icon-end (widget-get item-widget :icon-end))
1932 (bullet (widget-get item-widget :bullet))
1933 (use-bullet bullet)
1934 (was-bullet (widget-get item-widget :was-bullet))
1935 (distinctive (allout-distinctive-bullet bullet))
1936 (distinctive-start (widget-get item-widget :distinctive-start))
1937 (distinctive-end (widget-get item-widget :distinctive-end))
1938 (does-encrypt (widget-get item-widget :does-encrypt))
1939 (is-encrypted (and does-encrypt (widget-get item-widget
1940 :is-encrypted)))
1941 (expanded (widget-get item-widget :expanded))
1942 (has-subitems (widget-get item-widget :has-subitems))
1943 (inhibit-read-only t)
1944 icon-state)
1946 (when (not (and (equal (widget-get item-widget :was-expanded) expanded)
1947 (equal (widget-get item-widget :was-has-subitems)
1948 has-subitems)
1949 (equal (widget-get item-widget :was-does-encrypt)
1950 does-encrypt)
1951 (equal (widget-get item-widget :was-is-encrypted)
1952 is-encrypted)))
1954 (setq icon-state
1955 (cond (does-encrypt (if is-encrypted
1956 'locked-encrypted
1957 'unlocked-encrypted))
1958 (expanded 'opened)
1959 (has-subitems 'closed)
1960 (t 'empty)))
1961 (put-text-property icon-start (1+ icon-start)
1962 'display (allout-fetch-icon-image icon-state))
1963 (widget-put item-widget :was-expanded expanded)
1964 (widget-put item-widget :was-has-subitems has-subitems)
1965 (widget-put item-widget :was-does-encrypt does-encrypt)
1966 (widget-put item-widget :was-is-encrypted is-encrypted)
1967 ;; preserve as a widget property to track last known:
1968 (widget-put item-widget :icon-state icon-state)
1969 ;; preserve as a text property to track undo:
1970 (put-text-property icon-start icon-end :icon-state icon-state))
1971 (allout-item-element-span-is item-widget :icon-span
1972 icon-start icon-end)
1973 (when (not (string= was-bullet bullet))
1974 (cond ((not distinctive)
1975 ;; XXX we strip the prior properties without even checking if
1976 ;; the prior bullet was distinctive, because the widget
1977 ;; provisions to convey that info is disappearing, sigh.
1978 (remove-text-properties icon-end (1+ icon-end) '(display))
1979 (setq distinctive-start icon-end distinctive-end icon-end)
1980 (widget-put item-widget :distinctive-start distinctive-start)
1981 (widget-put item-widget :distinctive-end distinctive-end))
1983 ((not (string= bullet allout-numbered-bullet))
1984 (setq distinctive-start icon-end distinctive-end (+ icon-end 1)))
1986 (does-encrypt
1987 (setq distinctive-start icon-end distinctive-end (+ icon-end 1)))
1990 (goto-char icon-end)
1991 (looking-at "[0-9]+")
1992 (setq use-bullet (buffer-substring icon-end (match-end 0)))
1993 (setq distinctive-start icon-end
1994 distinctive-end (match-end 0))))
1995 (put-text-property distinctive-start distinctive-end 'display
1996 use-bullet)
1997 (widget-put item-widget :was-bullet bullet)
1998 (widget-put item-widget :distinctive-start distinctive-start)
1999 (widget-put item-widget :distinctive-end distinctive-end)))))
2000 ;;;_ > allout-decorate-item-cue (item-widget)
2001 (defun allout-decorate-item-cue (item-widget)
2002 "Incorporate space between bullet icon and body to the ITEM-WIDGET."
2003 ;; NOTE: most of the cue-area
2005 (when (not (widget-get item-widget :is-container))
2006 (let* ((cue-start (or (widget-get item-widget :distinctive-end)
2007 (widget-get item-widget :icon-end)))
2008 (body-start (widget-get item-widget :body-start))
2009 ;(expanded (widget-get item-widget :expanded))
2010 ;(has-subitems (widget-get item-widget :has-subitems))
2011 (inhibit-read-only t))
2013 (allout-item-element-span-is item-widget :cue-span cue-start body-start)
2014 (put-text-property (1- body-start) body-start 'rear-nonsticky t))))
2015 ;;;_ > allout-decorate-item-body (item-widget &optional force)
2016 (defun allout-decorate-item-body (item-widget &optional force)
2017 "Incorporate item body text as part the ITEM-WIDGET.
2019 Optional FORCE means force reassignment of the region property."
2021 (let* ((allout-inhibit-body-modification-hook t)
2022 (body-start (widget-get item-widget :body-start))
2023 (body-end (widget-get item-widget :body-end))
2024 (inhibit-read-only t))
2026 (allout-item-element-span-is item-widget :body-span
2027 body-start (min (1+ body-end) (point-max))
2028 force)))
2029 ;;;_ > allout-item-actual-position (item-widget field)
2030 (defun allout-item-actual-position (item-widget field)
2031 "Return ITEM-WIDGET FIELD position taking item displacement into account."
2033 ;; The item's sub-element positions (:icon-end, :body-start, etc) are
2034 ;; accurate when the item is parsed, but some offsets from the start
2035 ;; drift with text added in the body.
2037 ;; Rather than reparse an item with every change (inefficient), or derive
2038 ;; every position from a distinct field marker/overlay (prohibitive as
2039 ;; the number of items grows), we use the displacement tracking of the
2040 ;; :span-overlay's markers, against the registered :from or :body-end
2041 ;; (depending on whether the requested field value is before or after the
2042 ;; item body), to bias the registered values.
2044 ;; This is not necessary/useful when the item is being decorated, because
2045 ;; that always must be preceded by a fresh item parse.
2047 (if (not (eq field :body-end))
2048 (widget-get item-widget :from)
2050 (let* ((span-overlay (widget-get item-widget :span-overlay))
2051 (body-end-position (widget-get item-widget :body-end))
2052 (ref-marker-position (and span-overlay
2053 (overlay-end span-overlay)))
2054 (offset (and body-end-position span-overlay
2055 (- (or ref-marker-position 0)
2056 body-end-position))))
2057 (+ (widget-get item-widget field) (or offset 0)))))
2058 ;;;_ : Item undecoration
2059 ;;;_ > allout-widgets-undecorate-region (start end)
2060 (defun allout-widgets-undecorate-region (start end)
2061 "Eliminate widgets and decorations for all items in region from START to END."
2062 (let ((next start)
2063 widget)
2064 (save-excursion
2065 (goto-char start)
2066 (while (< (setq next (next-single-char-property-change next
2067 'display
2068 (current-buffer)
2069 end))
2070 end)
2071 (goto-char next)
2072 (when (setq widget (allout-get-item-widget))
2073 ;; if the next-property/overly progression got us to a widget:
2074 (allout-widgets-undecorate-item widget t))))))
2075 ;;;_ > allout-widgets-undecorate-text (text)
2076 (defun allout-widgets-undecorate-text (text)
2077 "Eliminate widgets and decorations for all items in TEXT."
2078 (remove-text-properties 0 (length text)
2079 '(display nil :icon-state nil rear-nonsticky nil
2080 category nil button nil field nil)
2081 text)
2082 text)
2083 ;;;_ > allout-widgets-undecorate-item (item-widget &optional no-expose)
2084 (defun allout-widgets-undecorate-item (item-widget &optional no-expose)
2085 "Remove widget decorations from ITEM-WIDGET.
2087 Any concealed content head lines and item body is exposed, unless
2088 optional NO-EXPOSE is non-nil."
2089 (let ((from (widget-get item-widget :from))
2090 (to (widget-get item-widget :to))
2091 (text-properties-to-remove '(display nil
2092 :icon-state nil
2093 rear-nonsticky nil
2094 category nil
2095 button nil
2096 field nil))
2097 (span-overlay (widget-get item-widget :span-overlay))
2098 (button-overlay (widget-get item-widget :button))
2099 (was-modified (buffer-modified-p))
2100 (buffer-undo-list t)
2101 (inhibit-read-only t))
2102 (if (not no-expose)
2103 (allout-flag-region from to nil))
2104 (allout-unprotected
2105 (remove-text-properties from to text-properties-to-remove))
2106 (when span-overlay
2107 (delete-overlay span-overlay) (widget-put item-widget :span-overlay nil))
2108 (when button-overlay
2109 (delete-overlay button-overlay) (widget-put item-widget :button nil))
2110 (set-marker from nil)
2111 (set-marker to nil)
2112 (if (not was-modified)
2113 (set-buffer-modified-p nil))))
2115 ;;;_ : Item decoration support
2116 ;;;_ > allout-item-span (item-widget &optional start end)
2117 (defun allout-item-span (item-widget &optional start end)
2118 "Return or register the location of an ITEM-WIDGET's actual START and END.
2120 If START and END are not passed in, return either a dotted pair
2121 of the current span, if established, or nil if not yet set.
2123 When the START and END are passed, return the distance that the
2124 start of the item moved. We return 0 if the span was not
2125 previously established or is not moved."
2126 (let ((overlay (widget-get item-widget :span-overlay)))
2127 (cond ((not overlay) (when start
2128 (setq overlay (make-overlay start end nil t nil))
2129 (overlay-put overlay 'button item-widget)
2130 (overlay-put overlay 'evaporate t)
2131 (widget-put item-widget :span-overlay overlay)
2133 ;; report:
2134 ((not start) (cons (overlay-start overlay) (overlay-end overlay)))
2135 ;; move:
2136 ((or (not (equal (overlay-start overlay) start))
2137 (not (equal (overlay-end overlay) end)))
2138 (move-overlay overlay start end)
2140 ;; specified span already set:
2141 (t nil))))
2142 ;;;_ > allout-item-element-span-is (item-widget element
2143 ;;; &optional start end force)
2144 (defun allout-item-element-span-is (item-widget element
2145 &optional start end force)
2146 "Return or register the location of the indicated ITEM-WIDGET ELEMENT.
2148 ELEMENT is one of :guides-span, :icon-span, :cue-span, or :body-span.
2150 When optional START is specified, optional END must also be.
2152 START and END are the actual bounds of the region, if provided.
2154 If START and END are not passed in, we return either a dotted
2155 pair of the current span, if established, or nil if not yet set.
2157 When the START and END are passed, we return t if the region
2158 changed or nil if not.
2160 Optional FORCE means force assignment of the region's text
2161 property, even if it's already set."
2162 (let ((span (widget-get item-widget element)))
2163 (cond ((or (not span) force)
2164 (when start
2165 (widget-put item-widget element (cons start end))
2166 (put-text-property start end 'category
2167 (cdr (assoc element
2168 allout-span-to-category)))
2170 ;; report:
2171 ((not start) span)
2172 ;; move if necessary:
2173 ((not (and (eq (car span) start)
2174 (eq (cdr span) end)))
2175 (widget-put item-widget element span)
2177 ;; specified span already set:
2178 (t nil))))
2179 ;;;_ : Item widget retrieval (/ high-level creation):
2180 ;;;_ > allout-get-item-widget (&optional container)
2181 (defun allout-get-item-widget (&optional container)
2182 "Return the widget for the item at point, or nil if no widget yet exists.
2184 Point must be situated *before* the start of the target item's
2185 body, so we don't get an existing containing item when we're in
2186 the process of creating an item in the middle of another.
2188 Optional CONTAINER is used to obtain the container item."
2189 (if (or container (zerop (allout-depth)))
2190 allout-container-item-widget
2191 ;; allout-recent-* are calibrated by (allout-depth) if we got here.
2192 (let ((got (widget-at allout-recent-prefix-beginning)))
2193 (if (and got (listp got))
2194 (if (marker-position (widget-get got :from))
2195 (and
2196 (>= (point) (widget-apply got :actual-position :from))
2197 (<= (point) (widget-apply got :actual-position :body-start))
2198 got)
2199 ;; a wacky residual item - undecorate and disregard:
2200 (allout-widgets-undecorate-item got)
2201 nil)))))
2202 ;;;_ > allout-get-or-create-item-widget (&optional redecorate blank-container)
2203 (defun allout-get-or-create-item-widget (&optional redecorate blank-container)
2204 "Return a widget for the item at point, creating the widget if necessary.
2206 When creating a widget, we assume there has been a context change
2207 and decorate its siblings and parent, as well.
2209 Optional BLANK-CONTAINER is for internal use, to fabricate a
2210 meta-container item with an empty body when the first proper
2211 \(non-container) item starts at the beginning of the file.
2213 Optional REDECORATE, if non-nil, means to redecorate the widget
2214 if it already exists."
2215 (let ((widget (allout-get-item-widget blank-container))
2216 (buffer-undo-list t))
2217 (cond (widget (if redecorate
2218 (allout-redecorate-item widget))
2219 widget)
2220 ((or blank-container (zerop (allout-depth)))
2221 (or allout-container-item-widget
2222 (setq allout-container-item-widget
2223 (allout-decorate-item-and-context
2224 (widget-convert 'allout-item-widget)
2225 nil blank-container))))
2226 ;; create a widget for a regular/non-container item:
2227 (t (allout-decorate-item-and-context (widget-convert
2228 'allout-item-widget))))))
2229 ;;;_ > allout-get-or-create-parent-widget (&optional redecorate)
2230 (defun allout-get-or-create-parent-widget (&optional redecorate)
2231 "Return widget for parent of item at point, decorating it if necessary.
2233 We return the container widget if we're above the first proper item in the
2234 file.
2236 Optional REDECORATE, if non-nil, means to redecorate the widget if it
2237 already exists.
2239 Point will wind up positioned on the beginning of the parent or beginning
2240 of the buffer."
2241 ;; use existing widget, if there, else establish it
2242 (if (or (bobp) (and (not (allout-ascend))
2243 (looking-at-p allout-regexp)))
2244 (allout-get-or-create-item-widget redecorate 'blank-container)
2245 (allout-get-or-create-item-widget redecorate)))
2246 ;;;_ : X- Item ancillaries
2247 ;;;_ >X allout-body-modification-handler (beg end)
2248 (defun allout-body-modification-handler (_beg _end)
2249 "Do routine processing of body text before and after modification.
2251 Operation is inhibited by `allout-inhibit-body-modification-handler'."
2253 ;; The primary duties are:
2255 ;; - marking of escaped prefix-like text for delayed cleanup of escapes
2256 ;; - removal and replacement of the settings
2257 ;; - maintenance of beginning-of-line guide lines
2259 ;; ?? Escapes removal (before changes) is not done when edits span multiple
2260 ;; items, recognizing that item structure is being preserved, including
2261 ;; escaping of item-prefix-like text within bodies. See
2262 ;; `allout-before-modification-handler' and
2263 ;; `allout-inhibit-body-modification-handler'.
2265 ;; Adds the overlay to the `allout-unresolved-body-mod-workhash' during
2266 ;; before-change operation, and removes from that list during after-change
2267 ;; operation.
2268 (cond (allout-inhibit-body-modification-hook nil)))
2269 ;;;_ >X allout-graphics-modification-handler (beg end)
2270 (defun allout-graphics-modification-handler (beg _end)
2271 "Protect against incoherent deletion of decoration graphics.
2273 Deletes allowed only when `inhibit-read-only' is t."
2274 (cond
2275 (undo-in-progress (when (eq (get-text-property beg 'category)
2276 'allout-icon-span-category)
2277 (save-excursion
2278 (goto-char beg)
2279 (let* ((item-widget (allout-get-item-widget)))
2280 (if item-widget
2281 (allout-widgets-exposure-undo-recorder
2282 item-widget))))))
2283 (inhibit-read-only t)
2284 ((not (and (boundp 'allout-mode) allout-mode)) t)
2285 ((equal this-command 'quoted-insert) t)
2286 ((yes-or-no-p "Unruly edit of outline structure - allow? ")
2287 (setq allout-widgets-unset-inhibit-read-only (not inhibit-read-only)
2288 inhibit-read-only t))
2289 (t (error "%s"
2290 (substitute-command-keys allout-structure-unruly-deletion-message)))))
2291 ;;;_ > allout-item-icon-key-handler ()
2292 (defun allout-item-icon-key-handler ()
2293 "Catchall handling of key bindings in item icon/cue hot-spots.
2295 Applies `allout-hotspot-key-handler' and calls the result, if any, as an
2296 interactive command."
2298 (interactive)
2299 (let* ((mapped-binding (allout-hotspot-key-handler)))
2300 (when mapped-binding
2301 (call-interactively mapped-binding))))
2303 ;;;_ : Status
2304 ;;;_ . allout-item-location (item-widget)
2305 (defun allout-item-location (item-widget)
2306 "Location of the start of the item's text."
2307 (overlay-start (widget-get item-widget :span-overlay)))
2309 ;;;_ : Icon management
2310 ;;;_ > allout-fetch-icon-image (name)
2311 (defun allout-fetch-icon-image (name)
2312 "Fetch allout icon for symbol NAME.
2314 We use a caching strategy, so the caller doesn't need to do so."
2315 (let* ((types allout-widgets-icon-types)
2316 (use-dir (if (equal (allout-frame-property nil 'background-mode)
2317 'light)
2318 allout-widgets-icons-light-subdir
2319 allout-widgets-icons-dark-subdir))
2320 (key (list name use-dir))
2321 (got (assoc key allout-widgets-icons-cache)))
2322 (if got
2323 ;; display system shows only first of subsequent adjacent
2324 ;; `eq'-identical repeats - use copies to avoid this problem.
2325 (allout-widgets-copy-list (cadr got))
2326 (while (and types (not got))
2327 (setq got
2328 (allout-find-image
2329 (list (append (list :type (car types)
2330 :file (concat use-dir
2331 (symbol-name name)
2332 "." (symbol-name
2333 (car types))))
2334 (if (featurep 'xemacs)
2335 allout-widgets-item-image-properties-xemacs
2336 allout-widgets-item-image-properties-emacs)
2337 ))))
2338 (setq types (cdr types)))
2339 (if got
2340 (push (list key got) allout-widgets-icons-cache))
2341 got)))
2343 ;;;_ : Miscellaneous
2344 ;;;_ > allout-elapsed-time-seconds (time-value time-value)
2345 (defun allout-elapsed-time-seconds (end start)
2346 "Return seconds between START/END time values."
2347 (let ((elapsed (time-subtract end start)))
2348 (float-time elapsed)))
2349 ;;;_ > allout-frame-property (frame property)
2350 (defalias 'allout-frame-property
2351 (cond ((fboundp 'frame-parameter)
2352 'frame-parameter)
2353 ((fboundp 'frame-property)
2354 'frame-property)
2355 (t nil)))
2356 ;;;_ > allout-find-image (specs)
2357 (defalias 'allout-find-image
2358 (if (fboundp 'find-image)
2359 'find-image
2360 nil) ; aka, not-yet-implemented for xemacs.
2362 ;;;_ > allout-widgets-copy-list (list)
2363 (defun allout-widgets-copy-list (list)
2364 ;; duplicated from cl.el 'copy-list' as of 2008-08-17
2365 "Return a copy of LIST, which may be a dotted list.
2366 The elements of LIST are not copied, just the list structure itself."
2367 (if (consp list)
2368 (let ((res nil))
2369 (while (consp list) (push (pop list) res))
2370 (prog1 (nreverse res) (setcdr res list)))
2371 (car list)))
2372 ;;;_ . allout-widgets-count-buttons-in-region (start end)
2373 (defun allout-widgets-count-buttons-in-region (start end)
2374 "Debugging/diagnostic tool - count overlays with `button' property in region."
2375 (interactive "r")
2376 (setq start (or start (point-min))
2377 end (or end (point-max)))
2378 (if (> start end) (let ((interim start)) (setq start end end interim)))
2379 (let ((button-overlays (delq nil
2380 (mapcar (function (lambda (o)
2381 (if (overlay-get o 'button)
2382 o)))
2383 (overlays-in start end)))))
2384 (length button-overlays)))
2386 ;;;_ : Run unit tests:
2387 (defun allout-widgets-run-unit-tests ()
2388 (message "Running allout-widget tests...")
2390 (allout-test-range-overlaps)
2392 (message "Running allout-widget tests... Done.")
2393 (sit-for .5))
2395 (when allout-widgets-run-unit-tests-on-load
2396 (allout-widgets-run-unit-tests))
2398 ;;;_ : provide
2399 (provide 'allout-widgets)
2401 ;;;_. Local emacs vars.
2402 ;;;_ , Local variables:
2403 ;;;_ , allout-layout: (-1 : 0)
2404 ;;;_ , End: