1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992, 1993, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com>
7 ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com>
8 ;; Created: Dec 1991 -- first release to usenet
10 ;; Keywords: outlines wp languages
11 ;; Website: http://myriadicity.net/Sundry/EmacsAllout
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;; Allout outline minor mode provides extensive outline formatting and
31 ;; and manipulation beyond standard emacs outline mode. Some features:
33 ;; - Classic outline-mode topic-oriented navigation and exposure adjustment
34 ;; - Topic-oriented editing including coherent topic and subtopic
35 ;; creation, promotion, demotion, cut/paste across depths, etc.
36 ;; - Incremental search with dynamic exposure and reconcealment of text
37 ;; - Customizable bullet format -- enables programming-language specific
38 ;; outlining, for code-folding editing. (Allout code itself is to try it;
39 ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but
40 ;; emacs local file variables need to be enabled when the
41 ;; file was visited -- see `enable-local-variables'.)
42 ;; - Configurable per-file initial exposure settings
43 ;; - Symmetric-key and key-pair topic encryption, plus symmetric passphrase
44 ;; mnemonic support, with verification against an established passphrase
45 ;; (using a stashed encrypted dummy string) and user-supplied hint
46 ;; maintenance. (See allout-toggle-current-subtree-encryption docstring.
47 ;; Currently only GnuPG encryption is supported, and integration
48 ;; with gpg-agent is not yet implemented.)
49 ;; - Automatic topic-number maintenance
50 ;; - "Hot-spot" operation, for single-keystroke maneuvering and
51 ;; exposure control (see the allout-mode docstring)
52 ;; - Easy rendering of exposed portions into numbered, latex, indented, etc
54 ;; - Careful attention to whitespace -- enabling blank lines between items
55 ;; and maintenance of hanging indentation (in paragraph auto-fill and
56 ;; across topic promotion and demotion) of topic bodies consistent with
57 ;; indentation of their topic header.
61 ;; See the `allout-mode' function's docstring for an introduction to the
64 ;; The latest development version and helpful notes are available at
65 ;; http://myriadicity.net/Sundry/EmacsAllout .
67 ;; The outline menubar additions provide quick reference to many of
68 ;; the features, and see the docstring of the variable `allout-init'
69 ;; for instructions on priming your Emacs session for automatic
70 ;; activation of allout-mode.
72 ;; See the docstring of the variables `allout-layout' and
73 ;; `allout-auto-activation' for details on automatic activation of
74 ;; `allout-mode' as a minor mode. (It has changed since allout
75 ;; 3.x, for those of you that depend on the old method.)
77 ;; Note -- the lines beginning with `;;;_' are outline topic headers.
78 ;; Just `ESC-x eval-buffer' to give it a whirl.
80 ;; ken manheimer (ken dot manheimer at gmail dot com)
84 ;;;_* Dependency autoloads
87 ;; Most of the requires here are for stuff covered by autoloads.
88 ;; Since just byte-compiling doesn't trigger autoloads, so that
89 ;; "function not found" warnings would occur without these requires.
94 ;; `cl' is required for `assert'. `assert' is not covered by a standard
95 ;; autoload, but it is a macro, so that eval-when-compile is sufficient
96 ;; to byte-compile it in, or to do the require when the buffer evalled.
100 ;;;_* USER CUSTOMIZATION VARIABLES:
102 ;;;_ > defgroup allout
104 "Extensive outline mode for use alone and with other modes."
108 ;;;_ + Layout, Mode, and Topic Header Configuration
110 ;;;_ = allout-command-prefix
111 (defcustom allout-command-prefix
"\C-c "
112 "*Key sequence to be used as prefix for outline mode command key bindings.
114 Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're
115 willing to let allout use a bunch of \C-c keybindings."
119 ;;;_ = allout-keybindings-list
120 ;;; You have to reactivate allout-mode -- `(allout-mode t)' -- to
121 ;;; institute changes to this var.
122 (defvar allout-keybindings-list
()
123 "*List of `allout-mode' key / function bindings, for `allout-mode-map'.
124 String or vector key will be prefaced with `allout-command-prefix',
125 unless optional third, non-nil element is present.")
126 (setq allout-keybindings-list
129 ("\C-n" allout-next-visible-heading
)
130 ("\C-p" allout-previous-visible-heading
)
131 ("\C-u" allout-up-current-level
)
132 ("\C-f" allout-forward-current-level
)
133 ("\C-b" allout-backward-current-level
)
134 ("\C-a" allout-beginning-of-current-entry
)
135 ("\C-e" allout-end-of-entry
)
137 ("\C-i" allout-show-children
)
138 ("\C-s" allout-show-current-subtree
)
139 ("\C-h" allout-hide-current-subtree
)
140 ("\C-t" allout-toggle-current-subtree-exposure
)
141 ("h" allout-hide-current-subtree
)
142 ("\C-o" allout-show-current-entry
)
143 ("!" allout-show-all
)
144 ("x" allout-toggle-current-subtree-encryption
)
145 ; Alteration commands:
146 (" " allout-open-sibtopic
)
147 ("." allout-open-subtopic
)
148 ("," allout-open-supertopic
)
149 ("'" allout-shift-in
)
150 (">" allout-shift-in
)
151 ("<" allout-shift-out
)
152 ("\C-m" allout-rebullet-topic
)
153 ("*" allout-rebullet-current-heading
)
154 ("#" allout-number-siblings
)
155 ("\C-k" allout-kill-line t
)
156 ([?\M-k
] allout-copy-line-as-kill t
)
157 ("\C-y" allout-yank t
)
158 ([?\M-y
] allout-yank-pop t
)
159 ("\C-k" allout-kill-topic
)
160 ([?\M-k
] allout-copy-topic-as-kill
)
161 ; Miscellaneous commands:
162 ;([?\C-\ ] allout-mark-topic)
163 ("@" allout-resolve-xref
)
164 ("=c" allout-copy-exposed-to-buffer
)
165 ("=i" allout-indented-exposed-to-buffer
)
166 ("=t" allout-latexify-exposed
)
167 ("=p" allout-flatten-exposed-to-buffer
)))
169 ;;;_ = allout-auto-activation
170 (defcustom allout-auto-activation nil
171 "*Regulates auto-activation modality of allout outlines -- see `allout-init'.
173 Setq-default by `allout-init' to regulate whether or not allout
174 outline mode is automatically activated when the buffer-specific
175 variable `allout-layout' is non-nil, and whether or not the layout
176 dictated by `allout-layout' should be imposed on mode activation.
178 With value t, auto-mode-activation and auto-layout are enabled.
179 \(This also depends on `allout-find-file-hook' being installed in
180 `find-file-hook', which is also done by `allout-init'.)
182 With value `ask', auto-mode-activation is enabled, and endorsement for
183 performing auto-layout is asked of the user each time.
185 With value `activate', only auto-mode-activation is enabled,
188 With value nil, neither auto-mode-activation nor auto-layout are
191 See the docstring for `allout-init' for the proper interface to
193 :type
'(choice (const :tag
"On" t
)
194 (const :tag
"Ask about layout" "ask")
195 (const :tag
"Mode only" "activate")
196 (const :tag
"Off" nil
))
198 ;;;_ = allout-default-layout
199 (defcustom allout-default-layout
'(-2 : 0)
200 "*Default allout outline layout specification.
202 This setting specifies the outline exposure to use when
203 `allout-layout' has the local value `t'. This docstring describes the
204 layout specifications.
206 A list value specifies a default layout for the current buffer,
207 to be applied upon activation of `allout-mode'. Any non-nil
208 value will automatically trigger `allout-mode', provided
209 `allout-init' has been called to enable this behavior.
211 The types of elements in the layout specification are:
213 INTEGER -- dictate the relative depth to open the corresponding topic(s),
215 -- negative numbers force the topic to be closed before opening
216 to the absolute value of the number, so all siblings are open
218 -- positive numbers open to the relative depth indicated by the
219 number, but do not force already opened subtopics to be closed.
220 -- 0 means to close topic -- hide all subitems.
221 : -- repeat spec -- apply the preceeding element to all siblings at
222 current level, *up to* those siblings that would be covered by specs
223 following the `:' on the list. Ie, apply to all topics at level but
224 trailing ones accounted for by trailing specs. (Only the first of
225 multiple colons at the same level is honored -- later ones are ignored.)
226 * -- completely exposes the topic, including bodies
227 + -- exposes all subtopics, but not the bodies
228 - -- exposes the body of the corresponding topic, but not subtopics
229 LIST -- a nested layout spec, to be applied intricately to its
230 corresponding item(s)
234 Collapse the top-level topics to show their children and
235 grandchildren, but completely collapse the final top-level topic.
237 Close the first topic so only the immediate subtopics are shown,
238 leave the subsequent topics exposed as they are until the second
239 second to last topic, which is exposed at least one level, and
240 completely close the last topic.
242 Expose children and grandchildren of all topics at current
243 level except the last two; expose children of the second to
244 last and completely expose the last one, including its subtopics.
246 See `allout-expose-topic' for more about the exposure process.
248 Also, allout's mode-specific provisions will make topic prefixes default
249 to the comment-start string, if any, of the language of the file. This
250 is modulo the setting of `allout-use-mode-specific-leader', which see."
251 :type
'allout-layout-type
253 ;;;_ : allout-layout-type
254 (define-widget 'allout-layout-type
'lazy
255 "Allout layout format customization basic building blocks."
257 (choice (integer :tag
"integer (<= zero is strict)")
258 (const :tag
": (repeat prior)" :)
259 (const :tag
"* (completely expose)" *)
260 (const :tag
"+ (expose all offspring, headlines only)" +)
261 (const :tag
"- (expose topic body but not offspring)" -
)
262 (allout-layout-type :tag
"<Nested layout>"))))
264 ;;;_ = allout-inhibit-auto-fill
265 (defcustom allout-inhibit-auto-fill nil
266 "*If non-nil, auto-fill will be inhibited in the allout buffers.
268 You can customize this setting to set it for all allout buffers, or set it
269 in individual buffers if you want to inhibit auto-fill only in particular
270 buffers. (You could use a function on `allout-mode-hook' to inhibit
271 auto-fill according, eg, to the major mode.)
273 If you don't set this and auto-fill-mode is enabled, allout will use the
274 value that `normal-auto-fill-function', if any, when allout mode starts, or
275 else allout's special hanging-indent maintaining auto-fill function,
279 (make-variable-buffer-local 'allout-inhibit-auto-fill
)
280 ;;;_ = allout-use-hanging-indents
281 (defcustom allout-use-hanging-indents t
282 "*If non-nil, topic body text auto-indent defaults to indent of the header.
283 Ie, it is indented to be just past the header prefix. This is
284 relevant mostly for use with `indented-text-mode', or other situations
285 where auto-fill occurs."
288 (make-variable-buffer-local 'allout-use-hanging-indents
)
290 (put 'allout-use-hanging-indents
'safe-local-variable
291 (if (fboundp 'booleanp
) 'booleanp
'(lambda (x) (member x
'(t nil
)))))
292 ;;;_ = allout-reindent-bodies
293 (defcustom allout-reindent-bodies
(if allout-use-hanging-indents
295 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
297 When active, topic body lines that are indented even with or beyond
298 their topic header are reindented to correspond with depth shifts of
301 A value of t enables reindent in non-programming-code buffers, ie
302 those that do not have the variable `comment-start' set. A value of
303 `force' enables reindent whether or not `comment-start' is set."
304 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
307 (make-variable-buffer-local 'allout-reindent-bodies
)
309 (put 'allout-reindent-bodies
'safe-local-variable
310 '(lambda (x) (memq x
'(nil t text force
))))
312 ;;;_ = allout-show-bodies
313 (defcustom allout-show-bodies nil
314 "*If non-nil, show entire body when exposing a topic, rather than
318 (make-variable-buffer-local 'allout-show-bodies
)
320 (put 'allout-show-bodies
'safe-local-variable
321 (if (fboundp 'booleanp
) 'booleanp
'(lambda (x) (member x
'(t nil
)))))
323 ;;;_ = allout-beginning-of-line-cycles
324 (defcustom allout-beginning-of-line-cycles t
325 "*If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
327 Cycling only happens on when the command is repeated, not when it
328 follows a different command.
330 Smart-placement means that repeated calls to this function will
333 - if the cursor is on a non-headline body line and not on the first column:
334 then it goes to the first column
335 - if the cursor is on the first column of a non-headline body line:
336 then it goes to the start of the headline within the item body
337 - if the cursor is on the headline and not the start of the headline:
338 then it goes to the start of the headline
339 - if the cursor is on the start of the headline:
340 then it goes to the bullet character (for hotspot navigation)
341 - if the cursor is on the bullet character:
342 then it goes to the first column of that line (the headline)
343 - if the cursor is on the first column of the headline:
344 then it goes to the start of the headline within the item body.
346 In this fashion, you can use the beginning-of-line command to do
347 its normal job and then, when repeated, advance through the
348 entry, cycling back to start.
350 If this configuration variable is nil, then the cursor is just
351 advanced to the beginning of the line and remains there on
353 :type
'boolean
:group
'allout
)
354 ;;;_ = allout-end-of-line-cycles
355 (defcustom allout-end-of-line-cycles t
356 "*If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
358 Cycling only happens on when the command is repeated, not when it
359 follows a different command.
361 Smart placement means that repeated calls to this function will
364 - if the cursor is not on the end-of-line,
365 then it goes to the end-of-line
366 - if the cursor is on the end-of-line but not the end-of-entry,
367 then it goes to the end-of-entry, exposing it if necessary
368 - if the cursor is on the end-of-entry,
369 then it goes to the end of the head line
371 In this fashion, you can use the end-of-line command to do its
372 normal job and then, when repeated, advance through the entry,
373 cycling back to start.
375 If this configuration variable is nil, then the cursor is just
376 advanced to the end of the line and remains there on repeated
378 :type
'boolean
:group
'allout
)
380 ;;;_ = allout-header-prefix
381 (defcustom allout-header-prefix
"."
382 ;; this string is treated as literal match. it will be `regexp-quote'd, so
383 ;; one cannot use regular expressions to match varying header prefixes.
384 "*Leading string which helps distinguish topic headers.
386 Outline topic header lines are identified by a leading topic
387 header prefix, which mostly have the value of this var at their front.
388 Level 1 topics are exceptions. They consist of only a single
389 character, which is typically set to the `allout-primary-bullet'."
392 (make-variable-buffer-local 'allout-header-prefix
)
394 (put 'allout-header-prefix
'safe-local-variable
'stringp
)
395 ;;;_ = allout-primary-bullet
396 (defcustom allout-primary-bullet
"*"
397 "Bullet used for top-level outline topics.
399 Outline topic header lines are identified by a leading topic header
400 prefix, which is concluded by bullets that includes the value of this
401 var and the respective allout-*-bullets-string vars.
403 The value of an asterisk (`*') provides for backwards compatibility
404 with the original Emacs outline mode. See `allout-plain-bullets-string'
405 and `allout-distinctive-bullets-string' for the range of available
409 (make-variable-buffer-local 'allout-primary-bullet
)
411 (put 'allout-primary-bullet
'safe-local-variable
'stringp
)
412 ;;;_ = allout-plain-bullets-string
413 (defcustom allout-plain-bullets-string
".,"
414 "*The bullets normally used in outline topic prefixes.
416 See `allout-distinctive-bullets-string' for the other kind of
419 DO NOT include the close-square-bracket, `]', as a bullet.
421 Outline mode has to be reactivated in order for changes to the value
422 of this var to take effect."
425 (make-variable-buffer-local 'allout-plain-bullets-string
)
427 (put 'allout-plain-bullets-string
'safe-local-variable
'stringp
)
428 ;;;_ = allout-distinctive-bullets-string
429 (defcustom allout-distinctive-bullets-string
"*+-=>()[{}&!?#%\"X@$~_\\:;^"
430 "*Persistent outline header bullets used to distinguish special topics.
432 These bullets are distinguish topics with particular character.
433 They are not used by default in the topic creation routines, but
434 are offered as options when you modify topic creation with a
435 universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]).
437 Distinctive bullets are not cycled when topics are shifted or
438 otherwise automatically rebulleted, so their marking is
439 persistent until deliberately changed. Their significance is
440 purely by convention, however. Some conventions suggest
443 `(' - open paren -- an aside or incidental point
444 `?' - question mark -- uncertain or outright question
445 `!' - exclamation point/bang -- emphatic
446 `[' - open square bracket -- meta-note, about item instead of item's subject
447 `\"' - double quote -- a quotation or other citation
448 `=' - equal sign -- an assignement, equating a name with some connotation
449 `^' - carat -- relates to something above
451 Some are more elusive, but their rationale may be recognizable:
453 `+' - plus -- pending consideration, completion
454 `_' - underscore -- done, completed
455 `&' - ampersand -- addendum, furthermore
457 \(Some other non-plain bullets have special meaning to the
458 software. By default:
460 `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
461 `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
463 See `allout-plain-bullets-string' for the standard, alternating
466 You must run `set-allout-regexp' in order for outline mode to
467 adopt changes of this value.
469 DO NOT include the close-square-bracket, `]', on either of the bullet
473 (make-variable-buffer-local 'allout-distinctive-bullets-string
)
475 (put 'allout-distinctive-bullets-string
'safe-local-variable
'stringp
)
477 ;;;_ = allout-use-mode-specific-leader
478 (defcustom allout-use-mode-specific-leader t
479 "*When non-nil, use mode-specific topic-header prefixes.
481 Allout outline mode will use the mode-specific `allout-mode-leaders' or
482 comment-start string, if any, to lead the topic prefix string, so topic
483 headers look like comments in the programming language. It will also use
484 the comment-start string, with an '_' appended, for `allout-primary-bullet'.
486 String values are used as literals, not regular expressions, so
487 do not escape any regulare-expression characters.
489 Value t means to first check for assoc value in `allout-mode-leaders'
490 alist, then use comment-start string, if any, then use default (`.').
491 \(See note about use of comment-start strings, below.)
493 Set to the symbol for either of `allout-mode-leaders' or
494 `comment-start' to use only one of them, respectively.
496 Value nil means to always use the default (`.') and leave
497 `allout-primary-bullet' unaltered.
499 comment-start strings that do not end in spaces are tripled in
500 the header-prefix, and an `_' underscore is tacked on the end, to
501 distinguish them from regular comment strings. comment-start
502 strings that do end in spaces are not tripled, but an underscore
503 is substituted for the space. [This presumes that the space is
504 for appearance, not comment syntax. You can use
505 `allout-mode-leaders' to override this behavior, when
507 :type
'(choice (const t
) (const nil
) string
508 (const allout-mode-leaders
)
509 (const comment-start
))
512 (put 'allout-use-mode-specific-leader
'safe-local-variable
513 '(lambda (x) (or (memq x
'(t nil allout-mode-leaders comment-start
))
515 ;;;_ = allout-mode-leaders
516 (defvar allout-mode-leaders
'()
517 "Specific allout-prefix leading strings per major modes.
519 Use this if the mode's comment-start string isn't what you
520 prefer, or if the mode lacks a comment-start string. See
521 `allout-use-mode-specific-leader' for more details.
523 If you're constructing a string that will comment-out outline
524 structuring so it can be included in program code, append an extra
525 character, like an \"_\" underscore, to distinguish the lead string
526 from regular comments that start at the beginning-of-line.")
528 ;;;_ = allout-old-style-prefixes
529 (defcustom allout-old-style-prefixes nil
530 "*When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
532 Non-nil restricts the topic creation and modification
533 functions to asterix-padded prefixes, so they look exactly
534 like the original Emacs-outline style prefixes.
536 Whatever the setting of this variable, both old and new style prefixes
537 are always respected by the topic maneuvering functions."
540 (make-variable-buffer-local 'allout-old-style-prefixes
)
542 (put 'allout-old-style-prefixes
'safe-local-variable
543 (if (fboundp 'booleanp
) 'booleanp
'(lambda (x) (member x
'(t nil
)))))
544 ;;;_ = allout-stylish-prefixes -- alternating bullets
545 (defcustom allout-stylish-prefixes t
546 "*Do fancy stuff with topic prefix bullets according to level, etc.
548 Non-nil enables topic creation, modification, and repositioning
549 functions to vary the topic bullet char (the char that marks the topic
550 depth) just preceding the start of the topic text) according to level.
551 Otherwise, only asterisks (`*') and distinctive bullets are used.
553 This is how an outline can look (but sans indentation) with stylish
558 . + One level 3 subtopic
559 . . One level 4 subtopic
560 . . A second 4 subtopic
561 . + Another level 3 subtopic
562 . #1 A numbered level 4 subtopic
564 . ! Another level 4 subtopic with a different distinctive bullet
565 . #4 And another numbered level 4 subtopic
567 This would be an outline with stylish prefixes inhibited (but the
568 numbered and other distinctive bullets retained):
572 . * One level 3 subtopic
573 . * One level 4 subtopic
574 . * A second 4 subtopic
575 . * Another level 3 subtopic
576 . #1 A numbered level 4 subtopic
578 . ! Another level 4 subtopic with a different distinctive bullet
579 . #4 And another numbered level 4 subtopic
581 Stylish and constant prefixes (as well as old-style prefixes) are
582 always respected by the topic maneuvering functions, regardless of
583 this variable setting.
585 The setting of this var is not relevant when `allout-old-style-prefixes'
589 (make-variable-buffer-local 'allout-stylish-prefixes
)
591 (put 'allout-stylish-prefixes
'safe-local-variable
592 (if (fboundp 'booleanp
) 'booleanp
'(lambda (x) (member x
'(t nil
)))))
594 ;;;_ = allout-numbered-bullet
595 (defcustom allout-numbered-bullet
"#"
596 "*String designating bullet of topics that have auto-numbering; nil for none.
598 Topics having this bullet have automatic maintenance of a sibling
599 sequence-number tacked on, just after the bullet. Conventionally set
600 to \"#\", you can set it to a bullet of your choice. A nil value
601 disables numbering maintenance."
602 :type
'(choice (const nil
) string
)
604 (make-variable-buffer-local 'allout-numbered-bullet
)
606 (put 'allout-numbered-bullet
'safe-local-variable
607 (if (fboundp 'string-or-null-p
)
609 '(lambda (x) (or (stringp x
) (null x
)))))
610 ;;;_ = allout-file-xref-bullet
611 (defcustom allout-file-xref-bullet
"@"
612 "*Bullet signifying file cross-references, for `allout-resolve-xref'.
614 Set this var to the bullet you want to use for file cross-references."
615 :type
'(choice (const nil
) string
)
618 (put 'allout-file-xref-bullet
'safe-local-variable
619 (if (fboundp 'string-or-null-p
)
621 '(lambda (x) (or (stringp x
) (null x
)))))
622 ;;;_ = allout-presentation-padding
623 (defcustom allout-presentation-padding
2
624 "*Presentation-format white-space padding factor, for greater indent."
628 (make-variable-buffer-local 'allout-presentation-padding
)
630 (put 'allout-presentation-padding
'safe-local-variable
'integerp
)
632 ;;;_ = allout-abbreviate-flattened-numbering
633 (defcustom allout-abbreviate-flattened-numbering nil
634 "*If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
635 numbers to minimal amount with some context. Otherwise, entire
636 numbers are always used."
640 ;;;_ + LaTeX formatting
641 ;;;_ - allout-number-pages
642 (defcustom allout-number-pages nil
643 "*Non-nil turns on page numbering for LaTeX formatting of an outline."
646 ;;;_ - allout-label-style
647 (defcustom allout-label-style
"\\large\\bf"
648 "*Font and size of labels for LaTeX formatting of an outline."
651 ;;;_ - allout-head-line-style
652 (defcustom allout-head-line-style
"\\large\\sl "
653 "*Font and size of entries for LaTeX formatting of an outline."
656 ;;;_ - allout-body-line-style
657 (defcustom allout-body-line-style
" "
658 "*Font and size of entries for LaTeX formatting of an outline."
661 ;;;_ - allout-title-style
662 (defcustom allout-title-style
"\\Large\\bf"
663 "*Font and size of titles for LaTeX formatting of an outline."
667 (defcustom allout-title
'(or buffer-file-name
(buffer-name))
668 "*Expression to be evaluated to determine the title for LaTeX
672 ;;;_ - allout-line-skip
673 (defcustom allout-line-skip
".05cm"
674 "*Space between lines for LaTeX formatting of an outline."
678 (defcustom allout-indent
".3cm"
679 "*LaTeX formatted depth-indent spacing."
683 ;;;_ + Topic encryption
684 ;;;_ = allout-encryption group
685 (defgroup allout-encryption nil
686 "Settings for topic encryption features of allout outliner."
688 ;;;_ = allout-topic-encryption-bullet
689 (defcustom allout-topic-encryption-bullet
"~"
690 "*Bullet signifying encryption of the entry's body."
691 :type
'(choice (const nil
) string
)
693 :group
'allout-encryption
)
694 ;;;_ = allout-passphrase-verifier-handling
695 (defcustom allout-passphrase-verifier-handling t
696 "*Enable use of symmetric encryption passphrase verifier if non-nil.
698 See the docstring for the `allout-enable-file-variable-adjustment'
699 variable for details about allout ajustment of file variables."
702 :group
'allout-encryption
)
703 (make-variable-buffer-local 'allout-passphrase-verifier-handling
)
704 ;;;_ = allout-passphrase-hint-handling
705 (defcustom allout-passphrase-hint-handling
'always
706 "*Dictate outline encryption passphrase reminder handling:
708 always -- always show reminder when prompting
709 needed -- show reminder on passphrase entry failure
710 disabled -- never present or adjust reminder
712 See the docstring for the `allout-enable-file-variable-adjustment'
713 variable for details about allout ajustment of file variables."
714 :type
'(choice (const always
)
718 :group
'allout-encryption
)
719 (make-variable-buffer-local 'allout-passphrase-hint-handling
)
720 ;;;_ = allout-encrypt-unencrypted-on-saves
721 (defcustom allout-encrypt-unencrypted-on-saves t
722 "*When saving, should topics pending encryption be encrypted?
724 The idea is to prevent file-system exposure of any un-encrypted stuff, and
725 mostly covers both deliberate file writes and auto-saves.
727 - Yes: encrypt all topics pending encryption, even if it's the one
728 currently being edited. (In that case, the currently edited topic
729 will be automatically decrypted before any user interaction, so they
730 can continue editing but the copy on the file system will be
732 Auto-saves will use the \"All except current topic\" mode if this
733 one is selected, to avoid practical difficulties -- see below.
734 - All except current topic: skip the topic currently being edited, even if
735 it's pending encryption. This may expose the current topic on the
736 file sytem, but avoids the nuisance of prompts for the encryption
737 passphrase in the middle of editing for, eg, autosaves.
738 This mode is used for auto-saves for both this option and \"Yes\".
739 - No: leave it to the user to encrypt any unencrypted topics.
741 For practical reasons, auto-saves always use the 'except-current policy
742 when auto-encryption is enabled. (Otherwise, spurious passphrase prompts
743 and unavoidable timing collisions are too disruptive.) If security for a
744 file requires that even the current topic is never auto-saved in the clear,
745 disable auto-saves for that file."
747 :type
'(choice (const :tag
"Yes" t
)
748 (const :tag
"All except current topic" except-current
)
749 (const :tag
"No" nil
))
751 :group
'allout-encryption
)
752 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves
)
755 ;;;_ = allout-developer group
756 (defgroup allout-developer nil
757 "Settings for topic encryption features of allout outliner."
759 ;;;_ = allout-run-unit-tests-on-load
760 (defcustom allout-run-unit-tests-on-load nil
761 "*When non-nil, unit tests will be run at end of loading the allout module.
763 Generally, allout code developers are the only ones who'll want to set this.
765 \(If set, this makes it an even better practice to exercise changes by
766 doing byte-compilation with a repeat count, so the file is loaded after
769 See `allout-run-unit-tests' to see what's run."
771 :group
'allout-developer
)
773 ;;;_ + Miscellaneous customization
775 ;;;_ = allout-enable-file-variable-adjustment
776 (defcustom allout-enable-file-variable-adjustment t
777 "*If non-nil, some allout outline actions edit Emacs local file var text.
779 This can range from changes to existing entries, addition of new ones,
780 and creation of a new local variables section when necessary.
782 Emacs file variables adjustments are also inhibited if `enable-local-variables'
785 Operations potentially causing edits include allout encryption routines.
786 For details, see `allout-toggle-current-subtree-encryption's docstring."
789 (make-variable-buffer-local 'allout-enable-file-variable-adjustment
)
791 ;;;_* CODE -- no user customizations below.
793 ;;;_ #1 Internal Outline Formatting and Configuration
795 ;;;_ = allout-version
796 (defvar allout-version
"2.2.1"
797 "Version of currently loaded outline package. (allout.el)")
798 ;;;_ > allout-version
799 (defun allout-version (&optional here
)
800 "Return string describing the loaded outline version."
802 (let ((msg (concat "Allout Outline Mode v " allout-version
)))
803 (if here
(insert msg
))
806 ;;;_ : Mode activation (defined here because it's referenced early)
808 (defvar allout-mode nil
"Allout outline mode minor-mode flag.")
809 (make-variable-buffer-local 'allout-mode
)
810 ;;;_ = allout-layout nil
811 (defvar allout-layout nil
; LEAVE GLOBAL VALUE NIL -- see docstring.
812 "Buffer-specific setting for allout layout.
814 In buffers where this is non-nil (and if `allout-init' has been run, to
815 enable this behavior), `allout-mode' will be automatically activated. The
816 layout dictated by the value will be used to set the initial exposure when
817 `allout-mode' is activated.
819 \*You should not setq-default this variable non-nil unless you want every
820 visited file to be treated as an allout file.*
822 The value would typically be set by a file local variable. For
823 example, the following lines at the bottom of an Emacs Lisp file:
826 ;;;allout-layout: (0 : -1 -1 0)
829 dictate activation of `allout-mode' mode when the file is visited
830 \(presuming allout-init was already run), followed by the
831 equivalent of `(allout-expose-topic 0 : -1 -1 0)'. (This is
832 the layout used for the allout.el source file.)
834 `allout-default-layout' describes the specification format.
835 `allout-layout' can additionally have the value `t', in which
836 case the value of `allout-default-layout' is used.")
837 (make-variable-buffer-local 'allout-layout
)
839 (put 'allout-layout
'safe-local-variable
840 '(lambda (x) (or (numberp x
) (listp x
) (memq x
'(: * + -
)))))
842 ;;;_ : Topic header format
844 (defvar allout-regexp
""
845 "*Regular expression to match the beginning of a heading line.
847 Any line whose beginning matches this regexp is considered a
848 heading. This var is set according to the user configuration vars
849 by `set-allout-regexp'.")
850 (make-variable-buffer-local 'allout-regexp
)
851 ;;;_ = allout-bullets-string
852 (defvar allout-bullets-string
""
853 "A string dictating the valid set of outline topic bullets.
855 This var should *not* be set by the user -- it is set by `set-allout-regexp',
856 and is produced from the elements of `allout-plain-bullets-string'
857 and `allout-distinctive-bullets-string'.")
858 (make-variable-buffer-local 'allout-bullets-string
)
859 ;;;_ = allout-bullets-string-len
860 (defvar allout-bullets-string-len
0
861 "Length of current buffers' `allout-plain-bullets-string'.")
862 (make-variable-buffer-local 'allout-bullets-string-len
)
863 ;;;_ = allout-depth-specific-regexp
864 (defvar allout-depth-specific-regexp
""
865 "*Regular expression to match a heading line prefix for a particular depth.
867 This expression is used to search for depth-specific topic
868 headers at depth 2 and greater. Use `allout-depth-one-regexp'
869 for to seek topics at depth one.
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-specific-regexp
)
876 ;;;_ = allout-depth-one-regexp
877 (defvar allout-depth-one-regexp
""
878 "*Regular expression to match a heading line prefix for depth one.
880 This var is set according to the user configuration vars by
881 `set-allout-regexp'. It is prepared with format strings for two
882 decimal numbers, which should each be one less than the depth of the
883 topic prefix to be matched.")
884 (make-variable-buffer-local 'allout-depth-one-regexp
)
885 ;;;_ = allout-line-boundary-regexp
886 (defvar allout-line-boundary-regexp
()
887 "`allout-regexp' prepended with a newline for the search target.
889 This is properly set by `set-allout-regexp'.")
890 (make-variable-buffer-local 'allout-line-boundary-regexp
)
891 ;;;_ = allout-bob-regexp
892 (defvar allout-bob-regexp
()
893 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
894 (make-variable-buffer-local 'allout-bob-regexp
)
895 ;;;_ = allout-header-subtraction
896 (defvar allout-header-subtraction
(1- (length allout-header-prefix
))
897 "Allout-header prefix length to subtract when computing topic depth.")
898 (make-variable-buffer-local 'allout-header-subtraction
)
899 ;;;_ = allout-plain-bullets-string-len
900 (defvar allout-plain-bullets-string-len
(length allout-plain-bullets-string
)
901 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
902 (make-variable-buffer-local 'allout-plain-bullets-string-len
)
904 ;;;_ = allout-doublecheck-at-and-shallower
905 (defconst allout-doublecheck-at-and-shallower
3
906 "Validate apparent topics of this depth and shallower as being non-aberrant.
908 Verified with `allout-aberrant-container-p'. The usefulness of
909 this check is limited to shallow depths, because the
910 determination of aberrance is according to the mistaken item
911 being followed by a legitimate item of excessively greater depth.
913 The classic example of a mistaken item, for a standard allout
914 outline configuration, is a body line that begins with an '...'
915 ellipsis. This happens to contain a legitimate depth-2 header
916 prefix, constituted by two '..' dots at the beginning of the
917 line. The only thing that can distinguish it *in principle* from
918 a legitimate one is if the following real header is at a depth
919 that is discontinuous from the depth of 2 implied by the
920 ellipsis, ie depth 4 or more. As the depth being tested gets
921 greater, the likelihood of this kind of disqualification is
922 lower, and the usefulness of this test is lower.
924 Extending the depth of the doublecheck increases the amount it is
925 applied, increasing the cost of the test - on casual estimation,
926 for outlines with many deep topics, geometrically (O(n)?).
927 Taken together with decreasing likelihood that the test will be
928 useful at greater depths, more modest doublecheck limits are more
929 suitably economical.")
930 ;;;_ X allout-reset-header-lead (header-lead)
931 (defun allout-reset-header-lead (header-lead)
932 "*Reset the leading string used to identify topic headers."
933 (interactive "sNew lead string: ")
934 (setq allout-header-prefix header-lead
)
935 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
937 ;;;_ X allout-lead-with-comment-string (header-lead)
938 (defun allout-lead-with-comment-string (&optional header-lead
)
939 "*Set the topic-header leading string to specified string.
941 Useful when for encapsulating outline structure in programming
942 language comments. Returns the leading string."
945 (if (not (stringp header-lead
))
946 (setq header-lead
(read-string
947 "String prefix for topic headers: ")))
948 (setq allout-reindent-bodies nil
)
949 (allout-reset-header-lead header-lead
)
951 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
952 (defun allout-infer-header-lead-and-primary-bullet ()
953 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
955 Works according to settings of:
958 `allout-header-prefix' (default)
959 `allout-use-mode-specific-leader'
960 and `allout-mode-leaders'.
962 Apply this via (re)activation of `allout-mode', rather than
963 invoking it directly."
964 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader
)
965 (if (or (stringp allout-use-mode-specific-leader
)
966 (memq allout-use-mode-specific-leader
967 '(allout-mode-leaders
970 allout-use-mode-specific-leader
971 ;; Oops -- garbled value, equate with effect of t:
975 ((not use-leader
) nil
)
976 ;; Use the explicitly designated leader:
977 ((stringp use-leader
) use-leader
)
978 (t (or (and (memq use-leader
'(t allout-mode-leaders
))
979 ;; Get it from outline mode leaders?
980 (cdr (assq major-mode allout-mode-leaders
)))
981 ;; ... didn't get from allout-mode-leaders...
982 (and (memq use-leader
'(t comment-start
))
984 ;; Use comment-start, maybe tripled, and with
988 (substring comment-start
989 (1- (length comment-start
))))
990 ;; Use comment-start, sans trailing space:
991 (substring comment-start
0 -
1)
992 (concat comment-start comment-start comment-start
))
993 ;; ... and append underscore, whichever:
997 (setq allout-header-prefix leader
)
998 (if (not allout-old-style-prefixes
)
999 ;; setting allout-primary-bullet makes the top level topics use --
1000 ;; actually, be -- the special prefix:
1001 (setq allout-primary-bullet leader
))
1002 allout-header-prefix
)))
1003 (defalias 'allout-infer-header-lead
1004 'allout-infer-header-lead-and-primary-bullet
)
1005 ;;;_ > allout-infer-body-reindent ()
1006 (defun allout-infer-body-reindent ()
1007 "Determine proper setting for `allout-reindent-bodies'.
1009 Depends on default setting of `allout-reindent-bodies' (which see)
1010 and presence of setting for `comment-start', to tell whether the
1011 file is programming code."
1012 (if (and allout-reindent-bodies
1014 (not (eq 'force allout-reindent-bodies
)))
1015 (setq allout-reindent-bodies nil
)))
1016 ;;;_ > set-allout-regexp ()
1017 (defun set-allout-regexp ()
1018 "Generate proper topic-header regexp form for outline functions.
1020 Works with respect to `allout-plain-bullets-string' and
1021 `allout-distinctive-bullets-string'.
1023 Also refresh various data structures that hinge on the regexp."
1026 ;; Derive allout-bullets-string from user configured components:
1027 (setq allout-bullets-string
"")
1028 (let ((strings (list 'allout-plain-bullets-string
1029 'allout-distinctive-bullets-string
1030 'allout-primary-bullet
))
1037 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
1038 (while (< index cur-len
)
1039 (setq cur-char
(aref cur-string index
))
1040 (setq allout-bullets-string
1041 (concat allout-bullets-string
1043 ; Single dash would denote a
1044 ; sequence, repeated denotes
1046 ((eq cur-char ?-
) "--")
1047 ; literal close-square-bracket
1048 ; doesn't work right in the
1050 ((eq cur-char ?\
]) "")
1051 (t (regexp-quote (char-to-string cur-char
))))))
1052 (setq index
(1+ index
)))
1053 (setq strings
(cdr strings
)))
1055 ;; Derive next for repeated use in allout-pending-bullet:
1056 (setq allout-plain-bullets-string-len
(length allout-plain-bullets-string
))
1057 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1059 (let (new-part old-part formfeed-part
)
1060 (setq new-part
(concat "\\("
1061 (regexp-quote allout-header-prefix
)
1063 ;; already regexp-quoted in a custom way:
1064 "[" allout-bullets-string
"]"
1066 old-part
(concat "\\("
1067 (regexp-quote allout-primary-bullet
)
1069 (regexp-quote allout-header-prefix
)
1072 " ?[^" allout-primary-bullet
"]")
1073 formfeed-part
"\\(\^L\\)"
1075 allout-regexp
(concat new-part
1081 allout-line-boundary-regexp
(concat "\n" new-part
1087 allout-bob-regexp
(concat "\\`" new-part
1094 (setq allout-depth-specific-regexp
1095 (concat "\\(^\\|\\`\\)"
1098 ;; new-style spacers-then-bullet string:
1100 (allout-format-quote (regexp-quote allout-header-prefix
))
1102 "[" (allout-format-quote allout-bullets-string
) "]"
1105 ;; old-style all-bullets string, if primary not multi-char:
1106 (if (< 0 allout-header-subtraction
)
1109 (allout-format-quote
1110 (regexp-quote allout-primary-bullet
))
1111 (allout-format-quote
1112 (regexp-quote allout-primary-bullet
))
1113 (allout-format-quote
1114 (regexp-quote allout-primary-bullet
))
1116 ;; disqualify greater depths:
1118 (allout-format-quote allout-primary-bullet
)
1123 (setq allout-depth-one-regexp
1124 (concat "\\(^\\|\\`\\)"
1128 (regexp-quote allout-header-prefix
)
1129 ;; disqualify any bullet char following any amount of
1130 ;; intervening whitespace:
1132 (concat "[^ " allout-bullets-string
"]")
1134 (if (< 0 allout-header-subtraction
)
1135 ;; Need not support anything like the old
1136 ;; bullet style if the prefix is multi-char.
1139 (regexp-quote allout-primary-bullet
)
1140 ;; disqualify deeper primary-bullet sequences:
1141 "[^" allout-primary-bullet
"]"))
1145 ;;;_ = allout-mode-map
1146 (defvar allout-mode-map nil
"Keybindings for (allout) outline minor mode.")
1147 ;;;_ > produce-allout-mode-map (keymap-alist &optional base-map)
1148 (defun produce-allout-mode-map (keymap-list &optional base-map
)
1149 "Produce keymap for use as `allout-mode-map', from KEYMAP-LIST.
1151 Built on top of optional BASE-MAP, or empty sparse map if none specified.
1152 See doc string for `allout-keybindings-list' for format of binding list."
1153 (let ((map (or base-map
(make-sparse-keymap)))
1154 (pref (list allout-command-prefix
)))
1157 (let ((add-pref (null (cdr (cdr cell
))))
1158 (key-suff (list (car cell
))))
1161 (apply 'vconcat
(if add-pref
1162 (append pref key-suff
)
1164 (car (cdr cell
)))))))
1168 (defvar allout-mode-exposure-menu
)
1169 (defvar allout-mode-editing-menu
)
1170 (defvar allout-mode-navigation-menu
)
1171 (defvar allout-mode-misc-menu
)
1172 (defun produce-allout-mode-menubar-entries ()
1174 (easy-menu-define allout-mode-exposure-menu
1176 "Allout outline exposure menu."
1178 ["Show Entry" allout-show-current-entry t
]
1179 ["Show Children" allout-show-children t
]
1180 ["Show Subtree" allout-show-current-subtree t
]
1181 ["Hide Subtree" allout-hide-current-subtree t
]
1182 ["Hide Leaves" allout-hide-current-leaves t
]
1184 ["Show All" allout-show-all t
]))
1185 (easy-menu-define allout-mode-editing-menu
1187 "Allout outline editing menu."
1189 ["Open Sibling" allout-open-sibtopic t
]
1190 ["Open Subtopic" allout-open-subtopic t
]
1191 ["Open Supertopic" allout-open-supertopic t
]
1193 ["Shift Topic In" allout-shift-in t
]
1194 ["Shift Topic Out" allout-shift-out t
]
1195 ["Rebullet Topic" allout-rebullet-topic t
]
1196 ["Rebullet Heading" allout-rebullet-current-heading t
]
1197 ["Number Siblings" allout-number-siblings t
]
1199 ["Toggle Topic Encryption"
1200 allout-toggle-current-subtree-encryption
1201 (> (allout-current-depth) 1)]))
1202 (easy-menu-define allout-mode-navigation-menu
1204 "Allout outline navigation menu."
1206 ["Next Visible Heading" allout-next-visible-heading t
]
1207 ["Previous Visible Heading"
1208 allout-previous-visible-heading t
]
1210 ["Up Level" allout-up-current-level t
]
1211 ["Forward Current Level" allout-forward-current-level t
]
1212 ["Backward Current Level"
1213 allout-backward-current-level t
]
1215 ["Beginning of Entry"
1216 allout-beginning-of-current-entry t
]
1217 ["End of Entry" allout-end-of-entry t
]
1218 ["End of Subtree" allout-end-of-current-subtree t
]))
1219 (easy-menu-define allout-mode-misc-menu
1221 "Allout outlines miscellaneous bindings."
1223 ["Version" allout-version t
]
1225 ["Duplicate Exposed" allout-copy-exposed-to-buffer t
]
1226 ["Duplicate Exposed, numbered"
1227 allout-flatten-exposed-to-buffer t
]
1228 ["Duplicate Exposed, indented"
1229 allout-indented-exposed-to-buffer t
]
1231 ["Set Header Lead" allout-reset-header-lead t
]
1232 ["Set New Exposure" allout-expose-topic t
])))
1233 ;;;_ : Allout Modal-Variables Utilities
1234 ;;;_ = allout-mode-prior-settings
1235 (defvar allout-mode-prior-settings nil
1236 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1238 See `allout-add-resumptions' and `allout-do-resumptions'.")
1239 (make-variable-buffer-local 'allout-mode-prior-settings
)
1240 ;;;_ > allout-add-resumptions (&rest pairs)
1241 (defun allout-add-resumptions (&rest pairs
)
1242 "Set name/value PAIRS.
1244 Old settings are preserved for later resumption using `allout-do-resumptions'.
1246 The new values are set as a buffer local. On resumption, the prior buffer
1247 scope of the variable is restored along with its value. If it was a void
1248 buffer-local value, then it is left as nil on resumption.
1250 The pairs are lists whose car is the name of the variable and car of the
1251 cdr is the new value: '(some-var some-value)'. The pairs can actually be
1252 triples, where the third element qualifies the disposition of the setting,
1253 as described further below.
1255 If the optional third element is the symbol 'extend, then the new value
1256 created by `cons'ing the second element of the pair onto the front of the
1259 If the optional third element is the symbol 'append, then the new value is
1260 extended from the existing one by `append'ing a list containing the second
1261 element of the pair onto the end of the existing value.
1263 Extension, and resumptions in general, should not be used for hook
1264 functions -- use the 'local mode of `add-hook' for that, instead.
1266 The settings are stored on `allout-mode-prior-settings'."
1268 (let* ((pair (pop pairs
))
1271 (qualifier (if (> (length pair
) 2)
1274 (if (not (symbolp name
))
1275 (error "Pair's name, %S, must be a symbol, not %s"
1276 name
(type-of name
)))
1277 (setq prior-value
(condition-case nil
1279 (void-variable nil
)))
1280 (when (not (assoc name allout-mode-prior-settings
))
1281 ;; Not already added as a resumption, create the prior setting entry.
1282 (if (local-variable-p name
)
1283 ;; is already local variable -- preserve the prior value:
1284 (push (list name prior-value
) allout-mode-prior-settings
)
1285 ;; wasn't local variable, indicate so for resumption by killing
1286 ;; local value, and make it local:
1287 (push (list name
) allout-mode-prior-settings
)
1288 (make-local-variable name
)))
1290 (cond ((eq qualifier
'extend
)
1291 (if (not (listp prior-value
))
1292 (error "extension of non-list prior value attempted")
1293 (set name
(cons value prior-value
))))
1294 ((eq qualifier
'append
)
1295 (if (not (listp prior-value
))
1296 (error "appending of non-list prior value attempted")
1297 (set name
(append prior-value
(list value
)))))
1298 (t (error "unrecognized setting qualifier `%s' encountered"
1300 (set name value
)))))
1301 ;;;_ > allout-do-resumptions ()
1302 (defun allout-do-resumptions ()
1303 "Resume all name/value settings registered by `allout-add-resumptions'.
1305 This is used when concluding allout-mode, to resume selected variables to
1306 their settings before allout-mode was started."
1308 (while allout-mode-prior-settings
1309 (let* ((pair (pop allout-mode-prior-settings
))
1311 (value-cell (cdr pair
)))
1312 (if (not value-cell
)
1313 ;; Prior value was global:
1314 (kill-local-variable name
)
1315 ;; Prior value was explicit:
1316 (set name
(car value-cell
))))))
1317 ;;;_ : Mode-specific incidentals
1318 ;;;_ > allout-unprotected (expr)
1319 (defmacro allout-unprotected
(expr)
1320 "Enable internal outline operations to alter invisible text."
1321 `(let ((inhibit-read-only (if (not buffer-read-only
) t
))
1322 (inhibit-field-text-motion t
))
1324 ;;;_ = allout-mode-hook
1325 (defvar allout-mode-hook nil
1326 "*Hook that's run when allout mode starts.")
1327 ;;;_ = allout-mode-deactivate-hook
1328 (defvar allout-mode-deactivate-hook nil
1329 "*Hook that's run when allout mode ends.")
1330 ;;;_ = allout-exposure-category
1331 (defvar allout-exposure-category nil
1332 "Symbol for use as allout invisible-text overlay category.")
1333 ;;;_ x allout-view-change-hook
1334 (defvar allout-view-change-hook nil
1335 "*(Deprecated) A hook run after allout outline exposure changes.
1337 Switch to using `allout-exposure-change-hook' instead. Both hooks are
1338 currently respected, but the other conveys the details of the exposure
1339 change via explicit parameters, and this one will eventually be disabled in
1340 a subsequent allout version.")
1341 ;;;_ = allout-exposure-change-hook
1342 (defvar allout-exposure-change-hook nil
1343 "*Hook that's run after allout outline subtree exposure changes.
1345 It is run at the conclusion of `allout-flag-region'.
1347 Functions on the hook must take three arguments:
1349 - FROM -- integer indicating the point at the start of the change.
1350 - TO -- integer indicating the point of the end of the change.
1351 - FLAG -- change mode: nil for exposure, otherwise concealment.
1353 This hook might be invoked multiple times by a single command.
1355 This hook is replacing `allout-view-change-hook', which is being deprecated
1356 and eventually will not be invoked.")
1357 ;;;_ = allout-structure-added-hook
1358 (defvar allout-structure-added-hook nil
1359 "*Hook that's run after addition of items to the outline.
1361 Functions on the hook should take two arguments:
1363 - NEW-START -- integer indicating position of start of the first new item.
1364 - NEW-END -- integer indicating position of end of the last new item.
1366 Some edits that introduce new items may missed by this hook:
1367 specifically edits that native allout routines do not control.
1369 This hook might be invoked multiple times by a single command.")
1370 ;;;_ = allout-structure-deleted-hook
1371 (defvar allout-structure-deleted-hook nil
1372 "*Hook that's run after disciplined deletion of subtrees from the outline.
1374 Functions on the hook must take two arguments:
1376 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1377 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1379 Some edits that remove or invalidate items may missed by this hook:
1380 specifically edits that native allout routines do not control.
1382 This hook might be invoked multiple times by a single command.")
1383 ;;;_ = allout-structure-shifted-hook
1384 (defvar allout-structure-shifted-hook nil
1385 "*Hook that's run after shifting of items in the outline.
1387 Functions on the hook should take two arguments:
1389 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1390 - START -- integer indicating the start point of the shifted parent item.
1392 Some edits that shift items can be missed by this hook: specifically edits
1393 that native allout routines do not control.
1395 This hook might be invoked multiple times by a single command.")
1396 ;;;_ = allout-outside-normal-auto-fill-function
1397 (defvar allout-outside-normal-auto-fill-function nil
1398 "Value of normal-auto-fill-function outside of allout mode.
1400 Used by allout-auto-fill to do the mandated normal-auto-fill-function
1401 wrapped within allout's automatic fill-prefix setting.")
1402 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function
)
1403 ;;;_ = file-var-bug hack
1404 (defvar allout-v18
/19-file-var-hack nil
1405 "Horrible hack used to prevent invalid multiple triggering of outline
1406 mode from prop-line file-var activation. Used by `allout-mode' function
1408 ;;;_ = allout-passphrase-verifier-string
1409 (defvar allout-passphrase-verifier-string nil
1410 "Setting used to test solicited encryption passphrases against the one
1411 already associated with a file.
1413 It consists of an encrypted random string useful only to verify that a
1414 passphrase entered by the user is effective for decryption. The passphrase
1415 itself is \*not* recorded in the file anywhere, and the encrypted contents
1416 are random binary characters to avoid exposing greater susceptibility to
1419 The verifier string is retained as an Emacs file variable, as well as in
1420 the Emacs buffer state, if file variable adjustments are enabled. See
1421 `allout-enable-file-variable-adjustment' for details about that.")
1422 (make-variable-buffer-local 'allout-passphrase-verifier-string
)
1424 (put 'allout-passphrase-verifier-string
'safe-local-variable
'stringp
)
1425 ;;;_ = allout-passphrase-hint-string
1426 (defvar allout-passphrase-hint-string
""
1427 "Variable used to retain reminder string for file's encryption passphrase.
1429 See the description of `allout-passphrase-hint-handling' for details about how
1430 the reminder is deployed.
1432 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1433 state, if file variable adjustments are enabled. See
1434 `allout-enable-file-variable-adjustment' for details about that.")
1435 (make-variable-buffer-local 'allout-passphrase-hint-string
)
1436 (setq-default allout-passphrase-hint-string
"")
1438 (put 'allout-passphrase-hint-string
'safe-local-variable
'stringp
)
1439 ;;;_ = allout-after-save-decrypt
1440 (defvar allout-after-save-decrypt nil
1441 "Internal variable, is nil or has the value of two points:
1443 - the location of a topic to be decrypted after saving is done
1444 - where to situate the cursor after the decryption is performed
1446 This is used to decrypt the topic that was currently being edited, if it
1447 was encrypted automatically as part of a file write or autosave.")
1448 (make-variable-buffer-local 'allout-after-save-decrypt
)
1449 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1450 (defvar allout-encryption-plaintext-sanitization-regexps nil
1451 "List of regexps whose matches are removed from plaintext before encryption.
1453 This is for the sake of removing artifacts, like escapes, that are added on
1454 and not actually part of the original plaintext. The removal is done just
1455 prior to encryption.
1457 Entries must be symbols that are bound to the desired values.
1459 Each value can be a regexp or a list with a regexp followed by a
1460 substitution string. If it's just a regexp, all its matches are removed
1461 before the text is encrypted. If it's a regexp and a substitution, the
1462 substition is used against the regexp matches, a la `replace-match'.")
1463 (make-variable-buffer-local 'allout-encryption-text-removal-regexps
)
1464 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1465 (defvar allout-encryption-ciphertext-rejection-regexps nil
1466 "Variable for regexps matching plaintext to remove before encryption.
1468 This is for the sake of redoing encryption in cases where the ciphertext
1469 incidentally contains strings that would disrupt mode operation --
1470 for example, a line that happens to look like an allout-mode topic prefix.
1472 Entries must be symbols that are bound to the desired regexp values.
1474 The encryption will be retried up to
1475 `allout-encryption-ciphertext-rejection-limit' times, after which an error
1478 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps
)
1479 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1480 (defvar allout-encryption-ciphertext-rejection-ceiling
5
1481 "Limit on number of times encryption ciphertext is rejected.
1483 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1484 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling
)
1485 ;;;_ > allout-mode-p ()
1486 ;; Must define this macro above any uses, or byte compilation will lack
1487 ;; proper def, if file isn't loaded -- eg, during emacs build!
1488 (defmacro allout-mode-p
()
1489 "Return t if `allout-mode' is active in current buffer."
1491 ;;;_ > allout-write-file-hook-handler ()
1492 (defun allout-write-file-hook-handler ()
1493 "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes."
1495 (if (or (not (allout-mode-p))
1496 (not (boundp 'allout-encrypt-unencrypted-on-saves
))
1497 (not allout-encrypt-unencrypted-on-saves
))
1499 (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves
1502 (if (save-excursion (goto-char (point-min))
1503 (allout-next-topic-pending-encryption except-mark
))
1505 (message "auto-encrypting pending topics")
1507 (condition-case failure
1508 (setq allout-after-save-decrypt
1509 (allout-encrypt-decrypted except-mark
))
1511 "allout-write-file-hook-handler suppressing error %s"
1516 ;;;_ > allout-auto-save-hook-handler ()
1517 (defun allout-auto-save-hook-handler ()
1518 "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save."
1520 (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves
)
1521 ;; Always implement 'except-current policy when enabled.
1522 (let ((allout-encrypt-unencrypted-on-saves 'except-current
))
1523 (allout-write-file-hook-handler))))
1524 ;;;_ > allout-after-saves-handler ()
1525 (defun allout-after-saves-handler ()
1526 "Decrypt topic encrypted for save, if it's currently being edited.
1528 Ie, if it was pending encryption and contained the point in its body before
1531 We use values stored in `allout-after-save-decrypt' to locate the topic
1532 and the place for the cursor after the decryption is done."
1533 (if (not (and (allout-mode-p)
1534 (boundp 'allout-after-save-decrypt
)
1535 allout-after-save-decrypt
))
1537 (goto-char (car allout-after-save-decrypt
))
1538 (let ((was-modified (buffer-modified-p)))
1539 (allout-toggle-subtree-encryption)
1540 (if (not was-modified
)
1541 (set-buffer-modified-p nil
)))
1542 (goto-char (cadr allout-after-save-decrypt
))
1543 (setq allout-after-save-decrypt nil
))
1545 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1546 ;; In some exceptional moments, disparate topic depths need to be allowed
1547 ;; momentarily, eg when one topic is being yanked into another and they're
1548 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1549 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1550 ;; processing to happen in the presence of such discrepancies. It should
1551 ;; almost never be needed, however.
1552 (defvar allout-inhibit-aberrance-doublecheck nil
1553 "Internal state, for momentarily inhibits aberrance doublecheck.
1555 This should only be momentarily let-bound non-nil, not set
1556 non-nil in a lasting way.")
1558 ;;;_ #2 Mode activation
1559 ;;;_ = allout-explicitly-deactivated
1560 (defvar allout-explicitly-deactivated nil
1561 "If t, `allout-mode's last deactivation was deliberate.
1562 So `allout-post-command-business' should not reactivate it...")
1563 (make-variable-buffer-local 'allout-explicitly-deactivated
)
1564 ;;;_ > allout-init (&optional mode)
1565 (defun allout-init (&optional mode
)
1566 "Prime `allout-mode' to enable/disable auto-activation, wrt `allout-layout'.
1568 MODE is one of the following symbols:
1570 - nil (or no argument) deactivate auto-activation/layout;
1571 - `activate', enable auto-activation only;
1572 - `ask', enable auto-activation, and enable auto-layout but with
1573 confirmation for layout operation solicited from user each time;
1574 - `report', just report and return the current auto-activation state;
1575 - anything else (eg, t) for auto-activation and auto-layout, without
1576 any confirmation check.
1578 Use this function to setup your Emacs session for automatic activation
1579 of allout outline mode, contingent to the buffer-specific setting of
1580 the `allout-layout' variable. (See `allout-layout' and
1581 `allout-expose-topic' docstrings for more details on auto layout).
1583 `allout-init' works by setting up (or removing) the `allout-mode'
1584 find-file-hook, and giving `allout-auto-activation' a suitable
1587 To prime your Emacs session for full auto-outline operation, include
1588 the following two lines in your Emacs init file:
1598 (concat "Select outline auto setup mode "
1599 "(empty for report, ? for options) ")
1600 '(("nil")("full")("activate")("deactivate")
1601 ("ask") ("report") (""))
1604 (if (string= mode
"")
1606 (setq mode
(intern-soft mode
)))))
1608 ;; convenience aliases, for consistent ref to respective vars:
1609 ((hook 'allout-find-file-hook
)
1610 (find-file-hook-var-name (if (boundp 'find-file-hook
)
1613 (curr-mode 'allout-auto-activation
))
1616 (set find-file-hook-var-name
1617 (delq hook
(symbol-value find-file-hook-var-name
)))
1619 (message "Allout outline mode auto-activation inhibited.")))
1621 (if (not (memq hook
(symbol-value find-file-hook-var-name
)))
1623 ;; Just punt and use the reports from each of the modes:
1624 (allout-init (symbol-value curr-mode
))))
1625 (t (add-hook find-file-hook-var-name hook
)
1626 (set curr-mode
; `set', not `setq'!
1627 (cond ((eq mode
'activate
)
1629 "Outline mode auto-activation enabled.")
1632 ;; Return the current mode setting:
1636 (concat "Outline mode auto-activation and "
1637 "-layout (upon confirmation) enabled."))
1640 "Outline mode auto-activation and -layout enabled.")
1642 ;;;_ > allout-setup-menubar ()
1643 (defun allout-setup-menubar ()
1644 "Populate the current buffer's menubar with `allout-mode' stuff."
1645 (let ((menus (list allout-mode-exposure-menu
1646 allout-mode-editing-menu
1647 allout-mode-navigation-menu
1648 allout-mode-misc-menu
))
1651 (setq cur
(car menus
)
1653 (easy-menu-add cur
))))
1654 ;;;_ > allout-overlay-preparations
1655 (defun allout-overlay-preparations ()
1656 "Set the properties of the allout invisible-text overlay and others."
1657 (setplist 'allout-exposure-category nil
)
1658 (put 'allout-exposure-category
'invisible
'allout
)
1659 (put 'allout-exposure-category
'evaporate t
)
1660 ;; XXX We use isearch-open-invisible *and* isearch-mode-end-hook. The
1661 ;; latter would be sufficient, but it seems that a separate behavior --
1662 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1663 ;; presence of the isearch-open-invisible property -- even though this
1664 ;; property controls the isearch _arrival_ behavior. This is the case at
1665 ;; least in emacs 21, 22.1, and xemacs 21.4.
1666 (put 'allout-exposure-category
'isearch-open-invisible
1667 'allout-isearch-end-handler
)
1668 (if (featurep 'xemacs
)
1669 (put 'allout-exposure-category
'start-open t
)
1670 (put 'allout-exposure-category
'insert-in-front-hooks
1671 '(allout-overlay-insert-in-front-handler)))
1672 (put 'allout-exposure-category
'modification-hooks
1673 '(allout-overlay-interior-modification-handler)))
1674 ;;;_ > allout-mode (&optional toggle)
1677 (defun allout-mode (&optional toggle
)
1679 "Toggle minor mode for controlling exposure and editing of text outlines.
1682 Optional prefix argument TOGGLE forces the mode to re-initialize
1683 if it is positive, otherwise it turns the mode off. Allout
1684 outline mode always runs as a minor mode.
1686 Allout outline mode provides extensive outline oriented formatting and
1687 manipulation. It enables structural editing of outlines, as well as
1688 navigation and exposure. It also is specifically aimed at
1689 accommodating syntax-sensitive text like programming languages. (For
1690 an example, see the allout code itself, which is organized as an allout
1693 In addition to typical outline navigation and exposure, allout includes:
1695 - topic-oriented authoring, including keystroke-based topic creation,
1696 repositioning, promotion/demotion, cut, and paste
1697 - incremental search with dynamic exposure and reconcealment of hidden text
1698 - adjustable format, so programming code can be developed in outline-structure
1699 - easy topic encryption and decryption
1700 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1701 - integral outline layout, for automatic initial exposure when visiting a file
1702 - independent extensibility, using comprehensive exposure and authoring hooks
1704 and many other features.
1706 Below is a description of the key bindings, and then explanation of
1707 special `allout-mode' features and terminology. See also the outline
1708 menubar additions for quick reference to many of the features, and see
1709 the docstring of the function `allout-init' for instructions on
1710 priming your emacs session for automatic activation of `allout-mode'.
1712 The bindings are dictated by the customizable `allout-keybindings-list'
1713 variable. We recommend customizing `allout-command-prefix' to use just
1714 `\\C-c' as the command prefix, if the allout bindings don't conflict with
1715 any personal bindings you have on \\C-c. In any case, outline structure
1716 navigation and authoring is simplified by positioning the cursor on an
1717 item's bullet character, the \"hot-spot\" -- then you can invoke allout
1718 commands with just the un-prefixed, un-control-shifted command letters.
1719 This is described further in the HOT-SPOT Operation section.
1723 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1724 \\[allout-show-children] `allout-show-children'
1725 \\[allout-show-current-subtree] `allout-show-current-subtree'
1726 \\[allout-show-current-entry] `allout-show-current-entry'
1727 \\[allout-show-all] `allout-show-all'
1731 \\[allout-next-visible-heading] `allout-next-visible-heading'
1732 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1733 \\[allout-up-current-level] `allout-up-current-level'
1734 \\[allout-forward-current-level] `allout-forward-current-level'
1735 \\[allout-backward-current-level] `allout-backward-current-level'
1736 \\[allout-end-of-entry] `allout-end-of-entry'
1737 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1738 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1739 if immediately repeated cycles to the beginning of the current item
1740 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1743 Topic Header Production:
1744 -----------------------
1745 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1746 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1747 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1749 Topic Level and Prefix Adjustment:
1750 ---------------------------------
1751 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1752 \\[allout-shift-out] `allout-shift-out' ... less deep
1753 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1755 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1756 its' offspring -- distinctive bullets are not changed, others
1757 are alternated according to nesting depth.
1758 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1759 the offspring are not affected.
1760 With repeat count, revoke numbering.
1762 Topic-oriented Killing and Yanking:
1763 ----------------------------------
1764 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1765 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1766 \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure.
1767 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1768 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1769 depth of heading if yanking into bare topic
1770 heading (ie, prefix sans text).
1771 \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank
1773 Topic-oriented Encryption:
1774 -------------------------
1775 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1776 Encrypt/Decrypt topic content
1780 M-x outlineify-sticky Activate outline mode for current buffer,
1781 and establish a default file-var setting
1782 for `allout-layout'.
1783 \\[allout-mark-topic] `allout-mark-topic'
1784 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1785 Duplicate outline, sans concealed text, to
1786 buffer with name derived from derived from that
1787 of current buffer -- \"*BUFFERNAME exposed*\".
1788 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1789 Like above 'copy-exposed', but convert topic
1790 prefixes to section.subsection... numeric
1792 \\[eval-expression] (allout-init t) Setup Emacs session for outline mode
1797 Outline mode supports gpg encryption of topics, with support for
1798 symmetric and key-pair modes, passphrase timeout, passphrase
1799 consistency checking, user-provided hinting for symmetric key
1800 mode, and auto-encryption of topics pending encryption on save.
1802 Topics pending encryption are, by default, automatically
1803 encrypted during file saves. If the contents of the topic
1804 containing the cursor was encrypted for a save, it is
1805 automatically decrypted for continued editing.
1807 The aim of these measures is reliable topic privacy while
1808 preventing accidents like neglected encryption before saves,
1809 forgetting which passphrase was used, and other practical
1812 See `allout-toggle-current-subtree-encryption' function docstring
1813 and `allout-encrypt-unencrypted-on-saves' customization variable
1818 Hot-spot operation provides a means for easy, single-keystroke outline
1819 navigation and exposure control.
1821 When the text cursor is positioned directly on the bullet character of
1822 a topic, regular characters (a to z) invoke the commands of the
1823 corresponding allout-mode keymap control chars. For example, \"f\"
1824 would invoke the command typically bound to \"C-c<space>C-f\"
1825 \(\\[allout-forward-current-level] `allout-forward-current-level').
1827 Thus, by positioning the cursor on a topic bullet, you can
1828 execute the outline navigation and manipulation commands with a
1829 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1830 this special translation, so you can use them to get out of the
1831 hot-spot and back to normal editing operation.
1833 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]]) is
1834 replaced with one that makes it easy to get to the hot-spot. If you
1835 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1836 is set) to the beginning of the item and then, if you hit it again
1837 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1838 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1839 at the beginning of the current entry.
1843 Allout exposure and authoring activites all have associated
1844 hooks, by which independent code can cooperate with allout
1845 without changes to the allout core. Here are key ones:
1848 `allout-mode-deactivate-hook'
1849 `allout-exposure-change-hook'
1850 `allout-structure-added-hook'
1851 `allout-structure-deleted-hook'
1852 `allout-structure-shifted-hook'
1856 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1858 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1859 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1860 and with no intervening items of lower DEPTH than the container.
1862 The visible ITEM most immediately containing the cursor.
1863 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1864 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1866 LEVEL: The same as DEPTH.
1869 Those ITEMs whose TOPICs contain an ITEM.
1870 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1873 The ITEMs contained within an ITEM's TOPIC.
1875 An OFFSPRING of its ANCESTOR TOPICs.
1877 An immediate SUBTOPIC of its PARENT.
1879 TOPICs having the same PARENT and DEPTH.
1881 Topic text constituents:
1883 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1885 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1886 the HEADER text and distinct from the ITEM PREFIX.
1887 BODY: Same as ENTRY.
1888 PREFIX: The leading text of an ITEM which distinguishes it from normal
1889 ENTRY text. Allout recognizes the outline structure according
1890 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1891 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1892 number, indicating the ordinal number of the topic among its
1893 siblings, or an asterisk indicating encryption, plus an optional
1894 space. After that is the ITEM HEADER text, which is not part of
1897 The relative length of the PREFIX determines the nesting DEPTH
1900 The string at the beginning of a HEADER PREFIX, by default a `.'.
1901 It can be customized by changing the setting of
1902 `allout-header-prefix' and then reinitializing `allout-mode'.
1904 When the PREFIX-LEAD is set to the comment-string of a
1905 programming language, outline structuring can be embedded in
1906 program code without interfering with processing of the text
1907 (by emacs or the language processor) as program code. This
1908 setting happens automatically when allout mode is used in
1909 programming-mode buffers. See `allout-use-mode-specific-leader'
1910 docstring for more detail.
1912 Spaces or asterisks which separate the PREFIX-LEAD and the
1913 bullet, determining the ITEM's DEPTH.
1914 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1915 the characters listed on `allout-plain-bullets-string' or
1916 `allout-distinctive-bullets-string'. When creating a TOPIC,
1917 plain BULLETs are by default used, according to the DEPTH of the
1918 TOPIC. Choice among the distinctive BULLETs is offered when you
1919 provide a universal argugment \(\\[universal-argument]) to the
1920 TOPIC creation command, or when explictly rebulleting a TOPIC. The
1921 significance of the various distinctive bullets is purely by
1922 convention. See the documentation for the above bullet strings for
1925 The state of a TOPIC which determines the on-screen visibility
1926 of its OFFSPRING and contained ENTRY text.
1928 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1929 text is represented by \"...\" ellipses.
1931 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1932 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1933 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1937 (let* ((active (and (not (equal major-mode
'outline
))
1939 ; Massage universal-arg `toggle' val:
1941 (or (and (listp toggle
)(car toggle
))
1943 ; Activation specifically demanded?
1944 (explicit-activation (and toggle
1945 (or (symbolp toggle
)
1946 (and (wholenump toggle
)
1947 (not (zerop toggle
))))))
1948 ;; allout-mode already called once during this complex command?
1949 (same-complex-command (eq allout-v18
/19-file-var-hack
1950 (car command-history
)))
1951 (write-file-hook-var-name (cond ((boundp 'write-file-functions
)
1952 'write-file-functions
)
1953 ((boundp 'write-file-hooks
)
1955 (t 'local-write-file-hooks
)))
1959 ; See comments below re v19.18,.19 bug.
1960 (setq allout-v18
/19-file-var-hack
(car command-history
))
1964 ;; Provision for v19.18, 19.19 bug --
1965 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1966 ;; modes twice when file is visited. We have to avoid toggling mode
1967 ;; off on second invocation, so we detect it as best we can, and
1969 ((and same-complex-command
; Still in same complex command
1970 ; as last time `allout-mode' invoked.
1971 active
; Already activated.
1972 (not explicit-activation
) ; Prop-line file-vars don't have args.
1973 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1974 emacs-version
)); 19.19.
1978 ((and (not explicit-activation
)
1980 ; Activation not explicitly
1981 ; requested, and either in
1982 ; active state or *de*activation
1983 ; specifically requested:
1984 (setq allout-explicitly-deactivated t
)
1986 (allout-do-resumptions)
1988 (remove-from-invisibility-spec '(allout . t
))
1989 (remove-hook 'pre-command-hook
'allout-pre-command-business t
)
1990 (remove-hook 'post-command-hook
'allout-post-command-business t
)
1991 (remove-hook 'before-change-functions
'allout-before-change-handler t
)
1992 (remove-hook 'isearch-mode-end-hook
'allout-isearch-end-handler t
)
1993 (remove-hook write-file-hook-var-name
'allout-write-file-hook-handler t
)
1994 (remove-hook 'auto-save-hook
'allout-auto-save-hook-handler t
)
1996 (remove-overlays (point-min) (point-max)
1997 'category
'allout-exposure-category
)
1999 (setq allout-mode nil
)
2000 (run-hooks 'allout-mode-deactivate-hook
))
2004 (setq allout-explicitly-deactivated nil
)
2005 (if allout-old-style-prefixes
2006 ;; Inhibit all the fancy formatting:
2007 (allout-add-resumptions '(allout-primary-bullet "*")))
2009 (allout-overlay-preparations) ; Doesn't hurt to redo this.
2011 (allout-infer-header-lead-and-primary-bullet)
2012 (allout-infer-body-reindent)
2015 (allout-add-resumptions
2016 '(allout-encryption-ciphertext-rejection-regexps
2017 allout-line-boundary-regexp
2019 '(allout-encryption-ciphertext-rejection-regexps
2023 ;; Produce map from current version of allout-keybindings-list:
2024 (allout-setup-mode-map)
2025 (produce-allout-mode-menubar-entries)
2027 ;; Include on minor-mode-map-alist, if not already there:
2028 (if (not (member '(allout-mode . allout-mode-map
)
2029 minor-mode-map-alist
))
2030 (setq minor-mode-map-alist
2031 (cons '(allout-mode . allout-mode-map
)
2032 minor-mode-map-alist
)))
2034 (add-to-invisibility-spec '(allout . t
))
2036 (allout-add-resumptions '(line-move-ignore-invisible t
))
2037 (add-hook 'pre-command-hook
'allout-pre-command-business nil t
)
2038 (add-hook 'post-command-hook
'allout-post-command-business nil t
)
2039 (add-hook 'before-change-functions
'allout-before-change-handler
2041 (add-hook 'isearch-mode-end-hook
'allout-isearch-end-handler nil t
)
2042 (add-hook write-file-hook-var-name
'allout-write-file-hook-handler
2044 (add-hook 'auto-save-hook
'allout-auto-save-hook-handler
2047 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2048 ;; func will be used if auto-fill is active or activated. (The
2049 ;; custom func respects topic headline, maintains hanging-indents,
2051 (if (and auto-fill-function
(not allout-inhibit-auto-fill
))
2052 ;; allout-auto-fill will use the stashed values and so forth.
2053 (allout-add-resumptions '(auto-fill-function allout-auto-fill
)))
2054 (allout-add-resumptions (list 'allout-former-auto-filler
2056 ;; Register allout-auto-fill to be used if
2057 ;; filling is active:
2058 (list 'allout-outside-normal-auto-fill-function
2059 normal-auto-fill-function
)
2060 '(normal-auto-fill-function allout-auto-fill
)
2061 ;; Paragraphs are broken by topic headlines.
2062 (list 'paragraph-start
2063 (concat paragraph-start
"\\|^\\("
2064 allout-regexp
"\\)"))
2065 (list 'paragraph-separate
2066 (concat paragraph-separate
"\\|^\\("
2067 allout-regexp
"\\)")))
2068 (or (assq 'allout-mode minor-mode-alist
)
2069 (setq minor-mode-alist
2070 (cons '(allout-mode " Allout") minor-mode-alist
)))
2072 (allout-setup-menubar)
2077 (setq allout-mode t
)
2078 (run-hooks 'allout-mode-hook
))
2082 (allout-infer-body-reindent))
2083 ) ;; end of activation-mode cases.
2085 ;; Do auto layout if warranted:
2086 (let ((use-layout (if (listp allout-layout
)
2088 allout-default-layout
)))
2090 allout-auto-activation
2092 (and (not (eq allout-auto-activation
'activate
))
2093 (if (eq allout-auto-activation
'ask
)
2094 (if (y-or-n-p (format "Expose %s with layout '%s'? "
2098 (message "Skipped %s layout." (buffer-name))
2102 (message "Adjusting '%s' exposure..." (buffer-name))
2104 (allout-this-or-next-heading)
2107 (apply 'allout-expose-topic
(list use-layout
))
2108 (message "Adjusting '%s' exposure... done." (buffer-name)))
2109 ;; Problem applying exposure -- notify user, but don't
2110 ;; interrupt, eg, file visit:
2111 (error (message "%s" (car (cdr err
)))
2117 (defun allout-setup-mode-map ()
2118 "Establish allout-mode bindings."
2119 (setq-default allout-mode-map
2120 (produce-allout-mode-map allout-keybindings-list
))
2121 (setq allout-mode-map
2122 (produce-allout-mode-map allout-keybindings-list
))
2123 (substitute-key-definition 'beginning-of-line
2124 'allout-beginning-of-line
2125 allout-mode-map global-map
)
2126 (substitute-key-definition 'move-beginning-of-line
2127 'allout-beginning-of-line
2128 allout-mode-map global-map
)
2129 (substitute-key-definition 'end-of-line
2131 allout-mode-map global-map
)
2132 (substitute-key-definition 'move-end-of-line
2134 allout-mode-map global-map
)
2135 (fset 'allout-mode-map allout-mode-map
))
2137 ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
2139 (allout-setup-mode-map)
2141 ;;;_ > allout-minor-mode
2142 (defalias 'allout-minor-mode
'allout-mode
)
2144 ;;;_ > allout-unload-function
2145 (defun allout-unload-function ()
2146 "Unload the allout outline library."
2147 (save-current-buffer
2148 (dolist (buffer (buffer-list))
2150 (when allout-mode
(allout-mode -
1))))
2151 ;; continue standard unloading
2154 ;;;_ - Position Assessment
2155 ;;;_ > allout-hidden-p (&optional pos)
2156 (defsubst allout-hidden-p
(&optional pos
)
2157 "Non-nil if the character after point is invisible."
2158 (eq (get-char-property (or pos
(point)) 'invisible
) 'allout
))
2160 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2161 ;;; &optional prelen)
2162 (defun allout-overlay-insert-in-front-handler (ol after beg end
2164 "Shift the overlay so stuff inserted in front of it is excluded."
2166 ;; XXX Shouldn't moving the overlay should be unnecessary, if overlay
2167 ;; front-advance on the overlay worked as it should?
2168 (move-overlay ol
(1+ beg
) (overlay-end ol
))))
2169 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2170 ;;; &optional prelen)
2171 (defun allout-overlay-interior-modification-handler (ol after beg end
2173 "Get confirmation before making arbitrary changes to invisible text.
2175 We expose the invisible text and ask for confirmation. Refusal or
2176 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2177 reclosing the opened text.
2179 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2180 internal functions use this feature cohesively bunch changes."
2182 (when (and (not inhibit-read-only
) (not after
))
2183 (let ((start (point))
2184 (ol-start (overlay-start ol
))
2185 (ol-end (overlay-end ol
))
2188 (while (< (point) end
)
2189 (when (allout-hidden-p)
2190 (allout-show-to-offshoot)
2191 (if (allout-hidden-p)
2192 (save-excursion (forward-char 1)
2193 (allout-show-to-offshoot)))
2195 (setq first
(point))))
2196 (goto-char (if (featurep 'xemacs
)
2197 (next-property-change (1+ (point)) nil end
)
2198 (next-char-property-change (1+ (point)) end
))))
2204 (substitute-command-keys
2205 (concat "Modify concealed text? (\"no\" just aborts,"
2206 " \\[keyboard-quit] also reconceals) "))))
2207 (progn (goto-char start
)
2208 (error "Concealed-text change refused.")))
2209 (quit (allout-flag-region ol-start ol-end nil
)
2210 (allout-flag-region ol-start ol-end t
)
2211 (error "Concealed-text change abandoned, text reconcealed."))))
2212 (goto-char start
))))
2213 ;;;_ > allout-before-change-handler (beg end)
2214 (defun allout-before-change-handler (beg end
)
2215 "Protect against changes to invisible text.
2217 See `allout-overlay-interior-modification-handler' for details."
2219 (if (and (allout-mode-p) undo-in-progress
(allout-hidden-p))
2220 (allout-show-to-offshoot))
2222 ;; allout-overlay-interior-modification-handler on an overlay handles
2223 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2224 (when (and (featurep 'xemacs
) (allout-mode-p))
2225 ;; process all of the pending overlays:
2228 (let ((overlay (allout-get-invisibility-overlay)))
2229 (allout-overlay-interior-modification-handler
2230 overlay nil beg end nil
)))))
2231 ;;;_ > allout-isearch-end-handler (&optional overlay)
2232 (defun allout-isearch-end-handler (&optional overlay
)
2233 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2235 Optional OVERLAY parameter is for when this function is used by
2236 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2237 function can also be used as an `isearch-mode-end-hook'."
2239 (if (and (allout-mode-p) (allout-hidden-p))
2240 (allout-show-to-offshoot)))
2242 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2243 ;;; All the basic outline functions that directly do string matches to
2244 ;;; evaluate heading prefix location set the variables
2245 ;;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2246 ;;; when successful. Functions starting with `allout-recent-' all
2247 ;;; use this state, providing the means to avoid redundant searches
2248 ;;; for just-established data. This optimization can provide
2249 ;;; significant speed improvement, but it must be employed carefully.
2250 ;;;_ = allout-recent-prefix-beginning
2251 (defvar allout-recent-prefix-beginning
0
2252 "Buffer point of the start of the last topic prefix encountered.")
2253 (make-variable-buffer-local 'allout-recent-prefix-beginning
)
2254 ;;;_ = allout-recent-prefix-end
2255 (defvar allout-recent-prefix-end
0
2256 "Buffer point of the end of the last topic prefix encountered.")
2257 (make-variable-buffer-local 'allout-recent-prefix-end
)
2258 ;;;_ = allout-recent-depth
2259 (defvar allout-recent-depth
0
2260 "Depth of the last topic prefix encountered.")
2261 (make-variable-buffer-local 'allout-recent-depth
)
2262 ;;;_ = allout-recent-end-of-subtree
2263 (defvar allout-recent-end-of-subtree
0
2264 "Buffer point last returned by `allout-end-of-current-subtree'.")
2265 (make-variable-buffer-local 'allout-recent-end-of-subtree
)
2266 ;;;_ > allout-prefix-data ()
2267 (defsubst allout-prefix-data
()
2268 "Register allout-prefix state data.
2270 For reference by `allout-recent' funcs. Return
2271 the new value of `allout-recent-prefix-beginning'."
2272 (setq allout-recent-prefix-end
(or (match-end 1) (match-end 2) (match-end 3))
2273 allout-recent-prefix-beginning
(or (match-beginning 1)
2275 (match-beginning 3))
2276 allout-recent-depth
(max 1 (- allout-recent-prefix-end
2277 allout-recent-prefix-beginning
2278 allout-header-subtraction
)))
2279 allout-recent-prefix-beginning
)
2280 ;;;_ > nullify-allout-prefix-data ()
2281 (defsubst nullify-allout-prefix-data
()
2282 "Mark allout prefix data as being uninformative."
2283 (setq allout-recent-prefix-end
(point)
2284 allout-recent-prefix-beginning
(point)
2285 allout-recent-depth
0)
2286 allout-recent-prefix-beginning
)
2287 ;;;_ > allout-recent-depth ()
2288 (defsubst allout-recent-depth
()
2289 "Return depth of last heading encountered by an outline maneuvering function.
2291 All outline functions which directly do string matches to assess
2292 headings set the variables `allout-recent-prefix-beginning' and
2293 `allout-recent-prefix-end' if successful. This function uses those settings
2294 to return the current depth."
2296 allout-recent-depth
)
2297 ;;;_ > allout-recent-prefix ()
2298 (defsubst allout-recent-prefix
()
2299 "Like `allout-recent-depth', but returns text of last encountered prefix.
2301 All outline functions which directly do string matches to assess
2302 headings set the variables `allout-recent-prefix-beginning' and
2303 `allout-recent-prefix-end' if successful. This function uses those settings
2304 to return the current prefix."
2305 (buffer-substring-no-properties allout-recent-prefix-beginning
2306 allout-recent-prefix-end
))
2307 ;;;_ > allout-recent-bullet ()
2308 (defmacro allout-recent-bullet
()
2309 "Like allout-recent-prefix, but returns bullet of last encountered prefix.
2311 All outline functions which directly do string matches to assess
2312 headings set the variables `allout-recent-prefix-beginning' and
2313 `allout-recent-prefix-end' if successful. This function uses those settings
2314 to return the current depth of the most recently matched topic."
2315 '(buffer-substring-no-properties (1- allout-recent-prefix-end
)
2316 allout-recent-prefix-end
))
2320 ;;;_ - Position Assessment
2321 ;;;_ : Location Predicates
2322 ;;;_ > allout-do-doublecheck ()
2323 (defsubst allout-do-doublecheck
()
2324 "True if current item conditions qualify for checking on topic aberrance."
2326 ;; presume integrity of outline and yanked content during yank -- necessary
2327 ;; to allow for level disparity of yank location and yanked text:
2328 (not allout-inhibit-aberrance-doublecheck
)
2329 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2330 (<= allout-recent-depth allout-doublecheck-at-and-shallower
)))
2331 ;;;_ > allout-aberrant-container-p ()
2332 (defun allout-aberrant-container-p ()
2333 "True if topic, or next sibling with children, contains them discontinuously.
2335 Discontinuous means an immediate offspring that is nested more
2336 than one level deeper than the topic.
2338 If topic has no offspring, then the next sibling with offspring will
2339 determine whether or not this one is determined to be aberrant.
2341 If true, then the allout-recent-* settings are calibrated on the
2342 offspring that qaulifies it as aberrant, ie with depth that
2343 exceeds the topic by more than one."
2345 ;; This is most clearly understood when considering standard-prefix-leader
2346 ;; low-level topics, which can all too easily match text not intended as
2347 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2348 ;; following bullet qualifies without this protection. (A sequence of
2349 ;; them can occur naturally, eg a typical textual bullet list.) We
2350 ;; disqualify such low-level sequences when they are followed by a
2351 ;; discontinuously contained child, inferring that the sequences are not
2352 ;; actually connected with their prospective context.
2354 (let ((depth (allout-depth))
2355 (start-point (point))
2359 (while (and (not done
)
2360 (re-search-forward allout-line-boundary-regexp nil
0))
2361 (allout-prefix-data)
2362 (goto-char allout-recent-prefix-beginning
)
2364 ;; sibling -- continue:
2365 ((eq allout-recent-depth depth
))
2366 ;; first offspring is excessive -- aberrant:
2367 ((> allout-recent-depth
(1+ depth
))
2368 (setq done t aberrant t
))
2369 ;; next non-sibling is lower-depth -- not aberrant:
2370 (t (setq done t
))))))
2373 (goto-char start-point
)
2374 ;; recalibrate allout-recent-*
2377 ;;;_ > allout-on-current-heading-p ()
2378 (defun allout-on-current-heading-p ()
2379 "Return non-nil if point is on current visible topics' header line.
2381 Actually, returns prefix beginning point."
2383 (allout-beginning-of-current-line)
2385 (and (looking-at allout-regexp
)
2386 (allout-prefix-data)
2387 (or (not (allout-do-doublecheck))
2388 (not (allout-aberrant-container-p)))))))
2389 ;;;_ > allout-on-heading-p ()
2390 (defalias 'allout-on-heading-p
'allout-on-current-heading-p
)
2391 ;;;_ > allout-e-o-prefix-p ()
2392 (defun allout-e-o-prefix-p ()
2393 "True if point is located where current topic prefix ends, heading begins."
2394 (and (save-match-data
2395 (save-excursion (let ((inhibit-field-text-motion t
))
2396 (beginning-of-line))
2397 (looking-at allout-regexp
))
2398 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2399 ;;;_ : Location attributes
2400 ;;;_ > allout-depth ()
2401 (defun allout-depth ()
2402 "Return depth of topic most immediately containing point.
2404 Does not do doublecheck for aberrant topic header.
2406 Return zero if point is not within any topic.
2408 Like `allout-current-depth', but respects hidden as well as visible topics."
2410 (let ((start-point (point)))
2411 (if (and (allout-goto-prefix)
2412 (not (< start-point
(point))))
2415 ;; Oops, no prefix, nullify it:
2416 (nullify-allout-prefix-data)
2417 ;; ... and return 0:
2419 ;;;_ > allout-current-depth ()
2420 (defun allout-current-depth ()
2421 "Return depth of visible topic most immediately containing point.
2423 Return zero if point is not within any topic."
2425 (if (allout-back-to-current-heading)
2427 (- allout-recent-prefix-end
2428 allout-recent-prefix-beginning
2429 allout-header-subtraction
))
2431 ;;;_ > allout-get-current-prefix ()
2432 (defun allout-get-current-prefix ()
2433 "Topic prefix of the current topic."
2435 (if (allout-goto-prefix)
2436 (allout-recent-prefix))))
2437 ;;;_ > allout-get-bullet ()
2438 (defun allout-get-bullet ()
2439 "Return bullet of containing topic (visible or not)."
2441 (and (allout-goto-prefix)
2442 (allout-recent-bullet))))
2443 ;;;_ > allout-current-bullet ()
2444 (defun allout-current-bullet ()
2445 "Return bullet of current (visible) topic heading, or none if none found."
2448 (allout-back-to-current-heading)
2449 (buffer-substring-no-properties (- allout-recent-prefix-end
1)
2450 allout-recent-prefix-end
))
2451 ;; Quick and dirty provision, ostensibly for missing bullet:
2452 (args-out-of-range nil
))
2454 ;;;_ > allout-get-prefix-bullet (prefix)
2455 (defun allout-get-prefix-bullet (prefix)
2456 "Return the bullet of the header prefix string PREFIX."
2457 ;; Doesn't make sense if we're old-style prefixes, but this just
2458 ;; oughtn't be called then, so forget about it...
2459 (if (string-match allout-regexp prefix
)
2460 (substring prefix
(1- (match-end 2)) (match-end 2))))
2461 ;;;_ > allout-sibling-index (&optional depth)
2462 (defun allout-sibling-index (&optional depth
)
2463 "Item number of this prospective topic among its siblings.
2465 If optional arg DEPTH is greater than current depth, then we're
2466 opening a new level, and return 0.
2468 If less than this depth, ascend to that depth and count..."
2471 (cond ((and depth
(<= depth
0) 0))
2472 ((or (null depth
) (= depth
(allout-depth)))
2474 (while (allout-previous-sibling allout-recent-depth nil
)
2475 (setq index
(1+ index
)))
2477 ((< depth allout-recent-depth
)
2478 (allout-ascend-to-depth depth
)
2479 (allout-sibling-index))
2481 ;;;_ > allout-topic-flat-index ()
2482 (defun allout-topic-flat-index ()
2483 "Return a list indicating point's numeric section.subsect.subsubsect...
2484 Outermost is first."
2485 (let* ((depth (allout-depth))
2486 (next-index (allout-sibling-index depth
))
2488 (while (> next-index
0)
2489 (setq rev-sibls
(cons next-index rev-sibls
))
2490 (setq depth
(1- depth
))
2491 (setq next-index
(allout-sibling-index depth
)))
2495 ;;;_ - Navigation routines
2496 ;;;_ > allout-beginning-of-current-line ()
2497 (defun allout-beginning-of-current-line ()
2498 "Like beginning of line, but to visible text."
2500 ;; This combination of move-beginning-of-line and beginning-of-line is
2501 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2502 (let ((inhibit-field-text-motion t
))
2503 (move-beginning-of-line 1)
2505 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2507 (if (or (allout-hidden-p) (not (bolp)))
2508 (forward-char -
1)))))
2509 ;;;_ > allout-end-of-current-line ()
2510 (defun allout-end-of-current-line ()
2511 "Move to the end of line, past concealed text if any."
2512 ;; XXX This is for symmetry with `allout-beginning-of-current-line' --
2513 ;; `move-end-of-line' doesn't suffer the same problem as
2514 ;; `move-beginning-of-line'.
2515 (let ((inhibit-field-text-motion t
))
2517 (while (allout-hidden-p)
2519 (if (allout-hidden-p) (forward-char 1)))))
2520 ;;;_ > allout-beginning-of-line ()
2521 (defun allout-beginning-of-line ()
2522 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2526 (if (or (not allout-beginning-of-line-cycles
)
2527 (not (equal last-command this-command
)))
2529 (if (and (not (bolp))
2530 (allout-hidden-p (1- (point))))
2531 (goto-char (previous-single-char-property-change
2532 (1- (point)) 'invisible
)))
2533 (move-beginning-of-line 1))
2535 (let ((beginning-of-body
2537 (while (and (allout-do-doublecheck)
2538 (allout-aberrant-container-p)
2539 (allout-previous-visible-heading 1)))
2540 (allout-beginning-of-current-entry)
2542 (cond ((= (current-column) 0)
2543 (goto-char beginning-of-body
))
2544 ((< (point) beginning-of-body
)
2545 (allout-beginning-of-current-line))
2546 ((= (point) beginning-of-body
)
2547 (goto-char (allout-current-bullet-pos)))
2548 (t (allout-beginning-of-current-line)
2549 (if (< (point) beginning-of-body
)
2550 ;; we were on the headline after its start:
2551 (goto-char beginning-of-body
)))))))
2552 ;;;_ > allout-end-of-line ()
2553 (defun allout-end-of-line ()
2554 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2558 (if (or (not allout-end-of-line-cycles
)
2559 (not (equal last-command this-command
)))
2560 (allout-end-of-current-line)
2561 (let ((end-of-entry (save-excursion
2562 (allout-end-of-entry)
2565 (allout-end-of-current-line))
2566 ((or (allout-hidden-p) (save-excursion
2569 (allout-back-to-current-heading)
2570 (allout-show-current-entry)
2571 (allout-show-children)
2572 (allout-end-of-entry))
2573 ((>= (point) end-of-entry
)
2574 (allout-back-to-current-heading)
2575 (allout-end-of-current-line))
2577 (if (not (and transient-mark-mode mark-active
))
2579 (allout-end-of-entry))))))
2580 ;;;_ > allout-next-heading ()
2581 (defsubst allout-next-heading
()
2582 "Move to the heading for the topic (possibly invisible) after this one.
2584 Returns the location of the heading, or nil if none found.
2586 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2589 (if (looking-at allout-regexp
)
2592 (when (re-search-forward allout-line-boundary-regexp nil
0)
2593 (allout-prefix-data)
2594 (goto-char allout-recent-prefix-beginning
)
2597 (and (allout-do-doublecheck)
2598 ;; this will set allout-recent-* on the first non-aberrant topic,
2599 ;; whether it's the current one or one that disqualifies it:
2600 (allout-aberrant-container-p))
2601 ;; this may or may not be the same as above depending on doublecheck:
2602 (goto-char allout-recent-prefix-beginning
))))
2603 ;;;_ > allout-this-or-next-heading
2604 (defun allout-this-or-next-heading ()
2605 "Position cursor on current or next heading."
2606 ;; A throwaway non-macro that is defined after allout-next-heading
2607 ;; and usable by allout-mode.
2608 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2609 ;;;_ > allout-previous-heading ()
2610 (defun allout-previous-heading ()
2611 "Move to the prior (possibly invisible) heading line.
2613 Return the location of the beginning of the heading, or nil if not found.
2615 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2619 (let ((start-point (point)))
2620 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2621 (allout-goto-prefix)
2623 (when (or (re-search-backward allout-line-boundary-regexp nil
0)
2624 (looking-at allout-bob-regexp
))
2625 (goto-char (allout-prefix-data))
2626 (if (and (allout-do-doublecheck)
2627 (allout-aberrant-container-p))
2628 (or (allout-previous-heading)
2629 (and (goto-char start-point
)
2630 ;; recalibrate allout-recent-*:
2634 ;;;_ > allout-get-invisibility-overlay ()
2635 (defun allout-get-invisibility-overlay ()
2636 "Return the overlay at point that dictates allout invisibility."
2637 (let ((overlays (overlays-at (point)))
2639 (while (and overlays
(not got
))
2640 (if (equal (overlay-get (car overlays
) 'invisible
) 'allout
)
2641 (setq got
(car overlays
))
2644 ;;;_ > allout-back-to-visible-text ()
2645 (defun allout-back-to-visible-text ()
2646 "Move to most recent prior character that is visible, and return point."
2647 (if (allout-hidden-p)
2648 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2651 ;;;_ - Subtree Charting
2652 ;;;_ " These routines either produce or assess charts, which are
2653 ;;; nested lists of the locations of topics within a subtree.
2655 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2656 ;;; for elaborate, compound assessment and adjustment of a subtree.
2658 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2659 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth
)
2660 "Produce a location \"chart\" of subtopics of the containing topic.
2662 Optional argument LEVELS specifies a depth limit (relative to start
2663 depth) for the chart. Null LEVELS means no limit.
2665 When optional argument VISIBLE is non-nil, the chart includes
2666 only the visible subelements of the charted subjects.
2668 The remaining optional args are for internal use by the function.
2670 Point is left at the end of the subtree.
2672 Charts are used to capture outline structure, so that outline-altering
2673 routines need assess the structure only once, and then use the chart
2674 for their elaborate manipulations.
2676 The chart entries for the topics are in reverse order, so the
2677 last topic is listed first. The entry for each topic consists of
2678 an integer indicating the point at the beginning of the topic
2679 prefix. Charts for offspring consists of a list containing,
2680 recursively, the charts for the respective subtopics. The chart
2681 for a topics' offspring precedes the entry for the topic itself.
2683 The other function parameters are for internal recursion, and should
2684 not be specified by external callers. ORIG-DEPTH is depth of topic at
2685 starting point, and PREV-DEPTH is depth of prior topic."
2687 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
2690 (if original
; Just starting?
2691 ; Register initial settings and
2692 ; position to first offspring:
2693 (progn (setq orig-depth
(allout-depth))
2694 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
2696 (allout-next-visible-heading 1)
2697 (allout-next-heading))))
2699 ;; Loop over the current levels' siblings. Besides being more
2700 ;; efficient than tail-recursing over a level, it avoids exceeding
2701 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2703 ;; Probably would speed things up to implement loop-based stack
2704 ;; operation rather than recursing for lower levels. Bah.
2706 (while (and (not (eobp))
2707 ; Still within original topic?
2708 (< orig-depth
(setq curr-depth allout-recent-depth
))
2709 (cond ((= prev-depth curr-depth
)
2710 ;; Register this one and move on:
2711 (setq chart
(cons allout-recent-prefix-beginning chart
))
2712 (if (and levels
(<= levels
1))
2713 ;; At depth limit -- skip sublevels:
2714 (or (allout-next-sibling curr-depth
)
2715 ;; or no more siblings -- proceed to
2716 ;; next heading at lesser depth:
2717 (while (and (<= curr-depth
2718 allout-recent-depth
)
2720 (allout-next-visible-heading 1)
2721 (allout-next-heading)))))
2723 (allout-next-visible-heading 1)
2724 (allout-next-heading))))
2726 ((and (< prev-depth curr-depth
)
2729 ;; Recurse on deeper level of curr topic:
2731 (cons (allout-chart-subtree (and levels
2737 ;; ... then continue with this one.
2740 ;; ... else nil if we've ascended back to prev-depth.
2744 (if original
; We're at the last sibling on
2745 ; the original level. Position
2747 (progn (and (not (eobp)) (forward-char -
1))
2748 (and (= (preceding-char) ?
\n)
2749 (= (aref (buffer-substring (max 1 (- (point) 3))
2754 (setq allout-recent-end-of-subtree
(point))))
2756 chart
; (nreverse chart) not necessary,
2757 ; and maybe not preferable.
2759 ;;;_ > allout-chart-siblings (&optional start end)
2760 (defun allout-chart-siblings (&optional start end
)
2761 "Produce a list of locations of this and succeeding sibling topics.
2762 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2763 for an explanation of charts."
2765 (when (allout-goto-prefix-doublechecked)
2766 (let ((chart (list (point))))
2767 (while (allout-next-sibling)
2768 (setq chart
(cons (point) chart
)))
2769 (if chart
(setq chart
(nreverse chart
)))))))
2770 ;;;_ > allout-chart-to-reveal (chart depth)
2771 (defun allout-chart-to-reveal (chart depth
)
2773 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2775 If DEPTH is nil, include hidden points at any depth.
2777 Note that point can be left at any of the points on chart, or at the
2781 (while (and (or (null depth
) (> depth
0))
2783 (setq here
(car chart
))
2785 (let ((further (allout-chart-to-reveal here
(if (null depth
)
2788 ;; We're on the start of a subtree -- recurse with it, if there's
2789 ;; more depth to go:
2790 (if further
(setq result
(append further result
)))
2791 (setq chart
(cdr chart
)))
2793 (if (allout-hidden-p)
2794 (setq result
(cons here result
)))
2795 (setq chart
(cdr chart
))))
2797 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2798 ;; (defun allout-chart-spec (chart spec &optional exposing)
2799 ;; "Not yet (if ever) implemented.
2801 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2803 ;; Exposure spec indicates the locations to be exposed and the prescribed
2804 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2805 ;; indicating pending concealment, anything higher indicating depth to
2806 ;; which subtopic headers should be exposed, and negative numbers
2807 ;; indicating (negative of) the depth to which subtopic headers and
2808 ;; bodies should be exposed.
2810 ;; The produced list can have two types of entries. Bare numbers
2811 ;; indicate points in the buffer where topic headers that should be
2814 ;; - bare negative numbers indicates that the topic starting at the
2815 ;; point which is the negative of the number should be opened,
2816 ;; including their entries.
2817 ;; - bare positive values indicate that this topic header should be
2819 ;; - Lists signify the beginning and end points of regions that should
2820 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2823 ;; (cond ((listp spec)
2826 ;; (setq spec (cdr spec)))
2830 ;;;_ > allout-goto-prefix ()
2831 (defun allout-goto-prefix ()
2832 "Put point at beginning of immediately containing outline topic.
2834 Goes to most immediate subsequent topic if none immediately containing.
2836 Not sensitive to topic visibility.
2838 Returns the point at the beginning of the prefix, or nil if none."
2842 (while (and (not done
)
2843 (search-backward "\n" nil
1))
2845 (if (looking-at allout-regexp
)
2846 (setq done
(allout-prefix-data))
2849 (cond ((looking-at allout-regexp
)
2850 (allout-prefix-data))
2851 ((allout-next-heading))
2854 ;;;_ > allout-goto-prefix-doublechecked ()
2855 (defun allout-goto-prefix-doublechecked ()
2856 "Put point at beginning of immediately containing outline topic.
2858 Like `allout-goto-prefix', but shallow topics (according to
2859 `allout-doublecheck-at-and-shallower') are checked and
2860 disqualified for child containment discontinuity, according to
2861 `allout-aberrant-container-p'."
2862 (if (allout-goto-prefix)
2863 (if (and (allout-do-doublecheck)
2864 (allout-aberrant-container-p))
2865 (allout-previous-heading)
2868 ;;;_ > allout-end-of-prefix ()
2869 (defun allout-end-of-prefix (&optional ignore-decorations
)
2870 "Position cursor at beginning of header text.
2872 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2873 otherwise skip white space between bullet and ensuing text."
2875 (if (not (allout-goto-prefix-doublechecked))
2877 (goto-char allout-recent-prefix-end
)
2879 (if ignore-decorations
2881 (while (looking-at "[0-9]") (forward-char 1))
2882 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2883 ;; Reestablish where we are:
2884 (allout-current-depth)))
2885 ;;;_ > allout-current-bullet-pos ()
2886 (defun allout-current-bullet-pos ()
2887 "Return position of current (visible) topic's bullet."
2889 (if (not (allout-current-depth))
2891 (1- allout-recent-prefix-end
)))
2892 ;;;_ > allout-back-to-current-heading ()
2893 (defun allout-back-to-current-heading ()
2894 "Move to heading line of current topic, or beginning if not in a topic.
2896 If interactive, we position at the end of the prefix.
2898 Return value of resulting point, unless we started outside
2899 of (before any) topics, in which case we return nil."
2901 (allout-beginning-of-current-line)
2902 (let ((bol-point (point)))
2903 (if (allout-goto-prefix-doublechecked)
2904 (if (<= (point) bol-point
)
2906 (allout-end-of-prefix)
2908 (goto-char (point-min))
2910 ;;;_ > allout-back-to-heading ()
2911 (defalias 'allout-back-to-heading
'allout-back-to-current-heading
)
2912 ;;;_ > allout-pre-next-prefix ()
2913 (defun allout-pre-next-prefix ()
2914 "Skip forward to just before the next heading line.
2916 Returns that character position."
2918 (if (allout-next-heading)
2919 (goto-char (1- allout-recent-prefix-beginning
))))
2920 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2921 (defun allout-end-of-subtree (&optional current include-trailing-blank
)
2922 "Put point at the end of the last leaf in the containing topic.
2924 Optional CURRENT means put point at the end of the containing
2927 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2928 any, as part of the subtree. Otherwise, that trailing blank will be
2929 excluded as delimiting whitespace between topics.
2931 Returns the value of point."
2934 (allout-back-to-current-heading)
2935 (allout-goto-prefix-doublechecked))
2936 (let ((level allout-recent-depth
))
2937 (allout-next-heading)
2938 (while (and (not (eobp))
2939 (> allout-recent-depth level
))
2940 (allout-next-heading))
2942 (allout-end-of-entry)
2944 (if (and (not include-trailing-blank
) (= ?
\n (preceding-char)))
2946 (setq allout-recent-end-of-subtree
(point))))
2947 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2948 (defun allout-end-of-current-subtree (&optional include-trailing-blank
)
2950 "Put point at end of last leaf in currently visible containing topic.
2952 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2953 any, as part of the subtree. Otherwise, that trailing blank will be
2954 excluded as delimiting whitespace between topics.
2956 Returns the value of point."
2958 (allout-end-of-subtree t include-trailing-blank
))
2959 ;;;_ > allout-beginning-of-current-entry ()
2960 (defun allout-beginning-of-current-entry ()
2961 "When not already there, position point at beginning of current topic header.
2963 If already there, move cursor to bullet for hot-spot operation.
2964 \(See `allout-mode' doc string for details of hot-spot operation.)"
2966 (let ((start-point (point)))
2967 (move-beginning-of-line 1)
2968 (if (< 0 (allout-current-depth))
2969 (goto-char allout-recent-prefix-end
)
2970 (goto-char (point-min)))
2971 (allout-end-of-prefix)
2972 (if (and (interactive-p)
2973 (= (point) start-point
))
2974 (goto-char (allout-current-bullet-pos)))))
2975 ;;;_ > allout-end-of-entry (&optional inclusive)
2976 (defun allout-end-of-entry (&optional inclusive
)
2977 "Position the point at the end of the current topics' entry.
2979 Optional INCLUSIVE means also include trailing empty line, if any. When
2980 unset, whitespace between items separates them even when the items are
2983 (allout-pre-next-prefix)
2984 (if (and (not inclusive
) (not (bobp)) (= ?
\n (preceding-char)))
2987 ;;;_ > allout-end-of-current-heading ()
2988 (defun allout-end-of-current-heading ()
2990 (allout-beginning-of-current-entry)
2991 (search-forward "\n" nil t
)
2993 (defalias 'allout-end-of-heading
'allout-end-of-current-heading
)
2994 ;;;_ > allout-get-body-text ()
2995 (defun allout-get-body-text ()
2996 "Return the unmangled body text of the topic immediately containing point."
2998 (allout-end-of-prefix)
2999 (if (not (search-forward "\n" nil t
))
3002 (let ((pre-body (point)))
3005 (allout-end-of-entry t
)
3006 (if (not (= pre-body
(point)))
3007 (buffer-substring-no-properties (1+ pre-body
) (point))))
3014 ;;;_ > allout-ascend-to-depth (depth)
3015 (defun allout-ascend-to-depth (depth)
3016 "Ascend to depth DEPTH, returning depth if successful, nil if not."
3017 (if (and (> depth
0)(<= depth
(allout-depth)))
3018 (let (last-ascended)
3019 (while (and (< depth allout-recent-depth
)
3020 (setq last-ascended
(allout-ascend))))
3021 (goto-char allout-recent-prefix-beginning
)
3022 (if (interactive-p) (allout-end-of-prefix))
3023 (and last-ascended allout-recent-depth
))))
3024 ;;;_ > allout-ascend ()
3025 (defun allout-ascend (&optional dont-move-if-unsuccessful
)
3026 "Ascend one level, returning resulting depth if successful, nil if not.
3028 Point is left at the beginning of the level whether or not
3029 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
3030 which case point is returned to its original starting location."
3031 (if dont-move-if-unsuccessful
3032 (setq dont-move-if-unsuccessful
(point)))
3034 (if (allout-beginning-of-level)
3035 (let ((bolevel (point))
3036 (bolevel-depth allout-recent-depth
))
3037 (allout-previous-heading)
3038 (cond ((< allout-recent-depth bolevel-depth
)
3039 allout-recent-depth
)
3040 ((= allout-recent-depth bolevel-depth
)
3041 (if dont-move-if-unsuccessful
3042 (goto-char dont-move-if-unsuccessful
))
3046 ;; some topic after very first is lower depth than first:
3050 (if (interactive-p) (allout-end-of-prefix))))
3051 ;;;_ > allout-descend-to-depth (depth)
3052 (defun allout-descend-to-depth (depth)
3053 "Descend to depth DEPTH within current topic.
3055 Returning depth if successful, nil if not."
3056 (let ((start-point (point))
3057 (start-depth (allout-depth)))
3059 (and (> (allout-depth) 0)
3060 (not (= depth allout-recent-depth
)) ; ... not there yet
3061 (allout-next-heading) ; ... go further
3062 (< start-depth allout-recent-depth
))) ; ... still in topic
3063 (if (and (> (allout-depth) 0)
3064 (= allout-recent-depth depth
))
3066 (goto-char start-point
)
3069 ;;;_ > allout-up-current-level (arg)
3070 (defun allout-up-current-level (arg)
3071 "Move out ARG levels from current visible topic."
3073 (let ((start-point (point)))
3074 (allout-back-to-current-heading)
3075 (if (not (allout-ascend))
3076 (progn (goto-char start-point
)
3077 (error "Can't ascend past outermost level"))
3078 (if (interactive-p) (allout-end-of-prefix))
3079 allout-recent-prefix-beginning
)))
3082 ;;;_ > allout-next-sibling (&optional depth backward)
3083 (defun allout-next-sibling (&optional depth backward
)
3084 "Like `allout-forward-current-level', but respects invisible topics.
3086 Traverse at optional DEPTH, or current depth if none specified.
3088 Go backward if optional arg BACKWARD is non-nil.
3090 Return the start point of the new topic if successful, nil otherwise."
3092 (if (if backward
(bobp) (eobp))
3094 (let ((target-depth (or depth
(allout-depth)))
3095 (start-point (point))
3096 (start-prefix-beginning allout-recent-prefix-beginning
)
3101 ;; done too few single steps to resort to the leap routine:
3104 (not (if backward
(bobp) (eobp)))
3105 ;; still traversable:
3106 (if backward
(allout-previous-heading) (allout-next-heading))
3107 ;; we're below the target depth
3108 (> (setq last-depth allout-recent-depth
) target-depth
))
3109 (setq count
(1+ count
))
3110 (if (> count
7) ; lists are commonly 7 +- 2, right?-)
3113 (or (allout-next-sibling-leap target-depth backward
)
3115 (goto-char start-point
)
3116 (if depth
(allout-depth) target-depth
)
3119 (and (> (or last-depth
(allout-depth)) 0)
3120 (= allout-recent-depth target-depth
))
3121 (not (= start-prefix-beginning
3122 allout-recent-prefix-beginning
)))
3123 allout-recent-prefix-beginning
)
3125 (goto-char start-point
)
3126 (if depth
(allout-depth) target-depth
)
3128 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3129 (defun allout-next-sibling-leap (&optional depth backward
)
3130 "Like `allout-next-sibling', but by direct search for topic at depth.
3132 Traverse at optional DEPTH, or current depth if none specified.
3134 Go backward if optional arg BACKWARD is non-nil.
3136 Return the start point of the new topic if successful, nil otherwise.
3138 Costs more than regular `allout-next-sibling' for short traversals:
3140 - we have to check the prior (next, if travelling backwards)
3141 item to confirm connectivity with the prior topic, and
3142 - if confirmed, we have to reestablish the allout-recent-* settings with
3143 some extra navigation
3144 - if confirmation fails, we have to do more work to recover
3146 It is an increasingly big win when there are many intervening
3147 offspring before the next sibling, however, so
3148 `allout-next-sibling' resorts to this if it finds itself in that
3151 (if (if backward
(bobp) (eobp))
3153 (let* ((start-point (point))
3154 (target-depth (or depth
(allout-depth)))
3155 (search-whitespace-regexp nil
)
3156 (depth-biased (- target-depth
2))
3157 (expression (if (<= target-depth
1)
3158 allout-depth-one-regexp
3159 (format allout-depth-specific-regexp
3160 depth-biased depth-biased
)))
3164 (setq found
(save-match-data
3166 (re-search-backward expression nil
'to-limit
)
3168 (re-search-forward expression nil
'to-limit
))))
3169 (if (and found
(allout-aberrant-container-p))
3171 (setq done
(or found
(if backward
(bobp) (eobp)))))
3173 (progn (goto-char start-point
)
3175 ;; rationale: if any intervening items were at a lower depth, we
3176 ;; would now be on the first offspring at the target depth -- ie,
3177 ;; the preceeding item (per the search direction) must be at a
3178 ;; lesser depth. that's all we need to check.
3179 (if backward
(allout-next-heading) (allout-previous-heading))
3180 (if (< allout-recent-depth target-depth
)
3181 ;; return to start and reestablish allout-recent-*:
3183 (goto-char start-point
)
3187 ;; locate cursor and set allout-recent-*:
3188 (allout-goto-prefix))))))
3189 ;;;_ > allout-previous-sibling (&optional depth backward)
3190 (defun allout-previous-sibling (&optional depth backward
)
3191 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3193 Optional DEPTH specifies depth to traverse, default current depth.
3195 Optional BACKWARD reverses direction.
3197 Return depth if successful, nil otherwise."
3198 (allout-next-sibling depth
(not backward
))
3200 ;;;_ > allout-snug-back ()
3201 (defun allout-snug-back ()
3202 "Position cursor at end of previous topic.
3204 Presumes point is at the start of a topic prefix."
3205 (if (or (bobp) (eobp))
3208 (if (or (bobp) (not (= ?
\n (preceding-char))))
3212 ;;;_ > allout-beginning-of-level ()
3213 (defun allout-beginning-of-level ()
3214 "Go back to the first sibling at this level, visible or not."
3215 (allout-end-of-level 'backward
))
3216 ;;;_ > allout-end-of-level (&optional backward)
3217 (defun allout-end-of-level (&optional backward
)
3218 "Go to the last sibling at this level, visible or not."
3220 (let ((depth (allout-depth)))
3221 (while (allout-previous-sibling depth nil
))
3222 (prog1 allout-recent-depth
3223 (if (interactive-p) (allout-end-of-prefix)))))
3224 ;;;_ > allout-next-visible-heading (arg)
3225 (defun allout-next-visible-heading (arg)
3226 "Move to the next ARG'th visible heading line, backward if arg is negative.
3228 Move to buffer limit in indicated direction if headings are exhausted."
3231 (let* ((inhibit-field-text-motion t
)
3232 (backward (if (< arg
0) (setq arg
(* -
1 arg
))))
3233 (step (if backward -
1 1))
3238 ;; Boundary condition:
3239 (not (if backward
(bobp)(eobp)))
3240 ;; Move, skipping over all concealed lines in one fell swoop:
3241 (prog1 (condition-case nil
(or (line-move step
) t
)
3243 (allout-beginning-of-current-line))
3244 ;; Deal with apparent header line:
3246 (if (not (looking-at allout-regexp
))
3247 ;; not a header line, keep looking:
3249 (allout-prefix-data)
3250 (if (and (allout-do-doublecheck)
3251 (allout-aberrant-container-p))
3252 ;; skip this aberrant prospective header line:
3254 ;; this prospective headerline qualifies -- register:
3255 (setq got allout-recent-prefix-beginning
)
3256 ;; and break the loop:
3258 ;; Register this got, it may be the last:
3259 (if got
(setq prev got
))
3260 (setq arg
(1- arg
)))
3261 (cond (got ; Last move was to a prefix:
3262 (allout-end-of-prefix))
3263 (prev ; Last move wasn't, but prev was:
3265 (allout-end-of-prefix))
3266 ((not backward
) (end-of-line) nil
))))
3267 ;;;_ > allout-previous-visible-heading (arg)
3268 (defun allout-previous-visible-heading (arg)
3269 "Move to the previous heading line.
3271 With argument, repeats or can move forward if negative.
3272 A heading line is one that starts with a `*' (or that `allout-regexp'
3275 (prog1 (allout-next-visible-heading (- arg
))
3276 (if (interactive-p) (allout-end-of-prefix))))
3277 ;;;_ > allout-forward-current-level (arg)
3278 (defun allout-forward-current-level (arg)
3279 "Position point at the next heading of the same level.
3281 Takes optional repeat-count, goes backward if count is negative.
3283 Returns resulting position, else nil if none found."
3285 (let ((start-depth (allout-current-depth))
3287 (backward (> 0 arg
)))
3288 (if (= 0 start-depth
)
3289 (error "No siblings, not in a topic..."))
3290 (if backward
(setq arg
(* -
1 arg
)))
3291 (allout-back-to-current-heading)
3292 (while (and (not (zerop arg
))
3294 (allout-previous-sibling)
3295 (allout-next-sibling)))
3296 (setq arg
(1- arg
)))
3297 (if (not (interactive-p))
3299 (allout-end-of-prefix)
3300 (if (not (zerop arg
))
3301 (error "Hit %s level %d topic, traversed %d of %d requested"
3302 (if backward
"first" "last")
3304 (- (abs start-arg
) arg
)
3305 (abs start-arg
))))))
3306 ;;;_ > allout-backward-current-level (arg)
3307 (defun allout-backward-current-level (arg)
3308 "Inverse of `allout-forward-current-level'."
3311 (let ((current-prefix-arg (* -
1 arg
)))
3312 (call-interactively 'allout-forward-current-level
))
3313 (allout-forward-current-level (* -
1 arg
))))
3318 ;;;_ = allout-post-goto-bullet
3319 (defvar allout-post-goto-bullet nil
3320 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3322 When set, tells post-processing to reposition on topic bullet, and
3323 then unset it. Set by `allout-pre-command-business' when implementing
3324 hot-spot operation, where literal characters typed over a topic bullet
3325 are mapped to the command of the corresponding control-key on the
3326 `allout-mode-map'.")
3327 (make-variable-buffer-local 'allout-post-goto-bullet
)
3328 ;;;_ = allout-command-counter
3329 (defvar allout-command-counter
0
3330 "Counter that monotonically increases in allout-mode buffers.
3332 Set by `allout-pre-command-business', to support allout addons in
3333 coordinating with allout activity.")
3334 (make-variable-buffer-local 'allout-command-counter
)
3335 ;;;_ > allout-post-command-business ()
3336 (defun allout-post-command-business ()
3337 "Outline `post-command-hook' function.
3339 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3342 - Decrypt topic currently being edited if it was encrypted for a save."
3344 ; Apply any external change func:
3345 (if (not (allout-mode-p)) ; In allout-mode.
3348 (if (and (boundp 'allout-after-save-decrypt
)
3349 allout-after-save-decrypt
)
3350 (allout-after-saves-handler))
3352 ;; Implement allout-post-goto-bullet, if set:
3353 (if (and allout-post-goto-bullet
3354 (allout-current-bullet-pos))
3355 (progn (goto-char (allout-current-bullet-pos))
3356 (setq allout-post-goto-bullet nil
)))
3358 ;;;_ > allout-pre-command-business ()
3359 (defun allout-pre-command-business ()
3360 "Outline `pre-command-hook' function for outline buffers.
3362 Among other things, implements special behavior when the cursor is on the
3363 topic bullet character.
3365 When the cursor is on the bullet character, self-insert characters are
3366 reinterpreted as the corresponding control-character in the
3367 `allout-mode-map'. The `allout-mode' `post-command-hook' insures that
3368 the cursor which has moved as a result of such reinterpretation is
3369 positioned on the bullet character of the destination topic.
3371 The upshot is that you can get easy, single (ie, unmodified) key
3372 outline maneuvering operations by positioning the cursor on the bullet
3373 char. When in this mode you can use regular cursor-positioning
3374 command/keystrokes to relocate the cursor off of a bullet character to
3375 return to regular interpretation of self-insert characters."
3377 (if (not (allout-mode-p))
3379 ;; Increment allout-command-counter
3380 (setq allout-command-counter
(1+ allout-command-counter
))
3381 ;; Do hot-spot navigation.
3382 (if (and (eq this-command
'self-insert-command
)
3383 (eq (point)(allout-current-bullet-pos)))
3384 (allout-hotspot-key-handler))))
3385 ;;;_ > allout-hotspot-key-handler ()
3386 (defun allout-hotspot-key-handler ()
3387 "Catchall handling of key bindings in hot-spots.
3389 Translates unmodified keystrokes to corresponding allout commands, when
3390 they would qualify if prefixed with the allout-command-prefix, and sets
3391 this-command accordingly.
3393 Returns the qualifying command, if any, else nil."
3395 (let* ((key-string (if (numberp last-command-char
)
3396 (char-to-string last-command-char
)))
3397 (key-num (cond ((numberp last-command-char
) last-command-char
)
3398 ;; for XEmacs character type:
3399 ((and (fboundp 'characterp
)
3400 (apply 'characterp
(list last-command-char
)))
3401 (apply 'char-to-int
(list last-command-char
)))
3409 ;; exclude control chars and escape:
3411 (setq mapped-binding
3412 (or (and (assoc key-string allout-keybindings-list
)
3413 ;; translate literal membership on list:
3414 (cadr (assoc key-string allout-keybindings-list
)))
3415 ;; translate as a keybinding:
3416 (key-binding (vconcat allout-command-prefix
3418 (if (and (<= 97 key-num
) ; "a"
3419 (>= 122 key-num
)) ; "z"
3420 (- key-num
96) key-num
)))
3422 ;; Qualified as an allout command -- do hot-spot operation.
3423 (setq allout-post-goto-bullet t
)
3424 ;; accept-defaults nil, or else we'll get allout-item-icon-key-handler.
3425 (setq mapped-binding
(key-binding (char-to-string key-num
))))
3427 (while (keymapp mapped-binding
)
3428 (setq mapped-binding
3429 (lookup-key mapped-binding
(vector (read-char)))))
3432 (setq this-command mapped-binding
)))))
3434 ;;;_ > allout-find-file-hook ()
3435 (defun allout-find-file-hook ()
3436 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3438 See `allout-init' for setup instructions."
3439 (if (and allout-auto-activation
3440 (not (allout-mode-p))
3444 ;;;_ - Topic Format Assessment
3445 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3446 (defun allout-solicit-alternate-bullet (depth &optional current-bullet
)
3448 "Prompt for and return a bullet char as an alternative to the current one.
3450 Offer one suitable for current depth DEPTH as default."
3452 (let* ((default-bullet (or (and (stringp current-bullet
) current-bullet
)
3453 (allout-bullet-for-depth depth
)))
3454 (sans-escapes (regexp-sans-escapes allout-bullets-string
))
3457 (goto-char (allout-current-bullet-pos))
3458 (setq choice
(solicit-char-in-string
3459 (format "Select bullet: %s ('%s' default): "
3461 (substring-no-properties default-bullet
))
3465 (if (string= choice
"") default-bullet choice
))
3467 ;;;_ > allout-distinctive-bullet (bullet)
3468 (defun allout-distinctive-bullet (bullet)
3469 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3470 (string-match (regexp-quote bullet
) allout-distinctive-bullets-string
))
3471 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3472 (defun allout-numbered-type-prefix (&optional prefix
)
3473 "True if current header prefix bullet is numbered bullet."
3474 (and allout-numbered-bullet
3475 (string= allout-numbered-bullet
3477 (allout-get-prefix-bullet prefix
)
3478 (allout-get-bullet)))))
3479 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3480 (defun allout-encrypted-type-prefix (&optional prefix
)
3481 "True if current header prefix bullet is for an encrypted entry (body)."
3482 (and allout-topic-encryption-bullet
3483 (string= allout-topic-encryption-bullet
3485 (allout-get-prefix-bullet prefix
)
3486 (allout-get-bullet)))))
3487 ;;;_ > allout-bullet-for-depth (&optional depth)
3488 (defun allout-bullet-for-depth (&optional depth
)
3489 "Return outline topic bullet suited to optional DEPTH, or current depth."
3490 ;; Find bullet in plain-bullets-string modulo DEPTH.
3491 (if allout-stylish-prefixes
3492 (char-to-string (aref allout-plain-bullets-string
3493 (%
(max 0 (- depth
2))
3494 allout-plain-bullets-string-len
)))
3495 allout-primary-bullet
)
3498 ;;;_ - Topic Production
3499 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3500 (defun allout-make-topic-prefix (&optional prior-bullet
3506 ;; Depth null means use current depth, non-null means we're either
3507 ;; opening a new topic after current topic, lower or higher, or we're
3508 ;; changing level of current topic.
3509 ;; Solicit dominates specified bullet-char.
3511 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3513 All the arguments are optional.
3515 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3516 nil if none. This bullet may be preserved (other options
3517 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3520 Second arg NEW indicates that a new topic is being opened after the
3521 topic at point, if non-nil. Default bullet for new topics, eg, may
3522 be set (contingent to other args) to numbered bullets if previous
3523 sibling is one. The implication otherwise is that the current topic
3524 is being adjusted -- shifted or rebulleted -- and we don't consider
3525 bullet or previous sibling.
3527 Third arg DEPTH forces the topic prefix to that depth, regardless of
3528 the current topics' depth.
3530 If SOLICIT is non-nil, then the choice of bullet is solicited from
3531 user. If it's a character, then that character is offered as the
3532 default, otherwise the one suited to the context (according to
3533 distinction or depth) is offered. (This overrides other options,
3534 including, eg, a distinctive PRIOR-BULLET.) If non-nil, then the
3535 context-specific bullet is used.
3537 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3538 is non-nil *and* soliciting was not explicitly invoked. Then
3539 NUMBER-CONTROL non-nil forces prefix to either numbered or
3540 denumbered format, depending on the value of the sixth arg, INDEX.
3542 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3544 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3545 the prefix of the topic is forced to be numbered. Non-nil
3546 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3547 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3548 that the index for the numbered prefix will be derived, by counting
3549 siblings back to start of level. If INDEX is a number, then that
3550 number is used as the index for the numbered prefix (allowing, eg,
3551 sequential renumbering to not require this function counting back the
3552 index for each successive sibling)."
3554 ;; The options are ordered in likely frequence of use, most common
3555 ;; highest, least lowest. Ie, more likely to be doing prefix
3556 ;; adjustments than soliciting, and yet more than numbering.
3557 ;; Current prefix is least dominant, but most likely to be commonly
3563 (depth (or depth
(allout-depth)))
3564 (header-lead allout-header-prefix
)
3567 ;; Getting value for bullet char is practically the whole job:
3570 ; Simplest situation -- level 1:
3571 ((<= depth
1) (setq header-lead
"") allout-primary-bullet
)
3572 ; Simple, too: all asterisks:
3573 (allout-old-style-prefixes
3574 ;; Cheat -- make body the whole thing, null out header-lead and
3576 (setq body
(make-string depth
3577 (string-to-char allout-primary-bullet
)))
3578 (setq header-lead
"")
3581 ;; (Neither level 1 nor old-style, so we're space padding.
3582 ;; Sneak it in the condition of the next case, whatever it is.)
3584 ;; Solicitation overrides numbering and other cases:
3585 ((progn (setq body
(make-string (- depth
2) ?\
))
3586 ;; The actual condition:
3588 (let* ((got (allout-solicit-alternate-bullet depth solicit
)))
3589 ;; Gotta check whether we're numbering and got a numbered bullet:
3590 (setq numbering
(and allout-numbered-bullet
3591 (not (and number-control
(not index
)))
3592 (string= got allout-numbered-bullet
)))
3593 ;; Now return what we got, regardless:
3596 ;; Numbering invoked through args:
3597 ((and allout-numbered-bullet number-control
)
3598 (if (setq numbering
(not (setq denumbering
(not index
))))
3599 allout-numbered-bullet
3600 (if (and prior-bullet
3601 (not (string= allout-numbered-bullet
3604 (allout-bullet-for-depth depth
))))
3606 ;;; Neither soliciting nor controlled numbering ;;;
3607 ;;; (may be controlled denumbering, tho) ;;;
3609 ;; Check wrt previous sibling:
3610 ((and new
; only check for new prefixes
3611 (<= depth
(allout-depth))
3612 allout-numbered-bullet
; ... & numbering enabled
3614 (let ((sibling-bullet
3616 ;; Locate correct sibling:
3617 (or (>= depth
(allout-depth))
3618 (allout-ascend-to-depth depth
))
3619 (allout-get-bullet))))
3620 (if (and sibling-bullet
3621 (string= allout-numbered-bullet sibling-bullet
))
3622 (setq numbering sibling-bullet
)))))
3624 ;; Distinctive prior bullet?
3626 (allout-distinctive-bullet prior-bullet
)
3627 ;; Either non-numbered:
3628 (or (not (and allout-numbered-bullet
3629 (string= prior-bullet allout-numbered-bullet
)))
3630 ;; or numbered, and not denumbering:
3631 (setq numbering
(not denumbering
)))
3635 ;; Else, standard bullet per depth:
3636 ((allout-bullet-for-depth depth
)))))
3642 (format "%d" (cond ((and index
(numberp index
)) index
)
3643 (new (1+ (allout-sibling-index depth
)))
3644 ((allout-sibling-index))))))
3647 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3648 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet
)
3649 "Open a new topic at depth DEPTH.
3651 New topic is situated after current one, unless optional flag BEFORE
3652 is non-nil, or unless current line is completely empty -- lacking even
3653 whitespace -- in which case open is done on the current line.
3655 When adding an offspring, it will be added immediately after the parent if
3656 the other offspring are exposed, or after the last child if the offspring
3657 are hidden. (The intervening offspring will be exposed in the latter
3660 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3664 - Creation of new topics is with respect to the visible topic
3665 containing the cursor, regardless of intervening concealed ones.
3667 - New headers are generally created after/before the body of a
3668 topic. However, they are created right at cursor location if the
3669 cursor is on a blank line, even if that breaks the current topic
3670 body. This is intentional, to provide a simple means for
3671 deliberately dividing topic bodies.
3673 - Double spacing of topic lists is preserved. Also, the first
3674 level two topic is created double-spaced (and so would be
3675 subsequent siblings, if that's left intact). Otherwise,
3676 single-spacing is used.
3678 - Creation of sibling or nested topics is with respect to the topic
3679 you're starting from, even when creating backwards. This way you
3680 can easily create a sibling in front of the current topic without
3681 having to go to its preceding sibling, and then open forward
3684 (allout-beginning-of-current-line)
3686 (let* ((inhibit-field-text-motion t
)
3687 (depth (+ (allout-current-depth) relative-depth
))
3688 (opening-on-blank (if (looking-at "^\$")
3689 (not (setq before nil
))))
3690 ;; bunch o vars set while computing ref-topic
3694 (ref-topic (save-excursion
3695 (cond ((< relative-depth
0)
3696 (allout-ascend-to-depth depth
))
3697 ((>= relative-depth
1) nil
)
3698 (t (allout-back-to-current-heading)))
3699 (setq ref-depth allout-recent-depth
)
3701 (if (> allout-recent-prefix-end
1)
3702 (allout-recent-bullet)
3704 (setq opening-numbered
3706 (and allout-numbered-bullet
3707 (or (<= relative-depth
0)
3708 (allout-descend-to-depth depth
))
3709 (if (allout-numbered-type-prefix)
3710 allout-numbered-bullet
))))
3716 (if (not opening-on-blank
)
3717 ; Positioning and vertical
3718 ; padding -- only if not
3721 (goto-char ref-topic
)
3722 (setq dbl-space
; Determine double space action:
3723 (or (and (<= relative-depth
0) ; not descending;
3725 ;; at b-o-b or preceded by a blank line?
3726 (or (> 0 (forward-line -
1))
3727 (looking-at "^\\s-*$")
3730 ;; succeeded by a blank line?
3731 (allout-end-of-current-subtree)
3732 (looking-at "\n\n")))
3733 (and (= ref-depth
1)
3737 ;; Don't already have following
3738 ;; vertical padding:
3739 (not (allout-pre-next-prefix)))))))
3741 ;; Position to prior heading, if inserting backwards, and not
3743 (if (and before
(>= relative-depth
0))
3744 (progn (allout-back-to-current-heading)
3745 (setq doing-beginning
(bobp))
3747 (allout-previous-heading)))
3748 (if (and before
(bobp))
3751 (if (<= relative-depth
0)
3752 ;; Not going inwards, don't snug up:
3758 (progn (end-of-line)
3759 (allout-pre-next-prefix)
3760 (while (and (= ?
\n (following-char))
3765 (if (not (looking-at "^$"))
3767 (allout-end-of-current-subtree)
3768 (if (looking-at "\n\n") (forward-char 1))))
3769 ;; Going inwards -- double-space if first offspring is
3770 ;; double-spaced, otherwise snug up.
3771 (allout-end-of-entry)
3775 (allout-beginning-of-current-line)
3778 ;; Blank lines between current header body and next
3779 ;; header -- get to last substantive (non-white-space)
3781 (progn (setq dbl-space t
)
3782 (re-search-backward "[^ \t\n]" nil t
)))
3783 (if (looking-at "\n\n")
3786 (allout-next-heading)
3787 (when (> allout-recent-depth ref-depth
)
3788 ;; This is an offspring.
3790 (looking-at "^\\s-*$")))
3791 (progn (forward-line 1)
3794 (allout-end-of-current-line))
3796 ;;(if doing-beginning (goto-char doing-beginning))
3798 ;; We insert a newline char rather than using open-line to
3799 ;; avoid rear-stickiness inheritence of read-only property.
3800 (progn (if (and (not (> depth ref-depth
))
3803 (if (and (not dbl-space
) (> depth ref-depth
))
3809 (if (and dbl-space
(not (> relative-depth
0)))
3811 (if (and (not (eobp))
3814 ;; bolp doesnt detect concealed
3815 ;; trailing newlines, compensate:
3818 (allout-hidden-p)))))
3821 (setq start
(point))
3822 (insert (concat (allout-make-topic-prefix opening-numbered t depth
)
3824 (setq end
(1+ (point)))
3826 (allout-rebullet-heading (and offer-recent-bullet ref-bullet
)
3828 (if (> relative-depth
0)
3829 (save-excursion (goto-char ref-topic
)
3830 (allout-show-children)))
3833 (run-hook-with-args 'allout-structure-added-hook start end
)
3837 ;;;_ > allout-open-subtopic (arg)
3838 (defun allout-open-subtopic (arg)
3839 "Open new topic header at deeper level than the current one.
3841 Negative universal arg means to open deeper, but place the new topic
3842 prior to the current one."
3844 (allout-open-topic 1 (> 0 arg
) (< 1 arg
)))
3845 ;;;_ > allout-open-sibtopic (arg)
3846 (defun allout-open-sibtopic (arg)
3847 "Open new topic header at same level as the current one.
3849 Positive universal arg means to use the bullet of the prior sibling.
3851 Negative universal arg means to place the new topic prior to the current
3854 (allout-open-topic 0 (> 0 arg
) (not (= 1 arg
))))
3855 ;;;_ > allout-open-supertopic (arg)
3856 (defun allout-open-supertopic (arg)
3857 "Open new topic header at shallower level than the current one.
3859 Negative universal arg means to open shallower, but place the new
3860 topic prior to the current one."
3863 (allout-open-topic -
1 (> 0 arg
) (< 1 arg
)))
3865 ;;;_ - Outline Alteration
3866 ;;;_ : Topic Modification
3867 ;;;_ = allout-former-auto-filler
3868 (defvar allout-former-auto-filler nil
3869 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3870 ;;;_ > allout-auto-fill ()
3871 (defun allout-auto-fill ()
3872 "`allout-mode' autofill function.
3874 Maintains outline hanging topic indentation if
3875 `allout-use-hanging-indents' is set."
3877 (when (not allout-inhibit-auto-fill
)
3878 (let ((fill-prefix (if allout-use-hanging-indents
3879 ;; Check for topic header indentation:
3883 (if (looking-at allout-regexp
)
3884 ;; ... construct indentation to account for
3885 ;; length of topic prefix:
3886 (make-string (progn (allout-end-of-prefix)
3889 (use-auto-fill-function (or allout-outside-normal-auto-fill-function
3892 (if (or allout-former-auto-filler allout-use-hanging-indents
)
3893 (funcall use-auto-fill-function
)))))
3894 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3895 (defun allout-reindent-body (old-depth new-depth
&optional number
)
3896 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3898 Optional arg NUMBER indicates numbering is being added, and it must
3901 Note that refill of indented paragraphs is not done."
3904 (allout-end-of-prefix)
3905 (let* ((new-margin (current-column))
3906 excess old-indent-begin old-indent-end
3907 ;; We want the column where the header-prefix text started
3908 ;; *before* the prefix was changed, so we infer it relative
3909 ;; to the new margin and the shift in depth:
3910 (old-margin (+ old-depth
(- new-margin new-depth
))))
3912 ;; Process lines up to (but excluding) next topic header:
3916 (and (re-search-forward "\n\\(\\s-*\\)"
3919 ;; Register the indent data, before we reset the
3920 ;; match data with a subsequent `looking-at':
3921 (setq old-indent-begin
(match-beginning 1)
3922 old-indent-end
(match-end 1))
3923 (not (looking-at allout-regexp
)))
3924 (if (> 0 (setq excess
(- (- old-indent-end old-indent-begin
)
3926 ;; Text starts left of old margin -- don't adjust:
3928 ;; Text was hanging at or right of old left margin --
3929 ;; reindent it, preserving its existing indentation
3930 ;; beyond the old margin:
3931 (delete-region old-indent-begin old-indent-end
)
3932 (indent-to (+ new-margin excess
(current-column))))))))))
3933 ;;;_ > allout-rebullet-current-heading (arg)
3934 (defun allout-rebullet-current-heading (arg)
3935 "Solicit new bullet for current visible heading."
3937 (let ((initial-col (current-column))
3938 (on-bullet (eq (point)(allout-current-bullet-pos)))
3940 (backwards (if (< arg
0)
3941 (setq arg
(* arg -
1)))))
3943 (save-excursion (allout-back-to-current-heading)
3944 (allout-end-of-prefix)
3945 (setq from allout-recent-prefix-beginning
3946 to allout-recent-prefix-end
)
3947 (allout-rebullet-heading t
;;; solicit
3949 nil
;;; number-control
3951 t
) ;;; do-successors
3952 (run-hook-with-args 'allout-exposure-change-hook
3957 (setq initial-col nil
) ; Override positioning back to init col
3959 (allout-next-visible-heading 1)
3960 (allout-goto-prefix-doublechecked)
3961 (allout-next-visible-heading -
1))))
3963 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
3964 (initial-col (move-to-column initial-col
)))))
3965 ;;;_ > allout-rebullet-heading (&optional solicit ...)
3966 (defun allout-rebullet-heading (&optional solicit
3972 "Adjust bullet of current topic prefix.
3974 All args are optional.
3976 If SOLICIT is non-nil, then the choice of bullet is solicited from
3977 user. If it's a character, then that character is offered as the
3978 default, otherwise the one suited to the context (according to
3979 distinction or depth) is offered. If non-nil, then the
3980 context-specific bullet is just used.
3982 Second arg DEPTH forces the topic prefix to that depth, regardless
3983 of the topic's current depth.
3985 Third arg NUMBER-CONTROL can force the prefix to or away from
3986 numbered form. It has effect only if `allout-numbered-bullet' is
3987 non-nil and soliciting was not explicitly invoked (via first arg).
3988 Its effect, numbering or denumbering, then depends on the setting
3989 of the fourth arg, INDEX.
3991 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
3992 prefix of the topic is forced to be non-numbered. Null index and
3993 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
3994 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
3995 INDEX is a number, then that number is used for the numbered
3996 prefix. Non-nil and non-number means that the index for the
3997 numbered prefix will be derived by allout-make-topic-prefix.
3999 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
4002 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
4003 and `allout-numbered-bullet', which all affect the behavior of
4006 (let* ((current-depth (allout-depth))
4007 (new-depth (or new-depth current-depth
))
4008 (mb allout-recent-prefix-beginning
)
4009 (me allout-recent-prefix-end
)
4010 (current-bullet (buffer-substring-no-properties (- me
1) me
))
4011 (has-annotation (get-text-property mb
'allout-was-hidden
))
4012 (new-prefix (allout-make-topic-prefix current-bullet
4019 ;; Is new one is identical to old?
4020 (if (and (= current-depth new-depth
)
4021 (string= current-bullet
4022 (substring new-prefix
(1- (length new-prefix
)))))
4026 ;; New prefix probably different from old:
4027 ; get rid of old one:
4028 (allout-unprotected (delete-region mb me
))
4030 ; Dispense with number if
4031 ; numbered-bullet prefix:
4033 (if (and allout-numbered-bullet
4034 (string= allout-numbered-bullet current-bullet
)
4035 (looking-at "[0-9]+"))
4037 (delete-region (match-beginning 0)(match-end 0)))))
4039 ;; convey 'allout-was-hidden annotation, if original had it:
4041 (put-text-property 0 (length new-prefix
) 'allout-was-hidden t
4044 ; Put in new prefix:
4045 (allout-unprotected (insert new-prefix
))
4047 ;; Reindent the body if elected, margin changed, and not encrypted body:
4048 (if (and allout-reindent-bodies
4049 (not (= new-depth current-depth
))
4050 (not (allout-encrypted-topic-p)))
4051 (allout-reindent-body current-depth new-depth
))
4053 ;; Recursively rectify successive siblings of orig topic if
4054 ;; caller elected for it:
4057 (while (allout-next-sibling new-depth nil
)
4059 (cond ((numberp index
) (1+ index
))
4060 ((not number-control
) (allout-sibling-index))))
4061 (if (allout-numbered-type-prefix)
4062 (allout-rebullet-heading nil
;;; solicit
4063 new-depth
;;; new-depth
4064 number-control
;;; number-control
4066 nil
))))) ;;;(dont!)do-successors
4067 ) ; (if (and (= current-depth new-depth)...))
4068 ) ; let* ((current-depth (allout-depth))...)
4070 ;;;_ > allout-rebullet-topic (arg)
4071 (defun allout-rebullet-topic (arg &optional sans-offspring
)
4072 "Rebullet the visible topic containing point and all contained subtopics.
4074 Descends into invisible as well as visible topics, however.
4076 When optional SANS-OFFSPRING is non-nil, subtopics are not
4077 shifted. (Shifting a topic outwards without shifting its
4078 offspring is disallowed, since this would create a \"containment
4079 discontinuity\", where the depth difference between a topic and
4080 its immediate offspring is greater than one.)
4082 With repeat count, shift topic depth by that amount."
4084 (let ((start-col (current-column)))
4087 (cond ((null arg
) (setq arg
0))
4088 ((listp arg
) (setq arg
(car arg
))))
4089 ;; Fill the user in, in case we're shifting a big topic:
4090 (if (not (zerop arg
)) (message "Shifting..."))
4091 (allout-back-to-current-heading)
4092 (if (<= (+ allout-recent-depth arg
) 0)
4093 (error "Attempt to shift topic below level 1"))
4094 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring
)
4095 (if (not (zerop arg
)) (message "Shifting... done.")))
4096 (move-to-column (max 0 (+ start-col arg
)))))
4097 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4098 (defun allout-rebullet-topic-grunt (&optional relative-depth
4104 "Like `allout-rebullet-topic', but on nearest containing topic
4107 See `allout-rebullet-heading' for rebulleting behavior.
4109 All arguments are optional.
4111 First arg RELATIVE-DEPTH means to shift the depth of the entire
4114 Several subsequent args are for internal recursive use by the function
4115 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4117 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4118 are not shifted. (Shifting a topic outwards without shifting
4119 its offspring is disallowed, since this would create a
4120 \"containment discontinuity\", where the depth difference between
4121 a topic and its immediate offspring is greater than one.)"
4123 ;; XXX the recursion here is peculiar, and in general the routine may
4124 ;; need simplification with refactoring.
4126 (if (and sans-offspring
4128 (< relative-depth
0))
4129 (error (concat "Attempt to shift topic outwards without offspring,"
4130 " would cause containment discontinuity.")))
4132 (let* ((relative-depth (or relative-depth
0))
4133 (new-depth (allout-depth))
4134 (starting-depth (or starting-depth new-depth
))
4135 (on-starting-call (null starting-point
))
4137 ;; Leave index null on starting call, so rebullet-heading
4138 ;; calculates it at what might be new depth:
4139 (and (or (zerop relative-depth
)
4140 (not on-starting-call
))
4141 (allout-sibling-index))))
4142 (starting-index index
)
4143 (moving-outwards (< 0 relative-depth
))
4144 (starting-point (or starting-point
(point)))
4145 (local-point (point)))
4147 ;; Sanity check for excessive promotion done only on starting call:
4148 (and on-starting-call
4150 (> 0 (+ starting-depth relative-depth
))
4151 (error "Attempt to shift topic out beyond level 1"))
4153 (cond ((= starting-depth new-depth
)
4154 ;; We're at depth to work on this one.
4156 ;; When shifting out we work on the children before working on
4157 ;; the parent to avoid interim `allout-aberrant-container-p'
4158 ;; aberrancy, and vice-versa when shifting in:
4159 (if (>= relative-depth
0)
4160 (allout-rebullet-heading nil
4161 (+ starting-depth relative-depth
)
4164 nil
)) ;;; do-successors
4165 (when (not sans-offspring
)
4166 ;; ... and work on subsequent ones which are at greater depth:
4168 (allout-next-heading)
4169 (while (and (not (eobp))
4170 (< starting-depth
(allout-depth)))
4171 (setq index
(1+ index
))
4172 (allout-rebullet-topic-grunt relative-depth
4176 (when (< relative-depth
0)
4178 (goto-char local-point
)
4179 (allout-rebullet-heading nil
;;; solicit
4180 (+ starting-depth relative-depth
)
4183 nil
)))) ;;; do-successors
4185 ((< starting-depth new-depth
)
4186 ;; Rare case -- subtopic more than one level deeper than parent.
4187 ;; Treat this one at an even deeper level:
4188 (allout-rebullet-topic-grunt relative-depth
4194 (if on-starting-call
4196 ;; Rectify numbering of former siblings of the adjusted topic,
4197 ;; if topic has changed depth
4198 (if (or do-successors
4199 (and (not (zerop relative-depth
))
4200 (or (= allout-recent-depth starting-depth
)
4201 (= allout-recent-depth
(+ starting-depth
4203 (allout-rebullet-heading nil nil nil nil t
))
4204 ;; Now rectify numbering of new siblings of the adjusted topic,
4205 ;; if depth has been changed:
4206 (progn (goto-char starting-point
)
4207 (if (not (zerop relative-depth
))
4208 (allout-rebullet-heading nil nil nil nil t
)))))
4211 ;;;_ > allout-renumber-to-depth (&optional depth)
4212 (defun allout-renumber-to-depth (&optional depth
)
4213 "Renumber siblings at current depth.
4215 Affects superior topics if optional arg DEPTH is less than current depth.
4217 Returns final depth."
4219 ;; Proceed by level, processing subsequent siblings on each,
4220 ;; ascending until we get shallower than the start depth:
4222 (let ((ascender (allout-depth))
4224 (while (and (not (eobp))
4226 (>= allout-recent-depth depth
)
4227 (>= ascender depth
))
4228 ; Skip over all topics at
4229 ; lesser depths, which can not
4230 ; have been disturbed:
4231 (while (and (not (setq was-eobp
(eobp)))
4232 (> allout-recent-depth ascender
))
4233 (allout-next-heading))
4234 ; Prime ascender for ascension:
4235 (setq ascender
(1- allout-recent-depth
))
4236 (if (>= allout-recent-depth depth
)
4237 (allout-rebullet-heading nil
;;; solicit
4239 nil
;;; number-control
4241 t
)) ;;; do-successors
4242 (if was-eobp
(goto-char (point-max)))))
4243 allout-recent-depth
)
4244 ;;;_ > allout-number-siblings (&optional denumber)
4245 (defun allout-number-siblings (&optional denumber
)
4246 "Assign numbered topic prefix to this topic and its siblings.
4248 With universal argument, denumber -- assign default bullet to this
4249 topic and its siblings.
4251 With repeated universal argument (`^U^U'), solicit bullet for each
4252 rebulleting each topic at this level."
4257 (allout-back-to-current-heading)
4258 (allout-beginning-of-level)
4259 (let ((depth allout-recent-depth
)
4260 (index (if (not denumber
) 1))
4261 (use-bullet (equal '(16) denumber
))
4264 (allout-rebullet-heading use-bullet
;;; solicit
4266 t
;;; number-control
4268 nil
) ;;; do-successors
4269 (if index
(setq index
(1+ index
)))
4270 (setq more
(allout-next-sibling depth nil
))))))
4271 ;;;_ > allout-shift-in (arg)
4272 (defun allout-shift-in (arg)
4273 "Increase depth of current heading and any items collapsed within it.
4275 With a negative argument, the item is shifted out using
4276 `allout-shift-out', instead.
4278 With an argument greater than one, shift-in the item but not its
4279 offspring, making the item into a sibling of its former children,
4280 and a child of sibling that formerly preceeded it.
4282 You are not allowed to shift the first offspring of a topic
4283 inwards, because that would yield a \"containment
4284 discontinuity\", where the depth difference between a topic and
4285 its immediate offspring is greater than one. The first topic in
4286 the file can be adjusted to any positive depth, however."
4290 (allout-shift-out (* arg -
1))
4291 ;; refuse to create a containment discontinuity:
4293 (allout-back-to-current-heading)
4295 (let* ((current-depth allout-recent-depth
)
4296 (start-point (point))
4297 (predecessor-depth (progn
4299 (allout-goto-prefix-doublechecked)
4300 (if (< (point) start-point
)
4303 (if (and (> predecessor-depth
0)
4304 (> (1+ current-depth
)
4305 (1+ predecessor-depth
)))
4306 (error (concat "Disallowed shift deeper than"
4307 " containing topic's children."))
4308 (allout-back-to-current-heading)
4309 (if (< allout-recent-depth
(1+ current-depth
))
4310 (allout-show-children))))))
4311 (let ((where (point)))
4312 (allout-rebullet-topic 1 (and (> arg
1) 'sans-offspring
))
4313 (run-hook-with-args 'allout-structure-shifted-hook arg where
))))
4314 ;;;_ > allout-shift-out (arg)
4315 (defun allout-shift-out (arg)
4316 "Decrease depth of current heading and any topics collapsed within it.
4317 This will make the item a sibling of its former container.
4319 With a negative argument, the item is shifted in using
4320 `allout-shift-in', instead.
4322 With an argument greater than one, shift-out the item's offspring
4323 but not the item itself, making the former children siblings of
4326 With an argument greater than 1, the item's offspring are shifted
4327 out without shifting the item. This will make the immediate
4328 subtopics into siblings of the item."
4331 (allout-shift-in (* arg -
1))
4332 ;; Get proper exposure in this area:
4333 (save-excursion (if (allout-ascend)
4334 (allout-show-children)))
4335 ;; Show collapsed children if there's a successor which will become
4337 (if (and (allout-current-topic-collapsed-p)
4338 (save-excursion (allout-next-sibling)))
4339 (allout-show-children))
4340 (let ((where (and (allout-depth) allout-recent-prefix-beginning
)))
4343 ;; Shift the offspring but not the topic:
4344 (let ((children-chart (allout-chart-subtree 1)))
4345 (if (listp (car children-chart
))
4347 (setq children-chart
(allout-flatten children-chart
)))
4349 (dolist (child-point children-chart
)
4350 (goto-char child-point
)
4351 (allout-shift-out 1))))
4352 (allout-rebullet-topic (* arg -
1))))
4353 (run-hook-with-args 'allout-structure-shifted-hook
(* arg -
1) where
))))
4354 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4355 ;;;_ > allout-kill-line (&optional arg)
4356 (defun allout-kill-line (&optional arg
)
4357 "Kill line, adjusting subsequent lines suitably for outline mode."
4361 (if (or (not (allout-mode-p))
4363 (not (save-match-data (looking-at allout-regexp
))))
4364 ;; Just do a regular kill:
4366 ;; Ah, have to watch out for adjustments:
4367 (let* ((beg (point))
4369 (beg-hidden (allout-hidden-p))
4370 (end-hidden (save-excursion (allout-end-of-current-line)
4373 (depth (allout-depth)))
4375 (allout-annotate-hidden beg end
)
4376 (if (and (not beg-hidden
) (not end-hidden
))
4377 (allout-unprotected (kill-line arg
))
4379 (allout-deannotate-hidden beg end
)
4381 (if allout-numbered-bullet
4382 (save-excursion ; Renumber subsequent topics if needed:
4383 (if (not (save-match-data (looking-at allout-regexp
)))
4384 (allout-next-heading))
4385 (allout-renumber-to-depth depth
)))
4386 (run-hook-with-args 'allout-structure-deleted-hook depth
(point)))))
4387 ;;;_ > allout-copy-line-as-kill ()
4388 (defun allout-copy-line-as-kill ()
4389 "Like allout-kill-topic, but save to kill ring instead of deleting."
4391 (let ((buffer-read-only t
))
4394 (buffer-read-only nil
))))
4395 ;;;_ > allout-kill-topic ()
4396 (defun allout-kill-topic ()
4397 "Kill topic together with subtopics.
4399 Trailing whitespace is killed with a topic if that whitespace:
4401 - would separate the topic from a subsequent sibling
4402 - would separate the topic from the end of buffer
4403 - would not be added to whitespace already separating the topic from the
4406 Topic exposure is marked with text-properties, to be used by
4407 `allout-yank-processing' for exposure recovery."
4410 (let* ((inhibit-field-text-motion t
)
4411 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4413 (depth allout-recent-depth
))
4414 (allout-end-of-current-subtree)
4415 (if (and (/= (current-column) 0) (not (eobp)))
4418 (if (and (save-match-data (looking-at "\n"))
4420 (or (not (allout-next-heading))
4421 (= depth allout-recent-depth
)))
4422 (and (> (- beg
(point-min)) 3)
4423 (string= (buffer-substring (- beg
2) beg
) "\n\n"))))
4426 (allout-annotate-hidden beg
(setq end
(point)))
4428 (allout-unprotected (kill-region beg end
))
4429 (if buffer-read-only
4430 ;; eg, during copy-as-kill.
4431 (allout-deannotate-hidden beg end
)))
4434 (allout-renumber-to-depth depth
))
4435 (run-hook-with-args 'allout-structure-deleted-hook depth
(point))))
4436 ;;;_ > allout-copy-topic-as-kill ()
4437 (defun allout-copy-topic-as-kill ()
4438 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4440 (let ((buffer-read-only t
))
4443 (buffer-read-only (message "Topic copied...")))))
4444 ;;;_ > allout-annotate-hidden (begin end)
4445 (defun allout-annotate-hidden (begin end
)
4446 "Qualify text with properties to indicate exposure status."
4448 (let ((was-modified (buffer-modified-p))
4449 (buffer-read-only nil
))
4450 (allout-deannotate-hidden begin end
)
4453 (let (done next prev overlay
)
4455 ;; at or advance to start of next hidden region:
4456 (if (not (allout-hidden-p))
4459 (next-single-char-property-change (point)
4462 (if (or (not next
) (eq prev next
))
4463 ;; still not at start of hidden area -- must not be any left.
4467 (if (not (allout-hidden-p))
4468 ;; still not at start of hidden area.
4470 (setq overlay
(allout-get-invisibility-overlay))
4471 (setq next
(overlay-end overlay
)
4473 ;; advance to end of this hidden area:
4477 (let ((buffer-undo-list t
))
4478 (put-text-property (overlay-start overlay
) next
4479 'allout-was-hidden t
)))))))))
4480 (set-buffer-modified-p was-modified
)))
4481 ;;;_ > allout-deannotate-hidden (begin end)
4482 (defun allout-deannotate-hidden (begin end
)
4483 "Remove allout hidden-text annotation between BEGIN and END."
4486 (let ((inhibit-read-only t
)
4487 (buffer-undo-list t
))
4488 ;(remove-text-properties begin end '(allout-was-hidden t))
4490 ;;;_ > allout-hide-by-annotation (begin end)
4491 (defun allout-hide-by-annotation (begin end
)
4492 "Translate text properties indicating exposure status into actual exposure."
4495 (let ((was-modified (buffer-modified-p))
4498 ;; at or advance to start of next annotation:
4499 (if (not (get-text-property (point) 'allout-was-hidden
))
4500 (setq next
(next-single-char-property-change (point)
4503 (if (or (not next
) (eq prev next
))
4504 ;; no more or not advancing -- must not be any left.
4508 (if (not (get-text-property (point) 'allout-was-hidden
))
4509 ;; still not at start of annotation.
4511 ;; advance to just after end of this annotation:
4512 (setq next
(next-single-char-property-change (point)
4515 (overlay-put (make-overlay prev next nil
'front-advance
)
4516 'category
'allout-exposure-category
)
4517 (allout-deannotate-hidden prev next
)
4519 (if next
(goto-char next
)))))
4520 (set-buffer-modified-p was-modified
))))
4521 ;;;_ > allout-yank-processing ()
4522 (defun allout-yank-processing (&optional arg
)
4524 "Incidental allout-specific business to be done just after text yanks.
4526 Does depth adjustment of yanked topics, when:
4528 1 the stuff being yanked starts with a valid outline header prefix, and
4529 2 it is being yanked at the end of a line which consists of only a valid
4532 Also, adjusts numbering of subsequent siblings when appropriate.
4534 Depth adjustment alters the depth of all the topics being yanked
4535 the amount it takes to make the first topic have the depth of the
4536 header into which it's being yanked.
4538 The point is left in front of yanked, adjusted topics, rather than
4539 at the end (and vice-versa with the mark). Non-adjusted yanks,
4540 however, are left exactly like normal, non-allout-specific yanks."
4543 ; Get to beginning, leaving
4544 ; region around subject:
4545 (if (< (allout-mark-marker t
) (point))
4546 (exchange-point-and-mark))
4548 (let* ((subj-beg (point))
4550 (subj-end (allout-mark-marker t
))
4551 ;; 'resituate' if yanking an entire topic into topic header:
4552 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t
))
4553 (allout-e-o-prefix-p))
4554 (looking-at allout-regexp
)
4555 (allout-prefix-data)))
4556 ;; `rectify-numbering' if resituating (where several topics may
4557 ;; be resituating) or yanking a topic into a topic slot (bol):
4558 (rectify-numbering (or resituate
4559 (and into-bol
(looking-at allout-regexp
)))))
4561 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4562 (let* ((inhibit-field-text-motion t
)
4563 (prefix-len (if (not (match-end 1))
4565 (- (match-end 1) subj-beg
)))
4566 (subj-depth allout-recent-depth
)
4567 (prefix-bullet (allout-recent-bullet))
4569 ;; Nil if adjustment unnecessary, otherwise depth to which
4570 ;; adjustment should be made:
4572 (and (goto-char subj-end
)
4574 (goto-char subj-beg
)
4575 (and (looking-at allout-regexp
)
4578 (not (= (point) subj-beg
)))
4579 (looking-at allout-regexp
)
4580 (allout-prefix-data))
4581 allout-recent-depth
)))
4583 (setq rectify-numbering allout-numbered-bullet
)
4585 ; Do the adjustment:
4588 (narrow-to-region subj-beg subj-end
)
4589 ; Trim off excessive blank
4590 ; line at end, if any:
4591 (goto-char (point-max))
4592 (if (looking-at "^$")
4593 (allout-unprotected (delete-char -
1)))
4594 ; Work backwards, with each
4596 ; successively excluding the
4597 ; last processed topic from
4598 ; the narrow region:
4600 (allout-back-to-current-heading)
4601 ; go as high as we can in each bunch:
4602 (while (allout-ascend t
))
4605 (allout-rebullet-topic-grunt (- adjust-to-depth
4608 (if (setq more
(not (bobp)))
4611 (narrow-to-region subj-beg
(point))))))
4612 ;; Preserve new bullet if it's a distinctive one, otherwise
4614 (if (string-match (regexp-quote prefix-bullet
)
4615 allout-distinctive-bullets-string
)
4616 ; Delete from bullet of old to
4617 ; before bullet of new:
4621 (delete-region (point) subj-beg
))
4622 (set-marker (allout-mark-marker t
) subj-end
)
4623 (goto-char subj-beg
)
4624 (allout-end-of-prefix))
4625 ; Delete base subj prefix,
4629 (delete-region (point) (+ (point)
4633 ; and delete residual subj
4634 ; prefix digits and space:
4635 (while (looking-at "[0-9]") (delete-char 1))
4636 (if (looking-at " ")
4637 (delete-char 1))))))
4638 (exchange-point-and-mark))))
4639 (if rectify-numbering
4642 ; Give some preliminary feedback:
4643 (message "... reconciling numbers")
4644 ; ... and renumber, in case necessary:
4645 (goto-char subj-beg
)
4646 (if (allout-goto-prefix-doublechecked)
4648 (allout-rebullet-heading nil
;;; solicit
4649 (allout-depth) ;;; depth
4650 nil
;;; number-control
4654 (if (or into-bol resituate
)
4655 (allout-hide-by-annotation (point) (allout-mark-marker t
))
4656 (allout-deannotate-hidden (allout-mark-marker t
) (point)))
4658 (exchange-point-and-mark))
4659 (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end
))))
4660 ;;;_ > allout-yank (&optional arg)
4661 (defun allout-yank (&optional arg
)
4662 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4664 Non-topic yanks work no differently than normal yanks.
4666 If a topic is being yanked into a bare topic prefix, the depth of the
4667 yanked topic is adjusted to the depth of the topic prefix.
4669 1 we're yanking in an `allout-mode' buffer
4670 2 the stuff being yanked starts with a valid outline header prefix, and
4671 3 it is being yanked at the end of a line which consists of only a valid
4674 If these conditions hold then the depth of the yanked topics are all
4675 adjusted the amount it takes to make the first one at the depth of the
4676 header into which it's being yanked.
4678 The point is left in front of yanked, adjusted topics, rather than
4679 at the end (and vice-versa with the mark). Non-adjusted yanks,
4680 however, (ones that don't qualify for adjustment) are handled
4681 exactly like normal yanks.
4683 Numbering of yanked topics, and the successive siblings at the depth
4684 into which they're being yanked, is adjusted.
4686 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4687 works with normal `yank' in non-outline buffers."
4690 (setq this-command
'yank
)
4694 (allout-yank-processing)))
4695 ;;;_ > allout-yank-pop (&optional arg)
4696 (defun allout-yank-pop (&optional arg
)
4697 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4699 Adapts level of popped topics to level of fresh prefix.
4701 Note -- prefix changes to distinctive bullets will stick, if followed
4702 by pops to non-distinctive yanks. Bug..."
4705 (setq this-command
'yank
)
4708 (allout-yank-processing)))
4710 ;;;_ - Specialty bullet functions
4711 ;;;_ : File Cross references
4712 ;;;_ > allout-resolve-xref ()
4713 (defun allout-resolve-xref ()
4714 "Pop to file associated with current heading, if it has an xref bullet.
4716 \(Works according to setting of `allout-file-xref-bullet')."
4718 (if (not allout-file-xref-bullet
)
4720 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4721 (if (not (string= (allout-current-bullet) allout-file-xref-bullet
))
4722 (error "Current heading lacks cross-reference bullet `%s'"
4723 allout-file-xref-bullet
)
4724 (let ((inhibit-field-text-motion t
)
4728 (let* ((text-start allout-recent-prefix-end
)
4729 (heading-end (progn (end-of-line) (point))))
4730 (goto-char text-start
)
4732 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
4733 (buffer-substring (match-beginning 1)
4735 (setq file-name
(expand-file-name file-name
))
4736 (if (or (file-exists-p file-name
)
4737 (if (file-writable-p file-name
)
4738 (y-or-n-p (format "%s not there, create one? "
4740 (error "%s not found and can't be created" file-name
)))
4741 (condition-case failure
4742 (find-file-other-window file-name
)
4744 (error "%s not found" file-name
))
4750 ;;;_ #6 Exposure Control
4753 ;;;_ > allout-flag-region (from to flag)
4754 (defun allout-flag-region (from to flag
)
4755 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4757 Exposure-change hook `allout-exposure-change-hook' is run with the same
4758 arguments as this function, after the exposure changes are made. (The old
4759 `allout-view-change-hook' is being deprecated, and eventually will not be
4762 ;; We use outline invisibility spec.
4763 (remove-overlays from to
'category
'allout-exposure-category
)
4765 (let ((o (make-overlay from to nil
'front-advance
)))
4766 (overlay-put o
'category
'allout-exposure-category
)
4767 (when (featurep 'xemacs
)
4768 (let ((props (symbol-plist 'allout-exposure-category
)))
4770 (overlay-put o
(pop props
) (pop props
)))))))
4771 (run-hooks 'allout-view-change-hook
)
4772 (run-hook-with-args 'allout-exposure-change-hook from to flag
))
4773 ;;;_ > allout-flag-current-subtree (flag)
4774 (defun allout-flag-current-subtree (flag)
4775 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4778 (allout-back-to-current-heading)
4779 (let ((inhibit-field-text-motion t
))
4781 (allout-flag-region (point)
4782 ;; Exposing must not leave trailing blanks hidden,
4783 ;; but can leave them exposed when hiding, so we
4784 ;; can use flag's inverse as the
4785 ;; include-trailing-blank cue:
4786 (allout-end-of-current-subtree (not flag
))
4789 ;;;_ - Topic-specific
4790 ;;;_ > allout-show-entry ()
4791 (defun allout-show-entry ()
4792 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4794 This is a way to give restricted peek at a concealed locality without the
4795 expense of exposing its context, but can leave the outline with aberrant
4796 exposure. `allout-show-offshoot' should be used after the peek to rectify
4802 (allout-goto-prefix-doublechecked)
4803 (setq beg
(if (allout-hidden-p) (1- (point)) (point)))
4804 (setq end
(allout-pre-next-prefix))
4805 (allout-flag-region beg end nil
)
4807 ;;;_ > allout-show-children (&optional level strict)
4808 (defun allout-show-children (&optional level strict
)
4810 "If point is visible, show all direct subheadings of this heading.
4812 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4814 Optional LEVEL specifies how many levels below the current level
4815 should be shown, or all levels if t. Default is 1.
4817 Optional STRICT means don't resort to -show-to-offshoot, no matter
4818 what. This is basically so -show-to-offshoot, which is called by
4819 this function, can employ the pure offspring-revealing capabilities of
4822 Returns point at end of subtree that was opened, if any. (May get a
4823 point of non-opened subtree?)"
4826 (let ((start-point (point)))
4827 (if (and (not strict
)
4830 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4832 ;; Then recurse, but with "strict" set so we don't
4833 ;; infinite regress:
4834 (allout-show-children level t
))
4837 (allout-beginning-of-current-line)
4840 ;; translate the level spec for this routine to the ones
4841 ;; used by -chart-subtree and -chart-to-reveal:
4842 (chart-level (cond ((not level
) 1)
4845 (chart (allout-chart-subtree chart-level
))
4846 (to-reveal (or (allout-chart-to-reveal chart chart-level
)
4847 ;; interactive, show discontinuous children:
4851 (allout-back-to-current-heading)
4852 (setq depth
(allout-current-depth))
4853 (and (allout-next-heading)
4854 (> allout-recent-depth
4857 "Discontinuous offspring; use `%s %s'%s."
4858 (substitute-command-keys
4859 "\\[universal-argument]")
4860 (substitute-command-keys
4861 "\\[allout-shift-out]")
4862 " to elevate them.")
4863 (allout-chart-to-reveal
4864 chart
(- allout-recent-depth depth
))))))
4865 (goto-char start-point
)
4866 (when (and strict
(allout-hidden-p))
4867 ;; Concealed root would already have been taken care of,
4868 ;; unless strict was set.
4869 (allout-flag-region (point) (allout-snug-back) nil
)
4870 (when allout-show-bodies
4871 (goto-char (car to-reveal
))
4872 (allout-show-current-entry)))
4874 (goto-char (car to-reveal
))
4875 (allout-flag-region (save-excursion (allout-snug-back) (point))
4876 (progn (search-forward "\n" nil t
)
4879 (when allout-show-bodies
4880 (goto-char (car to-reveal
))
4881 (allout-show-current-entry))
4882 (setq to-reveal
(cdr to-reveal
)))))))
4883 ;; Compensate for `save-excursion's maintenance of point
4884 ;; within invisible text:
4885 (goto-char start-point
)))
4886 ;;;_ > allout-show-to-offshoot ()
4887 (defun allout-show-to-offshoot ()
4888 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4890 Useful for coherently exposing to a random point in a hidden region."
4893 (let ((inhibit-field-text-motion t
)
4895 (orig-pref (allout-goto-prefix-doublechecked))
4898 (while (or (> bag-it
1) (allout-hidden-p))
4899 (while (allout-hidden-p)
4900 (move-beginning-of-line 1)
4901 (if (allout-hidden-p) (forward-char -
1)))
4902 (if (= last-at
(setq last-at
(point)))
4903 ;; Oops, we're not making any progress! Show the current topic
4904 ;; completely, and try one more time here, if we haven't already.
4905 (progn (beginning-of-line)
4906 (allout-show-current-subtree)
4908 (setq bag-it
(1+ bag-it
))
4910 (error "allout-show-to-offshoot: %s"
4911 "Stumped by aberrant nesting.")))
4912 (if (> bag-it
0) (setq bag-it
0))
4913 (allout-show-children)
4914 (goto-char orig-pref
)))
4915 (goto-char orig-pt
)))
4916 (if (allout-hidden-p)
4917 (allout-show-entry)))
4918 ;;;_ > allout-hide-current-entry ()
4919 (defun allout-hide-current-entry ()
4920 "Hide the body directly following this heading."
4922 (allout-back-to-current-heading)
4924 (let ((inhibit-field-text-motion t
))
4926 (allout-flag-region (point)
4927 (progn (allout-end-of-entry) (point))
4929 ;;;_ > allout-show-current-entry (&optional arg)
4930 (defun allout-show-current-entry (&optional arg
)
4931 "Show body following current heading, or hide entry with universal argument."
4935 (allout-hide-current-entry)
4936 (save-excursion (allout-show-to-offshoot))
4938 (allout-flag-region (point)
4939 (progn (allout-end-of-entry t
) (point))
4942 ;;;_ > allout-show-current-subtree (&optional arg)
4943 (defun allout-show-current-subtree (&optional arg
)
4944 "Show everything within the current topic.
4945 With a repeat-count, expose this topic and its siblings."
4948 (if (<= (allout-current-depth) 0)
4949 ;; Outside any topics -- try to get to the first:
4950 (if (not (allout-next-heading))
4952 ;; got to first, outermost topic -- set to expose it and siblings:
4953 (message "Above outermost topic -- exposing all.")
4954 (allout-flag-region (point-min)(point-max) nil
))
4955 (allout-beginning-of-current-line)
4957 (allout-flag-current-subtree nil
)
4958 (allout-beginning-of-level)
4959 (allout-expose-topic '(* :))))))
4960 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4961 (defun allout-current-topic-collapsed-p (&optional include-single-liners
)
4962 "True if the currently visible containing topic is already collapsed.
4964 Single line topics intrinsically can be considered as being both
4965 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
4966 true, then single-line topics are considered to be collapsed. By
4967 default, they are treated as being uncollapsed."
4971 ;; Is the topic all on one line (allowing for trailing blank line)?
4972 (>= (progn (allout-back-to-current-heading)
4973 (move-end-of-line 1)
4975 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
4977 (or include-single-liners
4978 (progn (backward-char 1) (allout-hidden-p)))))))
4979 ;;;_ > allout-hide-current-subtree (&optional just-close)
4980 (defun allout-hide-current-subtree (&optional just-close
)
4981 "Close the current topic, or containing topic if this one is already closed.
4983 If this topic is closed and it's a top level topic, close this topic
4986 If optional arg JUST-CLOSE is non-nil, do not close the parent or
4987 siblings, even if the target topic is already closed."
4990 (let* ((from (point))
4991 (sibs-msg "Top-level topic already closed -- closing siblings...")
4992 (current-exposed (not (allout-current-topic-collapsed-p t
))))
4993 (cond (current-exposed (allout-flag-current-subtree t
))
4995 ((allout-ascend) (allout-hide-current-subtree))
4998 (allout-goto-prefix-doublechecked)
4999 (allout-expose-topic '(0 :))
5000 (message (concat sibs-msg
" Done."))))
5002 ;;;_ > allout-toggle-current-subtree-exposure
5003 (defun allout-toggle-current-subtree-exposure ()
5004 "Show or hide the current subtree depending on its current state."
5005 ;; thanks to tassilo for suggesting this.
5008 (allout-back-to-heading)
5009 (if (allout-hidden-p (point-at-eol))
5010 (allout-show-current-subtree)
5011 (allout-hide-current-subtree))))
5012 ;;;_ > allout-show-current-branches ()
5013 (defun allout-show-current-branches ()
5014 "Show all subheadings of this heading, but not their bodies."
5016 (let ((inhibit-field-text-motion t
))
5017 (beginning-of-line))
5018 (allout-show-children t
))
5019 ;;;_ > allout-hide-current-leaves ()
5020 (defun allout-hide-current-leaves ()
5021 "Hide the bodies of the current topic and all its offspring."
5023 (allout-back-to-current-heading)
5024 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
5027 ;;;_ - Region and beyond
5028 ;;;_ > allout-show-all ()
5029 (defun allout-show-all ()
5030 "Show all of the text in the buffer."
5032 (message "Exposing entire buffer...")
5033 (allout-flag-region (point-min) (point-max) nil
)
5034 (message "Exposing entire buffer... Done."))
5035 ;;;_ > allout-hide-bodies ()
5036 (defun allout-hide-bodies ()
5037 "Hide all of buffer except headings."
5039 (allout-hide-region-body (point-min) (point-max)))
5040 ;;;_ > allout-hide-region-body (start end)
5041 (defun allout-hide-region-body (start end
)
5042 "Hide all body lines in the region, but not headings."
5046 (narrow-to-region start end
)
5047 (goto-char (point-min))
5048 (let ((inhibit-field-text-motion t
))
5051 (allout-flag-region (point) (allout-end-of-entry) t
)
5054 (if (looking-at "\n\n")
5057 ;;;_ > allout-expose-topic (spec)
5058 (defun allout-expose-topic (spec)
5059 "Apply exposure specs to successive outline topic items.
5061 Use the more convenient frontend, `allout-new-exposure', if you don't
5062 need evaluation of the arguments, or even better, the `allout-layout'
5063 variable-keyed mode-activation/auto-exposure feature of allout outline
5064 mode. See the respective documentation strings for more details.
5066 Cursor is left at start position.
5068 SPEC is either a number or a list.
5070 Successive specs on a list are applied to successive sibling topics.
5072 A simple spec (either a number, one of a few symbols, or the null
5073 list) dictates the exposure for the corresponding topic.
5075 Non-null lists recursively designate exposure specs for respective
5076 subtopics of the current topic.
5078 The `:' repeat spec is used to specify exposure for any number of
5079 successive siblings, up to the trailing ones for which there are
5080 explicit specs following the `:'.
5082 Simple (numeric and null-list) specs are interpreted as follows:
5084 Numbers indicate the relative depth to open the corresponding topic.
5085 - negative numbers force the topic to be closed before opening to the
5086 absolute value of the number, so all siblings are open only to
5088 - positive numbers open to the relative depth indicated by the
5089 number, but do not force already opened subtopics to be closed.
5090 - 0 means to close topic -- hide all offspring.
5092 apply prior element to all siblings at current level, *up to*
5093 those siblings that would be covered by specs following the `:'
5094 on the list. Ie, apply to all topics at level but the last
5095 ones. (Only first of multiple colons at same level is
5096 respected -- subsequent ones are discarded.)
5097 * - completely opens the topic, including bodies.
5098 + - shows all the sub headers, but not the bodies
5099 - - exposes the body of the corresponding topic.
5102 \(allout-expose-topic '(-1 : 0))
5103 Close this and all following topics at current level, exposing
5104 only their immediate children, but close down the last topic
5105 at this current level completely.
5106 \(allout-expose-topic '(-1 () : 1 0))
5107 Close current topic so only the immediate subtopics are shown;
5108 show the children in the second to last topic, and completely
5110 \(allout-expose-topic '(-2 : -1 *))
5111 Expose children and grandchildren of all topics at current
5112 level except the last two; expose children of the second to
5113 last and completely open the last one."
5115 (interactive "xExposure spec: ")
5116 (if (not (listp spec
))
5118 (let ((depth (allout-depth))
5123 (setq prev-elem curr-elem
5124 curr-elem
(car spec
)
5126 (cond ; Do current element:
5127 ((null curr-elem
) nil
)
5128 ((symbolp curr-elem
)
5129 (cond ((eq curr-elem
'*) (allout-show-current-subtree)
5130 (if (> allout-recent-end-of-subtree max-pos
)
5131 (setq max-pos allout-recent-end-of-subtree
)))
5133 (if (not (allout-hidden-p))
5134 (save-excursion (allout-hide-current-subtree t
)))
5135 (allout-show-current-branches)
5136 (if (> allout-recent-end-of-subtree max-pos
)
5137 (setq max-pos allout-recent-end-of-subtree
)))
5138 ((eq curr-elem
'-
) (allout-show-current-entry))
5141 ;; Expand the `repeat' spec to an explicit version,
5142 ;; w.r.t. remaining siblings:
5143 (let ((residue ; = # of sibs not covered by remaining spec
5144 ;; Dang, could be nice to make use of the chart, sigh:
5145 (- (length (allout-chart-siblings))
5148 ;; Some residue -- cover it with prev-elem:
5149 (setq spec
(append (make-list residue prev-elem
)
5151 ((numberp curr-elem
)
5152 (if (and (>= 0 curr-elem
) (not (allout-hidden-p)))
5153 (save-excursion (allout-hide-current-subtree t
)
5156 (if (> allout-recent-end-of-subtree max-pos
)
5158 allout-recent-end-of-subtree
)))))
5159 (if (> (abs curr-elem
) 0)
5160 (progn (allout-show-children (abs curr-elem
))
5161 (if (> allout-recent-end-of-subtree max-pos
)
5162 (setq max-pos allout-recent-end-of-subtree
)))))
5164 (if (allout-descend-to-depth (1+ depth
))
5165 (let ((got (allout-expose-topic curr-elem
)))
5166 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
5167 (cond (stay (setq stay nil
))
5168 ((listp (car spec
)) nil
)
5169 ((> max-pos
(point))
5170 ;; Capitalize on max-pos state to get us nearer next sibling:
5171 (progn (goto-char (min (point-max) max-pos
))
5172 (allout-next-heading)))
5173 ((allout-next-sibling depth
))))
5175 ;;;_ > allout-old-expose-topic (spec &rest followers)
5176 (defun allout-old-expose-topic (spec &rest followers
)
5178 "Deprecated. Use `allout-expose-topic' (with different schema
5181 Dictate wholesale exposure scheme for current topic, according to SPEC.
5183 SPEC is either a number or a list. Optional successive args
5184 dictate exposure for subsequent siblings of current topic.
5186 A simple spec (either a number, a special symbol, or the null list)
5187 dictates the overall exposure for a topic. Non null lists are
5188 composite specs whose first element dictates the overall exposure for
5189 a topic, with the subsequent elements in the list interpreted as specs
5190 that dictate the exposure for the successive offspring of the topic.
5192 Simple (numeric and null-list) specs are interpreted as follows:
5194 - Numbers indicate the relative depth to open the corresponding topic:
5195 - negative numbers force the topic to be close before opening to the
5196 absolute value of the number.
5197 - positive numbers just open to the relative depth indicated by the number.
5199 - `*' completely opens the topic, including bodies.
5200 - `+' shows all the sub headers, but not the bodies
5201 - `-' exposes the body and immediate offspring of the corresponding topic.
5203 If the spec is a list, the first element must be a number, which
5204 dictates the exposure depth of the topic as a whole. Subsequent
5205 elements of the list are nested SPECs, dictating the specific exposure
5206 for the corresponding offspring of the topic.
5208 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5210 (interactive "xExposure spec: ")
5211 (let ((inhibit-field-text-motion t
)
5212 (depth (allout-current-depth))
5214 (cond ((null spec
) nil
)
5216 (if (eq spec
'*) (allout-show-current-subtree))
5217 (if (eq spec
'+) (allout-show-current-branches))
5218 (if (eq spec
'-
) (allout-show-current-entry)))
5221 (save-excursion (allout-hide-current-subtree t
)
5223 (if (or (not max-pos
)
5224 (> (point) max-pos
))
5225 (setq max-pos
(point)))
5227 (setq spec
(* -
1 spec
)))))
5229 (allout-show-children spec
)))
5231 ;(let ((got (allout-old-expose-topic (car spec))))
5232 ; (if (and got (or (not max-pos) (> got max-pos)))
5233 ; (setq max-pos got)))
5234 (let ((new-depth (+ (allout-current-depth) 1))
5236 (setq max-pos
(allout-old-expose-topic (car spec
)))
5237 (setq spec
(cdr spec
))
5239 (allout-descend-to-depth new-depth
)
5240 (not (allout-hidden-p)))
5241 (progn (setq got
(apply 'allout-old-expose-topic spec
))
5242 (if (and got
(or (not max-pos
) (> got max-pos
)))
5243 (setq max-pos got
)))))))
5244 (while (and followers
5245 (progn (if (and max-pos
(< (point) max-pos
))
5246 (progn (goto-char max-pos
)
5247 (setq max-pos nil
)))
5249 (allout-next-sibling depth
)))
5250 (allout-old-expose-topic (car followers
))
5251 (setq followers
(cdr followers
)))
5253 ;;;_ > allout-new-exposure '()
5254 (defmacro allout-new-exposure
(&rest spec
)
5255 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5256 Some arguments that would need to be quoted in `allout-expose-topic'
5257 need not be quoted in `allout-new-exposure'.
5259 Cursor is left at start position.
5261 Use this instead of obsolete `allout-exposure'.
5264 \(allout-new-exposure (-1 () () () 1) 0)
5265 Close current topic at current level so only the immediate
5266 subtopics are shown, except also show the children of the
5267 third subtopic; and close the next topic at the current level.
5268 \(allout-new-exposure : -1 0)
5269 Close all topics at current level to expose only their
5270 immediate children, except for the last topic at the current
5271 level, in which even its immediate children are hidden.
5272 \(allout-new-exposure -2 : -1 *)
5273 Expose children and grandchildren of first topic at current
5274 level, and expose children of subsequent topics at current
5275 level *except* for the last, which should be opened completely."
5276 (list 'save-excursion
5277 '(if (not (or (allout-goto-prefix-doublechecked)
5278 (allout-next-heading)))
5279 (error "allout-new-exposure: Can't find any outline topics"))
5280 (list 'allout-expose-topic
(list 'quote spec
))))
5282 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5284 ;;;_ - Mapping and processing of topics
5285 ;;;_ ( See also Subtree Charting, in Navigation code.)
5286 ;;;_ > allout-stringify-flat-index (flat-index)
5287 (defun allout-stringify-flat-index (flat-index &optional context
)
5288 "Convert list representing section/subsection/... to document string.
5290 Optional arg CONTEXT indicates interior levels to include."
5294 (context-depth (or (and context
2) 1)))
5295 ;; Take care of the explicit context:
5296 (while (> context-depth
0)
5297 (setq numstr
(int-to-string (car flat-index
))
5298 flat-index
(cdr flat-index
)
5299 result
(if flat-index
5300 (cons delim
(cons numstr result
))
5301 (cons numstr result
))
5302 context-depth
(if flat-index
(1- context-depth
) 0)))
5304 ;; Take care of the indentation:
5311 (1+ (truncate (if (zerop (car flat-index
))
5313 (log10 (car flat-index
)))))
5316 (setq flat-index
(cdr flat-index
)))
5317 ;; Dispose of single extra delim:
5318 (setq result
(cdr result
))))
5319 (apply 'concat result
)))
5320 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5321 (defun allout-stringify-flat-index-plain (flat-index)
5322 "Convert list representing section/subsection/... to document string."
5326 (setq result
(cons (int-to-string (car flat-index
))
5328 (cons delim result
))))
5329 (setq flat-index
(cdr flat-index
)))
5330 (apply 'concat result
)))
5331 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5332 (defun allout-stringify-flat-index-indented (flat-index)
5333 "Convert list representing section/subsection/... to document string."
5337 ;; Take care of the explicit context:
5338 (setq numstr
(int-to-string (car flat-index
))
5339 flat-index
(cdr flat-index
)
5340 result
(if flat-index
5341 (cons delim
(cons numstr result
))
5342 (cons numstr result
)))
5344 ;; Take care of the indentation:
5351 (1+ (truncate (if (zerop (car flat-index
))
5353 (log10 (car flat-index
)))))
5356 (setq flat-index
(cdr flat-index
)))
5357 ;; Dispose of single extra delim:
5358 (setq result
(cdr result
))))
5359 (apply 'concat result
)))
5360 ;;;_ > allout-listify-exposed (&optional start end format)
5361 (defun allout-listify-exposed (&optional start end format
)
5363 "Produce a list representing exposed topics in current region.
5365 This list can then be used by `allout-process-exposed' to manipulate
5368 Optional START and END indicate bounds of region.
5370 Optional arg, FORMAT, designates an alternate presentation form for
5373 list -- Present prefix as numeric section.subsection..., starting with
5374 section indicated by the list, innermost nesting first.
5375 `indent' (symbol) -- Convert header prefixes to all white space,
5376 except for distinctive bullets.
5378 The elements of the list produced are lists that represents a topic
5379 header and body. The elements of that list are:
5381 - a number representing the depth of the topic,
5382 - a string representing the header-prefix, including trailing whitespace and
5384 - a string representing the bullet character,
5385 - and a series of strings, each containing one line of the exposed
5386 portion of the topic entry."
5391 ((inhibit-field-text-motion t
)
5393 strings prefix result depth new-depth out gone-out bullet beg
5398 ;; Goto initial topic, and register preceeding stuff, if any:
5399 (if (> (allout-goto-prefix-doublechecked) start
)
5400 ;; First topic follows beginning point -- register preliminary stuff:
5401 (setq result
(list (list 0 "" nil
5402 (buffer-substring start
(1- (point)))))))
5403 (while (and (not done
)
5404 (not (eobp)) ; Loop until we've covered the region.
5405 (not (> (point) end
)))
5406 (setq depth allout-recent-depth
; Current topics depth,
5407 bullet
(allout-recent-bullet) ; ... bullet,
5408 prefix
(allout-recent-prefix)
5409 beg
(progn (allout-end-of-prefix t
) (point))) ; and beginning.
5410 (setq done
; The boundary for the current topic:
5411 (not (allout-next-visible-heading 1)))
5412 (setq new-depth allout-recent-depth
)
5414 out
(< new-depth depth
))
5419 (while (> next
(point)) ; Get all the exposed text in
5421 (cons (buffer-substring
5423 ;To hidden text or end of line:
5426 (allout-back-to-visible-text)))
5428 (when (< (point) next
) ; Resume from after hid text, if any.
5430 (beginning-of-line))
5432 ;; Accumulate list for this topic:
5433 (setq strings
(nreverse strings
))
5437 (let ((special (if (string-match
5438 (regexp-quote bullet
)
5439 allout-distinctive-bullets-string
)
5441 (cond ((listp format
)
5443 (if allout-abbreviate-flattened-numbering
5444 (allout-stringify-flat-index format
5446 (allout-stringify-flat-index-plain
5450 ((eq format
'indent
)
5453 (concat (make-string (1+ depth
) ?
)
5454 (substring prefix -
1))
5457 (make-string depth ?
)
5459 (t (error "allout-listify-exposed: %s %s"
5460 "invalid format" format
))))
5461 (list depth prefix strings
))
5463 ;; Reasses format, if any:
5464 (if (and format
(listp format
))
5465 (cond ((= new-depth depth
)
5466 (setq format
(cons (1+ (car format
))
5468 ((> new-depth depth
) ; descending -- assume by 1:
5469 (setq format
(cons 1 format
)))
5472 (while (< new-depth depth
)
5473 (setq format
(cdr format
))
5474 (setq depth
(1- depth
)))
5475 ; And increment the current one:
5477 (cons (1+ (or (car format
)
5480 ;; Put the list with first at front, to last at back:
5481 (nreverse result
))))
5482 ;;;_ > allout-region-active-p ()
5483 (defmacro allout-region-active-p
()
5484 (cond ((fboundp 'use-region-p
) '(use-region-p))
5485 ((fboundp 'region-active-p
) '(region-active-p))
5487 ;;_ > allout-process-exposed (&optional func from to frombuf
5489 (defun allout-process-exposed (&optional func from to frombuf tobuf
5491 "Map function on exposed parts of current topic; results to another buffer.
5493 All args are options; default values itemized below.
5495 Apply FUNCTION to exposed portions FROM position TO position in buffer
5496 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5497 alternate presentation form:
5499 `flat' -- Present prefix as numeric section.subsection..., starting with
5500 section indicated by the START-NUM, innermost nesting first.
5501 X`flat-indented' -- Prefix is like `flat' for first topic at each
5502 X level, but subsequent topics have only leaf topic
5503 X number, padded with blanks to line up with first.
5504 `indent' (symbol) -- Convert header prefixes to all white space,
5505 except for distinctive bullets.
5508 FUNCTION: `allout-insert-listified'
5509 FROM: region start, if region active, else start of buffer
5510 TO: region end, if region active, else end of buffer
5511 FROMBUF: current buffer
5512 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5515 ; Resolve arguments,
5516 ; defaulting if necessary:
5517 (if (not func
) (setq func
'allout-insert-listified
))
5518 (if (not (and from to
))
5519 (if (allout-region-active-p)
5520 (setq from
(region-beginning) to
(region-end))
5521 (setq from
(point-min) to
(point-max))))
5523 (if (not (bufferp frombuf
))
5524 ;; Specified but not a buffer -- get it:
5525 (let ((got (get-buffer frombuf
)))
5527 (error (concat "allout-process-exposed: source buffer "
5530 (setq frombuf got
))))
5531 ;; not specified -- default it:
5532 (setq frombuf
(current-buffer)))
5534 (if (not (bufferp tobuf
))
5535 (setq tobuf
(get-buffer-create tobuf
)))
5536 ;; not specified -- default it:
5537 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
5542 (progn (set-buffer frombuf
)
5543 (allout-listify-exposed from to format
))))
5545 (mapc func listified
)
5546 (pop-to-buffer tobuf
)))
5549 ;;;_ > allout-insert-listified (listified)
5550 (defun allout-insert-listified (listified)
5551 "Insert contents of listified outline portion in current buffer.
5553 LISTIFIED is a list representing each topic header and body:
5555 \`(depth prefix text)'
5557 or \`(depth prefix text bullet-plus)'
5559 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5560 (setq listified
(cdr listified
))
5561 (let ((prefix (prog1
5563 (setq listified
(cdr listified
))))
5566 (setq listified
(cdr listified
))))
5567 (bullet-plus (car listified
)))
5569 (if bullet-plus
(insert (concat " " bullet-plus
)))
5572 (if (setq text
(cdr text
))
5575 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5576 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format
)
5577 "Duplicate exposed portions of current outline to another buffer.
5579 Other buffer has current buffers name with \" exposed\" appended to it.
5581 With repeat count, copy the exposed parts of only the current topic.
5583 Optional second arg TOBUF is target buffer name.
5585 Optional third arg FORMAT, if non-nil, symbolically designates an
5586 alternate presentation format for the outline:
5588 `flat' - Convert topic header prefixes to numeric
5589 section.subsection... identifiers.
5590 `indent' - Convert header prefixes to all white space, except for
5591 distinctive bullets.
5592 `indent-flat' - The best of both - only the first of each level has
5593 the full path, the rest have only the section number
5594 of the leaf, preceded by the right amount of indentation."
5598 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5599 (let* ((start-pt (point))
5600 (beg (if arg
(allout-back-to-current-heading) (point-min)))
5601 (end (if arg
(allout-end-of-current-subtree) (point-max)))
5602 (buf (current-buffer))
5604 (if (eq format
'flat
)
5605 (setq format
(if arg
(save-excursion
5607 (allout-topic-flat-index))
5609 (save-excursion (set-buffer tobuf
)(erase-buffer))
5610 (allout-process-exposed 'allout-insert-listified
5616 (goto-char (point-min))
5618 (goto-char start-pt
)))
5619 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5620 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf
)
5621 "Present numeric outline of outline's exposed portions in another buffer.
5623 The resulting outline is not compatible with outline mode -- use
5624 `allout-copy-exposed-to-buffer' if you want that.
5626 Use `allout-indented-exposed-to-buffer' for indented presentation.
5628 With repeat count, copy the exposed portions of only current topic.
5630 Other buffer has current buffer's name with \" exposed\" appended to
5631 it, unless optional second arg TOBUF is specified, in which case it is
5634 (allout-copy-exposed-to-buffer arg tobuf
'flat
))
5635 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5636 (defun allout-indented-exposed-to-buffer (&optional arg tobuf
)
5637 "Present indented outline of outline's exposed portions in another buffer.
5639 The resulting outline is not compatible with outline mode -- use
5640 `allout-copy-exposed-to-buffer' if you want that.
5642 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5644 With repeat count, copy the exposed portions of only current topic.
5646 Other buffer has current buffer's name with \" exposed\" appended to
5647 it, unless optional second arg TOBUF is specified, in which case it is
5650 (allout-copy-exposed-to-buffer arg tobuf
'indent
))
5652 ;;;_ - LaTeX formatting
5653 ;;;_ > allout-latex-verb-quote (string &optional flow)
5654 (defun allout-latex-verb-quote (string &optional flow
)
5655 "Return copy of STRING for literal reproduction across LaTeX processing.
5656 Expresses the original characters (including carriage returns) of the
5657 string across LaTeX processing."
5658 (mapconcat (function
5660 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
5661 (concat "\\char" (number-to-string char
) "{}"))
5662 ((= char ?
\n) "\\\\")
5663 (t (char-to-string char
)))))
5666 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5667 (defun allout-latex-verbatim-quote-curr-line ()
5668 "Express line for exact (literal) representation across LaTeX processing.
5670 Adjust line contents so it is unaltered (from the original line)
5671 across LaTeX processing, within the context of a `verbatim'
5672 environment. Leaves point at the end of the line."
5673 (let ((inhibit-field-text-motion t
))
5676 (end (progn (end-of-line)(point))))
5679 (while (re-search-forward "\\\\"
5680 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5681 end
; bounded by end-of-line
5682 1) ; no matches, move to end & return nil
5683 (goto-char (match-beginning 2))
5686 (goto-char (1+ (match-end 2))))))))
5687 ;;;_ > allout-insert-latex-header (buffer)
5688 (defun allout-insert-latex-header (buffer)
5689 "Insert initial LaTeX commands at point in BUFFER."
5690 ;; Much of this is being derived from the stuff in appendix of E in
5691 ;; the TeXBook, pg 421.
5693 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5695 (page-numbering (if allout-number-pages
5696 "\\pagestyle{empty}\n"
5698 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5699 allout-title-style
))
5700 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5701 allout-label-style
))
5702 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5703 allout-head-line-style
))
5704 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5705 allout-body-line-style
))
5706 (setlength (format "%s%s%s%s"
5707 "\\newlength{\\stepsize}\n"
5708 "\\setlength{\\stepsize}{"
5711 (oneheadline (format "%s%s%s%s%s%s%s"
5712 "\\newcommand{\\OneHeadLine}[3]{%\n"
5714 "\\hspace*{#2\\stepsize}%\n"
5715 "\\labelcmd{#1}\\hspace*{.2cm}"
5716 "\\headlinecmd{#3}\\\\["
5719 (onebodyline (format "%s%s%s%s%s%s"
5720 "\\newcommand{\\OneBodyLine}[2]{%\n"
5722 "\\hspace*{#1\\stepsize}%\n"
5723 "\\bodylinecmd{#2}\\\\["
5726 (begindoc "\\begin{document}\n\\begin{center}\n")
5727 (title (format "%s%s%s%s"
5729 (allout-latex-verb-quote (if allout-title
5732 (error "<unnamed buffer>"))
5735 "\\end{center}\n\n"))
5736 (hsize "\\hsize = 7.5 true in\n")
5737 (hoffset "\\hoffset = -1.5 true in\n")
5738 (vspace "\\vspace{.1cm}\n\n"))
5739 (insert (concat doc-style
5754 ;;;_ > allout-insert-latex-trailer (buffer)
5755 (defun allout-insert-latex-trailer (buffer)
5756 "Insert concluding LaTeX commands at point in BUFFER."
5758 (insert "\n\\end{document}\n"))
5759 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5760 (defun allout-latexify-one-item (depth prefix bullet text
)
5761 "Insert LaTeX commands for formatting one outline item.
5763 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5764 BULLET string, and a list of TEXT strings for the body."
5765 (let* ((head-line (if text
(car text
)))
5766 (body-lines (cdr text
))
5770 (insert (concat "\\OneHeadLine{\\verb\1 "
5771 (allout-latex-verb-quote bullet
)
5776 (allout-latex-verb-quote head-line
)
5779 (if (not body-lines
)
5781 ;;(insert "\\beginlines\n")
5782 (insert "\\begin{verbatim}\n")
5784 (setq curr-line
(car body-lines
))
5785 (if (and (not body-content
)
5786 (not (string-match "^\\s-*$" curr-line
)))
5787 (setq body-content t
))
5788 ; Mangle any occurrences of
5789 ; "\end{verbatim}" in text,
5791 (if (and body-content
5792 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
5793 (setq curr-line
(concat (substring curr-line
0 bop
)
5795 (substring curr-line bop
))))
5796 ;;(insert "|" (car body-lines) "|")
5798 (allout-latex-verbatim-quote-curr-line)
5800 (setq body-lines
(cdr body-lines
)))
5802 (setq body-content nil
)
5806 ;;(insert "\\endlines\n")
5807 (insert "\\end{verbatim}\n")
5809 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5810 (defun allout-latexify-exposed (arg &optional tobuf
)
5811 "Format current topics exposed portions to TOBUF for LaTeX processing.
5812 TOBUF defaults to a buffer named the same as the current buffer, but
5813 with \"*\" prepended and \" latex-formed*\" appended.
5815 With repeat count, copy the exposed portions of entire buffer."
5820 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5821 (let* ((start-pt (point))
5822 (beg (if arg
(point-min) (allout-back-to-current-heading)))
5823 (end (if arg
(point-max) (allout-end-of-current-subtree)))
5824 (buf (current-buffer)))
5827 (allout-insert-latex-header tobuf
)
5828 (goto-char (point-max))
5829 (allout-process-exposed 'allout-latexify-one-item
5834 (goto-char (point-max))
5835 (allout-insert-latex-trailer tobuf
)
5836 (goto-char (point-min))
5838 (goto-char start-pt
)))
5841 ;;;_ > allout-toggle-current-subtree-encryption (&optional fetch-pass)
5842 (defun allout-toggle-current-subtree-encryption (&optional fetch-pass
)
5843 "Encrypt clear or decrypt encoded text of visibly-containing topic's contents.
5845 Optional FETCH-PASS universal argument provokes key-pair encryption with
5846 single universal argument. With doubled universal argument (value = 16),
5847 it forces prompting for the passphrase regardless of availability from the
5848 passphrase cache. With no universal argument, the appropriate passphrase
5849 is obtained from the cache, if available, else from the user.
5851 Only GnuPG encryption is supported.
5853 \*NOTE WELL* that the encrypted text must be ascii-armored. For gnupg
5854 encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file.
5856 Both symmetric-key and key-pair encryption is implemented. Symmetric is
5857 the default, use a single (x4) universal argument for keypair mode.
5859 Encrypted topic's bullet is set to a `~' to signal that the contents of the
5860 topic (body and subtopics, but not heading) is pending encryption or
5861 encrypted. `*' asterisk immediately after the bullet signals that the body
5862 is encrypted, its' absence means the topic is meant to be encrypted but is
5863 not. When a file with topics pending encryption is saved, topics pending
5864 encryption are encrypted. See allout-encrypt-unencrypted-on-saves for
5865 auto-encryption specifics.
5867 \*NOTE WELL* that automatic encryption that happens during saves will
5868 default to symmetric encryption -- you must deliberately (re)encrypt key-pair
5869 encrypted topics if you want them to continue to use the key-pair cipher.
5871 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5872 encrypted. If you want to encrypt the contents of a top-level topic, use
5873 \\[allout-shift-in] to increase its depth.
5877 The encryption passphrase is solicited if not currently available in the
5878 passphrase cache from a recent encryption action.
5880 The solicited passphrase is retained for reuse in a cache, if enabled. See
5881 `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry' for details.
5883 Symmetric Passphrase Hinting and Verification
5885 If the file previously had no associated passphrase, or had a different
5886 passphrase than specified, the user is prompted to repeat the new one for
5887 corroboration. A random string encrypted by the new passphrase is set on
5888 the buffer-specific variable `allout-passphrase-verifier-string', for
5889 confirmation of the passphrase when next obtained, before encrypting or
5890 decrypting anything with it. This helps avoid mistakenly shifting between
5893 If allout customization var `allout-passphrase-verifier-handling' is
5894 non-nil, an entry for `allout-passphrase-verifier-string' and its value is
5895 added to an Emacs 'local variables' section at the end of the file, which
5896 is created if necessary. That setting is for retention of the passphrase
5897 verifier across Emacs sessions.
5899 Similarly, `allout-passphrase-hint-string' stores a user-provided reminder
5900 about their passphrase, and `allout-passphrase-hint-handling' specifies
5901 when the hint is presented, or if passphrase hints are disabled. If
5902 enabled (see the `allout-passphrase-hint-handling' docstring for details),
5903 the hint string is stored in the local-variables section of the file, and
5904 solicited whenever the passphrase is changed."
5907 (allout-back-to-current-heading)
5908 (allout-toggle-subtree-encryption fetch-pass
)
5911 ;;;_ > allout-toggle-subtree-encryption (&optional fetch-pass)
5912 (defun allout-toggle-subtree-encryption (&optional fetch-pass
)
5913 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5915 Optional FETCH-PASS universal argument provokes key-pair encryption with
5916 single universal argument. With doubled universal argument (value = 16),
5917 it forces prompting for the passphrase regardless of availability from the
5918 passphrase cache. With no universal argument, the appropriate passphrase
5919 is obtained from the cache, if available, else from the user.
5921 Currently only GnuPG encryption is supported, and integration
5922 with gpg-agent is not yet implemented.
5924 \**NOTE WELL** that the encrypted text must be ascii-armored. For gnupg
5925 encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file.
5927 See `allout-toggle-current-subtree-encryption' for more details."
5931 (allout-end-of-prefix t
)
5933 (if (= allout-recent-depth
1)
5934 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5935 " shift it in to make it encryptable")))
5937 (let* ((allout-buffer (current-buffer))
5939 (bullet-pos allout-recent-prefix-beginning
)
5940 (after-bullet-pos (point))
5942 (progn (if (= (point-max) after-bullet-pos
)
5943 (error "no body to encrypt"))
5944 (allout-encrypted-topic-p)))
5945 (was-collapsed (if (not (search-forward "\n" nil t
))
5949 (subtree-beg (1+ (point)))
5950 (subtree-end (allout-end-of-subtree))
5951 (subject-text (buffer-substring-no-properties subtree-beg
5953 (subtree-end-char (char-after (1- subtree-end
)))
5954 (subtree-trailing-char (char-after subtree-end
))
5955 ;; kluge -- result-text needs to be nil, but we also want to
5956 ;; check for the error condition
5957 (result-text (if (or (string= "" subject-text
)
5958 (string= "\n" subject-text
))
5959 (error "No topic contents to %scrypt"
5960 (if was-encrypted
"de" "en"))
5962 ;; Assess key parameters:
5964 ;; detect the type by which it is already encrypted
5966 (allout-encrypted-key-info subject-text
))
5967 (and (member fetch-pass
'(4 (4)))
5970 (for-key-type (car key-info
))
5971 (for-key-identity (cadr key-info
))
5972 (fetch-pass (and fetch-pass
(member fetch-pass
'(16 (16)))))
5973 (was-coding-system buffer-file-coding-system
))
5975 (when (not was-encrypted
)
5976 ;; ensure that non-ascii chars pending encryption are noticed before
5977 ;; they're encrypted, so the coding system is set to accommodate
5979 (setq buffer-file-coding-system
5980 (select-safe-coding-system subtree-beg subtree-end
))
5981 ;; if the coding system for the text being encrypted is different
5982 ;; than that prevailing, then there a real risk that the coding
5983 ;; system can't be noticed by emacs when the file is visited. to
5984 ;; mitigate that, offer to preserve the coding system using a file
5986 (if (and (not (equal buffer-file-coding-system
5989 (format (concat "Register coding system %s as file local"
5990 " var? Necessary when only encrypted text"
5991 " is in that coding system. ")
5992 buffer-file-coding-system
)))
5993 (allout-adjust-file-variable "buffer-file-coding-system"
5994 buffer-file-coding-system
)))
5997 (allout-encrypt-string subject-text was-encrypted
5999 for-key-type for-key-identity fetch-pass
))
6001 ;; Replace the subtree with the processed product.
6004 (set-buffer allout-buffer
)
6005 (delete-region subtree-beg subtree-end
)
6006 (insert result-text
)
6008 (allout-flag-region (1- subtree-beg
) (point) t
))
6009 ;; adjust trailing-blank-lines to preserve topic spacing:
6010 (if (not was-encrypted
)
6011 (if (and (= subtree-end-char ?
\n)
6012 (= subtree-trailing-char ?
\n))
6013 (insert subtree-trailing-char
)))
6014 ;; Ensure that the item has an encrypted-entry bullet:
6015 (if (not (string= (buffer-substring-no-properties
6016 (1- after-bullet-pos
) after-bullet-pos
)
6017 allout-topic-encryption-bullet
))
6018 (progn (goto-char (1- after-bullet-pos
))
6020 (insert allout-topic-encryption-bullet
)))
6022 ;; Remove the is-encrypted bullet qualifier:
6023 (progn (goto-char after-bullet-pos
)
6025 ;; Add the is-encrypted bullet qualifier:
6026 (goto-char after-bullet-pos
)
6028 (run-hook-with-args 'allout-structure-added-hook
6029 bullet-pos subtree-end
))))
6030 ;;;_ > allout-encrypt-string (text decrypt allout-buffer key-type for-key
6031 ;;; fetch-pass &optional retried verifying
6033 (defun allout-encrypt-string (text decrypt allout-buffer key-type for-key
6034 fetch-pass
&optional retried rejected
6035 verifying passphrase
)
6036 "Encrypt or decrypt message TEXT.
6038 If DECRYPT is true (default false), then decrypt instead of encrypt.
6040 FETCH-PASS (default false) forces fresh prompting for the passphrase.
6042 KEY-TYPE, either `symmetric' or `keypair', specifies which type
6045 FOR-KEY is human readable identification of the first of the user's
6046 eligible secret keys a keypair decryption targets, or else nil.
6048 Optional RETRIED is for internal use -- conveys the number of failed keys
6049 that have been solicited in sequence leading to this current call.
6051 Optional PASSPHRASE enables explicit delivery of the decryption passphrase,
6052 for verification purposes.
6054 Optional REJECTED is for internal use -- conveys the number of
6055 rejections due to matches against
6056 `allout-encryption-ciphertext-rejection-regexps', as limited by
6057 `allout-encryption-ciphertext-rejection-ceiling'.
6059 Returns the resulting string, or nil if the transformation fails."
6063 (if (not (fboundp 'pgg-encrypt-symmetric
))
6064 (error "Allout encryption depends on a newer version of pgg"))
6066 (let* ((scheme (upcase
6067 (format "%s" (or pgg-scheme pgg-default-scheme
"GPG"))))
6068 (for-key (and (equal key-type
'keypair
)
6070 (split-string (read-string
6071 (format "%s message recipients: "
6074 (target-prompt-id (if (equal key-type
'keypair
)
6075 (if (= (length for-key
) 1)
6076 (car for-key
) for-key
)
6077 (buffer-name allout-buffer
)))
6078 (target-cache-id (format "%s-%s"
6080 (if (equal key-type
'keypair
)
6082 (or (buffer-file-name allout-buffer
)
6083 target-prompt-id
))))
6084 (encoding (with-current-buffer allout-buffer
6085 buffer-file-coding-system
))
6086 (multibyte (with-current-buffer allout-buffer
6087 enable-multibyte-characters
))
6088 (strip-plaintext-regexps
6090 (allout-get-configvar-values
6091 'allout-encryption-plaintext-sanitization-regexps
)))
6092 (reject-ciphertext-regexps
6094 (allout-get-configvar-values
6095 'allout-encryption-ciphertext-rejection-regexps
)))
6096 (rejected (or rejected
0))
6097 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6102 (if (and fetch-pass
(not passphrase
))
6103 ;; Force later fetch by evicting passphrase from the cache.
6104 (pgg-remove-passphrase-from-cache target-cache-id t
))
6106 (catch 'encryption-failed
6108 ;; We handle only symmetric-key passphrase caching.
6109 (if (and (not passphrase
)
6110 (not (equal key-type
'keypair
)))
6111 (setq passphrase
(allout-obtain-passphrase for-key
6116 retried fetch-pass
)))
6122 ;; convey the text characteristics of the original buffer:
6123 (set-buffer-multibyte multibyte
)
6125 (set-buffer-file-coding-system encoding
)
6127 (encode-coding-region (point-min) (point-max) encoding
)))
6129 (when (and strip-plaintext-regexps
(not decrypt
))
6130 (dolist (re strip-plaintext-regexps
)
6131 (let ((re (if (listp re
) (car re
) re
))
6132 (replacement (if (listp re
) (cadr re
) "")))
6133 (goto-char (point-min))
6135 (while (re-search-forward re nil t
)
6136 (replace-match replacement nil nil
))))))
6141 ((equal key-type
'symmetric
)
6145 (pgg-decrypt (point-min) (point-max) passphrase
)
6147 (pgg-encrypt-symmetric (point-min) (point-max)
6151 (pgg-situate-output (point-min) (point-max))
6152 ;; failed -- handle passphrase caching
6154 (throw 'encryption-failed nil
)
6155 (pgg-remove-passphrase-from-cache target-cache-id t
)
6156 (error "Symmetric-cipher %scryption failed -- %s"
6157 (if decrypt
"de" "en")
6158 "try again with different passphrase"))))
6160 ;; encrypt `keypair':
6165 (pgg-encrypt for-key
6166 nil
(point-min) (point-max) passphrase
))
6169 (pgg-situate-output (point-min) (point-max))
6170 (error (pgg-remove-passphrase-from-cache target-cache-id t
)
6171 (error "encryption failed"))))
6173 ;; decrypt `keypair':
6177 (pgg-decrypt (point-min) (point-max) passphrase
))
6180 (pgg-situate-output (point-min) (point-max))
6181 (error (pgg-remove-passphrase-from-cache target-cache-id t
)
6182 (error "decryption failed")))))
6185 (buffer-substring-no-properties
6186 1 (- (point-max) (if decrypt
0 1))))
6189 ;; validate result -- non-empty
6190 (cond ((not result-text
)
6193 ;; transform was fruitless, retry w/new passphrase.
6194 (pgg-remove-passphrase-from-cache target-cache-id t
)
6195 (allout-encrypt-string text decrypt allout-buffer
6196 key-type for-key nil
6197 (if retried
(1+ retried
) 1)
6198 rejected verifying nil
)))
6200 ;; Retry (within limit) if ciphertext contains rejections:
6202 ;; Check for disqualification of this ciphertext:
6203 (let ((regexps reject-ciphertext-regexps
)
6205 (while (and regexps
(not reject-it
))
6206 (setq reject-it
(string-match (car regexps
)
6210 (setq rejections-left
(1- rejections-left
))
6211 (if (<= rejections-left
0)
6212 (error (concat "Ciphertext rejected too many times"
6214 allout-encryption-ciphertext-rejection-ceiling
6215 'allout-encryption-ciphertext-rejection-regexps
)
6216 (allout-encrypt-string text decrypt allout-buffer
6217 key-type for-key nil
6218 retried
(1+ rejected
)
6219 verifying passphrase
)))
6220 ;; Barf if encryption yields extraordinary control chars:
6222 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6224 (error (concat "Encryption produced non-armored text, which"
6225 "conflicts with allout mode -- reconfigure!")))
6227 ;; valid result and just verifying or non-symmetric:
6228 ((or verifying
(not (equal key-type
'symmetric
)))
6229 (if (or verifying decrypt
)
6230 (pgg-add-passphrase-to-cache target-cache-id
6234 ;; valid result and regular symmetric -- "register"
6235 ;; passphrase with mnemonic aids/cache.
6237 (set-buffer allout-buffer
)
6239 (pgg-add-passphrase-to-cache target-cache-id
6241 (allout-update-passphrase-mnemonic-aids for-key passphrase
6248 ;;;_ > allout-obtain-passphrase (for-key cache-id prompt-id key-type
6249 ;;; allout-buffer retried fetch-pass)
6250 (defun allout-obtain-passphrase (for-key cache-id prompt-id key-type
6251 allout-buffer retried fetch-pass
)
6252 "Obtain passphrase for a key from the cache or else from the user.
6254 When obtaining from the user, symmetric-cipher passphrases are verified
6255 against either, if available and enabled, a random string that was
6256 encrypted against the passphrase, or else against repeated entry by the
6257 user for corroboration.
6259 FOR-KEY is the key for which the passphrase is being obtained.
6261 CACHE-ID is the cache id of the key for the passphrase.
6263 PROMPT-ID is the id for use when prompting the user.
6265 KEY-TYPE is either `symmetric' or `keypair'.
6267 ALLOUT-BUFFER is the buffer containing the entry being en/decrypted.
6269 RETRIED is the number of this attempt to obtain this passphrase.
6271 FETCH-PASS causes the passphrase to be solicited from the user, regardless
6272 of the availability of a cached copy."
6274 (if (not (equal key-type
'symmetric
))
6275 ;; do regular passphrase read on non-symmetric passphrase:
6276 (pgg-read-passphrase (format "%s passphrase%s: "
6277 (upcase (format "%s" (or pgg-scheme
6281 (format " for %s" prompt-id
)
6285 ;; Symmetric hereon:
6288 (set-buffer allout-buffer
)
6289 (let* ((hint (if (and (not (string= allout-passphrase-hint-string
""))
6290 (or (equal allout-passphrase-hint-handling
'always
)
6291 (and (equal allout-passphrase-hint-handling
6294 (format " [%s]" allout-passphrase-hint-string
)
6296 (retry-message (if retried
(format " (%s retry)" retried
) ""))
6297 (prompt-sans-hint (format "'%s' symmetric passphrase%s: "
6298 prompt-id retry-message
))
6299 (full-prompt (format "'%s' symmetric passphrase%s%s: "
6300 prompt-id hint retry-message
))
6301 (prompt full-prompt
)
6302 (verifier-string (allout-get-encryption-passphrase-verifier))
6304 (cached (and (not fetch-pass
)
6305 (pgg-read-passphrase-from-cache cache-id t
)))
6306 (got-pass (or cached
6307 (pgg-read-passphrase full-prompt cache-id t
)))
6313 ;; Duplicate our handle on the passphrase so it's not clobbered by
6314 ;; deactivate-passwd memory clearing:
6315 (setq got-pass
(copy-sequence got-pass
))
6317 (cond (verifier-string
6318 (save-window-excursion
6319 (if (allout-encrypt-string verifier-string
'decrypt
6320 allout-buffer
'symmetric
6321 for-key nil
0 0 'verifying
6322 (copy-sequence got-pass
))
6323 (setq confirmation
(format "%s" got-pass
))))
6325 (if (and (not confirmation
)
6327 (concat "Passphrase differs from established"
6328 " -- use new one instead? "))
6329 ;; deactivate password for subsequent
6332 (pgg-remove-passphrase-from-cache cache-id t
)
6333 (setq prompt prompt-sans-hint
)
6336 (progn (pgg-remove-passphrase-from-cache cache-id t
)
6337 (error "Wrong passphrase."))))
6338 ;; No verifier string -- force confirmation by repetition of
6339 ;; (new) passphrase:
6340 ((or fetch-pass
(not cached
))
6341 (pgg-remove-passphrase-from-cache cache-id t
))))
6342 ;; confirmation vs new input -- doing pgg-read-passphrase will do the
6343 ;; right thing, in either case:
6344 (if (not confirmation
)
6346 (pgg-read-passphrase (concat prompt
6347 " ... confirm spelling: ")
6350 (if (equal got-pass confirmation
)
6352 (if (yes-or-no-p (concat "spelling of original and"
6353 " confirmation differ -- retry? "))
6354 (progn (setq retried
(if retried
(1+ retried
) 1))
6355 (pgg-remove-passphrase-from-cache cache-id t
)
6356 ;; recurse to this routine:
6357 (pgg-read-passphrase prompt-sans-hint cache-id t
))
6358 (pgg-remove-passphrase-from-cache cache-id t
)
6359 (error "Confirmation failed."))))))))
6360 ;;;_ > allout-encrypted-topic-p ()
6361 (defun allout-encrypted-topic-p ()
6362 "True if the current topic is encryptable and encrypted."
6364 (allout-end-of-prefix t
)
6365 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6366 allout-topic-encryption-bullet
)
6367 (save-match-data (looking-at "\\*")))
6370 ;;;_ > allout-encrypted-key-info (text)
6371 ;; XXX gpg-specific, alas
6372 (defun allout-encrypted-key-info (text)
6373 "Return a pair of the key type and identity of a recipient's secret key.
6375 The key type is one of `symmetric' or `keypair'.
6377 If `keypair', and some of the user's secret keys are among those for which
6378 the message was encoded, return the identity of the first. Otherwise,
6379 return nil for the second item of the pair.
6381 An error is raised if the text is not encrypted."
6382 (require 'pgg-parse
)
6386 (let* ((parsed-armor (pgg-parse-armor-region (point-min) (point-max)))
6387 (type (if (pgg-gpg-symmetric-key-p parsed-armor
)
6390 secret-keys first-secret-key for-key-owner
)
6391 (if (equal type
'keypair
)
6392 (setq secret-keys
(pgg-gpg-lookup-all-secret-keys)
6393 first-secret-key
(pgg-gpg-select-matching-key parsed-armor
6395 for-key-owner
(and first-secret-key
6396 (pgg-gpg-lookup-key-owner
6397 first-secret-key
))))
6398 (list type
(pgg-gpg-key-id-from-key-owner for-key-owner
))
6403 ;;;_ > allout-create-encryption-passphrase-verifier (passphrase)
6404 (defun allout-create-encryption-passphrase-verifier (passphrase)
6405 "Encrypt random message for later validation of symmetric key's passphrase."
6406 ;; use 20 random ascii characters, across the entire ascii range.
6408 (let ((spew (make-string 20 ?\
0)))
6409 (dotimes (i (length spew
))
6410 (aset spew i
(1+ (random 254))))
6411 (allout-encrypt-string spew nil
(current-buffer) 'symmetric
6412 nil nil
0 0 passphrase
))
6414 ;;;_ > allout-update-passphrase-mnemonic-aids (for-key passphrase
6416 (defun allout-update-passphrase-mnemonic-aids (for-key passphrase
6418 "Update passphrase verifier and hint strings if necessary.
6420 See `allout-passphrase-verifier-string' and `allout-passphrase-hint-string'
6423 PASSPHRASE is the passphrase being mnemonicized.
6425 OUTLINE-BUFFER is the buffer of the outline being adjusted.
6427 These are used to help the user keep track of the passphrase they use for
6428 symmetric encryption in the file.
6430 Behavior is governed by `allout-passphrase-verifier-handling',
6431 `allout-passphrase-hint-handling', and also, controlling whether the values
6432 are preserved on Emacs local file variables,
6433 `allout-enable-file-variable-adjustment'."
6435 ;; If passphrase doesn't agree with current verifier:
6436 ;; - adjust the verifier
6437 ;; - if passphrase hint handling is enabled, adjust the passphrase hint
6438 ;; - if file var settings are enabled, adjust the file vars
6440 (let* ((new-verifier-needed (not (allout-verify-passphrase
6441 for-key passphrase outline-buffer
)))
6442 (new-verifier-string
6443 (if new-verifier-needed
6444 ;; Collapse to a single line and enclose in string quotes:
6445 (subst-char-in-string
6446 ?
\n ?\C-a
(allout-create-encryption-passphrase-verifier
6449 (when new-verifier-string
6450 ;; do the passphrase hint first, since it's interactive
6451 (when (and allout-passphrase-hint-handling
6452 (not (equal allout-passphrase-hint-handling
'disabled
)))
6454 (read-from-minibuffer "Passphrase hint to jog your memory: "
6455 allout-passphrase-hint-string
))
6456 (when (not (string= new-hint allout-passphrase-hint-string
))
6457 (setq allout-passphrase-hint-string new-hint
)
6458 (allout-adjust-file-variable "allout-passphrase-hint-string"
6459 allout-passphrase-hint-string
)))
6460 (when allout-passphrase-verifier-handling
6461 (setq allout-passphrase-verifier-string new-verifier-string
)
6462 (allout-adjust-file-variable "allout-passphrase-verifier-string"
6463 allout-passphrase-verifier-string
))
6467 ;;;_ > allout-get-encryption-passphrase-verifier ()
6468 (defun allout-get-encryption-passphrase-verifier ()
6469 "Return text of the encrypt passphrase verifier, unmassaged, or nil if none.
6471 Derived from value of `allout-passphrase-verifier-string'."
6473 (let ((verifier-string (and (boundp 'allout-passphrase-verifier-string
)
6474 allout-passphrase-verifier-string
)))
6476 ;; Return it uncollapsed
6477 (subst-char-in-string ?\C-a ?
\n verifier-string
))
6480 ;;;_ > allout-verify-passphrase (key passphrase allout-buffer)
6481 (defun allout-verify-passphrase (key passphrase allout-buffer
)
6482 "True if passphrase successfully decrypts verifier, nil otherwise.
6484 \"Otherwise\" includes absence of passphrase verifier."
6486 (set-buffer allout-buffer
)
6487 (and (boundp 'allout-passphrase-verifier-string
)
6488 allout-passphrase-verifier-string
6489 (allout-encrypt-string (allout-get-encryption-passphrase-verifier)
6490 'decrypt allout-buffer
'symmetric
6491 key nil
0 0 'verifying passphrase
)
6493 ;;;_ > allout-next-topic-pending-encryption (&optional except-mark)
6494 (defun allout-next-topic-pending-encryption (&optional except-mark
)
6495 "Return the point of the next topic pending encryption, or nil if none.
6497 EXCEPT-MARK identifies a point whose containing topics should be excluded
6498 from encryption. This supports 'except-current mode of
6499 `allout-encrypt-unencrypted-on-saves'.
6501 Such a topic has the `allout-topic-encryption-bullet' without an
6502 immediately following '*' that would mark the topic as being encrypted. It
6503 must also have content."
6504 (let (done got content-beg
)
6508 (if (not (re-search-forward
6509 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6510 (regexp-quote allout-header-prefix
)
6511 (regexp-quote allout-topic-encryption-bullet
))
6515 (goto-char (setq got
(match-beginning 0)))
6516 (if (save-match-data (looking-at "\n"))
6523 ((not (search-forward "\n"))
6532 (setq content-beg
(point))
6534 (allout-end-of-subtree)
6535 (if (or (<= (point) content-beg
)
6537 (<= content-beg except-mark
)
6538 (>= (point) except-mark
)))
6550 ;;;_ > allout-encrypt-decrypted (&optional except-mark)
6551 (defun allout-encrypt-decrypted (&optional except-mark
)
6552 "Encrypt topics pending encryption except those containing exemption point.
6554 EXCEPT-MARK identifies a point whose containing topics should be excluded
6555 from encryption. This supports the `except-current' mode of
6556 `allout-encrypt-unencrypted-on-saves'.
6558 If a topic that is currently being edited was encrypted, we return a list
6559 containing the location of the topic and the location of the cursor just
6560 before the topic was encrypted. This can be used, eg, to decrypt the topic
6561 and exactly resituate the cursor if this is being done as part of a file
6562 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6567 (let* ((current-mark (point-marker))
6568 (current-mark-position (marker-position current-mark
))
6571 editing-topic editing-point
)
6572 (goto-char (point-min))
6573 (while (allout-next-topic-pending-encryption except-mark
)
6574 (setq was-modified
(buffer-modified-p))
6575 (when (save-excursion
6576 (and (boundp 'allout-encrypt-unencrypted-on-saves
)
6577 allout-encrypt-unencrypted-on-saves
6578 (setq bo-subtree
(re-search-forward "$"))
6579 (not (allout-hidden-p))
6580 (>= current-mark
(point))
6581 (allout-end-of-current-subtree)
6582 (<= current-mark
(point))))
6583 (setq editing-topic
(point)
6584 ;; we had to wait for this 'til now so prior topics are
6585 ;; encrypted, any relevant text shifts are in place:
6586 editing-point
(- current-mark-position
6587 (count-trailing-whitespace-region
6588 bo-subtree current-mark-position
))))
6589 (allout-toggle-subtree-encryption)
6590 (if (not was-modified
)
6591 (set-buffer-modified-p nil
))
6593 (if (not was-modified
)
6594 (set-buffer-modified-p nil
))
6595 (if editing-topic
(list editing-topic editing-point
))
6601 ;;;_ #9 miscellaneous
6603 ;;;_ > outlineify-sticky ()
6604 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6606 (defalias 'outlinify-sticky
'outlineify-sticky
)
6608 (defun outlineify-sticky (&optional arg
)
6609 "Activate outline mode and establish file var so it is started subsequently.
6611 See doc-string for `allout-layout' and `allout-init' for details on
6612 setup for auto-startup."
6619 (goto-char (point-min))
6620 (if (allout-goto-prefix)
6622 (allout-open-topic 2)
6623 (insert (concat "Dummy outline topic header -- see"
6624 "`allout-mode' docstring: `^Hm'."))
6625 (allout-adjust-file-variable
6626 "allout-layout" (or allout-layout
'(-1 : 0))))))
6627 ;;;_ > allout-file-vars-section-data ()
6628 (defun allout-file-vars-section-data ()
6629 "Return data identifying the file-vars section, or nil if none.
6631 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6632 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6633 (let (beg prefix suffix
)
6635 (goto-char (point-max))
6636 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move
)
6637 (if (let ((case-fold-search t
))
6638 (not (search-forward "Local Variables:" nil t
)))
6640 (setq beg
(- (point) 16))
6641 (setq suffix
(buffer-substring-no-properties
6643 (progn (if (search-forward "\n" nil t
)
6646 (setq prefix
(buffer-substring-no-properties
6647 (progn (if (search-backward "\n" nil t
)
6651 (list beg prefix suffix
))
6655 ;;;_ > allout-adjust-file-variable (varname value)
6656 (defun allout-adjust-file-variable (varname value
)
6657 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6659 This activity is inhibited if either `enable-local-variables'
6660 `allout-enable-file-variable-adjustment' are nil.
6662 When enabled, an entry for the variable is created if not already present,
6663 or changed if established with a different value. The section for the file
6664 variables, itself, is created if not already present. When created, the
6665 section lines (including the section line) exist as second-level topics in
6666 a top-level topic at the end of the file.
6668 `enable-local-variables' must be true for any of this to happen."
6669 (if (not (and enable-local-variables
6670 allout-enable-file-variable-adjustment
))
6673 (let ((inhibit-field-text-motion t
)
6674 (section-data (allout-file-vars-section-data))
6677 (setq beg
(car section-data
)
6678 prefix
(cadr section-data
)
6679 suffix
(car (cddr section-data
)))
6680 ;; create the section
6681 (goto-char (point-max))
6683 (allout-open-topic 0)
6685 (insert "Local emacs vars.\n")
6686 (allout-open-topic 1)
6689 prefix
(buffer-substring-no-properties (progn
6694 (insert "Local variables:\n")
6695 (allout-open-topic 0)
6698 ;; look for existing entry or create one, leaving point for insertion
6701 (allout-show-to-offshoot)
6702 (if (search-forward (concat "\n" prefix varname
":") nil t
)
6703 (let* ((value-beg (point))
6704 (line-end (progn (if (search-forward "\n" nil t
)
6707 (value-end (- line-end
(length suffix
))))
6708 (if (> value-end value-beg
)
6709 (delete-region value-beg value-end
)))
6713 (insert (concat prefix varname
":")))
6714 (insert (format " %S%s" value suffix
))
6719 ;;;_ > allout-get-configvar-values (varname)
6720 (defun allout-get-configvar-values (configvar-name)
6721 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6723 The user is prompted for removal of symbols that are unbound, and they
6724 otherwise are ignored.
6726 CONFIGVAR-NAME should be the name of the configuration variable,
6729 (let ((configvar-value (symbol-value configvar-name
))
6731 (dolist (sym configvar-value
)
6732 (if (not (boundp sym
))
6733 (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? "
6734 configvar-name sym
))
6735 (delq sym
(symbol-value configvar-name
)))
6736 (push (symbol-value sym
) got
)))
6739 ;;;_ > allout-mark-topic ()
6740 (defun allout-mark-topic ()
6741 "Put the region around topic currently containing point."
6743 (let ((inhibit-field-text-motion t
))
6744 (beginning-of-line))
6745 (allout-goto-prefix-doublechecked)
6747 (allout-end-of-current-subtree)
6748 (exchange-point-and-mark))
6750 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6751 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
6752 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6754 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6756 (let ((new-prompt prompt
)
6760 (message "%s" new-prompt
)
6762 ;; We do our own reading here, so we can circumvent, eg, special
6763 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6765 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
6768 (cond ((string-match (regexp-quote got
) string
) got
)
6769 ((and do-defaulting
(string= got
"\r"))
6770 ;; Return empty string to default:
6772 ((string= got
"\C-g") (signal 'quit nil
))
6774 (setq new-prompt
(concat prompt
6780 ;; got something out of loop -- return it:
6784 ;;;_ > regexp-sans-escapes (string)
6785 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
6786 "Return a copy of REGEXP with all character escapes stripped out.
6788 Representations of actual backslashes -- '\\\\\\\\' -- are left as a
6791 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6793 (if (string= regexp
"")
6795 ;; Set successive-backslashes to number if current char is
6796 ;; backslash, or else to nil:
6797 (setq successive-backslashes
6798 (if (= (aref regexp
0) ?
\\)
6799 (if successive-backslashes
(1+ successive-backslashes
) 1)
6801 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
6802 ;; Include first char:
6803 (concat (substring regexp
0 1)
6804 (regexp-sans-escapes (substring regexp
1)))
6805 ;; Exclude first char, but maintain count:
6806 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
6807 ;;;_ > count-trailing-whitespace-region (beg end)
6808 (defun count-trailing-whitespace-region (beg end
)
6809 "Return number of trailing whitespace chars between BEG and END.
6811 If BEG is bigger than END we return 0."
6818 (while (re-search-forward "[ ][ ]*$" end t
)
6819 (goto-char (1+ (match-beginning 2)))
6820 (setq count
(1+ count
)))
6822 ;;;_ > allout-format-quote (string)
6823 (defun allout-format-quote (string)
6824 "Return a copy of string with all \"%\" characters doubled."
6826 (mapcar (lambda (char) (if (= char ?%
) "%%" (char-to-string char
)))
6829 ;;;_ > allout-flatten (list)
6830 (defun allout-flatten (list)
6831 "Return a list of all atoms in list."
6833 (cond ((null list
) nil
)
6834 ((atom (car list
)) (cons (car list
) (allout-flatten (cdr list
))))
6835 (t (append (allout-flatten (car list
)) (allout-flatten (cdr list
))))))
6836 ;;;_ : Compatibility:
6837 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6838 (defun allout-mark-marker (&optional force buffer
)
6839 "Accommodate the different signature for `mark-marker' across Emacsen.
6841 XEmacs takes two optional args, while mainline GNU Emacs does not,
6842 so pass them along when appropriate."
6843 (if (featurep 'xemacs
)
6844 (apply 'mark-marker force buffer
)
6846 ;;;_ > subst-char-in-string if necessary
6847 (if (not (fboundp 'subst-char-in-string
))
6848 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
6849 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6850 Unless optional argument INPLACE is non-nil, return a new string."
6851 (let ((i (length string
))
6852 (newstr (if inplace string
(copy-sequence string
))))
6855 (if (eq (aref newstr i
) fromchar
)
6856 (aset newstr i tochar
)))
6858 ;;;_ > wholenump if necessary
6859 (if (not (fboundp 'wholenump
))
6860 (defalias 'wholenump
'natnump
))
6861 ;;;_ > remove-overlays if necessary
6862 (if (not (fboundp 'remove-overlays
))
6863 (defun remove-overlays (&optional beg end name val
)
6864 "Clear BEG and END of overlays whose property NAME has value VAL.
6865 Overlays might be moved and/or split.
6866 BEG and END default respectively to the beginning and end of buffer."
6867 (unless beg
(setq beg
(point-min)))
6868 (unless end
(setq end
(point-max)))
6870 (setq beg
(prog1 end
(setq end beg
))))
6872 (dolist (o (overlays-in beg end
))
6873 (when (eq (overlay-get o name
) val
)
6874 ;; Either push this overlay outside beg...end
6875 ;; or split it to exclude beg...end
6876 ;; or delete it entirely (if it is contained in beg...end).
6877 (if (< (overlay-start o
) beg
)
6878 (if (> (overlay-end o
) end
)
6880 (move-overlay (copy-overlay o
)
6881 (overlay-start o
) beg
)
6882 (move-overlay o end
(overlay-end o
)))
6883 (move-overlay o
(overlay-start o
) beg
))
6884 (if (> (overlay-end o
) end
)
6885 (move-overlay o end
(overlay-end o
))
6886 (delete-overlay o
)))))))
6888 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6889 (if (not (fboundp 'copy-overlay
))
6890 (defun copy-overlay (o)
6891 "Return a copy of overlay O."
6892 (let ((o1 (make-overlay (overlay-start o
) (overlay-end o
)
6893 ;; FIXME: there's no easy way to find the
6894 ;; insertion-type of the two markers.
6895 (overlay-buffer o
)))
6896 (props (overlay-properties o
)))
6898 (overlay-put o1
(pop props
) (pop props
)))
6900 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6901 (if (not (fboundp 'add-to-invisibility-spec
))
6902 (defun add-to-invisibility-spec (element)
6903 "Add ELEMENT to `buffer-invisibility-spec'.
6904 See documentation for `buffer-invisibility-spec' for the kind of elements
6906 (if (eq buffer-invisibility-spec t
)
6907 (setq buffer-invisibility-spec
(list t
)))
6908 (setq buffer-invisibility-spec
6909 (cons element buffer-invisibility-spec
))))
6910 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6911 (if (not (fboundp 'remove-from-invisibility-spec
))
6912 (defun remove-from-invisibility-spec (element)
6913 "Remove ELEMENT from `buffer-invisibility-spec'."
6914 (if (consp buffer-invisibility-spec
)
6915 (setq buffer-invisibility-spec
(delete element
6916 buffer-invisibility-spec
)))))
6917 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6918 (if (not (fboundp 'move-beginning-of-line
))
6919 (defun move-beginning-of-line (arg)
6920 "Move point to beginning of current line as displayed.
6921 \(This disregards invisible newlines such as those
6922 which are part of the text that an image rests on.)
6924 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6925 If point reaches the beginning or end of buffer, it stops there.
6926 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6928 (or arg
(setq arg
1))
6930 (condition-case nil
(line-move (1- arg
)) (error nil
)))
6932 ;; Move to beginning-of-line, ignoring fields and invisibles.
6933 (skip-chars-backward "^\n")
6934 (while (and (not (bobp))
6936 (get-char-property (1- (point)) 'invisible
)))
6937 (if (eq buffer-invisibility-spec t
)
6939 (or (memq prop buffer-invisibility-spec
)
6940 (assq prop buffer-invisibility-spec
)))))
6941 (goto-char (if (featurep 'xemacs
)
6942 (previous-property-change (point))
6943 (previous-char-property-change (point))))
6944 (skip-chars-backward "^\n"))
6945 (vertical-motion 0))
6947 ;;;_ > move-end-of-line if necessary -- older emacs, xemacs
6948 (if (not (fboundp 'move-end-of-line
))
6949 (defun move-end-of-line (arg)
6950 "Move point to end of current line as displayed.
6951 \(This disregards invisible newlines such as those
6952 which are part of the text that an image rests on.)
6954 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6955 If point reaches the beginning or end of buffer, it stops there.
6956 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6958 (or arg
(setq arg
1))
6963 (let ((goal-column 0))
6964 (and (condition-case nil
6965 (or (line-move arg
) t
)
6973 (get-char-property (1- (point))
6975 (if (eq buffer-invisibility-spec t
)
6978 buffer-invisibility-spec
)
6980 buffer-invisibility-spec
)))))
6982 (previous-char-property-change (point))))
6986 (if (and (> (point) newpos
)
6987 (eq (preceding-char) ?
\n))
6989 (if (and (> (point) newpos
) (not (eobp))
6990 (not (eq (following-char) ?
\n)))
6991 ;; If we skipped something intangible
6992 ;; and now we're not really at eol,
6999 ;;;_ > allout-bullet-isearch (&optional bullet)
7000 (defun allout-bullet-isearch (&optional bullet
)
7001 "Isearch (regexp) for topic with bullet BULLET."
7004 (setq bullet
(solicit-char-in-string
7005 "ISearch for topic with bullet: "
7006 (regexp-sans-escapes allout-bullets-string
))))
7008 (let ((isearch-regexp t
)
7009 (isearch-string (concat "^"
7010 allout-header-prefix
7013 (isearch-repeat 'forward
)
7016 ;;;_ #11 Unit tests -- this should be last item before "Provide"
7017 ;;;_ > allout-run-unit-tests ()
7018 (defun allout-run-unit-tests ()
7019 "Run the various allout unit tests."
7020 (message "Running allout tests...")
7021 (allout-test-resumptions)
7022 (message "Running allout tests... Done.")
7024 ;;;_ : test resumptions:
7025 ;;;_ > allout-tests-obliterate-variable (name)
7026 (defun allout-tests-obliterate-variable (name)
7027 "Completely unbind variable with NAME."
7028 (if (local-variable-p name
) (kill-local-variable name
))
7029 (while (boundp name
) (makunbound name
)))
7030 ;;;_ > allout-test-resumptions ()
7031 (defvar allout-tests-globally-unbound nil
7032 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
7033 (defvar allout-tests-globally-true nil
7034 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
7035 (defvar allout-tests-locally-true nil
7036 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
7037 (defun allout-test-resumptions ()
7038 "Exercise allout resumptions."
7039 ;; for each resumption case, we also test that the right local/global
7040 ;; scopes are affected during resumption effects:
7042 ;; ensure that previously unbound variables return to the unbound state.
7044 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
7045 (allout-add-resumptions '(allout-tests-globally-unbound t
))
7046 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
7047 (assert (local-variable-p 'allout-tests-globally-unbound
))
7048 (assert (boundp 'allout-tests-globally-unbound
))
7049 (assert (equal allout-tests-globally-unbound t
))
7050 (allout-do-resumptions)
7051 (assert (not (local-variable-p 'allout-tests-globally-unbound
)))
7052 (assert (not (boundp 'allout-tests-globally-unbound
))))
7054 ;; ensure that variable with prior global value is resumed
7056 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
7057 (setq allout-tests-globally-true t
)
7058 (allout-add-resumptions '(allout-tests-globally-true nil
))
7059 (assert (equal (default-value 'allout-tests-globally-true
) t
))
7060 (assert (local-variable-p 'allout-tests-globally-true
))
7061 (assert (equal allout-tests-globally-true nil
))
7062 (allout-do-resumptions)
7063 (assert (not (local-variable-p 'allout-tests-globally-true
)))
7064 (assert (boundp 'allout-tests-globally-true
))
7065 (assert (equal allout-tests-globally-true t
)))
7067 ;; ensure that prior local value is resumed
7069 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
7070 (set (make-local-variable 'allout-tests-locally-true
) t
)
7071 (assert (not (default-boundp 'allout-tests-locally-true
))
7072 nil
(concat "Test setup mistake -- variable supposed to"
7073 " not have global binding, but it does."))
7074 (assert (local-variable-p 'allout-tests-locally-true
)
7075 nil
(concat "Test setup mistake -- variable supposed to have"
7076 " local binding, but it lacks one."))
7077 (allout-add-resumptions '(allout-tests-locally-true nil
))
7078 (assert (not (default-boundp 'allout-tests-locally-true
)))
7079 (assert (local-variable-p 'allout-tests-locally-true
))
7080 (assert (equal allout-tests-locally-true nil
))
7081 (allout-do-resumptions)
7082 (assert (boundp 'allout-tests-locally-true
))
7083 (assert (local-variable-p 'allout-tests-locally-true
))
7084 (assert (equal allout-tests-locally-true t
))
7085 (assert (not (default-boundp 'allout-tests-locally-true
))))
7087 ;; ensure that last of multiple resumptions holds, for various scopes.
7089 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
7090 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
7091 (setq allout-tests-globally-true t
)
7092 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
7093 (set (make-local-variable 'allout-tests-locally-true
) t
)
7094 (allout-add-resumptions '(allout-tests-globally-unbound t
)
7095 '(allout-tests-globally-true nil
)
7096 '(allout-tests-locally-true nil
))
7097 (allout-add-resumptions '(allout-tests-globally-unbound 2)
7098 '(allout-tests-globally-true 3)
7099 '(allout-tests-locally-true 4))
7100 ;; reestablish many of the basic conditions are maintained after re-add:
7101 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
7102 (assert (local-variable-p 'allout-tests-globally-unbound
))
7103 (assert (equal allout-tests-globally-unbound
2))
7104 (assert (default-boundp 'allout-tests-globally-true
))
7105 (assert (local-variable-p 'allout-tests-globally-true
))
7106 (assert (equal allout-tests-globally-true
3))
7107 (assert (not (default-boundp 'allout-tests-locally-true
)))
7108 (assert (local-variable-p 'allout-tests-locally-true
))
7109 (assert (equal allout-tests-locally-true
4))
7110 (allout-do-resumptions)
7111 (assert (not (local-variable-p 'allout-tests-globally-unbound
)))
7112 (assert (not (boundp 'allout-tests-globally-unbound
)))
7113 (assert (not (local-variable-p 'allout-tests-globally-true
)))
7114 (assert (boundp 'allout-tests-globally-true
))
7115 (assert (equal allout-tests-globally-true t
))
7116 (assert (boundp 'allout-tests-locally-true
))
7117 (assert (local-variable-p 'allout-tests-locally-true
))
7118 (assert (equal allout-tests-locally-true t
))
7119 (assert (not (default-boundp 'allout-tests-locally-true
))))
7121 ;; ensure that deliberately unbinding registered variables doesn't foul things
7123 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
7124 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
7125 (setq allout-tests-globally-true t
)
7126 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
7127 (set (make-local-variable 'allout-tests-locally-true
) t
)
7128 (allout-add-resumptions '(allout-tests-globally-unbound t
)
7129 '(allout-tests-globally-true nil
)
7130 '(allout-tests-locally-true nil
))
7131 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
7132 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
7133 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
7134 (allout-do-resumptions))
7136 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
7137 (when allout-run-unit-tests-on-load
7138 (allout-run-unit-tests))
7143 ;;;_* Local emacs vars.
7144 ;; The following `allout-layout' local variable setting:
7145 ;; - closes all topics from the first topic to just before the third-to-last,
7146 ;; - shows the children of the third to last (config vars)
7147 ;; - and the second to last (code section),
7148 ;; - and closes the last topic (this local-variables section).
7150 ;;allout-layout: (0 : -1 -1 0)
7153 ;; arch-tag: cf38fbc3-c044-450f-8bff-afed8ba5681c
7154 ;;; allout.el ends here