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