Minor fixes to version-control material suggseted by RMS and Robert
[emacs.git] / lisp / allout.el
blob49dfef2154774462f9b99783df42899714044d0d
1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992, 1993, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com>
7 ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com>
8 ;; Created: Dec 1991 - first release to usenet
9 ;; Version: 2.2.1
10 ;; Keywords: outlines wp languages
11 ;; Website: http://myriadicity.net/Sundry/EmacsAllout
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
30 ;;; Commentary:
32 ;; Allout outline minor mode provides extensive outline formatting and
33 ;; and manipulation beyond standard emacs outline mode. Some features:
35 ;; - Classic outline-mode topic-oriented navigation and exposure adjustment
36 ;; - Topic-oriented editing including coherent topic and subtopic
37 ;; creation, promotion, demotion, cut/paste across depths, etc.
38 ;; - Incremental search with dynamic exposure and reconcealment of text
39 ;; - Customizable bullet format - enables programming-language specific
40 ;; outlining, for code-folding editing. (Allout code itself is to try it;
41 ;; formatted as an outline - do ESC-x eval-buffer in allout.el; but
42 ;; emacs local file variables need to be enabled when the
43 ;; file was visited - see `enable-local-variables'.)
44 ;; - Configurable per-file initial exposure settings
45 ;; - Symmetric-key and key-pair topic encryption, plus symmetric passphrase
46 ;; mnemonic support, with verification against an established passphrase
47 ;; (using a stashed encrypted dummy string) and user-supplied hint
48 ;; maintenance. (See allout-toggle-current-subtree-encryption docstring.
49 ;; Currently only GnuPG encryption is supported, and integration
50 ;; with gpg-agent is not yet implemented.)
51 ;; - Automatic topic-number maintenance
52 ;; - "Hot-spot" operation, for single-keystroke maneuvering and
53 ;; exposure control (see the allout-mode docstring)
54 ;; - Easy rendering of exposed portions into numbered, latex, indented, etc
55 ;; outline styles
56 ;; - Careful attention to whitespace - enabling blank lines between items
57 ;; and maintenance of hanging indentation (in paragraph auto-fill and
58 ;; across topic promotion and demotion) of topic bodies consistent with
59 ;; indentation of their topic header.
61 ;; and more.
63 ;; See the `allout-mode' function's docstring for an introduction to the
64 ;; mode.
66 ;; The latest development version and helpful notes are available at
67 ;; http://myriadicity.net/Sundry/EmacsAllout .
69 ;; The outline menubar additions provide quick reference to many of
70 ;; the features, and see the docstring of the variable `allout-init'
71 ;; for instructions on priming your Emacs session for automatic
72 ;; activation of allout-mode.
74 ;; See the docstring of the variables `allout-layout' and
75 ;; `allout-auto-activation' for details on automatic activation of
76 ;; `allout-mode' as a minor mode. (It has changed since allout
77 ;; 3.x, for those of you that depend on the old method.)
79 ;; Note - the lines beginning with `;;;_' are outline topic headers.
80 ;; Just `ESC-x eval-buffer' to give it a whirl.
82 ;; ken manheimer (ken dot manheimer at gmail dot com)
84 ;;; Code:
86 ;;;_* Dependency autoloads
87 (require 'overlay)
88 (eval-when-compile
89 ;; Most of the requires here are for stuff covered by autoloads.
90 ;; Since just byte-compiling doesn't trigger autoloads, so that
91 ;; "function not found" warnings would occur without these requires.
92 (progn
93 (require 'pgg)
94 (require 'pgg-gpg)
95 (require 'overlay)
96 ;; `cl' is required for `assert'. `assert' is not covered by a standard
97 ;; autoload, but it is a macro, so that eval-when-compile is sufficient
98 ;; to byte-compile it in, or to do the require when the buffer evalled.
99 (require 'cl)
102 ;;;_* USER CUSTOMIZATION VARIABLES:
104 ;;;_ > defgroup allout
105 (defgroup allout nil
106 "Extensive outline mode for use alone and with other modes."
107 :prefix "allout-"
108 :group 'outlines)
110 ;;;_ + Layout, Mode, and Topic Header Configuration
112 ;;;_ = allout-auto-activation
113 (defcustom allout-auto-activation nil
114 "*Regulates auto-activation modality of allout outlines - see `allout-init'.
116 Setq-default by `allout-init' to regulate whether or not allout
117 outline mode is automatically activated when the buffer-specific
118 variable `allout-layout' is non-nil, and whether or not the layout
119 dictated by `allout-layout' should be imposed on mode activation.
121 With value t, auto-mode-activation and auto-layout are enabled.
122 \(This also depends on `allout-find-file-hook' being installed in
123 `find-file-hook', which is also done by `allout-init'.)
125 With value `ask', auto-mode-activation is enabled, and endorsement for
126 performing auto-layout is asked of the user each time.
128 With value `activate', only auto-mode-activation is enabled,
129 auto-layout is not.
131 With value nil, neither auto-mode-activation nor auto-layout are
132 enabled.
134 See the docstring for `allout-init' for the proper interface to
135 this variable."
136 :type '(choice (const :tag "On" t)
137 (const :tag "Ask about layout" "ask")
138 (const :tag "Mode only" "activate")
139 (const :tag "Off" nil))
140 :group 'allout)
141 ;;;_ = allout-default-layout
142 (defcustom allout-default-layout '(-2 : 0)
143 "*Default allout outline layout specification.
145 This setting specifies the outline exposure to use when
146 `allout-layout' has the local value `t'. This docstring describes the
147 layout specifications.
149 A list value specifies a default layout for the current buffer,
150 to be applied upon activation of `allout-mode'. Any non-nil
151 value will automatically trigger `allout-mode', provided
152 `allout-init' has been called to enable this behavior.
154 The types of elements in the layout specification are:
156 integer - dictate the relative depth to open the corresponding topic(s),
157 where:
158 - negative numbers force the topic to be closed before opening
159 to the absolute value of the number, so all siblings are open
160 only to that level.
161 - positive numbers open to the relative depth indicated by the
162 number, but do not force already opened subtopics to be closed.
163 - 0 means to close topic - hide all subitems.
164 : - repeat spec - apply the preceeding element to all siblings at
165 current level, *up to* those siblings that would be covered by specs
166 following the `:' on the list. Ie, apply to all topics at level but
167 trailing ones accounted for by trailing specs. (Only the first of
168 multiple colons at the same level is honored - later ones are ignored.)
169 * - completely exposes the topic, including bodies
170 + - exposes all subtopics, but not the bodies
171 - - exposes the body of the corresponding topic, but not subtopics
172 list - a nested layout spec, to be applied intricately to its
173 corresponding item(s)
175 Examples:
176 '(-2 : 0)
177 Collapse the top-level topics to show their children and
178 grandchildren, but completely collapse the final top-level topic.
179 '(-1 () : 1 0)
180 Close the first topic so only the immediate subtopics are shown,
181 leave the subsequent topics exposed as they are until the second
182 second to last topic, which is exposed at least one level, and
183 completely close the last topic.
184 '(-2 : -1 *)
185 Expose children and grandchildren of all topics at current
186 level except the last two; expose children of the second to
187 last and completely expose the last one, including its subtopics.
189 See `allout-expose-topic' for more about the exposure process.
191 Also, allout's mode-specific provisions will make topic prefixes default
192 to the comment-start string, if any, of the language of the file. This
193 is modulo the setting of `allout-use-mode-specific-leader', which see."
194 :type 'allout-layout-type
195 :group 'allout)
196 ;;;_ : allout-layout-type
197 (define-widget 'allout-layout-type 'lazy
198 "Allout layout format customization basic building blocks."
199 :type '(repeat
200 (choice (integer :tag "integer (<= zero is strict)")
201 (const :tag ": (repeat prior)" :)
202 (const :tag "* (completely expose)" *)
203 (const :tag "+ (expose all offspring, headlines only)" +)
204 (const :tag "- (expose topic body but not offspring)" -)
205 (allout-layout-type :tag "<Nested layout>"))))
207 ;;;_ = allout-show-bodies
208 (defcustom allout-show-bodies nil
209 "*If non-nil, show entire body when exposing a topic, rather than
210 just the header."
211 :type 'boolean
212 :group 'allout)
213 (make-variable-buffer-local 'allout-show-bodies)
214 ;;;###autoload
215 (put 'allout-show-bodies 'safe-local-variable
216 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
218 ;;;_ = allout-beginning-of-line-cycles
219 (defcustom allout-beginning-of-line-cycles t
220 "*If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
222 Cycling only happens on when the command is repeated, not when it
223 follows a different command.
225 Smart-placement means that repeated calls to this function will
226 advance as follows:
228 - if the cursor is on a non-headline body line and not on the first column:
229 then it goes to the first column
230 - if the cursor is on the first column of a non-headline body line:
231 then it goes to the start of the headline within the item body
232 - if the cursor is on the headline and not the start of the headline:
233 then it goes to the start of the headline
234 - if the cursor is on the start of the headline:
235 then it goes to the bullet character (for hotspot navigation)
236 - if the cursor is on the bullet character:
237 then it goes to the first column of that line (the headline)
238 - if the cursor is on the first column of the headline:
239 then it goes to the start of the headline within the item body.
241 In this fashion, you can use the beginning-of-line command to do
242 its normal job and then, when repeated, advance through the
243 entry, cycling back to start.
245 If this configuration variable is nil, then the cursor is just
246 advanced to the beginning of the line and remains there on
247 repeated calls."
248 :type 'boolean :group 'allout)
249 ;;;_ = allout-end-of-line-cycles
250 (defcustom allout-end-of-line-cycles t
251 "*If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
253 Cycling only happens on when the command is repeated, not when it
254 follows a different command.
256 Smart-placement means that repeated calls to this function will
257 advance as follows:
259 - if the cursor is not on the end-of-line,
260 then it goes to the end-of-line
261 - if the cursor is on the end-of-line but not the end-of-entry,
262 then it goes to the end-of-entry, exposing it if necessary
263 - if the cursor is on the end-of-entry,
264 then it goes to the end of the head line
266 In this fashion, you can use the end-of-line command to do its
267 normal job and then, when repeated, advance through the entry,
268 cycling back to start.
270 If this configuration variable is nil, then the cursor is just
271 advanced to the end of the line and remains there on repeated
272 calls."
273 :type 'boolean :group 'allout)
275 ;;;_ = allout-header-prefix
276 (defcustom allout-header-prefix "."
277 ;; this string is treated as literal match. it will be `regexp-quote'd, so
278 ;; one cannot use regular expressions to match varying header prefixes.
279 "*Leading string which helps distinguish topic headers.
281 Outline topic header lines are identified by a leading topic
282 header prefix, which mostly have the value of this var at their front.
283 Level 1 topics are exceptions. They consist of only a single
284 character, which is typically set to the `allout-primary-bullet'."
285 :type 'string
286 :group 'allout)
287 (make-variable-buffer-local 'allout-header-prefix)
288 ;;;###autoload
289 (put 'allout-header-prefix 'safe-local-variable 'stringp)
290 ;;;_ = allout-primary-bullet
291 (defcustom allout-primary-bullet "*"
292 "Bullet used for top-level outline topics.
294 Outline topic header lines are identified by a leading topic header
295 prefix, which is concluded by bullets that includes the value of this
296 var and the respective allout-*-bullets-string vars.
298 The value of an asterisk (`*') provides for backwards compatibility
299 with the original Emacs outline mode. See `allout-plain-bullets-string'
300 and `allout-distinctive-bullets-string' for the range of available
301 bullets."
302 :type 'string
303 :group 'allout)
304 (make-variable-buffer-local 'allout-primary-bullet)
305 ;;;###autoload
306 (put 'allout-primary-bullet 'safe-local-variable 'stringp)
307 ;;;_ = allout-plain-bullets-string
308 (defcustom allout-plain-bullets-string ".,"
309 "*The bullets normally used in outline topic prefixes.
311 See `allout-distinctive-bullets-string' for the other kind of
312 bullets.
314 DO NOT include the close-square-bracket, `]', as a bullet.
316 Outline mode has to be reactivated in order for changes to the value
317 of this var to take effect."
318 :type 'string
319 :group 'allout)
320 (make-variable-buffer-local 'allout-plain-bullets-string)
321 ;;;###autoload
322 (put 'allout-plain-bullets-string 'safe-local-variable 'stringp)
323 ;;;_ = allout-distinctive-bullets-string
324 (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^"
325 "*Persistent outline header bullets used to distinguish special topics.
327 These bullets are distinguish topics with particular character.
328 They are not used by default in the topic creation routines, but
329 are offered as options when you modify topic creation with a
330 universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]).
332 Distinctive bullets are not cycled when topics are shifted or
333 otherwise automatically rebulleted, so their marking is
334 persistent until deliberately changed. Their significance is
335 purely by convention, however. Some conventions suggest
336 themselves:
338 `(' - open paren - an aside or incidental point
339 `?' - question mark - uncertain or outright question
340 `!' - exclamation point/bang - emphatic
341 `[' - open square bracket - meta-note, about item instead of item's subject
342 `\"' - double quote - a quotation or other citation
343 `=' - equal sign - an assignement, equating a name with some connotation
344 `^' - carat - relates to something above
346 Some are more elusive, but their rationale may be recognizable:
348 `+' - plus - pending consideration, completion
349 `_' - underscore - done, completed
350 `&' - ampersand - addendum, furthermore
352 \(Some other non-plain bullets have special meaning to the
353 software. By default:
355 `~' marks encryptable topics - see `allout-topic-encryption-bullet'
356 `#' marks auto-numbered bullets - see `allout-numbered-bullet'.)
358 See `allout-plain-bullets-string' for the standard, alternating
359 bullets.
361 You must run `set-allout-regexp' in order for outline mode to
362 adopt changes of this value.
364 DO NOT include the close-square-bracket, `]', on either of the bullet
365 strings."
366 :type 'string
367 :group 'allout)
368 (make-variable-buffer-local 'allout-distinctive-bullets-string)
369 ;;;###autoload
370 (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp)
372 ;;;_ = allout-use-mode-specific-leader
373 (defcustom allout-use-mode-specific-leader t
374 "*When non-nil, use mode-specific topic-header prefixes.
376 Allout outline mode will use the mode-specific `allout-mode-leaders' or
377 comment-start string, if any, to lead the topic prefix string, so topic
378 headers look like comments in the programming language. It will also use
379 the comment-start string, with an '_' appended, for `allout-primary-bullet'.
381 String values are used as literals, not regular expressions, so
382 do not escape any regulare-expression characters.
384 Value t means to first check for assoc value in `allout-mode-leaders'
385 alist, then use comment-start string, if any, then use default (`.').
386 \(See note about use of comment-start strings, below.)
388 Set to the symbol for either of `allout-mode-leaders' or
389 `comment-start' to use only one of them, respectively.
391 Value nil means to always use the default (`.') and leave
392 `allout-primary-bullet' unaltered.
394 comment-start strings that do not end in spaces are tripled in
395 the header-prefix, and an `_' underscore is tacked on the end, to
396 distinguish them from regular comment strings. comment-start
397 strings that do end in spaces are not tripled, but an underscore
398 is substituted for the space. [This presumes that the space is
399 for appearance, not comment syntax. You can use
400 `allout-mode-leaders' to override this behavior, when
401 undesired.]"
402 :type '(choice (const t) (const nil) string
403 (const allout-mode-leaders)
404 (const comment-start))
405 :group 'allout)
406 ;;;###autoload
407 (put 'allout-use-mode-specific-leader 'safe-local-variable
408 '(lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start))
409 (stringp x))))
410 ;;;_ = allout-mode-leaders
411 (defvar allout-mode-leaders '()
412 "Specific allout-prefix leading strings per major modes.
414 Use this if the mode's comment-start string isn't what you
415 prefer, or if the mode lacks a comment-start string. See
416 `allout-use-mode-specific-leader' for more details.
418 If you're constructing a string that will comment-out outline
419 structuring so it can be included in program code, append an extra
420 character, like an \"_\" underscore, to distinguish the lead string
421 from regular comments that start at the beginning-of-line.")
423 ;;;_ = allout-old-style-prefixes
424 (defcustom allout-old-style-prefixes nil
425 "*When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
427 Non-nil restricts the topic creation and modification
428 functions to asterix-padded prefixes, so they look exactly
429 like the original Emacs-outline style prefixes.
431 Whatever the setting of this variable, both old and new style prefixes
432 are always respected by the topic maneuvering functions."
433 :type 'boolean
434 :group 'allout)
435 (make-variable-buffer-local 'allout-old-style-prefixes)
436 ;;;###autoload
437 (put 'allout-old-style-prefixes 'safe-local-variable
438 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
439 ;;;_ = allout-stylish-prefixes - alternating bullets
440 (defcustom allout-stylish-prefixes t
441 "*Do fancy stuff with topic prefix bullets according to level, etc.
443 Non-nil enables topic creation, modification, and repositioning
444 functions to vary the topic bullet char (the char that marks the topic
445 depth) just preceding the start of the topic text) according to level.
446 Otherwise, only asterisks (`*') and distinctive bullets are used.
448 This is how an outline can look (but sans indentation) with stylish
449 prefixes:
451 * Top level
452 .* A topic
453 . + One level 3 subtopic
454 . . One level 4 subtopic
455 . . A second 4 subtopic
456 . + Another level 3 subtopic
457 . #1 A numbered level 4 subtopic
458 . #2 Another
459 . ! Another level 4 subtopic with a different distinctive bullet
460 . #4 And another numbered level 4 subtopic
462 This would be an outline with stylish prefixes inhibited (but the
463 numbered and other distinctive bullets retained):
465 * Top level
466 .* A topic
467 . * One level 3 subtopic
468 . * One level 4 subtopic
469 . * A second 4 subtopic
470 . * Another level 3 subtopic
471 . #1 A numbered level 4 subtopic
472 . #2 Another
473 . ! Another level 4 subtopic with a different distinctive bullet
474 . #4 And another numbered level 4 subtopic
476 Stylish and constant prefixes (as well as old-style prefixes) are
477 always respected by the topic maneuvering functions, regardless of
478 this variable setting.
480 The setting of this var is not relevant when `allout-old-style-prefixes'
481 is non-nil."
482 :type 'boolean
483 :group 'allout)
484 (make-variable-buffer-local 'allout-stylish-prefixes)
485 ;;;###autoload
486 (put 'allout-stylish-prefixes 'safe-local-variable
487 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
489 ;;;_ = allout-numbered-bullet
490 (defcustom allout-numbered-bullet "#"
491 "*String designating bullet of topics that have auto-numbering; nil for none.
493 Topics having this bullet have automatic maintenance of a sibling
494 sequence-number tacked on, just after the bullet. Conventionally set
495 to \"#\", you can set it to a bullet of your choice. A nil value
496 disables numbering maintenance."
497 :type '(choice (const nil) string)
498 :group 'allout)
499 (make-variable-buffer-local 'allout-numbered-bullet)
500 ;;;###autoload
501 (put 'allout-numbered-bullet 'safe-local-variable
502 (if (fboundp 'string-or-null-p)
503 'string-or-null-p
504 '(lambda (x) (or (stringp x) (null x)))))
505 ;;;_ = allout-file-xref-bullet
506 (defcustom allout-file-xref-bullet "@"
507 "*Bullet signifying file cross-references, for `allout-resolve-xref'.
509 Set this var to the bullet you want to use for file cross-references."
510 :type '(choice (const nil) string)
511 :group 'allout)
512 ;;;###autoload
513 (put 'allout-file-xref-bullet 'safe-local-variable
514 (if (fboundp 'string-or-null-p)
515 'string-or-null-p
516 '(lambda (x) (or (stringp x) (null x)))))
517 ;;;_ = allout-presentation-padding
518 (defcustom allout-presentation-padding 2
519 "*Presentation-format white-space padding factor, for greater indent."
520 :type 'integer
521 :group 'allout)
523 (make-variable-buffer-local 'allout-presentation-padding)
524 ;;;###autoload
525 (put 'allout-presentation-padding 'safe-local-variable 'integerp)
527 ;;;_ = allout-abbreviate-flattened-numbering
528 (defcustom allout-abbreviate-flattened-numbering nil
529 "*If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
530 numbers to minimal amount with some context. Otherwise, entire
531 numbers are always used."
532 :type 'boolean
533 :group 'allout)
535 ;;;_ + LaTeX formatting
536 ;;;_ - allout-number-pages
537 (defcustom allout-number-pages nil
538 "*Non-nil turns on page numbering for LaTeX formatting of an outline."
539 :type 'boolean
540 :group 'allout)
541 ;;;_ - allout-label-style
542 (defcustom allout-label-style "\\large\\bf"
543 "*Font and size of labels for LaTeX formatting of an outline."
544 :type 'string
545 :group 'allout)
546 ;;;_ - allout-head-line-style
547 (defcustom allout-head-line-style "\\large\\sl "
548 "*Font and size of entries for LaTeX formatting of an outline."
549 :type 'string
550 :group 'allout)
551 ;;;_ - allout-body-line-style
552 (defcustom allout-body-line-style " "
553 "*Font and size of entries for LaTeX formatting of an outline."
554 :type 'string
555 :group 'allout)
556 ;;;_ - allout-title-style
557 (defcustom allout-title-style "\\Large\\bf"
558 "*Font and size of titles for LaTeX formatting of an outline."
559 :type 'string
560 :group 'allout)
561 ;;;_ - allout-title
562 (defcustom allout-title '(or buffer-file-name (buffer-name))
563 "*Expression to be evaluated to determine the title for LaTeX
564 formatted copy."
565 :type 'sexp
566 :group 'allout)
567 ;;;_ - allout-line-skip
568 (defcustom allout-line-skip ".05cm"
569 "*Space between lines for LaTeX formatting of an outline."
570 :type 'string
571 :group 'allout)
572 ;;;_ - allout-indent
573 (defcustom allout-indent ".3cm"
574 "*LaTeX formatted depth-indent spacing."
575 :type 'string
576 :group 'allout)
578 ;;;_ + Topic encryption
579 ;;;_ = allout-encryption group
580 (defgroup allout-encryption nil
581 "Settings for topic encryption features of allout outliner."
582 :group 'allout)
583 ;;;_ = allout-topic-encryption-bullet
584 (defcustom allout-topic-encryption-bullet "~"
585 "*Bullet signifying encryption of the entry's body."
586 :type '(choice (const nil) string)
587 :version "22.0"
588 :group 'allout-encryption)
589 ;;;_ = allout-passphrase-verifier-handling
590 (defcustom allout-passphrase-verifier-handling t
591 "*Enable use of symmetric encryption passphrase verifier if non-nil.
593 See the docstring for the `allout-enable-file-variable-adjustment'
594 variable for details about allout ajustment of file variables."
595 :type 'boolean
596 :version "22.0"
597 :group 'allout-encryption)
598 (make-variable-buffer-local 'allout-passphrase-verifier-handling)
599 ;;;_ = allout-passphrase-hint-handling
600 (defcustom allout-passphrase-hint-handling 'always
601 "*Dictate outline encryption passphrase reminder handling:
603 always - always show reminder when prompting
604 needed - show reminder on passphrase entry failure
605 disabled - never present or adjust reminder
607 See the docstring for the `allout-enable-file-variable-adjustment'
608 variable for details about allout ajustment of file variables."
609 :type '(choice (const always)
610 (const needed)
611 (const disabled))
612 :version "22.0"
613 :group 'allout-encryption)
614 (make-variable-buffer-local 'allout-passphrase-hint-handling)
615 ;;;_ = allout-encrypt-unencrypted-on-saves
616 (defcustom allout-encrypt-unencrypted-on-saves t
617 "*When saving, should topics pending encryption be encrypted?
619 The idea is to prevent file-system exposure of any un-encrypted stuff, and
620 mostly covers both deliberate file writes and auto-saves.
622 - Yes: encrypt all topics pending encryption, even if it's the one
623 currently being edited. (In that case, the currently edited topic
624 will be automatically decrypted before any user interaction, so they
625 can continue editing but the copy on the file system will be
626 encrypted.)
627 Auto-saves will use the \"All except current topic\" mode if this
628 one is selected, to avoid practical difficulties - see below.
629 - All except current topic: skip the topic currently being edited, even if
630 it's pending encryption. This may expose the current topic on the
631 file sytem, but avoids the nuisance of prompts for the encryption
632 passphrase in the middle of editing for, eg, autosaves.
633 This mode is used for auto-saves for both this option and \"Yes\".
634 - No: leave it to the user to encrypt any unencrypted topics.
636 For practical reasons, auto-saves always use the 'except-current policy
637 when auto-encryption is enabled. (Otherwise, spurious passphrase prompts
638 and unavoidable timing collisions are too disruptive.) If security for a
639 file requires that even the current topic is never auto-saved in the clear,
640 disable auto-saves for that file."
642 :type '(choice (const :tag "Yes" t)
643 (const :tag "All except current topic" except-current)
644 (const :tag "No" nil))
645 :version "22.0"
646 :group 'allout-encryption)
647 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves)
649 ;;;_ + Developer
650 ;;;_ = allout-developer group
651 (defgroup allout-developer nil
652 "Settings for topic encryption features of allout outliner."
653 :group 'allout)
654 ;;;_ = allout-run-unit-tests-on-load
655 (defcustom allout-run-unit-tests-on-load nil
656 "*When non-nil, unit tests will be run at end of loading the allout module.
658 Generally, allout code developers are the only ones who'll want to set this.
660 \(If set, this makes it an even better practice to exercise changes by
661 doing byte-compilation with a repeat count, so the file is loaded after
662 compilation.)
664 See `allout-run-unit-tests' to see what's run."
665 :type 'boolean
666 :group 'allout-developer)
668 ;;;_ + Miscellaneous customization
670 ;;;_ = allout-command-prefix
671 (defcustom allout-command-prefix "\C-c "
672 "*Key sequence to be used as prefix for outline mode command key bindings.
674 Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're
675 willing to let allout use a bunch of \C-c keybindings."
676 :type 'string
677 :group 'allout)
679 ;;;_ = allout-keybindings-list
680 ;;; You have to reactivate allout-mode - `(allout-mode t)' - to
681 ;;; institute changes to this var.
682 (defvar allout-keybindings-list ()
683 "*List of `allout-mode' key / function bindings, for `allout-mode-map'.
685 String or vector key will be prefaced with `allout-command-prefix',
686 unless optional third, non-nil element is present.")
687 (setq allout-keybindings-list
689 ; Motion commands:
690 ("\C-n" allout-next-visible-heading)
691 ("\C-p" allout-previous-visible-heading)
692 ("\C-u" allout-up-current-level)
693 ("\C-f" allout-forward-current-level)
694 ("\C-b" allout-backward-current-level)
695 ("\C-a" allout-beginning-of-current-entry)
696 ("\C-e" allout-end-of-entry)
697 ; Exposure commands:
698 ("\C-i" allout-show-children)
699 ("\C-s" allout-show-current-subtree)
700 ("\C-h" allout-hide-current-subtree)
701 ("h" allout-hide-current-subtree)
702 ("\C-o" allout-show-current-entry)
703 ("!" allout-show-all)
704 ("x" allout-toggle-current-subtree-encryption)
705 ; Alteration commands:
706 (" " allout-open-sibtopic)
707 ("." allout-open-subtopic)
708 ("," allout-open-supertopic)
709 ("'" allout-shift-in)
710 (">" allout-shift-in)
711 ("<" allout-shift-out)
712 ("\C-m" allout-rebullet-topic)
713 ("*" allout-rebullet-current-heading)
714 ("#" allout-number-siblings)
715 ("\C-k" allout-kill-line t)
716 ("\M-k" allout-copy-line-as-kill t)
717 ("\C-y" allout-yank t)
718 ("\M-y" allout-yank-pop t)
719 ("\C-k" allout-kill-topic)
720 ("\M-k" allout-copy-topic-as-kill)
721 ; Miscellaneous commands:
722 ;([?\C-\ ] allout-mark-topic)
723 ("@" allout-resolve-xref)
724 ("=c" allout-copy-exposed-to-buffer)
725 ("=i" allout-indented-exposed-to-buffer)
726 ("=t" allout-latexify-exposed)
727 ("=p" allout-flatten-exposed-to-buffer)))
729 ;;;_ = allout-inhibit-auto-fill
730 (defcustom allout-inhibit-auto-fill nil
731 "*If non-nil, auto-fill will be inhibited in the allout buffers.
733 You can customize this setting to set it for all allout buffers, or set it
734 in individual buffers if you want to inhibit auto-fill only in particular
735 buffers. (You could use a function on `allout-mode-hook' to inhibit
736 auto-fill according, eg, to the major mode.)
738 If you don't set this and auto-fill-mode is enabled, allout will use the
739 value that `normal-auto-fill-function', if any, when allout mode starts, or
740 else allout's special hanging-indent maintaining auto-fill function,
741 `allout-auto-fill'."
742 :type 'boolean
743 :group 'allout)
744 (make-variable-buffer-local 'allout-inhibit-auto-fill)
746 ;;;_ = allout-use-hanging-indents
747 (defcustom allout-use-hanging-indents t
748 "*If non-nil, topic body text auto-indent defaults to indent of the header.
749 Ie, it is indented to be just past the header prefix. This is
750 relevant mostly for use with indented-text-mode, or other situations
751 where auto-fill occurs."
752 :type 'boolean
753 :group 'allout)
754 (make-variable-buffer-local 'allout-use-hanging-indents)
755 ;;;###autoload
756 (put 'allout-use-hanging-indents 'safe-local-variable
757 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
759 ;;;_ = allout-reindent-bodies
760 (defcustom allout-reindent-bodies (if allout-use-hanging-indents
761 'text)
762 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
764 When active, topic body lines that are indented even with or beyond
765 their topic header are reindented to correspond with depth shifts of
766 the header.
768 A value of t enables reindent in non-programming-code buffers, ie
769 those that do not have the variable `comment-start' set. A value of
770 `force' enables reindent whether or not `comment-start' is set."
771 :type '(choice (const nil) (const t) (const text) (const force))
772 :group 'allout)
774 (make-variable-buffer-local 'allout-reindent-bodies)
775 ;;;###autoload
776 (put 'allout-reindent-bodies 'safe-local-variable
777 '(lambda (x) (memq x '(nil t text force))))
779 ;;;_ = allout-enable-file-variable-adjustment
780 (defcustom allout-enable-file-variable-adjustment t
781 "*If non-nil, some allout outline actions edit Emacs local file var text.
783 This can range from changes to existing entries, addition of new ones,
784 and creation of a new local variables section when necessary.
786 Emacs file variables adjustments are also inhibited if `enable-local-variables'
787 is nil.
789 Operations potentially causing edits include allout encryption routines.
790 For details, see `allout-toggle-current-subtree-encryption's docstring."
791 :type 'boolean
792 :group 'allout)
793 (make-variable-buffer-local 'allout-enable-file-variable-adjustment)
795 ;;;_* CODE - no user customizations below.
797 ;;;_ #1 Internal Outline Formatting and Configuration
798 ;;;_ : Version
799 ;;;_ = allout-version
800 (defvar allout-version "2.2.1"
801 "Version of currently loaded outline package. (allout.el)")
802 ;;;_ > allout-version
803 (defun allout-version (&optional here)
804 "Return string describing the loaded outline version."
805 (interactive "P")
806 (let ((msg (concat "Allout Outline Mode v " allout-version)))
807 (if here (insert msg))
808 (message "%s" msg)
809 msg))
810 ;;;_ : Mode activation (defined here because it's referenced early)
811 ;;;_ = allout-mode
812 (defvar allout-mode nil "Allout outline mode minor-mode flag.")
813 (make-variable-buffer-local 'allout-mode)
814 ;;;_ = allout-layout nil
815 (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL - see docstring.
816 "Buffer-specific setting for allout layout.
818 In buffers where this is non-nil (and if `allout-init' has been run, to
819 enable this behavior), `allout-mode' will be automatically activated. The
820 layout dictated by the value will be used to set the initial exposure when
821 `allout-mode' is activated.
823 \*You should not setq-default this variable non-nil unless you want every
824 visited file to be treated as an allout file.*
826 The value would typically be set by a file local variable. For
827 example, the following lines at the bottom of an Emacs Lisp file:
829 ;;;Local variables:
830 ;;;allout-layout: (0 : -1 -1 0)
831 ;;;End:
833 dictate activation of `allout-mode' mode when the file is visited
834 \(presuming allout-init was already run), followed by the
835 equivalent of `(allout-expose-topic 0 : -1 -1 0)'. (This is
836 the layout used for the allout.el source file.)
838 `allout-default-layout' describes the specification format.
839 `allout-layout' can additionally have the value `t', in which
840 case the value of `allout-default-layout' is used.")
841 (make-variable-buffer-local 'allout-layout)
842 ;;;###autoload
843 (put 'allout-layout 'safe-local-variable
844 '(lambda (x) (or (numberp x) (listp x) (memq x '(: * + -)))))
846 ;;;_ : Topic header format
847 ;;;_ = allout-regexp
848 (defvar allout-regexp ""
849 "*Regular expression to match the beginning of a heading line.
851 Any line whose beginning matches this regexp is considered a
852 heading. This var is set according to the user configuration vars
853 by `set-allout-regexp'.")
854 (make-variable-buffer-local 'allout-regexp)
855 ;;;_ = allout-bullets-string
856 (defvar allout-bullets-string ""
857 "A string dictating the valid set of outline topic bullets.
859 This var should *not* be set by the user - it is set by `set-allout-regexp',
860 and is produced from the elements of `allout-plain-bullets-string'
861 and `allout-distinctive-bullets-string'.")
862 (make-variable-buffer-local 'allout-bullets-string)
863 ;;;_ = allout-bullets-string-len
864 (defvar allout-bullets-string-len 0
865 "Length of current buffers' `allout-plain-bullets-string'.")
866 (make-variable-buffer-local 'allout-bullets-string-len)
867 ;;;_ = allout-depth-specific-regexp
868 (defvar allout-depth-specific-regexp ""
869 "*Regular expression to match a heading line prefix for a particular depth.
871 This expression is used to search for depth-specific topic
872 headers at depth 2 and greater. Use `allout-depth-one-regexp'
873 for to seek topics at depth one.
875 This var is set according to the user configuration vars by
876 `set-allout-regexp'. It is prepared with format strings for two
877 decimal numbers, which should each be one less than the depth of the
878 topic prefix to be matched.")
879 (make-variable-buffer-local 'allout-depth-specific-regexp)
880 ;;;_ = allout-depth-one-regexp
881 (defvar allout-depth-one-regexp ""
882 "*Regular expression to match a heading line prefix for depth one.
884 This var is set according to the user configuration vars by
885 `set-allout-regexp'. It is prepared with format strings for two
886 decimal numbers, which should each be one less than the depth of the
887 topic prefix to be matched.")
888 (make-variable-buffer-local 'allout-depth-one-regexp)
889 ;;;_ = allout-line-boundary-regexp
890 (defvar allout-line-boundary-regexp ()
891 "`allout-regexp' with outline style beginning-of-line anchor.
893 This is properly set by `set-allout-regexp'.")
894 (make-variable-buffer-local 'allout-line-boundary-regexp)
895 ;;;_ = allout-bob-regexp
896 (defvar allout-bob-regexp ()
897 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
898 (make-variable-buffer-local 'allout-bob-regexp)
899 ;;;_ = allout-header-subtraction
900 (defvar allout-header-subtraction (1- (length allout-header-prefix))
901 "Allout-header prefix length to subtract when computing topic depth.")
902 (make-variable-buffer-local 'allout-header-subtraction)
903 ;;;_ = allout-plain-bullets-string-len
904 (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string)
905 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
906 (make-variable-buffer-local 'allout-plain-bullets-string-len)
908 ;;;_ = allout-doublecheck-at-and-shallower
909 (defconst allout-doublecheck-at-and-shallower 2
910 "Validate apparent topics of this depth and shallower as being non-aberrant.
912 Verified with `allout-aberrant-container-p'. This check's usefulness is
913 limited to shallow depths, because the determination of aberrance
914 is according to the mistaken item being followed by a legitimate item of
915 excessively greater depth.")
916 ;;;_ X allout-reset-header-lead (header-lead)
917 (defun allout-reset-header-lead (header-lead)
918 "*Reset the leading string used to identify topic headers."
919 (interactive "sNew lead string: ")
920 (setq allout-header-prefix header-lead)
921 (setq allout-header-subtraction (1- (length allout-header-prefix)))
922 (set-allout-regexp))
923 ;;;_ X allout-lead-with-comment-string (header-lead)
924 (defun allout-lead-with-comment-string (&optional header-lead)
925 "*Set the topic-header leading string to specified string.
927 Useful when for encapsulating outline structure in programming
928 language comments. Returns the leading string."
930 (interactive "P")
931 (if (not (stringp header-lead))
932 (setq header-lead (read-string
933 "String prefix for topic headers: ")))
934 (setq allout-reindent-bodies nil)
935 (allout-reset-header-lead header-lead)
936 header-lead)
937 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
938 (defun allout-infer-header-lead-and-primary-bullet ()
939 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
941 Works according to settings of:
943 `comment-start'
944 `allout-header-prefix' (default)
945 `allout-use-mode-specific-leader'
946 and `allout-mode-leaders'.
948 Apply this via (re)activation of `allout-mode', rather than
949 invoking it directly."
950 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader)
951 (if (or (stringp allout-use-mode-specific-leader)
952 (memq allout-use-mode-specific-leader
953 '(allout-mode-leaders
954 comment-start
955 t)))
956 allout-use-mode-specific-leader
957 ;; Oops - garbled value, equate with effect of 't:
958 t)))
959 (leader
960 (cond
961 ((not use-leader) nil)
962 ;; Use the explicitly designated leader:
963 ((stringp use-leader) use-leader)
964 (t (or (and (memq use-leader '(t allout-mode-leaders))
965 ;; Get it from outline mode leaders?
966 (cdr (assq major-mode allout-mode-leaders)))
967 ;; ... didn't get from allout-mode-leaders...
968 (and (memq use-leader '(t comment-start))
969 comment-start
970 ;; Use comment-start, maybe tripled, and with
971 ;; underscore:
972 (concat
973 (if (string= " "
974 (substring comment-start
975 (1- (length comment-start))))
976 ;; Use comment-start, sans trailing space:
977 (substring comment-start 0 -1)
978 (concat comment-start comment-start comment-start))
979 ;; ... and append underscore, whichever:
980 "_")))))))
981 (if (not leader)
983 (setq allout-header-prefix leader)
984 (if (not allout-old-style-prefixes)
985 ;; setting allout-primary-bullet makes the top level topics use -
986 ;; actually, be - the special prefix:
987 (setq allout-primary-bullet leader))
988 allout-header-prefix)))
989 (defalias 'allout-infer-header-lead
990 'allout-infer-header-lead-and-primary-bullet)
991 ;;;_ > allout-infer-body-reindent ()
992 (defun allout-infer-body-reindent ()
993 "Determine proper setting for `allout-reindent-bodies'.
995 Depends on default setting of `allout-reindent-bodies' (which see)
996 and presence of setting for `comment-start', to tell whether the
997 file is programming code."
998 (if (and allout-reindent-bodies
999 comment-start
1000 (not (eq 'force allout-reindent-bodies)))
1001 (setq allout-reindent-bodies nil)))
1002 ;;;_ > set-allout-regexp ()
1003 (defun set-allout-regexp ()
1004 "Generate proper topic-header regexp form for outline functions.
1006 Works with respect to `allout-plain-bullets-string' and
1007 `allout-distinctive-bullets-string'.
1009 Also refresh various data structures that hinge on the regexp."
1011 (interactive)
1012 ;; Derive allout-bullets-string from user configured components:
1013 (setq allout-bullets-string "")
1014 (let ((strings (list 'allout-plain-bullets-string
1015 'allout-distinctive-bullets-string
1016 'allout-primary-bullet))
1017 cur-string
1018 cur-len
1019 cur-char
1020 index)
1021 (while strings
1022 (setq index 0)
1023 (setq cur-len (length (setq cur-string (symbol-value (car strings)))))
1024 (while (< index cur-len)
1025 (setq cur-char (aref cur-string index))
1026 (setq allout-bullets-string
1027 (concat allout-bullets-string
1028 (cond
1029 ; Single dash would denote a
1030 ; sequence, repeated denotes
1031 ; a dash:
1032 ((eq cur-char ?-) "--")
1033 ; literal close-square-bracket
1034 ; doesn't work right in the
1035 ; expr, exclude it:
1036 ((eq cur-char ?\]) "")
1037 (t (regexp-quote (char-to-string cur-char))))))
1038 (setq index (1+ index)))
1039 (setq strings (cdr strings)))
1041 ;; Derive next for repeated use in allout-pending-bullet:
1042 (setq allout-plain-bullets-string-len (length allout-plain-bullets-string))
1043 (setq allout-header-subtraction (1- (length allout-header-prefix)))
1045 (let (new-part old-part)
1046 (setq new-part (concat "\\("
1047 (regexp-quote allout-header-prefix)
1048 "[ \t]*"
1049 ;; already regexp-quoted in a custom way:
1050 "[" allout-bullets-string "]"
1051 "\\)")
1052 old-part (concat "\\("
1053 (regexp-quote allout-primary-bullet)
1054 "\\|"
1055 (regexp-quote allout-header-prefix)
1056 "\\)"
1058 " ?[^" allout-primary-bullet "]")
1059 allout-regexp (concat new-part
1060 "\\|"
1061 old-part
1062 "\\|\^l")
1064 allout-line-boundary-regexp (concat "\n" new-part
1065 "\\|"
1066 "\n" old-part)
1068 allout-bob-regexp (concat "\\`" new-part
1069 "\\|"
1070 "\\`" old-part))
1072 (setq allout-depth-specific-regexp
1073 (concat "\\(^\\|\\`\\)"
1074 "\\("
1076 ;; new-style spacers-then-bullet string:
1077 "\\("
1078 (allout-format-quote (regexp-quote allout-header-prefix))
1079 " \\{%s\\}"
1080 "[" (allout-format-quote allout-bullets-string) "]"
1081 "\\)"
1083 ;; old-style all-bullets string, if primary not multi-char:
1084 (if (< 0 allout-header-subtraction)
1086 (concat "\\|\\("
1087 (allout-format-quote
1088 (regexp-quote allout-primary-bullet))
1089 (allout-format-quote
1090 (regexp-quote allout-primary-bullet))
1091 (allout-format-quote
1092 (regexp-quote allout-primary-bullet))
1093 "\\{%s\\}"
1094 ;; disqualify greater depths:
1095 "[^"
1096 (allout-format-quote allout-primary-bullet)
1097 "]\\)"
1099 "\\)"
1101 (setq allout-depth-one-regexp
1102 (concat "\\(^\\|\\`\\)"
1103 "\\("
1105 "\\("
1106 (regexp-quote allout-header-prefix)
1107 ;; disqualify any bullet char following any amount of
1108 ;; intervening whitespace:
1109 " *"
1110 (concat "[^ " allout-bullets-string "]")
1111 "\\)"
1112 (if (< 0 allout-header-subtraction)
1113 ;; Need not support anything like the old
1114 ;; bullet style if the prefix is multi-char.
1116 (concat "\\|"
1117 (regexp-quote allout-primary-bullet)
1118 ;; disqualify deeper primary-bullet sequences:
1119 "[^" allout-primary-bullet "]"))
1120 "\\)"
1121 ))))
1122 ;;;_ : Key bindings
1123 ;;;_ = allout-mode-map
1124 (defvar allout-mode-map nil "Keybindings for (allout) outline minor mode.")
1125 ;;;_ > produce-allout-mode-map (keymap-alist &optional base-map)
1126 (defun produce-allout-mode-map (keymap-list &optional base-map)
1127 "Produce keymap for use as allout-mode-map, from KEYMAP-LIST.
1129 Built on top of optional BASE-MAP, or empty sparse map if none specified.
1130 See doc string for allout-keybindings-list for format of binding list."
1131 (let ((map (or base-map (make-sparse-keymap)))
1132 (pref (list allout-command-prefix)))
1133 (mapc (function
1134 (lambda (cell)
1135 (let ((add-pref (null (cdr (cdr cell))))
1136 (key-suff (list (car cell))))
1137 (apply 'define-key
1138 (list map
1139 (apply 'concat (if add-pref
1140 (append pref key-suff)
1141 key-suff))
1142 (car (cdr cell)))))))
1143 keymap-list)
1144 map))
1145 ;;;_ : Menu bar
1146 (defvar allout-mode-exposure-menu)
1147 (defvar allout-mode-editing-menu)
1148 (defvar allout-mode-navigation-menu)
1149 (defvar allout-mode-misc-menu)
1150 (defun produce-allout-mode-menubar-entries ()
1151 (require 'easymenu)
1152 (easy-menu-define allout-mode-exposure-menu
1153 allout-mode-map
1154 "Allout outline exposure menu."
1155 '("Exposure"
1156 ["Show Entry" allout-show-current-entry t]
1157 ["Show Children" allout-show-children t]
1158 ["Show Subtree" allout-show-current-subtree t]
1159 ["Hide Subtree" allout-hide-current-subtree t]
1160 ["Hide Leaves" allout-hide-current-leaves t]
1161 "----"
1162 ["Show All" allout-show-all t]))
1163 (easy-menu-define allout-mode-editing-menu
1164 allout-mode-map
1165 "Allout outline editing menu."
1166 '("Headings"
1167 ["Open Sibling" allout-open-sibtopic t]
1168 ["Open Subtopic" allout-open-subtopic t]
1169 ["Open Supertopic" allout-open-supertopic t]
1170 "----"
1171 ["Shift Topic In" allout-shift-in t]
1172 ["Shift Topic Out" allout-shift-out t]
1173 ["Rebullet Topic" allout-rebullet-topic t]
1174 ["Rebullet Heading" allout-rebullet-current-heading t]
1175 ["Number Siblings" allout-number-siblings t]
1176 "----"
1177 ["Toggle Topic Encryption"
1178 allout-toggle-current-subtree-encryption
1179 (> (allout-current-depth) 1)]))
1180 (easy-menu-define allout-mode-navigation-menu
1181 allout-mode-map
1182 "Allout outline navigation menu."
1183 '("Navigation"
1184 ["Next Visible Heading" allout-next-visible-heading t]
1185 ["Previous Visible Heading"
1186 allout-previous-visible-heading t]
1187 "----"
1188 ["Up Level" allout-up-current-level t]
1189 ["Forward Current Level" allout-forward-current-level t]
1190 ["Backward Current Level"
1191 allout-backward-current-level t]
1192 "----"
1193 ["Beginning of Entry"
1194 allout-beginning-of-current-entry t]
1195 ["End of Entry" allout-end-of-entry t]
1196 ["End of Subtree" allout-end-of-current-subtree t]))
1197 (easy-menu-define allout-mode-misc-menu
1198 allout-mode-map
1199 "Allout outlines miscellaneous bindings."
1200 '("Misc"
1201 ["Version" allout-version t]
1202 "----"
1203 ["Duplicate Exposed" allout-copy-exposed-to-buffer t]
1204 ["Duplicate Exposed, numbered"
1205 allout-flatten-exposed-to-buffer t]
1206 ["Duplicate Exposed, indented"
1207 allout-indented-exposed-to-buffer t]
1208 "----"
1209 ["Set Header Lead" allout-reset-header-lead t]
1210 ["Set New Exposure" allout-expose-topic t])))
1211 ;;;_ : Allout Modal-Variables Utilities
1212 ;;;_ = allout-mode-prior-settings
1213 (defvar allout-mode-prior-settings nil
1214 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1216 See `allout-add-resumptions' and `allout-do-resumptions'.")
1217 (make-variable-buffer-local 'allout-mode-prior-settings)
1218 ;;;_ > allout-add-resumptions (&rest pairs)
1219 (defun allout-add-resumptions (&rest pairs)
1220 "Set name/value PAIRS.
1222 Old settings are preserved for later resumption using `allout-do-resumptions'.
1224 The new values are set as a buffer local. On resumption, the prior buffer
1225 scope of the variable is restored along with its value. If it was a void
1226 buffer-local value, then it is left as nil on resumption.
1228 The pairs are lists whose car is the name of the variable and car of the
1229 cdr is the new value: '(some-var some-value)'. The pairs can actually be
1230 triples, where the third element qualifies the disposition of the setting,
1231 as described further below.
1233 If the optional third element is the symbol 'extend, then the new value
1234 created by `cons'ing the second element of the pair onto the front of the
1235 existing value.
1237 If the optional third element is the symbol 'append, then the new value is
1238 extended from the existing one by `append'ing a list containing the second
1239 element of the pair onto the end of the existing value.
1241 Extension, and resumptions in general, should not be used for hook
1242 functions - use the 'local mode of `add-hook' for that, instead.
1244 The settings are stored on `allout-mode-prior-settings'."
1245 (while pairs
1246 (let* ((pair (pop pairs))
1247 (name (car pair))
1248 (value (cadr pair))
1249 (qualifier (if (> (length pair) 2)
1250 (caddr pair)))
1251 prior-value)
1252 (if (not (symbolp name))
1253 (error "Pair's name, %S, must be a symbol, not %s"
1254 name (type-of name)))
1255 (setq prior-value (condition-case nil
1256 (symbol-value name)
1257 (void-variable nil)))
1258 (when (not (assoc name allout-mode-prior-settings))
1259 ;; Not already added as a resumption, create the prior setting entry.
1260 (if (local-variable-p name)
1261 ;; is already local variable - preserve the prior value:
1262 (push (list name prior-value) allout-mode-prior-settings)
1263 ;; wasn't local variable, indicate so for resumption by killing
1264 ;; local value, and make it local:
1265 (push (list name) allout-mode-prior-settings)
1266 (make-local-variable name)))
1267 (if qualifier
1268 (cond ((eq qualifier 'extend)
1269 (if (not (listp prior-value))
1270 (error "extension of non-list prior value attempted")
1271 (set name (cons value prior-value))))
1272 ((eq qualifier 'append)
1273 (if (not (listp prior-value))
1274 (error "appending of non-list prior value attempted")
1275 (set name (append prior-value (list value)))))
1276 (t (error "unrecognized setting qualifier `%s' encountered"
1277 qualifier)))
1278 (set name value)))))
1279 ;;;_ > allout-do-resumptions ()
1280 (defun allout-do-resumptions ()
1281 "Resume all name/value settings registered by `allout-add-resumptions'.
1283 This is used when concluding allout-mode, to resume selected variables to
1284 their settings before allout-mode was started."
1286 (while allout-mode-prior-settings
1287 (let* ((pair (pop allout-mode-prior-settings))
1288 (name (car pair))
1289 (value-cell (cdr pair)))
1290 (if (not value-cell)
1291 ;; Prior value was global:
1292 (kill-local-variable name)
1293 ;; Prior value was explicit:
1294 (set name (car value-cell))))))
1295 ;;;_ : Mode-specific incidentals
1296 ;;;_ > allout-unprotected (expr)
1297 (defmacro allout-unprotected (expr)
1298 "Enable internal outline operations to alter invisible text."
1299 `(let ((inhibit-read-only (if (not buffer-read-only) t))
1300 (inhibit-field-text-motion t))
1301 ,expr))
1302 ;;;_ = allout-mode-hook
1303 (defvar allout-mode-hook nil
1304 "*Hook that's run when allout mode starts.")
1305 ;;;_ = allout-mode-deactivate-hook
1306 (defvar allout-mode-deactivate-hook nil
1307 "*Hook that's run when allout mode ends.")
1308 ;;;_ = allout-exposure-category
1309 (defvar allout-exposure-category nil
1310 "Symbol for use as allout invisible-text overlay category.")
1311 ;;;_ x allout-view-change-hook
1312 (defvar allout-view-change-hook nil
1313 "*(Deprecated) A hook run after allout outline exposure changes.
1315 Switch to using `allout-exposure-change-hook' instead. Both hooks are
1316 currently respected, but the other conveys the details of the exposure
1317 change via explicit parameters, and this one will eventually be disabled in
1318 a subsequent allout version.")
1319 ;;;_ = allout-exposure-change-hook
1320 (defvar allout-exposure-change-hook nil
1321 "*Hook that's run after allout outline subtree exposure changes.
1323 It is run at the conclusion of `allout-flag-region'.
1325 Functions on the hook must take three arguments:
1327 - from - integer indicating the point at the start of the change.
1328 - to - integer indicating the point of the end of the change.
1329 - flag - change mode: nil for exposure, otherwise concealment.
1331 This hook might be invoked multiple times by a single command.
1333 This hook is replacing `allout-view-change-hook', which is being deprecated
1334 and eventually will not be invoked.")
1335 ;;;_ = allout-structure-added-hook
1336 (defvar allout-structure-added-hook nil
1337 "*Hook that's run after addition of items to the outline.
1339 Functions on the hook should take two arguments:
1341 - new-start - integer indicating the point at the start of the first new item.
1342 - new-end - integer indicating the point of the end of the last new item.
1344 Some edits that introduce new items may missed by this hook -
1345 specifically edits that native allout routines do not control.
1347 This hook might be invoked multiple times by a single command.")
1348 ;;;_ = allout-structure-deleted-hook
1349 (defvar allout-structure-deleted-hook nil
1350 "*Hook that's run after disciplined deletion of subtrees from the outline.
1352 Functions on the hook must take two arguments:
1354 - depth - integer indicating the depth of the subtree that was deleted.
1355 - removed-from - integer indicating the point where the subtree was removed.
1357 Some edits that remove or invalidate items may missed by this hook -
1358 specifically edits that native allout routines do not control.
1360 This hook might be invoked multiple times by a single command.")
1361 ;;;_ = allout-structure-shifted-hook
1362 (defvar allout-structure-shifted-hook nil
1363 "*Hook that's run after shifting of items in the outline.
1365 Functions on the hook should take two arguments:
1367 - depth-change - integer indicating depth increase, negative for decrease
1368 - start - integer indicating the start point of the shifted parent item.
1370 Some edits that shift items can be missed by this hook - specifically edits
1371 that native allout routines do not control.
1373 This hook might be invoked multiple times by a single command.")
1374 ;;;_ = allout-outside-normal-auto-fill-function
1375 (defvar allout-outside-normal-auto-fill-function nil
1376 "Value of normal-auto-fill-function outside of allout mode.
1378 Used by allout-auto-fill to do the mandated normal-auto-fill-function
1379 wrapped within allout's automatic fill-prefix setting.")
1380 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function)
1381 ;;;_ = file-var-bug hack
1382 (defvar allout-v18/19-file-var-hack nil
1383 "Horrible hack used to prevent invalid multiple triggering of outline
1384 mode from prop-line file-var activation. Used by `allout-mode' function
1385 to track repeats.")
1386 ;;;_ = allout-passphrase-verifier-string
1387 (defvar allout-passphrase-verifier-string nil
1388 "Setting used to test solicited encryption passphrases against the one
1389 already associated with a file.
1391 It consists of an encrypted random string useful only to verify that a
1392 passphrase entered by the user is effective for decryption. The passphrase
1393 itself is \*not* recorded in the file anywhere, and the encrypted contents
1394 are random binary characters to avoid exposing greater susceptibility to
1395 search attacks.
1397 The verifier string is retained as an Emacs file variable, as well as in
1398 the Emacs buffer state, if file variable adjustments are enabled. See
1399 `allout-enable-file-variable-adjustment' for details about that.")
1400 (make-variable-buffer-local 'allout-passphrase-verifier-string)
1401 ;;;###autoload
1402 (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp)
1403 ;;;_ = allout-passphrase-hint-string
1404 (defvar allout-passphrase-hint-string ""
1405 "Variable used to retain reminder string for file's encryption passphrase.
1407 See the description of `allout-passphrase-hint-handling' for details about how
1408 the reminder is deployed.
1410 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1411 state, if file variable adjustments are enabled. See
1412 `allout-enable-file-variable-adjustment' for details about that.")
1413 (make-variable-buffer-local 'allout-passphrase-hint-string)
1414 (setq-default allout-passphrase-hint-string "")
1415 ;;;###autoload
1416 (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp)
1417 ;;;_ = allout-after-save-decrypt
1418 (defvar allout-after-save-decrypt nil
1419 "Internal variable, is nil or has the value of two points:
1421 - the location of a topic to be decrypted after saving is done
1422 - where to situate the cursor after the decryption is performed
1424 This is used to decrypt the topic that was currently being edited, if it
1425 was encrypted automatically as part of a file write or autosave.")
1426 (make-variable-buffer-local 'allout-after-save-decrypt)
1427 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1428 (defvar allout-encryption-plaintext-sanitization-regexps nil
1429 "List of regexps whose matches are removed from plaintext before encryption.
1431 This is for the sake of removing artifacts, like escapes, that are added on
1432 and not actually part of the original plaintext. The removal is done just
1433 prior to encryption.
1435 Entries must be symbols that are bound to the desired values.
1437 Each value can be a regexp or a list with a regexp followed by a
1438 substitution string. If it's just a regexp, all its matches are removed
1439 before the text is encrypted. If it's a regexp and a substitution, the
1440 substition is used against the regexp matches, a la `replace-match'.")
1441 (make-variable-buffer-local 'allout-encryption-text-removal-regexps)
1442 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1443 (defvar allout-encryption-ciphertext-rejection-regexps nil
1444 "Variable for regexps matching plaintext to remove before encryption.
1446 This is for the sake of redoing encryption in cases where the ciphertext
1447 incidentally contains strings that would disrupt mode operation -
1448 for example, a line that happens to look like an allout-mode topic prefix.
1450 Entries must be symbols that are bound to the desired regexp values.
1452 The encryption will be retried up to
1453 `allout-encryption-ciphertext-rejection-limit' times, after which an error
1454 is raised.")
1456 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps)
1457 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1458 (defvar allout-encryption-ciphertext-rejection-ceiling 5
1459 "Limit on number of times encryption ciphertext is rejected.
1461 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1462 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling)
1463 ;;;_ > allout-mode-p ()
1464 ;; Must define this macro above any uses, or byte compilation will lack
1465 ;; proper def, if file isn't loaded - eg, during emacs build!
1466 (defmacro allout-mode-p ()
1467 "Return t if `allout-mode' is active in current buffer."
1468 'allout-mode)
1469 ;;;_ > allout-write-file-hook-handler ()
1470 (defun allout-write-file-hook-handler ()
1471 "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes."
1473 (if (or (not (allout-mode-p))
1474 (not (boundp 'allout-encrypt-unencrypted-on-saves))
1475 (not allout-encrypt-unencrypted-on-saves))
1477 (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves
1478 'except-current)
1479 (point-marker))))
1480 (if (save-excursion (goto-char (point-min))
1481 (allout-next-topic-pending-encryption except-mark))
1482 (progn
1483 (message "auto-encrypting pending topics")
1484 (sit-for 0)
1485 (condition-case failure
1486 (setq allout-after-save-decrypt
1487 (allout-encrypt-decrypted except-mark))
1488 (error (progn
1489 (message
1490 "allout-write-file-hook-handler suppressing error %s"
1491 failure)
1492 (sit-for 2))))))
1494 nil)
1495 ;;;_ > allout-auto-save-hook-handler ()
1496 (defun allout-auto-save-hook-handler ()
1497 "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save."
1499 (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves)
1500 ;; Always implement 'except-current policy when enabled.
1501 (let ((allout-encrypt-unencrypted-on-saves 'except-current))
1502 (allout-write-file-hook-handler))))
1503 ;;;_ > allout-after-saves-handler ()
1504 (defun allout-after-saves-handler ()
1505 "Decrypt topic encrypted for save, if it's currently being edited.
1507 Ie, if it was pending encryption and contained the point in its body before
1508 the save.
1510 We use values stored in `allout-after-save-decrypt' to locate the topic
1511 and the place for the cursor after the decryption is done."
1512 (if (not (and (allout-mode-p)
1513 (boundp 'allout-after-save-decrypt)
1514 allout-after-save-decrypt))
1516 (goto-char (car allout-after-save-decrypt))
1517 (let ((was-modified (buffer-modified-p)))
1518 (allout-toggle-subtree-encryption)
1519 (if (not was-modified)
1520 (set-buffer-modified-p nil)))
1521 (goto-char (cadr allout-after-save-decrypt))
1522 (setq allout-after-save-decrypt nil))
1524 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1525 ;; In some exceptional moments, disparate topic depths need to be allowed
1526 ;; momentarily, eg when one topic is being yanked into another and they're
1527 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1528 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1529 ;; processing to happen in the presence of such discrepancies. It should
1530 ;; almost never be needed, however.
1531 (defvar allout-inhibit-aberrance-doublecheck nil
1532 "Internal state, for momentarily inhibits aberrance doublecheck.
1534 This should only be momentarily let-bound non-nil, not set
1535 non-nil in a lasting way.")
1537 ;;;_ #2 Mode activation
1538 ;;;_ = allout-explicitly-deactivated
1539 (defvar allout-explicitly-deactivated nil
1540 "If t, `allout-mode's last deactivation was deliberate.
1541 So `allout-post-command-business' should not reactivate it...")
1542 (make-variable-buffer-local 'allout-explicitly-deactivated)
1543 ;;;_ > allout-init (&optional mode)
1544 (defun allout-init (&optional mode)
1545 "Prime `allout-mode' to enable/disable auto-activation, wrt `allout-layout'.
1547 MODE is one of the following symbols:
1549 - nil (or no argument) deactivate auto-activation/layout;
1550 - `activate', enable auto-activation only;
1551 - `ask', enable auto-activation, and enable auto-layout but with
1552 confirmation for layout operation solicited from user each time;
1553 - `report', just report and return the current auto-activation state;
1554 - anything else (eg, t) for auto-activation and auto-layout, without
1555 any confirmation check.
1557 Use this function to setup your Emacs session for automatic activation
1558 of allout outline mode, contingent to the buffer-specific setting of
1559 the `allout-layout' variable. (See `allout-layout' and
1560 `allout-expose-topic' docstrings for more details on auto layout).
1562 `allout-init' works by setting up (or removing) the `allout-mode'
1563 find-file-hook, and giving `allout-auto-activation' a suitable
1564 setting.
1566 To prime your Emacs session for full auto-outline operation, include
1567 the following two lines in your Emacs init file:
1569 \(require 'allout)
1570 \(allout-init t)"
1572 (interactive)
1573 (if (interactive-p)
1574 (progn
1575 (setq mode
1576 (completing-read
1577 (concat "Select outline auto setup mode "
1578 "(empty for report, ? for options) ")
1579 '(("nil")("full")("activate")("deactivate")
1580 ("ask") ("report") (""))
1583 (if (string= mode "")
1584 (setq mode 'report)
1585 (setq mode (intern-soft mode)))))
1586 (let
1587 ;; convenience aliases, for consistent ref to respective vars:
1588 ((hook 'allout-find-file-hook)
1589 (find-file-hook-var-name (if (boundp 'find-file-hook)
1590 'find-file-hook
1591 'find-file-hooks))
1592 (curr-mode 'allout-auto-activation))
1594 (cond ((not mode)
1595 (set find-file-hook-var-name
1596 (delq hook (symbol-value find-file-hook-var-name)))
1597 (if (interactive-p)
1598 (message "Allout outline mode auto-activation inhibited.")))
1599 ((eq mode 'report)
1600 (if (not (memq hook (symbol-value find-file-hook-var-name)))
1601 (allout-init nil)
1602 ;; Just punt and use the reports from each of the modes:
1603 (allout-init (symbol-value curr-mode))))
1604 (t (add-hook find-file-hook-var-name hook)
1605 (set curr-mode ; `set', not `setq'!
1606 (cond ((eq mode 'activate)
1607 (message
1608 "Outline mode auto-activation enabled.")
1609 'activate)
1610 ((eq mode 'report)
1611 ;; Return the current mode setting:
1612 (allout-init mode))
1613 ((eq mode 'ask)
1614 (message
1615 (concat "Outline mode auto-activation and "
1616 "-layout (upon confirmation) enabled."))
1617 'ask)
1618 ((message
1619 "Outline mode auto-activation and -layout enabled.")
1620 'full)))))))
1621 ;;;_ > allout-setup-menubar ()
1622 (defun allout-setup-menubar ()
1623 "Populate the current buffer's menubar with `allout-mode' stuff."
1624 (let ((menus (list allout-mode-exposure-menu
1625 allout-mode-editing-menu
1626 allout-mode-navigation-menu
1627 allout-mode-misc-menu))
1628 cur)
1629 (while menus
1630 (setq cur (car menus)
1631 menus (cdr menus))
1632 (easy-menu-add cur))))
1633 ;;;_ > allout-overlay-preparations
1634 (defun allout-overlay-preparations ()
1635 "Set the properties of the allout invisible-text overlay and others."
1636 (setplist 'allout-exposure-category nil)
1637 (put 'allout-exposure-category 'invisible 'allout)
1638 (put 'allout-exposure-category 'evaporate t)
1639 ;; XXX We use isearch-open-invisible *and* isearch-mode-end-hook. The
1640 ;; latter would be sufficient, but it seems that a separate behavior -
1641 ;; the _transient_ opening of invisible text during isearch - is keyed to
1642 ;; presence of the isearch-open-invisible property - even though this
1643 ;; property controls the isearch _arrival_ behavior. This is the case at
1644 ;; least in emacs 21, 22.0, and xemacs 21.4.
1645 (put 'allout-exposure-category 'isearch-open-invisible
1646 'allout-isearch-end-handler)
1647 (if (featurep 'xemacs)
1648 (put 'allout-exposure-category 'start-open t)
1649 (put 'allout-exposure-category 'insert-in-front-hooks
1650 '(allout-overlay-insert-in-front-handler)))
1651 (put 'allout-exposure-category 'modification-hooks
1652 '(allout-overlay-interior-modification-handler)))
1653 ;;;_ > allout-mode (&optional toggle)
1654 ;;;_ : Defun:
1655 ;;;###autoload
1656 (defun allout-mode (&optional toggle)
1657 ;;;_ . Doc string:
1658 "Toggle minor mode for controlling exposure and editing of text outlines.
1659 \\<allout-mode-map>
1661 Optional prefix argument TOGGLE forces the mode to re-initialize
1662 if it is positive, otherwise it turns the mode off. Allout
1663 outline mode always runs as a minor mode.
1665 Allout outline mode provides extensive outline oriented formatting and
1666 manipulation. It enables structural editing of outlines, as well as
1667 navigation and exposure. It also is specifically aimed at
1668 accommodating syntax-sensitive text like programming languages. (For
1669 an example, see the allout code itself, which is organized as an allout
1670 outline.)
1672 In addition to typical outline navigation and exposure, allout includes:
1674 - topic-oriented authoring, including keystroke-based topic creation,
1675 repositioning, promotion/demotion, cut, and paste
1676 - incremental search with dynamic exposure and reconcealment of hidden text
1677 - adjustable format, so programming code can be developed in outline-structure
1678 - easy topic encryption and decryption
1679 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1680 - integral outline layout, for automatic initial exposure when visiting a file
1681 - independent extensibility, using comprehensive exposure and authoring hooks
1683 and many other features.
1685 Below is a description of the key bindings, and then explanation of
1686 special `allout-mode' features and terminology. See also the outline
1687 menubar additions for quick reference to many of the features, and see
1688 the docstring of the function `allout-init' for instructions on
1689 priming your emacs session for automatic activation of `allout-mode'.
1691 The bindings are dictated by the customizable `allout-keybindings-list'
1692 variable. We recommend customizing `allout-command-prefix' to use just
1693 `\\C-c' as the command prefix, if the allout bindings don't conflict with
1694 any personal bindings you have on \\C-c. In any case, outline structure
1695 navigation and authoring is simplified by positioning the cursor on an
1696 item's bullet character, the \"hot-spot\" - then you can invoke allout
1697 commands with just the un-prefixed, un-control-shifted command letters.
1698 This is described further in the HOT-SPOT Operation section.
1700 Exposure Control:
1701 ----------------
1702 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1703 \\[allout-show-children] `allout-show-children'
1704 \\[allout-show-current-subtree] `allout-show-current-subtree'
1705 \\[allout-show-current-entry] `allout-show-current-entry'
1706 \\[allout-show-all] `allout-show-all'
1708 Navigation:
1709 ----------
1710 \\[allout-next-visible-heading] `allout-next-visible-heading'
1711 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1712 \\[allout-up-current-level] `allout-up-current-level'
1713 \\[allout-forward-current-level] `allout-forward-current-level'
1714 \\[allout-backward-current-level] `allout-backward-current-level'
1715 \\[allout-end-of-entry] `allout-end-of-entry'
1716 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1717 \\[allout-beginning-of-line] `allout-beginning-of-line' - like regular beginning-of-line, but
1718 if immediately repeated cycles to the beginning of the current item
1719 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1722 Topic Header Production:
1723 -----------------------
1724 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1725 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1726 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1728 Topic Level and Prefix Adjustment:
1729 ---------------------------------
1730 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1731 \\[allout-shift-out] `allout-shift-out' ... less deep
1732 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1733 current topic
1734 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1735 its' offspring - distinctive bullets are not changed, others
1736 are alternated according to nesting depth.
1737 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -
1738 the offspring are not affected.
1739 With repeat count, revoke numbering.
1741 Topic-oriented Killing and Yanking:
1742 ----------------------------------
1743 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1744 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1745 \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure.
1746 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1747 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1748 depth of heading if yanking into bare topic
1749 heading (ie, prefix sans text).
1750 \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank
1752 Topic-oriented Encryption:
1753 -------------------------
1754 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1755 Encrypt/Decrypt topic content
1757 Misc commands:
1758 -------------
1759 M-x outlineify-sticky Activate outline mode for current buffer,
1760 and establish a default file-var setting
1761 for `allout-layout'.
1762 \\[allout-mark-topic] `allout-mark-topic'
1763 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1764 Duplicate outline, sans concealed text, to
1765 buffer with name derived from derived from that
1766 of current buffer - \"*BUFFERNAME exposed*\".
1767 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1768 Like above 'copy-exposed', but convert topic
1769 prefixes to section.subsection... numeric
1770 format.
1771 \\[eval-expression] (allout-init t) Setup Emacs session for outline mode
1772 auto-activation.
1774 Topic Encryption
1776 Outline mode supports gpg encryption of topics, with support for
1777 symmetric and key-pair modes, passphrase timeout, passphrase
1778 consistency checking, user-provided hinting for symmetric key
1779 mode, and auto-encryption of topics pending encryption on save.
1781 Topics pending encryption are, by default, automatically
1782 encrypted during file saves. If the contents of the topic
1783 containing the cursor was encrypted for a save, it is
1784 automatically decrypted for continued editing.
1786 The aim of these measures is reliable topic privacy while
1787 preventing accidents like neglected encryption before saves,
1788 forgetting which passphrase was used, and other practical
1789 pitfalls.
1791 See `allout-toggle-current-subtree-encryption' function docstring
1792 and `allout-encrypt-unencrypted-on-saves' customization variable
1793 for details.
1795 HOT-SPOT Operation
1797 Hot-spot operation provides a means for easy, single-keystroke outline
1798 navigation and exposure control.
1800 When the text cursor is positioned directly on the bullet character of
1801 a topic, regular characters (a to z) invoke the commands of the
1802 corresponding allout-mode keymap control chars. For example, \"f\"
1803 would invoke the command typically bound to \"C-c<space>C-f\"
1804 \(\\[allout-forward-current-level] `allout-forward-current-level').
1806 Thus, by positioning the cursor on a topic bullet, you can
1807 execute the outline navigation and manipulation commands with a
1808 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1809 this special translation, so you can use them to get out of the
1810 hot-spot and back to normal editing operation.
1812 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]]) is
1813 replaced with one that makes it easy to get to the hot-spot. If you
1814 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1815 is set) to the beginning of the item and then, if you hit it again
1816 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1817 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1818 at the beginning of the current entry.
1820 Extending Allout
1822 Allout exposure and authoring activites all have associated
1823 hooks, by which independent code can cooperate with allout
1824 without changes to the allout core. Here are key ones:
1826 `allout-mode-hook'
1827 `allout-mode-deactivate-hook'
1828 `allout-exposure-change-hook'
1829 `allout-structure-added-hook'
1830 `allout-structure-deleted-hook'
1831 `allout-structure-shifted-hook'
1833 Terminology
1835 Topic hierarchy constituents - TOPICS and SUBTOPICS:
1837 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1838 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1839 and with no intervening items of lower DEPTH than the container.
1840 CURRENT ITEM:
1841 The visible ITEM most immediately containing the cursor.
1842 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1843 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1844 called the:
1845 LEVEL: The same as DEPTH.
1847 ANCESTORS:
1848 Those ITEMs whose TOPICs contain an ITEM.
1849 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1850 of the ITEM.
1851 OFFSPRING:
1852 The ITEMs contained within an ITEM's TOPIC.
1853 SUBTOPIC:
1854 An OFFSPRING of its ANCESTOR TOPICs.
1855 CHILD:
1856 An immediate SUBTOPIC of its PARENT.
1857 SIBLINGS:
1858 TOPICs having the same PARENT and DEPTH.
1860 Topic text constituents:
1862 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1863 text.
1864 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1865 the HEADER text and distinct from the ITEM PREFIX.
1866 BODY: Same as ENTRY.
1867 PREFIX: The leading text of an ITEM which distinguishes it from normal
1868 ENTRY text. Allout recognizes the outline structure according
1869 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1870 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1871 number, indicating the ordinal number of the topic among its
1872 siblings, or an asterisk indicating encryption, plus an optional
1873 space. After that is the ITEM HEADER text, which is not part of
1874 the PREFIX.
1876 The relative length of the PREFIX determines the nesting DEPTH
1877 of the ITEM.
1878 PREFIX-LEAD:
1879 The string at the beginning of a HEADER PREFIX, by default a `.'.
1880 It can be customized by changing the setting of
1881 `allout-header-prefix' and then reinitializing `allout-mode'.
1883 When the PREFIX-LEAD is set to the comment-string of a
1884 programming language, outline structuring can be embedded in
1885 program code without interfering with processing of the text
1886 (by emacs or the language processor) as program code. This
1887 setting happens automatically when allout mode is used in
1888 programming-mode buffers. See `allout-use-mode-specific-leader'
1889 docstring for more detail.
1890 PREFIX-PADDING:
1891 Spaces or asterisks which separate the PREFIX-LEAD and the
1892 bullet, determining the ITEM's DEPTH.
1893 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1894 the characters listed on `allout-plain-bullets-string' or
1895 `allout-distinctive-bullets-string'. When creating a TOPIC,
1896 plain BULLETs are by default used, according to the DEPTH of the
1897 TOPIC. Choice among the distinctive BULLETs is offered when you
1898 provide a universal argugment \(\\[universal-argument]) to the
1899 TOPIC creation command, or when explictly rebulleting a TOPIC. The
1900 significance of the various distinctive bullets is purely by
1901 convention. See the documentation for the above bullet strings for
1902 more details.
1903 EXPOSURE:
1904 The state of a TOPIC which determines the on-screen visibility
1905 of its OFFSPRING and contained ENTRY text.
1906 CONCEALED:
1907 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1908 text is represented by \"...\" ellipses.
1910 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1911 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1912 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1913 ;;;_ . Code
1914 (interactive "P")
1916 (let* ((active (and (not (equal major-mode 'outline))
1917 (allout-mode-p)))
1918 ; Massage universal-arg `toggle' val:
1919 (toggle (and toggle
1920 (or (and (listp toggle)(car toggle))
1921 toggle)))
1922 ; Activation specifically demanded?
1923 (explicit-activation (and toggle
1924 (or (symbolp toggle)
1925 (and (wholenump toggle)
1926 (not (zerop toggle))))))
1927 ;; allout-mode already called once during this complex command?
1928 (same-complex-command (eq allout-v18/19-file-var-hack
1929 (car command-history)))
1930 (write-file-hook-var-name (cond ((boundp 'write-file-functions)
1931 'write-file-functions)
1932 ((boundp 'write-file-hooks)
1933 'write-file-hooks)
1934 (t 'local-write-file-hooks)))
1935 do-layout
1938 ; See comments below re v19.18,.19 bug.
1939 (setq allout-v18/19-file-var-hack (car command-history))
1941 (cond
1943 ;; Provision for v19.18, 19.19 bug -
1944 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1945 ;; modes twice when file is visited. We have to avoid toggling mode
1946 ;; off on second invocation, so we detect it as best we can, and
1947 ;; skip everything.
1948 ((and same-complex-command ; Still in same complex command
1949 ; as last time `allout-mode' invoked.
1950 active ; Already activated.
1951 (not explicit-activation) ; Prop-line file-vars don't have args.
1952 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1953 emacs-version)); 19.19.
1956 ;; Deactivation:
1957 ((and (not explicit-activation)
1958 (or active toggle))
1959 ; Activation not explicitly
1960 ; requested, and either in
1961 ; active state or *de*activation
1962 ; specifically requested:
1963 (setq allout-explicitly-deactivated t)
1965 (allout-do-resumptions)
1967 (remove-from-invisibility-spec '(allout . t))
1968 (remove-hook 'pre-command-hook 'allout-pre-command-business t)
1969 (remove-hook 'post-command-hook 'allout-post-command-business t)
1970 (remove-hook 'before-change-functions 'allout-before-change-handler t)
1971 (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t)
1972 (remove-hook write-file-hook-var-name 'allout-write-file-hook-handler t)
1973 (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t)
1975 (remove-overlays (point-min) (point-max)
1976 'category 'allout-exposure-category)
1978 (setq allout-mode nil)
1979 (run-hooks 'allout-mode-deactivate-hook))
1981 ;; Activation:
1982 ((not active)
1983 (setq allout-explicitly-deactivated nil)
1984 (if allout-old-style-prefixes
1985 ;; Inhibit all the fancy formatting:
1986 (allout-add-resumptions '(allout-primary-bullet "*")))
1988 (allout-overlay-preparations) ; Doesn't hurt to redo this.
1990 (allout-infer-header-lead-and-primary-bullet)
1991 (allout-infer-body-reindent)
1993 (set-allout-regexp)
1994 (allout-add-resumptions
1995 '(allout-encryption-ciphertext-rejection-regexps
1996 allout-line-boundary-regexp
1997 extend)
1998 '(allout-encryption-ciphertext-rejection-regexps
1999 allout-bob-regexp
2000 extend))
2002 ;; Produce map from current version of allout-keybindings-list:
2003 (allout-setup-mode-map)
2004 (produce-allout-mode-menubar-entries)
2006 ;; Include on minor-mode-map-alist, if not already there:
2007 (if (not (member '(allout-mode . allout-mode-map)
2008 minor-mode-map-alist))
2009 (setq minor-mode-map-alist
2010 (cons '(allout-mode . allout-mode-map)
2011 minor-mode-map-alist)))
2013 (add-to-invisibility-spec '(allout . t))
2015 (allout-add-resumptions '(line-move-ignore-invisible t))
2016 (add-hook 'pre-command-hook 'allout-pre-command-business nil t)
2017 (add-hook 'post-command-hook 'allout-post-command-business nil t)
2018 (add-hook 'before-change-functions 'allout-before-change-handler
2019 nil t)
2020 (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t)
2021 (add-hook write-file-hook-var-name 'allout-write-file-hook-handler
2022 nil t)
2023 (add-hook 'auto-save-hook 'allout-auto-save-hook-handler
2024 nil t)
2026 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2027 ;; func will be used if auto-fill is active or activated. (The
2028 ;; custom func respects topic headline, maintains hanging-indents,
2029 ;; etc.)
2030 (if (and auto-fill-function (not allout-inhibit-auto-fill))
2031 ;; allout-auto-fill will use the stashed values and so forth.
2032 (allout-add-resumptions '(auto-fill-function allout-auto-fill)))
2033 (allout-add-resumptions (list 'allout-former-auto-filler
2034 auto-fill-function)
2035 ;; Register allout-auto-fill to be used if
2036 ;; filling is active:
2037 (list 'allout-outside-normal-auto-fill-function
2038 normal-auto-fill-function)
2039 '(normal-auto-fill-function allout-auto-fill)
2040 ;; Paragraphs are broken by topic headlines.
2041 (list 'paragraph-start
2042 (concat paragraph-start "\\|^\\("
2043 allout-regexp "\\)"))
2044 (list 'paragraph-separate
2045 (concat paragraph-separate "\\|^\\("
2046 allout-regexp "\\)")))
2047 (or (assq 'allout-mode minor-mode-alist)
2048 (setq minor-mode-alist
2049 (cons '(allout-mode " Allout") minor-mode-alist)))
2051 (allout-setup-menubar)
2053 (if allout-layout
2054 (setq do-layout t))
2056 (setq allout-mode t)
2057 (run-hooks 'allout-mode-hook))
2059 ;; Reactivation:
2060 ((setq do-layout t)
2061 (allout-infer-body-reindent))
2062 ) ;; end of activation-mode cases.
2064 ;; Do auto layout if warranted:
2065 (let ((use-layout (if (listp allout-layout)
2066 allout-layout
2067 allout-default-layout)))
2068 (if (and do-layout
2069 allout-auto-activation
2070 use-layout
2071 (and (not (eq allout-auto-activation 'activate))
2072 (if (eq allout-auto-activation 'ask)
2073 (if (y-or-n-p (format "Expose %s with layout '%s'? "
2074 (buffer-name)
2075 use-layout))
2077 (message "Skipped %s layout." (buffer-name))
2078 nil)
2079 t)))
2080 (save-excursion
2081 (message "Adjusting '%s' exposure..." (buffer-name))
2082 (goto-char 0)
2083 (allout-this-or-next-heading)
2084 (condition-case err
2085 (progn
2086 (apply 'allout-expose-topic (list use-layout))
2087 (message "Adjusting '%s' exposure... done." (buffer-name)))
2088 ;; Problem applying exposure - notify user, but don't
2089 ;; interrupt, eg, file visit:
2090 (error (message "%s" (car (cdr err)))
2091 (sit-for 1))))))
2092 allout-mode
2093 ) ; let*
2094 ) ; defun
2096 (defun allout-setup-mode-map ()
2097 "Establish allout-mode bindings."
2098 (setq-default allout-mode-map
2099 (produce-allout-mode-map allout-keybindings-list))
2100 (setq allout-mode-map
2101 (produce-allout-mode-map allout-keybindings-list))
2102 (substitute-key-definition 'beginning-of-line
2103 'allout-beginning-of-line
2104 allout-mode-map global-map)
2105 (substitute-key-definition 'move-beginning-of-line
2106 'allout-beginning-of-line
2107 allout-mode-map global-map)
2108 (substitute-key-definition 'end-of-line
2109 'allout-end-of-line
2110 allout-mode-map global-map)
2111 (substitute-key-definition 'move-end-of-line
2112 'allout-end-of-line
2113 allout-mode-map global-map)
2114 (fset 'allout-mode-map allout-mode-map))
2116 ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
2117 ;; been invoked:
2118 (allout-setup-mode-map)
2120 ;;;_ > allout-minor-mode
2121 (defalias 'allout-minor-mode 'allout-mode)
2123 ;;;_ - Position Assessment
2124 ;;;_ > allout-hidden-p (&optional pos)
2125 (defsubst allout-hidden-p (&optional pos)
2126 "Non-nil if the character after point is invisible."
2127 (eq (get-char-property (or pos (point)) 'invisible) 'allout))
2129 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2130 ;;; &optional prelen)
2131 (defun allout-overlay-insert-in-front-handler (ol after beg end
2132 &optional prelen)
2133 "Shift the overlay so stuff inserted in front of it are excluded."
2134 (if after
2135 (move-overlay ol (1+ beg) (overlay-end ol))))
2136 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2137 ;;; &optional prelen)
2138 (defun allout-overlay-interior-modification-handler (ol after beg end
2139 &optional prelen)
2140 "Get confirmation before making arbitrary changes to invisible text.
2142 We expose the invisible text and ask for confirmation. Refusal or
2143 keyboard-quit abandons the changes, with keyboard-quit additionally
2144 reclosing the opened text.
2146 No confirmation is necessary when inhibit-read-only is set - eg, allout
2147 internal functions use this feature cohesively bunch changes."
2149 (when (and (not inhibit-read-only) (not after))
2150 (let ((start (point))
2151 (ol-start (overlay-start ol))
2152 (ol-end (overlay-end ol))
2153 first)
2154 (goto-char beg)
2155 (while (< (point) end)
2156 (when (allout-hidden-p)
2157 (allout-show-to-offshoot)
2158 (if (allout-hidden-p)
2159 (save-excursion (forward-char 1)
2160 (allout-show-to-offshoot)))
2161 (when (not first)
2162 (setq first (point))))
2163 (goto-char (if (featurep 'xemacs)
2164 (next-property-change (1+ (point)) nil end)
2165 (next-char-property-change (1+ (point)) end))))
2166 (when first
2167 (goto-char first)
2168 (condition-case nil
2169 (if (not
2170 (yes-or-no-p
2171 (substitute-command-keys
2172 (concat "Modify concealed text? (\"no\" just aborts,"
2173 " \\[keyboard-quit] also reconceals) "))))
2174 (progn (goto-char start)
2175 (error "Concealed-text change refused.")))
2176 (quit (allout-flag-region ol-start ol-end nil)
2177 (allout-flag-region ol-start ol-end t)
2178 (error "Concealed-text change abandoned, text reconcealed."))))
2179 (goto-char start))))
2180 ;;;_ > allout-before-change-handler (beg end)
2181 (defun allout-before-change-handler (beg end)
2182 "Protect against changes to invisible text.
2184 See allout-overlay-interior-modification-handler for details."
2186 (if (and (allout-mode-p) undo-in-progress (allout-hidden-p))
2187 (allout-show-to-offshoot))
2189 ;; allout-overlay-interior-modification-handler on an overlay handles
2190 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2191 (when (and (featurep 'xemacs) (allout-mode-p))
2192 ;; process all of the pending overlays:
2193 (save-excursion
2194 (goto-char beg)
2195 (let ((overlay (allout-get-invisibility-overlay)))
2196 (allout-overlay-interior-modification-handler
2197 overlay nil beg end nil)))))
2198 ;;;_ > allout-isearch-end-handler (&optional overlay)
2199 (defun allout-isearch-end-handler (&optional overlay)
2200 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2202 Optional OVERLAY parameter is for when this function is used by
2203 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2204 function can also be used as an `isearch-mode-end-hook'."
2206 (if (and (allout-mode-p) (allout-hidden-p))
2207 (allout-show-to-offshoot)))
2209 ;;;_ #3 Internal Position State-Tracking - "allout-recent-*" funcs
2210 ;;; All the basic outline functions that directly do string matches to
2211 ;;; evaluate heading prefix location set the variables
2212 ;;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2213 ;;; when successful. Functions starting with `allout-recent-' all
2214 ;;; use this state, providing the means to avoid redundant searches
2215 ;;; for just-established data. This optimization can provide
2216 ;;; significant speed improvement, but it must be employed carefully.
2217 ;;;_ = allout-recent-prefix-beginning
2218 (defvar allout-recent-prefix-beginning 0
2219 "Buffer point of the start of the last topic prefix encountered.")
2220 (make-variable-buffer-local 'allout-recent-prefix-beginning)
2221 ;;;_ = allout-recent-prefix-end
2222 (defvar allout-recent-prefix-end 0
2223 "Buffer point of the end of the last topic prefix encountered.")
2224 (make-variable-buffer-local 'allout-recent-prefix-end)
2225 ;;;_ = allout-recent-depth
2226 (defvar allout-recent-depth 0
2227 "Depth of the last topic prefix encountered.")
2228 (make-variable-buffer-local 'allout-recent-depth)
2229 ;;;_ = allout-recent-end-of-subtree
2230 (defvar allout-recent-end-of-subtree 0
2231 "Buffer point last returned by `allout-end-of-current-subtree'.")
2232 (make-variable-buffer-local 'allout-recent-end-of-subtree)
2233 ;;;_ > allout-prefix-data ()
2234 (defsubst allout-prefix-data ()
2235 "Register allout-prefix state data.
2237 For reference by `allout-recent' funcs. Returns BEGINNING."
2238 (setq allout-recent-prefix-end (or (match-end 1) (match-end 2))
2239 allout-recent-prefix-beginning (or (match-beginning 1)
2240 (match-beginning 2))
2241 allout-recent-depth (max 1 (- allout-recent-prefix-end
2242 allout-recent-prefix-beginning
2243 allout-header-subtraction)))
2244 allout-recent-prefix-beginning)
2245 ;;;_ > nullify-allout-prefix-data ()
2246 (defsubst nullify-allout-prefix-data ()
2247 "Mark allout prefix data as being uninformative."
2248 (setq allout-recent-prefix-end (point)
2249 allout-recent-prefix-beginning (point)
2250 allout-recent-depth 0)
2251 allout-recent-prefix-beginning)
2252 ;;;_ > allout-recent-depth ()
2253 (defsubst allout-recent-depth ()
2254 "Return depth of last heading encountered by an outline maneuvering function.
2256 All outline functions which directly do string matches to assess
2257 headings set the variables `allout-recent-prefix-beginning' and
2258 `allout-recent-prefix-end' if successful. This function uses those settings
2259 to return the current depth."
2261 allout-recent-depth)
2262 ;;;_ > allout-recent-prefix ()
2263 (defsubst allout-recent-prefix ()
2264 "Like `allout-recent-depth', but returns text of last encountered prefix.
2266 All outline functions which directly do string matches to assess
2267 headings set the variables `allout-recent-prefix-beginning' and
2268 `allout-recent-prefix-end' if successful. This function uses those settings
2269 to return the current prefix."
2270 (buffer-substring-no-properties allout-recent-prefix-beginning
2271 allout-recent-prefix-end))
2272 ;;;_ > allout-recent-bullet ()
2273 (defmacro allout-recent-bullet ()
2274 "Like allout-recent-prefix, but returns bullet of last encountered prefix.
2276 All outline functions which directly do string matches to assess
2277 headings set the variables `allout-recent-prefix-beginning' and
2278 `allout-recent-prefix-end' if successful. This function uses those settings
2279 to return the current depth of the most recently matched topic."
2280 '(buffer-substring-no-properties (1- allout-recent-prefix-end)
2281 allout-recent-prefix-end))
2283 ;;;_ #4 Navigation
2285 ;;;_ - Position Assessment
2286 ;;;_ : Location Predicates
2287 ;;;_ > allout-do-doublecheck ()
2288 (defsubst allout-do-doublecheck ()
2289 "True if current item conditions qualify for checking on topic aberrance."
2290 (and
2291 ;; presume integrity of outline and yanked content during yank - necessary,
2292 ;; to allow for level disparity of yank location and yanked text:
2293 (not allout-inhibit-aberrance-doublecheck)
2294 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2295 (<= allout-recent-depth allout-doublecheck-at-and-shallower)))
2296 ;;;_ > allout-aberrant-container-p ()
2297 (defun allout-aberrant-container-p ()
2298 "True if topic, or next sibling with children, contains them discontinuously.
2300 Discontinuous means an immediate offspring that is nested more
2301 than one level deeper than the topic.
2303 If topic has no offspring, then the next sibling with offspring will
2304 determine whether or not this one is determined to be aberrant.
2306 If true, then the allout-recent-* settings are calibrated on the
2307 offspring that qaulifies it as aberrant, ie with depth that
2308 exceeds the topic by more than one."
2310 ;; This is most clearly understood when considering standard-prefix-leader
2311 ;; low-level topics, which can all too easily match text not intended as
2312 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2313 ;; following bullet qualifies without this protection. (A sequence of
2314 ;; them can occur naturally, eg a typical textual bullet list.) We
2315 ;; disqualify such low-level sequences when they are followed by a
2316 ;; discontinuously contained child, inferring that the sequences are not
2317 ;; actually connected with their prospective context.
2319 (let ((depth (allout-depth))
2320 (start-point (point))
2321 done aberrant)
2322 (save-excursion
2323 (while (and (not done)
2324 (re-search-forward allout-line-boundary-regexp nil 0))
2325 (allout-prefix-data)
2326 (goto-char allout-recent-prefix-beginning)
2327 (cond
2328 ;; sibling - continue:
2329 ((eq allout-recent-depth depth))
2330 ;; first offspring is excessive - aberrant:
2331 ((> allout-recent-depth (1+ depth))
2332 (setq done t aberrant t))
2333 ;; next non-sibling is lower-depth - not aberrant:
2334 (t (setq done t)))))
2335 (if aberrant
2336 aberrant
2337 (goto-char start-point)
2338 ;; recalibrate allout-recent-*
2339 (allout-depth)
2340 nil)))
2341 ;;;_ > allout-on-current-heading-p ()
2342 (defun allout-on-current-heading-p ()
2343 "Return non-nil if point is on current visible topics' header line.
2345 Actually, returns prefix beginning point."
2346 (save-excursion
2347 (allout-beginning-of-current-line)
2348 (and (looking-at allout-regexp)
2349 (allout-prefix-data)
2350 (or (not (allout-do-doublecheck))
2351 (not (allout-aberrant-container-p))))))
2352 ;;;_ > allout-on-heading-p ()
2353 (defalias 'allout-on-heading-p 'allout-on-current-heading-p)
2354 ;;;_ > allout-e-o-prefix-p ()
2355 (defun allout-e-o-prefix-p ()
2356 "True if point is located where current topic prefix ends, heading begins."
2357 (and (save-excursion (let ((inhibit-field-text-motion t))
2358 (beginning-of-line))
2359 (looking-at allout-regexp))
2360 (= (point)(save-excursion (allout-end-of-prefix)(point)))))
2361 ;;;_ : Location attributes
2362 ;;;_ > allout-depth ()
2363 (defun allout-depth ()
2364 "Return depth of topic most immediately containing point.
2366 Return zero if point is not within any topic.
2368 Like `allout-current-depth', but respects hidden as well as visible topics."
2369 (save-excursion
2370 (let ((start-point (point)))
2371 (if (and (allout-goto-prefix)
2372 (not (< start-point (point))))
2373 allout-recent-depth
2374 (progn
2375 ;; Oops, no prefix, nullify it:
2376 (nullify-allout-prefix-data)
2377 ;; ... and return 0:
2378 0)))))
2379 ;;;_ > allout-current-depth ()
2380 (defun allout-current-depth ()
2381 "Return depth of visible topic most immediately containing point.
2383 Return zero if point is not within any topic."
2384 (save-excursion
2385 (if (allout-back-to-current-heading)
2386 (max 1
2387 (- allout-recent-prefix-end
2388 allout-recent-prefix-beginning
2389 allout-header-subtraction))
2390 0)))
2391 ;;;_ > allout-get-current-prefix ()
2392 (defun allout-get-current-prefix ()
2393 "Topic prefix of the current topic."
2394 (save-excursion
2395 (if (allout-goto-prefix)
2396 (allout-recent-prefix))))
2397 ;;;_ > allout-get-bullet ()
2398 (defun allout-get-bullet ()
2399 "Return bullet of containing topic (visible or not)."
2400 (save-excursion
2401 (and (allout-goto-prefix)
2402 (allout-recent-bullet))))
2403 ;;;_ > allout-current-bullet ()
2404 (defun allout-current-bullet ()
2405 "Return bullet of current (visible) topic heading, or none if none found."
2406 (condition-case nil
2407 (save-excursion
2408 (allout-back-to-current-heading)
2409 (buffer-substring-no-properties (- allout-recent-prefix-end 1)
2410 allout-recent-prefix-end))
2411 ;; Quick and dirty provision, ostensibly for missing bullet:
2412 (args-out-of-range nil))
2414 ;;;_ > allout-get-prefix-bullet (prefix)
2415 (defun allout-get-prefix-bullet (prefix)
2416 "Return the bullet of the header prefix string PREFIX."
2417 ;; Doesn't make sense if we're old-style prefixes, but this just
2418 ;; oughtn't be called then, so forget about it...
2419 (if (string-match allout-regexp prefix)
2420 (substring prefix (1- (match-end 2)) (match-end 2))))
2421 ;;;_ > allout-sibling-index (&optional depth)
2422 (defun allout-sibling-index (&optional depth)
2423 "Item number of this prospective topic among its siblings.
2425 If optional arg DEPTH is greater than current depth, then we're
2426 opening a new level, and return 0.
2428 If less than this depth, ascend to that depth and count..."
2430 (save-excursion
2431 (cond ((and depth (<= depth 0) 0))
2432 ((or (null depth) (= depth (allout-depth)))
2433 (let ((index 1))
2434 (while (allout-previous-sibling allout-recent-depth nil)
2435 (setq index (1+ index)))
2436 index))
2437 ((< depth allout-recent-depth)
2438 (allout-ascend-to-depth depth)
2439 (allout-sibling-index))
2440 (0))))
2441 ;;;_ > allout-topic-flat-index ()
2442 (defun allout-topic-flat-index ()
2443 "Return a list indicating point's numeric section.subsect.subsubsect...
2444 Outermost is first."
2445 (let* ((depth (allout-depth))
2446 (next-index (allout-sibling-index depth))
2447 (rev-sibls nil))
2448 (while (> next-index 0)
2449 (setq rev-sibls (cons next-index rev-sibls))
2450 (setq depth (1- depth))
2451 (setq next-index (allout-sibling-index depth)))
2452 rev-sibls)
2455 ;;;_ - Navigation routines
2456 ;;;_ > allout-beginning-of-current-line ()
2457 (defun allout-beginning-of-current-line ()
2458 "Like beginning of line, but to visible text."
2460 ;; This combination of move-beginning-of-line and beginning-of-line is
2461 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2462 (let ((inhibit-field-text-motion t))
2463 (move-beginning-of-line 1)
2464 (beginning-of-line)
2465 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2466 (beginning-of-line)
2467 (if (or (allout-hidden-p) (not (bolp)))
2468 (forward-char -1)))))
2469 ;;;_ > allout-end-of-current-line ()
2470 (defun allout-end-of-current-line ()
2471 "Move to the end of line, past concealed text if any."
2472 ;; XXX This is for symmetry with `allout-beginning-of-current-line' -
2473 ;; `move-end-of-line' doesn't suffer the same problem as
2474 ;; `move-beginning-of-line'.
2475 (let ((inhibit-field-text-motion t))
2476 (end-of-line)
2477 (while (allout-hidden-p)
2478 (end-of-line)
2479 (if (allout-hidden-p) (forward-char 1)))))
2480 ;;;_ > allout-beginning-of-line ()
2481 (defun allout-beginning-of-line ()
2482 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2484 (interactive)
2486 (if (or (not allout-beginning-of-line-cycles)
2487 (not (equal last-command this-command)))
2488 (move-beginning-of-line 1)
2489 (allout-depth)
2490 (let ((beginning-of-body
2491 (save-excursion
2492 (while (and (allout-do-doublecheck)
2493 (allout-aberrant-container-p)
2494 (allout-previous-visible-heading 1)))
2495 (allout-beginning-of-current-entry)
2496 (point))))
2497 (cond ((= (current-column) 0)
2498 (goto-char beginning-of-body))
2499 ((< (point) beginning-of-body)
2500 (allout-beginning-of-current-line))
2501 ((= (point) beginning-of-body)
2502 (goto-char (allout-current-bullet-pos)))
2503 (t (allout-beginning-of-current-line)
2504 (if (< (point) beginning-of-body)
2505 ;; we were on the headline after its start:
2506 (goto-char beginning-of-body)))))))
2507 ;;;_ > allout-end-of-line ()
2508 (defun allout-end-of-line ()
2509 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2511 (interactive)
2513 (if (or (not allout-end-of-line-cycles)
2514 (not (equal last-command this-command)))
2515 (allout-end-of-current-line)
2516 (let ((end-of-entry (save-excursion
2517 (allout-end-of-entry)
2518 (point))))
2519 (cond ((not (eolp))
2520 (allout-end-of-current-line))
2521 ((or (allout-hidden-p) (save-excursion
2522 (forward-char -1)
2523 (allout-hidden-p)))
2524 (allout-back-to-current-heading)
2525 (allout-show-current-entry)
2526 (allout-show-children)
2527 (allout-end-of-entry))
2528 ((>= (point) end-of-entry)
2529 (allout-back-to-current-heading)
2530 (allout-end-of-current-line))
2531 (t (allout-end-of-entry))))))
2532 ;;;_ > allout-next-heading ()
2533 (defsubst allout-next-heading ()
2534 "Move to the heading for the topic (possibly invisible) after this one.
2536 Returns the location of the heading, or nil if none found.
2538 We skip anomolous low-level topics, a la `allout-aberrant-container-p'."
2539 (if (looking-at allout-regexp)
2540 (forward-char 1))
2542 (when (re-search-forward allout-line-boundary-regexp nil 0)
2543 (allout-prefix-data)
2544 (and (allout-do-doublecheck)
2545 ;; this will set allout-recent-* on the first non-aberrant topic,
2546 ;; whether it's the current one or one that disqualifies it:
2547 (allout-aberrant-container-p))
2548 (goto-char allout-recent-prefix-beginning)))
2549 ;;;_ > allout-this-or-next-heading
2550 (defun allout-this-or-next-heading ()
2551 "Position cursor on current or next heading."
2552 ;; A throwaway non-macro that is defined after allout-next-heading
2553 ;; and usable by allout-mode.
2554 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2555 ;;;_ > allout-previous-heading ()
2556 (defun allout-previous-heading ()
2557 "Move to the prior (possibly invisible) heading line.
2559 Return the location of the beginning of the heading, or nil if not found.
2561 We skip anomolous low-level topics, a la `allout-aberrant-container-p'."
2563 (if (bobp)
2565 (let ((start-point (point)))
2566 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2567 (allout-goto-prefix)
2568 (when (or (re-search-backward allout-line-boundary-regexp nil 0)
2569 (looking-at allout-bob-regexp))
2570 (goto-char (allout-prefix-data))
2571 (if (and (allout-do-doublecheck)
2572 (allout-aberrant-container-p))
2573 (or (allout-previous-heading)
2574 (and (goto-char start-point)
2575 ;; recalibrate allout-recent-*:
2576 (allout-depth)
2577 nil))
2578 (point))))))
2579 ;;;_ > allout-get-invisibility-overlay ()
2580 (defun allout-get-invisibility-overlay ()
2581 "Return the overlay at point that dictates allout invisibility."
2582 (let ((overlays (overlays-at (point)))
2583 got)
2584 (while (and overlays (not got))
2585 (if (equal (overlay-get (car overlays) 'invisible) 'allout)
2586 (setq got (car overlays))
2587 (pop overlays)))
2588 got))
2589 ;;;_ > allout-back-to-visible-text ()
2590 (defun allout-back-to-visible-text ()
2591 "Move to most recent prior character that is visible, and return point."
2592 (if (allout-hidden-p)
2593 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2594 (point))
2596 ;;;_ - Subtree Charting
2597 ;;;_ " These routines either produce or assess charts, which are
2598 ;;; nested lists of the locations of topics within a subtree.
2600 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2601 ;;; for elaborate, compound assessment and adjustment of a subtree.
2603 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2604 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2605 "Produce a location \"chart\" of subtopics of the containing topic.
2607 Optional argument LEVELS specifies a depth limit (relative to start
2608 depth) for the chart. Null LEVELS means no limit.
2610 When optional argument VISIBLE is non-nil, the chart includes
2611 only the visible subelements of the charted subjects.
2613 The remaining optional args are for internal use by the function.
2615 Point is left at the end of the subtree.
2617 Charts are used to capture outline structure, so that outline-altering
2618 routines need assess the structure only once, and then use the chart
2619 for their elaborate manipulations.
2621 The chart entries for the topics are in reverse order, so the
2622 last topic is listed first. The entry for each topic consists of
2623 an integer indicating the point at the beginning of the topic
2624 prefix. Charts for offspring consists of a list containing,
2625 recursively, the charts for the respective subtopics. The chart
2626 for a topics' offspring precedes the entry for the topic itself.
2628 The other function parameters are for internal recursion, and should
2629 not be specified by external callers. ORIG-DEPTH is depth of topic at
2630 starting point, and PREV-DEPTH is depth of prior topic."
2632 (let ((original (not orig-depth)) ; `orig-depth' set only in recursion.
2633 chart curr-depth)
2635 (if original ; Just starting?
2636 ; Register initial settings and
2637 ; position to first offspring:
2638 (progn (setq orig-depth (allout-depth))
2639 (or prev-depth (setq prev-depth (1+ orig-depth)))
2640 (if visible
2641 (allout-next-visible-heading 1)
2642 (allout-next-heading))))
2644 ;; Loop over the current levels' siblings. Besides being more
2645 ;; efficient than tail-recursing over a level, it avoids exceeding
2646 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2648 ;; Probably would speed things up to implement loop-based stack
2649 ;; operation rather than recursing for lower levels. Bah.
2651 (while (and (not (eobp))
2652 ; Still within original topic?
2653 (< orig-depth (setq curr-depth allout-recent-depth))
2654 (cond ((= prev-depth curr-depth)
2655 ;; Register this one and move on:
2656 (setq chart (cons allout-recent-prefix-beginning chart))
2657 (if (and levels (<= levels 1))
2658 ;; At depth limit - skip sublevels:
2659 (or (allout-next-sibling curr-depth)
2660 ;; or no more siblings - proceed to
2661 ;; next heading at lesser depth:
2662 (while (and (<= curr-depth
2663 allout-recent-depth)
2664 (if visible
2665 (allout-next-visible-heading 1)
2666 (allout-next-heading)))))
2667 (if visible
2668 (allout-next-visible-heading 1)
2669 (allout-next-heading))))
2671 ((and (< prev-depth curr-depth)
2672 (or (not levels)
2673 (> levels 0)))
2674 ;; Recurse on deeper level of curr topic:
2675 (setq chart
2676 (cons (allout-chart-subtree (and levels
2677 (1- levels))
2678 visible
2679 orig-depth
2680 curr-depth)
2681 chart))
2682 ;; ... then continue with this one.
2685 ;; ... else nil if we've ascended back to prev-depth.
2689 (if original ; We're at the last sibling on
2690 ; the original level. Position
2691 ; to the end of it:
2692 (progn (and (not (eobp)) (forward-char -1))
2693 (and (= (preceding-char) ?\n)
2694 (= (aref (buffer-substring (max 1 (- (point) 3))
2695 (point))
2697 ?\n)
2698 (forward-char -1))
2699 (setq allout-recent-end-of-subtree (point))))
2701 chart ; (nreverse chart) not necessary,
2702 ; and maybe not preferable.
2704 ;;;_ > allout-chart-siblings (&optional start end)
2705 (defun allout-chart-siblings (&optional start end)
2706 "Produce a list of locations of this and succeeding sibling topics.
2707 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2708 for an explanation of charts."
2709 (save-excursion
2710 (when (allout-goto-prefix-doublechecked)
2711 (let ((chart (list (point))))
2712 (while (allout-next-sibling)
2713 (setq chart (cons (point) chart)))
2714 (if chart (setq chart (nreverse chart)))))))
2715 ;;;_ > allout-chart-to-reveal (chart depth)
2716 (defun allout-chart-to-reveal (chart depth)
2718 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2720 If DEPTH is nil, include hidden points at any depth.
2722 Note that point can be left at any of the points on chart, or at the
2723 start point."
2725 (let (result here)
2726 (while (and (or (null depth) (> depth 0))
2727 chart)
2728 (setq here (car chart))
2729 (if (listp here)
2730 (let ((further (allout-chart-to-reveal here (if (null depth)
2731 depth
2732 (1- depth)))))
2733 ;; We're on the start of a subtree - recurse with it, if there's
2734 ;; more depth to go:
2735 (if further (setq result (append further result)))
2736 (setq chart (cdr chart)))
2737 (goto-char here)
2738 (if (allout-hidden-p)
2739 (setq result (cons here result)))
2740 (setq chart (cdr chart))))
2741 result))
2742 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2743 ;; (defun allout-chart-spec (chart spec &optional exposing)
2744 ;; "Not yet (if ever) implemented.
2746 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2748 ;; Exposure spec indicates the locations to be exposed and the prescribed
2749 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2750 ;; indicating pending concealment, anything higher indicating depth to
2751 ;; which subtopic headers should be exposed, and negative numbers
2752 ;; indicating (negative of) the depth to which subtopic headers and
2753 ;; bodies should be exposed.
2755 ;; The produced list can have two types of entries. Bare numbers
2756 ;; indicate points in the buffer where topic headers that should be
2757 ;; exposed reside.
2759 ;; - bare negative numbers indicates that the topic starting at the
2760 ;; point which is the negative of the number should be opened,
2761 ;; including their entries.
2762 ;; - bare positive values indicate that this topic header should be
2763 ;; opened.
2764 ;; - Lists signify the beginning and end points of regions that should
2765 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2766 ;; exposure:"
2767 ;; (while spec
2768 ;; (cond ((listp spec)
2769 ;; )
2770 ;; )
2771 ;; (setq spec (cdr spec)))
2772 ;; )
2774 ;;;_ - Within Topic
2775 ;;;_ > allout-goto-prefix ()
2776 (defun allout-goto-prefix ()
2777 "Put point at beginning of immediately containing outline topic.
2779 Goes to most immediate subsequent topic if none immediately containing.
2781 Not sensitive to topic visibility.
2783 Returns the point at the beginning of the prefix, or nil if none."
2785 (let (done)
2786 (while (and (not done)
2787 (search-backward "\n" nil 1))
2788 (forward-char 1)
2789 (if (looking-at allout-regexp)
2790 (setq done (allout-prefix-data))
2791 (forward-char -1)))
2792 (if (bobp)
2793 (cond ((looking-at allout-regexp)
2794 (allout-prefix-data))
2795 ((allout-next-heading))
2796 (done))
2797 done)))
2798 ;;;_ > allout-goto-prefix-doublechecked ()
2799 (defun allout-goto-prefix-doublechecked ()
2800 "Put point at beginning of immediately containing outline topic.
2802 Like `allout-goto-prefix', but shallow topics (according to
2803 `allout-doublecheck-at-and-shallower') are checked and
2804 disqualified for child containment discontinuity, according to
2805 `allout-aberrant-container-p'."
2806 (if (allout-goto-prefix)
2807 (if (and (allout-do-doublecheck)
2808 (allout-aberrant-container-p))
2809 (allout-previous-heading)
2810 (point))))
2812 ;;;_ > allout-end-of-prefix ()
2813 (defun allout-end-of-prefix (&optional ignore-decorations)
2814 "Position cursor at beginning of header text.
2816 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2817 otherwise skip white space between bullet and ensuing text."
2819 (if (not (allout-goto-prefix-doublechecked))
2821 (goto-char allout-recent-prefix-end)
2822 (if ignore-decorations
2824 (while (looking-at "[0-9]") (forward-char 1))
2825 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))
2826 ;; Reestablish where we are:
2827 (allout-current-depth)))
2828 ;;;_ > allout-current-bullet-pos ()
2829 (defun allout-current-bullet-pos ()
2830 "Return position of current (visible) topic's bullet."
2832 (if (not (allout-current-depth))
2834 (1- allout-recent-prefix-end)))
2835 ;;;_ > allout-back-to-current-heading ()
2836 (defun allout-back-to-current-heading ()
2837 "Move to heading line of current topic, or beginning if not in a topic.
2839 If interactive, we position at the end of the prefix.
2841 Return value of resulting point, unless we started outside
2842 of (before any) topics, in which case we return nil."
2844 (allout-beginning-of-current-line)
2845 (let ((bol-point (point)))
2846 (if (allout-goto-prefix-doublechecked)
2847 (if (<= (point) bol-point)
2848 (if (interactive-p)
2849 (allout-end-of-prefix)
2850 (point))
2851 (goto-char (point-min))
2852 nil))))
2853 ;;;_ > allout-back-to-heading ()
2854 (defalias 'allout-back-to-heading 'allout-back-to-current-heading)
2855 ;;;_ > allout-pre-next-prefix ()
2856 (defun allout-pre-next-prefix ()
2857 "Skip forward to just before the next heading line.
2859 Returns that character position."
2861 (if (allout-next-heading)
2862 (goto-char (1- allout-recent-prefix-beginning))))
2863 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2864 (defun allout-end-of-subtree (&optional current include-trailing-blank)
2865 "Put point at the end of the last leaf in the containing topic.
2867 Optional CURRENT means put point at the end of the containing
2868 visible topic.
2870 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2871 any, as part of the subtree. Otherwise, that trailing blank will be
2872 excluded as delimiting whitespace between topics.
2874 Returns the value of point."
2875 (interactive "P")
2876 (if current
2877 (allout-back-to-current-heading)
2878 (allout-goto-prefix-doublechecked))
2879 (let ((level allout-recent-depth))
2880 (allout-next-heading)
2881 (while (and (not (eobp))
2882 (> allout-recent-depth level))
2883 (allout-next-heading))
2884 (if (eobp)
2885 (allout-end-of-entry)
2886 (forward-char -1))
2887 (if (and (not include-trailing-blank) (= ?\n (preceding-char)))
2888 (forward-char -1))
2889 (setq allout-recent-end-of-subtree (point))))
2890 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2891 (defun allout-end-of-current-subtree (&optional include-trailing-blank)
2893 "Put point at end of last leaf in currently visible containing topic.
2895 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2896 any, as part of the subtree. Otherwise, that trailing blank will be
2897 excluded as delimiting whitespace between topics.
2899 Returns the value of point."
2900 (interactive)
2901 (allout-end-of-subtree t include-trailing-blank))
2902 ;;;_ > allout-beginning-of-current-entry ()
2903 (defun allout-beginning-of-current-entry ()
2904 "When not already there, position point at beginning of current topic header.
2906 If already there, move cursor to bullet for hot-spot operation.
2907 \(See `allout-mode' doc string for details of hot-spot operation.)"
2908 (interactive)
2909 (let ((start-point (point)))
2910 (move-beginning-of-line 1)
2911 (if (< 0 (allout-current-depth))
2912 (goto-char allout-recent-prefix-end)
2913 (goto-char (point-min)))
2914 (allout-end-of-prefix)
2915 (if (and (interactive-p)
2916 (= (point) start-point))
2917 (goto-char (allout-current-bullet-pos)))))
2918 ;;;_ > allout-end-of-entry (&optional inclusive)
2919 (defun allout-end-of-entry (&optional inclusive)
2920 "Position the point at the end of the current topics' entry.
2922 Optional INCLUSIVE means also include trailing empty line, if any. When
2923 unset, whitespace between items separates them even when the items are
2924 collapsed."
2925 (interactive)
2926 (allout-pre-next-prefix)
2927 (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char)))
2928 (forward-char -1))
2929 (point))
2930 ;;;_ > allout-end-of-current-heading ()
2931 (defun allout-end-of-current-heading ()
2932 (interactive)
2933 (allout-beginning-of-current-entry)
2934 (search-forward "\n" nil t)
2935 (forward-char -1))
2936 (defalias 'allout-end-of-heading 'allout-end-of-current-heading)
2937 ;;;_ > allout-get-body-text ()
2938 (defun allout-get-body-text ()
2939 "Return the unmangled body text of the topic immediately containing point."
2940 (save-excursion
2941 (allout-end-of-prefix)
2942 (if (not (search-forward "\n" nil t))
2944 (backward-char 1)
2945 (let ((pre-body (point)))
2946 (if (not pre-body)
2948 (allout-end-of-entry t)
2949 (if (not (= pre-body (point)))
2950 (buffer-substring-no-properties (1+ pre-body) (point))))
2956 ;;;_ - Depth-wise
2957 ;;;_ > allout-ascend-to-depth (depth)
2958 (defun allout-ascend-to-depth (depth)
2959 "Ascend to depth DEPTH, returning depth if successful, nil if not."
2960 (if (and (> depth 0)(<= depth (allout-depth)))
2961 (let (last-ascended)
2962 (while (and (< depth allout-recent-depth)
2963 (setq last-ascended (allout-ascend))))
2964 (goto-char allout-recent-prefix-beginning)
2965 (if (interactive-p) (allout-end-of-prefix))
2966 (and last-ascended allout-recent-depth))))
2967 ;;;_ > allout-ascend ()
2968 (defun allout-ascend (&optional dont-move-if-unsuccessful)
2969 "Ascend one level, returning resulting depth if successful, nil if not.
2971 Point is left at the beginning of the level whether or not
2972 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
2973 which case point is returned to its original starting location."
2974 (if dont-move-if-unsuccessful
2975 (setq dont-move-if-unsuccessful (point)))
2976 (prog1
2977 (if (allout-beginning-of-level)
2978 (let ((bolevel (point))
2979 (bolevel-depth allout-recent-depth))
2980 (allout-previous-heading)
2981 (cond ((< allout-recent-depth bolevel-depth)
2982 allout-recent-depth)
2983 ((= allout-recent-depth bolevel-depth)
2984 (if dont-move-if-unsuccessful
2985 (goto-char dont-move-if-unsuccessful))
2986 (allout-depth)
2987 nil)
2989 ;; some topic after very first is lower depth than first:
2990 (goto-char bolevel)
2991 (allout-depth)
2992 nil))))
2993 (if (interactive-p) (allout-end-of-prefix))))
2994 ;;;_ > allout-descend-to-depth (depth)
2995 (defun allout-descend-to-depth (depth)
2996 "Descend to depth DEPTH within current topic.
2998 Returning depth if successful, nil if not."
2999 (let ((start-point (point))
3000 (start-depth (allout-depth)))
3001 (while
3002 (and (> (allout-depth) 0)
3003 (not (= depth allout-recent-depth)) ; ... not there yet
3004 (allout-next-heading) ; ... go further
3005 (< start-depth allout-recent-depth))) ; ... still in topic
3006 (if (and (> (allout-depth) 0)
3007 (= allout-recent-depth depth))
3008 depth
3009 (goto-char start-point)
3010 nil))
3012 ;;;_ > allout-up-current-level (arg)
3013 (defun allout-up-current-level (arg)
3014 "Move out ARG levels from current visible topic."
3015 (interactive "p")
3016 (let ((start-point (point)))
3017 (allout-back-to-current-heading)
3018 (if (not (allout-ascend))
3019 (progn (goto-char start-point)
3020 (error "Can't ascend past outermost level"))
3021 (if (interactive-p) (allout-end-of-prefix))
3022 allout-recent-prefix-beginning)))
3024 ;;;_ - Linear
3025 ;;;_ > allout-next-sibling (&optional depth backward)
3026 (defun allout-next-sibling (&optional depth backward)
3027 "Like `allout-forward-current-level', but respects invisible topics.
3029 Traverse at optional DEPTH, or current depth if none specified.
3031 Go backward if optional arg BACKWARD is non-nil.
3033 Return the start point of the new topic if successful, nil otherwise."
3035 (if (if backward (bobp) (eobp))
3037 (let ((target-depth (or depth (allout-depth)))
3038 (start-point (point))
3039 (start-prefix-beginning allout-recent-prefix-beginning)
3040 (count 0)
3041 leaping
3042 last-depth)
3043 (while (and
3044 ;; done too few single steps to resort to the leap routine:
3045 (not leaping)
3046 ;; not at limit:
3047 (not (if backward (bobp) (eobp)))
3048 ;; still traversable:
3049 (if backward (allout-previous-heading) (allout-next-heading))
3050 ;; we're below the target depth
3051 (> (setq last-depth allout-recent-depth) target-depth))
3052 (setq count (1+ count))
3053 (if (> count 7) ; lists are commonly 7 +- 2, right?-)
3054 (setq leaping t)))
3055 (cond (leaping
3056 (or (allout-next-sibling-leap target-depth backward)
3057 (progn
3058 (goto-char start-point)
3059 (if depth (allout-depth) target-depth)
3060 nil)))
3061 ((and (not (eobp))
3062 (and (> (or last-depth (allout-depth)) 0)
3063 (= allout-recent-depth target-depth))
3064 (not (= start-prefix-beginning
3065 allout-recent-prefix-beginning)))
3066 allout-recent-prefix-beginning)
3068 (goto-char start-point)
3069 (if depth (allout-depth) target-depth)
3070 nil)))))
3071 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3072 (defun allout-next-sibling-leap (&optional depth backward)
3073 "Like `allout-next-sibling', but by direct search for topic at depth.
3075 Traverse at optional DEPTH, or current depth if none specified.
3077 Go backward if optional arg BACKWARD is non-nil.
3079 Return the start point of the new topic if successful, nil otherwise.
3081 Costs more than regular `allout-next-sibling' for short traversals:
3083 - we have to check the prior (next, if travelling backwards)
3084 item to confirm connectivity with the prior topic, and
3085 - if confirmed, we have to reestablish the allout-recent-* settings with
3086 some extra navigation
3087 - if confirmation fails, we have to do more work to recover
3089 It is an increasingly big win when there are many intervening
3090 offspring before the next sibling, however, so
3091 `allout-next-sibling' resorts to this if it finds itself in that
3092 situation."
3094 (if (if backward (bobp) (eobp))
3096 (let* ((start-point (point))
3097 (target-depth (or depth (allout-depth)))
3098 (search-whitespace-regexp nil)
3099 (depth-biased (- target-depth 2))
3100 (expression (if (<= target-depth 1)
3101 allout-depth-one-regexp
3102 (format allout-depth-specific-regexp
3103 depth-biased depth-biased)))
3104 found
3105 done)
3106 (while (not done)
3107 (setq found (if backward
3108 (re-search-backward expression nil 'to-limit)
3109 (forward-char 1)
3110 (re-search-forward expression nil 'to-limit)))
3111 (if (and found (allout-aberrant-container-p))
3112 (setq found nil))
3113 (setq done (or found (if backward (bobp) (eobp)))))
3114 (if (not found)
3115 (progn (goto-char start-point)
3116 nil)
3117 ;; rationale: if any intervening items were at a lower depth, we
3118 ;; would now be on the first offspring at the target depth - ie,
3119 ;; the preceeding item (per the search direction) must be at a
3120 ;; lesser depth. that's all we need to check.
3121 (if backward (allout-next-heading) (allout-previous-heading))
3122 (if (< allout-recent-depth target-depth)
3123 ;; return to start and reestablish allout-recent-*:
3124 (progn
3125 (goto-char start-point)
3126 (allout-depth)
3127 nil)
3128 (goto-char found)
3129 ;; locate cursor and set allout-recent-*:
3130 (allout-goto-prefix))))))
3131 ;;;_ > allout-previous-sibling (&optional depth backward)
3132 (defun allout-previous-sibling (&optional depth backward)
3133 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3135 Optional DEPTH specifies depth to traverse, default current depth.
3137 Optional BACKWARD reverses direction.
3139 Return depth if successful, nil otherwise."
3140 (allout-next-sibling depth (not backward))
3142 ;;;_ > allout-snug-back ()
3143 (defun allout-snug-back ()
3144 "Position cursor at end of previous topic.
3146 Presumes point is at the start of a topic prefix."
3147 (if (or (bobp) (eobp))
3149 (forward-char -1))
3150 (if (or (bobp) (not (= ?\n (preceding-char))))
3152 (forward-char -1))
3153 (point))
3154 ;;;_ > allout-beginning-of-level ()
3155 (defun allout-beginning-of-level ()
3156 "Go back to the first sibling at this level, visible or not."
3157 (allout-end-of-level 'backward))
3158 ;;;_ > allout-end-of-level (&optional backward)
3159 (defun allout-end-of-level (&optional backward)
3160 "Go to the last sibling at this level, visible or not."
3162 (let ((depth (allout-depth)))
3163 (while (allout-previous-sibling depth nil))
3164 (prog1 allout-recent-depth
3165 (if (interactive-p) (allout-end-of-prefix)))))
3166 ;;;_ > allout-next-visible-heading (arg)
3167 (defun allout-next-visible-heading (arg)
3168 "Move to the next ARG'th visible heading line, backward if arg is negative.
3170 Move to buffer limit in indicated direction if headings are exhausted."
3172 (interactive "p")
3173 (let* ((inhibit-field-text-motion t)
3174 (backward (if (< arg 0) (setq arg (* -1 arg))))
3175 (step (if backward -1 1))
3176 prev got)
3178 (while (> arg 0)
3179 (while (and
3180 ;; Boundary condition:
3181 (not (if backward (bobp)(eobp)))
3182 ;; Move, skipping over all concealed lines in one fell swoop:
3183 (prog1 (condition-case nil (or (line-move step) t)
3184 (error nil))
3185 (allout-beginning-of-current-line))
3186 ;; Deal with apparent header line:
3187 (if (not (looking-at allout-regexp))
3188 ;; not a header line, keep looking:
3190 (allout-prefix-data)
3191 (if (and (allout-do-doublecheck)
3192 (allout-aberrant-container-p))
3193 ;; skip this aberrant prospective header line:
3195 ;; this prospective headerline qualifies - register:
3196 (setq got allout-recent-prefix-beginning)
3197 ;; and break the loop:
3198 nil))))
3199 ;; Register this got, it may be the last:
3200 (if got (setq prev got))
3201 (setq arg (1- arg)))
3202 (cond (got ; Last move was to a prefix:
3203 (allout-end-of-prefix))
3204 (prev ; Last move wasn't, but prev was:
3205 (goto-char prev)
3206 (allout-end-of-prefix))
3207 ((not backward) (end-of-line) nil))))
3208 ;;;_ > allout-previous-visible-heading (arg)
3209 (defun allout-previous-visible-heading (arg)
3210 "Move to the previous heading line.
3212 With argument, repeats or can move forward if negative.
3213 A heading line is one that starts with a `*' (or that `allout-regexp'
3214 matches)."
3215 (interactive "p")
3216 (prog1 (allout-next-visible-heading (- arg))
3217 (if (interactive-p) (allout-end-of-prefix))))
3218 ;;;_ > allout-forward-current-level (arg)
3219 (defun allout-forward-current-level (arg)
3220 "Position point at the next heading of the same level.
3222 Takes optional repeat-count, goes backward if count is negative.
3224 Returns resulting position, else nil if none found."
3225 (interactive "p")
3226 (let ((start-depth (allout-current-depth))
3227 (start-arg arg)
3228 (backward (> 0 arg)))
3229 (if (= 0 start-depth)
3230 (error "No siblings, not in a topic..."))
3231 (if backward (setq arg (* -1 arg)))
3232 (allout-back-to-current-heading)
3233 (while (and (not (zerop arg))
3234 (if backward
3235 (allout-previous-sibling)
3236 (allout-next-sibling)))
3237 (setq arg (1- arg)))
3238 (if (not (interactive-p))
3240 (allout-end-of-prefix)
3241 (if (not (zerop arg))
3242 (error "Hit %s level %d topic, traversed %d of %d requested"
3243 (if backward "first" "last")
3244 allout-recent-depth
3245 (- (abs start-arg) arg)
3246 (abs start-arg))))))
3247 ;;;_ > allout-backward-current-level (arg)
3248 (defun allout-backward-current-level (arg)
3249 "Inverse of `allout-forward-current-level'."
3250 (interactive "p")
3251 (if (interactive-p)
3252 (let ((current-prefix-arg (* -1 arg)))
3253 (call-interactively 'allout-forward-current-level))
3254 (allout-forward-current-level (* -1 arg))))
3256 ;;;_ #5 Alteration
3258 ;;;_ - Fundamental
3259 ;;;_ = allout-post-goto-bullet
3260 (defvar allout-post-goto-bullet nil
3261 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3263 When set, tells post-processing to reposition on topic bullet, and
3264 then unset it. Set by `allout-pre-command-business' when implementing
3265 hot-spot operation, where literal characters typed over a topic bullet
3266 are mapped to the command of the corresponding control-key on the
3267 `allout-mode-map'.")
3268 (make-variable-buffer-local 'allout-post-goto-bullet)
3269 ;;;_ = allout-command-counter
3270 (defvar allout-command-counter 0
3271 "Counter that monotonically increases in allout-mode buffers.
3273 Set by `allout-pre-command-business', to support allout addons in
3274 coordinating with allout activity.")
3275 (make-variable-buffer-local 'allout-command-counter)
3276 ;;;_ > allout-post-command-business ()
3277 (defun allout-post-command-business ()
3278 "Outline `post-command-hook' function.
3280 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3281 outline commands.
3283 - Decrypt topic currently being edited if it was encrypted for a save."
3285 ; Apply any external change func:
3286 (if (not (allout-mode-p)) ; In allout-mode.
3289 (if (and (boundp 'allout-after-save-decrypt)
3290 allout-after-save-decrypt)
3291 (allout-after-saves-handler))
3293 ;; Implement allout-post-goto-bullet, if set:
3294 (if (and allout-post-goto-bullet
3295 (allout-current-bullet-pos))
3296 (progn (goto-char (allout-current-bullet-pos))
3297 (setq allout-post-goto-bullet nil)))
3299 ;;;_ > allout-pre-command-business ()
3300 (defun allout-pre-command-business ()
3301 "Outline `pre-command-hook' function for outline buffers.
3303 Among other things, implements special behavior when the cursor is on the
3304 topic bullet character.
3306 When the cursor is on the bullet character, self-insert characters are
3307 reinterpreted as the corresponding control-character in the
3308 `allout-mode-map'. The `allout-mode' `post-command-hook' insures that
3309 the cursor which has moved as a result of such reinterpretation is
3310 positioned on the bullet character of the destination topic.
3312 The upshot is that you can get easy, single (ie, unmodified) key
3313 outline maneuvering operations by positioning the cursor on the bullet
3314 char. When in this mode you can use regular cursor-positioning
3315 command/keystrokes to relocate the cursor off of a bullet character to
3316 return to regular interpretation of self-insert characters."
3318 (if (not (allout-mode-p))
3320 ;; Increment allout-command-counter
3321 (setq allout-command-counter (1+ allout-command-counter))
3322 ;; Do hot-spot navigation.
3323 (if (and (eq this-command 'self-insert-command)
3324 (eq (point)(allout-current-bullet-pos)))
3325 (allout-hotspot-key-handler))))
3326 ;;;_ > allout-hotspot-key-handler ()
3327 (defun allout-hotspot-key-handler ()
3328 "Catchall handling of key bindings in hot-spots.
3330 Translates unmodified keystrokes to corresponding allout commands, when
3331 they would qualify if prefixed with the allout-command-prefix, and sets
3332 this-command accordingly.
3334 Returns the qualifying command, if any, else nil."
3335 (interactive)
3336 (let* ((key-string (if (numberp last-command-char)
3337 (char-to-string last-command-char)))
3338 (key-num (cond ((numberp last-command-char) last-command-char)
3339 ;; for XEmacs character type:
3340 ((and (fboundp 'characterp)
3341 (apply 'characterp (list last-command-char)))
3342 (apply 'char-to-int (list last-command-char)))
3343 (t 0)))
3344 mapped-binding)
3346 (if (zerop key-num)
3349 (if (and
3350 ;; exclude control chars and escape:
3351 (<= 33 key-num)
3352 (setq mapped-binding
3353 (or (and (assoc key-string allout-keybindings-list)
3354 ;; translate literal membership on list:
3355 (cadr (assoc key-string allout-keybindings-list)))
3356 ;; translate as a keybinding:
3357 (key-binding (concat allout-command-prefix
3358 (char-to-string
3359 (if (and (<= 97 key-num) ; "a"
3360 (>= 122 key-num)) ; "z"
3361 (- key-num 96) key-num)))
3362 t))))
3363 ;; Qualified as an allout command - do hot-spot operation.
3364 (setq allout-post-goto-bullet t)
3365 ;; accept-defaults nil, or else we'll get allout-item-icon-key-handler.
3366 (setq mapped-binding (key-binding (char-to-string key-num))))
3368 (while (keymapp mapped-binding)
3369 (setq mapped-binding
3370 (lookup-key mapped-binding (vector (read-char)))))
3372 (if mapped-binding
3373 (setq this-command mapped-binding)))))
3375 ;;;_ > allout-find-file-hook ()
3376 (defun allout-find-file-hook ()
3377 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3379 See `allout-init' for setup instructions."
3380 (if (and allout-auto-activation
3381 (not (allout-mode-p))
3382 allout-layout)
3383 (allout-mode t)))
3385 ;;;_ - Topic Format Assessment
3386 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3387 (defun allout-solicit-alternate-bullet (depth &optional current-bullet)
3389 "Prompt for and return a bullet char as an alternative to the current one.
3391 Offer one suitable for current depth DEPTH as default."
3393 (let* ((default-bullet (or (and (stringp current-bullet) current-bullet)
3394 (allout-bullet-for-depth depth)))
3395 (sans-escapes (regexp-sans-escapes allout-bullets-string))
3396 choice)
3397 (save-excursion
3398 (goto-char (allout-current-bullet-pos))
3399 (setq choice (solicit-char-in-string
3400 (format "Select bullet: %s ('%s' default): "
3401 sans-escapes
3402 (substring-no-properties default-bullet))
3403 sans-escapes
3404 t)))
3405 (message "")
3406 (if (string= choice "") default-bullet choice))
3408 ;;;_ > allout-distinctive-bullet (bullet)
3409 (defun allout-distinctive-bullet (bullet)
3410 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3411 (string-match (regexp-quote bullet) allout-distinctive-bullets-string))
3412 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3413 (defun allout-numbered-type-prefix (&optional prefix)
3414 "True if current header prefix bullet is numbered bullet."
3415 (and allout-numbered-bullet
3416 (string= allout-numbered-bullet
3417 (if prefix
3418 (allout-get-prefix-bullet prefix)
3419 (allout-get-bullet)))))
3420 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3421 (defun allout-encrypted-type-prefix (&optional prefix)
3422 "True if current header prefix bullet is for an encrypted entry (body)."
3423 (and allout-topic-encryption-bullet
3424 (string= allout-topic-encryption-bullet
3425 (if prefix
3426 (allout-get-prefix-bullet prefix)
3427 (allout-get-bullet)))))
3428 ;;;_ > allout-bullet-for-depth (&optional depth)
3429 (defun allout-bullet-for-depth (&optional depth)
3430 "Return outline topic bullet suited to optional DEPTH, or current depth."
3431 ;; Find bullet in plain-bullets-string modulo DEPTH.
3432 (if allout-stylish-prefixes
3433 (char-to-string (aref allout-plain-bullets-string
3434 (% (max 0 (- depth 2))
3435 allout-plain-bullets-string-len)))
3436 allout-primary-bullet)
3439 ;;;_ - Topic Production
3440 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3441 (defun allout-make-topic-prefix (&optional prior-bullet
3443 depth
3444 solicit
3445 number-control
3446 index)
3447 ;; Depth null means use current depth, non-null means we're either
3448 ;; opening a new topic after current topic, lower or higher, or we're
3449 ;; changing level of current topic.
3450 ;; Solicit dominates specified bullet-char.
3451 ;;;_ . Doc string:
3452 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3454 All the arguments are optional.
3456 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3457 nil if none. This bullet may be preserved (other options
3458 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3459 for instance.
3461 Second arg NEW indicates that a new topic is being opened after the
3462 topic at point, if non-nil. Default bullet for new topics, eg, may
3463 be set (contingent to other args) to numbered bullets if previous
3464 sibling is one. The implication otherwise is that the current topic
3465 is being adjusted - shifted or rebulleted - and we don't consider
3466 bullet or previous sibling.
3468 Third arg DEPTH forces the topic prefix to that depth, regardless of
3469 the current topics' depth.
3471 If SOLICIT is non-nil, then the choice of bullet is solicited from
3472 user. If it's a character, then that character is offered as the
3473 default, otherwise the one suited to the context (according to
3474 distinction or depth) is offered. (This overrides other options,
3475 including, eg, a distinctive PRIOR-BULLET.) If non-nil, then the
3476 context-specific bullet is used.
3478 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3479 is non-nil *and* soliciting was not explicitly invoked. Then
3480 NUMBER-CONTROL non-nil forces prefix to either numbered or
3481 denumbered format, depending on the value of the sixth arg, INDEX.
3483 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3485 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3486 the prefix of the topic is forced to be numbered. Non-nil
3487 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3488 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3489 that the index for the numbered prefix will be derived, by counting
3490 siblings back to start of level. If INDEX is a number, then that
3491 number is used as the index for the numbered prefix (allowing, eg,
3492 sequential renumbering to not require this function counting back the
3493 index for each successive sibling)."
3494 ;;;_ . Code:
3495 ;; The options are ordered in likely frequence of use, most common
3496 ;; highest, least lowest. Ie, more likely to be doing prefix
3497 ;; adjustments than soliciting, and yet more than numbering.
3498 ;; Current prefix is least dominant, but most likely to be commonly
3499 ;; specified...
3501 (let* (body
3502 numbering
3503 denumbering
3504 (depth (or depth (allout-depth)))
3505 (header-lead allout-header-prefix)
3506 (bullet-char
3508 ;; Getting value for bullet char is practically the whole job:
3510 (cond
3511 ; Simplest situation - level 1:
3512 ((<= depth 1) (setq header-lead "") allout-primary-bullet)
3513 ; Simple, too: all asterisks:
3514 (allout-old-style-prefixes
3515 ;; Cheat - make body the whole thing, null out header-lead and
3516 ;; bullet-char:
3517 (setq body (make-string depth
3518 (string-to-char allout-primary-bullet)))
3519 (setq header-lead "")
3522 ;; (Neither level 1 nor old-style, so we're space padding.
3523 ;; Sneak it in the condition of the next case, whatever it is.)
3525 ;; Solicitation overrides numbering and other cases:
3526 ((progn (setq body (make-string (- depth 2) ?\ ))
3527 ;; The actual condition:
3528 solicit)
3529 (let* ((got (allout-solicit-alternate-bullet depth solicit)))
3530 ;; Gotta check whether we're numbering and got a numbered bullet:
3531 (setq numbering (and allout-numbered-bullet
3532 (not (and number-control (not index)))
3533 (string= got allout-numbered-bullet)))
3534 ;; Now return what we got, regardless:
3535 got))
3537 ;; Numbering invoked through args:
3538 ((and allout-numbered-bullet number-control)
3539 (if (setq numbering (not (setq denumbering (not index))))
3540 allout-numbered-bullet
3541 (if (and prior-bullet
3542 (not (string= allout-numbered-bullet
3543 prior-bullet)))
3544 prior-bullet
3545 (allout-bullet-for-depth depth))))
3547 ;;; Neither soliciting nor controlled numbering ;;;
3548 ;;; (may be controlled denumbering, tho) ;;;
3550 ;; Check wrt previous sibling:
3551 ((and new ; only check for new prefixes
3552 (<= depth (allout-depth))
3553 allout-numbered-bullet ; ... & numbering enabled
3554 (not denumbering)
3555 (let ((sibling-bullet
3556 (save-excursion
3557 ;; Locate correct sibling:
3558 (or (>= depth (allout-depth))
3559 (allout-ascend-to-depth depth))
3560 (allout-get-bullet))))
3561 (if (and sibling-bullet
3562 (string= allout-numbered-bullet sibling-bullet))
3563 (setq numbering sibling-bullet)))))
3565 ;; Distinctive prior bullet?
3566 ((and prior-bullet
3567 (allout-distinctive-bullet prior-bullet)
3568 ;; Either non-numbered:
3569 (or (not (and allout-numbered-bullet
3570 (string= prior-bullet allout-numbered-bullet)))
3571 ;; or numbered, and not denumbering:
3572 (setq numbering (not denumbering)))
3573 ;; Here 'tis:
3574 prior-bullet))
3576 ;; Else, standard bullet per depth:
3577 ((allout-bullet-for-depth depth)))))
3579 (concat header-lead
3580 body
3581 bullet-char
3582 (if numbering
3583 (format "%d" (cond ((and index (numberp index)) index)
3584 (new (1+ (allout-sibling-index depth)))
3585 ((allout-sibling-index))))))
3588 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3589 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet)
3590 "Open a new topic at depth DEPTH.
3592 New topic is situated after current one, unless optional flag BEFORE
3593 is non-nil, or unless current line is completely empty - lacking even
3594 whitespace - in which case open is done on the current line.
3596 When adding an offspring, it will be added immediately after the parent if
3597 the other offspring are exposed, or after the last child if the offspring
3598 are hidden. (The intervening offspring will be exposed in the latter
3599 case.)
3601 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3603 Nuances:
3605 - Creation of new topics is with respect to the visible topic
3606 containing the cursor, regardless of intervening concealed ones.
3608 - New headers are generally created after/before the body of a
3609 topic. However, they are created right at cursor location if the
3610 cursor is on a blank line, even if that breaks the current topic
3611 body. This is intentional, to provide a simple means for
3612 deliberately dividing topic bodies.
3614 - Double spacing of topic lists is preserved. Also, the first
3615 level two topic is created double-spaced (and so would be
3616 subsequent siblings, if that's left intact). Otherwise,
3617 single-spacing is used.
3619 - Creation of sibling or nested topics is with respect to the topic
3620 you're starting from, even when creating backwards. This way you
3621 can easily create a sibling in front of the current topic without
3622 having to go to its preceding sibling, and then open forward
3623 from there."
3625 (allout-beginning-of-current-line)
3626 (let* ((inhibit-field-text-motion t)
3627 (depth (+ (allout-current-depth) relative-depth))
3628 (opening-on-blank (if (looking-at "^\$")
3629 (not (setq before nil))))
3630 ;; bunch o vars set while computing ref-topic
3631 opening-numbered
3632 ref-depth
3633 ref-bullet
3634 (ref-topic (save-excursion
3635 (cond ((< relative-depth 0)
3636 (allout-ascend-to-depth depth))
3637 ((>= relative-depth 1) nil)
3638 (t (allout-back-to-current-heading)))
3639 (setq ref-depth allout-recent-depth)
3640 (setq ref-bullet
3641 (if (> allout-recent-prefix-end 1)
3642 (allout-recent-bullet)
3643 ""))
3644 (setq opening-numbered
3645 (save-excursion
3646 (and allout-numbered-bullet
3647 (or (<= relative-depth 0)
3648 (allout-descend-to-depth depth))
3649 (if (allout-numbered-type-prefix)
3650 allout-numbered-bullet))))
3651 (point)))
3652 dbl-space
3653 doing-beginning
3654 start end)
3656 (if (not opening-on-blank)
3657 ; Positioning and vertical
3658 ; padding - only if not
3659 ; opening-on-blank:
3660 (progn
3661 (goto-char ref-topic)
3662 (setq dbl-space ; Determine double space action:
3663 (or (and (<= relative-depth 0) ; not descending;
3664 (save-excursion
3665 ;; at b-o-b or preceded by a blank line?
3666 (or (> 0 (forward-line -1))
3667 (looking-at "^\\s-*$")
3668 (bobp)))
3669 (save-excursion
3670 ;; succeeded by a blank line?
3671 (allout-end-of-current-subtree)
3672 (looking-at "\n\n")))
3673 (and (= ref-depth 1)
3674 (or before
3675 (= depth 1)
3676 (save-excursion
3677 ;; Don't already have following
3678 ;; vertical padding:
3679 (not (allout-pre-next-prefix)))))))
3681 ;; Position to prior heading, if inserting backwards, and not
3682 ;; going outwards:
3683 (if (and before (>= relative-depth 0))
3684 (progn (allout-back-to-current-heading)
3685 (setq doing-beginning (bobp))
3686 (if (not (bobp))
3687 (allout-previous-heading)))
3688 (if (and before (bobp))
3689 (open-line 1)))
3691 (if (<= relative-depth 0)
3692 ;; Not going inwards, don't snug up:
3693 (if doing-beginning
3694 (if (not dbl-space)
3695 (open-line 1)
3696 (open-line 2))
3697 (if before
3698 (progn (end-of-line)
3699 (allout-pre-next-prefix)
3700 (while (and (= ?\n (following-char))
3701 (save-excursion
3702 (forward-char 1)
3703 (allout-hidden-p)))
3704 (forward-char 1))
3705 (if (not (looking-at "^$"))
3706 (open-line 1)))
3707 (allout-end-of-current-subtree)
3708 (if (looking-at "\n\n") (forward-char 1))))
3709 ;; Going inwards - double-space if first offspring is
3710 ;; double-spaced, otherwise snug up.
3711 (allout-end-of-entry)
3712 (if (eobp)
3713 (newline 1)
3714 (line-move 1))
3715 (allout-beginning-of-current-line)
3716 (backward-char 1)
3717 (if (bolp)
3718 ;; Blank lines between current header body and next
3719 ;; header - get to last substantive (non-white-space)
3720 ;; line in body:
3721 (progn (setq dbl-space t)
3722 (re-search-backward "[^ \t\n]" nil t)))
3723 (if (looking-at "\n\n")
3724 (setq dbl-space t))
3725 (if (save-excursion
3726 (allout-next-heading)
3727 (when (> allout-recent-depth ref-depth)
3728 ;; This is an offspring.
3729 (forward-line -1)
3730 (looking-at "^\\s-*$")))
3731 (progn (forward-line 1)
3732 (open-line 1)
3733 (forward-line 1)))
3734 (allout-end-of-current-line))
3736 ;;(if doing-beginning (goto-char doing-beginning))
3737 (if (not (bobp))
3738 ;; We insert a newline char rather than using open-line to
3739 ;; avoid rear-stickiness inheritence of read-only property.
3740 (progn (if (and (not (> depth ref-depth))
3741 (not before))
3742 (open-line 1)
3743 (if (and (not dbl-space) (> depth ref-depth))
3744 (newline 1)
3745 (if dbl-space
3746 (open-line 1)
3747 (if (not before)
3748 (newline 1)))))
3749 (if (and dbl-space (not (> relative-depth 0)))
3750 (newline 1))
3751 (if (and (not (eobp))
3752 (or (not (bolp))
3753 (and (not (bobp))
3754 ;; bolp doesnt detect concealed
3755 ;; trailing newlines, compensate:
3756 (save-excursion
3757 (forward-char -1)
3758 (allout-hidden-p)))))
3759 (forward-char 1))))
3761 (setq start (point))
3762 (insert (concat (allout-make-topic-prefix opening-numbered t depth)
3763 " "))
3764 (setq end (1+ (point)))
3766 (allout-rebullet-heading (and offer-recent-bullet ref-bullet)
3767 depth nil nil t)
3768 (if (> relative-depth 0)
3769 (save-excursion (goto-char ref-topic)
3770 (allout-show-children)))
3771 (end-of-line)
3773 (run-hook-with-args 'allout-structure-added-hook start end)
3776 ;;;_ > allout-open-subtopic (arg)
3777 (defun allout-open-subtopic (arg)
3778 "Open new topic header at deeper level than the current one.
3780 Negative universal arg means to open deeper, but place the new topic
3781 prior to the current one."
3782 (interactive "p")
3783 (allout-open-topic 1 (> 0 arg) (< 1 arg)))
3784 ;;;_ > allout-open-sibtopic (arg)
3785 (defun allout-open-sibtopic (arg)
3786 "Open new topic header at same level as the current one.
3788 Positive universal arg means to use the bullet of the prior sibling.
3790 Negative universal arg means to place the new topic prior to the current
3791 one."
3792 (interactive "p")
3793 (allout-open-topic 0 (> 0 arg) (not (= 1 arg))))
3794 ;;;_ > allout-open-supertopic (arg)
3795 (defun allout-open-supertopic (arg)
3796 "Open new topic header at shallower level than the current one.
3798 Negative universal arg means to open shallower, but place the new
3799 topic prior to the current one."
3801 (interactive "p")
3802 (allout-open-topic -1 (> 0 arg) (< 1 arg)))
3804 ;;;_ - Outline Alteration
3805 ;;;_ : Topic Modification
3806 ;;;_ = allout-former-auto-filler
3807 (defvar allout-former-auto-filler nil
3808 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3809 ;;;_ > allout-auto-fill ()
3810 (defun allout-auto-fill ()
3811 "`allout-mode' autofill function.
3813 Maintains outline hanging topic indentation if
3814 `allout-use-hanging-indents' is set."
3816 (when (not allout-inhibit-auto-fill)
3817 (let ((fill-prefix (if allout-use-hanging-indents
3818 ;; Check for topic header indentation:
3819 (save-excursion
3820 (beginning-of-line)
3821 (if (looking-at allout-regexp)
3822 ;; ... construct indentation to account for
3823 ;; length of topic prefix:
3824 (make-string (progn (allout-end-of-prefix)
3825 (current-column))
3826 ?\ )))))
3827 (use-auto-fill-function (or allout-outside-normal-auto-fill-function
3828 auto-fill-function
3829 'do-auto-fill)))
3830 (if (or allout-former-auto-filler allout-use-hanging-indents)
3831 (funcall use-auto-fill-function)))))
3832 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3833 (defun allout-reindent-body (old-depth new-depth &optional number)
3834 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3836 Optional arg NUMBER indicates numbering is being added, and it must
3837 be accommodated.
3839 Note that refill of indented paragraphs is not done."
3841 (save-excursion
3842 (allout-end-of-prefix)
3843 (let* ((new-margin (current-column))
3844 excess old-indent-begin old-indent-end
3845 ;; We want the column where the header-prefix text started
3846 ;; *before* the prefix was changed, so we infer it relative
3847 ;; to the new margin and the shift in depth:
3848 (old-margin (+ old-depth (- new-margin new-depth))))
3850 ;; Process lines up to (but excluding) next topic header:
3851 (allout-unprotected
3852 (save-match-data
3853 (while
3854 (and (re-search-forward "\n\\(\\s-*\\)"
3857 ;; Register the indent data, before we reset the
3858 ;; match data with a subsequent `looking-at':
3859 (setq old-indent-begin (match-beginning 1)
3860 old-indent-end (match-end 1))
3861 (not (looking-at allout-regexp)))
3862 (if (> 0 (setq excess (- (- old-indent-end old-indent-begin)
3863 old-margin)))
3864 ;; Text starts left of old margin - don't adjust:
3866 ;; Text was hanging at or right of old left margin -
3867 ;; reindent it, preserving its existing indentation
3868 ;; beyond the old margin:
3869 (delete-region old-indent-begin old-indent-end)
3870 (indent-to (+ new-margin excess (current-column))))))))))
3871 ;;;_ > allout-rebullet-current-heading (arg)
3872 (defun allout-rebullet-current-heading (arg)
3873 "Solicit new bullet for current visible heading."
3874 (interactive "p")
3875 (let ((initial-col (current-column))
3876 (on-bullet (eq (point)(allout-current-bullet-pos)))
3877 from to
3878 (backwards (if (< arg 0)
3879 (setq arg (* arg -1)))))
3880 (while (> arg 0)
3881 (save-excursion (allout-back-to-current-heading)
3882 (allout-end-of-prefix)
3883 (setq from allout-recent-prefix-beginning
3884 to allout-recent-prefix-end)
3885 (allout-rebullet-heading t ;;; solicit
3886 nil ;;; depth
3887 nil ;;; number-control
3888 nil ;;; index
3889 t) ;;; do-successors
3890 (run-hook-with-args 'allout-exposure-change-hook
3891 from to t))
3892 (setq arg (1- arg))
3893 (if (<= arg 0)
3895 (setq initial-col nil) ; Override positioning back to init col
3896 (if (not backwards)
3897 (allout-next-visible-heading 1)
3898 (allout-goto-prefix-doublechecked)
3899 (allout-next-visible-heading -1))))
3900 (message "Done.")
3901 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
3902 (initial-col (move-to-column initial-col)))))
3903 ;;;_ > allout-rebullet-heading (&optional solicit ...)
3904 (defun allout-rebullet-heading (&optional solicit
3905 new-depth
3906 number-control
3907 index
3908 do-successors)
3910 "Adjust bullet of current topic prefix.
3912 All args are optional.
3914 If SOLICIT is non-nil, then the choice of bullet is solicited from
3915 user. If it's a character, then that character is offered as the
3916 default, otherwise the one suited to the context (according to
3917 distinction or depth) is offered. If non-nil, then the
3918 context-specific bullet is just used.
3920 Second arg DEPTH forces the topic prefix to that depth, regardless
3921 of the topic's current depth.
3923 Third arg NUMBER-CONTROL can force the prefix to or away from
3924 numbered form. It has effect only if `allout-numbered-bullet' is
3925 non-nil and soliciting was not explicitly invoked (via first arg).
3926 Its effect, numbering or denumbering, then depends on the setting
3927 of the forth arg, INDEX.
3929 If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the
3930 prefix of the topic is forced to be non-numbered. Null index and
3931 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
3932 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
3933 INDEX is a number, then that number is used for the numbered
3934 prefix. Non-nil and non-number means that the index for the
3935 numbered prefix will be derived by allout-make-topic-prefix.
3937 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
3938 siblings.
3940 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
3941 and `allout-numbered-bullet', which all affect the behavior of
3942 this function."
3944 (let* ((current-depth (allout-depth))
3945 (new-depth (or new-depth current-depth))
3946 (mb allout-recent-prefix-beginning)
3947 (me allout-recent-prefix-end)
3948 (current-bullet (buffer-substring-no-properties (- me 1) me))
3949 (has-annotation (get-text-property mb 'allout-was-hidden))
3950 (new-prefix (allout-make-topic-prefix current-bullet
3952 new-depth
3953 solicit
3954 number-control
3955 index)))
3957 ;; Is new one is identical to old?
3958 (if (and (= current-depth new-depth)
3959 (string= current-bullet
3960 (substring new-prefix (1- (length new-prefix)))))
3961 ;; Nothing to do:
3964 ;; New prefix probably different from old:
3965 ; get rid of old one:
3966 (allout-unprotected (delete-region mb me))
3967 (goto-char mb)
3968 ; Dispense with number if
3969 ; numbered-bullet prefix:
3970 (if (and allout-numbered-bullet
3971 (string= allout-numbered-bullet current-bullet)
3972 (looking-at "[0-9]+"))
3973 (allout-unprotected
3974 (delete-region (match-beginning 0)(match-end 0))))
3976 ;; convey 'allout-was-hidden annotation, if original had it:
3977 (if has-annotation
3978 (put-text-property 0 (length new-prefix) 'allout-was-hidden t
3979 new-prefix))
3981 ; Put in new prefix:
3982 (allout-unprotected (insert new-prefix))
3984 ;; Reindent the body if elected, margin changed, and not encrypted body:
3985 (if (and allout-reindent-bodies
3986 (not (= new-depth current-depth))
3987 (not (allout-encrypted-topic-p)))
3988 (allout-reindent-body current-depth new-depth))
3990 ;; Recursively rectify successive siblings of orig topic if
3991 ;; caller elected for it:
3992 (if do-successors
3993 (save-excursion
3994 (while (allout-next-sibling new-depth nil)
3995 (setq index
3996 (cond ((numberp index) (1+ index))
3997 ((not number-control) (allout-sibling-index))))
3998 (if (allout-numbered-type-prefix)
3999 (allout-rebullet-heading nil ;;; solicit
4000 new-depth ;;; new-depth
4001 number-control;;; number-control
4002 index ;;; index
4003 nil))))) ;;;(dont!)do-successors
4004 ) ; (if (and (= current-depth new-depth)...))
4005 ) ; let* ((current-depth (allout-depth))...)
4006 ) ; defun
4007 ;;;_ > allout-rebullet-topic (arg)
4008 (defun allout-rebullet-topic (arg &optional sans-offspring)
4009 "Rebullet the visible topic containing point and all contained subtopics.
4011 Descends into invisible as well as visible topics, however.
4013 When optional sans-offspring is non-nil, subtopics are not
4014 shifted. (Shifting a topic outwards without shifting its
4015 offspring is disallowed, since this would create a \"containment
4016 discontinuity\", where the depth difference between a topic and
4017 its immediate offspring is greater than one.)
4019 With repeat count, shift topic depth by that amount."
4020 (interactive "P")
4021 (let ((start-col (current-column)))
4022 (save-excursion
4023 ;; Normalize arg:
4024 (cond ((null arg) (setq arg 0))
4025 ((listp arg) (setq arg (car arg))))
4026 ;; Fill the user in, in case we're shifting a big topic:
4027 (if (not (zerop arg)) (message "Shifting..."))
4028 (allout-back-to-current-heading)
4029 (if (<= (+ allout-recent-depth arg) 0)
4030 (error "Attempt to shift topic below level 1"))
4031 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring)
4032 (if (not (zerop arg)) (message "Shifting... done.")))
4033 (move-to-column (max 0 (+ start-col arg)))))
4034 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4035 (defun allout-rebullet-topic-grunt (&optional relative-depth
4036 starting-depth
4037 starting-point
4038 index
4039 do-successors
4040 sans-offspring)
4041 "Like `allout-rebullet-topic', but on nearest containing topic
4042 \(visible or not).
4044 See `allout-rebullet-heading' for rebulleting behavior.
4046 All arguments are optional.
4048 First arg RELATIVE-DEPTH means to shift the depth of the entire
4049 topic that amount.
4051 Several subsequent args are for internal recursive use by the function
4052 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4054 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4055 are not shifted. (Shifting a topic outwards without shifting
4056 its offspring is disallowed, since this would create a
4057 \"containment discontinuity\", where the depth difference between
4058 a topic and its immediate offspring is greater than one..)"
4060 ;; XXX the recursion here is peculiar, and in general the routine may
4061 ;; need simplification with refactoring.
4063 (if (and sans-offspring
4064 relative-depth
4065 (< relative-depth 0))
4066 (error (concat "Attempt to shift topic outwards without offspring,"
4067 " would cause containment discontinuity.")))
4069 (let* ((relative-depth (or relative-depth 0))
4070 (new-depth (allout-depth))
4071 (starting-depth (or starting-depth new-depth))
4072 (on-starting-call (null starting-point))
4073 (index (or index
4074 ;; Leave index null on starting call, so rebullet-heading
4075 ;; calculates it at what might be new depth:
4076 (and (or (zerop relative-depth)
4077 (not on-starting-call))
4078 (allout-sibling-index))))
4079 (starting-index index)
4080 (moving-outwards (< 0 relative-depth))
4081 (starting-point (or starting-point (point)))
4082 (local-point (point)))
4084 ;; Sanity check for excessive promotion done only on starting call:
4085 (and on-starting-call
4086 moving-outwards
4087 (> 0 (+ starting-depth relative-depth))
4088 (error "Attempt to shift topic out beyond level 1"))
4090 (cond ((= starting-depth new-depth)
4091 ;; We're at depth to work on this one.
4093 ;; When shifting out we work on the children before working on
4094 ;; the parent to avoid interim `allout-aberrant-container-p'
4095 ;; aberrancy, and vice-versa when shifting in:
4096 (if (>= relative-depth 0)
4097 (allout-rebullet-heading nil
4098 (+ starting-depth relative-depth)
4099 nil ;;; number
4100 index
4101 nil)) ;;; do-successors
4102 (when (not sans-offspring)
4103 ;; ... and work on subsequent ones which are at greater depth:
4104 (setq index 0)
4105 (allout-next-heading)
4106 (while (and (not (eobp))
4107 (< starting-depth (allout-depth)))
4108 (setq index (1+ index))
4109 (allout-rebullet-topic-grunt relative-depth
4110 (1+ starting-depth)
4111 starting-point
4112 index)))
4113 (when (< relative-depth 0)
4114 (save-excursion
4115 (goto-char local-point)
4116 (allout-rebullet-heading nil ;;; solicit
4117 (+ starting-depth relative-depth)
4118 nil ;;; number
4119 starting-index
4120 nil)))) ;;; do-successors
4122 ((< starting-depth new-depth)
4123 ;; Rare case - subtopic more than one level deeper than parent.
4124 ;; Treat this one at an even deeper level:
4125 (allout-rebullet-topic-grunt relative-depth
4126 new-depth
4127 starting-point
4128 index
4129 sans-offspring)))
4131 (if on-starting-call
4132 (progn
4133 ;; Rectify numbering of former siblings of the adjusted topic,
4134 ;; if topic has changed depth
4135 (if (or do-successors
4136 (and (not (zerop relative-depth))
4137 (or (= allout-recent-depth starting-depth)
4138 (= allout-recent-depth (+ starting-depth
4139 relative-depth)))))
4140 (allout-rebullet-heading nil nil nil nil t))
4141 ;; Now rectify numbering of new siblings of the adjusted topic,
4142 ;; if depth has been changed:
4143 (progn (goto-char starting-point)
4144 (if (not (zerop relative-depth))
4145 (allout-rebullet-heading nil nil nil nil t)))))
4148 ;;;_ > allout-renumber-to-depth (&optional depth)
4149 (defun allout-renumber-to-depth (&optional depth)
4150 "Renumber siblings at current depth.
4152 Affects superior topics if optional arg DEPTH is less than current depth.
4154 Returns final depth."
4156 ;; Proceed by level, processing subsequent siblings on each,
4157 ;; ascending until we get shallower than the start depth:
4159 (let ((ascender (allout-depth))
4160 was-eobp)
4161 (while (and (not (eobp))
4162 (allout-depth)
4163 (>= allout-recent-depth depth)
4164 (>= ascender depth))
4165 ; Skip over all topics at
4166 ; lesser depths, which can not
4167 ; have been disturbed:
4168 (while (and (not (setq was-eobp (eobp)))
4169 (> allout-recent-depth ascender))
4170 (allout-next-heading))
4171 ; Prime ascender for ascension:
4172 (setq ascender (1- allout-recent-depth))
4173 (if (>= allout-recent-depth depth)
4174 (allout-rebullet-heading nil ;;; solicit
4175 nil ;;; depth
4176 nil ;;; number-control
4177 nil ;;; index
4178 t)) ;;; do-successors
4179 (if was-eobp (goto-char (point-max)))))
4180 allout-recent-depth)
4181 ;;;_ > allout-number-siblings (&optional denumber)
4182 (defun allout-number-siblings (&optional denumber)
4183 "Assign numbered topic prefix to this topic and its siblings.
4185 With universal argument, denumber - assign default bullet to this
4186 topic and its siblings.
4188 With repeated universal argument (`^U^U'), solicit bullet for each
4189 rebulleting each topic at this level."
4191 (interactive "P")
4193 (save-excursion
4194 (allout-back-to-current-heading)
4195 (allout-beginning-of-level)
4196 (let ((depth allout-recent-depth)
4197 (index (if (not denumber) 1))
4198 (use-bullet (equal '(16) denumber))
4199 (more t))
4200 (while more
4201 (allout-rebullet-heading use-bullet ;;; solicit
4202 depth ;;; depth
4203 t ;;; number-control
4204 index ;;; index
4205 nil) ;;; do-successors
4206 (if index (setq index (1+ index)))
4207 (setq more (allout-next-sibling depth nil))))))
4208 ;;;_ > allout-shift-in (arg)
4209 (defun allout-shift-in (arg)
4210 "Increase depth of current heading and any items collapsed within it.
4212 With a negative argument, the item is shifted out using
4213 `allout-shift-out', instead.
4215 With an argument greater than one, shift-in the item but not its
4216 offspring, making the item into a sibling of its former children,
4217 and a child of sibling that formerly preceeded it.
4219 You are not allowed to shift the first offspring of a topic
4220 inwards, because that would yield a \"containment
4221 discontinuity\", where the depth difference between a topic and
4222 its immediate offspring is greater than one. The first topic in
4223 the file can be adjusted to any positive depth, however."
4225 (interactive "p")
4226 (if (< arg 0)
4227 (allout-shift-out (* arg -1))
4228 ;; refuse to create a containment discontinuity:
4229 (save-excursion
4230 (allout-back-to-current-heading)
4231 (if (not (bobp))
4232 (let* ((current-depth allout-recent-depth)
4233 (start-point (point))
4234 (predecessor-depth (progn
4235 (forward-char -1)
4236 (allout-goto-prefix-doublechecked)
4237 (if (< (point) start-point)
4238 allout-recent-depth
4239 0))))
4240 (if (and (> predecessor-depth 0)
4241 (> (1+ current-depth)
4242 (1+ predecessor-depth)))
4243 (error (concat "Disallowed shift deeper than"
4244 " containing topic's children."))
4245 (allout-back-to-current-heading)
4246 (if (< allout-recent-depth (1+ current-depth))
4247 (allout-show-children))))))
4248 (let ((where (point)))
4249 (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring))
4250 (run-hook-with-args 'allout-structure-shifted-hook arg where))))
4251 ;;;_ > allout-shift-out (arg)
4252 (defun allout-shift-out (arg)
4253 "Decrease depth of current heading and any topics collapsed within it.
4254 This will make the item a sibling of its former container.
4256 With a negative argument, the item is shifted in using
4257 `allout-shift-in', instead.
4259 With an argument greater than one, shift-out the item's offspring
4260 but not the item itself, making the former children siblings of
4261 the item.
4263 With an argument greater than 1, the item's offspring are shifted
4264 out without shifting the item. This will make the immediate
4265 subtopics into siblings of the item."
4266 (interactive "p")
4267 (if (< arg 0)
4268 (allout-shift-in (* arg -1))
4269 ;; Get proper exposure in this area:
4270 (save-excursion (if (allout-ascend)
4271 (allout-show-children)))
4272 ;; Show collapsed children if there's a successor which will become
4273 ;; their sibling:
4274 (if (and (allout-current-topic-collapsed-p)
4275 (save-excursion (allout-next-sibling)))
4276 (allout-show-children))
4277 (let ((where (and (allout-depth) allout-recent-prefix-beginning)))
4278 (save-excursion
4279 (if (> arg 1)
4280 ;; Shift the offspring but not the topic:
4281 (let ((children-chart (allout-chart-subtree 1)))
4282 (if (listp (car children-chart))
4283 ;; whoops:
4284 (setq children-chart (allout-flatten children-chart)))
4285 (save-excursion
4286 (dolist (child-point children-chart)
4287 (goto-char child-point)
4288 (allout-shift-out 1))))
4289 (allout-rebullet-topic (* arg -1))))
4290 (run-hook-with-args 'allout-structure-shifted-hook (* arg -1) where))))
4291 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4292 ;;;_ > allout-kill-line (&optional arg)
4293 (defun allout-kill-line (&optional arg)
4294 "Kill line, adjusting subsequent lines suitably for outline mode."
4296 (interactive "*P")
4298 (if (or (not (allout-mode-p))
4299 (not (bolp))
4300 (not (looking-at allout-regexp)))
4301 ;; Just do a regular kill:
4302 (kill-line arg)
4303 ;; Ah, have to watch out for adjustments:
4304 (let* ((beg (point))
4306 (beg-hidden (allout-hidden-p))
4307 (end-hidden (save-excursion (allout-end-of-current-line)
4308 (setq end (point))
4309 (allout-hidden-p)))
4310 (depth (allout-depth)))
4312 (allout-annotate-hidden beg end)
4313 (if (and (not beg-hidden) (not end-hidden))
4314 (allout-unprotected (kill-line arg))
4315 (kill-line arg))
4316 (allout-deannotate-hidden beg end)
4318 (if allout-numbered-bullet
4319 (save-excursion ; Renumber subsequent topics if needed:
4320 (if (not (looking-at allout-regexp))
4321 (allout-next-heading))
4322 (allout-renumber-to-depth depth)))
4323 (run-hook-with-args 'allout-structure-deleted-hook depth (point)))))
4324 ;;;_ > allout-copy-line-as-kill ()
4325 (defun allout-copy-line-as-kill ()
4326 "Like allout-kill-topic, but save to kill ring instead of deleting."
4327 (interactive)
4328 (let ((buffer-read-only t))
4329 (condition-case nil
4330 (allout-kill-line)
4331 (buffer-read-only nil))))
4332 ;;;_ > allout-kill-topic ()
4333 (defun allout-kill-topic ()
4334 "Kill topic together with subtopics.
4336 Trailing whitespace is killed with a topic if that whitespace:
4338 - would separate the topic from a subsequent sibling
4339 - would separate the topic from the end of buffer
4340 - would not be added to whitespace already separating the topic from the
4341 previous one.
4343 Topic exposure is marked with text-properties, to be used by
4344 allout-yank-processing for exposure recovery."
4346 (interactive)
4347 (let* ((inhibit-field-text-motion t)
4348 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4350 (depth allout-recent-depth))
4351 (allout-end-of-current-subtree)
4352 (if (and (/= (current-column) 0) (not (eobp)))
4353 (forward-char 1))
4354 (if (not (eobp))
4355 (if (and (looking-at "\n")
4356 (or (save-excursion
4357 (or (not (allout-next-heading))
4358 (= depth allout-recent-depth)))
4359 (and (> (- beg (point-min)) 3)
4360 (string= (buffer-substring (- beg 2) beg) "\n\n"))))
4361 (forward-char 1)))
4363 (allout-annotate-hidden beg (setq end (point)))
4364 (unwind-protect
4365 (allout-unprotected (kill-region beg end))
4366 (if buffer-read-only
4367 ;; eg, during copy-as-kill.
4368 (allout-deannotate-hidden beg end)))
4370 (save-excursion
4371 (allout-renumber-to-depth depth))
4372 (run-hook-with-args 'allout-structure-deleted-hook depth (point))))
4373 ;;;_ > allout-copy-topic-as-kill ()
4374 (defun allout-copy-topic-as-kill ()
4375 "Like allout-kill-topic, but save to kill ring instead of deleting."
4376 (interactive)
4377 (let ((buffer-read-only t))
4378 (condition-case nil
4379 (allout-kill-topic)
4380 (buffer-read-only (message "Topic copied...")))))
4381 ;;;_ > allout-annotate-hidden (begin end)
4382 (defun allout-annotate-hidden (begin end)
4383 "Qualify text with properties to indicate exposure status."
4385 (let ((was-modified (buffer-modified-p))
4386 (buffer-read-only nil))
4387 (allout-deannotate-hidden begin end)
4388 (save-excursion
4389 (goto-char begin)
4390 (let (done next prev overlay)
4391 (while (not done)
4392 ;; at or advance to start of next hidden region:
4393 (if (not (allout-hidden-p))
4394 (setq next
4395 (max (1+ (point))
4396 (next-single-char-property-change (point)
4397 'invisible
4398 nil end))))
4399 (if (or (not next) (eq prev next))
4400 ;; still not at start of hidden area - must not be any left.
4401 (setq done t)
4402 (goto-char next)
4403 (setq prev next)
4404 (if (not (allout-hidden-p))
4405 ;; still not at start of hidden area.
4406 (setq done t)
4407 (setq overlay (allout-get-invisibility-overlay))
4408 (setq next (overlay-end overlay)
4409 prev next)
4410 ;; advance to end of this hidden area:
4411 (when next
4412 (goto-char next)
4413 (allout-unprotected
4414 (let ((buffer-undo-list t))
4415 (put-text-property (overlay-start overlay) next
4416 'allout-was-hidden t)))))))))
4417 (set-buffer-modified-p was-modified)))
4418 ;;;_ > allout-deannotate-hidden (begin end)
4419 (defun allout-deannotate-hidden (begin end)
4420 "Remove allout hidden-text annotation between BEGIN and END."
4422 (allout-unprotected
4423 (let ((inhibit-read-only t)
4424 (buffer-undo-list t))
4425 ;(remove-text-properties begin end '(allout-was-hidden t))
4427 ;;;_ > allout-hide-by-annotation (begin end)
4428 (defun allout-hide-by-annotation (begin end)
4429 "Translate text properties indicating exposure status into actual exposure."
4430 (save-excursion
4431 (goto-char begin)
4432 (let ((was-modified (buffer-modified-p))
4433 done next prev)
4434 (while (not done)
4435 ;; at or advance to start of next annotation:
4436 (if (not (get-text-property (point) 'allout-was-hidden))
4437 (setq next (next-single-char-property-change (point)
4438 'allout-was-hidden
4439 nil end)))
4440 (if (or (not next) (eq prev next))
4441 ;; no more or not advancing - must not be any left.
4442 (setq done t)
4443 (goto-char next)
4444 (setq prev next)
4445 (if (not (get-text-property (point) 'allout-was-hidden))
4446 ;; still not at start of annotation.
4447 (setq done t)
4448 ;; advance to just after end of this annotation:
4449 (setq next (next-single-char-property-change (point)
4450 'allout-was-hidden
4451 nil end))
4452 (overlay-put (make-overlay prev next)
4453 'category 'allout-exposure-category)
4454 (allout-deannotate-hidden prev next)
4455 (setq prev next)
4456 (if next (goto-char next)))))
4457 (set-buffer-modified-p was-modified))))
4458 ;;;_ > allout-yank-processing ()
4459 (defun allout-yank-processing (&optional arg)
4461 "Incidental allout-specific business to be done just after text yanks.
4463 Does depth adjustment of yanked topics, when:
4465 1 the stuff being yanked starts with a valid outline header prefix, and
4466 2 it is being yanked at the end of a line which consists of only a valid
4467 topic prefix.
4469 Also, adjusts numbering of subsequent siblings when appropriate.
4471 Depth adjustment alters the depth of all the topics being yanked
4472 the amount it takes to make the first topic have the depth of the
4473 header into which it's being yanked.
4475 The point is left in front of yanked, adjusted topics, rather than
4476 at the end (and vice-versa with the mark). Non-adjusted yanks,
4477 however, are left exactly like normal, non-allout-specific yanks."
4479 (interactive "*P")
4480 ; Get to beginning, leaving
4481 ; region around subject:
4482 (if (< (allout-mark-marker t) (point))
4483 (exchange-point-and-mark))
4484 (let* ((subj-beg (point))
4485 (into-bol (bolp))
4486 (subj-end (allout-mark-marker t))
4487 ;; 'resituate' if yanking an entire topic into topic header:
4488 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t))
4489 (allout-e-o-prefix-p))
4490 (looking-at allout-regexp)
4491 (allout-prefix-data)))
4492 ;; `rectify-numbering' if resituating (where several topics may
4493 ;; be resituating) or yanking a topic into a topic slot (bol):
4494 (rectify-numbering (or resituate
4495 (and into-bol (looking-at allout-regexp)))))
4496 (if resituate
4497 ;; Yanking a topic into the start of a topic - reconcile to fit:
4498 (let* ((inhibit-field-text-motion t)
4499 (prefix-len (if (not (match-end 1))
4501 (- (match-end 1) subj-beg)))
4502 (subj-depth allout-recent-depth)
4503 (prefix-bullet (allout-recent-bullet))
4504 (adjust-to-depth
4505 ;; Nil if adjustment unnecessary, otherwise depth to which
4506 ;; adjustment should be made:
4507 (save-excursion
4508 (and (goto-char subj-end)
4509 (eolp)
4510 (goto-char subj-beg)
4511 (and (looking-at allout-regexp)
4512 (progn
4513 (beginning-of-line)
4514 (not (= (point) subj-beg)))
4515 (looking-at allout-regexp)
4516 (allout-prefix-data))
4517 allout-recent-depth)))
4518 (more t))
4519 (setq rectify-numbering allout-numbered-bullet)
4520 (if adjust-to-depth
4521 ; Do the adjustment:
4522 (progn
4523 (save-restriction
4524 (narrow-to-region subj-beg subj-end)
4525 ; Trim off excessive blank
4526 ; line at end, if any:
4527 (goto-char (point-max))
4528 (if (looking-at "^$")
4529 (allout-unprotected (delete-char -1)))
4530 ; Work backwards, with each
4531 ; shallowest level,
4532 ; successively excluding the
4533 ; last processed topic from
4534 ; the narrow region:
4535 (while more
4536 (allout-back-to-current-heading)
4537 ; go as high as we can in each bunch:
4538 (while (allout-ascend t))
4539 (save-excursion
4540 (allout-unprotected
4541 (allout-rebullet-topic-grunt (- adjust-to-depth
4542 subj-depth)))
4543 (allout-depth))
4544 (if (setq more (not (bobp)))
4545 (progn (widen)
4546 (forward-char -1)
4547 (narrow-to-region subj-beg (point))))))
4548 ;; Preserve new bullet if it's a distinctive one, otherwise
4549 ;; use old one:
4550 (if (string-match (regexp-quote prefix-bullet)
4551 allout-distinctive-bullets-string)
4552 ; Delete from bullet of old to
4553 ; before bullet of new:
4554 (progn
4555 (beginning-of-line)
4556 (allout-unprotected
4557 (delete-region (point) subj-beg))
4558 (set-marker (allout-mark-marker t) subj-end)
4559 (goto-char subj-beg)
4560 (allout-end-of-prefix))
4561 ; Delete base subj prefix,
4562 ; leaving old one:
4563 (allout-unprotected
4564 (progn
4565 (delete-region (point) (+ (point)
4566 prefix-len
4567 (- adjust-to-depth
4568 subj-depth)))
4569 ; and delete residual subj
4570 ; prefix digits and space:
4571 (while (looking-at "[0-9]") (delete-char 1))
4572 (if (looking-at " ") (delete-char 1))))))
4573 (exchange-point-and-mark))))
4574 (if rectify-numbering
4575 (progn
4576 (save-excursion
4577 ; Give some preliminary feedback:
4578 (message "... reconciling numbers")
4579 ; ... and renumber, in case necessary:
4580 (goto-char subj-beg)
4581 (if (allout-goto-prefix-doublechecked)
4582 (allout-unprotected
4583 (allout-rebullet-heading nil ;;; solicit
4584 (allout-depth) ;;; depth
4585 nil ;;; number-control
4586 nil ;;; index
4587 t)))
4588 (message ""))))
4589 (if (or into-bol resituate)
4590 (allout-hide-by-annotation (point) (allout-mark-marker t))
4591 (allout-deannotate-hidden (allout-mark-marker t) (point)))
4592 (if (not resituate)
4593 (exchange-point-and-mark))
4594 (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end)))
4595 ;;;_ > allout-yank (&optional arg)
4596 (defun allout-yank (&optional arg)
4597 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4599 Non-topic yanks work no differently than normal yanks.
4601 If a topic is being yanked into a bare topic prefix, the depth of the
4602 yanked topic is adjusted to the depth of the topic prefix.
4604 1 we're yanking in an `allout-mode' buffer
4605 2 the stuff being yanked starts with a valid outline header prefix, and
4606 3 it is being yanked at the end of a line which consists of only a valid
4607 topic prefix.
4609 If these conditions hold then the depth of the yanked topics are all
4610 adjusted the amount it takes to make the first one at the depth of the
4611 header into which it's being yanked.
4613 The point is left in front of yanked, adjusted topics, rather than
4614 at the end (and vice-versa with the mark). Non-adjusted yanks,
4615 however, (ones that don't qualify for adjustment) are handled
4616 exactly like normal yanks.
4618 Numbering of yanked topics, and the successive siblings at the depth
4619 into which they're being yanked, is adjusted.
4621 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4622 works with normal `yank' in non-outline buffers."
4624 (interactive "*P")
4625 (setq this-command 'yank)
4626 (allout-unprotected
4627 (yank arg))
4628 (if (allout-mode-p)
4629 (allout-yank-processing)))
4630 ;;;_ > allout-yank-pop (&optional arg)
4631 (defun allout-yank-pop (&optional arg)
4632 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4634 Adapts level of popped topics to level of fresh prefix.
4636 Note - prefix changes to distinctive bullets will stick, if followed
4637 by pops to non-distinctive yanks. Bug..."
4639 (interactive "*p")
4640 (setq this-command 'yank)
4641 (yank-pop arg)
4642 (if (allout-mode-p)
4643 (allout-yank-processing)))
4645 ;;;_ - Specialty bullet functions
4646 ;;;_ : File Cross references
4647 ;;;_ > allout-resolve-xref ()
4648 (defun allout-resolve-xref ()
4649 "Pop to file associated with current heading, if it has an xref bullet.
4651 \(Works according to setting of `allout-file-xref-bullet')."
4652 (interactive)
4653 (if (not allout-file-xref-bullet)
4654 (error
4655 "Outline cross references disabled - no `allout-file-xref-bullet'")
4656 (if (not (string= (allout-current-bullet) allout-file-xref-bullet))
4657 (error "Current heading lacks cross-reference bullet `%s'"
4658 allout-file-xref-bullet)
4659 (let ((inhibit-field-text-motion t)
4660 file-name)
4661 (save-excursion
4662 (let* ((text-start allout-recent-prefix-end)
4663 (heading-end (progn (end-of-line) (point))))
4664 (goto-char text-start)
4665 (setq file-name
4666 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t)
4667 (buffer-substring (match-beginning 1) (match-end 1))))))
4668 (setq file-name (expand-file-name file-name))
4669 (if (or (file-exists-p file-name)
4670 (if (file-writable-p file-name)
4671 (y-or-n-p (format "%s not there, create one? "
4672 file-name))
4673 (error "%s not found and can't be created" file-name)))
4674 (condition-case failure
4675 (find-file-other-window file-name)
4676 (error failure))
4677 (error "%s not found" file-name))
4683 ;;;_ #6 Exposure Control
4685 ;;;_ - Fundamental
4686 ;;;_ > allout-flag-region (from to flag)
4687 (defun allout-flag-region (from to flag)
4688 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4690 Exposure-change hook `allout-exposure-change-hook' is run with the same
4691 arguments as this function, after the exposure changes are made. (The old
4692 `allout-view-change-hook' is being deprecated, and eventually will not be
4693 invoked.)"
4695 ;; We use outline invisibility spec.
4696 (remove-overlays from to 'category 'allout-exposure-category)
4697 (when flag
4698 (let ((o (make-overlay from to)))
4699 (overlay-put o 'category 'allout-exposure-category)
4700 (when (featurep 'xemacs)
4701 (let ((props (symbol-plist 'allout-exposure-category)))
4702 (while props
4703 (overlay-put o (pop props) (pop props)))))))
4704 (run-hooks 'allout-view-change-hook)
4705 (run-hook-with-args 'allout-exposure-change-hook from to flag))
4706 ;;;_ > allout-flag-current-subtree (flag)
4707 (defun allout-flag-current-subtree (flag)
4708 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4710 (save-excursion
4711 (allout-back-to-current-heading)
4712 (let ((inhibit-field-text-motion t))
4713 (end-of-line))
4714 (allout-flag-region (point)
4715 ;; Exposing must not leave trailing blanks hidden,
4716 ;; but can leave them exposed when hiding, so we
4717 ;; can use flag's inverse as the
4718 ;; include-trailing-blank cue:
4719 (allout-end-of-current-subtree (not flag))
4720 flag)))
4722 ;;;_ - Topic-specific
4723 ;;;_ > allout-show-entry ()
4724 (defun allout-show-entry ()
4725 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4727 This is a way to give restricted peek at a concealed locality without the
4728 expense of exposing its context, but can leave the outline with aberrant
4729 exposure. `allout-show-offshoot' should be used after the peek to rectify
4730 the exposure."
4732 (interactive)
4733 (save-excursion
4734 (let (beg end)
4735 (allout-goto-prefix-doublechecked)
4736 (setq beg (if (allout-hidden-p) (1- (point)) (point)))
4737 (setq end (allout-pre-next-prefix))
4738 (allout-flag-region beg end nil)
4739 (list beg end))))
4740 ;;;_ > allout-show-children (&optional level strict)
4741 (defun allout-show-children (&optional level strict)
4743 "If point is visible, show all direct subheadings of this heading.
4745 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4747 Optional LEVEL specifies how many levels below the current level
4748 should be shown, or all levels if t. Default is 1.
4750 Optional STRICT means don't resort to -show-to-offshoot, no matter
4751 what. This is basically so -show-to-offshoot, which is called by
4752 this function, can employ the pure offspring-revealing capabilities of
4755 Returns point at end of subtree that was opened, if any. (May get a
4756 point of non-opened subtree?)"
4758 (interactive "p")
4759 (let ((start-point (point)))
4760 (if (and (not strict)
4761 (allout-hidden-p))
4763 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4764 ; expose it.
4765 ;; Then recurse, but with "strict" set so we don't
4766 ;; infinite regress:
4767 (allout-show-children level t))
4769 (save-excursion
4770 (allout-beginning-of-current-line)
4771 (save-restriction
4772 (let* (depth
4773 ;; translate the level spec for this routine to the ones
4774 ;; used by -chart-subtree and -chart-to-reveal:
4775 (chart-level (cond ((not level) 1)
4776 ((eq level t) nil)
4777 (t level)))
4778 (chart (allout-chart-subtree chart-level))
4779 (to-reveal (or (allout-chart-to-reveal chart chart-level)
4780 ;; interactive, show discontinuous children:
4781 (and chart
4782 (interactive-p)
4783 (save-excursion
4784 (allout-back-to-current-heading)
4785 (setq depth (allout-current-depth))
4786 (and (allout-next-heading)
4787 (> allout-recent-depth
4788 (1+ depth))))
4789 (message
4790 "Discontinuous offspring; use `%s %s'%s."
4791 (substitute-command-keys
4792 "\\[universal-argument]")
4793 (substitute-command-keys
4794 "\\[allout-shift-out]")
4795 " to elevate them.")
4796 (allout-chart-to-reveal
4797 chart (- allout-recent-depth depth))))))
4798 (goto-char start-point)
4799 (when (and strict (allout-hidden-p))
4800 ;; Concealed root would already have been taken care of,
4801 ;; unless strict was set.
4802 (allout-flag-region (point) (allout-snug-back) nil)
4803 (when allout-show-bodies
4804 (goto-char (car to-reveal))
4805 (allout-show-current-entry)))
4806 (while to-reveal
4807 (goto-char (car to-reveal))
4808 (allout-flag-region (save-excursion (allout-snug-back) (point))
4809 (progn (search-forward "\n" nil t)
4810 (1- (point)))
4811 nil)
4812 (when allout-show-bodies
4813 (goto-char (car to-reveal))
4814 (allout-show-current-entry))
4815 (setq to-reveal (cdr to-reveal)))))))
4816 ;; Compensate for `save-excursion's maintenance of point
4817 ;; within invisible text:
4818 (goto-char start-point)))
4819 ;;;_ > allout-show-to-offshoot ()
4820 (defun allout-show-to-offshoot ()
4821 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4823 Useful for coherently exposing to a random point in a hidden region."
4824 (interactive)
4825 (save-excursion
4826 (let ((inhibit-field-text-motion t)
4827 (orig-pt (point))
4828 (orig-pref (allout-goto-prefix-doublechecked))
4829 (last-at (point))
4830 (bag-it 0))
4831 (while (or (> bag-it 1) (allout-hidden-p))
4832 (while (allout-hidden-p)
4833 (move-beginning-of-line 1)
4834 (if (allout-hidden-p) (forward-char -1)))
4835 (if (= last-at (setq last-at (point)))
4836 ;; Oops, we're not making any progress! Show the current topic
4837 ;; completely, and try one more time here, if we haven't already.
4838 (progn (beginning-of-line)
4839 (allout-show-current-subtree)
4840 (goto-char orig-pt)
4841 (setq bag-it (1+ bag-it))
4842 (if (> bag-it 1)
4843 (error "allout-show-to-offshoot: %s"
4844 "Stumped by aberrant nesting.")))
4845 (if (> bag-it 0) (setq bag-it 0))
4846 (allout-show-children)
4847 (goto-char orig-pref)))
4848 (goto-char orig-pt)))
4849 (if (allout-hidden-p)
4850 (allout-show-entry)))
4851 ;;;_ > allout-hide-current-entry ()
4852 (defun allout-hide-current-entry ()
4853 "Hide the body directly following this heading."
4854 (interactive)
4855 (allout-back-to-current-heading)
4856 (save-excursion
4857 (let ((inhibit-field-text-motion t))
4858 (end-of-line))
4859 (allout-flag-region (point)
4860 (progn (allout-end-of-entry) (point))
4861 t)))
4862 ;;;_ > allout-show-current-entry (&optional arg)
4863 (defun allout-show-current-entry (&optional arg)
4864 "Show body following current heading, or hide entry with universal argument."
4866 (interactive "P")
4867 (if arg
4868 (allout-hide-current-entry)
4869 (save-excursion (allout-show-to-offshoot))
4870 (save-excursion
4871 (allout-flag-region (point)
4872 (progn (allout-end-of-entry t) (point))
4873 nil)
4875 ;;;_ > allout-show-current-subtree (&optional arg)
4876 (defun allout-show-current-subtree (&optional arg)
4877 "Show everything within the current topic. With a repeat-count,
4878 expose this topic and its siblings."
4879 (interactive "P")
4880 (save-excursion
4881 (if (<= (allout-current-depth) 0)
4882 ;; Outside any topics - try to get to the first:
4883 (if (not (allout-next-heading))
4884 (error "No topics")
4885 ;; got to first, outermost topic - set to expose it and siblings:
4886 (message "Above outermost topic - exposing all.")
4887 (allout-flag-region (point-min)(point-max) nil))
4888 (allout-beginning-of-current-line)
4889 (if (not arg)
4890 (allout-flag-current-subtree nil)
4891 (allout-beginning-of-level)
4892 (allout-expose-topic '(* :))))))
4893 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4894 (defun allout-current-topic-collapsed-p (&optional include-single-liners)
4895 "True if the currently visible containing topic is already collapsed.
4897 Single line topics intrinsically can be considered as being both
4898 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
4899 true, then single-line topics are considered to be collapsed. By
4900 default, they are treated as being uncollapsed."
4901 (save-excursion
4902 (and
4903 ;; Is the topic all on one line (allowing for trailing blank line)?
4904 (>= (progn (allout-back-to-current-heading)
4905 (move-end-of-line 1)
4906 (point))
4907 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
4909 (or include-single-liners
4910 (progn (backward-char 1) (allout-hidden-p))))))
4911 ;;;_ > allout-hide-current-subtree (&optional just-close)
4912 (defun allout-hide-current-subtree (&optional just-close)
4913 "Close the current topic, or containing topic if this one is already closed.
4915 If this topic is closed and it's a top level topic, close this topic
4916 and its siblings.
4918 If optional arg JUST-CLOSE is non-nil, do not close the parent or
4919 siblings, even if the target topic is already closed."
4921 (interactive)
4922 (let* ((from (point))
4923 (sibs-msg "Top-level topic already closed - closing siblings...")
4924 (current-exposed (not (allout-current-topic-collapsed-p t))))
4925 (cond (current-exposed (allout-flag-current-subtree t))
4926 (just-close nil)
4927 ((allout-ascend) (allout-hide-current-subtree))
4928 (t (goto-char 0)
4929 (message sibs-msg)
4930 (allout-goto-prefix-doublechecked)
4931 (allout-expose-topic '(0 :))
4932 (message (concat sibs-msg " Done."))))
4933 (goto-char from)))
4934 ;;;_ > allout-show-current-branches ()
4935 (defun allout-show-current-branches ()
4936 "Show all subheadings of this heading, but not their bodies."
4937 (interactive)
4938 (let ((inhibit-field-text-motion t))
4939 (beginning-of-line))
4940 (allout-show-children t))
4941 ;;;_ > allout-hide-current-leaves ()
4942 (defun allout-hide-current-leaves ()
4943 "Hide the bodies of the current topic and all its offspring."
4944 (interactive)
4945 (allout-back-to-current-heading)
4946 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
4947 (point))))
4949 ;;;_ - Region and beyond
4950 ;;;_ > allout-show-all ()
4951 (defun allout-show-all ()
4952 "Show all of the text in the buffer."
4953 (interactive)
4954 (message "Exposing entire buffer...")
4955 (allout-flag-region (point-min) (point-max) nil)
4956 (message "Exposing entire buffer... Done."))
4957 ;;;_ > allout-hide-bodies ()
4958 (defun allout-hide-bodies ()
4959 "Hide all of buffer except headings."
4960 (interactive)
4961 (allout-hide-region-body (point-min) (point-max)))
4962 ;;;_ > allout-hide-region-body (start end)
4963 (defun allout-hide-region-body (start end)
4964 "Hide all body lines in the region, but not headings."
4965 (save-excursion
4966 (save-restriction
4967 (narrow-to-region start end)
4968 (goto-char (point-min))
4969 (let ((inhibit-field-text-motion t))
4970 (while (not (eobp))
4971 (end-of-line)
4972 (allout-flag-region (point) (allout-end-of-entry) t)
4973 (if (not (eobp))
4974 (forward-char
4975 (if (looking-at "\n\n")
4976 2 1))))))))
4978 ;;;_ > allout-expose-topic (spec)
4979 (defun allout-expose-topic (spec)
4980 "Apply exposure specs to successive outline topic items.
4982 Use the more convenient frontend, `allout-new-exposure', if you don't
4983 need evaluation of the arguments, or even better, the `allout-layout'
4984 variable-keyed mode-activation/auto-exposure feature of allout outline
4985 mode. See the respective documentation strings for more details.
4987 Cursor is left at start position.
4989 SPEC is either a number or a list.
4991 Successive specs on a list are applied to successive sibling topics.
4993 A simple spec (either a number, one of a few symbols, or the null
4994 list) dictates the exposure for the corresponding topic.
4996 Non-null lists recursively designate exposure specs for respective
4997 subtopics of the current topic.
4999 The `:' repeat spec is used to specify exposure for any number of
5000 successive siblings, up to the trailing ones for which there are
5001 explicit specs following the `:'.
5003 Simple (numeric and null-list) specs are interpreted as follows:
5005 Numbers indicate the relative depth to open the corresponding topic.
5006 - negative numbers force the topic to be closed before opening to the
5007 absolute value of the number, so all siblings are open only to
5008 that level.
5009 - positive numbers open to the relative depth indicated by the
5010 number, but do not force already opened subtopics to be closed.
5011 - 0 means to close topic - hide all offspring.
5012 : - `repeat'
5013 apply prior element to all siblings at current level, *up to*
5014 those siblings that would be covered by specs following the `:'
5015 on the list. Ie, apply to all topics at level but the last
5016 ones. (Only first of multiple colons at same level is
5017 respected - subsequent ones are discarded.)
5018 * - completely opens the topic, including bodies.
5019 + - shows all the sub headers, but not the bodies
5020 - - exposes the body of the corresponding topic.
5022 Examples:
5023 \(allout-expose-topic '(-1 : 0))
5024 Close this and all following topics at current level, exposing
5025 only their immediate children, but close down the last topic
5026 at this current level completely.
5027 \(allout-expose-topic '(-1 () : 1 0))
5028 Close current topic so only the immediate subtopics are shown;
5029 show the children in the second to last topic, and completely
5030 close the last one.
5031 \(allout-expose-topic '(-2 : -1 *))
5032 Expose children and grandchildren of all topics at current
5033 level except the last two; expose children of the second to
5034 last and completely open the last one."
5036 (interactive "xExposure spec: ")
5037 (if (not (listp spec))
5039 (let ((depth (allout-depth))
5040 (max-pos 0)
5041 prev-elem curr-elem
5042 stay)
5043 (while spec
5044 (setq prev-elem curr-elem
5045 curr-elem (car spec)
5046 spec (cdr spec))
5047 (cond ; Do current element:
5048 ((null curr-elem) nil)
5049 ((symbolp curr-elem)
5050 (cond ((eq curr-elem '*) (allout-show-current-subtree)
5051 (if (> allout-recent-end-of-subtree max-pos)
5052 (setq max-pos allout-recent-end-of-subtree)))
5053 ((eq curr-elem '+)
5054 (if (not (allout-hidden-p))
5055 (save-excursion (allout-hide-current-subtree t)))
5056 (allout-show-current-branches)
5057 (if (> allout-recent-end-of-subtree max-pos)
5058 (setq max-pos allout-recent-end-of-subtree)))
5059 ((eq curr-elem '-) (allout-show-current-entry))
5060 ((eq curr-elem ':)
5061 (setq stay t)
5062 ;; Expand the `repeat' spec to an explicit version,
5063 ;; w.r.t. remaining siblings:
5064 (let ((residue ; = # of sibs not covered by remaining spec
5065 ;; Dang - could be nice to make use of the chart, sigh:
5066 (- (length (allout-chart-siblings))
5067 (length spec))))
5068 (if (< 0 residue)
5069 ;; Some residue - cover it with prev-elem:
5070 (setq spec (append (make-list residue prev-elem)
5071 spec)))))))
5072 ((numberp curr-elem)
5073 (if (and (>= 0 curr-elem) (not (allout-hidden-p)))
5074 (save-excursion (allout-hide-current-subtree t)
5075 (if (> 0 curr-elem)
5077 (if (> allout-recent-end-of-subtree max-pos)
5078 (setq max-pos
5079 allout-recent-end-of-subtree)))))
5080 (if (> (abs curr-elem) 0)
5081 (progn (allout-show-children (abs curr-elem))
5082 (if (> allout-recent-end-of-subtree max-pos)
5083 (setq max-pos allout-recent-end-of-subtree)))))
5084 ((listp curr-elem)
5085 (if (allout-descend-to-depth (1+ depth))
5086 (let ((got (allout-expose-topic curr-elem)))
5087 (if (and got (> got max-pos)) (setq max-pos got))))))
5088 (cond (stay (setq stay nil))
5089 ((listp (car spec)) nil)
5090 ((> max-pos (point))
5091 ;; Capitalize on max-pos state to get us nearer next sibling:
5092 (progn (goto-char (min (point-max) max-pos))
5093 (allout-next-heading)))
5094 ((allout-next-sibling depth))))
5095 max-pos)))
5096 ;;;_ > allout-old-expose-topic (spec &rest followers)
5097 (defun allout-old-expose-topic (spec &rest followers)
5099 "Deprecated. Use `allout-expose-topic' (with different schema
5100 format) instead.
5102 Dictate wholesale exposure scheme for current topic, according to SPEC.
5104 SPEC is either a number or a list. Optional successive args
5105 dictate exposure for subsequent siblings of current topic.
5107 A simple spec (either a number, a special symbol, or the null list)
5108 dictates the overall exposure for a topic. Non null lists are
5109 composite specs whose first element dictates the overall exposure for
5110 a topic, with the subsequent elements in the list interpreted as specs
5111 that dictate the exposure for the successive offspring of the topic.
5113 Simple (numeric and null-list) specs are interpreted as follows:
5115 - Numbers indicate the relative depth to open the corresponding topic:
5116 - negative numbers force the topic to be close before opening to the
5117 absolute value of the number.
5118 - positive numbers just open to the relative depth indicated by the number.
5119 - 0 just closes
5120 - `*' completely opens the topic, including bodies.
5121 - `+' shows all the sub headers, but not the bodies
5122 - `-' exposes the body and immediate offspring of the corresponding topic.
5124 If the spec is a list, the first element must be a number, which
5125 dictates the exposure depth of the topic as a whole. Subsequent
5126 elements of the list are nested SPECs, dictating the specific exposure
5127 for the corresponding offspring of the topic.
5129 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5131 (interactive "xExposure spec: ")
5132 (let ((inhibit-field-text-motion t)
5133 (depth (allout-current-depth))
5134 max-pos)
5135 (cond ((null spec) nil)
5136 ((symbolp spec)
5137 (if (eq spec '*) (allout-show-current-subtree))
5138 (if (eq spec '+) (allout-show-current-branches))
5139 (if (eq spec '-) (allout-show-current-entry)))
5140 ((numberp spec)
5141 (if (>= 0 spec)
5142 (save-excursion (allout-hide-current-subtree t)
5143 (end-of-line)
5144 (if (or (not max-pos)
5145 (> (point) max-pos))
5146 (setq max-pos (point)))
5147 (if (> 0 spec)
5148 (setq spec (* -1 spec)))))
5149 (if (> spec 0)
5150 (allout-show-children spec)))
5151 ((listp spec)
5152 ;(let ((got (allout-old-expose-topic (car spec))))
5153 ; (if (and got (or (not max-pos) (> got max-pos)))
5154 ; (setq max-pos got)))
5155 (let ((new-depth (+ (allout-current-depth) 1))
5156 got)
5157 (setq max-pos (allout-old-expose-topic (car spec)))
5158 (setq spec (cdr spec))
5159 (if (and spec
5160 (allout-descend-to-depth new-depth)
5161 (not (allout-hidden-p)))
5162 (progn (setq got (apply 'allout-old-expose-topic spec))
5163 (if (and got (or (not max-pos) (> got max-pos)))
5164 (setq max-pos got)))))))
5165 (while (and followers
5166 (progn (if (and max-pos (< (point) max-pos))
5167 (progn (goto-char max-pos)
5168 (setq max-pos nil)))
5169 (end-of-line)
5170 (allout-next-sibling depth)))
5171 (allout-old-expose-topic (car followers))
5172 (setq followers (cdr followers)))
5173 max-pos))
5174 ;;;_ > allout-new-exposure '()
5175 (defmacro allout-new-exposure (&rest spec)
5176 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5177 Some arguments that would need to be quoted in `allout-expose-topic'
5178 need not be quoted in `allout-new-exposure'.
5180 Cursor is left at start position.
5182 Use this instead of obsolete `allout-exposure'.
5184 Examples:
5185 \(allout-new-exposure (-1 () () () 1) 0)
5186 Close current topic at current level so only the immediate
5187 subtopics are shown, except also show the children of the
5188 third subtopic; and close the next topic at the current level.
5189 \(allout-new-exposure : -1 0)
5190 Close all topics at current level to expose only their
5191 immediate children, except for the last topic at the current
5192 level, in which even its immediate children are hidden.
5193 \(allout-new-exposure -2 : -1 *)
5194 Expose children and grandchildren of first topic at current
5195 level, and expose children of subsequent topics at current
5196 level *except* for the last, which should be opened completely."
5197 (list 'save-excursion
5198 '(if (not (or (allout-goto-prefix-doublechecked)
5199 (allout-next-heading)))
5200 (error "allout-new-exposure: Can't find any outline topics"))
5201 (list 'allout-expose-topic (list 'quote spec))))
5203 ;;;_ #7 Systematic outline presentation - copying, printing, flattening
5205 ;;;_ - Mapping and processing of topics
5206 ;;;_ ( See also Subtree Charting, in Navigation code.)
5207 ;;;_ > allout-stringify-flat-index (flat-index)
5208 (defun allout-stringify-flat-index (flat-index &optional context)
5209 "Convert list representing section/subsection/... to document string.
5211 Optional arg CONTEXT indicates interior levels to include."
5212 (let ((delim ".")
5213 result
5214 numstr
5215 (context-depth (or (and context 2) 1)))
5216 ;; Take care of the explicit context:
5217 (while (> context-depth 0)
5218 (setq numstr (int-to-string (car flat-index))
5219 flat-index (cdr flat-index)
5220 result (if flat-index
5221 (cons delim (cons numstr result))
5222 (cons numstr result))
5223 context-depth (if flat-index (1- context-depth) 0)))
5224 (setq delim " ")
5225 ;; Take care of the indentation:
5226 (if flat-index
5227 (progn
5228 (while flat-index
5229 (setq result
5230 (cons delim
5231 (cons (make-string
5232 (1+ (truncate (if (zerop (car flat-index))
5234 (log10 (car flat-index)))))
5236 result)))
5237 (setq flat-index (cdr flat-index)))
5238 ;; Dispose of single extra delim:
5239 (setq result (cdr result))))
5240 (apply 'concat result)))
5241 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5242 (defun allout-stringify-flat-index-plain (flat-index)
5243 "Convert list representing section/subsection/... to document string."
5244 (let ((delim ".")
5245 result)
5246 (while flat-index
5247 (setq result (cons (int-to-string (car flat-index))
5248 (if result
5249 (cons delim result))))
5250 (setq flat-index (cdr flat-index)))
5251 (apply 'concat result)))
5252 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5253 (defun allout-stringify-flat-index-indented (flat-index)
5254 "Convert list representing section/subsection/... to document string."
5255 (let ((delim ".")
5256 result
5257 numstr)
5258 ;; Take care of the explicit context:
5259 (setq numstr (int-to-string (car flat-index))
5260 flat-index (cdr flat-index)
5261 result (if flat-index
5262 (cons delim (cons numstr result))
5263 (cons numstr result)))
5264 (setq delim " ")
5265 ;; Take care of the indentation:
5266 (if flat-index
5267 (progn
5268 (while flat-index
5269 (setq result
5270 (cons delim
5271 (cons (make-string
5272 (1+ (truncate (if (zerop (car flat-index))
5274 (log10 (car flat-index)))))
5276 result)))
5277 (setq flat-index (cdr flat-index)))
5278 ;; Dispose of single extra delim:
5279 (setq result (cdr result))))
5280 (apply 'concat result)))
5281 ;;;_ > allout-listify-exposed (&optional start end format)
5282 (defun allout-listify-exposed (&optional start end format)
5284 "Produce a list representing exposed topics in current region.
5286 This list can then be used by `allout-process-exposed' to manipulate
5287 the subject region.
5289 Optional START and END indicate bounds of region.
5291 optional arg, FORMAT, designates an alternate presentation form for
5292 the prefix:
5294 list - Present prefix as numeric section.subsection..., starting with
5295 section indicated by the list, innermost nesting first.
5296 `indent' (symbol) - Convert header prefixes to all white space,
5297 except for distinctive bullets.
5299 The elements of the list produced are lists that represents a topic
5300 header and body. The elements of that list are:
5302 - a number representing the depth of the topic,
5303 - a string representing the header-prefix, including trailing whitespace and
5304 bullet.
5305 - a string representing the bullet character,
5306 - and a series of strings, each containing one line of the exposed
5307 portion of the topic entry."
5309 (interactive "r")
5310 (save-excursion
5311 (let*
5312 ((inhibit-field-text-motion t)
5313 ;; state vars:
5314 strings prefix result depth new-depth out gone-out bullet beg
5315 next done)
5317 (goto-char start)
5318 (beginning-of-line)
5319 ;; Goto initial topic, and register preceeding stuff, if any:
5320 (if (> (allout-goto-prefix-doublechecked) start)
5321 ;; First topic follows beginning point - register preliminary stuff:
5322 (setq result (list (list 0 "" nil
5323 (buffer-substring start (1- (point)))))))
5324 (while (and (not done)
5325 (not (eobp)) ; Loop until we've covered the region.
5326 (not (> (point) end)))
5327 (setq depth allout-recent-depth ; Current topics depth,
5328 bullet (allout-recent-bullet) ; ... bullet,
5329 prefix (allout-recent-prefix)
5330 beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
5331 (setq done ; The boundary for the current topic:
5332 (not (allout-next-visible-heading 1)))
5333 (setq new-depth allout-recent-depth)
5334 (setq gone-out out
5335 out (< new-depth depth))
5336 (beginning-of-line)
5337 (setq next (point))
5338 (goto-char beg)
5339 (setq strings nil)
5340 (while (> next (point)) ; Get all the exposed text in
5341 (setq strings
5342 (cons (buffer-substring
5344 ;To hidden text or end of line:
5345 (progn
5346 (end-of-line)
5347 (allout-back-to-visible-text)))
5348 strings))
5349 (when (< (point) next) ; Resume from after hid text, if any.
5350 (line-move 1)
5351 (beginning-of-line))
5352 (setq beg (point)))
5353 ;; Accumulate list for this topic:
5354 (setq strings (nreverse strings))
5355 (setq result
5356 (cons
5357 (if format
5358 (let ((special (if (string-match
5359 (regexp-quote bullet)
5360 allout-distinctive-bullets-string)
5361 bullet)))
5362 (cond ((listp format)
5363 (list depth
5364 (if allout-abbreviate-flattened-numbering
5365 (allout-stringify-flat-index format
5366 gone-out)
5367 (allout-stringify-flat-index-plain
5368 format))
5369 strings
5370 special))
5371 ((eq format 'indent)
5372 (if special
5373 (list depth
5374 (concat (make-string (1+ depth) ? )
5375 (substring prefix -1))
5376 strings)
5377 (list depth
5378 (make-string depth ? )
5379 strings)))
5380 (t (error "allout-listify-exposed: %s %s"
5381 "invalid format" format))))
5382 (list depth prefix strings))
5383 result))
5384 ;; Reasses format, if any:
5385 (if (and format (listp format))
5386 (cond ((= new-depth depth)
5387 (setq format (cons (1+ (car format))
5388 (cdr format))))
5389 ((> new-depth depth) ; descending - assume by 1:
5390 (setq format (cons 1 format)))
5392 ; Pop the residue:
5393 (while (< new-depth depth)
5394 (setq format (cdr format))
5395 (setq depth (1- depth)))
5396 ; And increment the current one:
5397 (setq format
5398 (cons (1+ (or (car format)
5399 -1))
5400 (cdr format)))))))
5401 ;; Put the list with first at front, to last at back:
5402 (nreverse result))))
5403 ;;;_ > my-region-active-p ()
5404 (defmacro my-region-active-p ()
5405 (if (fboundp 'region-active-p)
5406 '(region-active-p)
5407 'mark-active))
5408 ;;;_ > allout-process-exposed (&optional func from to frombuf
5409 ;;; tobuf format)
5410 (defun allout-process-exposed (&optional func from to frombuf tobuf
5411 format start-num)
5412 "Map function on exposed parts of current topic; results to another buffer.
5414 All args are options; default values itemized below.
5416 Apply FUNCTION to exposed portions FROM position TO position in buffer
5417 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5418 alternate presentation form:
5420 `flat' - Present prefix as numeric section.subsection..., starting with
5421 section indicated by the start-num, innermost nesting first.
5422 X`flat-indented' - Prefix is like `flat' for first topic at each
5423 X level, but subsequent topics have only leaf topic
5424 X number, padded with blanks to line up with first.
5425 `indent' (symbol) - Convert header prefixes to all white space,
5426 except for distinctive bullets.
5428 Defaults:
5429 FUNCTION: `allout-insert-listified'
5430 FROM: region start, if region active, else start of buffer
5431 TO: region end, if region active, else end of buffer
5432 FROMBUF: current buffer
5433 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5434 FORMAT: nil"
5436 ; Resolve arguments,
5437 ; defaulting if necessary:
5438 (if (not func) (setq func 'allout-insert-listified))
5439 (if (not (and from to))
5440 (if (my-region-active-p)
5441 (setq from (region-beginning) to (region-end))
5442 (setq from (point-min) to (point-max))))
5443 (if frombuf
5444 (if (not (bufferp frombuf))
5445 ;; Specified but not a buffer - get it:
5446 (let ((got (get-buffer frombuf)))
5447 (if (not got)
5448 (error (concat "allout-process-exposed: source buffer "
5449 frombuf
5450 " not found."))
5451 (setq frombuf got))))
5452 ;; not specified - default it:
5453 (setq frombuf (current-buffer)))
5454 (if tobuf
5455 (if (not (bufferp tobuf))
5456 (setq tobuf (get-buffer-create tobuf)))
5457 ;; not specified - default it:
5458 (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
5459 (if (listp format)
5460 (nreverse format))
5462 (let* ((listified
5463 (progn (set-buffer frombuf)
5464 (allout-listify-exposed from to format))))
5465 (set-buffer tobuf)
5466 (mapc func listified)
5467 (pop-to-buffer tobuf)))
5469 ;;;_ - Copy exposed
5470 ;;;_ > allout-insert-listified (listified)
5471 (defun allout-insert-listified (listified)
5472 "Insert contents of listified outline portion in current buffer.
5474 LISTIFIED is a list representing each topic header and body:
5476 \`(depth prefix text)'
5478 or \`(depth prefix text bullet-plus)'
5480 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5481 (setq listified (cdr listified))
5482 (let ((prefix (prog1
5483 (car listified)
5484 (setq listified (cdr listified))))
5485 (text (prog1
5486 (car listified)
5487 (setq listified (cdr listified))))
5488 (bullet-plus (car listified)))
5489 (insert prefix)
5490 (if bullet-plus (insert (concat " " bullet-plus)))
5491 (while text
5492 (insert (car text))
5493 (if (setq text (cdr text))
5494 (insert "\n")))
5495 (insert "\n")))
5496 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5497 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format)
5498 "Duplicate exposed portions of current outline to another buffer.
5500 Other buffer has current buffers name with \" exposed\" appended to it.
5502 With repeat count, copy the exposed parts of only the current topic.
5504 Optional second arg TOBUF is target buffer name.
5506 Optional third arg FORMAT, if non-nil, symbolically designates an
5507 alternate presentation format for the outline:
5509 `flat' - Convert topic header prefixes to numeric
5510 section.subsection... identifiers.
5511 `indent' - Convert header prefixes to all white space, except for
5512 distinctive bullets.
5513 `indent-flat' - The best of both - only the first of each level has
5514 the full path, the rest have only the section number
5515 of the leaf, preceded by the right amount of indentation."
5517 (interactive "P")
5518 (if (not tobuf)
5519 (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5520 (let* ((start-pt (point))
5521 (beg (if arg (allout-back-to-current-heading) (point-min)))
5522 (end (if arg (allout-end-of-current-subtree) (point-max)))
5523 (buf (current-buffer))
5524 (start-list ()))
5525 (if (eq format 'flat)
5526 (setq format (if arg (save-excursion
5527 (goto-char beg)
5528 (allout-topic-flat-index))
5529 '(1))))
5530 (save-excursion (set-buffer tobuf)(erase-buffer))
5531 (allout-process-exposed 'allout-insert-listified
5534 (current-buffer)
5535 tobuf
5536 format start-list)
5537 (goto-char (point-min))
5538 (pop-to-buffer buf)
5539 (goto-char start-pt)))
5540 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5541 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf)
5542 "Present numeric outline of outline's exposed portions in another buffer.
5544 The resulting outline is not compatible with outline mode - use
5545 `allout-copy-exposed-to-buffer' if you want that.
5547 Use `allout-indented-exposed-to-buffer' for indented presentation.
5549 With repeat count, copy the exposed portions of only current topic.
5551 Other buffer has current buffer's name with \" exposed\" appended to
5552 it, unless optional second arg TOBUF is specified, in which case it is
5553 used verbatim."
5554 (interactive "P")
5555 (allout-copy-exposed-to-buffer arg tobuf 'flat))
5556 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5557 (defun allout-indented-exposed-to-buffer (&optional arg tobuf)
5558 "Present indented outline of outline's exposed portions in another buffer.
5560 The resulting outline is not compatible with outline mode - use
5561 `allout-copy-exposed-to-buffer' if you want that.
5563 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5565 With repeat count, copy the exposed portions of only current topic.
5567 Other buffer has current buffer's name with \" exposed\" appended to
5568 it, unless optional second arg TOBUF is specified, in which case it is
5569 used verbatim."
5570 (interactive "P")
5571 (allout-copy-exposed-to-buffer arg tobuf 'indent))
5573 ;;;_ - LaTeX formatting
5574 ;;;_ > allout-latex-verb-quote (string &optional flow)
5575 (defun allout-latex-verb-quote (string &optional flow)
5576 "Return copy of STRING for literal reproduction across LaTeX processing.
5577 Expresses the original characters (including carriage returns) of the
5578 string across LaTeX processing."
5579 (mapconcat (function
5580 (lambda (char)
5581 (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
5582 (concat "\\char" (number-to-string char) "{}"))
5583 ((= char ?\n) "\\\\")
5584 (t (char-to-string char)))))
5585 string
5586 ""))
5587 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5588 (defun allout-latex-verbatim-quote-curr-line ()
5589 "Express line for exact (literal) representation across LaTeX processing.
5591 Adjust line contents so it is unaltered (from the original line)
5592 across LaTeX processing, within the context of a `verbatim'
5593 environment. Leaves point at the end of the line."
5594 (let ((inhibit-field-text-motion t))
5595 (beginning-of-line)
5596 (let ((beg (point))
5597 (end (progn (end-of-line)(point))))
5598 (goto-char beg)
5599 (while (re-search-forward "\\\\"
5600 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5601 end ; bounded by end-of-line
5602 1) ; no matches, move to end & return nil
5603 (goto-char (match-beginning 2))
5604 (insert "\\")
5605 (setq end (1+ end))
5606 (goto-char (1+ (match-end 2)))))))
5607 ;;;_ > allout-insert-latex-header (buffer)
5608 (defun allout-insert-latex-header (buffer)
5609 "Insert initial LaTeX commands at point in BUFFER."
5610 ;; Much of this is being derived from the stuff in appendix of E in
5611 ;; the TeXBook, pg 421.
5612 (set-buffer buffer)
5613 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5614 "report"))
5615 (page-numbering (if allout-number-pages
5616 "\\pagestyle{empty}\n"
5617 ""))
5618 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5619 allout-title-style))
5620 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5621 allout-label-style))
5622 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5623 allout-head-line-style))
5624 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5625 allout-body-line-style))
5626 (setlength (format "%s%s%s%s"
5627 "\\newlength{\\stepsize}\n"
5628 "\\setlength{\\stepsize}{"
5629 allout-indent
5630 "}\n"))
5631 (oneheadline (format "%s%s%s%s%s%s%s"
5632 "\\newcommand{\\OneHeadLine}[3]{%\n"
5633 "\\noindent%\n"
5634 "\\hspace*{#2\\stepsize}%\n"
5635 "\\labelcmd{#1}\\hspace*{.2cm}"
5636 "\\headlinecmd{#3}\\\\["
5637 allout-line-skip
5638 "]\n}\n"))
5639 (onebodyline (format "%s%s%s%s%s%s"
5640 "\\newcommand{\\OneBodyLine}[2]{%\n"
5641 "\\noindent%\n"
5642 "\\hspace*{#1\\stepsize}%\n"
5643 "\\bodylinecmd{#2}\\\\["
5644 allout-line-skip
5645 "]\n}\n"))
5646 (begindoc "\\begin{document}\n\\begin{center}\n")
5647 (title (format "%s%s%s%s"
5648 "\\titlecmd{"
5649 (allout-latex-verb-quote (if allout-title
5650 (condition-case nil
5651 (eval allout-title)
5652 (error "<unnamed buffer>"))
5653 "Unnamed Outline"))
5654 "}\n"
5655 "\\end{center}\n\n"))
5656 (hsize "\\hsize = 7.5 true in\n")
5657 (hoffset "\\hoffset = -1.5 true in\n")
5658 (vspace "\\vspace{.1cm}\n\n"))
5659 (insert (concat doc-style
5660 page-numbering
5661 titlecmd
5662 labelcmd
5663 headlinecmd
5664 bodylinecmd
5665 setlength
5666 oneheadline
5667 onebodyline
5668 begindoc
5669 title
5670 hsize
5671 hoffset
5672 vspace)
5674 ;;;_ > allout-insert-latex-trailer (buffer)
5675 (defun allout-insert-latex-trailer (buffer)
5676 "Insert concluding LaTeX commands at point in BUFFER."
5677 (set-buffer buffer)
5678 (insert "\n\\end{document}\n"))
5679 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5680 (defun allout-latexify-one-item (depth prefix bullet text)
5681 "Insert LaTeX commands for formatting one outline item.
5683 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5684 BULLET string, and a list of TEXT strings for the body."
5685 (let* ((head-line (if text (car text)))
5686 (body-lines (cdr text))
5687 (curr-line)
5688 body-content bop)
5689 ; Do the head line:
5690 (insert (concat "\\OneHeadLine{\\verb\1 "
5691 (allout-latex-verb-quote bullet)
5692 "\1}{"
5693 depth
5694 "}{\\verb\1 "
5695 (if head-line
5696 (allout-latex-verb-quote head-line)
5698 "\1}\n"))
5699 (if (not body-lines)
5701 ;;(insert "\\beginlines\n")
5702 (insert "\\begin{verbatim}\n")
5703 (while body-lines
5704 (setq curr-line (car body-lines))
5705 (if (and (not body-content)
5706 (not (string-match "^\\s-*$" curr-line)))
5707 (setq body-content t))
5708 ; Mangle any occurrences of
5709 ; "\end{verbatim}" in text,
5710 ; it's special:
5711 (if (and body-content
5712 (setq bop (string-match "\\end{verbatim}" curr-line)))
5713 (setq curr-line (concat (substring curr-line 0 bop)
5715 (substring curr-line bop))))
5716 ;;(insert "|" (car body-lines) "|")
5717 (insert curr-line)
5718 (allout-latex-verbatim-quote-curr-line)
5719 (insert "\n")
5720 (setq body-lines (cdr body-lines)))
5721 (if body-content
5722 (setq body-content nil)
5723 (forward-char -1)
5724 (insert "\\ ")
5725 (forward-char 1))
5726 ;;(insert "\\endlines\n")
5727 (insert "\\end{verbatim}\n")
5729 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5730 (defun allout-latexify-exposed (arg &optional tobuf)
5731 "Format current topics exposed portions to TOBUF for LaTeX processing.
5732 TOBUF defaults to a buffer named the same as the current buffer, but
5733 with \"*\" prepended and \" latex-formed*\" appended.
5735 With repeat count, copy the exposed portions of entire buffer."
5737 (interactive "P")
5738 (if (not tobuf)
5739 (setq tobuf
5740 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5741 (let* ((start-pt (point))
5742 (beg (if arg (point-min) (allout-back-to-current-heading)))
5743 (end (if arg (point-max) (allout-end-of-current-subtree)))
5744 (buf (current-buffer)))
5745 (set-buffer tobuf)
5746 (erase-buffer)
5747 (allout-insert-latex-header tobuf)
5748 (goto-char (point-max))
5749 (allout-process-exposed 'allout-latexify-one-item
5753 tobuf)
5754 (goto-char (point-max))
5755 (allout-insert-latex-trailer tobuf)
5756 (goto-char (point-min))
5757 (pop-to-buffer buf)
5758 (goto-char start-pt)))
5760 ;;;_ #8 Encryption
5761 ;;;_ > allout-toggle-current-subtree-encryption (&optional fetch-pass)
5762 (defun allout-toggle-current-subtree-encryption (&optional fetch-pass)
5763 "Encrypt clear or decrypt encoded text of visibly-containing topic's contents.
5765 Optional FETCH-PASS universal argument provokes key-pair encryption with
5766 single universal argument. With doubled universal argument (value = 16),
5767 it forces prompting for the passphrase regardless of availability from the
5768 passphrase cache. With no universal argument, the appropriate passphrase
5769 is obtained from the cache, if available, else from the user.
5771 Only GnuPG encryption is supported.
5773 \*NOTE WELL* that the encrypted text must be ascii-armored. For gnupg
5774 encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file.
5776 Both symmetric-key and key-pair encryption is implemented. Symmetric is
5777 the default, use a single (x4) universal argument for keypair mode.
5779 Encrypted topic's bullet is set to a `~' to signal that the contents of the
5780 topic (body and subtopics, but not heading) is pending encryption or
5781 encrypted. `*' asterisk immediately after the bullet signals that the body
5782 is encrypted, its' absence means the topic is meant to be encrypted but is
5783 not. When a file with topics pending encryption is saved, topics pending
5784 encryption are encrypted. See allout-encrypt-unencrypted-on-saves for
5785 auto-encryption specifics.
5787 \*NOTE WELL* that automatic encryption that happens during saves will
5788 default to symmetric encryption - you must deliberately (re)encrypt key-pair
5789 encrypted topics if you want them to continue to use the key-pair cipher.
5791 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5792 encrypted. If you want to encrypt the contents of a top-level topic, use
5793 \\[allout-shift-in] to increase its depth.
5795 Passphrase Caching
5797 The encryption passphrase is solicited if not currently available in the
5798 passphrase cache from a recent encryption action.
5800 The solicited passphrase is retained for reuse in a cache, if enabled. See
5801 `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry' for details.
5803 Symmetric Passphrase Hinting and Verification
5805 If the file previously had no associated passphrase, or had a different
5806 passphrase than specified, the user is prompted to repeat the new one for
5807 corroboration. A random string encrypted by the new passphrase is set on
5808 the buffer-specific variable `allout-passphrase-verifier-string', for
5809 confirmation of the passphrase when next obtained, before encrypting or
5810 decrypting anything with it. This helps avoid mistakenly shifting between
5811 keys.
5813 If allout customization var `allout-passphrase-verifier-handling' is
5814 non-nil, an entry for `allout-passphrase-verifier-string' and its value is
5815 added to an Emacs 'local variables' section at the end of the file, which
5816 is created if necessary. That setting is for retention of the passphrase
5817 verifier across Emacs sessions.
5819 Similarly, `allout-passphrase-hint-string' stores a user-provided reminder
5820 about their passphrase, and `allout-passphrase-hint-handling' specifies
5821 when the hint is presented, or if passphrase hints are disabled. If
5822 enabled (see the `allout-passphrase-hint-handling' docstring for details),
5823 the hint string is stored in the local-variables section of the file, and
5824 solicited whenever the passphrase is changed."
5825 (interactive "P")
5826 (save-excursion
5827 (allout-back-to-current-heading)
5828 (allout-toggle-subtree-encryption fetch-pass)
5831 ;;;_ > allout-toggle-subtree-encryption (&optional fetch-pass)
5832 (defun allout-toggle-subtree-encryption (&optional fetch-pass)
5833 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5835 Optional FETCH-PASS universal argument provokes key-pair encryption with
5836 single universal argument. With doubled universal argument (value = 16),
5837 it forces prompting for the passphrase regardless of availability from the
5838 passphrase cache. With no universal argument, the appropriate passphrase
5839 is obtained from the cache, if available, else from the user.
5841 Currently only GnuPG encryption is supported, and integration
5842 with gpg-agent is not yet implemented.
5844 \**NOTE WELL** that the encrypted text must be ascii-armored. For gnupg
5845 encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file.
5847 See `allout-toggle-current-subtree-encryption' for more details."
5849 (interactive "P")
5850 (save-excursion
5851 (allout-end-of-prefix t)
5853 (if (= allout-recent-depth 1)
5854 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5855 " shift it in to make it encryptable")))
5857 (let* ((allout-buffer (current-buffer))
5858 ;; Assess location:
5859 (bullet-pos allout-recent-prefix-beginning)
5860 (after-bullet-pos (point))
5861 (was-encrypted
5862 (progn (if (= (point-max) after-bullet-pos)
5863 (error "no body to encrypt"))
5864 (allout-encrypted-topic-p)))
5865 (was-collapsed (if (not (search-forward "\n" nil t))
5867 (backward-char 1)
5868 (allout-hidden-p)))
5869 (subtree-beg (1+ (point)))
5870 (subtree-end (allout-end-of-subtree))
5871 (subject-text (buffer-substring-no-properties subtree-beg
5872 subtree-end))
5873 (subtree-end-char (char-after (1- subtree-end)))
5874 (subtree-trailing-char (char-after subtree-end))
5875 ;; kluge - result-text needs to be nil, but we also want to
5876 ;; check for the error condition
5877 (result-text (if (or (string= "" subject-text)
5878 (string= "\n" subject-text))
5879 (error "No topic contents to %scrypt"
5880 (if was-encrypted "de" "en"))
5881 nil))
5882 ;; Assess key parameters:
5883 (key-info (or
5884 ;; detect the type by which it is already encrypted
5885 (and was-encrypted
5886 (allout-encrypted-key-info subject-text))
5887 (and (member fetch-pass '(4 (4)))
5888 '(keypair nil))
5889 '(symmetric nil)))
5890 (for-key-type (car key-info))
5891 (for-key-identity (cadr key-info))
5892 (fetch-pass (and fetch-pass (member fetch-pass '(16 (16)))))
5893 (was-coding-system buffer-file-coding-system))
5895 (when (not was-encrypted)
5896 ;; ensure that non-ascii chars pending encryption are noticed before
5897 ;; they're encrypted, so the coding system is set to accomodate
5898 ;; them.
5899 (setq buffer-file-coding-system
5900 (select-safe-coding-system subtree-beg subtree-end))
5901 ;; if the coding system for the text being encrypted is different
5902 ;; than that prevailing, then there a real risk that the coding
5903 ;; system can't be noticed by emacs when the file is visited. to
5904 ;; mitigate that, offer to preserve the coding system using a file
5905 ;; local variable.
5906 (if (and (not (equal buffer-file-coding-system
5907 was-coding-system))
5908 (yes-or-no-p
5909 (format (concat "Register coding system %s as file local"
5910 " var? Necessary when only encrypted text"
5911 " is in that coding system. ")
5912 buffer-file-coding-system)))
5913 (allout-adjust-file-variable "buffer-file-coding-system"
5914 buffer-file-coding-system)))
5916 (setq result-text
5917 (allout-encrypt-string subject-text was-encrypted
5918 (current-buffer)
5919 for-key-type for-key-identity fetch-pass))
5921 ;; Replace the subtree with the processed product.
5922 (allout-unprotected
5923 (progn
5924 (set-buffer allout-buffer)
5925 (delete-region subtree-beg subtree-end)
5926 (insert result-text)
5927 (if was-collapsed
5928 (allout-flag-region (1- subtree-beg) (point) t))
5929 ;; adjust trailing-blank-lines to preserve topic spacing:
5930 (if (not was-encrypted)
5931 (if (and (= subtree-end-char ?\n)
5932 (= subtree-trailing-char ?\n))
5933 (insert subtree-trailing-char)))
5934 ;; Ensure that the item has an encrypted-entry bullet:
5935 (if (not (string= (buffer-substring-no-properties
5936 (1- after-bullet-pos) after-bullet-pos)
5937 allout-topic-encryption-bullet))
5938 (progn (goto-char (1- after-bullet-pos))
5939 (delete-char 1)
5940 (insert allout-topic-encryption-bullet)))
5941 (if was-encrypted
5942 ;; Remove the is-encrypted bullet qualifier:
5943 (progn (goto-char after-bullet-pos)
5944 (delete-char 1))
5945 ;; Add the is-encrypted bullet qualifier:
5946 (goto-char after-bullet-pos)
5947 (insert "*"))))
5948 (run-hook-with-args 'allout-structure-added-hook
5949 bullet-pos subtree-end))))
5950 ;;;_ > allout-encrypt-string (text decrypt allout-buffer key-type for-key
5951 ;;; fetch-pass &optional retried verifying
5952 ;;; passphrase)
5953 (defun allout-encrypt-string (text decrypt allout-buffer key-type for-key
5954 fetch-pass &optional retried rejected
5955 verifying passphrase)
5956 "Encrypt or decrypt message TEXT.
5958 If DECRYPT is true (default false), then decrypt instead of encrypt.
5960 FETCH-PASS (default false) forces fresh prompting for the passphrase.
5962 KEY-TYPE indicates whether to use a 'symmetric or 'keypair cipher.
5964 FOR-KEY is human readable identification of the first of the user's
5965 eligible secret keys a keypair decryption targets, or else nil.
5967 Optional RETRIED is for internal use - conveys the number of failed keys
5968 that have been solicited in sequence leading to this current call.
5970 Optional PASSPHRASE enables explicit delivery of the decryption passphrase,
5971 for verification purposes.
5973 Optional REJECTED is for internal use - conveys the number of
5974 rejections due to matches against
5975 `allout-encryption-ciphertext-rejection-regexps', as limited by
5976 `allout-encryption-ciphertext-rejection-ceiling'.
5978 Returns the resulting string, or nil if the transformation fails."
5980 (require 'pgg)
5982 (if (not (fboundp 'pgg-encrypt-symmetric))
5983 (error "Allout encryption depends on a newer version of pgg"))
5985 (let* ((scheme (upcase
5986 (format "%s" (or pgg-scheme pgg-default-scheme "GPG"))))
5987 (for-key (and (equal key-type 'keypair)
5988 (or for-key
5989 (split-string (read-string
5990 (format "%s message recipients: "
5991 scheme))
5992 "[ \t,]+"))))
5993 (target-prompt-id (if (equal key-type 'keypair)
5994 (if (= (length for-key) 1)
5995 (car for-key) for-key)
5996 (buffer-name allout-buffer)))
5997 (target-cache-id (format "%s-%s"
5998 key-type
5999 (if (equal key-type 'keypair)
6000 target-prompt-id
6001 (or (buffer-file-name allout-buffer)
6002 target-prompt-id))))
6003 (encoding (with-current-buffer allout-buffer
6004 buffer-file-coding-system))
6005 (multibyte (with-current-buffer allout-buffer
6006 enable-multibyte-characters))
6007 (strip-plaintext-regexps
6008 (if (not decrypt)
6009 (allout-get-configvar-values
6010 'allout-encryption-plaintext-sanitization-regexps)))
6011 (reject-ciphertext-regexps
6012 (if (not decrypt)
6013 (allout-get-configvar-values
6014 'allout-encryption-ciphertext-rejection-regexps)))
6015 (rejected (or rejected 0))
6016 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6017 rejected))
6018 result-text status
6021 (if (and fetch-pass (not passphrase))
6022 ;; Force later fetch by evicting passphrase from the cache.
6023 (pgg-remove-passphrase-from-cache target-cache-id t))
6025 (catch 'encryption-failed
6027 ;; We handle only symmetric-key passphrase caching.
6028 (if (and (not passphrase)
6029 (not (equal key-type 'keypair)))
6030 (setq passphrase (allout-obtain-passphrase for-key
6031 target-cache-id
6032 target-prompt-id
6033 key-type
6034 allout-buffer
6035 retried fetch-pass)))
6037 (with-temp-buffer
6039 (insert text)
6041 ;; convey the text characteristics of the original buffer:
6042 (set-buffer-multibyte multibyte)
6043 (when encoding
6044 (set-buffer-file-coding-system encoding)
6045 (if (not decrypt)
6046 (encode-coding-region (point-min) (point-max) encoding)))
6048 (when (and strip-plaintext-regexps (not decrypt))
6049 (dolist (re strip-plaintext-regexps)
6050 (let ((re (if (listp re) (car re) re))
6051 (replacement (if (listp re) (cadr re) "")))
6052 (goto-char (point-min))
6053 (while (re-search-forward re nil t)
6054 (replace-match replacement nil nil)))))
6056 (cond
6058 ;; symmetric:
6059 ((equal key-type 'symmetric)
6060 (setq status
6061 (if decrypt
6063 (pgg-decrypt (point-min) (point-max) passphrase)
6065 (pgg-encrypt-symmetric (point-min) (point-max)
6066 passphrase)))
6068 (if status
6069 (pgg-situate-output (point-min) (point-max))
6070 ;; failed - handle passphrase caching
6071 (if verifying
6072 (throw 'encryption-failed nil)
6073 (pgg-remove-passphrase-from-cache target-cache-id t)
6074 (error "Symmetric-cipher %scryption failed - %s"
6075 (if decrypt "de" "en")
6076 "try again with different passphrase."))))
6078 ;; encrypt 'keypair:
6079 ((not decrypt)
6081 (setq status
6083 (pgg-encrypt for-key
6084 nil (point-min) (point-max) passphrase))
6086 (if status
6087 (pgg-situate-output (point-min) (point-max))
6088 (error (pgg-remove-passphrase-from-cache target-cache-id t)
6089 (error "encryption failed"))))
6091 ;; decrypt 'keypair:
6094 (setq status
6095 (pgg-decrypt (point-min) (point-max) passphrase))
6097 (if status
6098 (pgg-situate-output (point-min) (point-max))
6099 (error (pgg-remove-passphrase-from-cache target-cache-id t)
6100 (error "decryption failed")))))
6102 (setq result-text
6103 (buffer-substring-no-properties
6104 1 (- (point-max) (if decrypt 0 1))))
6107 ;; validate result - non-empty
6108 (cond ((not result-text)
6109 (if verifying
6111 ;; transform was fruitless, retry w/new passphrase.
6112 (pgg-remove-passphrase-from-cache target-cache-id t)
6113 (allout-encrypt-string text decrypt allout-buffer
6114 key-type for-key nil
6115 (if retried (1+ retried) 1)
6116 rejected verifying nil)))
6118 ;; Retry (within limit) if ciphertext contains rejections:
6119 ((and (not decrypt)
6120 ;; Check for disqualification of this ciphertext:
6121 (let ((regexps reject-ciphertext-regexps)
6122 reject-it)
6123 (while (and regexps (not reject-it))
6124 (setq reject-it (string-match (car regexps)
6125 result-text))
6126 (pop regexps))
6127 reject-it))
6128 (setq rejections-left (1- rejections-left))
6129 (if (<= rejections-left 0)
6130 (error (concat "Ciphertext rejected too many times"
6131 " (%s), per `%s'")
6132 allout-encryption-ciphertext-rejection-ceiling
6133 'allout-encryption-ciphertext-rejection-regexps)
6134 (allout-encrypt-string text decrypt allout-buffer
6135 key-type for-key nil
6136 retried (1+ rejected)
6137 verifying passphrase)))
6138 ;; Barf if encryption yields extraordinary control chars:
6139 ((and (not decrypt)
6140 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6141 result-text))
6142 (error (concat "Encryption produced non-armored text, which"
6143 "conflicts with allout mode - reconfigure!")))
6145 ;; valid result and just verifying or non-symmetric:
6146 ((or verifying (not (equal key-type 'symmetric)))
6147 (if (or verifying decrypt)
6148 (pgg-add-passphrase-to-cache target-cache-id
6149 passphrase t))
6150 result-text)
6152 ;; valid result and regular symmetric - "register"
6153 ;; passphrase with mnemonic aids/cache.
6155 (set-buffer allout-buffer)
6156 (if passphrase
6157 (pgg-add-passphrase-to-cache target-cache-id
6158 passphrase t))
6159 (allout-update-passphrase-mnemonic-aids for-key passphrase
6160 allout-buffer)
6161 result-text)
6166 ;;;_ > allout-obtain-passphrase (for-key cache-id prompt-id key-type
6167 ;;; allout-buffer retried fetch-pass)
6168 (defun allout-obtain-passphrase (for-key cache-id prompt-id key-type
6169 allout-buffer retried fetch-pass)
6170 "Obtain passphrase for a key from the cache or else from the user.
6172 When obtaining from the user, symmetric-cipher passphrases are verified
6173 against either, if available and enabled, a random string that was
6174 encrypted against the passphrase, or else against repeated entry by the
6175 user for corroboration.
6177 FOR-KEY is the key for which the passphrase is being obtained.
6179 CACHE-ID is the cache id of the key for the passphrase.
6181 PROMPT-ID is the id for use when prompting the user.
6183 KEY-TYPE is either 'symmetric or 'keypair.
6185 ALLOUT-BUFFER is the buffer containing the entry being en/decrypted.
6187 RETRIED is the number of this attempt to obtain this passphrase.
6189 FETCH-PASS causes the passphrase to be solicited from the user, regardless
6190 of the availability of a cached copy."
6192 (if (not (equal key-type 'symmetric))
6193 ;; do regular passphrase read on non-symmetric passphrase:
6194 (pgg-read-passphrase (format "%s passphrase%s: "
6195 (upcase (format "%s" (or pgg-scheme
6196 pgg-default-scheme
6197 "GPG")))
6198 (if prompt-id
6199 (format " for %s" prompt-id)
6200 ""))
6201 cache-id t)
6203 ;; Symmetric hereon:
6205 (save-excursion
6206 (set-buffer allout-buffer)
6207 (let* ((hint (if (and (not (string= allout-passphrase-hint-string ""))
6208 (or (equal allout-passphrase-hint-handling 'always)
6209 (and (equal allout-passphrase-hint-handling
6210 'needed)
6211 retried)))
6212 (format " [%s]" allout-passphrase-hint-string)
6213 ""))
6214 (retry-message (if retried (format " (%s retry)" retried) ""))
6215 (prompt-sans-hint (format "'%s' symmetric passphrase%s: "
6216 prompt-id retry-message))
6217 (full-prompt (format "'%s' symmetric passphrase%s%s: "
6218 prompt-id hint retry-message))
6219 (prompt full-prompt)
6220 (verifier-string (allout-get-encryption-passphrase-verifier))
6222 (cached (and (not fetch-pass)
6223 (pgg-read-passphrase-from-cache cache-id t)))
6224 (got-pass (or cached
6225 (pgg-read-passphrase full-prompt cache-id t)))
6226 confirmation)
6228 (if (not got-pass)
6231 ;; Duplicate our handle on the passphrase so it's not clobbered by
6232 ;; deactivate-passwd memory clearing:
6233 (setq got-pass (copy-sequence got-pass))
6235 (cond (verifier-string
6236 (save-window-excursion
6237 (if (allout-encrypt-string verifier-string 'decrypt
6238 allout-buffer 'symmetric
6239 for-key nil 0 0 'verifying
6240 (copy-sequence got-pass))
6241 (setq confirmation (format "%s" got-pass))))
6243 (if (and (not confirmation)
6244 (if (yes-or-no-p
6245 (concat "Passphrase differs from established"
6246 " - use new one instead? "))
6247 ;; deactivate password for subsequent
6248 ;; confirmation:
6249 (progn
6250 (pgg-remove-passphrase-from-cache cache-id t)
6251 (setq prompt prompt-sans-hint)
6252 nil)
6254 (progn (pgg-remove-passphrase-from-cache cache-id t)
6255 (error "Wrong passphrase."))))
6256 ;; No verifier string - force confirmation by repetition of
6257 ;; (new) passphrase:
6258 ((or fetch-pass (not cached))
6259 (pgg-remove-passphrase-from-cache cache-id t))))
6260 ;; confirmation vs new input - doing pgg-read-passphrase will do the
6261 ;; right thing, in either case:
6262 (if (not confirmation)
6263 (setq confirmation
6264 (pgg-read-passphrase (concat prompt
6265 " ... confirm spelling: ")
6266 cache-id t)))
6267 (prog1
6268 (if (equal got-pass confirmation)
6269 confirmation
6270 (if (yes-or-no-p (concat "spelling of original and"
6271 " confirmation differ - retry? "))
6272 (progn (setq retried (if retried (1+ retried) 1))
6273 (pgg-remove-passphrase-from-cache cache-id t)
6274 ;; recurse to this routine:
6275 (pgg-read-passphrase prompt-sans-hint cache-id t))
6276 (pgg-remove-passphrase-from-cache cache-id t)
6277 (error "Confirmation failed."))))))))
6278 ;;;_ > allout-encrypted-topic-p ()
6279 (defun allout-encrypted-topic-p ()
6280 "True if the current topic is encryptable and encrypted."
6281 (save-excursion
6282 (allout-end-of-prefix t)
6283 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6284 allout-topic-encryption-bullet)
6285 (looking-at "\\*"))
6288 ;;;_ > allout-encrypted-key-info (text)
6289 ;; XXX gpg-specific, alas
6290 (defun allout-encrypted-key-info (text)
6291 "Return a pair of the key type and identity of a recipient's secret key.
6293 The key type is one of 'symmetric or 'keypair.
6295 if 'keypair, and some of the user's secret keys are among those for which
6296 the message was encoded, return the identity of the first. otherwise,
6297 return nil for the second item of the pair.
6299 An error is raised if the text is not encrypted."
6300 (require 'pgg-parse)
6301 (save-excursion
6302 (with-temp-buffer
6303 (insert text)
6304 (let* ((parsed-armor (pgg-parse-armor-region (point-min) (point-max)))
6305 (type (if (pgg-gpg-symmetric-key-p parsed-armor)
6306 'symmetric
6307 'keypair))
6308 secret-keys first-secret-key for-key-owner)
6309 (if (equal type 'keypair)
6310 (setq secret-keys (pgg-gpg-lookup-all-secret-keys)
6311 first-secret-key (pgg-gpg-select-matching-key parsed-armor
6312 secret-keys)
6313 for-key-owner (and first-secret-key
6314 (pgg-gpg-lookup-key-owner
6315 first-secret-key))))
6316 (list type (pgg-gpg-key-id-from-key-owner for-key-owner))
6321 ;;;_ > allout-create-encryption-passphrase-verifier (passphrase)
6322 (defun allout-create-encryption-passphrase-verifier (passphrase)
6323 "Encrypt random message for later validation of symmetric key's passphrase."
6324 ;; use 20 random ascii characters, across the entire ascii range.
6325 (random t)
6326 (let ((spew (make-string 20 ?\0)))
6327 (dotimes (i (length spew))
6328 (aset spew i (1+ (random 254))))
6329 (allout-encrypt-string spew nil (current-buffer) 'symmetric
6330 nil nil 0 0 passphrase))
6332 ;;;_ > allout-update-passphrase-mnemonic-aids (for-key passphrase
6333 ;;; outline-buffer)
6334 (defun allout-update-passphrase-mnemonic-aids (for-key passphrase
6335 outline-buffer)
6336 "Update passphrase verifier and hint strings if necessary.
6338 See `allout-passphrase-verifier-string' and `allout-passphrase-hint-string'
6339 settings.
6341 PASSPHRASE is the passphrase being mnemonicized
6343 OUTLINE-BUFFER is the buffer of the outline being adjusted.
6345 These are used to help the user keep track of the passphrase they use for
6346 symmetric encryption in the file.
6348 Behavior is governed by `allout-passphrase-verifier-handling',
6349 `allout-passphrase-hint-handling', and also, controlling whether the values
6350 are preserved on Emacs local file variables,
6351 `allout-enable-file-variable-adjustment'."
6353 ;; If passphrase doesn't agree with current verifier:
6354 ;; - adjust the verifier
6355 ;; - if passphrase hint handling is enabled, adjust the passphrase hint
6356 ;; - if file var settings are enabled, adjust the file vars
6358 (let* ((new-verifier-needed (not (allout-verify-passphrase
6359 for-key passphrase outline-buffer)))
6360 (new-verifier-string
6361 (if new-verifier-needed
6362 ;; Collapse to a single line and enclose in string quotes:
6363 (subst-char-in-string
6364 ?\n ?\C-a (allout-create-encryption-passphrase-verifier
6365 passphrase))))
6366 new-hint)
6367 (when new-verifier-string
6368 ;; do the passphrase hint first, since it's interactive
6369 (when (and allout-passphrase-hint-handling
6370 (not (equal allout-passphrase-hint-handling 'disabled)))
6371 (setq new-hint
6372 (read-from-minibuffer "Passphrase hint to jog your memory: "
6373 allout-passphrase-hint-string))
6374 (when (not (string= new-hint allout-passphrase-hint-string))
6375 (setq allout-passphrase-hint-string new-hint)
6376 (allout-adjust-file-variable "allout-passphrase-hint-string"
6377 allout-passphrase-hint-string)))
6378 (when allout-passphrase-verifier-handling
6379 (setq allout-passphrase-verifier-string new-verifier-string)
6380 (allout-adjust-file-variable "allout-passphrase-verifier-string"
6381 allout-passphrase-verifier-string))
6385 ;;;_ > allout-get-encryption-passphrase-verifier ()
6386 (defun allout-get-encryption-passphrase-verifier ()
6387 "Return text of the encrypt passphrase verifier, unmassaged, or nil if none.
6389 Derived from value of `allout-passphrase-verifier-string'."
6391 (let ((verifier-string (and (boundp 'allout-passphrase-verifier-string)
6392 allout-passphrase-verifier-string)))
6393 (if verifier-string
6394 ;; Return it uncollapsed
6395 (subst-char-in-string ?\C-a ?\n verifier-string))
6398 ;;;_ > allout-verify-passphrase (key passphrase allout-buffer)
6399 (defun allout-verify-passphrase (key passphrase allout-buffer)
6400 "True if passphrase successfully decrypts verifier, nil otherwise.
6402 \"Otherwise\" includes absence of passphrase verifier."
6403 (save-excursion
6404 (set-buffer allout-buffer)
6405 (and (boundp 'allout-passphrase-verifier-string)
6406 allout-passphrase-verifier-string
6407 (allout-encrypt-string (allout-get-encryption-passphrase-verifier)
6408 'decrypt allout-buffer 'symmetric
6409 key nil 0 0 'verifying passphrase)
6410 t)))
6411 ;;;_ > allout-next-topic-pending-encryption (&optional except-mark)
6412 (defun allout-next-topic-pending-encryption (&optional except-mark)
6413 "Return the point of the next topic pending encryption, or nil if none.
6415 EXCEPT-MARK identifies a point whose containing topics should be excluded
6416 from encryption. This supports 'except-current mode of
6417 `allout-encrypt-unencrypted-on-saves'.
6419 Such a topic has the allout-topic-encryption-bullet without an
6420 immediately following '*' that would mark the topic as being encrypted. It
6421 must also have content."
6422 (let (done got content-beg)
6423 (while (not done)
6425 (if (not (re-search-forward
6426 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6427 (regexp-quote allout-header-prefix)
6428 (regexp-quote allout-topic-encryption-bullet))
6429 nil t))
6430 (setq got nil
6431 done t)
6432 (goto-char (setq got (match-beginning 0)))
6433 (if (looking-at "\n")
6434 (forward-char 1))
6435 (setq got (point)))
6437 (cond ((not got)
6438 (setq done t))
6440 ((not (search-forward "\n"))
6441 (setq got nil
6442 done t))
6444 ((eobp)
6445 (setq got nil
6446 done t))
6449 (setq content-beg (point))
6450 (backward-char 1)
6451 (allout-end-of-subtree)
6452 (if (or (<= (point) content-beg)
6453 (and except-mark
6454 (<= content-beg except-mark)
6455 (>= (point) except-mark)))
6456 ;; Continue looking
6457 (setq got nil)
6458 ;; Got it!
6459 (setq done t)))
6462 (if got
6463 (goto-char got))
6466 ;;;_ > allout-encrypt-decrypted (&optional except-mark)
6467 (defun allout-encrypt-decrypted (&optional except-mark)
6468 "Encrypt topics pending encryption except those containing exemption point.
6470 EXCEPT-MARK identifies a point whose containing topics should be excluded
6471 from encryption. This supports 'except-current mode of
6472 `allout-encrypt-unencrypted-on-saves'.
6474 If a topic that is currently being edited was encrypted, we return a list
6475 containing the location of the topic and the location of the cursor just
6476 before the topic was encrypted. This can be used, eg, to decrypt the topic
6477 and exactly resituate the cursor if this is being done as part of a file
6478 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6480 (interactive "p")
6481 (save-excursion
6482 (let* ((current-mark (point-marker))
6483 (current-mark-position (marker-position current-mark))
6484 was-modified
6485 bo-subtree
6486 editing-topic editing-point)
6487 (goto-char (point-min))
6488 (while (allout-next-topic-pending-encryption except-mark)
6489 (setq was-modified (buffer-modified-p))
6490 (when (save-excursion
6491 (and (boundp 'allout-encrypt-unencrypted-on-saves)
6492 allout-encrypt-unencrypted-on-saves
6493 (setq bo-subtree (re-search-forward "$"))
6494 (not (allout-hidden-p))
6495 (>= current-mark (point))
6496 (allout-end-of-current-subtree)
6497 (<= current-mark (point))))
6498 (setq editing-topic (point)
6499 ;; we had to wait for this 'til now so prior topics are
6500 ;; encrypted, any relevant text shifts are in place:
6501 editing-point (- current-mark-position
6502 (count-trailing-whitespace-region
6503 bo-subtree current-mark-position))))
6504 (allout-toggle-subtree-encryption)
6505 (if (not was-modified)
6506 (set-buffer-modified-p nil))
6508 (if (not was-modified)
6509 (set-buffer-modified-p nil))
6510 (if editing-topic (list editing-topic editing-point))
6515 ;;;_ #9 miscellaneous
6516 ;;;_ : Mode:
6517 ;;;_ > outlineify-sticky ()
6518 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6519 ;;;###autoload
6520 (defalias 'outlinify-sticky 'outlineify-sticky)
6521 ;;;###autoload
6522 (defun outlineify-sticky (&optional arg)
6523 "Activate outline mode and establish file var so it is started subsequently.
6525 See doc-string for `allout-layout' and `allout-init' for details on
6526 setup for auto-startup."
6528 (interactive "P")
6530 (allout-mode t)
6532 (save-excursion
6533 (goto-char (point-min))
6534 (if (allout-goto-prefix)
6536 (allout-open-topic 2)
6537 (insert (concat "Dummy outline topic header - see"
6538 "`allout-mode' docstring: `^Hm'."))
6539 (allout-adjust-file-variable
6540 "allout-layout" (or allout-layout '(-1 : 0))))))
6541 ;;;_ > allout-file-vars-section-data ()
6542 (defun allout-file-vars-section-data ()
6543 "Return data identifying the file-vars section, or nil if none.
6545 Returns list `(beginning-point prefix-string suffix-string)'."
6546 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6547 (let (beg prefix suffix)
6548 (save-excursion
6549 (goto-char (point-max))
6550 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
6551 (if (let ((case-fold-search t))
6552 (not (search-forward "Local Variables:" nil t)))
6554 (setq beg (- (point) 16))
6555 (setq suffix (buffer-substring-no-properties
6556 (point)
6557 (progn (if (search-forward "\n" nil t)
6558 (forward-char -1))
6559 (point))))
6560 (setq prefix (buffer-substring-no-properties
6561 (progn (if (search-backward "\n" nil t)
6562 (forward-char 1))
6563 (point))
6564 beg))
6565 (list beg prefix suffix))
6569 ;;;_ > allout-adjust-file-variable (varname value)
6570 (defun allout-adjust-file-variable (varname value)
6571 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6573 This activity is inhibited if either `enable-local-variables'
6574 `allout-enable-file-variable-adjustment' are nil.
6576 When enabled, an entry for the variable is created if not already present,
6577 or changed if established with a different value. The section for the file
6578 variables, itself, is created if not already present. When created, the
6579 section lines (including the section line) exist as second-level topics in
6580 a top-level topic at the end of the file.
6582 `enable-local-variables' must be true for any of this to happen."
6583 (if (not (and enable-local-variables
6584 allout-enable-file-variable-adjustment))
6586 (save-excursion
6587 (let ((inhibit-field-text-motion t)
6588 (section-data (allout-file-vars-section-data))
6589 beg prefix suffix)
6590 (if section-data
6591 (setq beg (car section-data)
6592 prefix (cadr section-data)
6593 suffix (car (cddr section-data)))
6594 ;; create the section
6595 (goto-char (point-max))
6596 (open-line 1)
6597 (allout-open-topic 0)
6598 (end-of-line)
6599 (insert "Local emacs vars.\n")
6600 (allout-open-topic 1)
6601 (setq beg (point)
6602 suffix ""
6603 prefix (buffer-substring-no-properties (progn
6604 (beginning-of-line)
6605 (point))
6606 beg))
6607 (goto-char beg)
6608 (insert "Local variables:\n")
6609 (allout-open-topic 0)
6610 (insert "End:\n")
6612 ;; look for existing entry or create one, leaving point for insertion
6613 ;; of new value:
6614 (goto-char beg)
6615 (allout-show-to-offshoot)
6616 (if (search-forward (concat "\n" prefix varname ":") nil t)
6617 (let* ((value-beg (point))
6618 (line-end (progn (if (search-forward "\n" nil t)
6619 (forward-char -1))
6620 (point)))
6621 (value-end (- line-end (length suffix))))
6622 (if (> value-end value-beg)
6623 (delete-region value-beg value-end)))
6624 (end-of-line)
6625 (open-line 1)
6626 (forward-line 1)
6627 (insert (concat prefix varname ":")))
6628 (insert (format " %S%s" value suffix))
6633 ;;;_ > allout-get-configvar-values (varname)
6634 (defun allout-get-configvar-values (configvar-name)
6635 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6637 The user is prompted for removal of symbols that are unbound, and they
6638 otherwise are ignored.
6640 CONFIGVAR-NAME should be the name of the configuration variable,
6641 not its value."
6643 (let ((configvar-value (symbol-value configvar-name))
6644 got)
6645 (dolist (sym configvar-value)
6646 (if (not (boundp sym))
6647 (if (yes-or-no-p (format "%s entry `%s' is unbound - remove it? "
6648 configvar-name sym))
6649 (delq sym (symbol-value configvar-name)))
6650 (push (symbol-value sym) got)))
6651 (reverse got)))
6652 ;;;_ : Topics:
6653 ;;;_ > allout-mark-topic ()
6654 (defun allout-mark-topic ()
6655 "Put the region around topic currently containing point."
6656 (interactive)
6657 (let ((inhibit-field-text-motion t))
6658 (beginning-of-line))
6659 (allout-goto-prefix-doublechecked)
6660 (push-mark (point))
6661 (allout-end-of-current-subtree)
6662 (exchange-point-and-mark))
6663 ;;;_ : UI:
6664 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6665 (defun solicit-char-in-string (prompt string &optional do-defaulting)
6666 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6668 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6670 (let ((new-prompt prompt)
6671 got)
6673 (while (not got)
6674 (message "%s" new-prompt)
6676 ;; We do our own reading here, so we can circumvent, eg, special
6677 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6678 (setq got
6679 (char-to-string (let ((cursor-in-echo-area nil)) (read-char))))
6681 (setq got
6682 (cond ((string-match (regexp-quote got) string) got)
6683 ((and do-defaulting (string= got "\r"))
6684 ;; Return empty string to default:
6686 ((string= got "\C-g") (signal 'quit nil))
6688 (setq new-prompt (concat prompt
6690 " ...pick from: "
6691 string
6692 ""))
6693 nil))))
6694 ;; got something out of loop - return it:
6695 got)
6697 ;;;_ : Strings:
6698 ;;;_ > regexp-sans-escapes (string)
6699 (defun regexp-sans-escapes (regexp &optional successive-backslashes)
6700 "Return a copy of REGEXP with all character escapes stripped out.
6702 Representations of actual backslashes - '\\\\\\\\' - are left as a
6703 single backslash.
6705 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6707 (if (string= regexp "")
6709 ;; Set successive-backslashes to number if current char is
6710 ;; backslash, or else to nil:
6711 (setq successive-backslashes
6712 (if (= (aref regexp 0) ?\\)
6713 (if successive-backslashes (1+ successive-backslashes) 1)
6714 nil))
6715 (if (or (not successive-backslashes) (= 2 successive-backslashes))
6716 ;; Include first char:
6717 (concat (substring regexp 0 1)
6718 (regexp-sans-escapes (substring regexp 1)))
6719 ;; Exclude first char, but maintain count:
6720 (regexp-sans-escapes (substring regexp 1) successive-backslashes))))
6721 ;;;_ > count-trailing-whitespace-region (beg end)
6722 (defun count-trailing-whitespace-region (beg end)
6723 "Return number of trailing whitespace chars between BEG and END.
6725 If BEG is bigger than END we return 0."
6726 (if (> beg end)
6728 (save-excursion
6729 (goto-char beg)
6730 (let ((count 0))
6731 (while (re-search-forward "[ ][ ]*$" end t)
6732 (goto-char (1+ (match-beginning 2)))
6733 (setq count (1+ count)))
6734 count))))
6735 ;;;_ > allout-format-quote (string)
6736 (defun allout-format-quote (string)
6737 "Return a copy of string with all \"%\" characters doubled."
6738 (apply 'concat
6739 (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char)))
6740 string)))
6741 ;;;_ : lists
6742 ;;;_ > allout-flatten (list)
6743 (defun allout-flatten (list)
6744 "Return a list of all atoms in list."
6745 ;; classic.
6746 (cond ((null list) nil)
6747 ((atom (car list)) (cons (car list) (allout-flatten (cdr list))))
6748 (t (append (allout-flatten (car list)) (allout-flatten (cdr list))))))
6749 ;;;_ : Compatability:
6750 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6751 (defun allout-mark-marker (&optional force buffer)
6752 "Accommodate the different signature for `mark-marker' across Emacsen.
6754 XEmacs takes two optional args, while mainline GNU Emacs does not,
6755 so pass them along when appropriate."
6756 (if (featurep 'xemacs)
6757 (apply 'mark-marker force buffer)
6758 (mark-marker)))
6759 ;;;_ > subst-char-in-string if necessary
6760 (if (not (fboundp 'subst-char-in-string))
6761 (defun subst-char-in-string (fromchar tochar string &optional inplace)
6762 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6763 Unless optional argument INPLACE is non-nil, return a new string."
6764 (let ((i (length string))
6765 (newstr (if inplace string (copy-sequence string))))
6766 (while (> i 0)
6767 (setq i (1- i))
6768 (if (eq (aref newstr i) fromchar)
6769 (aset newstr i tochar)))
6770 newstr)))
6771 ;;;_ > wholenump if necessary
6772 (if (not (fboundp 'wholenump))
6773 (defalias 'wholenump 'natnump))
6774 ;;;_ > remove-overlays if necessary
6775 (if (not (fboundp 'remove-overlays))
6776 (defun remove-overlays (&optional beg end name val)
6777 "Clear BEG and END of overlays whose property NAME has value VAL.
6778 Overlays might be moved and/or split.
6779 BEG and END default respectively to the beginning and end of buffer."
6780 (unless beg (setq beg (point-min)))
6781 (unless end (setq end (point-max)))
6782 (if (< end beg)
6783 (setq beg (prog1 end (setq end beg))))
6784 (save-excursion
6785 (dolist (o (overlays-in beg end))
6786 (when (eq (overlay-get o name) val)
6787 ;; Either push this overlay outside beg...end
6788 ;; or split it to exclude beg...end
6789 ;; or delete it entirely (if it is contained in beg...end).
6790 (if (< (overlay-start o) beg)
6791 (if (> (overlay-end o) end)
6792 (progn
6793 (move-overlay (copy-overlay o)
6794 (overlay-start o) beg)
6795 (move-overlay o end (overlay-end o)))
6796 (move-overlay o (overlay-start o) beg))
6797 (if (> (overlay-end o) end)
6798 (move-overlay o end (overlay-end o))
6799 (delete-overlay o)))))))
6801 ;;;_ > copy-overlay if necessary - xemacs ~ 21.4
6802 (if (not (fboundp 'copy-overlay))
6803 (defun copy-overlay (o)
6804 "Return a copy of overlay O."
6805 (let ((o1 (make-overlay (overlay-start o) (overlay-end o)
6806 ;; FIXME: there's no easy way to find the
6807 ;; insertion-type of the two markers.
6808 (overlay-buffer o)))
6809 (props (overlay-properties o)))
6810 (while props
6811 (overlay-put o1 (pop props) (pop props)))
6812 o1)))
6813 ;;;_ > add-to-invisibility-spec if necessary - xemacs ~ 21.4
6814 (if (not (fboundp 'add-to-invisibility-spec))
6815 (defun add-to-invisibility-spec (element)
6816 "Add ELEMENT to `buffer-invisibility-spec'.
6817 See documentation for `buffer-invisibility-spec' for the kind of elements
6818 that can be added."
6819 (if (eq buffer-invisibility-spec t)
6820 (setq buffer-invisibility-spec (list t)))
6821 (setq buffer-invisibility-spec
6822 (cons element buffer-invisibility-spec))))
6823 ;;;_ > remove-from-invisibility-spec if necessary - xemacs ~ 21.4
6824 (if (not (fboundp 'remove-from-invisibility-spec))
6825 (defun remove-from-invisibility-spec (element)
6826 "Remove ELEMENT from `buffer-invisibility-spec'."
6827 (if (consp buffer-invisibility-spec)
6828 (setq buffer-invisibility-spec (delete element
6829 buffer-invisibility-spec)))))
6830 ;;;_ > move-beginning-of-line if necessary - older emacs, xemacs
6831 (if (not (fboundp 'move-beginning-of-line))
6832 (defun move-beginning-of-line (arg)
6833 "Move point to beginning of current line as displayed.
6834 \(This disregards invisible newlines such as those
6835 which are part of the text that an image rests on.)
6837 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6838 If point reaches the beginning or end of buffer, it stops there.
6839 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6840 (interactive "p")
6841 (or arg (setq arg 1))
6842 (if (/= arg 1)
6843 (condition-case nil (line-move (1- arg)) (error nil)))
6845 ;; Move to beginning-of-line, ignoring fields and invisibles.
6846 (skip-chars-backward "^\n")
6847 (while (and (not (bobp)) (line-move-invisible-p (1- (point))))
6848 (goto-char (if (featurep 'xemacs)
6849 (previous-property-change (point))
6850 (previous-char-property-change (point))))
6851 (skip-chars-backward "^\n"))
6852 (vertical-motion 0))
6854 ;;;_ > move-end-of-line if necessary - older emacs, xemacs
6855 (if (not (fboundp 'move-end-of-line))
6856 (defun move-end-of-line (arg)
6857 "Move point to end of current line as displayed.
6858 \(This disregards invisible newlines such as those
6859 which are part of the text that an image rests on.)
6861 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6862 If point reaches the beginning or end of buffer, it stops there.
6863 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6864 (interactive "p")
6865 (or arg (setq arg 1))
6866 (let (done)
6867 (while (not done)
6868 (let ((newpos
6869 (save-excursion
6870 (let ((goal-column 0))
6871 (and (condition-case nil
6872 (or (line-move arg) t)
6873 (error nil))
6874 (not (bobp))
6875 (progn
6876 (while (and (not (bobp))
6877 (line-move-invisible-p (1- (point))))
6878 (goto-char
6879 (previous-char-property-change (point))))
6880 (backward-char 1)))
6881 (point)))))
6882 (goto-char newpos)
6883 (if (and (> (point) newpos)
6884 (eq (preceding-char) ?\n))
6885 (backward-char 1)
6886 (if (and (> (point) newpos) (not (eobp))
6887 (not (eq (following-char) ?\n)))
6888 ;; If we skipped something intangible
6889 ;; and now we're not really at eol,
6890 ;; keep going.
6891 (setq arg 1)
6892 (setq done t)))))))
6894 ;;;_ > line-move-invisible-p if necessary
6895 (if (not (fboundp 'line-move-invisible-p))
6896 (defun line-move-invisible-p (pos)
6897 "Return non-nil if the character after POS is currently invisible."
6898 (let ((prop
6899 (get-char-property pos 'invisible)))
6900 (if (eq buffer-invisibility-spec t)
6901 prop
6902 (or (memq prop buffer-invisibility-spec)
6903 (assq prop buffer-invisibility-spec))))))
6905 ;;;_ #10 Unfinished
6906 ;;;_ > allout-bullet-isearch (&optional bullet)
6907 (defun allout-bullet-isearch (&optional bullet)
6908 "Isearch (regexp) for topic with bullet BULLET."
6909 (interactive)
6910 (if (not bullet)
6911 (setq bullet (solicit-char-in-string
6912 "ISearch for topic with bullet: "
6913 (regexp-sans-escapes allout-bullets-string))))
6915 (let ((isearch-regexp t)
6916 (isearch-string (concat "^"
6917 allout-header-prefix
6918 "[ \t]*"
6919 bullet)))
6920 (isearch-repeat 'forward)
6921 (isearch-mode t)))
6923 ;;;_ #11 Unit tests - this should be last item before "Provide"
6924 ;;;_ > allout-run-unit-tests ()
6925 (defun allout-run-unit-tests ()
6926 "Run the various allout unit tests."
6927 (message "Running allout tests...")
6928 (allout-test-resumptions)
6929 (message "Running allout tests... Done.")
6930 (sit-for .5))
6931 ;;;_ : test resumptions:
6932 ;;;_ > allout-tests-obliterate-variable (name)
6933 (defun allout-tests-obliterate-variable (name)
6934 "Completely unbind variable with NAME."
6935 (if (local-variable-p name) (kill-local-variable name))
6936 (while (boundp name) (makunbound name)))
6937 ;;;_ > allout-test-resumptions ()
6938 (defvar allout-tests-globally-unbound nil
6939 "Fodder for allout resumptions tests - defvar just for byte compiler.")
6940 (defvar allout-tests-globally-true nil
6941 "Fodder for allout resumptions tests - defvar just just for byte compiler.")
6942 (defvar allout-tests-locally-true nil
6943 "Fodder for allout resumptions tests - defvar just for byte compiler.")
6944 (defun allout-test-resumptions ()
6945 "Exercise allout resumptions."
6946 ;; for each resumption case, we also test that the right local/global
6947 ;; scopes are affected during resumption effects:
6949 ;; ensure that previously unbound variables return to the unbound state.
6950 (with-temp-buffer
6951 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6952 (allout-add-resumptions '(allout-tests-globally-unbound t))
6953 (assert (not (default-boundp 'allout-tests-globally-unbound)))
6954 (assert (local-variable-p 'allout-tests-globally-unbound))
6955 (assert (boundp 'allout-tests-globally-unbound))
6956 (assert (equal allout-tests-globally-unbound t))
6957 (allout-do-resumptions)
6958 (assert (not (local-variable-p 'allout-tests-globally-unbound)))
6959 (assert (not (boundp 'allout-tests-globally-unbound))))
6961 ;; ensure that variable with prior global value is resumed
6962 (with-temp-buffer
6963 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6964 (setq allout-tests-globally-true t)
6965 (allout-add-resumptions '(allout-tests-globally-true nil))
6966 (assert (equal (default-value 'allout-tests-globally-true) t))
6967 (assert (local-variable-p 'allout-tests-globally-true))
6968 (assert (equal allout-tests-globally-true nil))
6969 (allout-do-resumptions)
6970 (assert (not (local-variable-p 'allout-tests-globally-true)))
6971 (assert (boundp 'allout-tests-globally-true))
6972 (assert (equal allout-tests-globally-true t)))
6974 ;; ensure that prior local value is resumed
6975 (with-temp-buffer
6976 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6977 (set (make-local-variable 'allout-tests-locally-true) t)
6978 (assert (not (default-boundp 'allout-tests-locally-true))
6979 nil (concat "Test setup mistake - variable supposed to"
6980 " not have global binding, but it does."))
6981 (assert (local-variable-p 'allout-tests-locally-true)
6982 nil (concat "Test setup mistake - variable supposed to have"
6983 " local binding, but it lacks one."))
6984 (allout-add-resumptions '(allout-tests-locally-true nil))
6985 (assert (not (default-boundp 'allout-tests-locally-true)))
6986 (assert (local-variable-p 'allout-tests-locally-true))
6987 (assert (equal allout-tests-locally-true nil))
6988 (allout-do-resumptions)
6989 (assert (boundp 'allout-tests-locally-true))
6990 (assert (local-variable-p 'allout-tests-locally-true))
6991 (assert (equal allout-tests-locally-true t))
6992 (assert (not (default-boundp 'allout-tests-locally-true))))
6994 ;; ensure that last of multiple resumptions holds, for various scopes.
6995 (with-temp-buffer
6996 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6997 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6998 (setq allout-tests-globally-true t)
6999 (allout-tests-obliterate-variable 'allout-tests-locally-true)
7000 (set (make-local-variable 'allout-tests-locally-true) t)
7001 (allout-add-resumptions '(allout-tests-globally-unbound t)
7002 '(allout-tests-globally-true nil)
7003 '(allout-tests-locally-true nil))
7004 (allout-add-resumptions '(allout-tests-globally-unbound 2)
7005 '(allout-tests-globally-true 3)
7006 '(allout-tests-locally-true 4))
7007 ;; reestablish many of the basic conditions are maintained after re-add:
7008 (assert (not (default-boundp 'allout-tests-globally-unbound)))
7009 (assert (local-variable-p 'allout-tests-globally-unbound))
7010 (assert (equal allout-tests-globally-unbound 2))
7011 (assert (default-boundp 'allout-tests-globally-true))
7012 (assert (local-variable-p 'allout-tests-globally-true))
7013 (assert (equal allout-tests-globally-true 3))
7014 (assert (not (default-boundp 'allout-tests-locally-true)))
7015 (assert (local-variable-p 'allout-tests-locally-true))
7016 (assert (equal allout-tests-locally-true 4))
7017 (allout-do-resumptions)
7018 (assert (not (local-variable-p 'allout-tests-globally-unbound)))
7019 (assert (not (boundp 'allout-tests-globally-unbound)))
7020 (assert (not (local-variable-p 'allout-tests-globally-true)))
7021 (assert (boundp 'allout-tests-globally-true))
7022 (assert (equal allout-tests-globally-true t))
7023 (assert (boundp 'allout-tests-locally-true))
7024 (assert (local-variable-p 'allout-tests-locally-true))
7025 (assert (equal allout-tests-locally-true t))
7026 (assert (not (default-boundp 'allout-tests-locally-true))))
7028 ;; ensure that deliberately unbinding registered variables doesn't foul things
7029 (with-temp-buffer
7030 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
7031 (allout-tests-obliterate-variable 'allout-tests-globally-true)
7032 (setq allout-tests-globally-true t)
7033 (allout-tests-obliterate-variable 'allout-tests-locally-true)
7034 (set (make-local-variable 'allout-tests-locally-true) t)
7035 (allout-add-resumptions '(allout-tests-globally-unbound t)
7036 '(allout-tests-globally-true nil)
7037 '(allout-tests-locally-true nil))
7038 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
7039 (allout-tests-obliterate-variable 'allout-tests-globally-true)
7040 (allout-tests-obliterate-variable 'allout-tests-locally-true)
7041 (allout-do-resumptions))
7043 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
7044 (when allout-run-unit-tests-on-load
7045 (allout-run-unit-tests))
7047 ;;;_ #12 Provide
7048 (provide 'allout)
7050 ;;;_* Local emacs vars.
7051 ;; The following `allout-layout' local variable setting:
7052 ;; - closes all topics from the first topic to just before the third-to-last,
7053 ;; - shows the children of the third to last (config vars)
7054 ;; - and the second to last (code section),
7055 ;; - and closes the last topic (this local-variables section).
7056 ;;Local variables:
7057 ;;allout-layout: (0 : -1 -1 0)
7058 ;;End:
7060 ;; arch-tag: cf38fbc3-c044-450f-8bff-afed8ba5681c
7061 ;;; allout.el ends here