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