1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992-1994, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com>
6 ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com>
7 ;; Created: Dec 1991 -- first release to usenet
9 ;; Keywords: outlines, wp, languages, PGP, GnuPG
10 ;; Website: http://myriadicity.net/Sundry/EmacsAllout
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; Allout outline minor mode provides extensive outline formatting and
30 ;; and manipulation beyond standard emacs outline mode. Some features:
32 ;; - Classic outline-mode topic-oriented navigation and exposure adjustment
33 ;; - Topic-oriented editing including coherent topic and subtopic
34 ;; creation, promotion, demotion, cut/paste across depths, etc.
35 ;; - Incremental search with dynamic exposure and reconcealment of text
36 ;; - Customizable bullet format -- enables programming-language specific
37 ;; outlining, for code-folding editing. (Allout code itself is to try it;
38 ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but
39 ;; emacs local file variables need to be enabled when the
40 ;; file was visited -- see `enable-local-variables'.)
41 ;; - Configurable per-file initial exposure settings
42 ;; - Symmetric-key and key-pair topic encryption. Encryption is via the
43 ;; Emacs 'epg' library. See allout-toggle-current-subtree-encryption
45 ;; - Automatic topic-number maintenance
46 ;; - "Hot-spot" operation, for single-keystroke maneuvering and
47 ;; exposure control (see the allout-mode docstring)
48 ;; - Easy rendering of exposed portions into numbered, latex, indented, etc
50 ;; - Careful attention to whitespace -- enabling blank lines between items
51 ;; and maintenance of hanging indentation (in paragraph auto-fill and
52 ;; across topic promotion and demotion) of topic bodies consistent with
53 ;; indentation of their topic header.
57 ;; See the `allout-mode' function's docstring for an introduction to the
60 ;; Directions to the latest development version and helpful notes are
61 ;; available at http://myriadicity.net/Sundry/EmacsAllout .
63 ;; The outline menubar additions provide quick reference to many of the
64 ;; features. See the docstring of the variables `allout-layout' and
65 ;; `allout-auto-activation' for details on automatic activation of
66 ;; `allout-mode' as a minor mode. (`allout-init' is deprecated in favor of
67 ;; a purely customization-based method.)
69 ;; Note -- the lines beginning with `;;;_' are outline topic headers.
70 ;; Customize `allout-auto-activation' to enable, then revisit this
71 ;; buffer to give it a whirl.
73 ;; ken manheimer (ken dot manheimer at gmail dot com)
77 ;;;_* Dependency loads
80 ;; Most of the requires here are for stuff covered by autoloads, which
81 ;; byte-compiling doesn't trigger.
85 ;; `cl' is required for `assert'. `assert' is not covered by a standard
86 ;; autoload, but it is a macro, so that eval-when-compile is sufficient
87 ;; to byte-compile it in, or to do the require when the buffer evalled.
91 ;;;_* USER CUSTOMIZATION VARIABLES:
93 ;;;_ > defgroup allout, allout-keybindings
95 "Extensive outline minor-mode, for use stand-alone and with other modes.
97 See Allout Auto Activation for automatic activation."
100 (defgroup allout-keybindings nil
101 "Allout outline mode keyboard bindings configuration."
104 ;;;_ + Layout, Mode, and Topic Header Configuration
106 (defvar allout-command-prefix
) ; defined below
108 ;;;_ > allout-keybindings incidentals:
109 ;;;_ : internal key binding stuff - in this section for load-order.
110 ;;;_ = allout-mode-map
111 (defvar allout-mode-map
'allout-mode-map
112 "Keybindings place-holder for (allout) outline minor mode.
114 Do NOT set the value of this variable. Instead, customize
115 `allout-command-prefix', `allout-prefixed-keybindings', and
116 `allout-unprefixed-keybindings'.")
117 ;;;_ = allout-mode-map-value
118 (defvar allout-mode-map-value nil
119 "Keymap for allout outline minor mode.
121 Do NOT set the value of this variable. Instead, customize
122 `allout-command-prefix', `allout-prefixed-keybindings', and
123 `allout-unprefixed-keybindings'.")
124 ;;;_ = make allout-mode-map-value an alias for allout-mode-map:
125 ;; this needs to be revised when the value is changed, sigh.
126 (defalias 'allout-mode-map allout-mode-map-value
)
127 ;;;_ > allout-compose-and-institute-keymap (&optional varname value)
128 (defun allout-compose-and-institute-keymap (&optional varname value
)
129 "Create the allout keymap according to the keybinding specs, and set it.
131 Useful standalone or to effect customizations of the
132 respective allout-mode keybinding variables, `allout-command-prefix',
133 `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'"
134 ;; Set the customization variable, if any:
136 (set-default varname value
))
137 (let ((map (make-sparse-keymap)))
138 (when (boundp 'allout-prefixed-keybindings
)
139 ;; tolerate first definitions of the variables:
140 (dolist (entry allout-prefixed-keybindings
)
142 ;; XXX vector vs non-vector key descriptions?
143 (vconcat allout-command-prefix
144 (car (read-from-string (car entry
))))
146 (when (boundp 'allout-unprefixed-keybindings
)
147 (dolist (entry allout-unprefixed-keybindings
)
148 (define-key map
(car (read-from-string (car entry
))) (cadr entry
))))
149 (substitute-key-definition 'beginning-of-line
'allout-beginning-of-line
151 (substitute-key-definition 'move-beginning-of-line
'allout-beginning-of-line
153 (substitute-key-definition 'end-of-line
'allout-end-of-line
155 (substitute-key-definition 'move-end-of-line
'allout-end-of-line
157 (allout-institute-keymap map
)))
158 ;;;_ > allout-institute-keymap (map)
159 (defun allout-institute-keymap (map)
160 "Associate allout-mode bindings with allout as a minor mode."
162 ;; allout-mode-map var is a keymap by virtue of being a defalias for
163 ;; allout-mode-map-value, which has the actual keymap value.
164 ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be
165 ;; used in minor-mode-map-alist to indirect to the actual
166 ;; allout-mode-map-var value, which can be adjusted and reassigned.
168 ;; allout-mode-map-value for keymap reference in various places:
169 (setq allout-mode-map-value map
)
170 ;; the function value keymap of allout-mode-map is used in
171 ;; minor-mode-map-alist - update it:
172 (fset allout-mode-map allout-mode-map-value
))
173 ;;;_ * intialize the mode map:
174 ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
176 (allout-compose-and-institute-keymap)
177 ;;;_ = allout-command-prefix
178 (defcustom allout-command-prefix
"\C-c "
179 "Key sequence to be used as prefix for outline mode command key bindings.
181 Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're
182 willing to let allout use a bunch of \C-c keybindings."
184 :group
'allout-keybindings
185 :set
'allout-compose-and-institute-keymap
)
186 ;;;_ = allout-keybindings-binding
187 (define-widget 'allout-keybindings-binding
'lazy
188 "Structure of allout keybindings customization items."
190 (list (string :tag
"Key" :value
"[(meta control shift ?f)]")
191 (function :tag
"Function name"
192 :value allout-forward-current-level
))))
193 ;;;_ = allout-prefixed-keybindings
194 (defcustom allout-prefixed-keybindings
195 '(("[(control ?n)]" allout-next-visible-heading
)
196 ("[(control ?p)]" allout-previous-visible-heading
)
197 ("[(control ?u)]" allout-up-current-level
)
198 ("[(control ?f)]" allout-forward-current-level
)
199 ("[(control ?b)]" allout-backward-current-level
)
200 ("[(control ?a)]" allout-beginning-of-current-entry
)
201 ("[(control ?e)]" allout-end-of-entry
)
202 ("[(control ?i)]" allout-show-children
)
203 ("[(control ?s)]" allout-show-current-subtree
)
204 ("[(control ?t)]" allout-toggle-current-subtree-exposure
)
205 ;; Let user customize if they want to preempt describe-prefix-bindings ^h use.
206 ;; ("[(control ?h)]" allout-hide-current-subtree)
207 ("[?h]" allout-hide-current-subtree
)
208 ("[(control ?o)]" allout-show-current-entry
)
209 ("[?!]" allout-show-all
)
210 ("[?x]" allout-toggle-current-subtree-encryption
)
211 ("[? ]" allout-open-sibtopic
)
212 ("[?.]" allout-open-subtopic
)
213 ("[?,]" allout-open-supertopic
)
214 ("[?']" allout-shift-in
)
215 ("[?>]" allout-shift-in
)
216 ("[?<]" allout-shift-out
)
217 ("[(control ?m)]" allout-rebullet-topic
)
218 ("[?*]" allout-rebullet-current-heading
)
219 ("[?#]" allout-number-siblings
)
220 ("[(control ?k)]" allout-kill-topic
)
221 ("[(meta ?k)]" allout-copy-topic-as-kill
)
222 ("[?@]" allout-resolve-xref
)
223 ("[?=?c]" allout-copy-exposed-to-buffer
)
224 ("[?=?i]" allout-indented-exposed-to-buffer
)
225 ("[?=?t]" allout-latexify-exposed
)
226 ("[?=?p]" allout-flatten-exposed-to-buffer
)
228 "Allout-mode key bindings that are prefixed with `allout-command-prefix'.
230 See `allout-unprefixed-keybindings' for the list of keybindings
231 that are not prefixed.
233 Use vector format for the keys:
234 - put literal keys after a '?' question mark, eg: '?a', '?.'
235 - enclose control, shift, or meta-modified keys as sequences within
236 parentheses, with the literal key, as above, preceded by the name(s)
237 of the modifiers, eg: [(control ?a)]
238 See the existing keys for examples.
240 Functions can be bound to multiple keys, but binding keys to
241 multiple functions will not work - the last binding for a key
243 :type
'allout-keybindings-binding
244 :group
'allout-keybindings
245 :set
'allout-compose-and-institute-keymap
247 ;;;_ = allout-unprefixed-keybindings
248 (defcustom allout-unprefixed-keybindings
249 '(("[(control ?k)]" allout-kill-line
)
250 ("[(meta ?k)]" allout-copy-line-as-kill
)
251 ("[(control ?y)]" allout-yank
)
252 ("[(meta ?y)]" allout-yank-pop
)
254 "Allout-mode functions bound to keys without any added prefix.
256 This is in contrast to the majority of allout-mode bindings on
257 `allout-prefixed-bindings', whose bindings are created with a
258 preceding command key.
260 Use vector format for the keys:
261 - put literal keys after a '?' question mark, eg: '?a', '?.'
262 - enclose control, shift, or meta-modified keys as sequences within
263 parentheses, with the literal key, as above, preceded by the name(s)
264 of the modifiers, eg: [(control ?a)]
265 See the existing keys for examples."
266 :type
'allout-keybindings-binding
267 :group
'allout-keybindings
268 :set
'allout-compose-and-institute-keymap
271 ;;;_ > allout-auto-activation-helper (var value)
273 (defun allout-auto-activation-helper (var value
)
274 "Institute `allout-auto-activation'.
276 Intended to be used as the `allout-auto-activation' :set function."
277 (set-default var value
)
279 ;;;_ > allout-setup ()
281 (defun allout-setup ()
282 "Do fundamental emacs session for allout auto-activation.
284 Establishes allout processing as part of visiting a file if
285 `allout-auto-activation' is non-nil, or removes it otherwise.
287 The proper way to use this is through customizing the setting of
288 `allout-auto-activation'."
289 (if (not allout-auto-activation
)
290 (remove-hook 'find-file-hook
'allout-find-file-hook
)
291 (add-hook 'find-file-hook
'allout-find-file-hook
)))
292 ;;;_ = allout-auto-activation
294 (defcustom allout-auto-activation nil
295 "Configure allout outline mode auto-activation.
297 Control whether and how allout outline mode is automatically
298 activated when files are visited with non-nil buffer-specific
299 file variable `allout-layout'.
301 When allout-auto-activation is \"On\" \(t), allout mode is
302 activated in buffers with non-nil `allout-layout', and the
303 specified layout is applied.
305 With value \"ask\", auto-mode-activation is enabled, and endorsement for
306 performing auto-layout is asked of the user each time.
308 With value \"activate\", only auto-mode-activation is enabled.
311 With value nil, inhibit any automatic allout-mode activation."
312 :set
'allout-auto-activation-helper
313 ;; FIXME: Using strings here is unusual and less efficient than symbols.
314 :type
'(choice (const :tag
"On" t
)
315 (const :tag
"Ask about layout" "ask")
316 (const :tag
"Mode only" "activate")
317 (const :tag
"Off" nil
))
320 ;;;_ = allout-default-layout
321 (defcustom allout-default-layout
'(-2 : 0)
322 "Default allout outline layout specification.
324 This setting specifies the outline exposure to use when
325 `allout-layout' has the local value `t'. This docstring describes the
326 layout specifications.
328 A list value specifies a default layout for the current buffer,
329 to be applied upon activation of `allout-mode'. Any non-nil
330 value will automatically trigger `allout-mode', provided
331 `allout-auto-activation' has been customized to enable it.
333 The types of elements in the layout specification are:
335 INTEGER -- dictate the relative depth to open the corresponding topic(s),
337 -- negative numbers force the topic to be closed before opening
338 to the absolute value of the number, so all siblings are open
340 -- positive numbers open to the relative depth indicated by the
341 number, but do not force already opened subtopics to be closed.
342 -- 0 means to close topic -- hide all subitems.
343 : -- repeat spec -- apply the preceding element to all siblings at
344 current level, *up to* those siblings that would be covered by specs
345 following the `:' on the list. Ie, apply to all topics at level but
346 trailing ones accounted for by trailing specs. (Only the first of
347 multiple colons at the same level is honored -- later ones are ignored.)
348 * -- completely exposes the topic, including bodies
349 + -- exposes all subtopics, but not the bodies
350 - -- exposes the body of the corresponding topic, but not subtopics
351 LIST -- a nested layout spec, to be applied intricately to its
352 corresponding item(s)
356 Collapse the top-level topics to show their children and
357 grandchildren, but completely collapse the final top-level topic.
359 Close the first topic so only the immediate subtopics are shown,
360 leave the subsequent topics exposed as they are until the second
361 second to last topic, which is exposed at least one level, and
362 completely close the last topic.
364 Expose children and grandchildren of all topics at current
365 level except the last two; expose children of the second to
366 last and completely expose the last one, including its subtopics.
368 See `allout-expose-topic' for more about the exposure process.
370 Also, allout's mode-specific provisions will make topic prefixes default
371 to the comment-start string, if any, of the language of the file. This
372 is modulo the setting of `allout-use-mode-specific-leader', which see."
373 :type
'allout-layout-type
375 ;;;_ : allout-layout-type
376 (define-widget 'allout-layout-type
'lazy
377 "Allout layout format customization basic building blocks."
379 (choice (integer :tag
"integer (<= zero is strict)")
380 (const :tag
": (repeat prior)" :)
381 (const :tag
"* (completely expose)" *)
382 (const :tag
"+ (expose all offspring, headlines only)" +)
383 (const :tag
"- (expose topic body but not offspring)" -
)
384 (allout-layout-type :tag
"<Nested layout>"))))
386 ;;;_ = allout-inhibit-auto-fill
387 (defcustom allout-inhibit-auto-fill nil
388 "If non-nil, auto-fill will be inhibited in the allout buffers.
390 You can customize this setting to set it for all allout buffers, or set it
391 in individual buffers if you want to inhibit auto-fill only in particular
392 buffers. (You could use a function on `allout-mode-hook' to inhibit
393 auto-fill according, eg, to the major mode.)
395 If you don't set this and auto-fill-mode is enabled, allout will use the
396 value that `normal-auto-fill-function', if any, when allout mode starts, or
397 else allout's special hanging-indent maintaining auto-fill function,
401 (make-variable-buffer-local 'allout-inhibit-auto-fill
)
402 ;;;_ = allout-inhibit-auto-fill-on-headline
403 (defcustom allout-inhibit-auto-fill-on-headline nil
404 "If non-nil, auto-fill will be inhibited while on topic's header line."
407 (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline
)
408 ;;;_ = allout-use-hanging-indents
409 (defcustom allout-use-hanging-indents t
410 "If non-nil, topic body text auto-indent defaults to indent of the header.
411 Ie, it is indented to be just past the header prefix. This is
412 relevant mostly for use with `indented-text-mode', or other situations
413 where auto-fill occurs."
416 (make-variable-buffer-local 'allout-use-hanging-indents
)
418 (put 'allout-use-hanging-indents
'safe-local-variable
419 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
420 ;;;_ = allout-reindent-bodies
421 (defcustom allout-reindent-bodies
(if allout-use-hanging-indents
423 "Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
425 When active, topic body lines that are indented even with or beyond
426 their topic header are reindented to correspond with depth shifts of
429 A value of t enables reindent in non-programming-code buffers, ie
430 those that do not have the variable `comment-start' set. A value of
431 `force' enables reindent whether or not `comment-start' is set."
432 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
435 (make-variable-buffer-local 'allout-reindent-bodies
)
437 (put 'allout-reindent-bodies
'safe-local-variable
438 (lambda (x) (memq x
'(nil t text force
))))
440 ;;;_ = allout-show-bodies
441 (defcustom allout-show-bodies nil
442 "If non-nil, show entire body when exposing a topic, rather than
446 (make-variable-buffer-local 'allout-show-bodies
)
448 (put 'allout-show-bodies
'safe-local-variable
449 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
451 ;;;_ = allout-beginning-of-line-cycles
452 (defcustom allout-beginning-of-line-cycles t
453 "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
455 Cycling only happens on when the command is repeated, not when it
456 follows a different command.
458 Smart-placement means that repeated calls to this function will
461 - if the cursor is on a non-headline body line and not on the first column:
462 then it goes to the first column
463 - if the cursor is on the first column of a non-headline body line:
464 then it goes to the start of the headline within the item body
465 - if the cursor is on the headline and not the start of the headline:
466 then it goes to the start of the headline
467 - if the cursor is on the start of the headline:
468 then it goes to the bullet character (for hotspot navigation)
469 - if the cursor is on the bullet character:
470 then it goes to the first column of that line (the headline)
471 - if the cursor is on the first column of the headline:
472 then it goes to the start of the headline within the item body.
474 In this fashion, you can use the beginning-of-line command to do
475 its normal job and then, when repeated, advance through the
476 entry, cycling back to start.
478 If this configuration variable is nil, then the cursor is just
479 advanced to the beginning of the line and remains there on
481 :type
'boolean
:group
'allout
)
482 ;;;_ = allout-end-of-line-cycles
483 (defcustom allout-end-of-line-cycles t
484 "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
486 Cycling only happens on when the command is repeated, not when it
487 follows a different command.
489 Smart placement means that repeated calls to this function will
492 - if the cursor is not on the end-of-line,
493 then it goes to the end-of-line
494 - if the cursor is on the end-of-line but not the end-of-entry,
495 then it goes to the end-of-entry, exposing it if necessary
496 - if the cursor is on the end-of-entry,
497 then it goes to the end of the head line
499 In this fashion, you can use the end-of-line command to do its
500 normal job and then, when repeated, advance through the entry,
501 cycling back to start.
503 If this configuration variable is nil, then the cursor is just
504 advanced to the end of the line and remains there on repeated
506 :type
'boolean
:group
'allout
)
508 ;;;_ = allout-header-prefix
509 (defcustom allout-header-prefix
"."
510 ;; this string is treated as literal match. it will be `regexp-quote'd, so
511 ;; one cannot use regular expressions to match varying header prefixes.
512 "Leading string which helps distinguish topic headers.
514 Outline topic header lines are identified by a leading topic
515 header prefix, which mostly have the value of this var at their front.
516 Level 1 topics are exceptions. They consist of only a single
517 character, which is typically set to the `allout-primary-bullet'."
520 (make-variable-buffer-local 'allout-header-prefix
)
522 (put 'allout-header-prefix
'safe-local-variable
'stringp
)
523 ;;;_ = allout-primary-bullet
524 (defcustom allout-primary-bullet
"*"
525 "Bullet used for top-level outline topics.
527 Outline topic header lines are identified by a leading topic header
528 prefix, which is concluded by bullets that includes the value of this
529 var and the respective allout-*-bullets-string vars.
531 The value of an asterisk (`*') provides for backwards compatibility
532 with the original Emacs outline mode. See `allout-plain-bullets-string'
533 and `allout-distinctive-bullets-string' for the range of available
537 (make-variable-buffer-local 'allout-primary-bullet
)
539 (put 'allout-primary-bullet
'safe-local-variable
'stringp
)
540 ;;;_ = allout-plain-bullets-string
541 (defcustom allout-plain-bullets-string
".,"
542 "The bullets normally used in outline topic prefixes.
544 See `allout-distinctive-bullets-string' for the other kind of
547 DO NOT include the close-square-bracket, `]', as a bullet.
549 Outline mode has to be reactivated in order for changes to the value
550 of this var to take effect."
553 (make-variable-buffer-local 'allout-plain-bullets-string
)
555 (put 'allout-plain-bullets-string
'safe-local-variable
'stringp
)
556 ;;;_ = allout-distinctive-bullets-string
557 (defcustom allout-distinctive-bullets-string
"*+-=>()[{}&!?#%\"X@$~_\\:;^"
558 "Persistent outline header bullets used to distinguish special topics.
560 These bullets are distinguish topics with particular character.
561 They are not used by default in the topic creation routines, but
562 are offered as options when you modify topic creation with a
563 universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]).
565 Distinctive bullets are not cycled when topics are shifted or
566 otherwise automatically rebulleted, so their marking is
567 persistent until deliberately changed. Their significance is
568 purely by convention, however. Some conventions suggest
571 `(' - open paren -- an aside or incidental point
572 `?' - question mark -- uncertain or outright question
573 `!' - exclamation point/bang -- emphatic
574 `[' - open square bracket -- meta-note, about item instead of item's subject
575 `\"' - double quote -- a quotation or other citation
576 `=' - equal sign -- an assignment, some kind of definition
577 `^' - carat -- relates to something above
579 Some are more elusive, but their rationale may be recognizable:
581 `+' - plus -- pending consideration, completion
582 `_' - underscore -- done, completed
583 `&' - ampersand -- addendum, furthermore
585 \(Some other non-plain bullets have special meaning to the
586 software. By default:
588 `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
589 `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
591 See `allout-plain-bullets-string' for the standard, alternating
594 You must run `set-allout-regexp' in order for outline mode to
595 adopt changes of this value.
597 DO NOT include the close-square-bracket, `]', on either of the bullet
601 (make-variable-buffer-local 'allout-distinctive-bullets-string
)
603 (put 'allout-distinctive-bullets-string
'safe-local-variable
'stringp
)
605 ;;;_ = allout-use-mode-specific-leader
606 (defcustom allout-use-mode-specific-leader t
607 "When non-nil, use mode-specific topic-header prefixes.
609 Allout outline mode will use the mode-specific `allout-mode-leaders' or
610 comment-start string, if any, to lead the topic prefix string, so topic
611 headers look like comments in the programming language. It will also use
612 the comment-start string, with an '_' appended, for `allout-primary-bullet'.
614 String values are used as literals, not regular expressions, so
615 do not escape any regulare-expression characters.
617 Value t means to first check for assoc value in `allout-mode-leaders'
618 alist, then use comment-start string, if any, then use default (`.').
619 \(See note about use of comment-start strings, below.)
621 Set to the symbol for either of `allout-mode-leaders' or
622 `comment-start' to use only one of them, respectively.
624 Value nil means to always use the default (`.') and leave
625 `allout-primary-bullet' unaltered.
627 comment-start strings that do not end in spaces are tripled in
628 the header-prefix, and an `_' underscore is tacked on the end, to
629 distinguish them from regular comment strings. comment-start
630 strings that do end in spaces are not tripled, but an underscore
631 is substituted for the space. [This presumes that the space is
632 for appearance, not comment syntax. You can use
633 `allout-mode-leaders' to override this behavior, when
635 :type
'(choice (const t
) (const nil
) string
636 (const allout-mode-leaders
)
637 (const comment-start
))
640 (put 'allout-use-mode-specific-leader
'safe-local-variable
641 (lambda (x) (or (memq x
'(t nil allout-mode-leaders comment-start
))
643 ;;;_ = allout-mode-leaders
644 (defvar allout-mode-leaders
'()
645 "Specific allout-prefix leading strings per major modes.
647 Use this if the mode's comment-start string isn't what you
648 prefer, or if the mode lacks a comment-start string. See
649 `allout-use-mode-specific-leader' for more details.
651 If you're constructing a string that will comment-out outline
652 structuring so it can be included in program code, append an extra
653 character, like an \"_\" underscore, to distinguish the lead string
654 from regular comments that start at the beginning-of-line.")
656 ;;;_ = allout-old-style-prefixes
657 (defcustom allout-old-style-prefixes nil
658 "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
660 Non-nil restricts the topic creation and modification
661 functions to asterix-padded prefixes, so they look exactly
662 like the original Emacs-outline style prefixes.
664 Whatever the setting of this variable, both old and new style prefixes
665 are always respected by the topic maneuvering functions."
668 (make-variable-buffer-local 'allout-old-style-prefixes
)
670 (put 'allout-old-style-prefixes
'safe-local-variable
671 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
672 ;;;_ = allout-stylish-prefixes -- alternating bullets
673 (defcustom allout-stylish-prefixes t
674 "Do fancy stuff with topic prefix bullets according to level, etc.
676 Non-nil enables topic creation, modification, and repositioning
677 functions to vary the topic bullet char (the char that marks the topic
678 depth) just preceding the start of the topic text) according to level.
679 Otherwise, only asterisks (`*') and distinctive bullets are used.
681 This is how an outline can look (but sans indentation) with stylish
686 . + One level 3 subtopic
687 . . One level 4 subtopic
688 . . A second 4 subtopic
689 . + Another level 3 subtopic
690 . #1 A numbered level 4 subtopic
692 . ! Another level 4 subtopic with a different distinctive bullet
693 . #4 And another numbered level 4 subtopic
695 This would be an outline with stylish prefixes inhibited (but the
696 numbered and other distinctive bullets retained):
700 . * One level 3 subtopic
701 . * One level 4 subtopic
702 . * A second 4 subtopic
703 . * Another level 3 subtopic
704 . #1 A numbered level 4 subtopic
706 . ! Another level 4 subtopic with a different distinctive bullet
707 . #4 And another numbered level 4 subtopic
709 Stylish and constant prefixes (as well as old-style prefixes) are
710 always respected by the topic maneuvering functions, regardless of
711 this variable setting.
713 The setting of this var is not relevant when `allout-old-style-prefixes'
717 (make-variable-buffer-local 'allout-stylish-prefixes
)
719 (put 'allout-stylish-prefixes
'safe-local-variable
720 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
722 ;;;_ = allout-numbered-bullet
723 (defcustom allout-numbered-bullet
"#"
724 "String designating bullet of topics that have auto-numbering; nil for none.
726 Topics having this bullet have automatic maintenance of a sibling
727 sequence-number tacked on, just after the bullet. Conventionally set
728 to \"#\", you can set it to a bullet of your choice. A nil value
729 disables numbering maintenance."
730 :type
'(choice (const nil
) string
)
732 (make-variable-buffer-local 'allout-numbered-bullet
)
734 (put 'allout-numbered-bullet
'safe-local-variable
735 (if (fboundp 'string-or-null-p
)
737 (lambda (x) (or (stringp x
) (null x
)))))
738 ;;;_ = allout-file-xref-bullet
739 (defcustom allout-file-xref-bullet
"@"
740 "Bullet signifying file cross-references, for `allout-resolve-xref'.
742 Set this var to the bullet you want to use for file cross-references."
743 :type
'(choice (const nil
) string
)
746 (put 'allout-file-xref-bullet
'safe-local-variable
747 (if (fboundp 'string-or-null-p
)
749 (lambda (x) (or (stringp x
) (null x
)))))
750 ;;;_ = allout-presentation-padding
751 (defcustom allout-presentation-padding
2
752 "Presentation-format white-space padding factor, for greater indent."
756 (make-variable-buffer-local 'allout-presentation-padding
)
758 (put 'allout-presentation-padding
'safe-local-variable
'integerp
)
760 ;;;_ = allout-flattened-numbering-abbreviation
761 (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering
762 'allout-flattened-numbering-abbreviation
"24.1")
763 (defcustom allout-flattened-numbering-abbreviation nil
764 "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
765 numbers to minimal amount with some context. Otherwise, entire
766 numbers are always used."
770 ;;;_ + LaTeX formatting
771 ;;;_ - allout-number-pages
772 (defcustom allout-number-pages nil
773 "Non-nil turns on page numbering for LaTeX formatting of an outline."
776 ;;;_ - allout-label-style
777 (defcustom allout-label-style
"\\large\\bf"
778 "Font and size of labels for LaTeX formatting of an outline."
781 ;;;_ - allout-head-line-style
782 (defcustom allout-head-line-style
"\\large\\sl "
783 "Font and size of entries for LaTeX formatting of an outline."
786 ;;;_ - allout-body-line-style
787 (defcustom allout-body-line-style
" "
788 "Font and size of entries for LaTeX formatting of an outline."
791 ;;;_ - allout-title-style
792 (defcustom allout-title-style
"\\Large\\bf"
793 "Font and size of titles for LaTeX formatting of an outline."
797 (defcustom allout-title
'(or buffer-file-name
(buffer-name))
798 "Expression to be evaluated to determine the title for LaTeX
802 ;;;_ - allout-line-skip
803 (defcustom allout-line-skip
".05cm"
804 "Space between lines for LaTeX formatting of an outline."
808 (defcustom allout-indent
".3cm"
809 "LaTeX formatted depth-indent spacing."
813 ;;;_ + Topic encryption
814 ;;;_ = allout-encryption group
815 (defgroup allout-encryption nil
816 "Settings for topic encryption features of allout outliner."
818 ;;;_ = allout-topic-encryption-bullet
819 (defcustom allout-topic-encryption-bullet
"~"
820 "Bullet signifying encryption of the entry's body."
821 :type
'(choice (const nil
) string
)
823 :group
'allout-encryption
)
824 ;;;_ = allout-encrypt-unencrypted-on-saves
825 (defcustom allout-encrypt-unencrypted-on-saves t
826 "When saving, should topics pending encryption be encrypted?
828 The idea is to prevent file-system exposure of any un-encrypted stuff, and
829 mostly covers both deliberate file writes and auto-saves.
831 - Yes: encrypt all topics pending encryption, even if it's the one
832 currently being edited. (In that case, the currently edited topic
833 will be automatically decrypted before any user interaction, so they
834 can continue editing but the copy on the file system will be
836 Auto-saves will use the \"All except current topic\" mode if this
837 one is selected, to avoid practical difficulties -- see below.
838 - All except current topic: skip the topic currently being edited, even if
839 it's pending encryption. This may expose the current topic on the
840 file sytem, but avoids the nuisance of prompts for the encryption
841 passphrase in the middle of editing for, eg, autosaves.
842 This mode is used for auto-saves for both this option and \"Yes\".
843 - No: leave it to the user to encrypt any unencrypted topics.
845 For practical reasons, auto-saves always use the 'except-current policy
846 when auto-encryption is enabled. (Otherwise, spurious passphrase prompts
847 and unavoidable timing collisions are too disruptive.) If security for a
848 file requires that even the current topic is never auto-saved in the clear,
849 disable auto-saves for that file."
851 :type
'(choice (const :tag
"Yes" t
)
852 (const :tag
"All except current topic" except-current
)
853 (const :tag
"No" nil
))
855 :group
'allout-encryption
)
856 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves
)
859 ;;;_ = allout-developer group
860 (defgroup allout-developer nil
861 "Allout settings developers care about, including topic encryption and more."
863 ;;;_ = allout-run-unit-tests-on-load
864 (defcustom allout-run-unit-tests-on-load nil
865 "When non-nil, unit tests will be run at end of loading the allout module.
867 Generally, allout code developers are the only ones who'll want to set this.
869 \(If set, this makes it an even better practice to exercise changes by
870 doing byte-compilation with a repeat count, so the file is loaded after
873 See `allout-run-unit-tests' to see what's run."
875 :group
'allout-developer
)
877 ;;;_ + Miscellaneous customization
879 ;;;_ = allout-enable-file-variable-adjustment
880 (defcustom allout-enable-file-variable-adjustment t
881 "If non-nil, some allout outline actions edit Emacs local file var text.
883 This can range from changes to existing entries, addition of new ones,
884 and creation of a new local variables section when necessary.
886 Emacs file variables adjustments are also inhibited if `enable-local-variables'
889 Operations potentially causing edits include allout encryption routines.
890 For details, see `allout-toggle-current-subtree-encryption's docstring."
893 (make-variable-buffer-local 'allout-enable-file-variable-adjustment
)
895 ;;;_* CODE -- no user customizations below.
897 ;;;_ #1 Internal Outline Formatting and Configuration
899 ;;;_ = allout-version
900 (defvar allout-version
"2.3"
901 "Version of currently loaded outline package. (allout.el)")
902 ;;;_ > allout-version
903 (defun allout-version (&optional here
)
904 "Return string describing the loaded outline version."
906 (let ((msg (concat "Allout Outline Mode v " allout-version
)))
907 (if here
(insert msg
))
910 ;;;_ : Mode activation (defined here because it's referenced early)
912 (defvar allout-mode nil
"Allout outline mode minor-mode flag.")
913 (make-variable-buffer-local 'allout-mode
)
914 ;;;_ = allout-layout nil
915 (defvar allout-layout nil
; LEAVE GLOBAL VALUE NIL -- see docstring.
916 "Buffer-specific setting for allout layout.
918 In buffers where this is non-nil \(and if `allout-auto-activation'
919 has been customized to enable this behavior), `allout-mode' will be
920 automatically activated. The layout dictated by the value will be used to
921 set the initial exposure when `allout-mode' is activated.
923 \*You should not setq-default this variable non-nil unless you want every
924 visited file to be treated as an allout file.*
926 The value would typically be set by a file local variable. For
927 example, the following lines at the bottom of an Emacs Lisp file:
930 ;;;allout-layout: (0 : -1 -1 0)
933 dictate activation of `allout-mode' mode when the file is visited
934 \(presuming proper `allout-auto-activation' customization),
935 followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'.
936 \(This is the layout used for the allout.el source file.)
938 `allout-default-layout' describes the specification format.
939 `allout-layout' can additionally have the value `t', in which
940 case the value of `allout-default-layout' is used.")
941 (make-variable-buffer-local 'allout-layout
)
943 (put 'allout-layout
'safe-local-variable
944 (lambda (x) (or (numberp x
) (listp x
) (memq x
'(: * + -
)))))
946 ;;;_ : Topic header format
948 (defvar allout-regexp
""
949 "*Regular expression to match the beginning of a heading line.
951 Any line whose beginning matches this regexp is considered a
952 heading. This var is set according to the user configuration vars
953 by `set-allout-regexp'.")
954 (make-variable-buffer-local 'allout-regexp
)
955 ;;;_ = allout-bullets-string
956 (defvar allout-bullets-string
""
957 "A string dictating the valid set of outline topic bullets.
959 This var should *not* be set by the user -- it is set by `set-allout-regexp',
960 and is produced from the elements of `allout-plain-bullets-string'
961 and `allout-distinctive-bullets-string'.")
962 (make-variable-buffer-local 'allout-bullets-string
)
963 ;;;_ = allout-bullets-string-len
964 (defvar allout-bullets-string-len
0
965 "Length of current buffers' `allout-plain-bullets-string'.")
966 (make-variable-buffer-local 'allout-bullets-string-len
)
967 ;;;_ = allout-depth-specific-regexp
968 (defvar allout-depth-specific-regexp
""
969 "*Regular expression to match a heading line prefix for a particular depth.
971 This expression is used to search for depth-specific topic
972 headers at depth 2 and greater. Use `allout-depth-one-regexp'
973 for to seek topics at depth one.
975 This var is set according to the user configuration vars by
976 `set-allout-regexp'. It is prepared with format strings for two
977 decimal numbers, which should each be one less than the depth of the
978 topic prefix to be matched.")
979 (make-variable-buffer-local 'allout-depth-specific-regexp
)
980 ;;;_ = allout-depth-one-regexp
981 (defvar allout-depth-one-regexp
""
982 "*Regular expression to match a heading line prefix for depth one.
984 This var is set according to the user configuration vars by
985 `set-allout-regexp'. It is prepared with format strings for two
986 decimal numbers, which should each be one less than the depth of the
987 topic prefix to be matched.")
988 (make-variable-buffer-local 'allout-depth-one-regexp
)
989 ;;;_ = allout-line-boundary-regexp
990 (defvar allout-line-boundary-regexp
()
991 "`allout-regexp' prepended with a newline for the search target.
993 This is properly set by `set-allout-regexp'.")
994 (make-variable-buffer-local 'allout-line-boundary-regexp
)
995 ;;;_ = allout-bob-regexp
996 (defvar allout-bob-regexp
()
997 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
998 (make-variable-buffer-local 'allout-bob-regexp
)
999 ;;;_ = allout-header-subtraction
1000 (defvar allout-header-subtraction
(1- (length allout-header-prefix
))
1001 "Allout-header prefix length to subtract when computing topic depth.")
1002 (make-variable-buffer-local 'allout-header-subtraction
)
1003 ;;;_ = allout-plain-bullets-string-len
1004 (defvar allout-plain-bullets-string-len
(length allout-plain-bullets-string
)
1005 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
1006 (make-variable-buffer-local 'allout-plain-bullets-string-len
)
1008 ;;;_ = allout-doublecheck-at-and-shallower
1009 (defconst allout-doublecheck-at-and-shallower
3
1010 "Validate apparent topics of this depth and shallower as being non-aberrant.
1012 Verified with `allout-aberrant-container-p'. The usefulness of
1013 this check is limited to shallow depths, because the
1014 determination of aberrance is according to the mistaken item
1015 being followed by a legitimate item of excessively greater depth.
1017 The classic example of a mistaken item, for a standard allout
1018 outline configuration, is a body line that begins with an '...'
1019 ellipsis. This happens to contain a legitimate depth-2 header
1020 prefix, constituted by two '..' dots at the beginning of the
1021 line. The only thing that can distinguish it *in principle* from
1022 a legitimate one is if the following real header is at a depth
1023 that is discontinuous from the depth of 2 implied by the
1024 ellipsis, ie depth 4 or more. As the depth being tested gets
1025 greater, the likelihood of this kind of disqualification is
1026 lower, and the usefulness of this test is lower.
1028 Extending the depth of the doublecheck increases the amount it is
1029 applied, increasing the cost of the test - on casual estimation,
1030 for outlines with many deep topics, geometrically (O(n)?).
1031 Taken together with decreasing likelihood that the test will be
1032 useful at greater depths, more modest doublecheck limits are more
1033 suitably economical.")
1034 ;;;_ X allout-reset-header-lead (header-lead)
1035 (defun allout-reset-header-lead (header-lead)
1036 "Reset the leading string used to identify topic headers."
1037 (interactive "sNew lead string: ")
1038 (setq allout-header-prefix header-lead
)
1039 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1040 (set-allout-regexp))
1041 ;;;_ X allout-lead-with-comment-string (header-lead)
1042 (defun allout-lead-with-comment-string (&optional header-lead
)
1043 "Set the topic-header leading string to specified string.
1045 Useful when for encapsulating outline structure in programming
1046 language comments. Returns the leading string."
1049 (if (not (stringp header-lead
))
1050 (setq header-lead
(read-string
1051 "String prefix for topic headers: ")))
1052 (setq allout-reindent-bodies nil
)
1053 (allout-reset-header-lead header-lead
)
1055 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
1056 (defun allout-infer-header-lead-and-primary-bullet ()
1057 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
1059 Works according to settings of:
1062 `allout-header-prefix' (default)
1063 `allout-use-mode-specific-leader'
1064 and `allout-mode-leaders'.
1066 Apply this via (re)activation of `allout-mode', rather than
1067 invoking it directly."
1068 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader
)
1069 (if (or (stringp allout-use-mode-specific-leader
)
1070 (memq allout-use-mode-specific-leader
1071 '(allout-mode-leaders
1074 allout-use-mode-specific-leader
1075 ;; Oops -- garbled value, equate with effect of t:
1079 ((not use-leader
) nil
)
1080 ;; Use the explicitly designated leader:
1081 ((stringp use-leader
) use-leader
)
1082 (t (or (and (memq use-leader
'(t allout-mode-leaders
))
1083 ;; Get it from outline mode leaders?
1084 (cdr (assq major-mode allout-mode-leaders
)))
1085 ;; ... didn't get from allout-mode-leaders...
1086 (and (memq use-leader
'(t comment-start
))
1088 ;; Use comment-start, maybe tripled, and with
1092 (substring comment-start
1093 (1- (length comment-start
))))
1094 ;; Use comment-start, sans trailing space:
1095 (substring comment-start
0 -
1)
1096 (concat comment-start comment-start comment-start
))
1097 ;; ... and append underscore, whichever:
1101 (setq allout-header-prefix leader
)
1102 (if (not allout-old-style-prefixes
)
1103 ;; setting allout-primary-bullet makes the top level topics use --
1104 ;; actually, be -- the special prefix:
1105 (setq allout-primary-bullet leader
))
1106 allout-header-prefix
)))
1107 (defalias 'allout-infer-header-lead
1108 'allout-infer-header-lead-and-primary-bullet
)
1109 ;;;_ > allout-infer-body-reindent ()
1110 (defun allout-infer-body-reindent ()
1111 "Determine proper setting for `allout-reindent-bodies'.
1113 Depends on default setting of `allout-reindent-bodies' (which see)
1114 and presence of setting for `comment-start', to tell whether the
1115 file is programming code."
1116 (if (and allout-reindent-bodies
1118 (not (eq 'force allout-reindent-bodies
)))
1119 (setq allout-reindent-bodies nil
)))
1120 ;;;_ > set-allout-regexp ()
1121 (defun set-allout-regexp ()
1122 "Generate proper topic-header regexp form for outline functions.
1124 Works with respect to `allout-plain-bullets-string' and
1125 `allout-distinctive-bullets-string'.
1127 Also refresh various data structures that hinge on the regexp."
1130 ;; Derive allout-bullets-string from user configured components:
1131 (setq allout-bullets-string
"")
1132 (let ((strings (list 'allout-plain-bullets-string
1133 'allout-distinctive-bullets-string
1134 'allout-primary-bullet
))
1141 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
1142 (while (< index cur-len
)
1143 (setq cur-char
(aref cur-string index
))
1144 (setq allout-bullets-string
1145 (concat allout-bullets-string
1147 ; Single dash would denote a
1148 ; sequence, repeated denotes
1150 ((eq cur-char ?-
) "--")
1151 ; literal close-square-bracket
1152 ; doesn't work right in the
1154 ((eq cur-char ?\
]) "")
1155 (t (regexp-quote (char-to-string cur-char
))))))
1156 (setq index
(1+ index
)))
1157 (setq strings
(cdr strings
)))
1159 ;; Derive next for repeated use in allout-pending-bullet:
1160 (setq allout-plain-bullets-string-len
(length allout-plain-bullets-string
))
1161 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1163 (let (new-part old-part formfeed-part
)
1164 (setq new-part
(concat "\\("
1165 (regexp-quote allout-header-prefix
)
1167 ;; already regexp-quoted in a custom way:
1168 "[" allout-bullets-string
"]"
1170 old-part
(concat "\\("
1171 (regexp-quote allout-primary-bullet
)
1173 (regexp-quote allout-header-prefix
)
1176 " ?[^" allout-primary-bullet
"]")
1177 formfeed-part
"\\(\^L\\)"
1179 allout-regexp
(concat new-part
1185 allout-line-boundary-regexp
(concat "\n" new-part
1191 allout-bob-regexp
(concat "\\`" new-part
1198 (setq allout-depth-specific-regexp
1199 (concat "\\(^\\|\\`\\)"
1202 ;; new-style spacers-then-bullet string:
1204 (allout-format-quote (regexp-quote allout-header-prefix
))
1206 "[" (allout-format-quote allout-bullets-string
) "]"
1209 ;; old-style all-bullets string, if primary not multi-char:
1210 (if (< 0 allout-header-subtraction
)
1213 (allout-format-quote
1214 (regexp-quote allout-primary-bullet
))
1215 (allout-format-quote
1216 (regexp-quote allout-primary-bullet
))
1217 (allout-format-quote
1218 (regexp-quote allout-primary-bullet
))
1220 ;; disqualify greater depths:
1222 (allout-format-quote allout-primary-bullet
)
1227 (setq allout-depth-one-regexp
1228 (concat "\\(^\\|\\`\\)"
1232 (regexp-quote allout-header-prefix
)
1233 ;; disqualify any bullet char following any amount of
1234 ;; intervening whitespace:
1236 (concat "[^ " allout-bullets-string
"]")
1238 (if (< 0 allout-header-subtraction
)
1239 ;; Need not support anything like the old
1240 ;; bullet style if the prefix is multi-char.
1243 (regexp-quote allout-primary-bullet
)
1244 ;; disqualify deeper primary-bullet sequences:
1245 "[^" allout-primary-bullet
"]"))
1249 (defvar allout-mode-exposure-menu
)
1250 (defvar allout-mode-editing-menu
)
1251 (defvar allout-mode-navigation-menu
)
1252 (defvar allout-mode-misc-menu
)
1253 (defun produce-allout-mode-menubar-entries ()
1255 (easy-menu-define allout-mode-exposure-menu
1256 allout-mode-map-value
1257 "Allout outline exposure menu."
1259 ["Show Entry" allout-show-current-entry t
]
1260 ["Show Children" allout-show-children t
]
1261 ["Show Subtree" allout-show-current-subtree t
]
1262 ["Hide Subtree" allout-hide-current-subtree t
]
1263 ["Hide Leaves" allout-hide-current-leaves t
]
1265 ["Show All" allout-show-all t
]))
1266 (easy-menu-define allout-mode-editing-menu
1267 allout-mode-map-value
1268 "Allout outline editing menu."
1270 ["Open Sibling" allout-open-sibtopic t
]
1271 ["Open Subtopic" allout-open-subtopic t
]
1272 ["Open Supertopic" allout-open-supertopic t
]
1274 ["Shift Topic In" allout-shift-in t
]
1275 ["Shift Topic Out" allout-shift-out t
]
1276 ["Rebullet Topic" allout-rebullet-topic t
]
1277 ["Rebullet Heading" allout-rebullet-current-heading t
]
1278 ["Number Siblings" allout-number-siblings t
]
1280 ["Toggle Topic Encryption"
1281 allout-toggle-current-subtree-encryption
1282 (> (allout-current-depth) 1)]))
1283 (easy-menu-define allout-mode-navigation-menu
1284 allout-mode-map-value
1285 "Allout outline navigation menu."
1287 ["Next Visible Heading" allout-next-visible-heading t
]
1288 ["Previous Visible Heading"
1289 allout-previous-visible-heading t
]
1291 ["Up Level" allout-up-current-level t
]
1292 ["Forward Current Level" allout-forward-current-level t
]
1293 ["Backward Current Level"
1294 allout-backward-current-level t
]
1296 ["Beginning of Entry"
1297 allout-beginning-of-current-entry t
]
1298 ["End of Entry" allout-end-of-entry t
]
1299 ["End of Subtree" allout-end-of-current-subtree t
]))
1300 (easy-menu-define allout-mode-misc-menu
1301 allout-mode-map-value
1302 "Allout outlines miscellaneous bindings."
1304 ["Version" allout-version t
]
1306 ["Duplicate Exposed" allout-copy-exposed-to-buffer t
]
1307 ["Duplicate Exposed, numbered"
1308 allout-flatten-exposed-to-buffer t
]
1309 ["Duplicate Exposed, indented"
1310 allout-indented-exposed-to-buffer t
]
1312 ["Set Header Lead" allout-reset-header-lead t
]
1313 ["Set New Exposure" allout-expose-topic t
])))
1314 ;;;_ : Allout Modal-Variables Utilities
1315 ;;;_ = allout-mode-prior-settings
1316 (defvar allout-mode-prior-settings nil
1317 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1319 See `allout-add-resumptions' and `allout-do-resumptions'.")
1320 (make-variable-buffer-local 'allout-mode-prior-settings
)
1321 ;;;_ > allout-add-resumptions (&rest pairs)
1322 (defun allout-add-resumptions (&rest pairs
)
1323 "Set name/value PAIRS.
1325 Old settings are preserved for later resumption using `allout-do-resumptions'.
1327 The new values are set as a buffer local. On resumption, the prior buffer
1328 scope of the variable is restored along with its value. If it was a void
1329 buffer-local value, then it is left as nil on resumption.
1331 The pairs are lists whose car is the name of the variable and car of the
1332 cdr is the new value: '(some-var some-value)'. The pairs can actually be
1333 triples, where the third element qualifies the disposition of the setting,
1334 as described further below.
1336 If the optional third element is the symbol 'extend, then the new value
1337 created by `cons'ing the second element of the pair onto the front of the
1340 If the optional third element is the symbol 'append, then the new value is
1341 extended from the existing one by `append'ing a list containing the second
1342 element of the pair onto the end of the existing value.
1344 Extension, and resumptions in general, should not be used for hook
1345 functions -- use the 'local mode of `add-hook' for that, instead.
1347 The settings are stored on `allout-mode-prior-settings'."
1349 (let* ((pair (pop pairs
))
1352 (qualifier (if (> (length pair
) 2)
1355 (if (not (symbolp name
))
1356 (error "Pair's name, %S, must be a symbol, not %s"
1357 name
(type-of name
)))
1358 (setq prior-value
(condition-case nil
1360 (void-variable nil
)))
1361 (when (not (assoc name allout-mode-prior-settings
))
1362 ;; Not already added as a resumption, create the prior setting entry.
1363 (if (local-variable-p name
(current-buffer))
1364 ;; is already local variable -- preserve the prior value:
1365 (push (list name prior-value
) allout-mode-prior-settings
)
1366 ;; wasn't local variable, indicate so for resumption by killing
1367 ;; local value, and make it local:
1368 (push (list name
) allout-mode-prior-settings
)
1369 (make-local-variable name
)))
1371 (cond ((eq qualifier
'extend
)
1372 (if (not (listp prior-value
))
1373 (error "extension of non-list prior value attempted")
1374 (set name
(cons value prior-value
))))
1375 ((eq qualifier
'append
)
1376 (if (not (listp prior-value
))
1377 (error "appending of non-list prior value attempted")
1378 (set name
(append prior-value
(list value
)))))
1379 (t (error "unrecognized setting qualifier `%s' encountered"
1381 (set name value
)))))
1382 ;;;_ > allout-do-resumptions ()
1383 (defun allout-do-resumptions ()
1384 "Resume all name/value settings registered by `allout-add-resumptions'.
1386 This is used when concluding allout-mode, to resume selected variables to
1387 their settings before allout-mode was started."
1389 (while allout-mode-prior-settings
1390 (let* ((pair (pop allout-mode-prior-settings
))
1392 (value-cell (cdr pair
)))
1393 (if (not value-cell
)
1394 ;; Prior value was global:
1395 (kill-local-variable name
)
1396 ;; Prior value was explicit:
1397 (set name
(car value-cell
))))))
1398 ;;;_ : Mode-specific incidentals
1399 ;;;_ > allout-unprotected (expr)
1400 (defmacro allout-unprotected
(expr)
1401 "Enable internal outline operations to alter invisible text."
1402 `(let ((inhibit-read-only (if (not buffer-read-only
) t
))
1403 (inhibit-field-text-motion t
))
1405 ;;;_ = allout-mode-hook
1406 (defvar allout-mode-hook nil
1407 "*Hook that's run when allout mode starts.")
1408 ;;;_ = allout-mode-deactivate-hook
1409 (defvar allout-mode-deactivate-hook nil
1410 "*Hook that's run when allout mode ends.")
1411 (define-obsolete-variable-alias 'allout-mode-deactivate-hook
1412 'allout-mode-off-hook
"24.1")
1413 ;;;_ = allout-exposure-category
1414 (defvar allout-exposure-category nil
1415 "Symbol for use as allout invisible-text overlay category.")
1416 ;;;_ = allout-exposure-change-hook
1417 (defvar allout-exposure-change-hook nil
1418 "*Hook that's run after allout outline subtree exposure changes.
1420 It is run at the conclusion of `allout-flag-region'.
1422 Functions on the hook must take three arguments:
1424 - FROM -- integer indicating the point at the start of the change.
1425 - TO -- integer indicating the point of the end of the change.
1426 - FLAG -- change mode: nil for exposure, otherwise concealment.
1428 This hook might be invoked multiple times by a single command.")
1429 ;;;_ = allout-structure-added-hook
1430 (defvar allout-structure-added-hook nil
1431 "*Hook that's run after addition of items to the outline.
1433 Functions on the hook should take two arguments:
1435 - NEW-START -- integer indicating position of start of the first new item.
1436 - NEW-END -- integer indicating position of end of the last new item.
1438 This hook might be invoked multiple times by a single command.")
1439 ;;;_ = allout-structure-deleted-hook
1440 (defvar allout-structure-deleted-hook nil
1441 "*Hook that's run after disciplined deletion of subtrees from the outline.
1443 Functions on the hook must take two arguments:
1445 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1446 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1448 Some edits that remove or invalidate items may missed by this hook:
1449 specifically edits that native allout routines do not control.
1451 This hook might be invoked multiple times by a single command.")
1452 ;;;_ = allout-structure-shifted-hook
1453 (defvar allout-structure-shifted-hook nil
1454 "*Hook that's run after shifting of items in the outline.
1456 Functions on the hook should take two arguments:
1458 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1459 - START -- integer indicating the start point of the shifted parent item.
1461 Some edits that shift items can be missed by this hook: specifically edits
1462 that native allout routines do not control.
1464 This hook might be invoked multiple times by a single command.")
1465 ;;;_ = allout-after-copy-or-kill-hook
1466 (defvar allout-after-copy-or-kill-hook nil
1467 "*Hook that's run after copying outline text.
1469 Functions on the hook should not take any arguments.")
1470 ;;;_ = allout-outside-normal-auto-fill-function
1471 (defvar allout-outside-normal-auto-fill-function nil
1472 "Value of normal-auto-fill-function outside of allout mode.
1474 Used by allout-auto-fill to do the mandated normal-auto-fill-function
1475 wrapped within allout's automatic fill-prefix setting.")
1476 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function
)
1477 ;;;_ = prevent redundant activation by desktop mode:
1478 (add-to-list 'desktop-minor-mode-handlers
'(allout-mode . nil
))
1479 ;;;_ = allout-passphrase-verifier-string
1480 (defvar allout-passphrase-verifier-string nil
1481 "Setting used to test solicited encryption passphrases against the one
1482 already associated with a file.
1484 It consists of an encrypted random string useful only to verify that a
1485 passphrase entered by the user is effective for decryption. The passphrase
1486 itself is \*not* recorded in the file anywhere, and the encrypted contents
1487 are random binary characters to avoid exposing greater susceptibility to
1490 The verifier string is retained as an Emacs file variable, as well as in
1491 the Emacs buffer state, if file variable adjustments are enabled. See
1492 `allout-enable-file-variable-adjustment' for details about that.")
1493 (make-variable-buffer-local 'allout-passphrase-verifier-string
)
1494 (make-obsolete 'allout-passphrase-verifier-string
1495 'allout-passphrase-verifier-string
"23.3")
1497 (put 'allout-passphrase-verifier-string
'safe-local-variable
'stringp
)
1498 ;;;_ = allout-passphrase-hint-string
1499 (defvar allout-passphrase-hint-string
""
1500 "Variable used to retain reminder string for file's encryption passphrase.
1502 See the description of `allout-passphrase-hint-handling' for details about how
1503 the reminder is deployed.
1505 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1506 state, if file variable adjustments are enabled. See
1507 `allout-enable-file-variable-adjustment' for details about that.")
1508 (make-variable-buffer-local 'allout-passphrase-hint-string
)
1509 (setq-default allout-passphrase-hint-string
"")
1510 (make-obsolete 'allout-passphrase-hint-string
1511 'allout-passphrase-hint-string
"23.3")
1513 (put 'allout-passphrase-hint-string
'safe-local-variable
'stringp
)
1514 ;;;_ = allout-after-save-decrypt
1515 (defvar allout-after-save-decrypt nil
1516 "Internal variable, is nil or has the value of two points:
1518 - the location of a topic to be decrypted after saving is done
1519 - where to situate the cursor after the decryption is performed
1521 This is used to decrypt the topic that was currently being edited, if it
1522 was encrypted automatically as part of a file write or autosave.")
1523 (make-variable-buffer-local 'allout-after-save-decrypt
)
1524 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1525 (defvar allout-encryption-plaintext-sanitization-regexps nil
1526 "List of regexps whose matches are removed from plaintext before encryption.
1528 This is for the sake of removing artifacts, like escapes, that are added on
1529 and not actually part of the original plaintext. The removal is done just
1530 prior to encryption.
1532 Entries must be symbols that are bound to the desired values.
1534 Each value can be a regexp or a list with a regexp followed by a
1535 substitution string. If it's just a regexp, all its matches are removed
1536 before the text is encrypted. If it's a regexp and a substitution, the
1537 substition is used against the regexp matches, a la `replace-match'.")
1538 (make-variable-buffer-local 'allout-encryption-text-removal-regexps
)
1539 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1540 (defvar allout-encryption-ciphertext-rejection-regexps nil
1541 "Variable for regexps matching plaintext to remove before encryption.
1543 This is used to detect strings in encryption results that would
1544 register as allout mode structural elements, for exmple, as a
1547 Entries must be symbols that are bound to the desired regexp values.
1549 Encryptions that result in matches will be retried, up to
1550 `allout-encryption-ciphertext-rejection-limit' times, after which
1551 an error is raised.")
1553 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps
)
1554 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1555 (defvar allout-encryption-ciphertext-rejection-ceiling
5
1556 "Limit on number of times encryption ciphertext is rejected.
1558 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1559 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling
)
1560 ;;;_ > allout-mode-p ()
1561 ;; Must define this macro above any uses, or byte compilation will lack
1562 ;; proper def, if file isn't loaded -- eg, during emacs build!
1564 (defmacro allout-mode-p
()
1565 "Return t if `allout-mode' is active in current buffer."
1567 ;;;_ > allout-write-file-hook-handler ()
1568 (defun allout-write-file-hook-handler ()
1569 "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes."
1571 (if (or (not (allout-mode-p))
1572 (not (boundp 'allout-encrypt-unencrypted-on-saves
))
1573 (not allout-encrypt-unencrypted-on-saves
))
1575 (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves
1578 (if (save-excursion (goto-char (point-min))
1579 (allout-next-topic-pending-encryption except-mark
))
1581 (message "auto-encrypting pending topics")
1583 (condition-case failure
1584 (setq allout-after-save-decrypt
1585 (allout-encrypt-decrypted except-mark
))
1587 "allout-write-file-hook-handler suppressing error %s"
1592 ;;;_ > allout-auto-save-hook-handler ()
1593 (defun allout-auto-save-hook-handler ()
1594 "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save."
1596 (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves
)
1597 ;; Always implement 'except-current policy when enabled.
1598 (let ((allout-encrypt-unencrypted-on-saves 'except-current
))
1599 (allout-write-file-hook-handler))))
1600 ;;;_ > allout-after-saves-handler ()
1601 (defun allout-after-saves-handler ()
1602 "Decrypt topic encrypted for save, if it's currently being edited.
1604 Ie, if it was pending encryption and contained the point in its body before
1607 We use values stored in `allout-after-save-decrypt' to locate the topic
1608 and the place for the cursor after the decryption is done."
1609 (if (not (and (allout-mode-p)
1610 (boundp 'allout-after-save-decrypt
)
1611 allout-after-save-decrypt
))
1613 (goto-char (car allout-after-save-decrypt
))
1614 (let ((was-modified (buffer-modified-p)))
1615 (allout-toggle-subtree-encryption)
1616 (if (not was-modified
)
1617 (set-buffer-modified-p nil
)))
1618 (goto-char (cadr allout-after-save-decrypt
))
1619 (setq allout-after-save-decrypt nil
))
1621 ;;;_ > allout-called-interactively-p ()
1622 (defmacro allout-called-interactively-p
()
1623 "A version of called-interactively-p independent of emacs version."
1624 ;; ... to ease maintenance of allout without betraying deprecation.
1625 (if (equal (subr-arity (symbol-function 'called-interactively-p
))
1627 '(called-interactively-p)
1628 '(called-interactively-p 'interactive
)))
1629 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1630 ;; In some exceptional moments, disparate topic depths need to be allowed
1631 ;; momentarily, eg when one topic is being yanked into another and they're
1632 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1633 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1634 ;; processing to happen in the presence of such discrepancies. It should
1635 ;; almost never be needed, however.
1636 (defvar allout-inhibit-aberrance-doublecheck nil
1637 "Internal state, for momentarily inhibits aberrance doublecheck.
1639 This should only be momentarily let-bound non-nil, not set
1640 non-nil in a lasting way.")
1642 ;;;_ #2 Mode environment and activation
1643 ;;;_ = allout-explicitly-deactivated
1644 (defvar allout-explicitly-deactivated nil
1645 "If t, `allout-mode's last deactivation was deliberate.
1646 So `allout-post-command-business' should not reactivate it...")
1647 (make-variable-buffer-local 'allout-explicitly-deactivated
)
1648 ;;;_ > allout-init (mode)
1649 (defun allout-init (mode)
1650 "DEPRECATED - configure allout activation by customizing
1651 `allout-auto-activation'. This function remains around, limited
1652 from what it did before, for backwards compatibility.
1654 MODE is the activation mode - see `allout-auto-activation' for
1657 (custom-set-variables (list 'allout-auto-activation
(format "%s" mode
)))
1659 (make-obsolete 'allout-init
1660 "customize 'allout-auto-activation' instead." "23.3")
1661 ;;;_ > allout-setup-menubar ()
1662 (defun allout-setup-menubar ()
1663 "Populate the current buffer's menubar with `allout-mode' stuff."
1664 (let ((menus (list allout-mode-exposure-menu
1665 allout-mode-editing-menu
1666 allout-mode-navigation-menu
1667 allout-mode-misc-menu
))
1670 (setq cur
(car menus
)
1672 (easy-menu-add cur
))))
1673 ;;;_ > allout-overlay-preparations
1674 (defun allout-overlay-preparations ()
1675 "Set the properties of the allout invisible-text overlay and others."
1676 (setplist 'allout-exposure-category nil
)
1677 (put 'allout-exposure-category
'invisible
'allout
)
1678 (put 'allout-exposure-category
'evaporate t
)
1679 ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
1680 ;; latter would be sufficient, but it seems that a separate behavior --
1681 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1682 ;; presence of the isearch-open-invisible property -- even though this
1683 ;; property controls the isearch _arrival_ behavior. This is the case at
1684 ;; least in emacs 21, 22.1, and xemacs 21.4.
1685 (put 'allout-exposure-category
'isearch-open-invisible
1686 'allout-isearch-end-handler
)
1687 (if (featurep 'xemacs
)
1688 (put 'allout-exposure-category
'start-open t
)
1689 (put 'allout-exposure-category
'insert-in-front-hooks
1690 '(allout-overlay-insert-in-front-handler)))
1691 (put 'allout-exposure-category
'modification-hooks
1692 '(allout-overlay-interior-modification-handler)))
1693 ;;;_ > define-minor-mode allout-mode
1696 (define-minor-mode allout-mode
1698 "Toggle minor mode for controlling exposure and editing of text outlines.
1699 \\<allout-mode-map-value>
1701 Allout outline mode always runs as a minor mode.
1703 Allout outline mode provides extensive outline oriented
1704 formatting and manipulation. It enables structural editing of
1705 outlines, as well as navigation and exposure. It also is
1706 specifically aimed at accommodating syntax-sensitive text like
1707 programming languages. \(For example, see the allout code itself,
1708 which is organized as an allout outline.)
1710 In addition to typical outline navigation and exposure, allout includes:
1712 - topic-oriented authoring, including keystroke-based topic creation,
1713 repositioning, promotion/demotion, cut, and paste
1714 - incremental search with dynamic exposure and reconcealment of hidden text
1715 - adjustable format, so programming code can be developed in outline-structure
1716 - easy topic encryption and decryption, symmetric or key-pair
1717 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1718 - integral outline layout, for automatic initial exposure when visiting a file
1719 - independent extensibility, using comprehensive exposure and authoring hooks
1721 and many other features.
1723 Below is a description of the key bindings, and then description
1724 of special `allout-mode' features and terminology. See also the
1725 outline menubar additions for quick reference to many of the
1726 features. Customize `allout-auto-activation' to prepare your
1727 emacs session for automatic activation of `allout-mode'.
1729 The bindings are those listed in `allout-prefixed-keybindings'
1730 and `allout-unprefixed-keybindings'. We recommend customizing
1731 `allout-command-prefix' to use just `\\C-c' as the command
1732 prefix, if the allout bindings don't conflict with any personal
1733 bindings you have on \\C-c. In any case, outline structure
1734 navigation and authoring is simplified by positioning the cursor
1735 on an item's bullet character, the \"hot-spot\" -- then you can
1736 invoke allout commands with just the un-prefixed,
1737 un-control-shifted command letters. This is described further in
1738 the HOT-SPOT Operation section.
1742 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1743 \\[allout-show-children] `allout-show-children'
1744 \\[allout-show-current-subtree] `allout-show-current-subtree'
1745 \\[allout-show-current-entry] `allout-show-current-entry'
1746 \\[allout-show-all] `allout-show-all'
1750 \\[allout-next-visible-heading] `allout-next-visible-heading'
1751 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1752 \\[allout-up-current-level] `allout-up-current-level'
1753 \\[allout-forward-current-level] `allout-forward-current-level'
1754 \\[allout-backward-current-level] `allout-backward-current-level'
1755 \\[allout-end-of-entry] `allout-end-of-entry'
1756 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1757 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1758 if immediately repeated cycles to the beginning of the current item
1759 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1762 Topic Header Production:
1763 -----------------------
1764 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1765 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1766 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1768 Topic Level and Prefix Adjustment:
1769 ---------------------------------
1770 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1771 \\[allout-shift-out] `allout-shift-out' ... less deep
1772 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1774 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1775 its' offspring -- distinctive bullets are not changed, others
1776 are alternated according to nesting depth.
1777 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1778 the offspring are not affected.
1779 With repeat count, revoke numbering.
1781 Topic-oriented Killing and Yanking:
1782 ----------------------------------
1783 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1784 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1785 \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure.
1786 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1787 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1788 depth of heading if yanking into bare topic
1789 heading (ie, prefix sans text).
1790 \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank
1792 Topic-oriented Encryption:
1793 -------------------------
1794 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1795 Encrypt/Decrypt topic content
1799 M-x outlineify-sticky Activate outline mode for current buffer,
1800 and establish a default file-var setting
1801 for `allout-layout'.
1802 \\[allout-mark-topic] `allout-mark-topic'
1803 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1804 Duplicate outline, sans concealed text, to
1805 buffer with name derived from derived from that
1806 of current buffer -- \"*BUFFERNAME exposed*\".
1807 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1808 Like above 'copy-exposed', but convert topic
1809 prefixes to section.subsection... numeric
1811 \\[customize-variable] allout-auto-activation
1812 Prepare Emacs session for allout outline mode
1817 Outline mode supports gpg encryption of topics, with support for
1818 symmetric and key-pair modes, and auto-encryption of topics
1819 pending encryption on save.
1821 Topics pending encryption are, by default, automatically
1822 encrypted during file saves, including checkpoint saves, to avoid
1823 exposing the plain text of encrypted topics in the file system.
1824 If the content of the topic containing the cursor was encrypted
1825 for a save, it is automatically decrypted for continued editing.
1827 NOTE: A few GnuPG v2 versions improperly preserve incorrect
1828 symmetric decryption keys, preventing entry of the correct key on
1829 subsequent decryption attempts until the cache times-out. That
1830 can take several minutes. \(Decryption of other entries is not
1831 affected.) Upgrade your EasyPG version, if you can, and you can
1832 deliberately clear your gpg-agent's cache by sending it a '-HUP'
1835 See `allout-toggle-current-subtree-encryption' function docstring
1836 and `allout-encrypt-unencrypted-on-saves' customization variable
1841 Hot-spot operation provides a means for easy, single-keystroke outline
1842 navigation and exposure control.
1844 When the text cursor is positioned directly on the bullet character of
1845 a topic, regular characters (a to z) invoke the commands of the
1846 corresponding allout-mode keymap control chars. For example, \"f\"
1847 would invoke the command typically bound to \"C-c<space>C-f\"
1848 \(\\[allout-forward-current-level] `allout-forward-current-level').
1850 Thus, by positioning the cursor on a topic bullet, you can
1851 execute the outline navigation and manipulation commands with a
1852 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1853 this special translation, so you can use them to get out of the
1854 hot-spot and back to normal editing operation.
1856 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
1857 replaced with one that makes it easy to get to the hot-spot. If you
1858 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1859 is set) to the beginning of the item and then, if you hit it again
1860 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1861 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1862 at the beginning of the current entry.
1866 Allout exposure and authoring activites all have associated
1867 hooks, by which independent code can cooperate with allout
1868 without changes to the allout core. Here are key ones:
1871 `allout-mode-deactivate-hook' \(deprecated)
1872 `allout-mode-off-hook'
1873 `allout-exposure-change-hook'
1874 `allout-structure-added-hook'
1875 `allout-structure-deleted-hook'
1876 `allout-structure-shifted-hook'
1877 `allout-after-copy-or-kill-hook'
1881 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1883 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1884 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1885 and with no intervening items of lower DEPTH than the container.
1887 The visible ITEM most immediately containing the cursor.
1888 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1889 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1891 LEVEL: The same as DEPTH.
1894 Those ITEMs whose TOPICs contain an ITEM.
1895 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1898 The ITEMs contained within an ITEM's TOPIC.
1900 An OFFSPRING of its ANCESTOR TOPICs.
1902 An immediate SUBTOPIC of its PARENT.
1904 TOPICs having the same PARENT and DEPTH.
1906 Topic text constituents:
1908 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1910 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1911 the HEADER text and distinct from the ITEM PREFIX.
1912 BODY: Same as ENTRY.
1913 PREFIX: The leading text of an ITEM which distinguishes it from normal
1914 ENTRY text. Allout recognizes the outline structure according
1915 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1916 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1917 number, indicating the ordinal number of the topic among its
1918 siblings, or an asterisk indicating encryption, plus an optional
1919 space. After that is the ITEM HEADER text, which is not part of
1922 The relative length of the PREFIX determines the nesting DEPTH
1925 The string at the beginning of a HEADER PREFIX, by default a `.'.
1926 It can be customized by changing the setting of
1927 `allout-header-prefix' and then reinitializing `allout-mode'.
1929 When the PREFIX-LEAD is set to the comment-string of a
1930 programming language, outline structuring can be embedded in
1931 program code without interfering with processing of the text
1932 (by emacs or the language processor) as program code. This
1933 setting happens automatically when allout mode is used in
1934 programming-mode buffers. See `allout-use-mode-specific-leader'
1935 docstring for more detail.
1937 Spaces or asterisks which separate the PREFIX-LEAD and the
1938 bullet, determining the ITEM's DEPTH.
1939 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1940 the characters listed on `allout-plain-bullets-string' or
1941 `allout-distinctive-bullets-string'. When creating a TOPIC,
1942 plain BULLETs are by default used, according to the DEPTH of the
1943 TOPIC. Choice among the distinctive BULLETs is offered when you
1944 provide a universal argugment \(\\[universal-argument]) to the
1945 TOPIC creation command, or when explictly rebulleting a TOPIC. The
1946 significance of the various distinctive bullets is purely by
1947 convention. See the documentation for the above bullet strings for
1950 The state of a TOPIC which determines the on-screen visibility
1951 of its OFFSPRING and contained ENTRY text.
1953 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1954 text is represented by \"...\" ellipses.
1956 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1957 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1958 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1961 :keymap
'allout-mode-map
1963 (let ((write-file-hook-var-name (cond ((boundp 'write-file-functions
)
1964 'write-file-functions
)
1965 ((boundp 'write-file-hooks
)
1967 (t 'local-write-file-hooks
)))
1968 (use-layout (if (listp allout-layout
)
1970 allout-default-layout
)))
1972 (if (not (allout-mode-p))
1976 ; Activation not explicitly
1977 ; requested, and either in
1978 ; active state or *de*activation
1979 ; specifically requested:
1980 (allout-do-resumptions)
1982 (remove-from-invisibility-spec '(allout . t
))
1983 (remove-hook 'pre-command-hook
'allout-pre-command-business t
)
1984 (remove-hook 'post-command-hook
'allout-post-command-business t
)
1985 (remove-hook 'before-change-functions
'allout-before-change-handler t
)
1986 (remove-hook 'isearch-mode-end-hook
'allout-isearch-end-handler t
)
1987 (remove-hook write-file-hook-var-name
1988 'allout-write-file-hook-handler t
)
1989 (remove-hook 'auto-save-hook
'allout-auto-save-hook-handler t
)
1991 (remove-overlays (point-min) (point-max)
1992 'category
'allout-exposure-category
))
1995 (if allout-old-style-prefixes
1996 ;; Inhibit all the fancy formatting:
1997 (allout-add-resumptions '(allout-primary-bullet "*")))
1999 (allout-overlay-preparations) ; Doesn't hurt to redo this.
2001 (allout-infer-header-lead-and-primary-bullet)
2002 (allout-infer-body-reindent)
2005 (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
2006 allout-line-boundary-regexp
2008 '(allout-encryption-ciphertext-rejection-regexps
2012 (allout-compose-and-institute-keymap)
2013 (produce-allout-mode-menubar-entries)
2015 (add-to-invisibility-spec '(allout . t
))
2017 (allout-add-resumptions '(line-move-ignore-invisible t
))
2018 (add-hook 'pre-command-hook
'allout-pre-command-business nil t
)
2019 (add-hook 'post-command-hook
'allout-post-command-business nil t
)
2020 (add-hook 'before-change-functions
'allout-before-change-handler nil t
)
2021 (add-hook 'isearch-mode-end-hook
'allout-isearch-end-handler nil t
)
2022 (add-hook write-file-hook-var-name
'allout-write-file-hook-handler
2024 (add-hook 'auto-save-hook
'allout-auto-save-hook-handler nil t
)
2026 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2027 ;; func will be used if auto-fill is active or activated. (The
2028 ;; custom func respects topic headline, maintains hanging-indents,
2030 (allout-add-resumptions (list 'allout-former-auto-filler
2032 ;; Register allout-auto-fill to be used if
2033 ;; filling is active:
2034 (list 'allout-outside-normal-auto-fill-function
2035 normal-auto-fill-function
)
2036 '(normal-auto-fill-function allout-auto-fill
)
2037 ;; Paragraphs are broken by topic headlines.
2038 (list 'paragraph-start
2039 (concat paragraph-start
"\\|^\\("
2040 allout-regexp
"\\)"))
2041 (list 'paragraph-separate
2042 (concat paragraph-separate
"\\|^\\("
2043 allout-regexp
"\\)")))
2044 (if (and auto-fill-function
(not allout-inhibit-auto-fill
))
2045 ;; allout-auto-fill will use the stashed values and so forth.
2046 (allout-add-resumptions '(auto-fill-function allout-auto-fill
)))
2048 (allout-setup-menubar)
2050 ;; Do auto layout if warranted:
2051 (when (and allout-layout
2052 allout-auto-activation
2054 (and (not (string= allout-auto-activation
"activate"))
2055 (if (string= allout-auto-activation
"ask")
2056 (if (y-or-n-p (format "Expose %s with layout '%s'? "
2060 (message "Skipped %s layout." (buffer-name))
2064 (message "Adjusting '%s' exposure..." (buffer-name))
2066 (allout-this-or-next-heading)
2069 (apply 'allout-expose-topic
(list use-layout
))
2070 (message "Adjusting '%s' exposure... done."
2072 ;; Problem applying exposure -- notify user, but don't
2073 ;; interrupt, eg, file visit:
2074 (error (message "%s" (car (cdr err
)))
2076 ) ; when allout-layout
2077 ) ; if (allout-mode-p)
2079 ) ; define-minor-mode
2080 ;;;_ > allout-minor-mode alias
2081 (defalias 'allout-minor-mode
'allout-mode
)
2082 ;;;_ > allout-unload-function
2083 (defun allout-unload-function ()
2084 "Unload the allout outline library."
2085 (save-current-buffer
2086 (dolist (buffer (buffer-list))
2088 (when (allout-mode-p) (allout-mode))))
2089 ;; continue standard unloading
2092 ;;;_ - Position Assessment
2093 ;;;_ > allout-hidden-p (&optional pos)
2094 (defsubst allout-hidden-p
(&optional pos
)
2095 "Non-nil if the character after point was made invisible by allout."
2096 (eq (get-char-property (or pos
(point)) 'invisible
) 'allout
))
2098 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2099 ;;; &optional prelen)
2100 (defun allout-overlay-insert-in-front-handler (ol after beg end
2102 "Shift the overlay so stuff inserted in front of it is excluded."
2104 ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
2105 ;; front-advance on the overlay worked as expected?
2106 (move-overlay ol
(1+ beg
) (overlay-end ol
))))
2107 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2108 ;;; &optional prelen)
2109 (defun allout-overlay-interior-modification-handler (ol after beg end
2111 "Get confirmation before making arbitrary changes to invisible text.
2113 We expose the invisible text and ask for confirmation. Refusal or
2114 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2115 reclosing the opened text.
2117 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2118 internal functions use this feature cohesively bunch changes."
2120 (when (and (not inhibit-read-only
) (not after
))
2121 (let ((start (point))
2122 (ol-start (overlay-start ol
))
2123 (ol-end (overlay-end ol
))
2126 (while (< (point) end
)
2127 (when (allout-hidden-p)
2128 (allout-show-to-offshoot)
2129 (if (allout-hidden-p)
2130 (save-excursion (forward-char 1)
2131 (allout-show-to-offshoot)))
2133 (setq first
(point))))
2134 (goto-char (if (featurep 'xemacs
)
2135 (next-property-change (1+ (point)) nil end
)
2136 (next-char-property-change (1+ (point)) end
))))
2142 (substitute-command-keys
2143 (concat "Modify concealed text? (\"no\" just aborts,"
2144 " \\[keyboard-quit] also reconceals) "))))
2145 (progn (goto-char start
)
2146 (error "Concealed-text change refused")))
2147 (quit (allout-flag-region ol-start ol-end nil
)
2148 (allout-flag-region ol-start ol-end t
)
2149 (error "Concealed-text change abandoned, text reconcealed"))))
2150 (goto-char start
))))
2151 ;;;_ > allout-before-change-handler (beg end)
2152 (defun allout-before-change-handler (beg end
)
2153 "Protect against changes to invisible text.
2155 See `allout-overlay-interior-modification-handler' for details."
2157 (when (and (allout-mode-p) undo-in-progress
(allout-hidden-p))
2158 (allout-show-children))
2160 ;; allout-overlay-interior-modification-handler on an overlay handles
2161 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2162 (when (and (featurep 'xemacs
) (allout-mode-p))
2163 ;; process all of the pending overlays:
2166 (let ((overlay (allout-get-invisibility-overlay)))
2168 (allout-overlay-interior-modification-handler
2169 overlay nil beg end nil
))))))
2170 ;;;_ > allout-isearch-end-handler (&optional overlay)
2171 (defun allout-isearch-end-handler (&optional overlay
)
2172 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2174 Optional OVERLAY parameter is for when this function is used by
2175 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2176 function can also be used as an `isearch-mode-end-hook'."
2178 (if (and (allout-mode-p) (allout-hidden-p))
2179 (allout-show-to-offshoot)))
2181 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2182 ;; All the basic outline functions that directly do string matches to
2183 ;; evaluate heading prefix location set the variables
2184 ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2185 ;; when successful. Functions starting with `allout-recent-' all
2186 ;; use this state, providing the means to avoid redundant searches
2187 ;; for just-established data. This optimization can provide
2188 ;; significant speed improvement, but it must be employed carefully.
2189 ;;;_ = allout-recent-prefix-beginning
2190 (defvar allout-recent-prefix-beginning
0
2191 "Buffer point of the start of the last topic prefix encountered.")
2192 (make-variable-buffer-local 'allout-recent-prefix-beginning
)
2193 ;;;_ = allout-recent-prefix-end
2194 (defvar allout-recent-prefix-end
0
2195 "Buffer point of the end of the last topic prefix encountered.")
2196 (make-variable-buffer-local 'allout-recent-prefix-end
)
2197 ;;;_ = allout-recent-depth
2198 (defvar allout-recent-depth
0
2199 "Depth of the last topic prefix encountered.")
2200 (make-variable-buffer-local 'allout-recent-depth
)
2201 ;;;_ = allout-recent-end-of-subtree
2202 (defvar allout-recent-end-of-subtree
0
2203 "Buffer point last returned by `allout-end-of-current-subtree'.")
2204 (make-variable-buffer-local 'allout-recent-end-of-subtree
)
2205 ;;;_ > allout-prefix-data ()
2206 (defsubst allout-prefix-data
()
2207 "Register allout-prefix state data.
2209 For reference by `allout-recent' funcs. Return
2210 the new value of `allout-recent-prefix-beginning'."
2211 (setq allout-recent-prefix-end
(or (match-end 1) (match-end 2) (match-end 3))
2212 allout-recent-prefix-beginning
(or (match-beginning 1)
2214 (match-beginning 3))
2215 allout-recent-depth
(max 1 (- allout-recent-prefix-end
2216 allout-recent-prefix-beginning
2217 allout-header-subtraction
)))
2218 allout-recent-prefix-beginning
)
2219 ;;;_ > nullify-allout-prefix-data ()
2220 (defsubst nullify-allout-prefix-data
()
2221 "Mark allout prefix data as being uninformative."
2222 (setq allout-recent-prefix-end
(point)
2223 allout-recent-prefix-beginning
(point)
2224 allout-recent-depth
0)
2225 allout-recent-prefix-beginning
)
2226 ;;;_ > allout-recent-depth ()
2227 (defsubst allout-recent-depth
()
2228 "Return depth of last heading encountered by an outline maneuvering function.
2230 All outline functions which directly do string matches to assess
2231 headings set the variables `allout-recent-prefix-beginning' and
2232 `allout-recent-prefix-end' if successful. This function uses those settings
2233 to return the current depth."
2235 allout-recent-depth
)
2236 ;;;_ > allout-recent-prefix ()
2237 (defsubst allout-recent-prefix
()
2238 "Like `allout-recent-depth', but returns text of last encountered prefix.
2240 All outline functions which directly do string matches to assess
2241 headings set the variables `allout-recent-prefix-beginning' and
2242 `allout-recent-prefix-end' if successful. This function uses those settings
2243 to return the current prefix."
2244 (buffer-substring-no-properties allout-recent-prefix-beginning
2245 allout-recent-prefix-end
))
2246 ;;;_ > allout-recent-bullet ()
2247 (defmacro allout-recent-bullet
()
2248 "Like allout-recent-prefix, but returns bullet of last encountered prefix.
2250 All outline functions which directly do string matches to assess
2251 headings set the variables `allout-recent-prefix-beginning' and
2252 `allout-recent-prefix-end' if successful. This function uses those settings
2253 to return the current depth of the most recently matched topic."
2254 '(buffer-substring-no-properties (1- allout-recent-prefix-end
)
2255 allout-recent-prefix-end
))
2259 ;;;_ - Position Assessment
2260 ;;;_ : Location Predicates
2261 ;;;_ > allout-do-doublecheck ()
2262 (defsubst allout-do-doublecheck
()
2263 "True if current item conditions qualify for checking on topic aberrance."
2265 ;; presume integrity of outline and yanked content during yank -- necessary
2266 ;; to allow for level disparity of yank location and yanked text:
2267 (not allout-inhibit-aberrance-doublecheck
)
2268 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2269 (<= allout-recent-depth allout-doublecheck-at-and-shallower
)))
2270 ;;;_ > allout-aberrant-container-p ()
2271 (defun allout-aberrant-container-p ()
2272 "True if topic, or next sibling with children, contains them discontinuously.
2274 Discontinuous means an immediate offspring that is nested more
2275 than one level deeper than the topic.
2277 If topic has no offspring, then the next sibling with offspring will
2278 determine whether or not this one is determined to be aberrant.
2280 If true, then the allout-recent-* settings are calibrated on the
2281 offspring that qaulifies it as aberrant, ie with depth that
2282 exceeds the topic by more than one."
2284 ;; This is most clearly understood when considering standard-prefix-leader
2285 ;; low-level topics, which can all too easily match text not intended as
2286 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2287 ;; following bullet qualifies without this protection. (A sequence of
2288 ;; them can occur naturally, eg a typical textual bullet list.) We
2289 ;; disqualify such low-level sequences when they are followed by a
2290 ;; discontinuously contained child, inferring that the sequences are not
2291 ;; actually connected with their prospective context.
2293 (let ((depth (allout-depth))
2294 (start-point (point))
2298 (while (and (not done
)
2299 (re-search-forward allout-line-boundary-regexp nil
0))
2300 (allout-prefix-data)
2301 (goto-char allout-recent-prefix-beginning
)
2303 ;; sibling -- continue:
2304 ((eq allout-recent-depth depth
))
2305 ;; first offspring is excessive -- aberrant:
2306 ((> allout-recent-depth
(1+ depth
))
2307 (setq done t aberrant t
))
2308 ;; next non-sibling is lower-depth -- not aberrant:
2309 (t (setq done t
))))))
2312 (goto-char start-point
)
2313 ;; recalibrate allout-recent-*
2316 ;;;_ > allout-on-current-heading-p ()
2317 (defun allout-on-current-heading-p ()
2318 "Return non-nil if point is on current visible topics' header line.
2320 Actually, returns prefix beginning point."
2322 (allout-beginning-of-current-line)
2324 (and (looking-at allout-regexp
)
2325 (allout-prefix-data)
2326 (or (not (allout-do-doublecheck))
2327 (not (allout-aberrant-container-p)))))))
2328 ;;;_ > allout-on-heading-p ()
2329 (defalias 'allout-on-heading-p
'allout-on-current-heading-p
)
2330 ;;;_ > allout-e-o-prefix-p ()
2331 (defun allout-e-o-prefix-p ()
2332 "True if point is located where current topic prefix ends, heading begins."
2333 (and (save-match-data
2334 (save-excursion (let ((inhibit-field-text-motion t
))
2335 (beginning-of-line))
2336 (looking-at allout-regexp
))
2337 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2338 ;;;_ : Location attributes
2339 ;;;_ > allout-depth ()
2340 (defun allout-depth ()
2341 "Return depth of topic most immediately containing point.
2343 Does not do doublecheck for aberrant topic header.
2345 Return zero if point is not within any topic.
2347 Like `allout-current-depth', but respects hidden as well as visible topics."
2349 (let ((start-point (point)))
2350 (if (and (allout-goto-prefix)
2351 (not (< start-point
(point))))
2354 ;; Oops, no prefix, nullify it:
2355 (nullify-allout-prefix-data)
2356 ;; ... and return 0:
2358 ;;;_ > allout-current-depth ()
2359 (defun allout-current-depth ()
2360 "Return depth of visible topic most immediately containing point.
2362 Return zero if point is not within any topic."
2364 (if (allout-back-to-current-heading)
2366 (- allout-recent-prefix-end
2367 allout-recent-prefix-beginning
2368 allout-header-subtraction
))
2370 ;;;_ > allout-get-current-prefix ()
2371 (defun allout-get-current-prefix ()
2372 "Topic prefix of the current topic."
2374 (if (allout-goto-prefix)
2375 (allout-recent-prefix))))
2376 ;;;_ > allout-get-bullet ()
2377 (defun allout-get-bullet ()
2378 "Return bullet of containing topic (visible or not)."
2380 (and (allout-goto-prefix)
2381 (allout-recent-bullet))))
2382 ;;;_ > allout-current-bullet ()
2383 (defun allout-current-bullet ()
2384 "Return bullet of current (visible) topic heading, or none if none found."
2387 (allout-back-to-current-heading)
2388 (buffer-substring-no-properties (- allout-recent-prefix-end
1)
2389 allout-recent-prefix-end
))
2390 ;; Quick and dirty provision, ostensibly for missing bullet:
2391 (args-out-of-range nil
))
2393 ;;;_ > allout-get-prefix-bullet (prefix)
2394 (defun allout-get-prefix-bullet (prefix)
2395 "Return the bullet of the header prefix string PREFIX."
2396 ;; Doesn't make sense if we're old-style prefixes, but this just
2397 ;; oughtn't be called then, so forget about it...
2398 (if (string-match allout-regexp prefix
)
2399 (substring prefix
(1- (match-end 2)) (match-end 2))))
2400 ;;;_ > allout-sibling-index (&optional depth)
2401 (defun allout-sibling-index (&optional depth
)
2402 "Item number of this prospective topic among its siblings.
2404 If optional arg DEPTH is greater than current depth, then we're
2405 opening a new level, and return 0.
2407 If less than this depth, ascend to that depth and count..."
2410 (cond ((and depth
(<= depth
0) 0))
2411 ((or (null depth
) (= depth
(allout-depth)))
2413 (while (allout-previous-sibling allout-recent-depth nil
)
2414 (setq index
(1+ index
)))
2416 ((< depth allout-recent-depth
)
2417 (allout-ascend-to-depth depth
)
2418 (allout-sibling-index))
2420 ;;;_ > allout-topic-flat-index ()
2421 (defun allout-topic-flat-index ()
2422 "Return a list indicating point's numeric section.subsect.subsubsect...
2423 Outermost is first."
2424 (let* ((depth (allout-depth))
2425 (next-index (allout-sibling-index depth
))
2427 (while (> next-index
0)
2428 (setq rev-sibls
(cons next-index rev-sibls
))
2429 (setq depth
(1- depth
))
2430 (setq next-index
(allout-sibling-index depth
)))
2434 ;;;_ - Navigation routines
2435 ;;;_ > allout-beginning-of-current-line ()
2436 (defun allout-beginning-of-current-line ()
2437 "Like beginning of line, but to visible text."
2439 ;; This combination of move-beginning-of-line and beginning-of-line is
2440 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2441 (let ((inhibit-field-text-motion t
))
2442 (move-beginning-of-line 1)
2444 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2446 (if (or (allout-hidden-p) (not (bolp)))
2447 (forward-char -
1)))))
2448 ;;;_ > allout-end-of-current-line ()
2449 (defun allout-end-of-current-line ()
2450 "Move to the end of line, past concealed text if any."
2451 ;; This is for symmetry with `allout-beginning-of-current-line' --
2452 ;; `move-end-of-line' doesn't suffer the same problem as
2453 ;; `move-beginning-of-line'.
2454 (let ((inhibit-field-text-motion t
))
2456 (while (allout-hidden-p)
2458 (if (allout-hidden-p) (forward-char 1)))))
2459 ;;;_ > allout-beginning-of-line ()
2460 (defun allout-beginning-of-line ()
2461 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2465 (if (or (not allout-beginning-of-line-cycles
)
2466 (not (equal last-command this-command
)))
2468 (if (and (not (bolp))
2469 (allout-hidden-p (1- (point))))
2470 (goto-char (allout-previous-single-char-property-change
2471 (1- (point)) 'invisible
)))
2472 (move-beginning-of-line 1))
2474 (let ((beginning-of-body
2476 (while (and (allout-do-doublecheck)
2477 (allout-aberrant-container-p)
2478 (allout-previous-visible-heading 1)))
2479 (allout-beginning-of-current-entry)
2481 (cond ((= (current-column) 0)
2482 (goto-char beginning-of-body
))
2483 ((< (point) beginning-of-body
)
2484 (allout-beginning-of-current-line))
2485 ((= (point) beginning-of-body
)
2486 (goto-char (allout-current-bullet-pos)))
2487 (t (allout-beginning-of-current-line)
2488 (if (< (point) beginning-of-body
)
2489 ;; we were on the headline after its start:
2490 (goto-char beginning-of-body
)))))))
2491 ;;;_ > allout-end-of-line ()
2492 (defun allout-end-of-line ()
2493 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2497 (if (or (not allout-end-of-line-cycles
)
2498 (not (equal last-command this-command
)))
2499 (allout-end-of-current-line)
2500 (let ((end-of-entry (save-excursion
2501 (allout-end-of-entry)
2504 (allout-end-of-current-line))
2505 ((or (allout-hidden-p) (save-excursion
2508 (allout-back-to-current-heading)
2509 (allout-show-current-entry)
2510 (allout-show-children)
2511 (allout-end-of-entry))
2512 ((>= (point) end-of-entry
)
2513 (allout-back-to-current-heading)
2514 (allout-end-of-current-line))
2516 (if (not (allout-mark-active-p))
2518 (allout-end-of-entry))))))
2519 ;;;_ > allout-mark-active-p ()
2520 (defun allout-mark-active-p ()
2521 "True if the mark is currently or always active."
2522 ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
2523 ;; provisions, at least in fsf emacs to prevent warnings about lack of,
2524 ;; eg, region-active-p.
2525 (cond ((boundp 'mark-active
)
2527 ((fboundp 'region-active-p
)
2530 ;;;_ > allout-next-heading ()
2531 (defsubst allout-next-heading
()
2532 "Move to the heading for the topic (possibly invisible) after this one.
2534 Returns the location of the heading, or nil if none found.
2536 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2539 (if (looking-at allout-regexp
)
2542 (when (re-search-forward allout-line-boundary-regexp nil
0)
2543 (allout-prefix-data)
2544 (goto-char allout-recent-prefix-beginning
)
2547 (and (allout-do-doublecheck)
2548 ;; this will set allout-recent-* on the first non-aberrant topic,
2549 ;; whether it's the current one or one that disqualifies it:
2550 (allout-aberrant-container-p))
2551 ;; this may or may not be the same as above depending on doublecheck:
2552 (goto-char allout-recent-prefix-beginning
))))
2553 ;;;_ > allout-this-or-next-heading
2554 (defun allout-this-or-next-heading ()
2555 "Position cursor on current or next heading."
2556 ;; A throwaway non-macro that is defined after allout-next-heading
2557 ;; and usable by allout-mode.
2558 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2559 ;;;_ > allout-previous-heading ()
2560 (defun allout-previous-heading ()
2561 "Move to the prior (possibly invisible) heading line.
2563 Return the location of the beginning of the heading, or nil if not found.
2565 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2569 (let ((start-point (point)))
2570 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2571 (allout-goto-prefix)
2573 (when (or (re-search-backward allout-line-boundary-regexp nil
0)
2574 (looking-at allout-bob-regexp
))
2575 (goto-char (allout-prefix-data))
2576 (if (and (allout-do-doublecheck)
2577 (allout-aberrant-container-p))
2578 (or (allout-previous-heading)
2579 (and (goto-char start-point
)
2580 ;; recalibrate allout-recent-*:
2584 ;;;_ > allout-get-invisibility-overlay ()
2585 (defun allout-get-invisibility-overlay ()
2586 "Return the overlay at point that dictates allout invisibility."
2587 (let ((overlays (overlays-at (point)))
2589 (while (and overlays
(not got
))
2590 (if (equal (overlay-get (car overlays
) 'invisible
) 'allout
)
2591 (setq got
(car overlays
))
2594 ;;;_ > allout-back-to-visible-text ()
2595 (defun allout-back-to-visible-text ()
2596 "Move to most recent prior character that is visible, and return point."
2597 (if (allout-hidden-p)
2598 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2601 ;;;_ - Subtree Charting
2602 ;;;_ " These routines either produce or assess charts, which are
2603 ;;; nested lists of the locations of topics within a subtree.
2605 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2606 ;;; for elaborate, compound assessment and adjustment of a subtree.
2608 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2609 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth
)
2610 "Produce a location \"chart\" of subtopics of the containing topic.
2612 Optional argument LEVELS specifies a depth limit (relative to start
2613 depth) for the chart. Null LEVELS means no limit.
2615 When optional argument VISIBLE is non-nil, the chart includes
2616 only the visible subelements of the charted subjects.
2618 The remaining optional args are for internal use by the function.
2620 Point is left at the end of the subtree.
2622 Charts are used to capture outline structure, so that outline-altering
2623 routines need assess the structure only once, and then use the chart
2624 for their elaborate manipulations.
2626 The chart entries for the topics are in reverse order, so the
2627 last topic is listed first. The entry for each topic consists of
2628 an integer indicating the point at the beginning of the topic
2629 prefix. Charts for offspring consists of a list containing,
2630 recursively, the charts for the respective subtopics. The chart
2631 for a topics' offspring precedes the entry for the topic itself.
2633 The other function parameters are for internal recursion, and should
2634 not be specified by external callers. ORIG-DEPTH is depth of topic at
2635 starting point, and PREV-DEPTH is depth of prior topic."
2637 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
2640 (if original
; Just starting?
2641 ; Register initial settings and
2642 ; position to first offspring:
2643 (progn (setq orig-depth
(allout-depth))
2644 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
2646 (allout-next-visible-heading 1)
2647 (allout-next-heading))))
2649 ;; Loop over the current levels' siblings. Besides being more
2650 ;; efficient than tail-recursing over a level, it avoids exceeding
2651 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2653 ;; Probably would speed things up to implement loop-based stack
2654 ;; operation rather than recursing for lower levels. Bah.
2656 (while (and (not (eobp))
2657 ; Still within original topic?
2658 (< orig-depth
(setq curr-depth allout-recent-depth
))
2659 (cond ((= prev-depth curr-depth
)
2660 ;; Register this one and move on:
2661 (setq chart
(cons allout-recent-prefix-beginning chart
))
2662 (if (and levels
(<= levels
1))
2663 ;; At depth limit -- skip sublevels:
2664 (or (allout-next-sibling curr-depth
)
2665 ;; or no more siblings -- proceed to
2666 ;; next heading at lesser depth:
2667 (while (and (<= curr-depth
2668 allout-recent-depth
)
2670 (allout-next-visible-heading 1)
2671 (allout-next-heading)))))
2673 (allout-next-visible-heading 1)
2674 (allout-next-heading))))
2676 ((and (< prev-depth curr-depth
)
2679 ;; Recurse on deeper level of curr topic:
2681 (cons (allout-chart-subtree (and levels
2687 ;; ... then continue with this one.
2690 ;; ... else nil if we've ascended back to prev-depth.
2694 (if original
; We're at the last sibling on
2695 ; the original level. Position
2697 (progn (and (not (eobp)) (forward-char -
1))
2698 (and (= (preceding-char) ?
\n)
2699 (= (aref (buffer-substring (max 1 (- (point) 3))
2704 (setq allout-recent-end-of-subtree
(point))))
2706 chart
; (nreverse chart) not necessary,
2707 ; and maybe not preferable.
2709 ;;;_ > allout-chart-siblings (&optional start end)
2710 (defun allout-chart-siblings (&optional start end
)
2711 "Produce a list of locations of this and succeeding sibling topics.
2712 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2713 for an explanation of charts."
2715 (when (allout-goto-prefix-doublechecked)
2716 (let ((chart (list (point))))
2717 (while (allout-next-sibling)
2718 (setq chart
(cons (point) chart
)))
2719 (if chart
(setq chart
(nreverse chart
)))))))
2720 ;;;_ > allout-chart-to-reveal (chart depth)
2721 (defun allout-chart-to-reveal (chart depth
)
2723 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2725 If DEPTH is nil, include hidden points at any depth.
2727 Note that point can be left at any of the points on chart, or at the
2731 (while (and (or (null depth
) (> depth
0))
2733 (setq here
(car chart
))
2735 (let ((further (allout-chart-to-reveal here
(if (null depth
)
2738 ;; We're on the start of a subtree -- recurse with it, if there's
2739 ;; more depth to go:
2740 (if further
(setq result
(append further result
)))
2741 (setq chart
(cdr chart
)))
2743 (if (allout-hidden-p)
2744 (setq result
(cons here result
)))
2745 (setq chart
(cdr chart
))))
2747 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2748 ;; (defun allout-chart-spec (chart spec &optional exposing)
2749 ;; "Not yet (if ever) implemented.
2751 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2753 ;; Exposure spec indicates the locations to be exposed and the prescribed
2754 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2755 ;; indicating pending concealment, anything higher indicating depth to
2756 ;; which subtopic headers should be exposed, and negative numbers
2757 ;; indicating (negative of) the depth to which subtopic headers and
2758 ;; bodies should be exposed.
2760 ;; The produced list can have two types of entries. Bare numbers
2761 ;; indicate points in the buffer where topic headers that should be
2764 ;; - bare negative numbers indicates that the topic starting at the
2765 ;; point which is the negative of the number should be opened,
2766 ;; including their entries.
2767 ;; - bare positive values indicate that this topic header should be
2769 ;; - Lists signify the beginning and end points of regions that should
2770 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2773 ;; (cond ((listp spec)
2776 ;; (setq spec (cdr spec)))
2780 ;;;_ > allout-goto-prefix ()
2781 (defun allout-goto-prefix ()
2782 "Put point at beginning of immediately containing outline topic.
2784 Goes to most immediate subsequent topic if none immediately containing.
2786 Not sensitive to topic visibility.
2788 Returns the point at the beginning of the prefix, or nil if none."
2792 (while (and (not done
)
2793 (search-backward "\n" nil
1))
2795 (if (looking-at allout-regexp
)
2796 (setq done
(allout-prefix-data))
2799 (cond ((looking-at allout-regexp
)
2800 (allout-prefix-data))
2801 ((allout-next-heading))
2804 ;;;_ > allout-goto-prefix-doublechecked ()
2805 (defun allout-goto-prefix-doublechecked ()
2806 "Put point at beginning of immediately containing outline topic.
2808 Like `allout-goto-prefix', but shallow topics (according to
2809 `allout-doublecheck-at-and-shallower') are checked and
2810 disqualified for child containment discontinuity, according to
2811 `allout-aberrant-container-p'."
2812 (if (allout-goto-prefix)
2813 (if (and (allout-do-doublecheck)
2814 (allout-aberrant-container-p))
2815 (allout-previous-heading)
2818 ;;;_ > allout-end-of-prefix ()
2819 (defun allout-end-of-prefix (&optional ignore-decorations
)
2820 "Position cursor at beginning of header text.
2822 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2823 otherwise skip white space between bullet and ensuing text."
2825 (if (not (allout-goto-prefix-doublechecked))
2827 (goto-char allout-recent-prefix-end
)
2829 (if ignore-decorations
2831 (while (looking-at "[0-9]") (forward-char 1))
2832 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2833 ;; Reestablish where we are:
2834 (allout-current-depth)))
2835 ;;;_ > allout-current-bullet-pos ()
2836 (defun allout-current-bullet-pos ()
2837 "Return position of current (visible) topic's bullet."
2839 (if (not (allout-current-depth))
2841 (1- allout-recent-prefix-end
)))
2842 ;;;_ > allout-back-to-current-heading (&optional interactive)
2843 (defun allout-back-to-current-heading (&optional interactive
)
2844 "Move to heading line of current topic, or beginning if not in a topic.
2846 If interactive, we position at the end of the prefix.
2848 Return value of resulting point, unless we started outside
2849 of (before any) topics, in which case we return nil."
2853 (allout-beginning-of-current-line)
2854 (let ((bol-point (point)))
2855 (when (allout-goto-prefix-doublechecked)
2856 (if (<= (point) bol-point
)
2858 (setq bol-point
(point))
2859 (allout-beginning-of-current-line)
2860 (if (not (= bol-point
(point)))
2861 (if (looking-at allout-regexp
)
2862 (allout-prefix-data)))
2864 (allout-end-of-prefix)
2866 (goto-char (point-min))
2868 ;;;_ > allout-back-to-heading ()
2869 (defalias 'allout-back-to-heading
'allout-back-to-current-heading
)
2870 ;;;_ > allout-pre-next-prefix ()
2871 (defun allout-pre-next-prefix ()
2872 "Skip forward to just before the next heading line.
2874 Returns that character position."
2876 (if (allout-next-heading)
2877 (goto-char (1- allout-recent-prefix-beginning
))))
2878 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2879 (defun allout-end-of-subtree (&optional current include-trailing-blank
)
2880 "Put point at the end of the last leaf in the containing topic.
2882 Optional CURRENT means put point at the end of the containing
2885 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2886 any, as part of the subtree. Otherwise, that trailing blank will be
2887 excluded as delimiting whitespace between topics.
2889 Returns the value of point."
2892 (allout-back-to-current-heading)
2893 (allout-goto-prefix-doublechecked))
2894 (let ((level allout-recent-depth
))
2895 (allout-next-heading)
2896 (while (and (not (eobp))
2897 (> allout-recent-depth level
))
2898 (allout-next-heading))
2900 (allout-end-of-entry)
2902 (if (and (not include-trailing-blank
) (= ?
\n (preceding-char)))
2904 (setq allout-recent-end-of-subtree
(point))))
2905 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2906 (defun allout-end-of-current-subtree (&optional include-trailing-blank
)
2908 "Put point at end of last leaf in currently visible containing topic.
2910 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2911 any, as part of the subtree. Otherwise, that trailing blank will be
2912 excluded as delimiting whitespace between topics.
2914 Returns the value of point."
2916 (allout-end-of-subtree t include-trailing-blank
))
2917 ;;;_ > allout-beginning-of-current-entry (&optional interactive)
2918 (defun allout-beginning-of-current-entry (&optional interactive
)
2919 "When not already there, position point at beginning of current topic header.
2921 If already there, move cursor to bullet for hot-spot operation.
2922 \(See `allout-mode' doc string for details of hot-spot operation.)"
2924 (let ((start-point (point)))
2925 (move-beginning-of-line 1)
2926 (if (< 0 (allout-current-depth))
2927 (goto-char allout-recent-prefix-end
)
2928 (goto-char (point-min)))
2929 (allout-end-of-prefix)
2930 (if (and interactive
2931 (= (point) start-point
))
2932 (goto-char (allout-current-bullet-pos)))))
2933 ;;;_ > allout-end-of-entry (&optional inclusive)
2934 (defun allout-end-of-entry (&optional inclusive
)
2935 "Position the point at the end of the current topics' entry.
2937 Optional INCLUSIVE means also include trailing empty line, if any. When
2938 unset, whitespace between items separates them even when the items are
2941 (allout-pre-next-prefix)
2942 (if (and (not inclusive
) (not (bobp)) (= ?
\n (preceding-char)))
2945 ;;;_ > allout-end-of-current-heading ()
2946 (defun allout-end-of-current-heading ()
2948 (allout-beginning-of-current-entry)
2949 (search-forward "\n" nil t
)
2951 (defalias 'allout-end-of-heading
'allout-end-of-current-heading
)
2952 ;;;_ > allout-get-body-text ()
2953 (defun allout-get-body-text ()
2954 "Return the unmangled body text of the topic immediately containing point."
2956 (allout-end-of-prefix)
2957 (if (not (search-forward "\n" nil t
))
2960 (let ((pre-body (point)))
2963 (allout-end-of-entry t
)
2964 (if (not (= pre-body
(point)))
2965 (buffer-substring-no-properties (1+ pre-body
) (point))))
2972 ;;;_ > allout-ascend-to-depth (depth)
2973 (defun allout-ascend-to-depth (depth)
2974 "Ascend to depth DEPTH, returning depth if successful, nil if not."
2975 (if (and (> depth
0)(<= depth
(allout-depth)))
2976 (let (last-ascended)
2977 (while (and (< depth allout-recent-depth
)
2978 (setq last-ascended
(allout-ascend))))
2979 (goto-char allout-recent-prefix-beginning
)
2980 (if (allout-called-interactively-p) (allout-end-of-prefix))
2981 (and last-ascended allout-recent-depth
))))
2982 ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
2983 (defun allout-ascend (&optional dont-move-if-unsuccessful
)
2984 "Ascend one level, returning resulting depth if successful, nil if not.
2986 Point is left at the beginning of the level whether or not
2987 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
2988 which case point is returned to its original starting location."
2989 (if dont-move-if-unsuccessful
2990 (setq dont-move-if-unsuccessful
(point)))
2992 (if (allout-beginning-of-level)
2993 (let ((bolevel (point))
2994 (bolevel-depth allout-recent-depth
))
2995 (allout-previous-heading)
2996 (cond ((< allout-recent-depth bolevel-depth
)
2997 allout-recent-depth
)
2998 ((= allout-recent-depth bolevel-depth
)
2999 (if dont-move-if-unsuccessful
3000 (goto-char dont-move-if-unsuccessful
))
3004 ;; some topic after very first is lower depth than first:
3008 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3009 ;;;_ > allout-descend-to-depth (depth)
3010 (defun allout-descend-to-depth (depth)
3011 "Descend to depth DEPTH within current topic.
3013 Returning depth if successful, nil if not."
3014 (let ((start-point (point))
3015 (start-depth (allout-depth)))
3017 (and (> (allout-depth) 0)
3018 (not (= depth allout-recent-depth
)) ; ... not there yet
3019 (allout-next-heading) ; ... go further
3020 (< start-depth allout-recent-depth
))) ; ... still in topic
3021 (if (and (> (allout-depth) 0)
3022 (= allout-recent-depth depth
))
3024 (goto-char start-point
)
3027 ;;;_ > allout-up-current-level (arg)
3028 (defun allout-up-current-level (arg)
3029 "Move out ARG levels from current visible topic."
3031 (let ((start-point (point)))
3032 (allout-back-to-current-heading)
3033 (if (not (allout-ascend))
3034 (progn (goto-char start-point
)
3035 (error "Can't ascend past outermost level"))
3036 (if (allout-called-interactively-p) (allout-end-of-prefix))
3037 allout-recent-prefix-beginning
)))
3040 ;;;_ > allout-next-sibling (&optional depth backward)
3041 (defun allout-next-sibling (&optional depth backward
)
3042 "Like `allout-forward-current-level', but respects invisible topics.
3044 Traverse at optional DEPTH, or current depth if none specified.
3046 Go backward if optional arg BACKWARD is non-nil.
3048 Return the start point of the new topic if successful, nil otherwise."
3050 (if (if backward
(bobp) (eobp))
3052 (let ((target-depth (or depth
(allout-depth)))
3053 (start-point (point))
3054 (start-prefix-beginning allout-recent-prefix-beginning
)
3059 ;; done too few single steps to resort to the leap routine:
3062 (not (if backward
(bobp) (eobp)))
3063 ;; still traversable:
3064 (if backward
(allout-previous-heading) (allout-next-heading))
3065 ;; we're below the target depth
3066 (> (setq last-depth allout-recent-depth
) target-depth
))
3067 (setq count
(1+ count
))
3068 (if (> count
7) ; lists are commonly 7 +- 2, right?-)
3071 (or (allout-next-sibling-leap target-depth backward
)
3073 (goto-char start-point
)
3074 (if depth
(allout-depth) target-depth
)
3077 (and (> (or last-depth
(allout-depth)) 0)
3078 (= allout-recent-depth target-depth
))
3079 (not (= start-prefix-beginning
3080 allout-recent-prefix-beginning
)))
3081 allout-recent-prefix-beginning
)
3083 (goto-char start-point
)
3084 (if depth
(allout-depth) target-depth
)
3086 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3087 (defun allout-next-sibling-leap (&optional depth backward
)
3088 "Like `allout-next-sibling', but by direct search for topic at depth.
3090 Traverse at optional DEPTH, or current depth if none specified.
3092 Go backward if optional arg BACKWARD is non-nil.
3094 Return the start point of the new topic if successful, nil otherwise.
3096 Costs more than regular `allout-next-sibling' for short traversals:
3098 - we have to check the prior (next, if travelling backwards)
3099 item to confirm connectivity with the prior topic, and
3100 - if confirmed, we have to reestablish the allout-recent-* settings with
3101 some extra navigation
3102 - if confirmation fails, we have to do more work to recover
3104 It is an increasingly big win when there are many intervening
3105 offspring before the next sibling, however, so
3106 `allout-next-sibling' resorts to this if it finds itself in that
3109 (if (if backward
(bobp) (eobp))
3111 (let* ((start-point (point))
3112 (target-depth (or depth
(allout-depth)))
3113 (search-whitespace-regexp nil
)
3114 (depth-biased (- target-depth
2))
3115 (expression (if (<= target-depth
1)
3116 allout-depth-one-regexp
3117 (format allout-depth-specific-regexp
3118 depth-biased depth-biased
)))
3122 (setq found
(save-match-data
3124 (re-search-backward expression nil
'to-limit
)
3126 (re-search-forward expression nil
'to-limit
))))
3127 (if (and found
(allout-aberrant-container-p))
3129 (setq done
(or found
(if backward
(bobp) (eobp)))))
3131 (progn (goto-char start-point
)
3133 ;; rationale: if any intervening items were at a lower depth, we
3134 ;; would now be on the first offspring at the target depth -- ie,
3135 ;; the preceding item (per the search direction) must be at a
3136 ;; lesser depth. that's all we need to check.
3137 (if backward
(allout-next-heading) (allout-previous-heading))
3138 (if (< allout-recent-depth target-depth
)
3139 ;; return to start and reestablish allout-recent-*:
3141 (goto-char start-point
)
3145 ;; locate cursor and set allout-recent-*:
3146 (allout-goto-prefix))))))
3147 ;;;_ > allout-previous-sibling (&optional depth backward)
3148 (defun allout-previous-sibling (&optional depth backward
)
3149 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3151 Optional DEPTH specifies depth to traverse, default current depth.
3153 Optional BACKWARD reverses direction.
3155 Return depth if successful, nil otherwise."
3156 (allout-next-sibling depth
(not backward
))
3158 ;;;_ > allout-snug-back ()
3159 (defun allout-snug-back ()
3160 "Position cursor at end of previous topic.
3162 Presumes point is at the start of a topic prefix."
3163 (if (or (bobp) (eobp))
3166 (if (or (bobp) (not (= ?
\n (preceding-char))))
3170 ;;;_ > allout-beginning-of-level ()
3171 (defun allout-beginning-of-level ()
3172 "Go back to the first sibling at this level, visible or not."
3173 (allout-end-of-level 'backward
))
3174 ;;;_ > allout-end-of-level (&optional backward)
3175 (defun allout-end-of-level (&optional backward
)
3176 "Go to the last sibling at this level, visible or not."
3178 (let ((depth (allout-depth)))
3179 (while (allout-previous-sibling depth nil
))
3180 (prog1 allout-recent-depth
3181 (if (allout-called-interactively-p) (allout-end-of-prefix)))))
3182 ;;;_ > allout-next-visible-heading (arg)
3183 (defun allout-next-visible-heading (arg)
3184 "Move to the next ARG'th visible heading line, backward if arg is negative.
3186 Move to buffer limit in indicated direction if headings are exhausted."
3189 (let* ((inhibit-field-text-motion t
)
3190 (backward (if (< arg
0) (setq arg
(* -
1 arg
))))
3191 (step (if backward -
1 1))
3192 (progress (allout-current-bullet-pos))
3197 ;; Boundary condition:
3198 (not (if backward
(bobp)(eobp)))
3199 ;; Move, skipping over all concealed lines in one fell swoop:
3200 (prog1 (condition-case nil
(or (line-move step
) t
)
3202 (allout-beginning-of-current-line)
3203 ;; line-move can wind up on the same line if long.
3204 ;; when moving forward, that would yield no-progress
3205 (when (and (not backward
)
3206 (<= (point) progress
))
3207 ;; ensure progress by doing line-move from end-of-line:
3209 (condition-case nil
(or (line-move step
) t
)
3211 (allout-beginning-of-current-line)
3212 (setq progress
(point))))
3213 ;; Deal with apparent header line:
3215 (if (not (looking-at allout-regexp
))
3216 ;; not a header line, keep looking:
3218 (allout-prefix-data)
3219 (if (and (allout-do-doublecheck)
3220 (allout-aberrant-container-p))
3221 ;; skip this aberrant prospective header line:
3223 ;; this prospective headerline qualifies -- register:
3224 (setq got allout-recent-prefix-beginning
)
3225 ;; and break the loop:
3227 ;; Register this got, it may be the last:
3228 (if got
(setq prev got
))
3229 (setq arg
(1- arg
)))
3230 (cond (got ; Last move was to a prefix:
3231 (allout-end-of-prefix))
3232 (prev ; Last move wasn't, but prev was:
3234 (allout-end-of-prefix))
3235 ((not backward
) (end-of-line) nil
))))
3236 ;;;_ > allout-previous-visible-heading (arg)
3237 (defun allout-previous-visible-heading (arg)
3238 "Move to the previous heading line.
3240 With argument, repeats or can move forward if negative.
3241 A heading line is one that starts with a `*' (or that `allout-regexp'
3244 (prog1 (allout-next-visible-heading (- arg
))
3245 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3246 ;;;_ > allout-forward-current-level (arg)
3247 (defun allout-forward-current-level (arg)
3248 "Position point at the next heading of the same level.
3250 Takes optional repeat-count, goes backward if count is negative.
3252 Returns resulting position, else nil if none found."
3254 (let ((start-depth (allout-current-depth))
3256 (backward (> 0 arg
)))
3257 (if (= 0 start-depth
)
3258 (error "No siblings, not in a topic..."))
3259 (if backward
(setq arg
(* -
1 arg
)))
3260 (allout-back-to-current-heading)
3261 (while (and (not (zerop arg
))
3263 (allout-previous-sibling)
3264 (allout-next-sibling)))
3265 (setq arg
(1- arg
)))
3266 (if (not (allout-called-interactively-p))
3268 (allout-end-of-prefix)
3269 (if (not (zerop arg
))
3270 (error "Hit %s level %d topic, traversed %d of %d requested"
3271 (if backward
"first" "last")
3273 (- (abs start-arg
) arg
)
3274 (abs start-arg
))))))
3275 ;;;_ > allout-backward-current-level (arg)
3276 (defun allout-backward-current-level (arg)
3277 "Inverse of `allout-forward-current-level'."
3279 (if (allout-called-interactively-p)
3280 (let ((current-prefix-arg (* -
1 arg
)))
3281 (call-interactively 'allout-forward-current-level
))
3282 (allout-forward-current-level (* -
1 arg
))))
3287 ;;;_ = allout-post-goto-bullet
3288 (defvar allout-post-goto-bullet nil
3289 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3291 When set, tells post-processing to reposition on topic bullet, and
3292 then unset it. Set by `allout-pre-command-business' when implementing
3293 hot-spot operation, where literal characters typed over a topic bullet
3294 are mapped to the command of the corresponding control-key on the
3295 `allout-mode-map-value'.")
3296 (make-variable-buffer-local 'allout-post-goto-bullet
)
3297 ;;;_ = allout-command-counter
3298 (defvar allout-command-counter
0
3299 "Counter that monotonically increases in allout-mode buffers.
3301 Set by `allout-pre-command-business', to support allout addons in
3302 coordinating with allout activity.")
3303 (make-variable-buffer-local 'allout-command-counter
)
3304 ;;;_ > allout-post-command-business ()
3305 (defun allout-post-command-business ()
3306 "Outline `post-command-hook' function.
3308 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3311 - Decrypt topic currently being edited if it was encrypted for a save."
3313 ; Apply any external change func:
3314 (if (not (allout-mode-p)) ; In allout-mode.
3317 (if (and (boundp 'allout-after-save-decrypt
)
3318 allout-after-save-decrypt
)
3319 (allout-after-saves-handler))
3321 ;; Implement allout-post-goto-bullet, if set:
3322 (if (and allout-post-goto-bullet
3323 (allout-current-bullet-pos))
3324 (progn (goto-char (allout-current-bullet-pos))
3325 (setq allout-post-goto-bullet nil
)))
3327 ;;;_ > allout-pre-command-business ()
3328 (defun allout-pre-command-business ()
3329 "Outline `pre-command-hook' function for outline buffers.
3331 Among other things, implements special behavior when the cursor is on the
3332 topic bullet character.
3334 When the cursor is on the bullet character, self-insert
3335 characters are reinterpreted as the corresponding
3336 control-character in the `allout-mode-map-value'. The
3337 `allout-mode' `post-command-hook' insures that the cursor which
3338 has moved as a result of such reinterpretation is positioned on
3339 the bullet character of the destination topic.
3341 The upshot is that you can get easy, single (ie, unmodified) key
3342 outline maneuvering operations by positioning the cursor on the bullet
3343 char. When in this mode you can use regular cursor-positioning
3344 command/keystrokes to relocate the cursor off of a bullet character to
3345 return to regular interpretation of self-insert characters."
3347 (if (not (allout-mode-p))
3349 ;; Increment allout-command-counter
3350 (setq allout-command-counter
(1+ allout-command-counter
))
3351 ;; Do hot-spot navigation.
3352 (if (and (eq this-command
'self-insert-command
)
3353 (eq (point)(allout-current-bullet-pos)))
3354 (allout-hotspot-key-handler))))
3355 ;;;_ > allout-hotspot-key-handler ()
3356 (defun allout-hotspot-key-handler ()
3357 "Catchall handling of key bindings in hot-spots.
3359 Translates unmodified keystrokes to corresponding allout commands, when
3360 they would qualify if prefixed with the allout-command-prefix, and sets
3361 this-command accordingly.
3363 Returns the qualifying command, if any, else nil."
3365 (let* ((modified (event-modifiers last-command-event
))
3366 (key-num (cond ((numberp last-command-event
) last-command-event
)
3367 ;; for XEmacs character type:
3368 ((and (fboundp 'characterp
)
3369 (apply 'characterp
(list last-command-event
)))
3370 (apply 'char-to-int
(list last-command-event
)))
3378 ;; exclude control chars and escape:
3381 (setq mapped-binding
3383 ;; try control-modified versions of keys:
3384 (key-binding (vconcat allout-command-prefix
3386 (if (and (<= 97 key-num
) ; "a"
3387 (>= 122 key-num
)) ; "z"
3388 (- key-num
96) key-num
)))
3390 ;; try non-modified versions of keys:
3391 (key-binding (vconcat allout-command-prefix
3394 ;; Qualified as an allout command -- do hot-spot operation.
3395 (setq allout-post-goto-bullet t
)
3396 ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
3397 (setq mapped-binding
(key-binding (vector key-num
))))
3399 (while (keymapp mapped-binding
)
3400 (setq mapped-binding
3401 (lookup-key mapped-binding
(vector (read-char)))))
3403 (when mapped-binding
3404 (setq this-command mapped-binding
)))))
3406 ;;;_ > allout-find-file-hook ()
3407 (defun allout-find-file-hook ()
3408 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3410 See `allout-auto-activation' for setup instructions."
3411 (if (and allout-auto-activation
3412 (not (allout-mode-p))
3416 ;;;_ - Topic Format Assessment
3417 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3418 (defun allout-solicit-alternate-bullet (depth &optional current-bullet
)
3420 "Prompt for and return a bullet char as an alternative to the current one.
3422 Offer one suitable for current depth DEPTH as default."
3424 (let* ((default-bullet (or (and (stringp current-bullet
) current-bullet
)
3425 (allout-bullet-for-depth depth
)))
3426 (sans-escapes (regexp-sans-escapes allout-bullets-string
))
3429 (goto-char (allout-current-bullet-pos))
3430 (setq choice
(solicit-char-in-string
3431 (format "Select bullet: %s ('%s' default): "
3433 (allout-substring-no-properties default-bullet
))
3437 (if (string= choice
"") default-bullet choice
))
3439 ;;;_ > allout-distinctive-bullet (bullet)
3440 (defun allout-distinctive-bullet (bullet)
3441 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3442 (string-match (regexp-quote bullet
) allout-distinctive-bullets-string
))
3443 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3444 (defun allout-numbered-type-prefix (&optional prefix
)
3445 "True if current header prefix bullet is numbered bullet."
3446 (and allout-numbered-bullet
3447 (string= allout-numbered-bullet
3449 (allout-get-prefix-bullet prefix
)
3450 (allout-get-bullet)))))
3451 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3452 (defun allout-encrypted-type-prefix (&optional prefix
)
3453 "True if current header prefix bullet is for an encrypted entry (body)."
3454 (and allout-topic-encryption-bullet
3455 (string= allout-topic-encryption-bullet
3457 (allout-get-prefix-bullet prefix
)
3458 (allout-get-bullet)))))
3459 ;;;_ > allout-bullet-for-depth (&optional depth)
3460 (defun allout-bullet-for-depth (&optional depth
)
3461 "Return outline topic bullet suited to optional DEPTH, or current depth."
3462 ;; Find bullet in plain-bullets-string modulo DEPTH.
3463 (if allout-stylish-prefixes
3464 (char-to-string (aref allout-plain-bullets-string
3465 (%
(max 0 (- depth
2))
3466 allout-plain-bullets-string-len
)))
3467 allout-primary-bullet
)
3470 ;;;_ - Topic Production
3471 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3472 (defun allout-make-topic-prefix (&optional prior-bullet
3478 ;; Depth null means use current depth, non-null means we're either
3479 ;; opening a new topic after current topic, lower or higher, or we're
3480 ;; changing level of current topic.
3481 ;; Instead dominates specified bullet-char.
3483 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3485 All the arguments are optional.
3487 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3488 nil if none. This bullet may be preserved (other options
3489 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3492 Second arg NEW indicates that a new topic is being opened after the
3493 topic at point, if non-nil. Default bullet for new topics, eg, may
3494 be set (contingent to other args) to numbered bullets if previous
3495 sibling is one. The implication otherwise is that the current topic
3496 is being adjusted -- shifted or rebulleted -- and we don't consider
3497 bullet or previous sibling.
3499 Third arg DEPTH forces the topic prefix to that depth, regardless of
3500 the current topics' depth.
3504 - nil, then the bullet char for the context is used, per distinction or depth
3505 - a \(numeric) character, then character's string representation is used
3506 - a string, then the user is asked for bullet with the first char as default
3507 - anything else, the user is solicited with bullet char per context as default
3509 \(INSTEAD overrides other options, including, eg, a distinctive
3512 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3513 is non-nil *and* no specific INSTEAD was specified. Then
3514 NUMBER-CONTROL non-nil forces prefix to either numbered or
3515 denumbered format, depending on the value of the sixth arg, INDEX.
3517 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3519 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3520 the prefix of the topic is forced to be numbered. Non-nil
3521 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3522 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3523 that the index for the numbered prefix will be derived, by counting
3524 siblings back to start of level. If INDEX is a number, then that
3525 number is used as the index for the numbered prefix (allowing, eg,
3526 sequential renumbering to not require this function counting back the
3527 index for each successive sibling)."
3529 ;; The options are ordered in likely frequence of use, most common
3530 ;; highest, least lowest. Ie, more likely to be doing prefix
3531 ;; adjustments than soliciting, and yet more than numbering.
3532 ;; Current prefix is least dominant, but most likely to be commonly
3538 (depth (or depth
(allout-depth)))
3539 (header-lead allout-header-prefix
)
3542 ;; Getting value for bullet char is practically the whole job:
3545 ; Simplest situation -- level 1:
3546 ((<= depth
1) (setq header-lead
"") allout-primary-bullet
)
3547 ; Simple, too: all asterisks:
3548 (allout-old-style-prefixes
3549 ;; Cheat -- make body the whole thing, null out header-lead and
3551 (setq body
(make-string depth
3552 (string-to-char allout-primary-bullet
)))
3553 (setq header-lead
"")
3556 ;; (Neither level 1 nor old-style, so we're space padding.
3557 ;; Sneak it in the condition of the next case, whatever it is.)
3559 ;; Solicitation overrides numbering and other cases:
3560 ((progn (setq body
(make-string (- depth
2) ?\
))
3561 ;; The actual condition:
3563 (let ((got (cond ((stringp instead
)
3564 (if (> (length instead
) 0)
3565 (allout-solicit-alternate-bullet
3566 depth
(substring instead
0 1))))
3567 ((characterp instead
) (char-to-string instead
))
3568 (t (allout-solicit-alternate-bullet depth
)))))
3569 ;; Gotta check whether we're numbering and got a numbered bullet:
3570 (setq numbering
(and allout-numbered-bullet
3571 (not (and number-control
(not index
)))
3572 (string= got allout-numbered-bullet
)))
3573 ;; Now return what we got, regardless:
3576 ;; Numbering invoked through args:
3577 ((and allout-numbered-bullet number-control
)
3578 (if (setq numbering
(not (setq denumbering
(not index
))))
3579 allout-numbered-bullet
3580 (if (and prior-bullet
3581 (not (string= allout-numbered-bullet
3584 (allout-bullet-for-depth depth
))))
3586 ;;; Neither soliciting nor controlled numbering ;;;
3587 ;;; (may be controlled denumbering, tho) ;;;
3589 ;; Check wrt previous sibling:
3590 ((and new
; only check for new prefixes
3591 (<= depth
(allout-depth))
3592 allout-numbered-bullet
; ... & numbering enabled
3594 (let ((sibling-bullet
3596 ;; Locate correct sibling:
3597 (or (>= depth
(allout-depth))
3598 (allout-ascend-to-depth depth
))
3599 (allout-get-bullet))))
3600 (if (and sibling-bullet
3601 (string= allout-numbered-bullet sibling-bullet
))
3602 (setq numbering sibling-bullet
)))))
3604 ;; Distinctive prior bullet?
3606 (allout-distinctive-bullet prior-bullet
)
3607 ;; Either non-numbered:
3608 (or (not (and allout-numbered-bullet
3609 (string= prior-bullet allout-numbered-bullet
)))
3610 ;; or numbered, and not denumbering:
3611 (setq numbering
(not denumbering
)))
3615 ;; Else, standard bullet per depth:
3616 ((allout-bullet-for-depth depth
)))))
3622 (format "%d" (cond ((and index
(numberp index
)) index
)
3623 (new (1+ (allout-sibling-index depth
)))
3624 ((allout-sibling-index))))))
3627 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3628 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet
)
3629 "Open a new topic at depth DEPTH.
3631 New topic is situated after current one, unless optional flag BEFORE
3632 is non-nil, or unless current line is completely empty -- lacking even
3633 whitespace -- in which case open is done on the current line.
3635 When adding an offspring, it will be added immediately after the parent if
3636 the other offspring are exposed, or after the last child if the offspring
3637 are hidden. (The intervening offspring will be exposed in the latter
3640 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3644 - Creation of new topics is with respect to the visible topic
3645 containing the cursor, regardless of intervening concealed ones.
3647 - New headers are generally created after/before the body of a
3648 topic. However, they are created right at cursor location if the
3649 cursor is on a blank line, even if that breaks the current topic
3650 body. This is intentional, to provide a simple means for
3651 deliberately dividing topic bodies.
3653 - Double spacing of topic lists is preserved. Also, the first
3654 level two topic is created double-spaced (and so would be
3655 subsequent siblings, if that's left intact). Otherwise,
3656 single-spacing is used.
3658 - Creation of sibling or nested topics is with respect to the topic
3659 you're starting from, even when creating backwards. This way you
3660 can easily create a sibling in front of the current topic without
3661 having to go to its preceding sibling, and then open forward
3664 (allout-beginning-of-current-line)
3666 (let* ((inhibit-field-text-motion t
)
3667 (depth (+ (allout-current-depth) relative-depth
))
3668 (opening-on-blank (if (looking-at "^\$")
3669 (not (setq before nil
))))
3670 ;; bunch o vars set while computing ref-topic
3674 (ref-topic (save-excursion
3675 (cond ((< relative-depth
0)
3676 (allout-ascend-to-depth depth
))
3677 ((>= relative-depth
1) nil
)
3678 (t (allout-back-to-current-heading)))
3679 (setq ref-depth allout-recent-depth
)
3681 (if (> allout-recent-prefix-end
1)
3682 (allout-recent-bullet)
3684 (setq opening-numbered
3686 (and allout-numbered-bullet
3687 (or (<= relative-depth
0)
3688 (allout-descend-to-depth depth
))
3689 (if (allout-numbered-type-prefix)
3690 allout-numbered-bullet
))))
3696 (if (not opening-on-blank
)
3697 ; Positioning and vertical
3698 ; padding -- only if not
3701 (goto-char ref-topic
)
3702 (setq dbl-space
; Determine double space action:
3703 (or (and (<= relative-depth
0) ; not descending;
3705 ;; at b-o-b or preceded by a blank line?
3706 (or (> 0 (forward-line -
1))
3707 (looking-at "^\\s-*$")
3710 ;; succeeded by a blank line?
3711 (allout-end-of-current-subtree)
3712 (looking-at "\n\n")))
3713 (and (= ref-depth
1)
3717 ;; Don't already have following
3718 ;; vertical padding:
3719 (not (allout-pre-next-prefix)))))))
3721 ;; Position to prior heading, if inserting backwards, and not
3723 (if (and before
(>= relative-depth
0))
3724 (progn (allout-back-to-current-heading)
3725 (setq doing-beginning
(bobp))
3727 (allout-previous-heading)))
3728 (if (and before
(bobp))
3731 (if (<= relative-depth
0)
3732 ;; Not going inwards, don't snug up:
3738 (progn (end-of-line)
3739 (allout-pre-next-prefix)
3740 (while (and (= ?
\n (following-char))
3745 (if (not (looking-at "^$"))
3747 (allout-end-of-current-subtree)
3748 (if (looking-at "\n\n") (forward-char 1))))
3749 ;; Going inwards -- double-space if first offspring is
3750 ;; double-spaced, otherwise snug up.
3751 (allout-end-of-entry)
3755 (allout-beginning-of-current-line)
3758 ;; Blank lines between current header body and next
3759 ;; header -- get to last substantive (non-white-space)
3761 (progn (setq dbl-space t
)
3762 (re-search-backward "[^ \t\n]" nil t
)))
3763 (if (looking-at "\n\n")
3766 (allout-next-heading)
3767 (when (> allout-recent-depth ref-depth
)
3768 ;; This is an offspring.
3770 (looking-at "^\\s-*$")))
3771 (progn (forward-line 1)
3774 (allout-end-of-current-line))
3776 ;;(if doing-beginning (goto-char doing-beginning))
3778 ;; We insert a newline char rather than using open-line to
3779 ;; avoid rear-stickiness inheritence of read-only property.
3780 (progn (if (and (not (> depth ref-depth
))
3783 (if (and (not dbl-space
) (> depth ref-depth
))
3789 (if (and dbl-space
(not (> relative-depth
0)))
3791 (if (and (not (eobp))
3794 ;; bolp doesnt detect concealed
3795 ;; trailing newlines, compensate:
3798 (allout-hidden-p)))))
3801 (setq start
(point))
3802 (insert (concat (allout-make-topic-prefix opening-numbered t depth
)
3804 (setq end
(1+ (point)))
3806 (allout-rebullet-heading (and offer-recent-bullet ref-bullet
)
3808 (if (> relative-depth
0)
3809 (save-excursion (goto-char ref-topic
)
3810 (allout-show-children)))
3813 (run-hook-with-args 'allout-structure-added-hook start end
)
3817 ;;;_ > allout-open-subtopic (arg)
3818 (defun allout-open-subtopic (arg)
3819 "Open new topic header at deeper level than the current one.
3821 Negative universal arg means to open deeper, but place the new topic
3822 prior to the current one."
3824 (allout-open-topic 1 (> 0 arg
) (< 1 arg
)))
3825 ;;;_ > allout-open-sibtopic (arg)
3826 (defun allout-open-sibtopic (arg)
3827 "Open new topic header at same level as the current one.
3829 Positive universal arg means to use the bullet of the prior sibling.
3831 Negative universal arg means to place the new topic prior to the current
3834 (allout-open-topic 0 (> 0 arg
) (not (= 1 arg
))))
3835 ;;;_ > allout-open-supertopic (arg)
3836 (defun allout-open-supertopic (arg)
3837 "Open new topic header at shallower level than the current one.
3839 Negative universal arg means to open shallower, but place the new
3840 topic prior to the current one."
3843 (allout-open-topic -
1 (> 0 arg
) (< 1 arg
)))
3845 ;;;_ - Outline Alteration
3846 ;;;_ : Topic Modification
3847 ;;;_ = allout-former-auto-filler
3848 (defvar allout-former-auto-filler nil
3849 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3850 ;;;_ > allout-auto-fill ()
3851 (defun allout-auto-fill ()
3852 "`allout-mode' autofill function.
3854 Maintains outline hanging topic indentation if
3855 `allout-use-hanging-indents' is set."
3857 (when (and (not allout-inhibit-auto-fill
)
3858 (or (not allout-inhibit-auto-fill-on-headline
)
3859 (not (allout-on-current-heading-p))))
3860 (let ((fill-prefix (if allout-use-hanging-indents
3861 ;; Check for topic header indentation:
3865 (if (looking-at allout-regexp
)
3866 ;; ... construct indentation to account for
3867 ;; length of topic prefix:
3868 (make-string (progn (allout-end-of-prefix)
3871 (use-auto-fill-function
3872 (if (and (eq allout-outside-normal-auto-fill-function
3874 (eq auto-fill-function
'allout-auto-fill
))
3876 (or allout-outside-normal-auto-fill-function
3877 auto-fill-function
))))
3878 (if (or allout-former-auto-filler allout-use-hanging-indents
)
3879 (funcall use-auto-fill-function
)))))
3880 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3881 (defun allout-reindent-body (old-depth new-depth
&optional number
)
3882 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3884 Optional arg NUMBER indicates numbering is being added, and it must
3887 Note that refill of indented paragraphs is not done."
3890 (allout-end-of-prefix)
3891 (let* ((new-margin (current-column))
3892 excess old-indent-begin old-indent-end
3893 ;; We want the column where the header-prefix text started
3894 ;; *before* the prefix was changed, so we infer it relative
3895 ;; to the new margin and the shift in depth:
3896 (old-margin (+ old-depth
(- new-margin new-depth
))))
3898 ;; Process lines up to (but excluding) next topic header:
3902 (and (re-search-forward "\n\\(\\s-*\\)"
3905 ;; Register the indent data, before we reset the
3906 ;; match data with a subsequent `looking-at':
3907 (setq old-indent-begin
(match-beginning 1)
3908 old-indent-end
(match-end 1))
3909 (not (looking-at allout-regexp
)))
3910 (if (> 0 (setq excess
(- (- old-indent-end old-indent-begin
)
3912 ;; Text starts left of old margin -- don't adjust:
3914 ;; Text was hanging at or right of old left margin --
3915 ;; reindent it, preserving its existing indentation
3916 ;; beyond the old margin:
3917 (delete-region old-indent-begin old-indent-end
)
3918 (indent-to (+ new-margin excess
(current-column))))))))))
3919 ;;;_ > allout-rebullet-current-heading (arg)
3920 (defun allout-rebullet-current-heading (arg)
3921 "Solicit new bullet for current visible heading."
3923 (let ((initial-col (current-column))
3924 (on-bullet (eq (point)(allout-current-bullet-pos)))
3926 (backwards (if (< arg
0)
3927 (setq arg
(* arg -
1)))))
3929 (save-excursion (allout-back-to-current-heading)
3930 (allout-end-of-prefix)
3931 (setq from allout-recent-prefix-beginning
3932 to allout-recent-prefix-end
)
3933 (allout-rebullet-heading t
;;; instead
3935 nil
;;; number-control
3937 t
) ;;; do-successors
3938 (run-hook-with-args 'allout-exposure-change-hook
3943 (setq initial-col nil
) ; Override positioning back to init col
3945 (allout-next-visible-heading 1)
3946 (allout-goto-prefix-doublechecked)
3947 (allout-next-visible-heading -
1))))
3949 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
3950 (initial-col (move-to-column initial-col
)))))
3951 ;;;_ > allout-rebullet-heading (&optional instead ...)
3952 (defun allout-rebullet-heading (&optional instead
3958 "Adjust bullet of current topic prefix.
3960 All args are optional.
3963 - nil, then the bullet char for the context is used, per distinction or depth
3964 - a \(numeric) character, then character's string representation is used
3965 - a string, then the user is asked for bullet with the first char as default
3966 - anything else, the user is solicited with bullet char per context as default
3968 Second arg DEPTH forces the topic prefix to that depth, regardless
3969 of the topic's current depth.
3971 Third arg NUMBER-CONTROL can force the prefix to or away from
3972 numbered form. It has effect only if `allout-numbered-bullet' is
3973 non-nil and soliciting was not explicitly invoked (via first arg).
3974 Its effect, numbering or denumbering, then depends on the setting
3975 of the fourth arg, INDEX.
3977 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
3978 prefix of the topic is forced to be non-numbered. Null index and
3979 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
3980 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
3981 INDEX is a number, then that number is used for the numbered
3982 prefix. Non-nil and non-number means that the index for the
3983 numbered prefix will be derived by allout-make-topic-prefix.
3985 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
3988 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
3989 and `allout-numbered-bullet', which all affect the behavior of
3992 (let* ((current-depth (allout-depth))
3993 (new-depth (or new-depth current-depth
))
3994 (mb allout-recent-prefix-beginning
)
3995 (me allout-recent-prefix-end
)
3996 (current-bullet (buffer-substring-no-properties (- me
1) me
))
3997 (has-annotation (get-text-property mb
'allout-was-hidden
))
3998 (new-prefix (allout-make-topic-prefix current-bullet
4005 ;; Is new one is identical to old?
4006 (if (and (= current-depth new-depth
)
4007 (string= current-bullet
4008 (substring new-prefix
(1- (length new-prefix
)))))
4012 ;; New prefix probably different from old:
4013 ; get rid of old one:
4014 (allout-unprotected (delete-region mb me
))
4016 ; Dispense with number if
4017 ; numbered-bullet prefix:
4019 (if (and allout-numbered-bullet
4020 (string= allout-numbered-bullet current-bullet
)
4021 (looking-at "[0-9]+"))
4023 (delete-region (match-beginning 0)(match-end 0)))))
4025 ;; convey 'allout-was-hidden annotation, if original had it:
4027 (put-text-property 0 (length new-prefix
) 'allout-was-hidden t
4030 ; Put in new prefix:
4031 (allout-unprotected (insert new-prefix
))
4033 ;; Reindent the body if elected, margin changed, and not encrypted body:
4034 (if (and allout-reindent-bodies
4035 (not (= new-depth current-depth
))
4036 (not (allout-encrypted-topic-p)))
4037 (allout-reindent-body current-depth new-depth
))
4039 ;; Recursively rectify successive siblings of orig topic if
4040 ;; caller elected for it:
4043 (while (allout-next-sibling new-depth nil
)
4045 (cond ((numberp index
) (1+ index
))
4046 ((not number-control
) (allout-sibling-index))))
4047 (if (allout-numbered-type-prefix)
4048 (allout-rebullet-heading nil
;;; instead
4049 new-depth
;;; new-depth
4050 number-control
;;; number-control
4052 nil
))))) ;;;(dont!)do-successors
4053 ) ; (if (and (= current-depth new-depth)...))
4054 ) ; let* ((current-depth (allout-depth))...)
4056 ;;;_ > allout-rebullet-topic (arg)
4057 (defun allout-rebullet-topic (arg &optional sans-offspring
)
4058 "Rebullet the visible topic containing point and all contained subtopics.
4060 Descends into invisible as well as visible topics, however.
4062 When optional SANS-OFFSPRING is non-nil, subtopics are not
4063 shifted. (Shifting a topic outwards without shifting its
4064 offspring is disallowed, since this would create a \"containment
4065 discontinuity\", where the depth difference between a topic and
4066 its immediate offspring is greater than one.)
4068 With repeat count, shift topic depth by that amount."
4070 (let ((start-col (current-column)))
4073 (cond ((null arg
) (setq arg
0))
4074 ((listp arg
) (setq arg
(car arg
))))
4075 ;; Fill the user in, in case we're shifting a big topic:
4076 (if (not (zerop arg
)) (message "Shifting..."))
4077 (allout-back-to-current-heading)
4078 (if (<= (+ allout-recent-depth arg
) 0)
4079 (error "Attempt to shift topic below level 1"))
4080 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring
)
4081 (if (not (zerop arg
)) (message "Shifting... done.")))
4082 (move-to-column (max 0 (+ start-col arg
)))))
4083 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4084 (defun allout-rebullet-topic-grunt (&optional relative-depth
4090 "Like `allout-rebullet-topic', but on nearest containing topic
4093 See `allout-rebullet-heading' for rebulleting behavior.
4095 All arguments are optional.
4097 First arg RELATIVE-DEPTH means to shift the depth of the entire
4100 Several subsequent args are for internal recursive use by the function
4101 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4103 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4104 are not shifted. (Shifting a topic outwards without shifting
4105 its offspring is disallowed, since this would create a
4106 \"containment discontinuity\", where the depth difference between
4107 a topic and its immediate offspring is greater than one.)"
4109 ;; XXX the recursion here is peculiar, and in general the routine may
4110 ;; need simplification with refactoring.
4112 (if (and sans-offspring
4114 (< relative-depth
0))
4115 (error (concat "Attempt to shift topic outwards without offspring,"
4116 " would cause containment discontinuity.")))
4118 (let* ((relative-depth (or relative-depth
0))
4119 (new-depth (allout-depth))
4120 (starting-depth (or starting-depth new-depth
))
4121 (on-starting-call (null starting-point
))
4123 ;; Leave index null on starting call, so rebullet-heading
4124 ;; calculates it at what might be new depth:
4125 (and (or (zerop relative-depth
)
4126 (not on-starting-call
))
4127 (allout-sibling-index))))
4128 (starting-index index
)
4129 (moving-outwards (< 0 relative-depth
))
4130 (starting-point (or starting-point
(point)))
4131 (local-point (point)))
4133 ;; Sanity check for excessive promotion done only on starting call:
4134 (and on-starting-call
4136 (> 0 (+ starting-depth relative-depth
))
4137 (error "Attempt to shift topic out beyond level 1"))
4139 (cond ((= starting-depth new-depth
)
4140 ;; We're at depth to work on this one.
4142 ;; When shifting out we work on the children before working on
4143 ;; the parent to avoid interim `allout-aberrant-container-p'
4144 ;; aberrancy, and vice-versa when shifting in:
4145 (if (>= relative-depth
0)
4146 (allout-rebullet-heading nil
4147 (+ starting-depth relative-depth
)
4150 nil
)) ;;; do-successors
4151 (when (not sans-offspring
)
4152 ;; ... and work on subsequent ones which are at greater depth:
4154 (allout-next-heading)
4155 (while (and (not (eobp))
4156 (< starting-depth
(allout-depth)))
4157 (setq index
(1+ index
))
4158 (allout-rebullet-topic-grunt relative-depth
4162 (when (< relative-depth
0)
4164 (goto-char local-point
)
4165 (allout-rebullet-heading nil
;;; instead
4166 (+ starting-depth relative-depth
)
4169 nil
)))) ;;; do-successors
4171 ((< starting-depth new-depth
)
4172 ;; Rare case -- subtopic more than one level deeper than parent.
4173 ;; Treat this one at an even deeper level:
4174 (allout-rebullet-topic-grunt relative-depth
4180 (if on-starting-call
4182 ;; Rectify numbering of former siblings of the adjusted topic,
4183 ;; if topic has changed depth
4184 (if (or do-successors
4185 (and (not (zerop relative-depth
))
4186 (or (= allout-recent-depth starting-depth
)
4187 (= allout-recent-depth
(+ starting-depth
4189 (allout-rebullet-heading nil nil nil nil t
))
4190 ;; Now rectify numbering of new siblings of the adjusted topic,
4191 ;; if depth has been changed:
4192 (progn (goto-char starting-point
)
4193 (if (not (zerop relative-depth
))
4194 (allout-rebullet-heading nil nil nil nil t
)))))
4197 ;;;_ > allout-renumber-to-depth (&optional depth)
4198 (defun allout-renumber-to-depth (&optional depth
)
4199 "Renumber siblings at current depth.
4201 Affects superior topics if optional arg DEPTH is less than current depth.
4203 Returns final depth."
4205 ;; Proceed by level, processing subsequent siblings on each,
4206 ;; ascending until we get shallower than the start depth:
4208 (let ((ascender (allout-depth))
4210 (while (and (not (eobp))
4212 (>= allout-recent-depth depth
)
4213 (>= ascender depth
))
4214 ; Skip over all topics at
4215 ; lesser depths, which can not
4216 ; have been disturbed:
4217 (while (and (not (setq was-eobp
(eobp)))
4218 (> allout-recent-depth ascender
))
4219 (allout-next-heading))
4220 ; Prime ascender for ascension:
4221 (setq ascender
(1- allout-recent-depth
))
4222 (if (>= allout-recent-depth depth
)
4223 (allout-rebullet-heading nil
;;; instead
4225 nil
;;; number-control
4227 t
)) ;;; do-successors
4228 (if was-eobp
(goto-char (point-max)))))
4229 allout-recent-depth
)
4230 ;;;_ > allout-number-siblings (&optional denumber)
4231 (defun allout-number-siblings (&optional denumber
)
4232 "Assign numbered topic prefix to this topic and its siblings.
4234 With universal argument, denumber -- assign default bullet to this
4235 topic and its siblings.
4237 With repeated universal argument (`^U^U'), solicit bullet for each
4238 rebulleting each topic at this level."
4243 (allout-back-to-current-heading)
4244 (allout-beginning-of-level)
4245 (let ((depth allout-recent-depth
)
4246 (index (if (not denumber
) 1))
4247 (use-bullet (equal '(16) denumber
))
4250 (allout-rebullet-heading use-bullet
;;; instead
4252 t
;;; number-control
4254 nil
) ;;; do-successors
4255 (if index
(setq index
(1+ index
)))
4256 (setq more
(allout-next-sibling depth nil
))))))
4257 ;;;_ > allout-shift-in (arg)
4258 (defun allout-shift-in (arg)
4259 "Increase depth of current heading and any items collapsed within it.
4261 With a negative argument, the item is shifted out using
4262 `allout-shift-out', instead.
4264 With an argument greater than one, shift-in the item but not its
4265 offspring, making the item into a sibling of its former children,
4266 and a child of sibling that formerly preceded it.
4268 You are not allowed to shift the first offspring of a topic
4269 inwards, because that would yield a \"containment
4270 discontinuity\", where the depth difference between a topic and
4271 its immediate offspring is greater than one. The first topic in
4272 the file can be adjusted to any positive depth, however."
4276 (allout-shift-out (* arg -
1))
4277 ;; refuse to create a containment discontinuity:
4279 (allout-back-to-current-heading)
4281 (let* ((current-depth allout-recent-depth
)
4282 (start-point (point))
4283 (predecessor-depth (progn
4285 (allout-goto-prefix-doublechecked)
4286 (if (< (point) start-point
)
4289 (if (and (> predecessor-depth
0)
4290 (> (1+ current-depth
)
4291 (1+ predecessor-depth
)))
4292 (error (concat "Disallowed shift deeper than"
4293 " containing topic's children."))
4294 (allout-back-to-current-heading)
4295 (if (< allout-recent-depth
(1+ current-depth
))
4296 (allout-show-children))))))
4297 (let ((where (point)))
4298 (allout-rebullet-topic 1 (and (> arg
1) 'sans-offspring
))
4299 (run-hook-with-args 'allout-structure-shifted-hook arg where
))))
4300 ;;;_ > allout-shift-out (arg)
4301 (defun allout-shift-out (arg)
4302 "Decrease depth of current heading and any topics collapsed within it.
4303 This will make the item a sibling of its former container.
4305 With a negative argument, the item is shifted in using
4306 `allout-shift-in', instead.
4308 With an argument greater than one, shift-out the item's offspring
4309 but not the item itself, making the former children siblings of
4312 With an argument greater than 1, the item's offspring are shifted
4313 out without shifting the item. This will make the immediate
4314 subtopics into siblings of the item."
4317 (allout-shift-in (* arg -
1))
4318 ;; Get proper exposure in this area:
4319 (save-excursion (if (allout-ascend)
4320 (allout-show-children)))
4321 ;; Show collapsed children if there's a successor which will become
4323 (if (and (allout-current-topic-collapsed-p)
4324 (save-excursion (allout-next-sibling)))
4325 (allout-show-children))
4326 (let ((where (and (allout-depth) allout-recent-prefix-beginning
)))
4329 ;; Shift the offspring but not the topic:
4330 (let ((children-chart (allout-chart-subtree 1)))
4331 (if (listp (car children-chart
))
4333 (setq children-chart
(allout-flatten children-chart
)))
4335 (dolist (child-point children-chart
)
4336 (goto-char child-point
)
4337 (allout-shift-out 1))))
4338 (allout-rebullet-topic (* arg -
1))))
4339 (run-hook-with-args 'allout-structure-shifted-hook
(* arg -
1) where
))))
4340 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4341 ;;;_ > allout-kill-line (&optional arg)
4342 (defun allout-kill-line (&optional arg
)
4343 "Kill line, adjusting subsequent lines suitably for outline mode."
4347 (if (or (not (allout-mode-p))
4349 (not (save-match-data (looking-at allout-regexp
))))
4350 ;; Just do a regular kill:
4352 ;; Ah, have to watch out for adjustments:
4353 (let* ((beg (point))
4355 (beg-hidden (allout-hidden-p))
4356 (end-hidden (save-excursion (allout-end-of-current-line)
4359 (depth (allout-depth)))
4361 (allout-annotate-hidden beg end
)
4363 (if (and (not beg-hidden
) (not end-hidden
))
4364 (allout-unprotected (kill-line arg
))
4366 (run-hooks 'allout-after-copy-or-kill-hook
)
4367 (allout-deannotate-hidden beg end
)
4369 (if allout-numbered-bullet
4370 (save-excursion ; Renumber subsequent topics if needed:
4371 (if (not (save-match-data (looking-at allout-regexp
)))
4372 (allout-next-heading))
4373 (allout-renumber-to-depth depth
)))
4374 (run-hook-with-args 'allout-structure-deleted-hook depth
(point))))))
4375 ;;;_ > allout-copy-line-as-kill ()
4376 (defun allout-copy-line-as-kill ()
4377 "Like allout-kill-topic, but save to kill ring instead of deleting."
4379 (let ((buffer-read-only t
))
4382 (buffer-read-only nil
))))
4383 ;;;_ > allout-kill-topic ()
4384 (defun allout-kill-topic ()
4385 "Kill topic together with subtopics.
4387 Trailing whitespace is killed with a topic if that whitespace:
4389 - would separate the topic from a subsequent sibling
4390 - would separate the topic from the end of buffer
4391 - would not be added to whitespace already separating the topic from the
4394 Topic exposure is marked with text-properties, to be used by
4395 `allout-yank-processing' for exposure recovery."
4398 (let* ((inhibit-field-text-motion t
)
4399 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4401 (depth allout-recent-depth
))
4402 (allout-end-of-current-subtree)
4403 (if (and (/= (current-column) 0) (not (eobp)))
4406 (if (and (save-match-data (looking-at "\n"))
4408 (or (not (allout-next-heading))
4409 (= depth allout-recent-depth
)))
4410 (and (> (- beg
(point-min)) 3)
4411 (string= (buffer-substring (- beg
2) beg
) "\n\n"))))
4414 (allout-annotate-hidden beg
(setq end
(point)))
4415 (unwind-protect ; for possible barf-if-buffer-read-only.
4416 (allout-unprotected (kill-region beg end
))
4417 (allout-deannotate-hidden beg end
)
4418 (run-hooks 'allout-after-copy-or-kill-hook
)
4421 (allout-renumber-to-depth depth
))
4422 (run-hook-with-args 'allout-structure-deleted-hook depth
(point)))))
4423 ;;;_ > allout-copy-topic-as-kill ()
4424 (defun allout-copy-topic-as-kill ()
4425 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4427 (let ((buffer-read-only t
))
4430 (buffer-read-only (message "Topic copied...")))))
4431 ;;;_ > allout-annotate-hidden (begin end)
4432 (defun allout-annotate-hidden (begin end
)
4433 "Qualify text with properties to indicate exposure status."
4435 (let ((was-modified (buffer-modified-p))
4436 (buffer-read-only nil
))
4437 (allout-deannotate-hidden begin end
)
4440 (let (done next prev overlay
)
4442 ;; at or advance to start of next hidden region:
4443 (if (not (allout-hidden-p))
4446 (allout-next-single-char-property-change (point)
4449 (if (or (not next
) (eq prev next
))
4450 ;; still not at start of hidden area -- must not be any left.
4454 (if (not (allout-hidden-p))
4455 ;; still not at start of hidden area.
4457 (setq overlay
(allout-get-invisibility-overlay))
4458 (setq next
(overlay-end overlay
)
4460 ;; advance to end of this hidden area:
4464 (let ((buffer-undo-list t
))
4465 (put-text-property (overlay-start overlay
) next
4466 'allout-was-hidden t
)))))))))
4467 (set-buffer-modified-p was-modified
)))
4468 ;;;_ > allout-deannotate-hidden (begin end)
4469 (defun allout-deannotate-hidden (begin end
)
4470 "Remove allout hidden-text annotation between BEGIN and END."
4473 (let ((inhibit-read-only t
)
4474 (buffer-undo-list t
))
4475 (remove-text-properties begin
(min end
(point-max))
4476 '(allout-was-hidden t
)))))
4477 ;;;_ > allout-hide-by-annotation (begin end)
4478 (defun allout-hide-by-annotation (begin end
)
4479 "Translate text properties indicating exposure status into actual exposure."
4482 (let ((was-modified (buffer-modified-p))
4485 ;; at or advance to start of next annotation:
4486 (if (not (get-text-property (point) 'allout-was-hidden
))
4487 (setq next
(allout-next-single-char-property-change
4488 (point) 'allout-was-hidden nil end
)))
4489 (if (or (not next
) (eq prev next
))
4490 ;; no more or not advancing -- must not be any left.
4494 (if (not (get-text-property (point) 'allout-was-hidden
))
4495 ;; still not at start of annotation.
4497 ;; advance to just after end of this annotation:
4498 (setq next
(allout-next-single-char-property-change
4499 (point) 'allout-was-hidden nil end
))
4500 (let ((o (make-overlay prev next nil
'front-advance
)))
4501 (overlay-put o
'category
'allout-exposure-category
)
4502 (overlay-put o
'evaporate t
))
4503 (allout-deannotate-hidden prev next
)
4505 (if next
(goto-char next
)))))
4506 (set-buffer-modified-p was-modified
))))
4507 ;;;_ > allout-yank-processing ()
4508 (defun allout-yank-processing (&optional arg
)
4510 "Incidental allout-specific business to be done just after text yanks.
4512 Does depth adjustment of yanked topics, when:
4514 1 the stuff being yanked starts with a valid outline header prefix, and
4515 2 it is being yanked at the end of a line which consists of only a valid
4518 Also, adjusts numbering of subsequent siblings when appropriate.
4520 Depth adjustment alters the depth of all the topics being yanked
4521 the amount it takes to make the first topic have the depth of the
4522 header into which it's being yanked.
4524 The point is left in front of yanked, adjusted topics, rather than
4525 at the end (and vice-versa with the mark). Non-adjusted yanks,
4526 however, are left exactly like normal, non-allout-specific yanks."
4529 ; Get to beginning, leaving
4530 ; region around subject:
4531 (if (< (allout-mark-marker t
) (point))
4532 (exchange-point-and-mark))
4534 (let* ((subj-beg (point))
4536 (subj-end (allout-mark-marker t
))
4537 ;; 'resituate' if yanking an entire topic into topic header:
4538 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t
))
4539 (allout-e-o-prefix-p))
4540 (looking-at allout-regexp
)
4541 (allout-prefix-data)))
4542 ;; `rectify-numbering' if resituating (where several topics may
4543 ;; be resituating) or yanking a topic into a topic slot (bol):
4544 (rectify-numbering (or resituate
4545 (and into-bol
(looking-at allout-regexp
)))))
4547 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4548 (let* ((inhibit-field-text-motion t
)
4549 (prefix-len (if (not (match-end 1))
4551 (- (match-end 1) subj-beg
)))
4552 (subj-depth allout-recent-depth
)
4553 (prefix-bullet (allout-recent-bullet))
4555 ;; Nil if adjustment unnecessary, otherwise depth to which
4556 ;; adjustment should be made:
4558 (and (goto-char subj-end
)
4560 (goto-char subj-beg
)
4561 (and (looking-at allout-regexp
)
4564 (not (= (point) subj-beg
)))
4565 (looking-at allout-regexp
)
4566 (allout-prefix-data))
4567 allout-recent-depth
)))
4569 (setq rectify-numbering allout-numbered-bullet
)
4571 ; Do the adjustment:
4574 (narrow-to-region subj-beg subj-end
)
4575 ; Trim off excessive blank
4576 ; line at end, if any:
4577 (goto-char (point-max))
4578 (if (looking-at "^$")
4579 (allout-unprotected (delete-char -
1)))
4580 ; Work backwards, with each
4582 ; successively excluding the
4583 ; last processed topic from
4584 ; the narrow region:
4586 (allout-back-to-current-heading)
4587 ; go as high as we can in each bunch:
4588 (while (allout-ascend t
))
4591 (allout-rebullet-topic-grunt (- adjust-to-depth
4594 (if (setq more
(not (bobp)))
4597 (narrow-to-region subj-beg
(point))))))
4598 ;; Remove new heading prefix:
4601 (delete-region (point) (+ (point)
4605 ; and delete residual subj
4606 ; prefix digits and space:
4607 (while (looking-at "[0-9]") (delete-char 1))
4608 (if (looking-at " ")
4610 ;; Assert new topic's bullet - minimal effort if unchanged:
4611 (allout-rebullet-heading (string-to-char prefix-bullet
)))
4612 (exchange-point-and-mark))))
4613 (if rectify-numbering
4616 ; Give some preliminary feedback:
4617 (message "... reconciling numbers")
4618 ; ... and renumber, in case necessary:
4619 (goto-char subj-beg
)
4620 (if (allout-goto-prefix-doublechecked)
4622 (allout-rebullet-heading nil
;;; instead
4623 (allout-depth) ;;; depth
4624 nil
;;; number-control
4628 (if (or into-bol resituate
)
4629 (allout-hide-by-annotation (point) (allout-mark-marker t
))
4630 (allout-deannotate-hidden (allout-mark-marker t
) (point)))
4632 (exchange-point-and-mark))
4633 (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end
))))
4634 ;;;_ > allout-yank (&optional arg)
4635 (defun allout-yank (&optional arg
)
4636 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4638 Non-topic yanks work no differently than normal yanks.
4640 If a topic is being yanked into a bare topic prefix, the depth of the
4641 yanked topic is adjusted to the depth of the topic prefix.
4643 1 we're yanking in an `allout-mode' buffer
4644 2 the stuff being yanked starts with a valid outline header prefix, and
4645 3 it is being yanked at the end of a line which consists of only a valid
4648 If these conditions hold then the depth of the yanked topics are all
4649 adjusted the amount it takes to make the first one at the depth of the
4650 header into which it's being yanked.
4652 The point is left in front of yanked, adjusted topics, rather than
4653 at the end (and vice-versa with the mark). Non-adjusted yanks,
4654 however, (ones that don't qualify for adjustment) are handled
4655 exactly like normal yanks.
4657 Numbering of yanked topics, and the successive siblings at the depth
4658 into which they're being yanked, is adjusted.
4660 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4661 works with normal `yank' in non-outline buffers."
4664 (setq this-command
'yank
)
4668 (allout-yank-processing)))
4669 ;;;_ > allout-yank-pop (&optional arg)
4670 (defun allout-yank-pop (&optional arg
)
4671 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4673 Adapts level of popped topics to level of fresh prefix.
4675 Note -- prefix changes to distinctive bullets will stick, if followed
4676 by pops to non-distinctive yanks. Bug..."
4679 (setq this-command
'yank
)
4682 (allout-yank-processing)))
4684 ;;;_ - Specialty bullet functions
4685 ;;;_ : File Cross references
4686 ;;;_ > allout-resolve-xref ()
4687 (defun allout-resolve-xref ()
4688 "Pop to file associated with current heading, if it has an xref bullet.
4690 \(Works according to setting of `allout-file-xref-bullet')."
4692 (if (not allout-file-xref-bullet
)
4694 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4695 (if (not (string= (allout-current-bullet) allout-file-xref-bullet
))
4696 (error "Current heading lacks cross-reference bullet `%s'"
4697 allout-file-xref-bullet
)
4698 (let ((inhibit-field-text-motion t
)
4702 (let* ((text-start allout-recent-prefix-end
)
4703 (heading-end (point-at-eol)))
4704 (goto-char text-start
)
4706 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
4707 (buffer-substring (match-beginning 1)
4709 (setq file-name
(expand-file-name file-name
))
4710 (if (or (file-exists-p file-name
)
4711 (if (file-writable-p file-name
)
4712 (y-or-n-p (format "%s not there, create one? "
4714 (error "%s not found and can't be created" file-name
)))
4715 (condition-case failure
4716 (find-file-other-window file-name
)
4718 (error "%s not found" file-name
))
4724 ;;;_ #6 Exposure Control
4727 ;;;_ > allout-flag-region (from to flag)
4728 (defun allout-flag-region (from to flag
)
4729 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4731 Exposure-change hook `allout-exposure-change-hook' is run with the same
4732 arguments as this function, after the exposure changes are made."
4734 ;; We use outline invisibility spec.
4735 (remove-overlays from to
'category
'allout-exposure-category
)
4737 (let ((o (make-overlay from to nil
'front-advance
)))
4738 (overlay-put o
'category
'allout-exposure-category
)
4739 (when (featurep 'xemacs
)
4740 (let ((props (symbol-plist 'allout-exposure-category
)))
4743 ;; as of 2008-02-27, xemacs lacks modification-hooks
4744 (overlay-put o
(pop props
) (pop props
))
4746 (run-hook-with-args 'allout-exposure-change-hook from to flag
))
4747 ;;;_ > allout-flag-current-subtree (flag)
4748 (defun allout-flag-current-subtree (flag)
4749 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4752 (allout-back-to-current-heading)
4753 (let ((inhibit-field-text-motion t
))
4755 (allout-flag-region (point)
4756 ;; Exposing must not leave trailing blanks hidden,
4757 ;; but can leave them exposed when hiding, so we
4758 ;; can use flag's inverse as the
4759 ;; include-trailing-blank cue:
4760 (allout-end-of-current-subtree (not flag
))
4763 ;;;_ - Topic-specific
4764 ;;;_ > allout-show-entry ()
4765 (defun allout-show-entry ()
4766 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4768 This is a way to give restricted peek at a concealed locality without the
4769 expense of exposing its context, but can leave the outline with aberrant
4770 exposure. `allout-show-offshoot' should be used after the peek to rectify
4776 (allout-goto-prefix-doublechecked)
4777 (setq beg
(if (allout-hidden-p) (1- (point)) (point)))
4778 (setq end
(allout-pre-next-prefix))
4779 (allout-flag-region beg end nil
)
4781 ;;;_ > allout-show-children (&optional level strict)
4782 (defun allout-show-children (&optional level strict
)
4784 "If point is visible, show all direct subheadings of this heading.
4786 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4788 Optional LEVEL specifies how many levels below the current level
4789 should be shown, or all levels if t. Default is 1.
4791 Optional STRICT means don't resort to -show-to-offshoot, no matter
4792 what. This is basically so -show-to-offshoot, which is called by
4793 this function, can employ the pure offspring-revealing capabilities of
4796 Returns point at end of subtree that was opened, if any. (May get a
4797 point of non-opened subtree?)"
4800 (let ((start-point (point)))
4801 (if (and (not strict
)
4804 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4806 ;; Then recurse, but with "strict" set so we don't
4807 ;; infinite regress:
4808 (allout-show-children level t
))
4811 (allout-beginning-of-current-line)
4814 ;; translate the level spec for this routine to the ones
4815 ;; used by -chart-subtree and -chart-to-reveal:
4816 (chart-level (cond ((not level
) 1)
4819 (chart (allout-chart-subtree chart-level
))
4820 (to-reveal (or (allout-chart-to-reveal chart chart-level
)
4821 ;; interactive, show discontinuous children:
4823 (allout-called-interactively-p)
4825 (allout-back-to-current-heading)
4826 (setq depth
(allout-current-depth))
4827 (and (allout-next-heading)
4828 (> allout-recent-depth
4831 "Discontinuous offspring; use `%s %s'%s."
4832 (substitute-command-keys
4833 "\\[universal-argument]")
4834 (substitute-command-keys
4835 "\\[allout-shift-out]")
4836 " to elevate them.")
4837 (allout-chart-to-reveal
4838 chart
(- allout-recent-depth depth
))))))
4839 (goto-char start-point
)
4840 (when (and strict
(allout-hidden-p))
4841 ;; Concealed root would already have been taken care of,
4842 ;; unless strict was set.
4843 (allout-flag-region (point) (allout-snug-back) nil
)
4844 (when allout-show-bodies
4845 (goto-char (car to-reveal
))
4846 (allout-show-current-entry)))
4848 (goto-char (car to-reveal
))
4849 (allout-flag-region (save-excursion (allout-snug-back) (point))
4850 (progn (search-forward "\n" nil t
)
4853 (when allout-show-bodies
4854 (goto-char (car to-reveal
))
4855 (allout-show-current-entry))
4856 (setq to-reveal
(cdr to-reveal
)))))))
4857 ;; Compensate for `save-excursion's maintenance of point
4858 ;; within invisible text:
4859 (goto-char start-point
)))
4860 ;;;_ > allout-show-to-offshoot ()
4861 (defun allout-show-to-offshoot ()
4862 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4864 Useful for coherently exposing to a random point in a hidden region."
4867 (let ((inhibit-field-text-motion t
)
4869 (orig-pref (allout-goto-prefix-doublechecked))
4872 (while (or (> bag-it
1) (allout-hidden-p))
4873 (while (allout-hidden-p)
4874 (move-beginning-of-line 1)
4875 (if (allout-hidden-p) (forward-char -
1)))
4876 (if (= last-at
(setq last-at
(point)))
4877 ;; Oops, we're not making any progress! Show the current topic
4878 ;; completely, and try one more time here, if we haven't already.
4879 (progn (beginning-of-line)
4880 (allout-show-current-subtree)
4882 (setq bag-it
(1+ bag-it
))
4884 (error "allout-show-to-offshoot: %s"
4885 "Stumped by aberrant nesting.")))
4886 (if (> bag-it
0) (setq bag-it
0))
4887 (allout-show-children)
4888 (goto-char orig-pref
)))
4889 (goto-char orig-pt
)))
4890 (if (allout-hidden-p)
4891 (allout-show-entry)))
4892 ;;;_ > allout-hide-current-entry ()
4893 (defun allout-hide-current-entry ()
4894 "Hide the body directly following this heading."
4896 (allout-back-to-current-heading)
4898 (let ((inhibit-field-text-motion t
))
4900 (allout-flag-region (point)
4901 (progn (allout-end-of-entry) (point))
4903 ;;;_ > allout-show-current-entry (&optional arg)
4904 (defun allout-show-current-entry (&optional arg
)
4905 "Show body following current heading, or hide entry with universal argument."
4909 (allout-hide-current-entry)
4910 (save-excursion (allout-show-to-offshoot))
4912 (allout-flag-region (point)
4913 (progn (allout-end-of-entry t
) (point))
4916 ;;;_ > allout-show-current-subtree (&optional arg)
4917 (defun allout-show-current-subtree (&optional arg
)
4918 "Show everything within the current topic.
4919 With a repeat-count, expose this topic and its siblings."
4922 (if (<= (allout-current-depth) 0)
4923 ;; Outside any topics -- try to get to the first:
4924 (if (not (allout-next-heading))
4926 ;; got to first, outermost topic -- set to expose it and siblings:
4927 (message "Above outermost topic -- exposing all.")
4928 (allout-flag-region (point-min)(point-max) nil
))
4929 (allout-beginning-of-current-line)
4931 (allout-flag-current-subtree nil
)
4932 (allout-beginning-of-level)
4933 (allout-expose-topic '(* :))))))
4934 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4935 (defun allout-current-topic-collapsed-p (&optional include-single-liners
)
4936 "True if the currently visible containing topic is already collapsed.
4938 Single line topics intrinsically can be considered as being both
4939 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
4940 true, then single-line topics are considered to be collapsed. By
4941 default, they are treated as being uncollapsed."
4945 ;; Is the topic all on one line (allowing for trailing blank line)?
4946 (>= (progn (allout-back-to-current-heading)
4947 (let ((inhibit-field-text-motion t
))
4948 (move-end-of-line 1))
4950 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
4952 (or include-single-liners
4953 (progn (backward-char 1) (allout-hidden-p)))))))
4954 ;;;_ > allout-hide-current-subtree (&optional just-close)
4955 (defun allout-hide-current-subtree (&optional just-close
)
4956 "Close the current topic, or containing topic if this one is already closed.
4958 If this topic is closed and it's a top level topic, close this topic
4961 If optional arg JUST-CLOSE is non-nil, do not close the parent or
4962 siblings, even if the target topic is already closed."
4965 (let* ((from (point))
4966 (sibs-msg "Top-level topic already closed -- closing siblings...")
4967 (current-exposed (not (allout-current-topic-collapsed-p t
))))
4968 (cond (current-exposed (allout-flag-current-subtree t
))
4970 ((allout-ascend) (allout-hide-current-subtree))
4973 (allout-goto-prefix-doublechecked)
4974 (allout-expose-topic '(0 :))
4975 (message (concat sibs-msg
" Done."))))
4977 ;;;_ > allout-toggle-current-subtree-exposure
4978 (defun allout-toggle-current-subtree-exposure ()
4979 "Show or hide the current subtree depending on its current state."
4980 ;; thanks to tassilo for suggesting this.
4983 (allout-back-to-heading)
4984 (if (allout-hidden-p (point-at-eol))
4985 (allout-show-current-subtree)
4986 (allout-hide-current-subtree))))
4987 ;;;_ > allout-show-current-branches ()
4988 (defun allout-show-current-branches ()
4989 "Show all subheadings of this heading, but not their bodies."
4991 (let ((inhibit-field-text-motion t
))
4992 (beginning-of-line))
4993 (allout-show-children t
))
4994 ;;;_ > allout-hide-current-leaves ()
4995 (defun allout-hide-current-leaves ()
4996 "Hide the bodies of the current topic and all its offspring."
4998 (allout-back-to-current-heading)
4999 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
5002 ;;;_ - Region and beyond
5003 ;;;_ > allout-show-all ()
5004 (defun allout-show-all ()
5005 "Show all of the text in the buffer."
5007 (message "Exposing entire buffer...")
5008 (allout-flag-region (point-min) (point-max) nil
)
5009 (message "Exposing entire buffer... Done."))
5010 ;;;_ > allout-hide-bodies ()
5011 (defun allout-hide-bodies ()
5012 "Hide all of buffer except headings."
5014 (allout-hide-region-body (point-min) (point-max)))
5015 ;;;_ > allout-hide-region-body (start end)
5016 (defun allout-hide-region-body (start end
)
5017 "Hide all body lines in the region, but not headings."
5021 (narrow-to-region start end
)
5022 (goto-char (point-min))
5023 (let ((inhibit-field-text-motion t
))
5026 (allout-flag-region (point) (allout-end-of-entry) t
)
5029 (if (looking-at "\n\n")
5032 ;;;_ > allout-expose-topic (spec)
5033 (defun allout-expose-topic (spec)
5034 "Apply exposure specs to successive outline topic items.
5036 Use the more convenient frontend, `allout-new-exposure', if you don't
5037 need evaluation of the arguments, or even better, the `allout-layout'
5038 variable-keyed mode-activation/auto-exposure feature of allout outline
5039 mode. See the respective documentation strings for more details.
5041 Cursor is left at start position.
5043 SPEC is either a number or a list.
5045 Successive specs on a list are applied to successive sibling topics.
5047 A simple spec (either a number, one of a few symbols, or the null
5048 list) dictates the exposure for the corresponding topic.
5050 Non-null lists recursively designate exposure specs for respective
5051 subtopics of the current topic.
5053 The `:' repeat spec is used to specify exposure for any number of
5054 successive siblings, up to the trailing ones for which there are
5055 explicit specs following the `:'.
5057 Simple (numeric and null-list) specs are interpreted as follows:
5059 Numbers indicate the relative depth to open the corresponding topic.
5060 - negative numbers force the topic to be closed before opening to the
5061 absolute value of the number, so all siblings are open only to
5063 - positive numbers open to the relative depth indicated by the
5064 number, but do not force already opened subtopics to be closed.
5065 - 0 means to close topic -- hide all offspring.
5067 apply prior element to all siblings at current level, *up to*
5068 those siblings that would be covered by specs following the `:'
5069 on the list. Ie, apply to all topics at level but the last
5070 ones. (Only first of multiple colons at same level is
5071 respected -- subsequent ones are discarded.)
5072 * - completely opens the topic, including bodies.
5073 + - shows all the sub headers, but not the bodies
5074 - - exposes the body of the corresponding topic.
5077 \(allout-expose-topic '(-1 : 0))
5078 Close this and all following topics at current level, exposing
5079 only their immediate children, but close down the last topic
5080 at this current level completely.
5081 \(allout-expose-topic '(-1 () : 1 0))
5082 Close current topic so only the immediate subtopics are shown;
5083 show the children in the second to last topic, and completely
5085 \(allout-expose-topic '(-2 : -1 *))
5086 Expose children and grandchildren of all topics at current
5087 level except the last two; expose children of the second to
5088 last and completely open the last one."
5090 (interactive "xExposure spec: ")
5091 (if (not (listp spec
))
5093 (let ((depth (allout-depth))
5098 (setq prev-elem curr-elem
5099 curr-elem
(car spec
)
5101 (cond ; Do current element:
5102 ((null curr-elem
) nil
)
5103 ((symbolp curr-elem
)
5104 (cond ((eq curr-elem
'*) (allout-show-current-subtree)
5105 (if (> allout-recent-end-of-subtree max-pos
)
5106 (setq max-pos allout-recent-end-of-subtree
)))
5108 (if (not (allout-hidden-p))
5109 (save-excursion (allout-hide-current-subtree t
)))
5110 (allout-show-current-branches)
5111 (if (> allout-recent-end-of-subtree max-pos
)
5112 (setq max-pos allout-recent-end-of-subtree
)))
5113 ((eq curr-elem
'-
) (allout-show-current-entry))
5116 ;; Expand the `repeat' spec to an explicit version,
5117 ;; w.r.t. remaining siblings:
5118 (let ((residue ; = # of sibs not covered by remaining spec
5119 ;; Dang, could be nice to make use of the chart, sigh:
5120 (- (length (allout-chart-siblings))
5123 ;; Some residue -- cover it with prev-elem:
5124 (setq spec
(append (make-list residue prev-elem
)
5126 ((numberp curr-elem
)
5127 (if (and (>= 0 curr-elem
) (not (allout-hidden-p)))
5128 (save-excursion (allout-hide-current-subtree t
)
5131 (if (> allout-recent-end-of-subtree max-pos
)
5133 allout-recent-end-of-subtree
)))))
5134 (if (> (abs curr-elem
) 0)
5135 (progn (allout-show-children (abs curr-elem
))
5136 (if (> allout-recent-end-of-subtree max-pos
)
5137 (setq max-pos allout-recent-end-of-subtree
)))))
5139 (if (allout-descend-to-depth (1+ depth
))
5140 (let ((got (allout-expose-topic curr-elem
)))
5141 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
5142 (cond (stay (setq stay nil
))
5143 ((listp (car spec
)) nil
)
5144 ((> max-pos
(point))
5145 ;; Capitalize on max-pos state to get us nearer next sibling:
5146 (progn (goto-char (min (point-max) max-pos
))
5147 (allout-next-heading)))
5148 ((allout-next-sibling depth
))))
5150 ;;;_ > allout-old-expose-topic (spec &rest followers)
5151 (defun allout-old-expose-topic (spec &rest followers
)
5153 "Deprecated. Use `allout-expose-topic' (with different schema
5156 Dictate wholesale exposure scheme for current topic, according to SPEC.
5158 SPEC is either a number or a list. Optional successive args
5159 dictate exposure for subsequent siblings of current topic.
5161 A simple spec (either a number, a special symbol, or the null list)
5162 dictates the overall exposure for a topic. Non null lists are
5163 composite specs whose first element dictates the overall exposure for
5164 a topic, with the subsequent elements in the list interpreted as specs
5165 that dictate the exposure for the successive offspring of the topic.
5167 Simple (numeric and null-list) specs are interpreted as follows:
5169 - Numbers indicate the relative depth to open the corresponding topic:
5170 - negative numbers force the topic to be close before opening to the
5171 absolute value of the number.
5172 - positive numbers just open to the relative depth indicated by the number.
5174 - `*' completely opens the topic, including bodies.
5175 - `+' shows all the sub headers, but not the bodies
5176 - `-' exposes the body and immediate offspring of the corresponding topic.
5178 If the spec is a list, the first element must be a number, which
5179 dictates the exposure depth of the topic as a whole. Subsequent
5180 elements of the list are nested SPECs, dictating the specific exposure
5181 for the corresponding offspring of the topic.
5183 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5185 (interactive "xExposure spec: ")
5186 (let ((inhibit-field-text-motion t
)
5187 (depth (allout-current-depth))
5189 (cond ((null spec
) nil
)
5191 (if (eq spec
'*) (allout-show-current-subtree))
5192 (if (eq spec
'+) (allout-show-current-branches))
5193 (if (eq spec
'-
) (allout-show-current-entry)))
5196 (save-excursion (allout-hide-current-subtree t
)
5198 (if (or (not max-pos
)
5199 (> (point) max-pos
))
5200 (setq max-pos
(point)))
5202 (setq spec
(* -
1 spec
)))))
5204 (allout-show-children spec
)))
5206 ;(let ((got (allout-old-expose-topic (car spec))))
5207 ; (if (and got (or (not max-pos) (> got max-pos)))
5208 ; (setq max-pos got)))
5209 (let ((new-depth (+ (allout-current-depth) 1))
5211 (setq max-pos
(allout-old-expose-topic (car spec
)))
5212 (setq spec
(cdr spec
))
5214 (allout-descend-to-depth new-depth
)
5215 (not (allout-hidden-p)))
5216 (progn (setq got
(apply 'allout-old-expose-topic spec
))
5217 (if (and got
(or (not max-pos
) (> got max-pos
)))
5218 (setq max-pos got
)))))))
5219 (while (and followers
5220 (progn (if (and max-pos
(< (point) max-pos
))
5221 (progn (goto-char max-pos
)
5222 (setq max-pos nil
)))
5224 (allout-next-sibling depth
)))
5225 (allout-old-expose-topic (car followers
))
5226 (setq followers
(cdr followers
)))
5228 ;;;_ > allout-new-exposure '()
5229 (defmacro allout-new-exposure
(&rest spec
)
5230 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5231 Some arguments that would need to be quoted in `allout-expose-topic'
5232 need not be quoted in `allout-new-exposure'.
5234 Cursor is left at start position.
5236 Use this instead of obsolete `allout-exposure'.
5239 \(allout-new-exposure (-1 () () () 1) 0)
5240 Close current topic at current level so only the immediate
5241 subtopics are shown, except also show the children of the
5242 third subtopic; and close the next topic at the current level.
5243 \(allout-new-exposure : -1 0)
5244 Close all topics at current level to expose only their
5245 immediate children, except for the last topic at the current
5246 level, in which even its immediate children are hidden.
5247 \(allout-new-exposure -2 : -1 *)
5248 Expose children and grandchildren of first topic at current
5249 level, and expose children of subsequent topics at current
5250 level *except* for the last, which should be opened completely."
5251 (list 'save-excursion
5252 '(if (not (or (allout-goto-prefix-doublechecked)
5253 (allout-next-heading)))
5254 (error "allout-new-exposure: Can't find any outline topics"))
5255 (list 'allout-expose-topic
(list 'quote spec
))))
5257 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5259 ;;;_ - Mapping and processing of topics
5260 ;;;_ ( See also Subtree Charting, in Navigation code.)
5261 ;;;_ > allout-stringify-flat-index (flat-index)
5262 (defun allout-stringify-flat-index (flat-index &optional context
)
5263 "Convert list representing section/subsection/... to document string.
5265 Optional arg CONTEXT indicates interior levels to include."
5269 (context-depth (or (and context
2) 1)))
5270 ;; Take care of the explicit context:
5271 (while (> context-depth
0)
5272 (setq numstr
(int-to-string (car flat-index
))
5273 flat-index
(cdr flat-index
)
5274 result
(if flat-index
5275 (cons delim
(cons numstr result
))
5276 (cons numstr result
))
5277 context-depth
(if flat-index
(1- context-depth
) 0)))
5279 ;; Take care of the indentation:
5286 (1+ (truncate (if (zerop (car flat-index
))
5288 (log10 (car flat-index
)))))
5291 (setq flat-index
(cdr flat-index
)))
5292 ;; Dispose of single extra delim:
5293 (setq result
(cdr result
))))
5294 (apply 'concat result
)))
5295 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5296 (defun allout-stringify-flat-index-plain (flat-index)
5297 "Convert list representing section/subsection/... to document string."
5301 (setq result
(cons (int-to-string (car flat-index
))
5303 (cons delim result
))))
5304 (setq flat-index
(cdr flat-index
)))
5305 (apply 'concat result
)))
5306 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5307 (defun allout-stringify-flat-index-indented (flat-index)
5308 "Convert list representing section/subsection/... to document string."
5312 ;; Take care of the explicit context:
5313 (setq numstr
(int-to-string (car flat-index
))
5314 flat-index
(cdr flat-index
)
5315 result
(if flat-index
5316 (cons delim
(cons numstr result
))
5317 (cons numstr result
)))
5319 ;; Take care of the indentation:
5326 (1+ (truncate (if (zerop (car flat-index
))
5328 (log10 (car flat-index
)))))
5331 (setq flat-index
(cdr flat-index
)))
5332 ;; Dispose of single extra delim:
5333 (setq result
(cdr result
))))
5334 (apply 'concat result
)))
5335 ;;;_ > allout-listify-exposed (&optional start end format)
5336 (defun allout-listify-exposed (&optional start end format
)
5338 "Produce a list representing exposed topics in current region.
5340 This list can then be used by `allout-process-exposed' to manipulate
5343 Optional START and END indicate bounds of region.
5345 Optional arg, FORMAT, designates an alternate presentation form for
5348 list -- Present prefix as numeric section.subsection..., starting with
5349 section indicated by the list, innermost nesting first.
5350 `indent' (symbol) -- Convert header prefixes to all white space,
5351 except for distinctive bullets.
5353 The elements of the list produced are lists that represents a topic
5354 header and body. The elements of that list are:
5356 - a number representing the depth of the topic,
5357 - a string representing the header-prefix, including trailing whitespace and
5359 - a string representing the bullet character,
5360 - and a series of strings, each containing one line of the exposed
5361 portion of the topic entry."
5366 ((inhibit-field-text-motion t
)
5368 strings prefix result depth new-depth out gone-out bullet beg
5373 ;; Goto initial topic, and register preceding stuff, if any:
5374 (if (> (allout-goto-prefix-doublechecked) start
)
5375 ;; First topic follows beginning point -- register preliminary stuff:
5377 (list (list 0 "" nil
5378 (buffer-substring-no-properties start
5380 (while (and (not done
)
5381 (not (eobp)) ; Loop until we've covered the region.
5382 (not (> (point) end
)))
5383 (setq depth allout-recent-depth
; Current topics depth,
5384 bullet
(allout-recent-bullet) ; ... bullet,
5385 prefix
(allout-recent-prefix)
5386 beg
(progn (allout-end-of-prefix t
) (point))) ; and beginning.
5387 (setq done
; The boundary for the current topic:
5388 (not (allout-next-visible-heading 1)))
5389 (setq new-depth allout-recent-depth
)
5391 out
(< new-depth depth
))
5396 (while (> next
(point)) ; Get all the exposed text in
5398 (cons (buffer-substring-no-properties
5400 ;To hidden text or end of line:
5403 (allout-back-to-visible-text)))
5405 (when (< (point) next
) ; Resume from after hid text, if any.
5407 (beginning-of-line))
5409 ;; Accumulate list for this topic:
5410 (setq strings
(nreverse strings
))
5414 (let ((special (if (string-match
5415 (regexp-quote bullet
)
5416 allout-distinctive-bullets-string
)
5418 (cond ((listp format
)
5420 (if allout-flattened-numbering-abbreviation
5421 (allout-stringify-flat-index format
5423 (allout-stringify-flat-index-plain
5427 ((eq format
'indent
)
5430 (concat (make-string (1+ depth
) ?
)
5431 (substring prefix -
1))
5434 (make-string depth ?
)
5436 (t (error "allout-listify-exposed: %s %s"
5437 "invalid format" format
))))
5438 (list depth prefix strings
))
5440 ;; Reasses format, if any:
5441 (if (and format
(listp format
))
5442 (cond ((= new-depth depth
)
5443 (setq format
(cons (1+ (car format
))
5445 ((> new-depth depth
) ; descending -- assume by 1:
5446 (setq format
(cons 1 format
)))
5449 (while (< new-depth depth
)
5450 (setq format
(cdr format
))
5451 (setq depth
(1- depth
)))
5452 ; And increment the current one:
5454 (cons (1+ (or (car format
)
5457 ;; Put the list with first at front, to last at back:
5458 (nreverse result
))))
5459 ;;;_ > allout-region-active-p ()
5460 (defmacro allout-region-active-p
()
5461 (cond ((fboundp 'use-region-p
) '(use-region-p))
5462 ((fboundp 'region-active-p
) '(region-active-p))
5464 ;;_ > allout-process-exposed (&optional func from to frombuf
5466 (defun allout-process-exposed (&optional func from to frombuf tobuf
5468 "Map function on exposed parts of current topic; results to another buffer.
5470 All args are options; default values itemized below.
5472 Apply FUNCTION to exposed portions FROM position TO position in buffer
5473 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5474 alternate presentation form:
5476 `flat' -- Present prefix as numeric section.subsection..., starting with
5477 section indicated by the START-NUM, innermost nesting first.
5478 X`flat-indented' -- Prefix is like `flat' for first topic at each
5479 X level, but subsequent topics have only leaf topic
5480 X number, padded with blanks to line up with first.
5481 `indent' (symbol) -- Convert header prefixes to all white space,
5482 except for distinctive bullets.
5485 FUNCTION: `allout-insert-listified'
5486 FROM: region start, if region active, else start of buffer
5487 TO: region end, if region active, else end of buffer
5488 FROMBUF: current buffer
5489 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5492 ; Resolve arguments,
5493 ; defaulting if necessary:
5494 (if (not func
) (setq func
'allout-insert-listified
))
5495 (if (not (and from to
))
5496 (if (allout-region-active-p)
5497 (setq from
(region-beginning) to
(region-end))
5498 (setq from
(point-min) to
(point-max))))
5500 (if (not (bufferp frombuf
))
5501 ;; Specified but not a buffer -- get it:
5502 (let ((got (get-buffer frombuf
)))
5504 (error (concat "allout-process-exposed: source buffer "
5507 (setq frombuf got
))))
5508 ;; not specified -- default it:
5509 (setq frombuf
(current-buffer)))
5511 (if (not (bufferp tobuf
))
5512 (setq tobuf
(get-buffer-create tobuf
)))
5513 ;; not specified -- default it:
5514 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
5519 (progn (set-buffer frombuf
)
5520 (allout-listify-exposed from to format
))))
5522 (mapc func listified
)
5523 (pop-to-buffer tobuf
)))
5526 ;;;_ > allout-insert-listified (listified)
5527 (defun allout-insert-listified (listified)
5528 "Insert contents of listified outline portion in current buffer.
5530 LISTIFIED is a list representing each topic header and body:
5532 \`(depth prefix text)'
5534 or \`(depth prefix text bullet-plus)'
5536 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5537 (setq listified
(cdr listified
))
5538 (let ((prefix (prog1
5540 (setq listified
(cdr listified
))))
5543 (setq listified
(cdr listified
))))
5544 (bullet-plus (car listified
)))
5546 (if bullet-plus
(insert (concat " " bullet-plus
)))
5549 (if (setq text
(cdr text
))
5552 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5553 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format
)
5554 "Duplicate exposed portions of current outline to another buffer.
5556 Other buffer has current buffers name with \" exposed\" appended to it.
5558 With repeat count, copy the exposed parts of only the current topic.
5560 Optional second arg TOBUF is target buffer name.
5562 Optional third arg FORMAT, if non-nil, symbolically designates an
5563 alternate presentation format for the outline:
5565 `flat' - Convert topic header prefixes to numeric
5566 section.subsection... identifiers.
5567 `indent' - Convert header prefixes to all white space, except for
5568 distinctive bullets.
5569 `indent-flat' - The best of both - only the first of each level has
5570 the full path, the rest have only the section number
5571 of the leaf, preceded by the right amount of indentation."
5575 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5576 (let* ((start-pt (point))
5577 (beg (if arg
(allout-back-to-current-heading) (point-min)))
5578 (end (if arg
(allout-end-of-current-subtree) (point-max)))
5579 (buf (current-buffer))
5581 (if (eq format
'flat
)
5582 (setq format
(if arg
(save-excursion
5584 (allout-topic-flat-index))
5586 (with-current-buffer tobuf
(erase-buffer))
5587 (allout-process-exposed 'allout-insert-listified
5593 (goto-char (point-min))
5595 (goto-char start-pt
)))
5596 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5597 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf
)
5598 "Present numeric outline of outline's exposed portions in another buffer.
5600 The resulting outline is not compatible with outline mode -- use
5601 `allout-copy-exposed-to-buffer' if you want that.
5603 Use `allout-indented-exposed-to-buffer' for indented presentation.
5605 With repeat count, copy the exposed portions of only current topic.
5607 Other buffer has current buffer's name with \" exposed\" appended to
5608 it, unless optional second arg TOBUF is specified, in which case it is
5611 (allout-copy-exposed-to-buffer arg tobuf
'flat
))
5612 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5613 (defun allout-indented-exposed-to-buffer (&optional arg tobuf
)
5614 "Present indented outline of outline's exposed portions in another buffer.
5616 The resulting outline is not compatible with outline mode -- use
5617 `allout-copy-exposed-to-buffer' if you want that.
5619 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5621 With repeat count, copy the exposed portions of only current topic.
5623 Other buffer has current buffer's name with \" exposed\" appended to
5624 it, unless optional second arg TOBUF is specified, in which case it is
5627 (allout-copy-exposed-to-buffer arg tobuf
'indent
))
5629 ;;;_ - LaTeX formatting
5630 ;;;_ > allout-latex-verb-quote (string &optional flow)
5631 (defun allout-latex-verb-quote (string &optional flow
)
5632 "Return copy of STRING for literal reproduction across LaTeX processing.
5633 Expresses the original characters (including carriage returns) of the
5634 string across LaTeX processing."
5635 (mapconcat (function
5637 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
5638 (concat "\\char" (number-to-string char
) "{}"))
5639 ((= char ?
\n) "\\\\")
5640 (t (char-to-string char
)))))
5643 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5644 (defun allout-latex-verbatim-quote-curr-line ()
5645 "Express line for exact (literal) representation across LaTeX processing.
5647 Adjust line contents so it is unaltered (from the original line)
5648 across LaTeX processing, within the context of a `verbatim'
5649 environment. Leaves point at the end of the line."
5650 (let ((inhibit-field-text-motion t
))
5653 (end (point-at-eol)))
5655 (while (re-search-forward "\\\\"
5656 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5657 end
; bounded by end-of-line
5658 1) ; no matches, move to end & return nil
5659 (goto-char (match-beginning 2))
5662 (goto-char (1+ (match-end 2))))))))
5663 ;;;_ > allout-insert-latex-header (buffer)
5664 (defun allout-insert-latex-header (buffer)
5665 "Insert initial LaTeX commands at point in BUFFER."
5666 ;; Much of this is being derived from the stuff in appendix of E in
5667 ;; the TeXBook, pg 421.
5669 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5671 (page-numbering (if allout-number-pages
5672 "\\pagestyle{empty}\n"
5674 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5675 allout-title-style
))
5676 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5677 allout-label-style
))
5678 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5679 allout-head-line-style
))
5680 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5681 allout-body-line-style
))
5682 (setlength (format "%s%s%s%s"
5683 "\\newlength{\\stepsize}\n"
5684 "\\setlength{\\stepsize}{"
5687 (oneheadline (format "%s%s%s%s%s%s%s"
5688 "\\newcommand{\\OneHeadLine}[3]{%\n"
5690 "\\hspace*{#2\\stepsize}%\n"
5691 "\\labelcmd{#1}\\hspace*{.2cm}"
5692 "\\headlinecmd{#3}\\\\["
5695 (onebodyline (format "%s%s%s%s%s%s"
5696 "\\newcommand{\\OneBodyLine}[2]{%\n"
5698 "\\hspace*{#1\\stepsize}%\n"
5699 "\\bodylinecmd{#2}\\\\["
5702 (begindoc "\\begin{document}\n\\begin{center}\n")
5703 (title (format "%s%s%s%s"
5705 (allout-latex-verb-quote (if allout-title
5708 (error "<unnamed buffer>"))
5711 "\\end{center}\n\n"))
5712 (hsize "\\hsize = 7.5 true in\n")
5713 (hoffset "\\hoffset = -1.5 true in\n")
5714 (vspace "\\vspace{.1cm}\n\n"))
5715 (insert (concat doc-style
5730 ;;;_ > allout-insert-latex-trailer (buffer)
5731 (defun allout-insert-latex-trailer (buffer)
5732 "Insert concluding LaTeX commands at point in BUFFER."
5734 (insert "\n\\end{document}\n"))
5735 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5736 (defun allout-latexify-one-item (depth prefix bullet text
)
5737 "Insert LaTeX commands for formatting one outline item.
5739 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5740 BULLET string, and a list of TEXT strings for the body."
5741 (let* ((head-line (if text
(car text
)))
5742 (body-lines (cdr text
))
5746 (insert (concat "\\OneHeadLine{\\verb\1 "
5747 (allout-latex-verb-quote bullet
)
5752 (allout-latex-verb-quote head-line
)
5755 (if (not body-lines
)
5757 ;;(insert "\\beginlines\n")
5758 (insert "\\begin{verbatim}\n")
5760 (setq curr-line
(car body-lines
))
5761 (if (and (not body-content
)
5762 (not (string-match "^\\s-*$" curr-line
)))
5763 (setq body-content t
))
5764 ; Mangle any occurrences of
5765 ; "\end{verbatim}" in text,
5767 (if (and body-content
5768 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
5769 (setq curr-line
(concat (substring curr-line
0 bop
)
5771 (substring curr-line bop
))))
5772 ;;(insert "|" (car body-lines) "|")
5774 (allout-latex-verbatim-quote-curr-line)
5776 (setq body-lines
(cdr body-lines
)))
5778 (setq body-content nil
)
5782 ;;(insert "\\endlines\n")
5783 (insert "\\end{verbatim}\n")
5785 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5786 (defun allout-latexify-exposed (arg &optional tobuf
)
5787 "Format current topics exposed portions to TOBUF for LaTeX processing.
5788 TOBUF defaults to a buffer named the same as the current buffer, but
5789 with \"*\" prepended and \" latex-formed*\" appended.
5791 With repeat count, copy the exposed portions of entire buffer."
5796 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5797 (let* ((start-pt (point))
5798 (beg (if arg
(point-min) (allout-back-to-current-heading)))
5799 (end (if arg
(point-max) (allout-end-of-current-subtree)))
5800 (buf (current-buffer)))
5803 (allout-insert-latex-header tobuf
)
5804 (goto-char (point-max))
5805 (allout-process-exposed 'allout-latexify-one-item
5810 (goto-char (point-max))
5811 (allout-insert-latex-trailer tobuf
)
5812 (goto-char (point-min))
5814 (goto-char start-pt
)))
5817 ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue)
5818 (defun allout-toggle-current-subtree-encryption (&optional keymode-cue
)
5819 "Encrypt clear or decrypt encoded topic text.
5821 Allout uses emacs 'epg' libary to perform encryption. Symmetric
5822 and keypair encryption are supported. All encryption is ascii
5825 Entry encryption defaults to symmetric key mode unless keypair
5826 recipients are associated with the file \(see
5827 `epa-file-encrypt-to') or the function is invoked with a
5828 \(KEYMODE-CUE) universal argument greater than 1.
5830 When encrypting, KEYMODE-CUE universal argument greater than 1
5831 causes prompting for recipients for public-key keypair
5832 encryption. Selecting no recipients results in symmetric key
5835 Further, encrypting with a KEYMODE-CUE universal argument greater
5836 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5837 the specified recipients with the file, replacing those currently
5838 associated with it. This can be used to deassociate any
5839 recipients with the file, by selecting no recipients in the
5842 Encrypted topic's bullets are set to a `~' to signal that the
5843 contents of the topic (body and subtopics, but not heading) is
5844 pending encryption or encrypted. `*' asterisk immediately after
5845 the bullet signals that the body is encrypted, its absence means
5846 the topic is meant to be encrypted but is not currently. When a
5847 file with topics pending encryption is saved, topics pending
5848 encryption are encrypted. See allout-encrypt-unencrypted-on-saves
5849 for auto-encryption specifics.
5851 \*NOTE WELL* that automatic encryption that happens during saves will
5852 default to symmetric encryption -- you must deliberately (re)encrypt key-pair
5853 encrypted topics if you want them to continue to use the key-pair cipher.
5855 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5856 encrypted. If you want to encrypt the contents of a top-level topic, use
5857 \\[allout-shift-in] to increase its depth."
5860 (allout-back-to-current-heading)
5861 (allout-toggle-subtree-encryption keymode-cue
)))
5862 ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue)
5863 (defun allout-toggle-subtree-encryption (&optional keymode-cue
)
5864 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5866 Entry encryption defaults to symmetric key mode unless keypair
5867 recipients are associated with the file \(see
5868 `epa-file-encrypt-to') or the function is invoked with a
5869 \(KEYMODE-CUE) universal argument greater than 1.
5871 When encrypting, KEYMODE-CUE universal argument greater than 1
5872 causes prompting for recipients for public-key keypair
5873 encryption. Selecting no recipients results in symmetric key
5876 Further, encrypting with a KEYMODE-CUE universal argument greater
5877 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5878 the specified recipients with the file, replacing those currently
5879 associated with it. This can be used to deassociate any
5880 recipients with the file, by selecting no recipients in the
5883 Encryption and decryption uses the emacs epg library.
5885 Encrypted text will be ascii-armored.
5887 See `allout-toggle-current-subtree-encryption' for more details."
5891 (allout-end-of-prefix t
)
5893 (if (= allout-recent-depth
1)
5894 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5895 " shift it in to make it encryptable")))
5897 (let* ((allout-buffer (current-buffer))
5899 (bullet-pos allout-recent-prefix-beginning
)
5900 (after-bullet-pos (point))
5902 (progn (if (= (point-max) after-bullet-pos
)
5903 (error "no body to encrypt"))
5904 (allout-encrypted-topic-p)))
5905 (was-collapsed (if (not (search-forward "\n" nil t
))
5909 (subtree-beg (1+ (point)))
5910 (subtree-end (allout-end-of-subtree))
5911 (subject-text (buffer-substring-no-properties subtree-beg
5913 (subtree-end-char (char-after (1- subtree-end
)))
5914 (subtree-trailing-char (char-after subtree-end
))
5915 ;; kluge -- result-text needs to be nil, but we also want to
5916 ;; check for the error condition
5917 (result-text (if (or (string= "" subject-text
)
5918 (string= "\n" subject-text
))
5919 (error "No topic contents to %scrypt"
5920 (if was-encrypted
"de" "en"))
5922 ;; Assess key parameters:
5923 (was-coding-system buffer-file-coding-system
))
5925 (when (not was-encrypted
)
5926 ;; ensure that non-ascii chars pending encryption are noticed before
5927 ;; they're encrypted, so the coding system is set to accommodate
5929 (setq buffer-file-coding-system
5930 (allout-select-safe-coding-system subtree-beg subtree-end
))
5931 ;; if the coding system for the text being encrypted is different
5932 ;; than that prevailing, then there a real risk that the coding
5933 ;; system can't be noticed by emacs when the file is visited. to
5934 ;; mitigate that, offer to preserve the coding system using a file
5936 (if (and (not (equal buffer-file-coding-system
5939 (format (concat "Register coding system %s as file local"
5940 " var? Necessary when only encrypted text"
5941 " is in that coding system. ")
5942 buffer-file-coding-system
)))
5943 (allout-adjust-file-variable "buffer-file-coding-system"
5944 buffer-file-coding-system
)))
5947 (allout-encrypt-string subject-text was-encrypted
5948 (current-buffer) keymode-cue
))
5950 ;; Replace the subtree with the processed product.
5953 (set-buffer allout-buffer
)
5954 (delete-region subtree-beg subtree-end
)
5955 (insert result-text
)
5957 (allout-flag-region (1- subtree-beg
) (point) t
))
5958 ;; adjust trailing-blank-lines to preserve topic spacing:
5959 (if (not was-encrypted
)
5960 (if (and (= subtree-end-char ?
\n)
5961 (= subtree-trailing-char ?
\n))
5962 (insert subtree-trailing-char
)))
5963 ;; Ensure that the item has an encrypted-entry bullet:
5964 (if (not (string= (buffer-substring-no-properties
5965 (1- after-bullet-pos
) after-bullet-pos
)
5966 allout-topic-encryption-bullet
))
5967 (progn (goto-char (1- after-bullet-pos
))
5969 (insert allout-topic-encryption-bullet
)))
5971 ;; Remove the is-encrypted bullet qualifier:
5972 (progn (goto-char after-bullet-pos
)
5974 ;; Add the is-encrypted bullet qualifier:
5975 (goto-char after-bullet-pos
)
5977 (run-hook-with-args 'allout-structure-added-hook
5978 bullet-pos subtree-end
))))
5979 ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
5980 ;;; &optional rejected)
5981 (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue
5983 "Encrypt or decrypt message TEXT.
5985 Returns the resulting string, or nil if the transformation fails.
5987 If DECRYPT is true (default false), then decrypt instead of encrypt.
5989 ALLOUT-BUFFER identifies the buffer containing the text.
5991 Entry encryption defaults to symmetric key mode unless keypair
5992 recipients are associated with the file \(see
5993 `epa-file-encrypt-to') or the function is invoked with a
5994 \(KEYMODE-CUE) universal argument greater than 1.
5996 When encrypting, KEYMODE-CUE universal argument greater than 1
5997 causes prompting for recipients for public-key keypair
5998 encryption. Selecting no recipients results in symmetric key
6001 Further, encrypting with a KEYMODE-CUE universal argument greater
6002 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
6003 the specified recipients with the file, replacing those currently
6004 associated with it. This can be used to deassociate any
6005 recipients with the file, by selecting no recipients in the
6008 Optional REJECTED is for internal use, to convey the number of
6009 rejections due to matches against
6010 `allout-encryption-ciphertext-rejection-regexps', as limited by
6011 `allout-encryption-ciphertext-rejection-ceiling'.
6013 NOTE: A few GnuPG v2 versions improperly preserve incorrect
6014 symmetric decryption keys, preventing entry of the correct key on
6015 subsequent decryption attempts until the cache times-out. That
6016 can take several minutes. \(Decryption of other entries is not
6017 affected.) Upgrade your EasyPG version, if you can, and you can
6018 deliberately clear your gpg-agent's cache by sending it a '-HUP'
6024 (let* ((epg-context (let* ((context (epg-make-context nil t
)))
6025 (epg-context-set-passphrase-callback
6026 context
#'epa-passphrase-callback-function
)
6028 (encoding (with-current-buffer allout-buffer
6029 buffer-file-coding-system
))
6030 (multibyte (with-current-buffer allout-buffer
6031 enable-multibyte-characters
))
6032 ;; "sanitization" avoids encryption results that are outline structure.
6033 (sani-regexps 'allout-encryption-plaintext-sanitization-regexps
)
6034 (strip-plaintext-regexps (if (not decrypt
)
6035 (allout-get-configvar-values
6037 (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps
)
6038 (reject-ciphertext-regexps (if (not decrypt
)
6039 (allout-get-configvar-values
6040 rejection-regexps
)))
6041 (rejected (or rejected
0))
6042 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6044 (keypair-mode (cond (decrypt 'decrypting
)
6045 ((<= (prefix-numeric-value keymode-cue
) 1)
6047 ((<= (prefix-numeric-value keymode-cue
) 4)
6049 ((> (prefix-numeric-value keymode-cue
) 4)
6051 (keypair-message (concat "Select encryption recipients.\n"
6052 "Symmetric encryption is done if no"
6053 " recipients are selected. "))
6054 (encrypt-to (and (boundp 'epa-file-encrypt-to
) epa-file-encrypt-to
))
6060 ;; Massage the subject text for encoding and filtering.
6063 ;; convey the text characteristics of the original buffer:
6064 (set-buffer-multibyte multibyte
)
6066 (set-buffer-file-coding-system encoding
)
6068 (encode-coding-region (point-min) (point-max) encoding
)))
6070 ;; remove sanitization regexps matches before encrypting:
6071 (when (and strip-plaintext-regexps
(not decrypt
))
6072 (dolist (re strip-plaintext-regexps
)
6073 (let ((re (if (listp re
) (car re
) re
))
6074 (replacement (if (listp re
) (cadr re
) "")))
6075 (goto-char (point-min))
6077 (while (re-search-forward re nil t
)
6078 (replace-match replacement nil nil
))))))
6079 (setq massaged-text
(buffer-substring-no-properties (point-min)
6081 ;; determine key mode and, if keypair, recipients:
6087 (default (if encrypt-to
(epg-list-keys epg-context encrypt-to
)))
6089 ((prompt prompt-save
)
6090 (save-window-excursion
6091 (epa-select-keys epg-context keypair-message
)))))
6096 (epg-decrypt-string epg-context
6097 (encode-coding-string massaged-text
6098 (or encoding
'utf-8
)))
6101 (cons (concat (cadr err
) " - gpg version problem?")
6103 (replace-regexp-in-string "\n$" ""
6104 (epg-encrypt-string epg-context
6105 (encode-coding-string massaged-text
6106 (or encoding
'utf-8
))
6109 ;; validate result -- non-empty
6110 (if (not result-text
)
6111 (error "%scryption failed." (if decrypt
"De" "En")))
6114 (when (eq keypair-mode
'prompt-save
)
6115 ;; set epa-file-encrypt-to in the buffer:
6116 (setq epa-file-encrypt-to
(mapcar (lambda (key)
6118 (car (epg-key-user-id-list key
))))
6120 ;; change the file variable:
6121 (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to
))
6124 ;; Retry (within limit) if ciphertext contains rejections:
6126 ;; Check for disqualification of this ciphertext:
6127 (let ((regexps reject-ciphertext-regexps
)
6129 (while (and regexps
(not reject-it
))
6130 (setq reject-it
(string-match (car regexps
) result-text
))
6133 (setq rejections-left
(1- rejections-left
))
6134 (if (<= rejections-left
0)
6135 (error (concat "Ciphertext rejected too many times"
6137 allout-encryption-ciphertext-rejection-ceiling
6138 'allout-encryption-ciphertext-rejection-regexps
)
6139 ;; try again (gpg-agent may have the key cached):
6140 (allout-encrypt-string text decrypt allout-buffer keypair-mode
6143 ;; Barf if encryption yields extraordinary control chars:
6145 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6147 (error (concat "Encryption produced non-armored text, which"
6148 "conflicts with allout mode -- reconfigure!")))
6151 ;;;_ > allout-encrypted-topic-p ()
6152 (defun allout-encrypted-topic-p ()
6153 "True if the current topic is encryptable and encrypted."
6155 (allout-end-of-prefix t
)
6156 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6157 allout-topic-encryption-bullet
)
6158 (save-match-data (looking-at "\\*")))
6161 ;;;_ > allout-next-topic-pending-encryption (&optional except-mark)
6162 (defun allout-next-topic-pending-encryption (&optional except-mark
)
6163 "Return the point of the next topic pending encryption, or nil if none.
6165 EXCEPT-MARK identifies a point whose containing topics should be excluded
6166 from encryption. This supports 'except-current mode of
6167 `allout-encrypt-unencrypted-on-saves'.
6169 Such a topic has the `allout-topic-encryption-bullet' without an
6170 immediately following '*' that would mark the topic as being encrypted. It
6171 must also have content."
6172 (let (done got content-beg
)
6176 (if (not (re-search-forward
6177 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6178 (regexp-quote allout-header-prefix
)
6179 (regexp-quote allout-topic-encryption-bullet
))
6183 (goto-char (setq got
(match-beginning 0)))
6184 (if (save-match-data (looking-at "\n"))
6191 ((not (search-forward "\n"))
6200 (setq content-beg
(point))
6202 (allout-end-of-subtree)
6203 (if (or (<= (point) content-beg
)
6205 (<= content-beg except-mark
)
6206 (>= (point) except-mark
)))
6218 ;;;_ > allout-encrypt-decrypted (&optional except-mark)
6219 (defun allout-encrypt-decrypted (&optional except-mark
)
6220 "Encrypt topics pending encryption except those containing exemption point.
6222 EXCEPT-MARK identifies a point whose containing topics should be excluded
6223 from encryption. This supports the `except-current' mode of
6224 `allout-encrypt-unencrypted-on-saves'.
6226 If a topic that is currently being edited was encrypted, we return a list
6227 containing the location of the topic and the location of the cursor just
6228 before the topic was encrypted. This can be used, eg, to decrypt the topic
6229 and exactly resituate the cursor if this is being done as part of a file
6230 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6235 (let* ((current-mark (point-marker))
6236 (current-mark-position (marker-position current-mark
))
6239 editing-topic editing-point
)
6240 (goto-char (point-min))
6241 (while (allout-next-topic-pending-encryption except-mark
)
6242 (setq was-modified
(buffer-modified-p))
6243 (when (save-excursion
6244 (and (boundp 'allout-encrypt-unencrypted-on-saves
)
6245 allout-encrypt-unencrypted-on-saves
6246 (setq bo-subtree
(re-search-forward "$"))
6247 (not (allout-hidden-p))
6248 (>= current-mark
(point))
6249 (allout-end-of-current-subtree)
6250 (<= current-mark
(point))))
6251 (setq editing-topic
(point)
6252 ;; we had to wait for this 'til now so prior topics are
6253 ;; encrypted, any relevant text shifts are in place:
6254 editing-point
(- current-mark-position
6255 (count-trailing-whitespace-region
6256 bo-subtree current-mark-position
))))
6257 (allout-toggle-subtree-encryption)
6258 (if (not was-modified
)
6259 (set-buffer-modified-p nil
))
6261 (if (not was-modified
)
6262 (set-buffer-modified-p nil
))
6263 (if editing-topic
(list editing-topic editing-point
))
6269 ;;;_ #9 miscellaneous
6271 ;;;_ > outlineify-sticky ()
6272 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6274 (defalias 'outlinify-sticky
'outlineify-sticky
)
6276 (defun outlineify-sticky (&optional arg
)
6277 "Activate outline mode and establish file var so it is started subsequently.
6279 See `allout-layout' and customization of `allout-auto-activation'
6280 for details on preparing emacs for automatic allout activation."
6284 (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
6288 (goto-char (point-min))
6289 (if (allout-goto-prefix)
6291 (allout-open-topic 2)
6292 (insert (concat "Dummy outline topic header -- see"
6293 "`allout-mode' docstring: `^Hm'."))
6294 (allout-adjust-file-variable
6295 "allout-layout" (or allout-layout
'(-1 : 0))))))
6296 ;;;_ > allout-file-vars-section-data ()
6297 (defun allout-file-vars-section-data ()
6298 "Return data identifying the file-vars section, or nil if none.
6300 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6301 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6302 (let (beg prefix suffix
)
6304 (goto-char (point-max))
6305 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move
)
6306 (if (let ((case-fold-search t
))
6307 (not (search-forward "Local Variables:" nil t
)))
6309 (setq beg
(- (point) 16))
6310 (setq suffix
(buffer-substring-no-properties
6312 (progn (if (search-forward "\n" nil t
)
6315 (setq prefix
(buffer-substring-no-properties
6316 (progn (if (search-backward "\n" nil t
)
6320 (list beg prefix suffix
))
6324 ;;;_ > allout-adjust-file-variable (varname value)
6325 (defun allout-adjust-file-variable (varname value
)
6326 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6328 This activity is inhibited if either `enable-local-variables'
6329 `allout-enable-file-variable-adjustment' are nil.
6331 When enabled, an entry for the variable is created if not already present,
6332 or changed if established with a different value. The section for the file
6333 variables, itself, is created if not already present. When created, the
6334 section lines (including the section line) exist as second-level topics in
6335 a top-level topic at the end of the file.
6337 `enable-local-variables' must be true for any of this to happen."
6338 (if (not (and enable-local-variables
6339 allout-enable-file-variable-adjustment
))
6342 (let ((inhibit-field-text-motion t
)
6343 (section-data (allout-file-vars-section-data))
6346 (setq beg
(car section-data
)
6347 prefix
(cadr section-data
)
6348 suffix
(car (cddr section-data
)))
6349 ;; create the section
6350 (goto-char (point-max))
6352 (allout-open-topic 0)
6354 (insert "Local emacs vars.\n")
6355 (allout-open-topic 1)
6358 prefix
(buffer-substring-no-properties (progn
6363 (insert "Local variables:\n")
6364 (allout-open-topic 0)
6367 ;; look for existing entry or create one, leaving point for insertion
6370 (allout-show-to-offshoot)
6371 (if (search-forward (concat "\n" prefix varname
":") nil t
)
6372 (let* ((value-beg (point))
6373 (line-end (progn (if (search-forward "\n" nil t
)
6376 (value-end (- line-end
(length suffix
))))
6377 (if (> value-end value-beg
)
6378 (delete-region value-beg value-end
)))
6382 (insert (concat prefix varname
":")))
6383 (insert (format " %S%s" value suffix
))
6388 ;;;_ > allout-get-configvar-values (varname)
6389 (defun allout-get-configvar-values (configvar-name)
6390 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6392 The user is prompted for removal of symbols that are unbound, and they
6393 otherwise are ignored.
6395 CONFIGVAR-NAME should be the name of the configuration variable,
6398 (let ((configvar-value (symbol-value configvar-name
))
6400 (dolist (sym configvar-value
)
6401 (if (not (boundp sym
))
6402 (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? "
6403 configvar-name sym
))
6404 (delq sym
(symbol-value configvar-name
)))
6405 (push (symbol-value sym
) got
)))
6408 ;;;_ > allout-mark-topic ()
6409 (defun allout-mark-topic ()
6410 "Put the region around topic currently containing point."
6412 (let ((inhibit-field-text-motion t
))
6413 (beginning-of-line))
6414 (allout-goto-prefix-doublechecked)
6416 (allout-end-of-current-subtree)
6417 (exchange-point-and-mark))
6419 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6420 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
6421 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6423 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6425 (let ((new-prompt prompt
)
6429 (message "%s" new-prompt
)
6431 ;; We do our own reading here, so we can circumvent, eg, special
6432 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6434 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
6437 (cond ((string-match (regexp-quote got
) string
) got
)
6438 ((and do-defaulting
(string= got
"\r"))
6439 ;; Return empty string to default:
6441 ((string= got
"\C-g") (signal 'quit nil
))
6443 (setq new-prompt
(concat prompt
6449 ;; got something out of loop -- return it:
6453 ;;;_ > regexp-sans-escapes (string)
6454 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
6455 "Return a copy of REGEXP with all character escapes stripped out.
6457 Representations of actual backslashes -- '\\\\\\\\' -- are left as a
6460 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6462 (if (string= regexp
"")
6464 ;; Set successive-backslashes to number if current char is
6465 ;; backslash, or else to nil:
6466 (setq successive-backslashes
6467 (if (= (aref regexp
0) ?
\\)
6468 (if successive-backslashes
(1+ successive-backslashes
) 1)
6470 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
6471 ;; Include first char:
6472 (concat (substring regexp
0 1)
6473 (regexp-sans-escapes (substring regexp
1)))
6474 ;; Exclude first char, but maintain count:
6475 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
6476 ;;;_ > count-trailing-whitespace-region (beg end)
6477 (defun count-trailing-whitespace-region (beg end
)
6478 "Return number of trailing whitespace chars between BEG and END.
6480 If BEG is bigger than END we return 0."
6487 (while (re-search-forward "[ ][ ]*$" end t
)
6488 (goto-char (1+ (match-beginning 2)))
6489 (setq count
(1+ count
)))
6491 ;;;_ > allout-format-quote (string)
6492 (defun allout-format-quote (string)
6493 "Return a copy of string with all \"%\" characters doubled."
6495 (mapcar (lambda (char) (if (= char ?%
) "%%" (char-to-string char
)))
6498 ;;;_ > allout-flatten (list)
6499 (defun allout-flatten (list)
6500 "Return a list of all atoms in list."
6502 (cond ((null list
) nil
)
6503 ((atom (car list
)) (cons (car list
) (allout-flatten (cdr list
))))
6504 (t (append (allout-flatten (car list
)) (allout-flatten (cdr list
))))))
6505 ;;;_ : Compatibility:
6506 ;;;_ : xemacs undo-in-progress provision:
6507 (unless (boundp 'undo-in-progress
)
6508 (defvar undo-in-progress nil
6509 "Placeholder defvar for XEmacs compatibility from allout.el.")
6510 (defadvice undo-more
(around allout activate
)
6511 ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
6512 (let ((undo-in-progress t
)) ad-do-it
)))
6514 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6515 (defun allout-mark-marker (&optional force buffer
)
6516 "Accommodate the different signature for `mark-marker' across Emacsen.
6518 XEmacs takes two optional args, while Emacs does not,
6519 so pass them along when appropriate."
6520 (if (featurep 'xemacs
)
6521 (apply 'mark-marker force buffer
)
6523 ;;;_ > subst-char-in-string if necessary
6524 (if (not (fboundp 'subst-char-in-string
))
6525 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
6526 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6527 Unless optional argument INPLACE is non-nil, return a new string."
6528 (let ((i (length string
))
6529 (newstr (if inplace string
(copy-sequence string
))))
6532 (if (eq (aref newstr i
) fromchar
)
6533 (aset newstr i tochar
)))
6535 ;;;_ > wholenump if necessary
6536 (if (not (fboundp 'wholenump
))
6537 (defalias 'wholenump
'natnump
))
6538 ;;;_ > remove-overlays if necessary
6539 (if (not (fboundp 'remove-overlays
))
6540 (defun remove-overlays (&optional beg end name val
)
6541 "Clear BEG and END of overlays whose property NAME has value VAL.
6542 Overlays might be moved and/or split.
6543 BEG and END default respectively to the beginning and end of buffer."
6544 (unless beg
(setq beg
(point-min)))
6545 (unless end
(setq end
(point-max)))
6547 (setq beg
(prog1 end
(setq end beg
))))
6549 (dolist (o (overlays-in beg end
))
6550 (when (eq (overlay-get o name
) val
)
6551 ;; Either push this overlay outside beg...end
6552 ;; or split it to exclude beg...end
6553 ;; or delete it entirely (if it is contained in beg...end).
6554 (if (< (overlay-start o
) beg
)
6555 (if (> (overlay-end o
) end
)
6557 (move-overlay (copy-overlay o
)
6558 (overlay-start o
) beg
)
6559 (move-overlay o end
(overlay-end o
)))
6560 (move-overlay o
(overlay-start o
) beg
))
6561 (if (> (overlay-end o
) end
)
6562 (move-overlay o end
(overlay-end o
))
6563 (delete-overlay o
)))))))
6565 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6566 (if (not (fboundp 'copy-overlay
))
6567 (defun copy-overlay (o)
6568 "Return a copy of overlay O."
6569 (let ((o1 (make-overlay (overlay-start o
) (overlay-end o
)
6570 ;; FIXME: there's no easy way to find the
6571 ;; insertion-type of the two markers.
6572 (overlay-buffer o
)))
6573 (props (overlay-properties o
)))
6575 (overlay-put o1
(pop props
) (pop props
)))
6577 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6578 (if (not (fboundp 'add-to-invisibility-spec
))
6579 (defun add-to-invisibility-spec (element)
6580 "Add ELEMENT to `buffer-invisibility-spec'.
6581 See documentation for `buffer-invisibility-spec' for the kind of elements
6583 (if (eq buffer-invisibility-spec t
)
6584 (setq buffer-invisibility-spec
(list t
)))
6585 (setq buffer-invisibility-spec
6586 (cons element buffer-invisibility-spec
))))
6587 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6588 (if (not (fboundp 'remove-from-invisibility-spec
))
6589 (defun remove-from-invisibility-spec (element)
6590 "Remove ELEMENT from `buffer-invisibility-spec'."
6591 (if (consp buffer-invisibility-spec
)
6592 (setq buffer-invisibility-spec
(delete element
6593 buffer-invisibility-spec
)))))
6594 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6595 (if (not (fboundp 'move-beginning-of-line
))
6596 (defun move-beginning-of-line (arg)
6597 "Move point to beginning of current line as displayed.
6598 \(This disregards invisible newlines such as those
6599 which are part of the text that an image rests on.)
6601 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6602 If point reaches the beginning or end of buffer, it stops there.
6603 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6605 (or arg
(setq arg
1))
6607 (condition-case nil
(line-move (1- arg
)) (error nil
)))
6609 ;; Move to beginning-of-line, ignoring fields and invisibles.
6610 (skip-chars-backward "^\n")
6611 (while (and (not (bobp))
6613 (get-char-property (1- (point)) 'invisible
)))
6614 (if (eq buffer-invisibility-spec t
)
6616 (or (memq prop buffer-invisibility-spec
)
6617 (assq prop buffer-invisibility-spec
)))))
6618 (goto-char (if (featurep 'xemacs
)
6619 (previous-property-change (point))
6620 (previous-char-property-change (point))))
6621 (skip-chars-backward "^\n"))
6622 (vertical-motion 0))
6624 ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
6625 (if (not (fboundp 'move-end-of-line
))
6626 (defun move-end-of-line (arg)
6627 "Move point to end of current line as displayed.
6628 \(This disregards invisible newlines such as those
6629 which are part of the text that an image rests on.)
6631 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6632 If point reaches the beginning or end of buffer, it stops there.
6633 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6635 (or arg
(setq arg
1))
6640 (let ((goal-column 0))
6641 (and (condition-case nil
6642 (or (line-move arg
) t
)
6650 (get-char-property (1- (point))
6652 (if (eq buffer-invisibility-spec t
)
6655 buffer-invisibility-spec
)
6657 buffer-invisibility-spec
)))))
6659 (previous-char-property-change (point))))
6663 (if (and (> (point) newpos
)
6664 (eq (preceding-char) ?
\n))
6666 (if (and (> (point) newpos
) (not (eobp))
6667 (not (eq (following-char) ?
\n)))
6668 ;; If we skipped something intangible
6669 ;; and now we're not really at eol,
6674 ;;;_ > allout-next-single-char-property-change -- alias unless lacking
6675 (defalias 'allout-next-single-char-property-change
6676 (if (fboundp 'next-single-char-property-change
)
6677 'next-single-char-property-change
6678 'next-single-property-change
)
6679 ;; No docstring because xemacs defalias doesn't support it.
6681 ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
6682 (defalias 'allout-previous-single-char-property-change
6683 (if (fboundp 'previous-single-char-property-change
)
6684 'previous-single-char-property-change
6685 'previous-single-property-change
)
6686 ;; No docstring because xemacs defalias doesn't support it.
6688 ;;;_ > allout-select-safe-coding-system
6689 (defalias 'allout-select-safe-coding-system
6690 (if (fboundp 'select-safe-coding-system
)
6691 'select-safe-coding-system
6692 'detect-coding-region
)
6694 ;;;_ > allout-substring-no-properties
6695 ;; define as alias first, so byte compiler is happy.
6696 (defalias 'allout-substring-no-properties
'substring-no-properties
)
6697 ;; then supplant with definition if underlying alias absent.
6698 (if (not (fboundp 'substring-no-properties
))
6699 (defun allout-substring-no-properties (string &optional start end
)
6700 (substring string
(or start
0) end
))
6704 ;;;_ > allout-bullet-isearch (&optional bullet)
6705 (defun allout-bullet-isearch (&optional bullet
)
6706 "Isearch (regexp) for topic with bullet BULLET."
6709 (setq bullet
(solicit-char-in-string
6710 "ISearch for topic with bullet: "
6711 (regexp-sans-escapes allout-bullets-string
))))
6713 (let ((isearch-regexp t
)
6714 (isearch-string (concat "^"
6715 allout-header-prefix
6718 (isearch-repeat 'forward
)
6721 ;;;_ #11 Unit tests -- this should be last item before "Provide"
6722 ;;;_ > allout-run-unit-tests ()
6723 (defun allout-run-unit-tests ()
6724 "Run the various allout unit tests."
6725 (message "Running allout tests...")
6726 (allout-test-resumptions)
6727 (message "Running allout tests... Done.")
6729 ;;;_ : test resumptions:
6730 ;;;_ > allout-tests-obliterate-variable (name)
6731 (defun allout-tests-obliterate-variable (name)
6732 "Completely unbind variable with NAME."
6733 (if (local-variable-p name
(current-buffer)) (kill-local-variable name
))
6734 (while (boundp name
) (makunbound name
)))
6735 ;;;_ > allout-test-resumptions ()
6736 (defvar allout-tests-globally-unbound nil
6737 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6738 (defvar allout-tests-globally-true nil
6739 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6740 (defvar allout-tests-locally-true nil
6741 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6742 (defun allout-test-resumptions ()
6743 "Exercise allout resumptions."
6744 ;; for each resumption case, we also test that the right local/global
6745 ;; scopes are affected during resumption effects:
6747 ;; ensure that previously unbound variables return to the unbound state.
6749 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6750 (allout-add-resumptions '(allout-tests-globally-unbound t
))
6751 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6752 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6753 (assert (boundp 'allout-tests-globally-unbound
))
6754 (assert (equal allout-tests-globally-unbound t
))
6755 (allout-do-resumptions)
6756 (assert (not (local-variable-p 'allout-tests-globally-unbound
6758 (assert (not (boundp 'allout-tests-globally-unbound
))))
6760 ;; ensure that variable with prior global value is resumed
6762 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6763 (setq allout-tests-globally-true t
)
6764 (allout-add-resumptions '(allout-tests-globally-true nil
))
6765 (assert (equal (default-value 'allout-tests-globally-true
) t
))
6766 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6767 (assert (equal allout-tests-globally-true nil
))
6768 (allout-do-resumptions)
6769 (assert (not (local-variable-p 'allout-tests-globally-true
6771 (assert (boundp 'allout-tests-globally-true
))
6772 (assert (equal allout-tests-globally-true t
)))
6774 ;; ensure that prior local value is resumed
6776 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6777 (set (make-local-variable 'allout-tests-locally-true
) t
)
6778 (assert (not (default-boundp 'allout-tests-locally-true
))
6779 nil
(concat "Test setup mistake -- variable supposed to"
6780 " not have global binding, but it does."))
6781 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer))
6782 nil
(concat "Test setup mistake -- variable supposed to have"
6783 " local binding, but it lacks one."))
6784 (allout-add-resumptions '(allout-tests-locally-true nil
))
6785 (assert (not (default-boundp 'allout-tests-locally-true
)))
6786 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6787 (assert (equal allout-tests-locally-true nil
))
6788 (allout-do-resumptions)
6789 (assert (boundp 'allout-tests-locally-true
))
6790 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6791 (assert (equal allout-tests-locally-true t
))
6792 (assert (not (default-boundp 'allout-tests-locally-true
))))
6794 ;; ensure that last of multiple resumptions holds, for various scopes.
6796 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6797 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6798 (setq allout-tests-globally-true t
)
6799 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6800 (set (make-local-variable 'allout-tests-locally-true
) t
)
6801 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6802 '(allout-tests-globally-true nil
)
6803 '(allout-tests-locally-true nil
))
6804 (allout-add-resumptions '(allout-tests-globally-unbound 2)
6805 '(allout-tests-globally-true 3)
6806 '(allout-tests-locally-true 4))
6807 ;; reestablish many of the basic conditions are maintained after re-add:
6808 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6809 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6810 (assert (equal allout-tests-globally-unbound
2))
6811 (assert (default-boundp 'allout-tests-globally-true
))
6812 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6813 (assert (equal allout-tests-globally-true
3))
6814 (assert (not (default-boundp 'allout-tests-locally-true
)))
6815 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6816 (assert (equal allout-tests-locally-true
4))
6817 (allout-do-resumptions)
6818 (assert (not (local-variable-p 'allout-tests-globally-unbound
6820 (assert (not (boundp 'allout-tests-globally-unbound
)))
6821 (assert (not (local-variable-p 'allout-tests-globally-true
6823 (assert (boundp 'allout-tests-globally-true
))
6824 (assert (equal allout-tests-globally-true t
))
6825 (assert (boundp 'allout-tests-locally-true
))
6826 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6827 (assert (equal allout-tests-locally-true t
))
6828 (assert (not (default-boundp 'allout-tests-locally-true
))))
6830 ;; ensure that deliberately unbinding registered variables doesn't foul things
6832 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6833 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6834 (setq allout-tests-globally-true t
)
6835 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6836 (set (make-local-variable 'allout-tests-locally-true
) t
)
6837 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6838 '(allout-tests-globally-true nil
)
6839 '(allout-tests-locally-true nil
))
6840 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6841 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6842 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6843 (allout-do-resumptions))
6845 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
6846 (when allout-run-unit-tests-on-load
6847 (allout-run-unit-tests))
6852 ;;;_* Local emacs vars.
6853 ;; The following `allout-layout' local variable setting:
6854 ;; - closes all topics from the first topic to just before the third-to-last,
6855 ;; - shows the children of the third to last (config vars)
6856 ;; - and the second to last (code section),
6857 ;; - and closes the last topic (this local-variables section).
6859 ;;allout-layout: (0 : -1 -1 0)
6862 ;;; allout.el ends here