lisp/progmodes/python.el: Updated Copyright years.
[emacs.git] / lisp / allout-widgets.el
blob962a8fb557ac6addaabae1acef0d6605ab882840
1 ;; allout-widgets.el --- Visually highlight allout outline structure.
3 ;; Copyright (C) 2005-2012 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 disable allout-widgets-mode."
654 (allout-widgets-mode 1))
655 ;;;_ > allout-setup-text-properties ()
656 (defun allout-setup-text-properties ()
657 "Configure category and literal text properties."
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 failure
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 err
815 (yes-or-no-p
816 (concat "Misplaced item won't be recognizable "
817 " as part of outline - rectify? "))
818 (quit nil)))
819 (progn
820 (if (allout-hidden-p (max (1- (point)) 1))
821 (save-excursion
822 (goto-char (max (1- (point)) 1))
823 (allout-show-to-offshoot)))
824 (allout-widgets-undecorate-item this-widget))
825 ;; expose any hidden intervening items, so resulting
826 ;; position is clear:
827 (setq inserted-at (point))
828 (allout-unprotected (insert-before-markers "\n"))
829 (forward-char -1)
830 ;; ensure the inserted newline is visible:
831 (allout-flag-region inserted-at (1+ inserted-at) nil)
832 (allout-widgets-post-command-business 'recursing)
833 (message (concat "outline structure corrected - item"
834 " moved to beginning of new line"))
835 ;; preserve cursor position in some cases:
836 (if (and inserted-at
837 (> (point) inserted-at))
838 (forward-char -1)))))))
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 handled-conceal
1003 covered
1004 deactivate-mark)
1006 (dolist (change changes)
1007 (let (handling
1008 (from (cadr change))
1009 bucket got
1010 (to (caddr change))
1011 (flag (cadddr change))
1012 parent)
1014 ;; swap from and to:
1015 (if (< to from) (setq bucket to
1016 to from
1017 from bucket))
1019 ;; have we already handled exposure changes in this region?
1020 (setq handling (if flag 'handled-conceal 'handled-expose)
1021 got (allout-range-overlaps from to (symbol-value handling))
1022 covered (car got))
1023 (set handling (cadr got))
1025 (when (not covered)
1026 (save-excursion
1027 (goto-char from)
1028 (cond
1030 ;; collapsing:
1031 (flag
1032 (allout-widgets-undecorate-region from to)
1033 (allout-beginning-of-current-line)
1034 (let ((widget (allout-get-item-widget)))
1035 (if (not widget)
1036 (allout-get-or-create-item-widget)
1037 (widget-apply widget :redecorate))))
1039 ;; expanding:
1041 (while (< (point) to)
1042 (allout-beginning-of-current-line)
1043 (setq parent (allout-get-item-widget))
1044 (if (not parent)
1045 (setq parent (allout-get-or-create-item-widget))
1046 (widget-apply parent :redecorate))
1047 (allout-next-visible-heading 1)
1048 (if (widget-get parent :has-subitems)
1049 (allout-redecorate-visible-subtree parent))
1050 (if (> (point) to)
1051 ;; subtree may be well beyond to - incorporate in ranges:
1052 (setq handled-expose
1053 (allout-range-overlaps from (point) handled-expose)
1054 covered (car handled-expose)
1055 handled-expose (cadr handled-expose)))
1056 (allout-next-visible-heading 1))))))))))
1058 ;;;_ > allout-widgets-additions-recorder (from to)
1059 (defun allout-widgets-additions-recorder (from to)
1060 "Record allout item additions for tracking during post-command processing.
1062 Intended for use on `allout-structure-added-functions'.
1064 FROM point at the start of the first new item and TO is point at the start
1065 of the last one.
1067 Records changes in `allout-widgets-changes-record'."
1068 (push (list :added from to) allout-widgets-changes-record))
1069 ;;;_ > allout-widgets-additions-processor (changes)
1070 (defun allout-widgets-additions-processor (changes)
1071 "Widgetize and adjust items tracking allout outline structure additions.
1073 Dispatched by `allout-widgets-post-command-business' in response to
1074 :added entries recorded by `allout-widgets-additions-recorder'."
1075 (save-excursion
1076 (let (handled
1077 covered)
1078 (dolist (change changes)
1079 (let ((from (cadr change))
1080 bucket
1081 (to (caddr change)))
1082 (if (< to from) (setq bucket to to from from bucket))
1083 ;; have we already handled exposure changes in this region?
1084 (setq handled (allout-range-overlaps from to handled)
1085 covered (car handled)
1086 handled (cadr handled))
1087 (when (not covered)
1088 (goto-char from)
1089 ;; Prior sibling and parent can both be affected.
1090 (if (allout-ascend)
1091 (allout-redecorate-visible-subtree
1092 (allout-get-or-create-item-widget 'redecorate)))
1093 (if (< (point) from)
1094 (goto-char from))
1095 (while (and (< (point) to) (not (eobp)))
1096 (allout-beginning-of-current-line)
1097 (allout-redecorate-visible-subtree
1098 (allout-get-or-create-item-widget))
1099 (allout-next-visible-heading 1))
1100 (if (> (point) to)
1101 ;; subtree may be well beyond to - incorporate in ranges:
1102 (setq handled (allout-range-overlaps from (point) handled)
1103 covered (car handled)
1104 handled (cadr handled)))))))))
1106 ;;;_ > allout-widgets-deletions-recorder (depth from)
1107 (defun allout-widgets-deletions-recorder (depth from)
1108 "Record allout item deletions for tracking during post-command processing.
1109 Intended for use on `allout-structure-deleted-functions'.
1111 DEPTH is the depth of the deleted subtree, and FROM is the point from which
1112 the subtree was deleted.
1114 Records changes in `allout-widgets-changes-record'."
1115 (push (list :deleted depth from) allout-widgets-changes-record))
1116 ;;;_ > allout-widgets-deletions-processor (changes)
1117 (defun allout-widgets-deletions-processor (changes)
1118 "Adjust items tracking allout outline structure deletions.
1120 Dispatched by `allout-widgets-post-command-business' in response to
1121 :deleted entries recorded by `allout-widgets-deletions-recorder'."
1122 (save-excursion
1123 (dolist (change changes)
1124 (let ((depth (cadr change))
1125 (from (caddr change)))
1126 (goto-char from)
1127 (when (allout-previous-visible-heading 1)
1128 (if (> depth 1)
1129 (allout-ascend-to-depth (1- depth)))
1130 (allout-redecorate-visible-subtree
1131 (allout-get-or-create-item-widget 'redecorate)))))))
1133 ;;;_ > allout-widgets-shifts-recorder (shifted-amount at)
1134 (defun allout-widgets-shifts-recorder (shifted-amount at)
1135 "Record outline subtree shifts for tracking during post-command processing.
1136 Intended for use on `allout-structure-shifted-functions'.
1138 SHIFTED-AMOUNT is the depth change and AT is the point at the start of the
1139 subtree that's been shifted.
1141 Records changes in `allout-widgets-changes-record'."
1142 (push (list :shifted shifted-amount at) allout-widgets-changes-record))
1143 ;;;_ > allout-widgets-shifts-processor (changes)
1144 (defun allout-widgets-shifts-processor (changes)
1145 "Widgetize and adjust items tracking allout outline structure additions.
1147 Dispatched by `allout-widgets-post-command-business' in response to
1148 :shifted entries recorded by `allout-widgets-shifts-recorder'."
1149 (save-excursion
1150 (dolist (change changes)
1151 (goto-char (caddr change))
1152 (allout-ascend)
1153 (allout-redecorate-visible-subtree))))
1154 ;;;_ > allout-widgets-after-copy-or-kill-function ()
1155 (defun allout-widgets-after-copy-or-kill-function ()
1156 "Do allout-widgets processing of text just placed in the kill ring.
1158 Intended for use on allout-after-copy-or-kill-hook."
1159 (if (car kill-ring)
1160 (setcar kill-ring (allout-widgets-undecorate-text (car kill-ring)))))
1161 ;;;_ > allout-widgets-after-undo-function ()
1162 (defun allout-widgets-after-undo-function ()
1163 "Do allout-widgets processing of text after an undo.
1165 Intended for use on allout-post-undo-hook."
1166 (save-excursion
1167 (if (allout-goto-prefix)
1168 (allout-redecorate-item (allout-get-or-create-item-widget)))))
1170 ;;;_ > allout-widgets-exposure-undo-recorder (widget from-state)
1171 (defun allout-widgets-exposure-undo-recorder (widget)
1172 "Record outline exposure undo for tracking during post-command processing.
1174 Intended for use by `allout-graphics-modification-handler'.
1176 WIDGET is the widget being changed.
1178 Records changes in `allout-widgets-changes-record'."
1179 ;; disregard the events if we're currently processing them.
1180 (if (not allout-undo-exposure-in-progress)
1181 (push widget allout-widgets-undo-exposure-record)))
1182 ;;;_ > allout-widgets-exposure-undo-processor ()
1183 (defun allout-widgets-exposure-undo-processor ()
1184 "Adjust items tracking undo of allout outline structure exposure.
1186 Dispatched by `allout-widgets-post-command-business' in response to
1187 :undone-exposure entries recorded by `allout-widgets-exposure-undo-recorder'."
1188 (let* ((allout-undo-exposure-in-progress t)
1189 ;; inhibit undo recording while twiddling exposure to track undo:
1190 (widgets allout-widgets-undo-exposure-record)
1191 widget widget-start-marker widget-end-marker
1192 from-state icon-start-point to-state
1193 handled covered)
1194 (setq allout-widgets-undo-exposure-record nil)
1195 (save-excursion
1196 (dolist (widget widgets)
1197 (setq widget-start-marker (widget-get widget :from)
1198 widget-end-marker (widget-get widget :to)
1199 from-state (widget-get widget :icon-state)
1200 icon-start-point (widget-apply widget :actual-position
1201 :icon-start)
1202 to-state (get-text-property icon-start-point
1203 :icon-state))
1204 (setq handled (allout-range-overlaps widget-start-marker
1205 widget-end-marker
1206 handled)
1207 covered (car handled)
1208 handled (cadr handled))
1209 (when (not covered)
1210 (goto-char (widget-get widget :from))
1211 (when (not (allout-hidden-p))
1212 ;; adjust actual exposure to that of to-state viz from-state
1213 (cond ((and (eq to-state 'closed) (eq from-state 'opened))
1214 (allout-hide-current-subtree)
1215 (allout-decorate-item-and-context widget))
1216 ((and (eq to-state 'opened) (eq from-state 'closed))
1217 (save-excursion
1218 (dolist
1219 (expose-to (allout-chart-exposure-contour-by-icon))
1220 (goto-char expose-to)
1221 (allout-show-to-offshoot)))))))))))
1222 ;;;_ > allout-chart-exposure-contour-by-icon (&optional from-depth)
1223 (defun allout-chart-exposure-contour-by-icon (&optional from-depth)
1224 "Return points of subtree items to which exposure should be extended.
1226 The qualifying items are ones with a widget icon that is in the closed or
1227 empty state, or items with undecorated subitems.
1229 The resulting list of points is in reverse order.
1231 Optional FROM-DEPTH is for internal use."
1232 ;; During internal recursion, we return a pair: (at-end . result)
1233 ;; Otherwise we just return the result.
1234 (let ((from-depth from-depth)
1235 start-point
1236 at-end level-depth
1237 this-widget
1238 got subgot)
1239 (if from-depth
1240 (setq level-depth (allout-depth))
1241 ;; at containing item:
1242 (setq start-point (point))
1243 (setq from-depth (allout-depth))
1244 (setq at-end (not (allout-next-heading))
1245 level-depth allout-recent-depth))
1247 ;; traverse the level, recursing on deeper levels:
1248 (while (and (not at-end)
1249 (> allout-recent-depth from-depth)
1250 (setq this-widget (allout-get-item-widget)))
1251 (if (< level-depth allout-recent-depth)
1252 ;; recurse:
1253 (progn
1254 (setq subgot (allout-chart-exposure-contour-by-icon level-depth)
1255 at-end (car subgot)
1256 subgot (cdr subgot))
1257 (if subgot (setq got (append subgot got))))
1258 ;; progress at this level:
1259 (when (memq (widget-get this-widget :icon-state) '(closed empty))
1260 (push (point) got)
1261 (allout-end-of-subtree))
1262 (setq at-end (not (allout-next-heading)))))
1264 ;; tailor result depending on whether or not we're a recursion:
1265 (if (not start-point)
1266 (cons at-end got)
1267 (goto-char start-point)
1268 got)))
1269 ;;;_ > allout-range-overlaps (from to ranges)
1270 (defun allout-range-overlaps (from to ranges)
1271 "Return a pair indicating overlap of FROM and TO subtree range in RANGES.
1273 First element of result indicates whether candidate range FROM, TO
1274 overlapped any of the existing ranges.
1276 Second element of result is a new version of RANGES incorporating the
1277 candidate range with overlaps consolidated.
1279 FROM and TO must be in increasing order, as must be the pairs in RANGES."
1280 ;; to append to the end: (rplacd next-to-last-cdr (list 'f))
1281 (let (new-ranges
1282 entry
1283 ;; the start of the range that includes the candidate from:
1284 included-from
1285 ;; the end of the range that includes the candidate to:
1286 included-to
1287 ;; the candidates were inserted:
1288 done)
1289 (while (and ranges (not done))
1290 (setq entry (car ranges)
1291 ranges (cdr ranges))
1293 (cond
1295 (included-from
1296 ;; some entry included the candidate from.
1297 (cond ((> (car entry) to)
1298 ;; current entry exceeds end of candidate range - done.
1299 (push (list included-from to) new-ranges)
1300 (push entry new-ranges)
1301 (setq included-to to
1302 done t))
1303 ((>= (cadr entry) to)
1304 ;; current entry includes end of candidate range - done.
1305 (push (list included-from (cadr entry)) new-ranges)
1306 (setq included-to (cadr entry)
1307 done t))
1308 ;; current entry contained in candidate range - ditch, continue:
1309 (t nil)))
1311 ((> (car entry) to)
1312 ;; current entry start exceeds candidate end - done, placed as new entry
1313 (push (list from to) new-ranges)
1314 (push entry new-ranges)
1315 (setq included-to to
1316 done t))
1318 ((>= (car entry) from)
1319 ;; current entry start is above candidate start, but not above
1320 ;; candidate end (by prior case).
1321 (setq included-from from)
1322 ;; now we have to check on whether this entry contains to, or continue:
1323 (when (>= (cadr entry) to)
1324 ;; current entry contains only candidate end - done:
1325 (push (list included-from (cadr entry)) new-ranges)
1326 (setq included-to (cadr entry)
1327 done t))
1328 ;; otherwise, we will continue to look for placement of candidate end.
1331 ((>= (cadr entry) to)
1332 ;; current entry properly contains candidate range.
1333 (push entry new-ranges)
1334 (setq included-from (car entry)
1335 included-to (cadr entry)
1336 done t))
1338 ((>= (cadr entry) from)
1339 ;; current entry contains start of candidate range.
1340 (setq included-from (car entry)))
1343 ;; current entry is below the candidate range.
1344 (push entry new-ranges))))
1346 (cond ((and included-from included-to)
1347 ;; candidates placed.
1348 nil)
1349 ((not (or included-from included-to))
1350 ;; candidates found no place, must be at the end:
1351 (push (list from to) new-ranges))
1352 (included-from
1353 ;; candidate start placed but end not:
1354 (push (list included-from to) new-ranges))
1355 ;; might be included-to and not included-from, indicating new entry.
1357 (setq new-ranges (nreverse new-ranges))
1358 (if ranges (setq new-ranges (append new-ranges ranges)))
1359 (list (if included-from t) new-ranges)))
1360 ;;;_ > allout-test-range-overlaps ()
1361 (defun allout-test-range-overlaps ()
1362 "allout-range-overlaps unit tests."
1363 (let* (ranges
1365 (try (lambda (from to)
1366 (setq got (allout-range-overlaps from to ranges))
1367 (setq ranges (cadr got))
1368 got)))
1369 ;; ;; biggie:
1370 ;; (setq ranges nil)
1371 ;; ;; ~ .02 to .1 seconds for just repeated listing args instead of funcall
1372 ;; ;; ~ 13 seconds for doing repeated funcall
1373 ;; (message "time-trial: %s, resulting size %s"
1374 ;; (time-trial
1375 ;; '(let ((size 10000)
1376 ;; doing)
1377 ;; (random t)
1378 ;; (dotimes (count size)
1379 ;; (setq doing (random size))
1380 ;; (funcall try doing (+ doing (random 5)))
1381 ;; ;;(list doing (+ doing (random 5)))
1382 ;; )))
1383 ;; (length ranges))
1384 ;; (sit-for 2)
1386 ;; fresh:
1387 (setq ranges nil)
1388 (assert (equal (funcall try 3 5) '(nil ((3 5)))))
1389 ;; add range at end:
1390 (assert (equal (funcall try 10 12) '(nil ((3 5) (10 12)))))
1391 ;; add range at beginning:
1392 (assert (equal (funcall try 1 2) '(nil ((1 2) (3 5) (10 12)))))
1393 ;; insert range somewhere in the middle:
1394 (assert (equal (funcall try 7 9) '(nil ((1 2) (3 5) (7 9) (10 12)))))
1395 ;; consolidate some:
1396 (assert (equal (funcall try 5 8) '(t ((1 2) (3 9) (10 12)))))
1397 ;; add more:
1398 (assert (equal (funcall try 15 17) '(nil ((1 2) (3 9) (10 12) (15 17)))))
1399 ;; add more:
1400 (assert (equal (funcall try 20 22)
1401 '(nil ((1 2) (3 9) (10 12) (15 17) (20 22)))))
1402 ;; encompass more:
1403 (assert (equal (funcall try 4 11) '(t ((1 2) (3 12) (15 17) (20 22)))))
1404 ;; encompass all:
1405 (assert (equal (funcall try 2 25) '(t ((1 25)))))
1407 ;; fresh slate:
1408 (setq ranges nil)
1409 (assert (equal (funcall try 20 25) '(nil ((20 25)))))
1410 (assert (equal (funcall try 30 35) '(nil ((20 25) (30 35)))))
1411 (assert (equal (funcall try 26 28) '(nil ((20 25) (26 28) (30 35)))))
1412 (assert (equal (funcall try 15 20) '(t ((15 25) (26 28) (30 35)))))
1413 (assert (equal (funcall try 10 30) '(t ((10 35)))))
1414 (assert (equal (funcall try 5 6) '(nil ((5 6) (10 35)))))
1415 (assert (equal (funcall try 2 100) '(t ((2 100)))))
1417 (setq ranges nil)
1419 ;;;_ > allout-widgetize-buffer (&optional doing)
1420 (defun allout-widgetize-buffer (&optional doing)
1421 "EXAMPLE FUNCTION. Widgetize items in buffer using allout-chart-subtree.
1423 We economize by just focusing on the first of local-maximum depth siblings.
1425 Optional DOING is for internal use - a chart of the current level, for
1426 recursive operation."
1428 (interactive)
1429 (if (not doing)
1431 (save-excursion
1432 (goto-char (point-min))
1433 ;; Construct the chart by scanning the siblings:
1434 (dolist (top-level-sibling (allout-chart-siblings))
1435 (goto-char top-level-sibling)
1436 (let ((subchart (allout-chart-subtree)))
1437 (if subchart
1438 (allout-widgetize-buffer subchart)))))
1440 ;; save-excursion was done on recursion entry, not necessary here.
1441 (let (have-sublists)
1442 (dolist (sibling doing)
1443 (when (listp sibling)
1444 (setq have-sublists t)
1445 (allout-widgetize-buffer sibling)))
1446 (when (and (not have-sublists) (not (widget-at (car doing))))
1447 (goto-char (car doing))
1448 (allout-get-or-create-item-widget)))))
1450 ;;;_ : Item widget and constructors
1452 ;;;_ $ allout-item-widget
1453 (define-widget 'allout-item-widget 'default
1454 "A widget presenting an allout outline item."
1456 'button nil
1457 ;; widget-field-at respects this to get item if 'field is unused.
1458 ;; we don't use field to avoid collision with end-of-line, etc, on which
1459 ;; allout depends.
1460 'real-field nil
1462 ;; data fields:
1465 ;; tailor the widget for a specific item
1466 :create 'allout-decorate-item-and-context
1467 :value-delete 'allout-widgets-undecorate-item
1468 ;; Not Yet Converted (from original, tree-widget stab)
1469 :expander 'allout-tree-event-dispatcher ; get children when nil :args
1470 :expander-p 'identity ; always engage the :expander
1471 :action 'allout-tree-widget-action
1472 ;; :notify "when item changes"
1474 ;; force decoration of item but not context, unless already done this tick:
1475 :redecorate 'allout-redecorate-item
1476 :last-decorated-tick nil
1477 ;; recognize the actual situation of the item's text:
1478 :parse-item 'allout-parse-item-at-point
1479 ;; decorate the entirety of the item, sans offspring:
1480 :decorate-item-span 'allout-decorate-item-span
1481 ;; decorate the various item elements:
1482 :decorate-guides 'allout-decorate-item-guides
1483 :decorate-icon 'allout-decorate-item-icon
1484 :decorate-cue 'allout-decorate-item-cue
1485 :decorate-body 'allout-decorate-item-body
1486 :actual-position 'allout-item-actual-position
1488 ;; Layout parameters:
1489 :is-container nil ; is this actually the encompassing file/connection?
1491 :from nil ; item beginning - marker
1492 :to nil ; item end - marker
1493 :span-overlay nil ; overlay by which actual position is determined
1495 ;; also serves as guide-end:
1496 :icon-start nil
1497 :icon-end nil
1498 :distinctive-start nil
1499 ;; also serves as cue-start:
1500 :distinctive-end nil
1501 ;; also serves as cue-end:
1502 :body-start nil
1503 :body-end nil
1504 :depth nil
1505 :has-subitems nil
1506 :was-has-subitems 'init
1507 :expanded nil
1508 :was-expanded 'init
1509 :brief nil
1510 :was-brief 'init
1512 :does-encrypt nil ; pending encryption when :is-encrypted false.
1513 :is-encrypted nil
1515 ;; the actual location of the item text:
1516 :location 'allout-item-location
1518 :button-keymap allout-item-icon-keymap ; XEmacs
1519 :keymap allout-item-icon-keymap ; Emacs
1521 ;; Element regions:
1522 :guides-span nil
1523 :icon-span nil
1524 :cue-span nil
1525 :bullet nil
1526 :was-bullet nil
1527 :body-span nil
1529 :body-brevity-p 'allout-body-brevity-p
1531 ;; :guide-column-flags indicate (in reverse order) whether or not the
1532 ;; item's ancestor at the depth corresponding to the column has a
1533 ;; subsequent sibling - ie, whether or not the corresponding column needs
1534 ;; a descender line to connect that ancestor with its sibling.
1535 :guide-column-flags nil
1536 :was-guide-column-flags 'init
1538 ;; ie, has subitems:
1539 :populous-p 'allout-item-populous-p
1540 :help-echo 'allout-tree-widget-help-echo
1542 ;;;_ > allout-new-item-widget ()
1543 (defsubst allout-new-item-widget ()
1544 "create a new item widget, not yet situated anywhere."
1545 (if allout-widgets-maintain-tally
1546 ;; all the extra overhead is incurred only when doing the
1547 ;; maintenance, except the condition, which can't be avoided.
1548 (let ((widget (widget-convert 'allout-item-widget)))
1549 (puthash widget nil allout-widgets-tally)
1550 widget)
1551 (widget-convert 'allout-item-widget)))
1552 ;;;_ : Item decoration
1553 ;;;_ > allout-decorate-item-and-context (item-widget &optional redecorate
1554 ;;; blank-container parent)
1555 (defun allout-decorate-item-and-context (item-widget &optional redecorate
1556 blank-container parent)
1557 "Create or adjust widget decorations for ITEM-WIDGET and neighbors at point.
1559 The neighbors include its siblings and parent.
1561 ITEM-WIDGET can be a created or converted allout-item-widget.
1563 If you're only trying to get or create a widget for an item, use
1564 `allout-get-or-create-item-widget'. If you have the item-widget, applying
1565 :redecorate will do the right thing.
1567 Optional BLANK-CONTAINER is for internal use. It is used to fabricate a
1568 container widget for an empty-bodied container, in the course of decorating
1569 a proper \(non-container\) item which starts at the beginning of the file.
1571 Optional REDECORATE causes redecoration of the item-widget and
1572 its siblings, even if already decorated in this cycle of the command loop.
1574 Optional PARENT, when provided, bypasses some navigation and computation
1575 necessary to obtain the parent of the items being processed.
1577 We return the item-widget corresponding to the item at point."
1579 (when (or redecorate
1580 (not (equal (widget-get item-widget :last-decorated-tick)
1581 allout-command-counter)))
1582 (let* ((allout-inhibit-body-modification-hook t)
1583 (was-modified (buffer-modified-p))
1584 (was-point (point))
1585 prefix-start
1586 (is-container (or blank-container
1587 (not (setq prefix-start (allout-goto-prefix)))
1588 (< was-point prefix-start)))
1589 ;; steady-point (set in two steps) is reliable across parent
1590 ;; widget-creation.
1591 (steady-point (progn (if is-container (goto-char 1))
1592 (point-marker)))
1593 (steady-point (progn (set-marker-insertion-type steady-point t)
1594 steady-point))
1595 (parent (and (not is-container)
1596 (allout-get-or-create-parent-widget)))
1597 parent-flags parent-depth
1598 successor-sibling
1599 body
1600 doing-item
1601 sub-item-widget
1602 depth
1603 reverse-siblings-chart
1604 (buffer-undo-list t))
1606 ;; At this point the parent is decorated and parent-flags indicate
1607 ;; its guide lines. We will iterate over the siblings according to a
1608 ;; chart we create at the start, and going from last to first so we
1609 ;; don't have to worry about text displacement caused by widgetizing.
1611 (if is-container
1612 (progn (widget-put item-widget :is-container t)
1613 (setq reverse-siblings-chart (list 1)))
1614 (goto-char (widget-apply parent :actual-position :from))
1615 (if (widget-get parent :is-container)
1616 ;; `allout-goto-prefix' will go to first non-container item:
1617 (allout-goto-prefix)
1618 (allout-next-heading))
1619 (setq depth (allout-recent-depth))
1620 (setq reverse-siblings-chart (list allout-recent-prefix-beginning))
1621 (while (allout-next-sibling)
1622 (push allout-recent-prefix-beginning reverse-siblings-chart)))
1624 (dolist (doing-at reverse-siblings-chart)
1625 (goto-char doing-at)
1626 (when allout-widgets-track-decoration
1627 (sit-for 0))
1629 (setq doing-item (if (= doing-at steady-point)
1630 item-widget
1631 (or (allout-get-item-widget)
1632 (allout-new-item-widget))))
1634 (when (or redecorate (not (equal (widget-get doing-item
1635 :last-decorated-tick)
1636 allout-command-counter)))
1637 (widget-apply doing-item :parse-item t blank-container)
1638 (widget-apply doing-item :decorate-item-span)
1640 (widget-apply doing-item :decorate-guides
1641 parent (and successor-sibling t))
1642 (widget-apply doing-item :decorate-icon)
1643 (widget-apply doing-item :decorate-cue)
1644 (widget-apply doing-item :decorate-body)
1646 (widget-put doing-item :last-decorated-tick allout-command-counter))
1648 (setq successor-sibling doing-at))
1650 (set-buffer-modified-p was-modified)
1651 (goto-char steady-point)
1652 ;; must null the marker or the buffer gets clogged with impedance:
1653 (set-marker steady-point nil)
1655 item-widget)))
1656 ;;;_ > allout-redecorate-item (item)
1657 (defun allout-redecorate-item (item-widget)
1658 "Resituate ITEM-WIDGET decorations, disregarding context.
1660 Use this to redecorate only the item, when you know that its
1661 situation with respect to siblings, parent, and offspring is
1662 unchanged from its last decoration. Use
1663 `allout-decorate-item-and-context' instead to reassess and adjust
1664 relevant context, when suitable."
1665 (if (not (equal (widget-get item-widget :last-decorated-tick)
1666 allout-command-counter))
1667 (let ((was-modified (buffer-modified-p))
1668 (buffer-undo-list t))
1669 (widget-apply item-widget :parse-item)
1670 (widget-apply item-widget :decorate-guides)
1671 (widget-apply item-widget :decorate-icon)
1672 (widget-apply item-widget :decorate-cue)
1673 (widget-apply item-widget :decorate-body)
1674 (set-buffer-modified-p was-modified))))
1675 ;;;_ > allout-redecorate-visible-subtree (&optional parent-widget
1676 ;;; depth chart)
1677 (defun allout-redecorate-visible-subtree (&optional parent-widget depth chart)
1678 "Redecorate all visible items in subtree at point.
1680 Optional PARENT-WIDGET is for optimization, when the parent
1681 widget is already available.
1683 Optional DEPTH restricts the excursion depth of covered.
1685 Optional CHART is for internal recursion, to carry a chart of the
1686 target items.
1688 Point is left at the last sibling in the visible subtree."
1689 ;; using a treatment that takes care of all the siblings on a level, we
1690 ;; only need apply it to the first sibling on the level, and we can
1691 ;; collect and pass the parent of the lower levels to recursive calls as
1692 ;; we go.
1693 (let ((parent-widget
1694 (if (and parent-widget (widget-apply parent-widget
1695 :actual-position :from))
1696 (progn (goto-char (widget-apply parent-widget
1697 :actual-position :from))
1698 parent-widget)
1699 (let ((got (allout-get-item-widget)))
1700 (if got
1701 (allout-decorate-item-and-context got 'redecorate)
1702 (allout-get-or-create-item-widget 'redecorate)))))
1703 (pending-chart (or chart (allout-chart-subtree nil 'visible)))
1704 item-widget
1705 previous-sibling-point
1706 previous-sibling
1707 recent-sibling-point)
1708 (setq pending-chart (nreverse pending-chart))
1709 (dolist (sibling-point pending-chart)
1710 (cond ((integerp sibling-point)
1711 (when (not previous-sibling-point)
1712 (goto-char sibling-point)
1713 (if (setq item-widget (allout-get-item-widget nil))
1714 (allout-decorate-item-and-context item-widget 'redecorate
1715 nil parent-widget)
1716 (allout-get-or-create-item-widget)))
1717 (setq previous-sibling-point sibling-point
1718 recent-sibling-point sibling-point))
1719 ((listp sibling-point)
1720 (if (or (not depth)
1721 (> depth 1))
1722 (allout-redecorate-visible-subtree
1723 (if (not previous-sibling-point)
1724 ;; containment discontinuity - sigh
1725 parent-widget
1726 (allout-get-or-create-item-widget 'redecorate))
1727 (if depth (1- depth))
1728 sibling-point)))))
1729 (if (and recent-sibling-point (< (point) recent-sibling-point))
1730 (goto-char recent-sibling-point))))
1731 ;;;_ > allout-parse-item-at-point (item-widget &optional at-beginning
1732 ;;; blank-container)
1733 (defun allout-parse-item-at-point (item-widget &optional at-beginning
1734 blank-container)
1735 "Set widget ITEM-WIDGET layout parameters per item-at-point's actual layout.
1737 If optional AT-BEGINNING is t, then point is assumed to be at the start of
1738 the item prefix.
1740 If optional BLANK-CONTAINER is true, then the parameters of a container
1741 which has an empty body are set. \(Though the body is blank, the object
1742 may have subitems.\)"
1744 ;; Uncomment this sit-for to notice where decoration is happening:
1745 ;; (sit-for .1)
1746 (let* ((depth (allout-depth))
1747 (depth (if blank-container 0 depth))
1748 (is-container (or blank-container (zerop depth)))
1750 (does-encrypt (and (not is-container)
1751 (allout-encrypted-type-prefix)))
1752 (is-encrypted (and does-encrypt (allout-encrypted-topic-p)))
1753 (icon-end allout-recent-prefix-end)
1754 (icon-start (1- icon-end))
1755 body-start
1756 body-end
1757 bullet
1758 has-subitems
1759 (contents-depth (1+ depth))
1761 (widget-put item-widget :depth depth)
1762 (if is-container
1764 (progn
1765 (widget-put item-widget :from (allout-set-boundary-marker
1766 :from (point-min)
1767 (widget-get item-widget :from)))
1768 (widget-put item-widget :icon-end nil)
1769 (widget-put item-widget :icon-start nil)
1770 (setq body-start (widget-put item-widget :body-start 1)))
1772 ;; not container:
1774 (widget-put item-widget :from (allout-set-boundary-marker
1775 :from (if at-beginning
1776 (point)
1777 allout-recent-prefix-beginning)
1778 (widget-get item-widget :from)))
1779 (widget-put item-widget :icon-start icon-start)
1780 (widget-put item-widget :icon-end icon-end)
1781 (when does-encrypt
1782 (widget-put item-widget :does-encrypt t)
1783 (widget-put item-widget :is-encrypted is-encrypted))
1785 ;; cue area:
1786 (setq body-start icon-end)
1787 (widget-put item-widget :bullet (setq bullet (allout-get-bullet)))
1788 (if (equal (char-after body-start) ? )
1789 (setq body-start (1+ body-start)))
1790 (widget-put item-widget :body-start body-start)
1793 ;; Both container and regular items:
1795 ;; :body-end (doesn't include a trailing blank line, if any) -
1796 (widget-put item-widget :body-end (setq body-end
1797 (if blank-container
1799 (allout-end-of-entry))))
1801 (widget-put item-widget :to (allout-set-boundary-marker
1802 :to (if blank-container
1803 (point-min)
1804 (or (allout-pre-next-prefix)
1805 (goto-char (point-max))))
1806 (widget-get item-widget :to)))
1807 (widget-put item-widget :has-subitems
1808 (setq has-subitems
1809 (and
1810 ;; has a subsequent item:
1811 (not (= body-end (point-max)))
1812 ;; subsequent item is deeper:
1813 (< depth (setq contents-depth (allout-recent-depth))))))
1814 ;; note :expanded - true if widget item's content is currently visible?
1815 (widget-put item-widget :expanded
1816 (and has-subitems
1817 ;; subsequent item is or isn't visible:
1818 (save-excursion
1819 (goto-char allout-recent-prefix-beginning)
1820 (not (allout-hidden-p)))))))
1821 ;;;_ > allout-set-boundary-marker (boundary position &optional current-marker)
1822 (defun allout-set-boundary-marker (boundary position &optional current-marker)
1823 "Set or create item widget BOUNDARY type marker at POSITION.
1825 Optional CURRENT-MARKER is the marker currently being used for
1826 the boundary, if any.
1828 BOUNDARY type is either :from or :to, determining the marker insertion type."
1829 (if (not position) (setq position (point)))
1830 (if current-marker
1831 (set-marker current-marker position)
1832 (let ((marker (make-marker)))
1833 ;; XXX dang - would like for :from boundary to advance after inserted
1834 ;; text, but that would omit new header prefixes when allout
1835 ;; relevels, etc. this competes with ad-hoc edits, which would
1836 ;; better be omitted
1837 (set-marker-insertion-type marker nil)
1838 (set-marker marker position))))
1839 ;;;_ > allout-decorate-item-span (item-widget)
1840 (defun allout-decorate-item-span (item-widget)
1841 "Equip the item with a span, as an entirety.
1843 This span is implemented so it can be used to detect displacement
1844 of the widget in absolute terms, and provides an offset bias for
1845 the various element spans."
1847 (if (and (widget-get item-widget :is-container)
1848 ;; the only case where the span could be empty.
1849 (eq (widget-get item-widget :from)
1850 (widget-get item-widget :to)))
1852 (allout-item-span item-widget
1853 (widget-get item-widget :from)
1854 (widget-get item-widget :to))))
1855 ;;;_ > allout-decorate-item-guides (item-widget
1856 ;;; &optional parent-widget has-successor)
1857 (defun allout-decorate-item-guides (item-widget
1858 &optional parent-widget has-successor)
1859 "Add ITEM-WIDGET guide icon-prefix descender and connector text properties.
1861 Optional arguments provide context for deriving the guides. In
1862 their absence, the current guide column flags are used.
1864 Optional PARENT-WIDGET is the widget for the item's parent item.
1866 Optional HAS-SUCCESSOR is true iff the item is followed by a sibling.
1868 We also hide the header-prefix string.
1870 Guides are established according to the item-widget's :guide-column-flags,
1871 when different than :was-guide-column-flags. Changing that property and
1872 reapplying this method will rectify the glyphs."
1874 (when (not (widget-get item-widget :is-container))
1875 (let* ((depth (widget-get item-widget :depth))
1876 (parent-depth (and parent-widget
1877 (widget-get parent-widget :depth)))
1878 (parent-flags (and parent-widget
1879 (widget-get parent-widget :guide-column-flags)))
1880 (parent-flags-depth (length parent-flags))
1881 (extender-length (- depth (+ parent-flags-depth 2)))
1882 (flags (or (and (> depth 1)
1883 parent-widget
1884 (widget-put item-widget :guide-column-flags
1885 (append (list has-successor)
1886 (if (< 0 extender-length)
1887 (make-list extender-length
1888 '-))
1889 parent-flags)))
1890 (widget-get item-widget :guide-column-flags)))
1891 (was-flags (widget-get item-widget :was-guide-column-flags))
1892 (guides-start (widget-get item-widget :from))
1893 (guides-end (widget-get item-widget :icon-start))
1894 (position guides-start)
1895 (increment (length allout-header-prefix))
1896 reverse-flags
1897 guide-name
1898 extenders paint-extenders
1899 (inhibit-read-only t))
1901 (when (not (equal was-flags flags))
1903 (setq reverse-flags (reverse flags))
1904 (while reverse-flags
1905 (setq guide-name
1906 (cond ((null (cdr reverse-flags))
1907 (if (car reverse-flags)
1908 'mid-connector
1909 'end-connector))
1910 ((eq (car reverse-flags) '-)
1911 ;; accumulate extenders tally, to be painted on next
1912 ;; non-extender flag, according to the flag type.
1913 (setq extenders (1+ (or extenders 0)))
1914 nil)
1915 ((car reverse-flags)
1916 'through-descender)
1917 (t 'skip-descender)))
1918 (when guide-name
1919 (put-text-property position (setq position (+ position increment))
1920 'display (allout-fetch-icon-image guide-name))
1921 (if (> increment 1) (setq increment 1))
1922 (when extenders
1923 ;; paint extenders after a connector, else leave spaces.
1924 (dotimes (i extenders)
1925 (put-text-property
1926 position (setq position (1+ position))
1927 'display (allout-fetch-icon-image
1928 (if (memq guide-name '(mid-connector end-connector))
1929 'extender-connector
1930 'skip-descender))))
1931 (setq extenders nil)))
1932 (setq reverse-flags (cdr reverse-flags)))
1933 (widget-put item-widget :was-guide-column-flags flags))
1935 (allout-item-element-span-is item-widget :guides-span
1936 guides-start guides-end))))
1937 ;;;_ > allout-decorate-item-icon (item-widget)
1938 (defun allout-decorate-item-icon (item-widget)
1939 "Add item icon glyph and distinctive bullet text properties to ITEM-WIDGET."
1941 (when (not (widget-get item-widget :is-container))
1942 (let* ((icon-start (widget-get item-widget :icon-start))
1943 (icon-end (widget-get item-widget :icon-end))
1944 (bullet (widget-get item-widget :bullet))
1945 (use-bullet bullet)
1946 (was-bullet (widget-get item-widget :was-bullet))
1947 (distinctive (allout-distinctive-bullet bullet))
1948 (distinctive-start (widget-get item-widget :distinctive-start))
1949 (distinctive-end (widget-get item-widget :distinctive-end))
1950 (does-encrypt (widget-get item-widget :does-encrypt))
1951 (is-encrypted (and does-encrypt (widget-get item-widget
1952 :is-encrypted)))
1953 (expanded (widget-get item-widget :expanded))
1954 (has-subitems (widget-get item-widget :has-subitems))
1955 (inhibit-read-only t)
1956 icon-state)
1958 (when (not (and (equal (widget-get item-widget :was-expanded) expanded)
1959 (equal (widget-get item-widget :was-has-subitems)
1960 has-subitems)
1961 (equal (widget-get item-widget :was-does-encrypt)
1962 does-encrypt)
1963 (equal (widget-get item-widget :was-is-encrypted)
1964 is-encrypted)))
1966 (setq icon-state
1967 (cond (does-encrypt (if is-encrypted
1968 'locked-encrypted
1969 'unlocked-encrypted))
1970 (expanded 'opened)
1971 (has-subitems 'closed)
1972 (t 'empty)))
1973 (put-text-property icon-start (1+ icon-start)
1974 'display (allout-fetch-icon-image icon-state))
1975 (widget-put item-widget :was-expanded expanded)
1976 (widget-put item-widget :was-has-subitems has-subitems)
1977 (widget-put item-widget :was-does-encrypt does-encrypt)
1978 (widget-put item-widget :was-is-encrypted is-encrypted)
1979 ;; preserve as a widget property to track last known:
1980 (widget-put item-widget :icon-state icon-state)
1981 ;; preserve as a text property to track undo:
1982 (put-text-property icon-start icon-end :icon-state icon-state))
1983 (allout-item-element-span-is item-widget :icon-span
1984 icon-start icon-end)
1985 (when (not (string= was-bullet bullet))
1986 (cond ((not distinctive)
1987 ;; XXX we strip the prior properties without even checking if
1988 ;; the prior bullet was distinctive, because the widget
1989 ;; provisions to convey that info is disappearing, sigh.
1990 (remove-text-properties icon-end (1+ icon-end) '(display))
1991 (setq distinctive-start icon-end distinctive-end icon-end)
1992 (widget-put item-widget :distinctive-start distinctive-start)
1993 (widget-put item-widget :distinctive-end distinctive-end))
1995 ((not (string= bullet allout-numbered-bullet))
1996 (setq distinctive-start icon-end distinctive-end (+ icon-end 1)))
1998 (does-encrypt
1999 (setq distinctive-start icon-end distinctive-end (+ icon-end 1)))
2002 (goto-char icon-end)
2003 (looking-at "[0-9]+")
2004 (setq use-bullet (buffer-substring icon-end (match-end 0)))
2005 (setq distinctive-start icon-end
2006 distinctive-end (match-end 0))))
2007 (put-text-property distinctive-start distinctive-end 'display
2008 use-bullet)
2009 (widget-put item-widget :was-bullet bullet)
2010 (widget-put item-widget :distinctive-start distinctive-start)
2011 (widget-put item-widget :distinctive-end distinctive-end)))))
2012 ;;;_ > allout-decorate-item-cue (item-widget)
2013 (defun allout-decorate-item-cue (item-widget)
2014 "Incorporate space between bullet icon and body to the ITEM-WIDGET."
2015 ;; NOTE: most of the cue-area
2017 (when (not (widget-get item-widget :is-container))
2018 (let* ((cue-start (or (widget-get item-widget :distinctive-end)
2019 (widget-get item-widget :icon-end)))
2020 (body-start (widget-get item-widget :body-start))
2021 (expanded (widget-get item-widget :expanded))
2022 (has-subitems (widget-get item-widget :has-subitems))
2023 (inhibit-read-only t))
2025 (allout-item-element-span-is item-widget :cue-span cue-start body-start)
2026 (put-text-property (1- body-start) body-start 'rear-nonsticky t))))
2027 ;;;_ > allout-decorate-item-body (item-widget &optional force)
2028 (defun allout-decorate-item-body (item-widget &optional force)
2029 "Incorporate item body text as part the ITEM-WIDGET.
2031 Optional FORCE means force reassignment of the region property."
2033 (let* ((allout-inhibit-body-modification-hook t)
2034 (body-start (widget-get item-widget :body-start))
2035 (body-end (widget-get item-widget :body-end))
2036 (body-text-end body-end)
2037 (inhibit-read-only t))
2039 (allout-item-element-span-is item-widget :body-span
2040 body-start (min (1+ body-end) (point-max))
2041 force)))
2042 ;;;_ > allout-item-actual-position (item-widget field)
2043 (defun allout-item-actual-position (item-widget field)
2044 "Return ITEM-WIDGET FIELD position taking item displacement into account."
2046 ;; The item's sub-element positions (:icon-end, :body-start, etc) are
2047 ;; accurate when the item is parsed, but some offsets from the start
2048 ;; drift with text added in the body.
2050 ;; Rather than reparse an item with every change (inefficient), or derive
2051 ;; every position from a distinct field marker/overlay (prohibitive as
2052 ;; the number of items grows), we use the displacement tracking of the
2053 ;; :span-overlay's markers, against the registered :from or :body-end
2054 ;; (depending on whether the requested field value is before or after the
2055 ;; item body), to bias the registered values.
2057 ;; This is not necessary/useful when the item is being decorated, because
2058 ;; that always must be preceded by a fresh item parse.
2060 (if (not (eq field :body-end))
2061 (widget-get item-widget :from)
2063 (let* ((span-overlay (widget-get item-widget :span-overlay))
2064 (body-end-position (widget-get item-widget :body-end))
2065 (ref-marker-position (and span-overlay
2066 (overlay-end span-overlay)))
2067 (offset (and body-end-position span-overlay
2068 (- (or ref-marker-position 0)
2069 body-end-position))))
2070 (+ (widget-get item-widget field) (or offset 0)))))
2071 ;;;_ : Item undecoration
2072 ;;;_ > allout-widgets-undecorate-region (start end)
2073 (defun allout-widgets-undecorate-region (start end)
2074 "Eliminate widgets and decorations for all items in region from START to END."
2075 (let ((next start)
2076 widget)
2077 (save-excursion
2078 (goto-char start)
2079 (while (< (setq next (next-single-char-property-change next
2080 'display
2081 (current-buffer)
2082 end))
2083 end)
2084 (goto-char next)
2085 (when (setq widget (allout-get-item-widget))
2086 ;; if the next-property/overly progression got us to a widget:
2087 (allout-widgets-undecorate-item widget t))))))
2088 ;;;_ > allout-widgets-undecorate-text (text)
2089 (defun allout-widgets-undecorate-text (text)
2090 "Eliminate widgets and decorations for all items in TEXT."
2091 (remove-text-properties 0 (length text)
2092 '(display nil :icon-state nil rear-nonsticky nil
2093 category nil button nil field nil)
2094 text)
2095 text)
2096 ;;;_ > allout-widgets-undecorate-item (item-widget &optional no-expose)
2097 (defun allout-widgets-undecorate-item (item-widget &optional no-expose)
2098 "Remove widget decorations from ITEM-WIDGET.
2100 Any concealed content head lines and item body is exposed, unless
2101 optional NO-EXPOSE is non-nil."
2102 (let ((from (widget-get item-widget :from))
2103 (to (widget-get item-widget :to))
2104 (text-properties-to-remove '(display nil
2105 :icon-state nil
2106 rear-nonsticky nil
2107 category nil
2108 button nil
2109 field nil))
2110 (span-overlay (widget-get item-widget :span-overlay))
2111 (button-overlay (widget-get item-widget :button))
2112 (was-modified (buffer-modified-p))
2113 (buffer-undo-list t)
2114 (inhibit-read-only t))
2115 (if (not no-expose)
2116 (allout-flag-region from to nil))
2117 (allout-unprotected
2118 (remove-text-properties from to text-properties-to-remove))
2119 (when span-overlay
2120 (delete-overlay span-overlay) (widget-put item-widget :span-overlay nil))
2121 (when button-overlay
2122 (delete-overlay button-overlay) (widget-put item-widget :button nil))
2123 (set-marker from nil)
2124 (set-marker to nil)
2125 (if (not was-modified)
2126 (set-buffer-modified-p nil))))
2128 ;;;_ : Item decoration support
2129 ;;;_ > allout-item-span (item-widget &optional start end)
2130 (defun allout-item-span (item-widget &optional start end)
2131 "Return or register the location of an ITEM-WIDGET's actual START and END.
2133 If START and END are not passed in, return either a dotted pair
2134 of the current span, if established, or nil if not yet set.
2136 When the START and END are passed, return the distance that the
2137 start of the item moved. We return 0 if the span was not
2138 previously established or is not moved."
2139 (let ((overlay (widget-get item-widget :span-overlay))
2140 was-start was-end
2141 changed)
2142 (cond ((not overlay) (when start
2143 (setq overlay (make-overlay start end nil t nil))
2144 (overlay-put overlay 'button item-widget)
2145 (overlay-put overlay 'evaporate t)
2146 (widget-put item-widget :span-overlay overlay)
2148 ;; report:
2149 ((not start) (cons (overlay-start overlay) (overlay-end overlay)))
2150 ;; move:
2151 ((or (not (equal (overlay-start overlay) start))
2152 (not (equal (overlay-end overlay) end)))
2153 (move-overlay overlay start end)
2155 ;; specified span already set:
2156 (t nil))))
2157 ;;;_ > allout-item-element-span-is (item-widget element
2158 ;;; &optional start end force)
2159 (defun allout-item-element-span-is (item-widget element
2160 &optional start end force)
2161 "Return or register the location of the indicated ITEM-WIDGET ELEMENT.
2163 ELEMENT is one of :guides-span, :icon-span, :cue-span, or :body-span.
2165 When optional START is specified, optional END must also be.
2167 START and END are the actual bounds of the region, if provided.
2169 If START and END are not passed in, we return either a dotted
2170 pair of the current span, if established, or nil if not yet set.
2172 When the START and END are passed, we return t if the region
2173 changed or nil if not.
2175 Optional FORCE means force assignment of the region's text
2176 property, even if it's already set."
2177 (let ((span (widget-get item-widget element)))
2178 (cond ((or (not span) force)
2179 (when start
2180 (widget-put item-widget element (cons start end))
2181 (put-text-property start end 'category
2182 (cdr (assoc element
2183 allout-span-to-category)))
2185 ;; report:
2186 ((not start) span)
2187 ;; move if necessary:
2188 ((not (and (eq (car span) start)
2189 (eq (cdr span) end)))
2190 (widget-put item-widget element span)
2192 ;; specified span already set:
2193 (t nil))))
2194 ;;;_ : Item widget retrieval (/ high-level creation):
2195 ;;;_ > allout-get-item-widget (&optional container)
2196 (defun allout-get-item-widget (&optional container)
2197 "Return the widget for the item at point, or nil if no widget yet exists.
2199 Point must be situated *before* the start of the target item's
2200 body, so we don't get an existing containing item when we're in
2201 the process of creating an item in the middle of another.
2203 Optional CONTAINER is used to obtain the container item."
2204 (if (or container (zerop (allout-depth)))
2205 allout-container-item-widget
2206 ;; allout-recent-* are calibrated by (allout-depth) if we got here.
2207 (let ((got (widget-at allout-recent-prefix-beginning)))
2208 (if (and got (listp got))
2209 (if (marker-position (widget-get got :from))
2210 (and
2211 (>= (point) (widget-apply got :actual-position :from))
2212 (<= (point) (widget-apply got :actual-position :body-start))
2213 got)
2214 ;; a wacky residual item - undecorate and disregard:
2215 (allout-widgets-undecorate-item got)
2216 nil)))))
2217 ;;;_ > allout-get-or-create-item-widget (&optional redecorate blank-container)
2218 (defun allout-get-or-create-item-widget (&optional redecorate blank-container)
2219 "Return a widget for the item at point, creating the widget if necessary.
2221 When creating a widget, we assume there has been a context change
2222 and decorate its siblings and parent, as well.
2224 Optional BLANK-CONTAINER is for internal use, to fabricate a
2225 meta-container item with an empty body when the first proper
2226 \(non-container\) item starts at the beginning of the file.
2228 Optional REDECORATE, if non-nil, means to redecorate the widget
2229 if it already exists."
2230 (let ((widget (allout-get-item-widget blank-container))
2231 (buffer-undo-list t))
2232 (cond (widget (if redecorate
2233 (allout-redecorate-item widget))
2234 widget)
2235 ((or blank-container (zerop (allout-depth)))
2236 (or allout-container-item-widget
2237 (setq allout-container-item-widget
2238 (allout-decorate-item-and-context
2239 (widget-convert 'allout-item-widget)
2240 nil blank-container))))
2241 ;; create a widget for a regular/non-container item:
2242 (t (allout-decorate-item-and-context (widget-convert
2243 'allout-item-widget))))))
2244 ;;;_ > allout-get-or-create-parent-widget (&optional redecorate)
2245 (defun allout-get-or-create-parent-widget (&optional redecorate)
2246 "Return widget for parent of item at point, decorating it if necessary.
2248 We return the container widget if we're above the first proper item in the
2249 file.
2251 Optional REDECORATE, if non-nil, means to redecorate the widget if it
2252 already exists.
2254 Point will wind up positioned on the beginning of the parent or beginning
2255 of the buffer."
2256 ;; use existing widget, if there, else establish it
2257 (if (or (bobp) (and (not (allout-ascend))
2258 (looking-at allout-regexp)))
2259 (allout-get-or-create-item-widget redecorate 'blank-container)
2260 (allout-get-or-create-item-widget redecorate)))
2261 ;;;_ : X- Item ancillaries
2262 ;;;_ >X allout-body-modification-handler (beg end)
2263 (defun allout-body-modification-handler (beg end)
2264 "Do routine processing of body text before and after modification.
2266 Operation is inhibited by `allout-inhibit-body-modification-handler'."
2268 ;; The primary duties are:
2270 ;; - marking of escaped prefix-like text for delayed cleanup of escapes
2271 ;; - removal and replacement of the settings
2272 ;; - maintenance of beginning-of-line guide lines
2274 ;; ?? Escapes removal \(before changes\) is not done when edits span multiple
2275 ;; items, recognizing that item structure is being preserved, including
2276 ;; escaping of item-prefix-like text within bodies. See
2277 ;; `allout-before-modification-handler' and
2278 ;; `allout-inhibit-body-modification-handler'.
2280 ;; Adds the overlay to the `allout-unresolved-body-mod-workhash' during
2281 ;; before-change operation, and removes from that list during after-change
2282 ;; operation.
2283 (cond (allout-inhibit-body-modification-hook nil)))
2284 ;;;_ >X allout-graphics-modification-handler (beg end)
2285 (defun allout-graphics-modification-handler (beg end)
2286 "Protect against incoherent deletion of decoration graphics.
2288 Deletes allowed only when inhibit-read-only is t."
2289 (cond
2290 (undo-in-progress (when (eq (get-text-property beg 'category)
2291 'allout-icon-span-category)
2292 (save-excursion
2293 (goto-char beg)
2294 (let* ((item-widget (allout-get-item-widget)))
2295 (if item-widget
2296 (allout-widgets-exposure-undo-recorder
2297 item-widget))))))
2298 (inhibit-read-only t)
2299 ((not (and (boundp 'allout-mode) allout-mode)) t)
2300 ((equal this-command 'quoted-insert) t)
2301 ((yes-or-no-p "Unruly edit of outline structure - allow? ")
2302 (setq allout-widgets-unset-inhibit-read-only (not inhibit-read-only)
2303 inhibit-read-only t))
2304 (t (error
2305 (substitute-command-keys allout-structure-unruly-deletion-message)))))
2306 ;;;_ > allout-item-icon-key-handler ()
2307 (defun allout-item-icon-key-handler ()
2308 "Catchall handling of key bindings in item icon/cue hot-spots.
2310 Applies `allout-hotspot-key-handler' and calls the result, if any, as an
2311 interactive command."
2313 (interactive)
2314 (let* ((mapped-binding (allout-hotspot-key-handler)))
2315 (when mapped-binding
2316 (call-interactively mapped-binding))))
2318 ;;;_ : Status
2319 ;;;_ . allout-item-location (item-widget)
2320 (defun allout-item-location (item-widget)
2321 "Location of the start of the item's text."
2322 (overlay-start (widget-get item-widget :span-overlay)))
2324 ;;;_ : Icon management
2325 ;;;_ > allout-fetch-icon-image (name)
2326 (defun allout-fetch-icon-image (name)
2327 "Fetch allout icon for symbol NAME.
2329 We use a caching strategy, so the caller doesn't need to do so."
2330 (let* ((types allout-widgets-icon-types)
2331 (use-dir (if (equal (allout-frame-property nil 'background-mode)
2332 'light)
2333 allout-widgets-icons-light-subdir
2334 allout-widgets-icons-dark-subdir))
2335 (key (list name use-dir))
2336 (got (assoc key allout-widgets-icons-cache)))
2337 (if got
2338 ;; display system shows only first of subsequent adjacent
2339 ;; `eq'-identical repeats - use copies to avoid this problem.
2340 (allout-widgets-copy-list (cadr got))
2341 (while (and types (not got))
2342 (setq got
2343 (allout-find-image
2344 (list (append (list :type (car types)
2345 :file (concat use-dir
2346 (symbol-name name)
2347 "." (symbol-name
2348 (car types))))
2349 (if (featurep 'xemacs)
2350 allout-widgets-item-image-properties-xemacs
2351 allout-widgets-item-image-properties-emacs)
2352 ))))
2353 (setq types (cdr types)))
2354 (if got
2355 (push (list key got) allout-widgets-icons-cache))
2356 got)))
2358 ;;;_ : Miscellaneous
2359 ;;;_ > allout-elapsed-time-seconds (triple)
2360 (defun allout-elapsed-time-seconds (end start)
2361 "Return seconds between `current-time' style time START/END triples."
2362 (let ((elapsed (time-subtract end start)))
2363 (float-time elapsed)))
2364 ;;;_ > allout-frame-property (frame property)
2365 (defalias 'allout-frame-property
2366 (cond ((fboundp 'frame-parameter)
2367 'frame-parameter)
2368 ((fboundp 'frame-property)
2369 'frame-property)
2370 (t nil)))
2371 ;;;_ > allout-find-image (specs)
2372 (defalias 'allout-find-image
2373 (if (fboundp 'find-image)
2374 'find-image
2375 nil) ; aka, not-yet-implemented for xemacs.
2377 ;;;_ > allout-widgets-copy-list (list)
2378 (defun allout-widgets-copy-list (list)
2379 ;; duplicated from cl.el 'copy-list' as of 2008-08-17
2380 "Return a copy of LIST, which may be a dotted list.
2381 The elements of LIST are not copied, just the list structure itself."
2382 (if (consp list)
2383 (let ((res nil))
2384 (while (consp list) (push (pop list) res))
2385 (prog1 (nreverse res) (setcdr res list)))
2386 (car list)))
2387 ;;;_ . allout-widgets-count-buttons-in-region (start end)
2388 (defun allout-widgets-count-buttons-in-region (start end)
2389 "Debugging/diagnostic tool - count overlays with 'button' property in region."
2390 (interactive "r")
2391 (setq start (or start (point-min))
2392 end (or end (point-max)))
2393 (if (> start end) (let ((interim start)) (setq start end end interim)))
2394 (let ((button-overlays (delq nil
2395 (mapcar (function (lambda (o)
2396 (if (overlay-get o 'button)
2397 o)))
2398 (overlays-in start end)))))
2399 (length button-overlays)))
2401 ;;;_ : Run unit tests:
2402 (defun allout-widgets-run-unit-tests ()
2403 (message "Running allout-widget tests...")
2405 (allout-test-range-overlaps)
2407 (message "Running allout-widget tests... Done.")
2408 (sit-for .5))
2410 (when allout-widgets-run-unit-tests-on-load
2411 (allout-widgets-run-unit-tests))
2413 ;;;_ : provide
2414 (provide 'allout-widgets)
2416 ;;;_. Local emacs vars.
2417 ;;;_ , Local variables:
2418 ;;;_ , allout-layout: (-1 : 0)
2419 ;;;_ , End: