1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992-1994, 2001-2012 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <ken dot manheimer at gmail...>
6 ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...>
7 ;; Created: Dec 1991 -- first release to usenet
9 ;; Keywords: outlines, wp, languages, PGP, GnuPG
10 ;; Website: http://myriadicity.net/software-and-systems/craft/emacs-allout
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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 ;;;_ * initialize 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
244 :type
'allout-keybindings-binding
245 :group
'allout-keybindings
246 :set
'allout-compose-and-institute-keymap
248 ;;;_ = allout-unprefixed-keybindings
249 (defcustom allout-unprefixed-keybindings
250 '(("[(control ?k)]" allout-kill-line
)
251 ("[(meta ?k)]" allout-copy-line-as-kill
)
252 ("[(control ?y)]" allout-yank
)
253 ("[(meta ?y)]" allout-yank-pop
)
255 "Allout-mode functions bound to keys without any added prefix.
257 This is in contrast to the majority of allout-mode bindings on
258 `allout-prefixed-bindings', whose bindings are created with a
259 preceding command key.
261 Use vector format for the keys:
262 - put literal keys after a '?' question mark, eg: '?a', '?.'
263 - enclose control, shift, or meta-modified keys as sequences within
264 parentheses, with the literal key, as above, preceded by the name(s)
265 of the modifiers, eg: [(control ?a)]
266 See the existing keys for examples."
268 :type
'allout-keybindings-binding
269 :group
'allout-keybindings
270 :set
'allout-compose-and-institute-keymap
273 ;;;_ > allout-auto-activation-helper (var value)
275 (defun allout-auto-activation-helper (var value
)
276 "Institute `allout-auto-activation'.
278 Intended to be used as the `allout-auto-activation' :set function."
279 (set-default var value
)
281 ;;;_ > allout-setup ()
283 (defun allout-setup ()
284 "Do fundamental Emacs session for allout auto-activation.
286 Establishes allout processing as part of visiting a file if
287 `allout-auto-activation' is non-nil, or removes it otherwise.
289 The proper way to use this is through customizing the setting of
290 `allout-auto-activation'."
291 (if (not allout-auto-activation
)
292 (remove-hook 'find-file-hook
'allout-find-file-hook
)
293 (add-hook 'find-file-hook
'allout-find-file-hook
)))
294 ;;;_ = allout-auto-activation
296 (defcustom allout-auto-activation nil
297 "Configure allout outline mode auto-activation.
299 Control whether and how allout outline mode is automatically
300 activated when files are visited with non-nil buffer-specific
301 file variable `allout-layout'.
303 When allout-auto-activation is \"On\" (t), allout mode is
304 activated in buffers with non-nil `allout-layout', and the
305 specified layout is applied.
307 With value \"ask\", auto-mode-activation is enabled, and endorsement for
308 performing auto-layout is asked of the user each time.
310 With value \"activate\", only auto-mode-activation is enabled.
313 With value nil, inhibit any automatic allout-mode activation."
314 :set
'allout-auto-activation-helper
315 ;; FIXME: Using strings here is unusual and less efficient than symbols.
316 :type
'(choice (const :tag
"On" t
)
317 (const :tag
"Ask about layout" "ask")
318 (const :tag
"Mode only" "activate")
319 (const :tag
"Off" nil
))
322 ;;;_ = allout-default-layout
323 (defcustom allout-default-layout
'(-2 : 0)
324 "Default allout outline layout specification.
326 This setting specifies the outline exposure to use when
327 `allout-layout' has the local value `t'. This docstring describes the
328 layout specifications.
330 A list value specifies a default layout for the current buffer,
331 to be applied upon activation of `allout-mode'. Any non-nil
332 value will automatically trigger `allout-mode', provided
333 `allout-auto-activation' has been customized to enable it.
335 The types of elements in the layout specification are:
337 INTEGER -- dictate the relative depth to open the corresponding topic(s),
339 -- negative numbers force the topic to be closed before opening
340 to the absolute value of the number, so all siblings are open
342 -- positive numbers open to the relative depth indicated by the
343 number, but do not force already opened subtopics to be closed.
344 -- 0 means to close topic -- hide all subitems.
345 : -- repeat spec -- apply the preceding element to all siblings at
346 current level, *up to* those siblings that would be covered by specs
347 following the `:' on the list. Ie, apply to all topics at level but
348 trailing ones accounted for by trailing specs. (Only the first of
349 multiple colons at the same level is honored -- later ones are ignored.)
350 * -- completely exposes the topic, including bodies
351 + -- exposes all subtopics, but not the bodies
352 - -- exposes the body of the corresponding topic, but not subtopics
353 LIST -- a nested layout spec, to be applied intricately to its
354 corresponding item(s)
358 Collapse the top-level topics to show their children and
359 grandchildren, but completely collapse the final top-level topic.
361 Close the first topic so only the immediate subtopics are shown,
362 leave the subsequent topics exposed as they are until the second
363 second to last topic, which is exposed at least one level, and
364 completely close the last topic.
366 Expose children and grandchildren of all topics at current
367 level except the last two; expose children of the second to
368 last and completely expose the last one, including its subtopics.
370 See `allout-expose-topic' for more about the exposure process.
372 Also, allout's mode-specific provisions will make topic prefixes default
373 to the comment-start string, if any, of the language of the file. This
374 is modulo the setting of `allout-use-mode-specific-leader', which see."
375 :type
'allout-layout-type
377 ;;;_ : allout-layout-type
378 (define-widget 'allout-layout-type
'lazy
379 "Allout layout format customization basic building blocks."
381 (choice (integer :tag
"integer (<= zero is strict)")
382 (const :tag
": (repeat prior)" :)
383 (const :tag
"* (completely expose)" *)
384 (const :tag
"+ (expose all offspring, headlines only)" +)
385 (const :tag
"- (expose topic body but not offspring)" -
)
386 (allout-layout-type :tag
"<Nested layout>"))))
388 ;;;_ = allout-inhibit-auto-fill
389 (defcustom allout-inhibit-auto-fill nil
390 "If non-nil, auto-fill will be inhibited in the allout buffers.
392 You can customize this setting to set it for all allout buffers, or set it
393 in individual buffers if you want to inhibit auto-fill only in particular
394 buffers. (You could use a function on `allout-mode-hook' to inhibit
395 auto-fill according, eg, to the major mode.)
397 If you don't set this and auto-fill-mode is enabled, allout will use the
398 value that `normal-auto-fill-function', if any, when allout mode starts, or
399 else allout's special hanging-indent maintaining auto-fill function,
403 (make-variable-buffer-local 'allout-inhibit-auto-fill
)
404 ;;;_ = allout-inhibit-auto-fill-on-headline
405 (defcustom allout-inhibit-auto-fill-on-headline nil
406 "If non-nil, auto-fill will be inhibited while on topic's header line."
410 (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline
)
411 ;;;_ = allout-use-hanging-indents
412 (defcustom allout-use-hanging-indents t
413 "If non-nil, topic body text auto-indent defaults to indent of the header.
414 Ie, it is indented to be just past the header prefix. This is
415 relevant mostly for use with `indented-text-mode', or other situations
416 where auto-fill occurs."
419 (make-variable-buffer-local 'allout-use-hanging-indents
)
421 (put 'allout-use-hanging-indents
'safe-local-variable
422 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
423 ;;;_ = allout-reindent-bodies
424 (defcustom allout-reindent-bodies
(if allout-use-hanging-indents
426 "Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
428 When active, topic body lines that are indented even with or beyond
429 their topic header are reindented to correspond with depth shifts of
432 A value of t enables reindent in non-programming-code buffers, ie
433 those that do not have the variable `comment-start' set. A value of
434 `force' enables reindent whether or not `comment-start' is set."
435 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
438 (make-variable-buffer-local 'allout-reindent-bodies
)
440 (put 'allout-reindent-bodies
'safe-local-variable
441 (lambda (x) (memq x
'(nil t text force
))))
443 ;;;_ = allout-show-bodies
444 (defcustom allout-show-bodies nil
445 "If non-nil, show entire body when exposing a topic, rather than
449 (make-variable-buffer-local 'allout-show-bodies
)
451 (put 'allout-show-bodies
'safe-local-variable
452 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
454 ;;;_ = allout-beginning-of-line-cycles
455 (defcustom allout-beginning-of-line-cycles t
456 "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
458 Cycling only happens on when the command is repeated, not when it
459 follows a different command.
461 Smart-placement means that repeated calls to this function will
464 - if the cursor is on a non-headline body line and not on the first column:
465 then it goes to the first column
466 - if the cursor is on the first column of a non-headline body line:
467 then it goes to the start of the headline within the item body
468 - if the cursor is on the headline and not the start of the headline:
469 then it goes to the start of the headline
470 - if the cursor is on the start of the headline:
471 then it goes to the bullet character (for hotspot navigation)
472 - if the cursor is on the bullet character:
473 then it goes to the first column of that line (the headline)
474 - if the cursor is on the first column of the headline:
475 then it goes to the start of the headline within the item body.
477 In this fashion, you can use the beginning-of-line command to do
478 its normal job and then, when repeated, advance through the
479 entry, cycling back to start.
481 If this configuration variable is nil, then the cursor is just
482 advanced to the beginning of the line and remains there on
484 :type
'boolean
:group
'allout
)
485 ;;;_ = allout-end-of-line-cycles
486 (defcustom allout-end-of-line-cycles t
487 "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
489 Cycling only happens on when the command is repeated, not when it
490 follows a different command.
492 Smart placement means that repeated calls to this function will
495 - if the cursor is not on the end-of-line,
496 then it goes to the end-of-line
497 - if the cursor is on the end-of-line but not the end-of-entry,
498 then it goes to the end-of-entry, exposing it if necessary
499 - if the cursor is on the end-of-entry,
500 then it goes to the end of the head line
502 In this fashion, you can use the end-of-line command to do its
503 normal job and then, when repeated, advance through the entry,
504 cycling back to start.
506 If this configuration variable is nil, then the cursor is just
507 advanced to the end of the line and remains there on repeated
509 :type
'boolean
:group
'allout
)
511 ;;;_ = allout-header-prefix
512 (defcustom allout-header-prefix
"."
513 ;; this string is treated as literal match. it will be `regexp-quote'd, so
514 ;; one cannot use regular expressions to match varying header prefixes.
515 "Leading string which helps distinguish topic headers.
517 Outline topic header lines are identified by a leading topic
518 header prefix, which mostly have the value of this var at their front.
519 Level 1 topics are exceptions. They consist of only a single
520 character, which is typically set to the `allout-primary-bullet'."
523 (make-variable-buffer-local 'allout-header-prefix
)
525 (put 'allout-header-prefix
'safe-local-variable
'stringp
)
526 ;;;_ = allout-primary-bullet
527 (defcustom allout-primary-bullet
"*"
528 "Bullet used for top-level outline topics.
530 Outline topic header lines are identified by a leading topic header
531 prefix, which is concluded by bullets that includes the value of this
532 var and the respective allout-*-bullets-string vars.
534 The value of an asterisk (`*') provides for backwards compatibility
535 with the original Emacs outline mode. See `allout-plain-bullets-string'
536 and `allout-distinctive-bullets-string' for the range of available
540 (make-variable-buffer-local 'allout-primary-bullet
)
542 (put 'allout-primary-bullet
'safe-local-variable
'stringp
)
543 ;;;_ = allout-plain-bullets-string
544 (defcustom allout-plain-bullets-string
".,"
545 "The bullets normally used in outline topic prefixes.
547 See `allout-distinctive-bullets-string' for the other kind of
550 DO NOT include the close-square-bracket, `]', as a bullet.
552 Outline mode has to be reactivated in order for changes to the value
553 of this var to take effect."
556 (make-variable-buffer-local 'allout-plain-bullets-string
)
558 (put 'allout-plain-bullets-string
'safe-local-variable
'stringp
)
559 ;;;_ = allout-distinctive-bullets-string
560 (defcustom allout-distinctive-bullets-string
"*+-=>()[{}&!?#%\"X@$~_\\:;^"
561 "Persistent outline header bullets used to distinguish special topics.
563 These bullets are distinguish topics with particular character.
564 They are not used by default in the topic creation routines, but
565 are offered as options when you modify topic creation with a
566 universal argument (\\[universal-argument]), or during rebulleting (\\[allout-rebullet-current-heading]).
568 Distinctive bullets are not cycled when topics are shifted or
569 otherwise automatically rebulleted, so their marking is
570 persistent until deliberately changed. Their significance is
571 purely by convention, however. Some conventions suggest
574 `(' - open paren -- an aside or incidental point
575 `?' - question mark -- uncertain or outright question
576 `!' - exclamation point/bang -- emphatic
577 `[' - open square bracket -- meta-note, about item instead of item's subject
578 `\"' - double quote -- a quotation or other citation
579 `=' - equal sign -- an assignment, some kind of definition
580 `^' - carat -- relates to something above
582 Some are more elusive, but their rationale may be recognizable:
584 `+' - plus -- pending consideration, completion
585 `_' - underscore -- done, completed
586 `&' - ampersand -- addendum, furthermore
588 \(Some other non-plain bullets have special meaning to the
589 software. By default:
591 `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
592 `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
594 See `allout-plain-bullets-string' for the standard, alternating
597 You must run `set-allout-regexp' in order for outline mode to
598 adopt changes of this value.
600 DO NOT include the close-square-bracket, `]', on either of the bullet
604 (make-variable-buffer-local 'allout-distinctive-bullets-string
)
606 (put 'allout-distinctive-bullets-string
'safe-local-variable
'stringp
)
608 ;;;_ = allout-use-mode-specific-leader
609 (defcustom allout-use-mode-specific-leader t
610 "When non-nil, use mode-specific topic-header prefixes.
612 Allout outline mode will use the mode-specific `allout-mode-leaders' or
613 comment-start string, if any, to lead the topic prefix string, so topic
614 headers look like comments in the programming language. It will also use
615 the comment-start string, with an '_' appended, for `allout-primary-bullet'.
617 String values are used as literals, not regular expressions, so
618 do not escape any regular-expression characters.
620 Value t means to first check for assoc value in `allout-mode-leaders'
621 alist, then use comment-start string, if any, then use default (`.').
622 \(See note about use of comment-start strings, below.)
624 Set to the symbol for either of `allout-mode-leaders' or
625 `comment-start' to use only one of them, respectively.
627 Value nil means to always use the default (`.') and leave
628 `allout-primary-bullet' unaltered.
630 comment-start strings that do not end in spaces are tripled in
631 the header-prefix, and an `_' underscore is tacked on the end, to
632 distinguish them from regular comment strings. comment-start
633 strings that do end in spaces are not tripled, but an underscore
634 is substituted for the space. [This presumes that the space is
635 for appearance, not comment syntax. You can use
636 `allout-mode-leaders' to override this behavior, when
638 :type
'(choice (const t
) (const nil
) string
639 (const allout-mode-leaders
)
640 (const comment-start
))
643 (put 'allout-use-mode-specific-leader
'safe-local-variable
644 (lambda (x) (or (memq x
'(t nil allout-mode-leaders comment-start
))
646 ;;;_ = allout-mode-leaders
647 (defvar allout-mode-leaders
'()
648 "Specific allout-prefix leading strings per major modes.
650 Use this if the mode's comment-start string isn't what you
651 prefer, or if the mode lacks a comment-start string. See
652 `allout-use-mode-specific-leader' for more details.
654 If you're constructing a string that will comment-out outline
655 structuring so it can be included in program code, append an extra
656 character, like an \"_\" underscore, to distinguish the lead string
657 from regular comments that start at the beginning-of-line.")
659 ;;;_ = allout-old-style-prefixes
660 (defcustom allout-old-style-prefixes nil
661 "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
663 Non-nil restricts the topic creation and modification
664 functions to asterix-padded prefixes, so they look exactly
665 like the original Emacs-outline style prefixes.
667 Whatever the setting of this variable, both old and new style prefixes
668 are always respected by the topic maneuvering functions."
671 (make-variable-buffer-local 'allout-old-style-prefixes
)
673 (put 'allout-old-style-prefixes
'safe-local-variable
674 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
675 ;;;_ = allout-stylish-prefixes -- alternating bullets
676 (defcustom allout-stylish-prefixes t
677 "Do fancy stuff with topic prefix bullets according to level, etc.
679 Non-nil enables topic creation, modification, and repositioning
680 functions to vary the topic bullet char (the char that marks the topic
681 depth) just preceding the start of the topic text) according to level.
682 Otherwise, only asterisks (`*') and distinctive bullets are used.
684 This is how an outline can look (but sans indentation) with stylish
689 . + One level 3 subtopic
690 . . One level 4 subtopic
691 . . A second 4 subtopic
692 . + Another level 3 subtopic
693 . #1 A numbered level 4 subtopic
695 . ! Another level 4 subtopic with a different distinctive bullet
696 . #4 And another numbered level 4 subtopic
698 This would be an outline with stylish prefixes inhibited (but the
699 numbered and other distinctive bullets retained):
703 . * One level 3 subtopic
704 . * One level 4 subtopic
705 . * A second 4 subtopic
706 . * Another level 3 subtopic
707 . #1 A numbered level 4 subtopic
709 . ! Another level 4 subtopic with a different distinctive bullet
710 . #4 And another numbered level 4 subtopic
712 Stylish and constant prefixes (as well as old-style prefixes) are
713 always respected by the topic maneuvering functions, regardless of
714 this variable setting.
716 The setting of this var is not relevant when `allout-old-style-prefixes'
720 (make-variable-buffer-local 'allout-stylish-prefixes
)
722 (put 'allout-stylish-prefixes
'safe-local-variable
723 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
725 ;;;_ = allout-numbered-bullet
726 (defcustom allout-numbered-bullet
"#"
727 "String designating bullet of topics that have auto-numbering; nil for none.
729 Topics having this bullet have automatic maintenance of a sibling
730 sequence-number tacked on, just after the bullet. Conventionally set
731 to \"#\", you can set it to a bullet of your choice. A nil value
732 disables numbering maintenance."
733 :type
'(choice (const nil
) string
)
735 (make-variable-buffer-local 'allout-numbered-bullet
)
737 (put 'allout-numbered-bullet
'safe-local-variable
738 (if (fboundp 'string-or-null-p
)
740 (lambda (x) (or (stringp x
) (null x
)))))
741 ;;;_ = allout-file-xref-bullet
742 (defcustom allout-file-xref-bullet
"@"
743 "Bullet signifying file cross-references, for `allout-resolve-xref'.
745 Set this var to the bullet you want to use for file cross-references."
746 :type
'(choice (const nil
) string
)
749 (put 'allout-file-xref-bullet
'safe-local-variable
750 (if (fboundp 'string-or-null-p
)
752 (lambda (x) (or (stringp x
) (null x
)))))
753 ;;;_ = allout-presentation-padding
754 (defcustom allout-presentation-padding
2
755 "Presentation-format white-space padding factor, for greater indent."
759 (make-variable-buffer-local 'allout-presentation-padding
)
761 (put 'allout-presentation-padding
'safe-local-variable
'integerp
)
763 ;;;_ = allout-flattened-numbering-abbreviation
764 (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering
765 'allout-flattened-numbering-abbreviation
"24.1")
766 (defcustom allout-flattened-numbering-abbreviation nil
767 "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
768 numbers to minimal amount with some context. Otherwise, entire
769 numbers are always used."
774 ;;;_ + LaTeX formatting
775 ;;;_ - allout-number-pages
776 (defcustom allout-number-pages nil
777 "Non-nil turns on page numbering for LaTeX formatting of an outline."
780 ;;;_ - allout-label-style
781 (defcustom allout-label-style
"\\large\\bf"
782 "Font and size of labels for LaTeX formatting of an outline."
785 ;;;_ - allout-head-line-style
786 (defcustom allout-head-line-style
"\\large\\sl "
787 "Font and size of entries for LaTeX formatting of an outline."
790 ;;;_ - allout-body-line-style
791 (defcustom allout-body-line-style
" "
792 "Font and size of entries for LaTeX formatting of an outline."
795 ;;;_ - allout-title-style
796 (defcustom allout-title-style
"\\Large\\bf"
797 "Font and size of titles for LaTeX formatting of an outline."
801 (defcustom allout-title
'(or buffer-file-name
(buffer-name))
802 "Expression to be evaluated to determine the title for LaTeX
806 ;;;_ - allout-line-skip
807 (defcustom allout-line-skip
".05cm"
808 "Space between lines for LaTeX formatting of an outline."
812 (defcustom allout-indent
".3cm"
813 "LaTeX formatted depth-indent spacing."
817 ;;;_ + Topic encryption
818 ;;;_ = allout-encryption group
819 (defgroup allout-encryption nil
820 "Settings for topic encryption features of allout outliner."
822 ;;;_ = allout-topic-encryption-bullet
823 (defcustom allout-topic-encryption-bullet
"~"
824 "Bullet signifying encryption of the entry's body."
825 :type
'(choice (const nil
) string
)
827 :group
'allout-encryption
)
828 ;;;_ = allout-encrypt-unencrypted-on-saves
829 (defcustom allout-encrypt-unencrypted-on-saves t
830 "If non-nil, topics pending encryption are encrypted during buffer saves.
832 This prevents file-system exposure of un-encrypted contents of
833 items marked for encryption.
835 When non-nil, if the topic currently being edited is decrypted,
836 it will be encrypted for saving but automatically decrypted
837 before any subsequent user interaction, so it is once again clear
838 text for editing though the file system copy is encrypted.
840 \(Auto-saves are handled differently. Buffers with plain-text
841 exposed encrypted topics are exempted from auto saves until all
842 such topics are encrypted.)"
846 :group
'allout-encryption
)
847 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves
)
848 (defvar allout-auto-save-temporarily-disabled nil
849 "True while topic encryption is pending and auto-saving was active.
851 The value of `buffer-saved-size' at the time of decryption is used,
852 for restoring when all encryptions are established.")
853 (defvar allout-just-did-undo nil
854 "True just after undo commands, until allout-post-command-business.")
855 (make-variable-buffer-local 'allout-just-did-undo
)
858 ;;;_ = allout-developer group
859 (defgroup allout-developer nil
860 "Allout settings developers care about, including topic encryption and more."
862 ;;;_ = allout-run-unit-tests-on-load
863 (defcustom allout-run-unit-tests-on-load nil
864 "When non-nil, unit tests will be run at end of loading the allout module.
866 Generally, allout code developers are the only ones who'll want to set this.
868 \(If set, this makes it an even better practice to exercise changes by
869 doing byte-compilation with a repeat count, so the file is loaded after
872 See `allout-run-unit-tests' to see what's run."
874 :group
'allout-developer
)
876 ;;;_ + Miscellaneous customization
878 ;;;_ = allout-enable-file-variable-adjustment
879 (defcustom allout-enable-file-variable-adjustment t
880 "If non-nil, some allout outline actions edit Emacs local file var text.
882 This can range from changes to existing entries, addition of new ones,
883 and creation of a new local variables section when necessary.
885 Emacs file variables adjustments are also inhibited if `enable-local-variables'
888 Operations potentially causing edits include allout encryption routines.
889 For details, see `allout-toggle-current-subtree-encryption's docstring."
892 (make-variable-buffer-local 'allout-enable-file-variable-adjustment
)
894 ;;;_* CODE -- no user customizations below.
896 ;;;_ #1 Internal Outline Formatting and Configuration
898 ;;;_ = allout-version
899 (defvar allout-version
"2.3"
900 "Version of currently loaded outline package. (allout.el)")
901 ;;;_ > allout-version
902 (defun allout-version (&optional here
)
903 "Return string describing the loaded outline version."
905 (let ((msg (concat "Allout Outline Mode v " allout-version
)))
906 (if here
(insert msg
))
909 ;;;_ : Mode activation (defined here because it's referenced early)
911 (defvar allout-mode nil
"Allout outline mode minor-mode flag.")
912 (make-variable-buffer-local 'allout-mode
)
913 ;;;_ = allout-layout nil
914 (defvar allout-layout nil
; LEAVE GLOBAL VALUE NIL -- see docstring.
915 "Buffer-specific setting for allout layout.
917 In buffers where this is non-nil (and if `allout-auto-activation'
918 has been customized to enable this behavior), `allout-mode' will be
919 automatically activated. The layout dictated by the value will be used to
920 set the initial exposure when `allout-mode' is activated.
922 \*You should not setq-default this variable non-nil unless you want every
923 visited file to be treated as an allout file.*
925 The value would typically be set by a file local variable. For
926 example, the following lines at the bottom of an Emacs Lisp file:
929 ;;;allout-layout: (0 : -1 -1 0)
932 dictate activation of `allout-mode' mode when the file is visited
933 \(presuming proper `allout-auto-activation' customization),
934 followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'.
935 \(This is the layout used for the allout.el source file.)
937 `allout-default-layout' describes the specification format.
938 `allout-layout' can additionally have the value `t', in which
939 case the value of `allout-default-layout' is used.")
940 (make-variable-buffer-local 'allout-layout
)
942 (put 'allout-layout
'safe-local-variable
943 (lambda (x) (or (numberp x
) (listp x
) (memq x
'(: * + -
)))))
945 ;;;_ : Topic header format
947 (defvar allout-regexp
""
948 "Regular expression to match the beginning of a heading line.
950 Any line whose beginning matches this regexp is considered a
951 heading. This var is set according to the user configuration vars
952 by `set-allout-regexp'.")
953 (make-variable-buffer-local 'allout-regexp
)
954 ;;;_ = allout-bullets-string
955 (defvar allout-bullets-string
""
956 "A string dictating the valid set of outline topic bullets.
958 This var should *not* be set by the user -- it is set by `set-allout-regexp',
959 and is produced from the elements of `allout-plain-bullets-string'
960 and `allout-distinctive-bullets-string'.")
961 (make-variable-buffer-local 'allout-bullets-string
)
962 ;;;_ = allout-bullets-string-len
963 (defvar allout-bullets-string-len
0
964 "Length of current buffers' `allout-plain-bullets-string'.")
965 (make-variable-buffer-local 'allout-bullets-string-len
)
966 ;;;_ = allout-depth-specific-regexp
967 (defvar allout-depth-specific-regexp
""
968 "Regular expression to match a heading line prefix for a particular depth.
970 This expression is used to search for depth-specific topic
971 headers at depth 2 and greater. Use `allout-depth-one-regexp'
972 for to seek topics at depth one.
974 This var is set according to the user configuration vars by
975 `set-allout-regexp'. It is prepared with format strings for two
976 decimal numbers, which should each be one less than the depth of the
977 topic prefix to be matched.")
978 (make-variable-buffer-local 'allout-depth-specific-regexp
)
979 ;;;_ = allout-depth-one-regexp
980 (defvar allout-depth-one-regexp
""
981 "Regular expression to match a heading line prefix for depth one.
983 This var is set according to the user configuration vars by
984 `set-allout-regexp'. It is prepared with format strings for two
985 decimal numbers, which should each be one less than the depth of the
986 topic prefix to be matched.")
987 (make-variable-buffer-local 'allout-depth-one-regexp
)
988 ;;;_ = allout-line-boundary-regexp
989 (defvar allout-line-boundary-regexp
()
990 "`allout-regexp' prepended with a newline for the search target.
992 This is properly set by `set-allout-regexp'.")
993 (make-variable-buffer-local 'allout-line-boundary-regexp
)
994 ;;;_ = allout-bob-regexp
995 (defvar allout-bob-regexp
()
996 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
997 (make-variable-buffer-local 'allout-bob-regexp
)
998 ;;;_ = allout-header-subtraction
999 (defvar allout-header-subtraction
(1- (length allout-header-prefix
))
1000 "Allout-header prefix length to subtract when computing topic depth.")
1001 (make-variable-buffer-local 'allout-header-subtraction
)
1002 ;;;_ = allout-plain-bullets-string-len
1003 (defvar allout-plain-bullets-string-len
(length allout-plain-bullets-string
)
1004 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
1005 (make-variable-buffer-local 'allout-plain-bullets-string-len
)
1007 ;;;_ = allout-doublecheck-at-and-shallower
1008 (defconst allout-doublecheck-at-and-shallower
3
1009 "Validate apparent topics of this depth and shallower as being non-aberrant.
1011 Verified with `allout-aberrant-container-p'. The usefulness of
1012 this check is limited to shallow depths, because the
1013 determination of aberrance is according to the mistaken item
1014 being followed by a legitimate item of excessively greater depth.
1016 The classic example of a mistaken item, for a standard allout
1017 outline configuration, is a body line that begins with an '...'
1018 ellipsis. This happens to contain a legitimate depth-2 header
1019 prefix, constituted by two '..' dots at the beginning of the
1020 line. The only thing that can distinguish it *in principle* from
1021 a legitimate one is if the following real header is at a depth
1022 that is discontinuous from the depth of 2 implied by the
1023 ellipsis, ie depth 4 or more. As the depth being tested gets
1024 greater, the likelihood of this kind of disqualification is
1025 lower, and the usefulness of this test is lower.
1027 Extending the depth of the doublecheck increases the amount it is
1028 applied, increasing the cost of the test - on casual estimation,
1029 for outlines with many deep topics, geometrically (O(n)?).
1030 Taken together with decreasing likelihood that the test will be
1031 useful at greater depths, more modest doublecheck limits are more
1032 suitably economical.")
1033 ;;;_ X allout-reset-header-lead (header-lead)
1034 (defun allout-reset-header-lead (header-lead)
1035 "Reset the leading string used to identify topic headers."
1036 (interactive "sNew lead string: ")
1037 (setq allout-header-prefix header-lead
)
1038 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1039 (set-allout-regexp))
1040 ;;;_ X allout-lead-with-comment-string (header-lead)
1041 (defun allout-lead-with-comment-string (&optional header-lead
)
1042 "Set the topic-header leading string to specified string.
1044 Useful for encapsulating outline structure in programming
1045 language comments. Returns the leading string."
1048 (if (not (stringp header-lead
))
1049 (setq header-lead
(read-string
1050 "String prefix for topic headers: ")))
1051 (setq allout-reindent-bodies nil
)
1052 (allout-reset-header-lead header-lead
)
1054 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
1055 (defun allout-infer-header-lead-and-primary-bullet ()
1056 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
1058 Works according to settings of:
1061 `allout-header-prefix' (default)
1062 `allout-use-mode-specific-leader'
1063 and `allout-mode-leaders'.
1065 Apply this via (re)activation of `allout-mode', rather than
1066 invoking it directly."
1067 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader
)
1068 (if (or (stringp allout-use-mode-specific-leader
)
1069 (memq allout-use-mode-specific-leader
1070 '(allout-mode-leaders
1073 allout-use-mode-specific-leader
1074 ;; Oops -- garbled value, equate with effect of t:
1078 ((not use-leader
) nil
)
1079 ;; Use the explicitly designated leader:
1080 ((stringp use-leader
) use-leader
)
1081 (t (or (and (memq use-leader
'(t allout-mode-leaders
))
1082 ;; Get it from outline mode leaders?
1083 (cdr (assq major-mode allout-mode-leaders
)))
1084 ;; ... didn't get from allout-mode-leaders...
1085 (and (memq use-leader
'(t comment-start
))
1087 ;; Use comment-start, maybe tripled, and with
1091 (substring comment-start
1092 (1- (length comment-start
))))
1093 ;; Use comment-start, sans trailing space:
1094 (substring comment-start
0 -
1)
1095 (concat comment-start comment-start comment-start
))
1096 ;; ... and append underscore, whichever:
1100 (setq allout-header-prefix leader
)
1101 (if (not allout-old-style-prefixes
)
1102 ;; setting allout-primary-bullet makes the top level topics use --
1103 ;; actually, be -- the special prefix:
1104 (setq allout-primary-bullet leader
))
1105 allout-header-prefix
)))
1106 (defalias 'allout-infer-header-lead
1107 'allout-infer-header-lead-and-primary-bullet
)
1108 ;;;_ > allout-infer-body-reindent ()
1109 (defun allout-infer-body-reindent ()
1110 "Determine proper setting for `allout-reindent-bodies'.
1112 Depends on default setting of `allout-reindent-bodies' (which see)
1113 and presence of setting for `comment-start', to tell whether the
1114 file is programming code."
1115 (if (and allout-reindent-bodies
1117 (not (eq 'force allout-reindent-bodies
)))
1118 (setq allout-reindent-bodies nil
)))
1119 ;;;_ > set-allout-regexp ()
1120 (defun set-allout-regexp ()
1121 "Generate proper topic-header regexp form for outline functions.
1123 Works with respect to `allout-plain-bullets-string' and
1124 `allout-distinctive-bullets-string'.
1126 Also refresh various data structures that hinge on the regexp."
1129 ;; Derive allout-bullets-string from user configured components:
1130 (setq allout-bullets-string
"")
1131 (let ((strings (list 'allout-plain-bullets-string
1132 'allout-distinctive-bullets-string
1133 'allout-primary-bullet
))
1140 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
1141 (while (< index cur-len
)
1142 (setq cur-char
(aref cur-string index
))
1143 (setq allout-bullets-string
1144 (concat allout-bullets-string
1146 ; Single dash would denote a
1147 ; sequence, repeated denotes
1149 ((eq cur-char ?-
) "--")
1150 ; literal close-square-bracket
1151 ; doesn't work right in the
1153 ((eq cur-char ?\
]) "")
1154 (t (regexp-quote (char-to-string cur-char
))))))
1155 (setq index
(1+ index
)))
1156 (setq strings
(cdr strings
)))
1158 ;; Derive next for repeated use in allout-pending-bullet:
1159 (setq allout-plain-bullets-string-len
(length allout-plain-bullets-string
))
1160 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1162 (let (new-part old-part formfeed-part
)
1163 (setq new-part
(concat "\\("
1164 (regexp-quote allout-header-prefix
)
1166 ;; already regexp-quoted in a custom way:
1167 "[" allout-bullets-string
"]"
1169 old-part
(concat "\\("
1170 (regexp-quote allout-primary-bullet
)
1172 (regexp-quote allout-header-prefix
)
1175 " ?[^" allout-primary-bullet
"]")
1176 formfeed-part
"\\(\^L\\)"
1178 allout-regexp
(concat new-part
1184 allout-line-boundary-regexp
(concat "\n" new-part
1190 allout-bob-regexp
(concat "\\`" new-part
1197 (setq allout-depth-specific-regexp
1198 (concat "\\(^\\|\\`\\)"
1201 ;; new-style spacers-then-bullet string:
1203 (allout-format-quote (regexp-quote allout-header-prefix
))
1205 "[" (allout-format-quote allout-bullets-string
) "]"
1208 ;; old-style all-bullets string, if primary not multi-char:
1209 (if (< 0 allout-header-subtraction
)
1212 (allout-format-quote
1213 (regexp-quote allout-primary-bullet
))
1214 (allout-format-quote
1215 (regexp-quote allout-primary-bullet
))
1216 (allout-format-quote
1217 (regexp-quote allout-primary-bullet
))
1219 ;; disqualify greater depths:
1221 (allout-format-quote allout-primary-bullet
)
1226 (setq allout-depth-one-regexp
1227 (concat "\\(^\\|\\`\\)"
1231 (regexp-quote allout-header-prefix
)
1232 ;; disqualify any bullet char following any amount of
1233 ;; intervening whitespace:
1235 (concat "[^ " allout-bullets-string
"]")
1237 (if (< 0 allout-header-subtraction
)
1238 ;; Need not support anything like the old
1239 ;; bullet style if the prefix is multi-char.
1242 (regexp-quote allout-primary-bullet
)
1243 ;; disqualify deeper primary-bullet sequences:
1244 "[^" allout-primary-bullet
"]"))
1248 (defvar allout-mode-exposure-menu
)
1249 (defvar allout-mode-editing-menu
)
1250 (defvar allout-mode-navigation-menu
)
1251 (defvar allout-mode-misc-menu
)
1252 (defun produce-allout-mode-menubar-entries ()
1254 (easy-menu-define allout-mode-exposure-menu
1255 allout-mode-map-value
1256 "Allout outline exposure menu."
1258 ["Show Entry" allout-show-current-entry t
]
1259 ["Show Children" allout-show-children t
]
1260 ["Show Subtree" allout-show-current-subtree t
]
1261 ["Hide Subtree" allout-hide-current-subtree t
]
1262 ["Hide Leaves" allout-hide-current-leaves t
]
1264 ["Show All" allout-show-all t
]))
1265 (easy-menu-define allout-mode-editing-menu
1266 allout-mode-map-value
1267 "Allout outline editing menu."
1269 ["Open Sibling" allout-open-sibtopic t
]
1270 ["Open Subtopic" allout-open-subtopic t
]
1271 ["Open Supertopic" allout-open-supertopic t
]
1273 ["Shift Topic In" allout-shift-in t
]
1274 ["Shift Topic Out" allout-shift-out t
]
1275 ["Rebullet Topic" allout-rebullet-topic t
]
1276 ["Rebullet Heading" allout-rebullet-current-heading t
]
1277 ["Number Siblings" allout-number-siblings t
]
1279 ["Toggle Topic Encryption"
1280 allout-toggle-current-subtree-encryption
1281 (> (allout-current-depth) 1)]))
1282 (easy-menu-define allout-mode-navigation-menu
1283 allout-mode-map-value
1284 "Allout outline navigation menu."
1286 ["Next Visible Heading" allout-next-visible-heading t
]
1287 ["Previous Visible Heading"
1288 allout-previous-visible-heading t
]
1290 ["Up Level" allout-up-current-level t
]
1291 ["Forward Current Level" allout-forward-current-level t
]
1292 ["Backward Current Level"
1293 allout-backward-current-level t
]
1295 ["Beginning of Entry"
1296 allout-beginning-of-current-entry t
]
1297 ["End of Entry" allout-end-of-entry t
]
1298 ["End of Subtree" allout-end-of-current-subtree t
]))
1299 (easy-menu-define allout-mode-misc-menu
1300 allout-mode-map-value
1301 "Allout outlines miscellaneous bindings."
1303 ["Version" allout-version t
]
1305 ["Duplicate Exposed" allout-copy-exposed-to-buffer t
]
1306 ["Duplicate Exposed, numbered"
1307 allout-flatten-exposed-to-buffer t
]
1308 ["Duplicate Exposed, indented"
1309 allout-indented-exposed-to-buffer t
]
1311 ["Set Header Lead" allout-reset-header-lead t
]
1312 ["Set New Exposure" allout-expose-topic t
])))
1313 ;;;_ : Allout Modal-Variables Utilities
1314 ;;;_ = allout-mode-prior-settings
1315 (defvar allout-mode-prior-settings nil
1316 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1318 See `allout-add-resumptions' and `allout-do-resumptions'.")
1319 (make-variable-buffer-local 'allout-mode-prior-settings
)
1320 ;;;_ > allout-add-resumptions (&rest pairs)
1321 (defun allout-add-resumptions (&rest pairs
)
1322 "Set name/value PAIRS.
1324 Old settings are preserved for later resumption using `allout-do-resumptions'.
1326 The new values are set as a buffer local. On resumption, the prior buffer
1327 scope of the variable is restored along with its value. If it was a void
1328 buffer-local value, then it is left as nil on resumption.
1330 The pairs are lists whose car is the name of the variable and car of the
1331 cdr is the new value: '(some-var some-value)'. The pairs can actually be
1332 triples, where the third element qualifies the disposition of the setting,
1333 as described further below.
1335 If the optional third element is the symbol 'extend, then the new value
1336 created by `cons'ing the second element of the pair onto the front of the
1339 If the optional third element is the symbol 'append, then the new value is
1340 extended from the existing one by `append'ing a list containing the second
1341 element of the pair onto the end of the existing value.
1343 Extension, and resumptions in general, should not be used for hook
1344 functions -- use the 'local mode of `add-hook' for that, instead.
1346 The settings are stored on `allout-mode-prior-settings'."
1348 (let* ((pair (pop pairs
))
1351 (qualifier (if (> (length pair
) 2)
1354 (if (not (symbolp name
))
1355 (error "Pair's name, %S, must be a symbol, not %s"
1356 name
(type-of name
)))
1357 (setq prior-value
(condition-case nil
1359 (void-variable nil
)))
1360 (when (not (assoc name allout-mode-prior-settings
))
1361 ;; Not already added as a resumption, create the prior setting entry.
1362 (if (local-variable-p name
(current-buffer))
1363 ;; is already local variable -- preserve the prior value:
1364 (push (list name prior-value
) allout-mode-prior-settings
)
1365 ;; wasn't local variable, indicate so for resumption by killing
1366 ;; local value, and make it local:
1367 (push (list name
) allout-mode-prior-settings
)
1368 (make-local-variable name
)))
1370 (cond ((eq qualifier
'extend
)
1371 (if (not (listp prior-value
))
1372 (error "extension of non-list prior value attempted")
1373 (set name
(cons value prior-value
))))
1374 ((eq qualifier
'append
)
1375 (if (not (listp prior-value
))
1376 (error "appending of non-list prior value attempted")
1377 (set name
(append prior-value
(list value
)))))
1378 (t (error "unrecognized setting qualifier `%s' encountered"
1380 (set name value
)))))
1381 ;;;_ > allout-do-resumptions ()
1382 (defun allout-do-resumptions ()
1383 "Resume all name/value settings registered by `allout-add-resumptions'.
1385 This is used when concluding allout-mode, to resume selected variables to
1386 their settings before allout-mode was started."
1388 (while allout-mode-prior-settings
1389 (let* ((pair (pop allout-mode-prior-settings
))
1391 (value-cell (cdr pair
)))
1392 (if (not value-cell
)
1393 ;; Prior value was global:
1394 (kill-local-variable name
)
1395 ;; Prior value was explicit:
1396 (set name
(car value-cell
))))))
1397 ;;;_ : Mode-specific incidentals
1398 ;;;_ > allout-unprotected (expr)
1399 (defmacro allout-unprotected
(expr)
1400 "Enable internal outline operations to alter invisible text."
1401 `(let ((inhibit-read-only (if (not buffer-read-only
) t
))
1402 (inhibit-field-text-motion t
))
1404 ;;;_ = allout-mode-hook
1405 (defvar allout-mode-hook nil
1406 "Hook run when allout mode starts.")
1407 ;;;_ = allout-mode-deactivate-hook
1408 (define-obsolete-variable-alias 'allout-mode-deactivate-hook
1409 'allout-mode-off-hook
"24.1")
1410 (defvar allout-mode-deactivate-hook nil
1411 "Hook run when allout mode ends.")
1412 ;;;_ = allout-exposure-category
1413 (defvar allout-exposure-category nil
1414 "Symbol for use as allout invisible-text overlay category.")
1416 ;;;_ = allout-exposure-change-functions
1417 (define-obsolete-variable-alias 'allout-exposure-change-hook
1418 'allout-exposure-change-functions
"24.2")
1419 (defcustom allout-exposure-change-functions nil
1420 "Abnormal hook run after allout outline subtree exposure changes.
1421 It is run at the conclusion of `allout-flag-region'.
1423 Functions on the hook must take three arguments:
1425 - FROM -- integer indicating the point at the start of the change.
1426 - TO -- integer indicating the point of the end of the change.
1427 - FLAG -- change mode: nil for exposure, otherwise concealment.
1429 This hook might be invoked multiple times by a single command."
1434 ;;;_ = allout-structure-added-functions
1435 (define-obsolete-variable-alias 'allout-structure-added-hook
1436 'allout-structure-added-functions
"24.2")
1437 (defcustom allout-structure-added-functions nil
1438 "Abnormal hook run after adding items to an Allout outline.
1439 Functions on the hook should take two arguments:
1441 - NEW-START -- integer indicating position of start of the first new item.
1442 - NEW-END -- integer indicating position of end of the last new item.
1444 This hook might be invoked multiple times by a single command."
1449 ;;;_ = allout-structure-deleted-functions
1450 (define-obsolete-variable-alias 'allout-structure-deleted-hook
1451 'allout-structure-deleted-functions
"24.2")
1452 (defcustom allout-structure-deleted-functions nil
1453 "Abnormal hook run after deleting subtrees from an Allout outline.
1454 Functions on the hook must take two arguments:
1456 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1457 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1459 Some edits that remove or invalidate items may be missed by this hook:
1460 specifically edits that native allout routines do not control.
1462 This hook might be invoked multiple times by a single command."
1467 ;;;_ = allout-structure-shifted-functions
1468 (define-obsolete-variable-alias 'allout-structure-shifted-hook
1469 'allout-structure-shifted-functions
"24.2")
1470 (defcustom allout-structure-shifted-functions nil
1471 "Abnormal hook run after shifting items in an Allout outline.
1472 Functions on the hook should take two arguments:
1474 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1475 - START -- integer indicating the start point of the shifted parent item.
1477 Some edits that shift items can be missed by this hook: specifically edits
1478 that native allout routines do not control.
1480 This hook might be invoked multiple times by a single command."
1485 ;;;_ = allout-after-copy-or-kill-hook
1486 (defcustom allout-after-copy-or-kill-hook nil
1487 "Normal hook run after copying outline text.."
1492 ;;;_ = allout-post-undo-hook
1493 (defcustom allout-post-undo-hook nil
1494 "Normal hook run after undo activity.
1495 The item that's current when the hook is run *may* be the one
1496 that was affected by the undo.."
1501 ;;;_ = allout-outside-normal-auto-fill-function
1502 (defvar allout-outside-normal-auto-fill-function nil
1503 "Value of `normal-auto-fill-function' outside of allout mode.
1505 Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function'
1506 wrapped within allout's automatic `fill-prefix' setting.")
1507 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function
)
1508 ;;;_ = prevent redundant activation by desktop mode:
1509 (add-to-list 'desktop-minor-mode-handlers
'(allout-mode . nil
))
1510 ;;;_ = allout-passphrase-verifier-string
1511 (defvar allout-passphrase-verifier-string nil
1512 "Setting used to test solicited encryption passphrases against the one
1513 already associated with a file.
1515 It consists of an encrypted random string useful only to verify that a
1516 passphrase entered by the user is effective for decryption. The passphrase
1517 itself is \*not* recorded in the file anywhere, and the encrypted contents
1518 are random binary characters to avoid exposing greater susceptibility to
1521 The verifier string is retained as an Emacs file variable, as well as in
1522 the Emacs buffer state, if file variable adjustments are enabled. See
1523 `allout-enable-file-variable-adjustment' for details about that.")
1524 (make-variable-buffer-local 'allout-passphrase-verifier-string
)
1525 (make-obsolete 'allout-passphrase-verifier-string
1526 'allout-passphrase-verifier-string
"23.3")
1528 (put 'allout-passphrase-verifier-string
'safe-local-variable
'stringp
)
1529 ;;;_ = allout-passphrase-hint-string
1530 (defvar allout-passphrase-hint-string
""
1531 "Variable used to retain reminder string for file's encryption passphrase.
1533 See the description of `allout-passphrase-hint-handling' for details about how
1534 the reminder is deployed.
1536 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1537 state, if file variable adjustments are enabled. See
1538 `allout-enable-file-variable-adjustment' for details about that.")
1539 (make-variable-buffer-local 'allout-passphrase-hint-string
)
1540 (setq-default allout-passphrase-hint-string
"")
1541 (make-obsolete 'allout-passphrase-hint-string
1542 'allout-passphrase-hint-string
"23.3")
1544 (put 'allout-passphrase-hint-string
'safe-local-variable
'stringp
)
1545 ;;;_ = allout-after-save-decrypt
1546 (defvar allout-after-save-decrypt nil
1547 "Internal variable, is nil or has the value of two points:
1549 - the location of a topic to be decrypted after saving is done
1550 - where to situate the cursor after the decryption is performed
1552 This is used to decrypt the topic that was currently being edited, if it
1553 was encrypted automatically as part of a file write or autosave.")
1554 (make-variable-buffer-local 'allout-after-save-decrypt
)
1555 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1556 (defvar allout-encryption-plaintext-sanitization-regexps nil
1557 "List of regexps whose matches are removed from plaintext before encryption.
1559 This is for the sake of removing artifacts, like escapes, that are added on
1560 and not actually part of the original plaintext. The removal is done just
1561 prior to encryption.
1563 Entries must be symbols that are bound to the desired values.
1565 Each value can be a regexp or a list with a regexp followed by a
1566 substitution string. If it's just a regexp, all its matches are removed
1567 before the text is encrypted. If it's a regexp and a substitution, the
1568 substitution is used against the regexp matches, a la `replace-match'.")
1569 (make-variable-buffer-local 'allout-encryption-text-removal-regexps
)
1570 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1571 (defvar allout-encryption-ciphertext-rejection-regexps nil
1572 "Variable for regexps matching plaintext to remove before encryption.
1574 This is used to detect strings in encryption results that would
1575 register as allout mode structural elements, for example, as a
1578 Entries must be symbols that are bound to the desired regexp values.
1580 Encryptions that result in matches will be retried, up to
1581 `allout-encryption-ciphertext-rejection-limit' times, after which
1582 an error is raised.")
1584 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps
)
1585 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1586 (defvar allout-encryption-ciphertext-rejection-ceiling
5
1587 "Limit on number of times encryption ciphertext is rejected.
1589 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1590 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling
)
1591 ;;;_ > allout-mode-p ()
1592 ;; Must define this macro above any uses, or byte compilation will lack
1593 ;; proper def, if file isn't loaded -- eg, during emacs build!
1595 (defmacro allout-mode-p
()
1596 "Return t if `allout-mode' is active in current buffer."
1598 ;;;_ > allout-write-contents-hook-handler ()
1599 (defun allout-write-contents-hook-handler ()
1600 "Implement `allout-encrypt-unencrypted-on-saves' for file writes
1602 Return nil if all goes smoothly, or else return an informative
1603 message if an error is encountered. The message will serve as a
1604 non-nil return on `write-contents-functions' to prevent saving of
1605 the buffer while it has decrypted content.
1607 This behavior depends on Emacs versions that implement the
1608 `write-contents-functions' hook."
1610 (if (or (not (allout-mode-p))
1611 (not (boundp 'allout-encrypt-unencrypted-on-saves
))
1612 (not allout-encrypt-unencrypted-on-saves
))
1614 (if (save-excursion (goto-char (point-min))
1615 (allout-next-topic-pending-encryption))
1617 (message "auto-encrypting pending topics")
1619 (condition-case failure
1621 (setq allout-after-save-decrypt
1622 (allout-encrypt-decrypted))
1623 ;; aok - return nil:
1626 ;; whoops - probably some still-decrypted items, return non-nil:
1627 (let ((text (format (concat "%s contents write inhibited due to"
1628 " encrypted topic encryption error:"
1630 (buffer-name (current-buffer))
1632 (message text
)(sit-for 2)
1635 ;;;_ > allout-after-saves-handler ()
1636 (defun allout-after-saves-handler ()
1637 "Decrypt topic encrypted for save, if it's currently being edited.
1639 Ie, if it was pending encryption and contained the point in its body before
1642 We use values stored in `allout-after-save-decrypt' to locate the topic
1643 and the place for the cursor after the decryption is done."
1644 (if (not (and (allout-mode-p)
1645 (boundp 'allout-after-save-decrypt
)
1646 allout-after-save-decrypt
))
1648 (goto-char (car allout-after-save-decrypt
))
1649 (let ((was-modified (buffer-modified-p)))
1650 (allout-toggle-subtree-encryption)
1651 (if (not was-modified
)
1652 (set-buffer-modified-p nil
)))
1653 (goto-char (cadr allout-after-save-decrypt
))
1654 (setq allout-after-save-decrypt nil
))
1656 ;;;_ > allout-called-interactively-p ()
1657 (defmacro allout-called-interactively-p
()
1658 "A version of `called-interactively-p' independent of Emacs version."
1659 ;; ... to ease maintenance of allout without betraying deprecation.
1660 (if (equal (subr-arity (symbol-function 'called-interactively-p
))
1662 '(called-interactively-p)
1663 '(called-interactively-p 'interactive
)))
1664 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1665 ;; In some exceptional moments, disparate topic depths need to be allowed
1666 ;; momentarily, eg when one topic is being yanked into another and they're
1667 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1668 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1669 ;; processing to happen in the presence of such discrepancies. It should
1670 ;; almost never be needed, however.
1671 (defvar allout-inhibit-aberrance-doublecheck nil
1672 "Internal state, for momentarily inhibits aberrance doublecheck.
1674 This should only be momentarily let-bound non-nil, not set
1675 non-nil in a lasting way.")
1677 ;;;_ #2 Mode environment and activation
1678 ;;;_ = allout-explicitly-deactivated
1679 (defvar allout-explicitly-deactivated nil
1680 "If t, `allout-mode's last deactivation was deliberate.
1681 So `allout-post-command-business' should not reactivate it...")
1682 (make-variable-buffer-local 'allout-explicitly-deactivated
)
1683 ;;;_ > allout-init (mode)
1684 (defun allout-init (mode)
1685 "DEPRECATED - configure allout activation by customizing
1686 `allout-auto-activation'. This function remains around, limited
1687 from what it did before, for backwards compatibility.
1689 MODE is the activation mode - see `allout-auto-activation' for
1692 (custom-set-variables (list 'allout-auto-activation
(format "%s" mode
)))
1694 (make-obsolete 'allout-init
1695 "customize 'allout-auto-activation' instead." "23.3")
1696 ;;;_ > allout-setup-menubar ()
1697 (defun allout-setup-menubar ()
1698 "Populate the current buffer's menubar with `allout-mode' stuff."
1699 (let ((menus (list allout-mode-exposure-menu
1700 allout-mode-editing-menu
1701 allout-mode-navigation-menu
1702 allout-mode-misc-menu
))
1705 (setq cur
(car menus
)
1707 (easy-menu-add cur
))))
1708 ;;;_ > allout-overlay-preparations
1709 (defun allout-overlay-preparations ()
1710 "Set the properties of the allout invisible-text overlay and others."
1711 (setplist 'allout-exposure-category nil
)
1712 (put 'allout-exposure-category
'invisible
'allout
)
1713 (put 'allout-exposure-category
'evaporate t
)
1714 ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
1715 ;; latter would be sufficient, but it seems that a separate behavior --
1716 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1717 ;; presence of the isearch-open-invisible property -- even though this
1718 ;; property controls the isearch _arrival_ behavior. This is the case at
1719 ;; least in emacs 21, 22.1, and xemacs 21.4.
1720 (put 'allout-exposure-category
'isearch-open-invisible
1721 'allout-isearch-end-handler
)
1722 (if (featurep 'xemacs
)
1723 (put 'allout-exposure-category
'start-open t
)
1724 (put 'allout-exposure-category
'insert-in-front-hooks
1725 '(allout-overlay-insert-in-front-handler)))
1726 (put 'allout-exposure-category
'modification-hooks
1727 '(allout-overlay-interior-modification-handler)))
1728 ;;;_ > define-minor-mode allout-mode
1731 (define-minor-mode allout-mode
1733 "Toggle Allout outline mode.
1734 With a prefix argument ARG, enable Allout outline mode if ARG is
1735 positive, and disable it otherwise. If called from Lisp, enable
1736 the mode if ARG is omitted or nil.
1738 \\<allout-mode-map-value>
1739 Allout outline mode is a minor mode that provides extensive
1740 outline oriented formatting and manipulation. It enables
1741 structural editing of outlines, as well as navigation and
1742 exposure. It also is specifically aimed at accommodating
1743 syntax-sensitive text like programming languages. (For example,
1744 see the allout code itself, which is organized as an allout
1747 In addition to typical outline navigation and exposure, allout includes:
1749 - topic-oriented authoring, including keystroke-based topic creation,
1750 repositioning, promotion/demotion, cut, and paste
1751 - incremental search with dynamic exposure and reconcealment of hidden text
1752 - adjustable format, so programming code can be developed in outline-structure
1753 - easy topic encryption and decryption, symmetric or key-pair
1754 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1755 - integral outline layout, for automatic initial exposure when visiting a file
1756 - independent extensibility, using comprehensive exposure and authoring hooks
1758 and many other features.
1760 Below is a description of the key bindings, and then description
1761 of special `allout-mode' features and terminology. See also the
1762 outline menubar additions for quick reference to many of the
1763 features. Customize `allout-auto-activation' to prepare your
1764 Emacs session for automatic activation of `allout-mode'.
1766 The bindings are those listed in `allout-prefixed-keybindings'
1767 and `allout-unprefixed-keybindings'. We recommend customizing
1768 `allout-command-prefix' to use just `\\C-c' as the command
1769 prefix, if the allout bindings don't conflict with any personal
1770 bindings you have on \\C-c. In any case, outline structure
1771 navigation and authoring is simplified by positioning the cursor
1772 on an item's bullet character, the \"hot-spot\" -- then you can
1773 invoke allout commands with just the un-prefixed,
1774 un-control-shifted command letters. This is described further in
1775 the HOT-SPOT Operation section.
1779 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1780 \\[allout-show-children] `allout-show-children'
1781 \\[allout-show-current-subtree] `allout-show-current-subtree'
1782 \\[allout-show-current-entry] `allout-show-current-entry'
1783 \\[allout-show-all] `allout-show-all'
1787 \\[allout-next-visible-heading] `allout-next-visible-heading'
1788 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1789 \\[allout-up-current-level] `allout-up-current-level'
1790 \\[allout-forward-current-level] `allout-forward-current-level'
1791 \\[allout-backward-current-level] `allout-backward-current-level'
1792 \\[allout-end-of-entry] `allout-end-of-entry'
1793 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1794 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1795 if immediately repeated cycles to the beginning of the current item
1796 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1799 Topic Header Production:
1800 -----------------------
1801 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1802 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1803 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1805 Topic Level and Prefix Adjustment:
1806 ---------------------------------
1807 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1808 \\[allout-shift-out] `allout-shift-out' ... less deep
1809 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1811 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1812 its offspring -- distinctive bullets are not changed, others
1813 are alternated according to nesting depth.
1814 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1815 the offspring are not affected.
1816 With repeat count, revoke numbering.
1818 Topic-oriented Killing and Yanking:
1819 ----------------------------------
1820 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1821 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1822 \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure.
1823 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1824 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1825 depth of heading if yanking into bare topic
1826 heading (ie, prefix sans text).
1827 \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'.
1829 Topic-oriented Encryption:
1830 -------------------------
1831 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1832 Encrypt/Decrypt topic content
1836 M-x outlineify-sticky Activate outline mode for current buffer,
1837 and establish a default file-var setting
1838 for `allout-layout'.
1839 \\[allout-mark-topic] `allout-mark-topic'
1840 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1841 Duplicate outline, sans concealed text, to
1842 buffer with name derived from derived from that
1843 of current buffer -- \"*BUFFERNAME exposed*\".
1844 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1845 Like above 'copy-exposed', but convert topic
1846 prefixes to section.subsection... numeric
1848 \\[customize-variable] allout-auto-activation
1849 Prepare Emacs session for allout outline mode
1854 Outline mode supports gpg encryption of topics, with support for
1855 symmetric and key-pair modes, and auto-encryption of topics
1856 pending encryption on save.
1858 Topics pending encryption are, by default, automatically
1859 encrypted during file saves, including checkpoint saves, to avoid
1860 exposing the plain text of encrypted topics in the file system.
1861 If the content of the topic containing the cursor was encrypted
1862 for a save, it is automatically decrypted for continued editing.
1864 NOTE: A few GnuPG v2 versions improperly preserve incorrect
1865 symmetric decryption keys, preventing entry of the correct key on
1866 subsequent decryption attempts until the cache times-out. That
1867 can take several minutes. (Decryption of other entries is not
1868 affected.) Upgrade your EasyPG version, if you can, and you can
1869 deliberately clear your gpg-agent's cache by sending it a '-HUP'
1872 See `allout-toggle-current-subtree-encryption' function docstring
1873 and `allout-encrypt-unencrypted-on-saves' customization variable
1878 Hot-spot operation provides a means for easy, single-keystroke outline
1879 navigation and exposure control.
1881 When the text cursor is positioned directly on the bullet character of
1882 a topic, regular characters (a to z) invoke the commands of the
1883 corresponding allout-mode keymap control chars. For example, \"f\"
1884 would invoke the command typically bound to \"C-c<space>C-f\"
1885 \(\\[allout-forward-current-level] `allout-forward-current-level').
1887 Thus, by positioning the cursor on a topic bullet, you can
1888 execute the outline navigation and manipulation commands with a
1889 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1890 this special translation, so you can use them to get out of the
1891 hot-spot and back to normal editing operation.
1893 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
1894 replaced with one that makes it easy to get to the hot-spot. If you
1895 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1896 is set) to the beginning of the item and then, if you hit it again
1897 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1898 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1899 at the beginning of the current entry.
1903 Allout exposure and authoring activities all have associated
1904 hooks, by which independent code can cooperate with allout
1905 without changes to the allout core. Here are key ones:
1908 `allout-mode-deactivate-hook' (deprecated)
1909 `allout-mode-off-hook'
1910 `allout-exposure-change-functions'
1911 `allout-structure-added-functions'
1912 `allout-structure-deleted-functions'
1913 `allout-structure-shifted-functions'
1914 `allout-after-copy-or-kill-hook'
1915 `allout-post-undo-hook'
1919 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1921 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1922 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1923 and with no intervening items of lower DEPTH than the container.
1925 The visible ITEM most immediately containing the cursor.
1926 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1927 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1929 LEVEL: The same as DEPTH.
1932 Those ITEMs whose TOPICs contain an ITEM.
1933 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1936 The ITEMs contained within an ITEM's TOPIC.
1938 An OFFSPRING of its ANCESTOR TOPICs.
1940 An immediate SUBTOPIC of its PARENT.
1942 TOPICs having the same PARENT and DEPTH.
1944 Topic text constituents:
1946 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1948 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1949 the HEADER text and distinct from the ITEM PREFIX.
1950 BODY: Same as ENTRY.
1951 PREFIX: The leading text of an ITEM which distinguishes it from normal
1952 ENTRY text. Allout recognizes the outline structure according
1953 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1954 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1955 number, indicating the ordinal number of the topic among its
1956 siblings, or an asterisk indicating encryption, plus an optional
1957 space. After that is the ITEM HEADER text, which is not part of
1960 The relative length of the PREFIX determines the nesting DEPTH
1963 The string at the beginning of a HEADER PREFIX, by default a `.'.
1964 It can be customized by changing the setting of
1965 `allout-header-prefix' and then reinitializing `allout-mode'.
1967 When the PREFIX-LEAD is set to the comment-string of a
1968 programming language, outline structuring can be embedded in
1969 program code without interfering with processing of the text
1970 (by Emacs or the language processor) as program code. This
1971 setting happens automatically when allout mode is used in
1972 programming-mode buffers. See `allout-use-mode-specific-leader'
1973 docstring for more detail.
1975 Spaces or asterisks which separate the PREFIX-LEAD and the
1976 bullet, determining the ITEM's DEPTH.
1977 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1978 the characters listed on `allout-plain-bullets-string' or
1979 `allout-distinctive-bullets-string'. When creating a TOPIC,
1980 plain BULLETs are by default used, according to the DEPTH of the
1981 TOPIC. Choice among the distinctive BULLETs is offered when you
1982 provide a universal argument (\\[universal-argument]) to the
1983 TOPIC creation command, or when explicitly rebulleting a TOPIC. The
1984 significance of the various distinctive bullets is purely by
1985 convention. See the documentation for the above bullet strings for
1988 The state of a TOPIC which determines the on-screen visibility
1989 of its OFFSPRING and contained ENTRY text.
1991 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1992 text is represented by \"...\" ellipses.
1994 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1995 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1996 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1999 :keymap
'allout-mode-map
2001 (let ((use-layout (if (listp allout-layout
)
2003 allout-default-layout
)))
2005 (if (not (allout-mode-p))
2009 ; Activation not explicitly
2010 ; requested, and either in
2011 ; active state or *de*activation
2012 ; specifically requested:
2013 (allout-do-resumptions)
2015 (remove-from-invisibility-spec '(allout . t
))
2016 (remove-hook 'pre-command-hook
'allout-pre-command-business t
)
2017 (remove-hook 'post-command-hook
'allout-post-command-business t
)
2018 (remove-hook 'before-change-functions
'allout-before-change-handler t
)
2019 (remove-hook 'isearch-mode-end-hook
'allout-isearch-end-handler t
)
2020 (remove-hook 'write-contents-functions
2021 'allout-write-contents-hook-handler t
)
2023 (remove-overlays (point-min) (point-max)
2024 'category
'allout-exposure-category
))
2027 (if allout-old-style-prefixes
2028 ;; Inhibit all the fancy formatting:
2029 (allout-add-resumptions '(allout-primary-bullet "*")))
2031 (allout-overlay-preparations) ; Doesn't hurt to redo this.
2033 (allout-infer-header-lead-and-primary-bullet)
2034 (allout-infer-body-reindent)
2037 (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
2038 allout-line-boundary-regexp
2040 '(allout-encryption-ciphertext-rejection-regexps
2044 (allout-compose-and-institute-keymap)
2045 (produce-allout-mode-menubar-entries)
2047 (add-to-invisibility-spec '(allout . t
))
2049 (allout-add-resumptions '(line-move-ignore-invisible t
))
2050 (add-hook 'pre-command-hook
'allout-pre-command-business nil t
)
2051 (add-hook 'post-command-hook
'allout-post-command-business nil t
)
2052 (add-hook 'before-change-functions
'allout-before-change-handler nil t
)
2053 (add-hook 'isearch-mode-end-hook
'allout-isearch-end-handler nil t
)
2054 (add-hook 'write-contents-functions
'allout-write-contents-hook-handler
2057 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2058 ;; func will be used if auto-fill is active or activated. (The
2059 ;; custom func respects topic headline, maintains hanging-indents,
2061 (allout-add-resumptions (list 'allout-former-auto-filler
2063 ;; Register allout-auto-fill to be used if
2064 ;; filling is active:
2065 (list 'allout-outside-normal-auto-fill-function
2066 normal-auto-fill-function
)
2067 '(normal-auto-fill-function allout-auto-fill
)
2068 ;; Paragraphs are broken by topic headlines.
2069 (list 'paragraph-start
2070 (concat paragraph-start
"\\|^\\("
2071 allout-regexp
"\\)"))
2072 (list 'paragraph-separate
2073 (concat paragraph-separate
"\\|^\\("
2074 allout-regexp
"\\)")))
2075 (if (and auto-fill-function
(not allout-inhibit-auto-fill
))
2076 ;; allout-auto-fill will use the stashed values and so forth.
2077 (allout-add-resumptions '(auto-fill-function allout-auto-fill
)))
2079 (allout-setup-menubar)
2081 ;; Do auto layout if warranted:
2082 (when (and allout-layout
2083 allout-auto-activation
2085 (and (not (string= allout-auto-activation
"activate"))
2086 (if (string= allout-auto-activation
"ask")
2087 (if (y-or-n-p (format "Expose %s with layout '%s'? "
2091 (message "Skipped %s layout." (buffer-name))
2095 (message "Adjusting '%s' exposure..." (buffer-name))
2097 (allout-this-or-next-heading)
2100 (apply 'allout-expose-topic
(list use-layout
))
2101 (message "Adjusting '%s' exposure... done."
2103 ;; Problem applying exposure -- notify user, but don't
2104 ;; interrupt, eg, file visit:
2105 (error (message "%s" (car (cdr err
)))
2107 ) ; when allout-layout
2108 ) ; if (allout-mode-p)
2110 ) ; define-minor-mode
2111 ;;;_ > allout-minor-mode alias
2112 (defalias 'allout-minor-mode
'allout-mode
)
2113 ;;;_ > allout-unload-function
2114 (defun allout-unload-function ()
2115 "Unload the allout outline library."
2116 (save-current-buffer
2117 (dolist (buffer (buffer-list))
2119 (when (allout-mode-p) (allout-mode -
1))))
2120 ;; continue standard unloading
2123 ;;;_ - Position Assessment
2124 ;;;_ > allout-hidden-p (&optional pos)
2125 (defsubst allout-hidden-p
(&optional pos
)
2126 "Non-nil if the character after point was made invisible by allout."
2127 (eq (get-char-property (or pos
(point)) 'invisible
) 'allout
))
2129 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2130 ;;; &optional prelen)
2131 (defun allout-overlay-insert-in-front-handler (ol after beg end
2133 "Shift the overlay so stuff inserted in front of it is excluded."
2135 ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
2136 ;; front-advance on the overlay worked as expected?
2137 (move-overlay ol
(1+ beg
) (overlay-end ol
))))
2138 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2139 ;;; &optional prelen)
2140 (defun allout-overlay-interior-modification-handler (ol after beg end
2142 "Get confirmation before making arbitrary changes to invisible text.
2144 We expose the invisible text and ask for confirmation. Refusal or
2145 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2146 reclosing the opened text.
2148 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2149 internal functions use this feature cohesively bunch changes."
2151 (when (and (not inhibit-read-only
) (not after
))
2152 (let ((start (point))
2153 (ol-start (overlay-start ol
))
2154 (ol-end (overlay-end ol
))
2157 (while (< (point) end
)
2158 (when (allout-hidden-p)
2159 (allout-show-to-offshoot)
2160 (if (allout-hidden-p)
2161 (save-excursion (forward-char 1)
2162 (allout-show-to-offshoot)))
2164 (setq first
(point))))
2165 (goto-char (if (featurep 'xemacs
)
2166 (next-property-change (1+ (point)) nil end
)
2167 (next-char-property-change (1+ (point)) end
))))
2173 (substitute-command-keys
2174 (concat "Modify concealed text? (\"no\" just aborts,"
2175 " \\[keyboard-quit] also reconceals) "))))
2176 (progn (goto-char start
)
2177 (error "Concealed-text change refused")))
2178 (quit (allout-flag-region ol-start ol-end nil
)
2179 (allout-flag-region ol-start ol-end t
)
2180 (error "Concealed-text change abandoned, text reconcealed"))))
2181 (goto-char start
))))
2182 ;;;_ > allout-before-change-handler (beg end)
2183 (defun allout-before-change-handler (beg end
)
2184 "Protect against changes to invisible text.
2186 See `allout-overlay-interior-modification-handler' for details."
2188 (when (and (allout-mode-p) undo-in-progress
)
2189 (setq allout-just-did-undo t
)
2190 (if (allout-hidden-p)
2191 (allout-show-children)))
2193 ;; allout-overlay-interior-modification-handler on an overlay handles
2194 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2195 (when (and (featurep 'xemacs
) (allout-mode-p))
2196 ;; process all of the pending overlays:
2199 (let ((overlay (allout-get-invisibility-overlay)))
2201 (allout-overlay-interior-modification-handler
2202 overlay nil beg end nil
))))))
2203 ;;;_ > allout-isearch-end-handler (&optional overlay)
2204 (defun allout-isearch-end-handler (&optional overlay
)
2205 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2207 Optional OVERLAY parameter is for when this function is used by
2208 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2209 function can also be used as an `isearch-mode-end-hook'."
2211 (if (and (allout-mode-p) (allout-hidden-p))
2212 (allout-show-to-offshoot)))
2214 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2215 ;; All the basic outline functions that directly do string matches to
2216 ;; evaluate heading prefix location set the variables
2217 ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2218 ;; when successful. Functions starting with `allout-recent-' all
2219 ;; use this state, providing the means to avoid redundant searches
2220 ;; for just-established data. This optimization can provide
2221 ;; significant speed improvement, but it must be employed carefully.
2222 ;;;_ = allout-recent-prefix-beginning
2223 (defvar allout-recent-prefix-beginning
0
2224 "Buffer point of the start of the last topic prefix encountered.")
2225 (make-variable-buffer-local 'allout-recent-prefix-beginning
)
2226 ;;;_ = allout-recent-prefix-end
2227 (defvar allout-recent-prefix-end
0
2228 "Buffer point of the end of the last topic prefix encountered.")
2229 (make-variable-buffer-local 'allout-recent-prefix-end
)
2230 ;;;_ = allout-recent-depth
2231 (defvar allout-recent-depth
0
2232 "Depth of the last topic prefix encountered.")
2233 (make-variable-buffer-local 'allout-recent-depth
)
2234 ;;;_ = allout-recent-end-of-subtree
2235 (defvar allout-recent-end-of-subtree
0
2236 "Buffer point last returned by `allout-end-of-current-subtree'.")
2237 (make-variable-buffer-local 'allout-recent-end-of-subtree
)
2238 ;;;_ > allout-prefix-data ()
2239 (defsubst allout-prefix-data
()
2240 "Register allout-prefix state data.
2242 For reference by `allout-recent' funcs. Return
2243 the new value of `allout-recent-prefix-beginning'."
2244 (setq allout-recent-prefix-end
(or (match-end 1) (match-end 2) (match-end 3))
2245 allout-recent-prefix-beginning
(or (match-beginning 1)
2247 (match-beginning 3))
2248 allout-recent-depth
(max 1 (- allout-recent-prefix-end
2249 allout-recent-prefix-beginning
2250 allout-header-subtraction
)))
2251 allout-recent-prefix-beginning
)
2252 ;;;_ > nullify-allout-prefix-data ()
2253 (defsubst nullify-allout-prefix-data
()
2254 "Mark allout prefix data as being uninformative."
2255 (setq allout-recent-prefix-end
(point)
2256 allout-recent-prefix-beginning
(point)
2257 allout-recent-depth
0)
2258 allout-recent-prefix-beginning
)
2259 ;;;_ > allout-recent-depth ()
2260 (defsubst allout-recent-depth
()
2261 "Return depth of last heading encountered by an outline maneuvering function.
2263 All outline functions which directly do string matches to assess
2264 headings set the variables `allout-recent-prefix-beginning' and
2265 `allout-recent-prefix-end' if successful. This function uses those settings
2266 to return the current depth."
2268 allout-recent-depth
)
2269 ;;;_ > allout-recent-prefix ()
2270 (defsubst allout-recent-prefix
()
2271 "Like `allout-recent-depth', but returns text of last encountered prefix.
2273 All outline functions which directly do string matches to assess
2274 headings set the variables `allout-recent-prefix-beginning' and
2275 `allout-recent-prefix-end' if successful. This function uses those settings
2276 to return the current prefix."
2277 (buffer-substring-no-properties allout-recent-prefix-beginning
2278 allout-recent-prefix-end
))
2279 ;;;_ > allout-recent-bullet ()
2280 (defmacro allout-recent-bullet
()
2281 "Like `allout-recent-prefix', but returns bullet of last encountered prefix.
2283 All outline functions which directly do string matches to assess
2284 headings set the variables `allout-recent-prefix-beginning' and
2285 `allout-recent-prefix-end' if successful. This function uses those settings
2286 to return the current depth of the most recently matched topic."
2287 '(buffer-substring-no-properties (1- allout-recent-prefix-end
)
2288 allout-recent-prefix-end
))
2292 ;;;_ - Position Assessment
2293 ;;;_ : Location Predicates
2294 ;;;_ > allout-do-doublecheck ()
2295 (defsubst allout-do-doublecheck
()
2296 "True if current item conditions qualify for checking on topic aberrance."
2298 ;; presume integrity of outline and yanked content during yank -- necessary
2299 ;; to allow for level disparity of yank location and yanked text:
2300 (not allout-inhibit-aberrance-doublecheck
)
2301 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2302 (<= allout-recent-depth allout-doublecheck-at-and-shallower
)))
2303 ;;;_ > allout-aberrant-container-p ()
2304 (defun allout-aberrant-container-p ()
2305 "True if topic, or next sibling with children, contains them discontinuously.
2307 Discontinuous means an immediate offspring that is nested more
2308 than one level deeper than the topic.
2310 If topic has no offspring, then the next sibling with offspring will
2311 determine whether or not this one is determined to be aberrant.
2313 If true, then the allout-recent-* settings are calibrated on the
2314 offspring that qualifies it as aberrant, ie with depth that
2315 exceeds the topic by more than one."
2317 ;; This is most clearly understood when considering standard-prefix-leader
2318 ;; low-level topics, which can all too easily match text not intended as
2319 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2320 ;; following bullet qualifies without this protection. (A sequence of
2321 ;; them can occur naturally, eg a typical textual bullet list.) We
2322 ;; disqualify such low-level sequences when they are followed by a
2323 ;; discontinuously contained child, inferring that the sequences are not
2324 ;; actually connected with their prospective context.
2326 (let ((depth (allout-depth))
2327 (start-point (point))
2331 (while (and (not done
)
2332 (re-search-forward allout-line-boundary-regexp nil
0))
2333 (allout-prefix-data)
2334 (goto-char allout-recent-prefix-beginning
)
2336 ;; sibling -- continue:
2337 ((eq allout-recent-depth depth
))
2338 ;; first offspring is excessive -- aberrant:
2339 ((> allout-recent-depth
(1+ depth
))
2340 (setq done t aberrant t
))
2341 ;; next non-sibling is lower-depth -- not aberrant:
2342 (t (setq done t
))))))
2345 (goto-char start-point
)
2346 ;; recalibrate allout-recent-*
2349 ;;;_ > allout-on-current-heading-p ()
2350 (defun allout-on-current-heading-p ()
2351 "Return non-nil if point is on current visible topics' header line.
2353 Actually, returns prefix beginning point."
2355 (allout-beginning-of-current-line)
2357 (and (looking-at allout-regexp
)
2358 (allout-prefix-data)
2359 (or (not (allout-do-doublecheck))
2360 (not (allout-aberrant-container-p)))))))
2361 ;;;_ > allout-on-heading-p ()
2362 (defalias 'allout-on-heading-p
'allout-on-current-heading-p
)
2363 ;;;_ > allout-e-o-prefix-p ()
2364 (defun allout-e-o-prefix-p ()
2365 "True if point is located where current topic prefix ends, heading begins."
2366 (and (save-match-data
2367 (save-excursion (let ((inhibit-field-text-motion t
))
2368 (beginning-of-line))
2369 (looking-at allout-regexp
))
2370 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2371 ;;;_ : Location attributes
2372 ;;;_ > allout-depth ()
2373 (defun allout-depth ()
2374 "Return depth of topic most immediately containing point.
2376 Does not do doublecheck for aberrant topic header.
2378 Return zero if point is not within any topic.
2380 Like `allout-current-depth', but respects hidden as well as visible topics."
2382 (let ((start-point (point)))
2383 (if (and (allout-goto-prefix)
2384 (not (< start-point
(point))))
2387 ;; Oops, no prefix, nullify it:
2388 (nullify-allout-prefix-data)
2389 ;; ... and return 0:
2391 ;;;_ > allout-current-depth ()
2392 (defun allout-current-depth ()
2393 "Return depth of visible topic most immediately containing point.
2395 Return zero if point is not within any topic."
2397 (if (allout-back-to-current-heading)
2399 (- allout-recent-prefix-end
2400 allout-recent-prefix-beginning
2401 allout-header-subtraction
))
2403 ;;;_ > allout-get-current-prefix ()
2404 (defun allout-get-current-prefix ()
2405 "Topic prefix of the current topic."
2407 (if (allout-goto-prefix)
2408 (allout-recent-prefix))))
2409 ;;;_ > allout-get-bullet ()
2410 (defun allout-get-bullet ()
2411 "Return bullet of containing topic (visible or not)."
2413 (and (allout-goto-prefix)
2414 (allout-recent-bullet))))
2415 ;;;_ > allout-current-bullet ()
2416 (defun allout-current-bullet ()
2417 "Return bullet of current (visible) topic heading, or none if none found."
2420 (allout-back-to-current-heading)
2421 (buffer-substring-no-properties (- allout-recent-prefix-end
1)
2422 allout-recent-prefix-end
))
2423 ;; Quick and dirty provision, ostensibly for missing bullet:
2424 (args-out-of-range nil
))
2426 ;;;_ > allout-get-prefix-bullet (prefix)
2427 (defun allout-get-prefix-bullet (prefix)
2428 "Return the bullet of the header prefix string PREFIX."
2429 ;; Doesn't make sense if we're old-style prefixes, but this just
2430 ;; oughtn't be called then, so forget about it...
2431 (if (string-match allout-regexp prefix
)
2432 (substring prefix
(1- (match-end 2)) (match-end 2))))
2433 ;;;_ > allout-sibling-index (&optional depth)
2434 (defun allout-sibling-index (&optional depth
)
2435 "Item number of this prospective topic among its siblings.
2437 If optional arg DEPTH is greater than current depth, then we're
2438 opening a new level, and return 0.
2440 If less than this depth, ascend to that depth and count..."
2443 (cond ((and depth
(<= depth
0) 0))
2444 ((or (null depth
) (= depth
(allout-depth)))
2446 (while (allout-previous-sibling allout-recent-depth nil
)
2447 (setq index
(1+ index
)))
2449 ((< depth allout-recent-depth
)
2450 (allout-ascend-to-depth depth
)
2451 (allout-sibling-index))
2453 ;;;_ > allout-topic-flat-index ()
2454 (defun allout-topic-flat-index ()
2455 "Return a list indicating point's numeric section.subsect.subsubsect...
2456 Outermost is first."
2457 (let* ((depth (allout-depth))
2458 (next-index (allout-sibling-index depth
))
2460 (while (> next-index
0)
2461 (setq rev-sibls
(cons next-index rev-sibls
))
2462 (setq depth
(1- depth
))
2463 (setq next-index
(allout-sibling-index depth
)))
2467 ;;;_ - Navigation routines
2468 ;;;_ > allout-beginning-of-current-line ()
2469 (defun allout-beginning-of-current-line ()
2470 "Like beginning of line, but to visible text."
2472 ;; This combination of move-beginning-of-line and beginning-of-line is
2473 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2474 (let ((inhibit-field-text-motion t
))
2475 (move-beginning-of-line 1)
2477 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2479 (if (or (allout-hidden-p) (not (bolp)))
2480 (forward-char -
1)))))
2481 ;;;_ > allout-end-of-current-line ()
2482 (defun allout-end-of-current-line ()
2483 "Move to the end of line, past concealed text if any."
2484 ;; This is for symmetry with `allout-beginning-of-current-line' --
2485 ;; `move-end-of-line' doesn't suffer the same problem as
2486 ;; `move-beginning-of-line'.
2487 (let ((inhibit-field-text-motion t
))
2489 (while (allout-hidden-p)
2491 (if (allout-hidden-p) (forward-char 1)))))
2492 ;;;_ > allout-beginning-of-line ()
2493 (defun allout-beginning-of-line ()
2494 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2498 (if (or (not allout-beginning-of-line-cycles
)
2499 (not (equal last-command this-command
)))
2501 (if (and (not (bolp))
2502 (allout-hidden-p (1- (point))))
2503 (goto-char (allout-previous-single-char-property-change
2504 (1- (point)) 'invisible
)))
2505 (move-beginning-of-line 1))
2507 (let ((beginning-of-body
2509 (while (and (allout-do-doublecheck)
2510 (allout-aberrant-container-p)
2511 (allout-previous-visible-heading 1)))
2512 (allout-beginning-of-current-entry)
2514 (cond ((= (current-column) 0)
2515 (goto-char beginning-of-body
))
2516 ((< (point) beginning-of-body
)
2517 (allout-beginning-of-current-line))
2518 ((= (point) beginning-of-body
)
2519 (goto-char (allout-current-bullet-pos)))
2520 (t (allout-beginning-of-current-line)
2521 (if (< (point) beginning-of-body
)
2522 ;; we were on the headline after its start:
2523 (goto-char beginning-of-body
)))))))
2524 ;;;_ > allout-end-of-line ()
2525 (defun allout-end-of-line ()
2526 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2530 (if (or (not allout-end-of-line-cycles
)
2531 (not (equal last-command this-command
)))
2532 (allout-end-of-current-line)
2533 (let ((end-of-entry (save-excursion
2534 (allout-end-of-entry)
2537 (allout-end-of-current-line))
2538 ((or (allout-hidden-p) (save-excursion
2541 (allout-back-to-current-heading)
2542 (allout-show-current-entry)
2543 (allout-show-children)
2544 (allout-end-of-entry))
2545 ((>= (point) end-of-entry
)
2546 (allout-back-to-current-heading)
2547 (allout-end-of-current-line))
2549 (if (not (allout-mark-active-p))
2551 (allout-end-of-entry))))))
2552 ;;;_ > allout-mark-active-p ()
2553 (defun allout-mark-active-p ()
2554 "True if the mark is currently or always active."
2555 ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
2556 ;; provisions, at least in GNU Emacs to prevent warnings about lack of,
2557 ;; eg, region-active-p.
2558 (cond ((boundp 'mark-active
)
2560 ((fboundp 'region-active-p
)
2563 ;;;_ > allout-next-heading ()
2564 (defsubst allout-next-heading
()
2565 "Move to the heading for the topic (possibly invisible) after this one.
2567 Returns the location of the heading, or nil if none found.
2569 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2572 (if (looking-at allout-regexp
)
2575 (when (re-search-forward allout-line-boundary-regexp nil
0)
2576 (allout-prefix-data)
2577 (goto-char allout-recent-prefix-beginning
)
2580 (and (allout-do-doublecheck)
2581 ;; this will set allout-recent-* on the first non-aberrant topic,
2582 ;; whether it's the current one or one that disqualifies it:
2583 (allout-aberrant-container-p))
2584 ;; this may or may not be the same as above depending on doublecheck:
2585 (goto-char allout-recent-prefix-beginning
))))
2586 ;;;_ > allout-this-or-next-heading
2587 (defun allout-this-or-next-heading ()
2588 "Position cursor on current or next heading."
2589 ;; A throwaway non-macro that is defined after allout-next-heading
2590 ;; and usable by allout-mode.
2591 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2592 ;;;_ > allout-previous-heading ()
2593 (defun allout-previous-heading ()
2594 "Move to the prior (possibly invisible) heading line.
2596 Return the location of the beginning of the heading, or nil if not found.
2598 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2602 (let ((start-point (point)))
2603 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2604 (allout-goto-prefix)
2606 (when (or (re-search-backward allout-line-boundary-regexp nil
0)
2607 (looking-at allout-bob-regexp
))
2608 (goto-char (allout-prefix-data))
2609 (if (and (allout-do-doublecheck)
2610 (allout-aberrant-container-p))
2611 (or (allout-previous-heading)
2612 (and (goto-char start-point
)
2613 ;; recalibrate allout-recent-*:
2617 ;;;_ > allout-get-invisibility-overlay ()
2618 (defun allout-get-invisibility-overlay ()
2619 "Return the overlay at point that dictates allout invisibility."
2620 (let ((overlays (overlays-at (point)))
2622 (while (and overlays
(not got
))
2623 (if (equal (overlay-get (car overlays
) 'invisible
) 'allout
)
2624 (setq got
(car overlays
))
2627 ;;;_ > allout-back-to-visible-text ()
2628 (defun allout-back-to-visible-text ()
2629 "Move to most recent prior character that is visible, and return point."
2630 (if (allout-hidden-p)
2631 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2634 ;;;_ - Subtree Charting
2635 ;;;_ " These routines either produce or assess charts, which are
2636 ;;; nested lists of the locations of topics within a subtree.
2638 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2639 ;;; for elaborate, compound assessment and adjustment of a subtree.
2641 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2642 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth
)
2643 "Produce a location \"chart\" of subtopics of the containing topic.
2645 Optional argument LEVELS specifies a depth limit (relative to start
2646 depth) for the chart. Null LEVELS means no limit.
2648 When optional argument VISIBLE is non-nil, the chart includes
2649 only the visible subelements of the charted subjects.
2651 The remaining optional args are for internal use by the function.
2653 Point is left at the end of the subtree.
2655 Charts are used to capture outline structure, so that outline-altering
2656 routines need to assess the structure only once, and then use the chart
2657 for their elaborate manipulations.
2659 The chart entries for the topics are in reverse order, so the
2660 last topic is listed first. The entry for each topic consists of
2661 an integer indicating the point at the beginning of the topic
2662 prefix. Charts for offspring consist of a list containing,
2663 recursively, the charts for the respective subtopics. The chart
2664 for a topics' offspring precedes the entry for the topic itself.
2666 The other function parameters are for internal recursion, and should
2667 not be specified by external callers. ORIG-DEPTH is depth of topic at
2668 starting point, and PREV-DEPTH is depth of prior topic."
2670 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
2673 (if original
; Just starting?
2674 ; Register initial settings and
2675 ; position to first offspring:
2676 (progn (setq orig-depth
(allout-depth))
2677 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
2679 (allout-next-visible-heading 1)
2680 (allout-next-heading))))
2682 ;; Loop over the current levels' siblings. Besides being more
2683 ;; efficient than tail-recursing over a level, it avoids exceeding
2684 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2686 ;; Probably would speed things up to implement loop-based stack
2687 ;; operation rather than recursing for lower levels. Bah.
2689 (while (and (not (eobp))
2690 ; Still within original topic?
2691 (< orig-depth
(setq curr-depth allout-recent-depth
))
2692 (cond ((= prev-depth curr-depth
)
2693 ;; Register this one and move on:
2694 (setq chart
(cons allout-recent-prefix-beginning chart
))
2695 (if (and levels
(<= levels
1))
2696 ;; At depth limit -- skip sublevels:
2697 (or (allout-next-sibling curr-depth
)
2698 ;; or no more siblings -- proceed to
2699 ;; next heading at lesser depth:
2700 (while (and (<= curr-depth
2701 allout-recent-depth
)
2703 (allout-next-visible-heading 1)
2704 (allout-next-heading)))))
2706 (allout-next-visible-heading 1)
2707 (allout-next-heading))))
2709 ((and (< prev-depth curr-depth
)
2712 ;; Recurse on deeper level of curr topic:
2714 (cons (allout-chart-subtree (and levels
2720 ;; ... then continue with this one.
2723 ;; ... else nil if we've ascended back to prev-depth.
2727 (if original
; We're at the last sibling on
2728 ; the original level. Position
2730 (progn (and (not (eobp)) (forward-char -
1))
2731 (and (= (preceding-char) ?
\n)
2732 (= (aref (buffer-substring (max 1 (- (point) 3))
2737 (setq allout-recent-end-of-subtree
(point))))
2739 chart
; (nreverse chart) not necessary,
2740 ; and maybe not preferable.
2742 ;;;_ > allout-chart-siblings (&optional start end)
2743 (defun allout-chart-siblings (&optional start end
)
2744 "Produce a list of locations of this and succeeding sibling topics.
2745 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2746 for an explanation of charts."
2748 (when (allout-goto-prefix-doublechecked)
2749 (let ((chart (list (point))))
2750 (while (allout-next-sibling)
2751 (setq chart
(cons (point) chart
)))
2752 (if chart
(setq chart
(nreverse chart
)))))))
2753 ;;;_ > allout-chart-to-reveal (chart depth)
2754 (defun allout-chart-to-reveal (chart depth
)
2756 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2758 If DEPTH is nil, include hidden points at any depth.
2760 Note that point can be left at any of the points on chart, or at the
2764 (while (and (or (null depth
) (> depth
0))
2766 (setq here
(car chart
))
2768 (let ((further (allout-chart-to-reveal here
(if (null depth
)
2771 ;; We're on the start of a subtree -- recurse with it, if there's
2772 ;; more depth to go:
2773 (if further
(setq result
(append further result
)))
2774 (setq chart
(cdr chart
)))
2776 (if (allout-hidden-p)
2777 (setq result
(cons here result
)))
2778 (setq chart
(cdr chart
))))
2780 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2781 ;; (defun allout-chart-spec (chart spec &optional exposing)
2782 ;; "Not yet (if ever) implemented.
2784 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2786 ;; Exposure spec indicates the locations to be exposed and the prescribed
2787 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2788 ;; indicating pending concealment, anything higher indicating depth to
2789 ;; which subtopic headers should be exposed, and negative numbers
2790 ;; indicating (negative of) the depth to which subtopic headers and
2791 ;; bodies should be exposed.
2793 ;; The produced list can have two types of entries. Bare numbers
2794 ;; indicate points in the buffer where topic headers that should be
2797 ;; - bare negative numbers indicates that the topic starting at the
2798 ;; point which is the negative of the number should be opened,
2799 ;; including their entries.
2800 ;; - bare positive values indicate that this topic header should be
2802 ;; - Lists signify the beginning and end points of regions that should
2803 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2806 ;; (cond ((listp spec)
2809 ;; (setq spec (cdr spec)))
2813 ;;;_ > allout-goto-prefix ()
2814 (defun allout-goto-prefix ()
2815 "Put point at beginning of immediately containing outline topic.
2817 Goes to most immediate subsequent topic if none immediately containing.
2819 Not sensitive to topic visibility.
2821 Returns the point at the beginning of the prefix, or nil if none."
2825 (while (and (not done
)
2826 (search-backward "\n" nil
1))
2828 (if (looking-at allout-regexp
)
2829 (setq done
(allout-prefix-data))
2832 (cond ((looking-at allout-regexp
)
2833 (allout-prefix-data))
2834 ((allout-next-heading))
2837 ;;;_ > allout-goto-prefix-doublechecked ()
2838 (defun allout-goto-prefix-doublechecked ()
2839 "Put point at beginning of immediately containing outline topic.
2841 Like `allout-goto-prefix', but shallow topics (according to
2842 `allout-doublecheck-at-and-shallower') are checked and
2843 disqualified for child containment discontinuity, according to
2844 `allout-aberrant-container-p'."
2845 (if (allout-goto-prefix)
2846 (if (and (allout-do-doublecheck)
2847 (allout-aberrant-container-p))
2848 (allout-previous-heading)
2851 ;;;_ > allout-end-of-prefix ()
2852 (defun allout-end-of-prefix (&optional ignore-decorations
)
2853 "Position cursor at beginning of header text.
2855 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2856 otherwise skip white space between bullet and ensuing text."
2858 (if (not (allout-goto-prefix-doublechecked))
2860 (goto-char allout-recent-prefix-end
)
2862 (if ignore-decorations
2864 (while (looking-at "[0-9]") (forward-char 1))
2865 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2866 ;; Reestablish where we are:
2867 (allout-current-depth)))
2868 ;;;_ > allout-current-bullet-pos ()
2869 (defun allout-current-bullet-pos ()
2870 "Return position of current (visible) topic's bullet."
2872 (if (not (allout-current-depth))
2874 (1- allout-recent-prefix-end
)))
2875 ;;;_ > allout-back-to-current-heading (&optional interactive)
2876 (defun allout-back-to-current-heading (&optional interactive
)
2877 "Move to heading line of current topic, or beginning if not in a topic.
2879 If interactive, we position at the end of the prefix.
2881 Return value of resulting point, unless we started outside
2882 of (before any) topics, in which case we return nil."
2886 (allout-beginning-of-current-line)
2887 (let ((bol-point (point)))
2888 (when (allout-goto-prefix-doublechecked)
2889 (if (<= (point) bol-point
)
2891 (setq bol-point
(point))
2892 (allout-beginning-of-current-line)
2893 (if (not (= bol-point
(point)))
2894 (if (looking-at allout-regexp
)
2895 (allout-prefix-data)))
2897 (allout-end-of-prefix)
2899 (goto-char (point-min))
2901 ;;;_ > allout-back-to-heading ()
2902 (defalias 'allout-back-to-heading
'allout-back-to-current-heading
)
2903 ;;;_ > allout-pre-next-prefix ()
2904 (defun allout-pre-next-prefix ()
2905 "Skip forward to just before the next heading line.
2907 Returns that character position."
2909 (if (allout-next-heading)
2910 (goto-char (1- allout-recent-prefix-beginning
))))
2911 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2912 (defun allout-end-of-subtree (&optional current include-trailing-blank
)
2913 "Put point at the end of the last leaf in the containing topic.
2915 Optional CURRENT means put point at the end of the containing
2918 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2919 any, as part of the subtree. Otherwise, that trailing blank will be
2920 excluded as delimiting whitespace between topics.
2922 Returns the value of point."
2925 (allout-back-to-current-heading)
2926 (allout-goto-prefix-doublechecked))
2927 (let ((level allout-recent-depth
))
2928 (allout-next-heading)
2929 (while (and (not (eobp))
2930 (> allout-recent-depth level
))
2931 (allout-next-heading))
2933 (allout-end-of-entry)
2935 (if (and (not include-trailing-blank
) (= ?
\n (preceding-char)))
2937 (setq allout-recent-end-of-subtree
(point))))
2938 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2939 (defun allout-end-of-current-subtree (&optional include-trailing-blank
)
2941 "Put point at end of last leaf in currently visible containing topic.
2943 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2944 any, as part of the subtree. Otherwise, that trailing blank will be
2945 excluded as delimiting whitespace between topics.
2947 Returns the value of point."
2949 (allout-end-of-subtree t include-trailing-blank
))
2950 ;;;_ > allout-beginning-of-current-entry (&optional interactive)
2951 (defun allout-beginning-of-current-entry (&optional interactive
)
2952 "When not already there, position point at beginning of current topic header.
2954 If already there, move cursor to bullet for hot-spot operation.
2955 \(See `allout-mode' doc string for details of hot-spot operation.)"
2957 (let ((start-point (point)))
2958 (move-beginning-of-line 1)
2959 (if (< 0 (allout-current-depth))
2960 (goto-char allout-recent-prefix-end
)
2961 (goto-char (point-min)))
2962 (allout-end-of-prefix)
2963 (if (and interactive
2964 (= (point) start-point
))
2965 (goto-char (allout-current-bullet-pos)))))
2966 ;;;_ > allout-end-of-entry (&optional inclusive)
2967 (defun allout-end-of-entry (&optional inclusive
)
2968 "Position the point at the end of the current topics' entry.
2970 Optional INCLUSIVE means also include trailing empty line, if any. When
2971 unset, whitespace between items separates them even when the items are
2974 (allout-pre-next-prefix)
2975 (if (and (not inclusive
) (not (bobp)) (= ?
\n (preceding-char)))
2978 ;;;_ > allout-end-of-current-heading ()
2979 (defun allout-end-of-current-heading ()
2981 (allout-beginning-of-current-entry)
2982 (search-forward "\n" nil t
)
2984 (defalias 'allout-end-of-heading
'allout-end-of-current-heading
)
2985 ;;;_ > allout-get-body-text ()
2986 (defun allout-get-body-text ()
2987 "Return the unmangled body text of the topic immediately containing point."
2989 (allout-end-of-prefix)
2990 (if (not (search-forward "\n" nil t
))
2993 (let ((pre-body (point)))
2996 (allout-end-of-entry t
)
2997 (if (not (= pre-body
(point)))
2998 (buffer-substring-no-properties (1+ pre-body
) (point))))
3005 ;;;_ > allout-ascend-to-depth (depth)
3006 (defun allout-ascend-to-depth (depth)
3007 "Ascend to depth DEPTH, returning depth if successful, nil if not."
3008 (if (and (> depth
0)(<= depth
(allout-depth)))
3009 (let (last-ascended)
3010 (while (and (< depth allout-recent-depth
)
3011 (setq last-ascended
(allout-ascend))))
3012 (goto-char allout-recent-prefix-beginning
)
3013 (if (allout-called-interactively-p) (allout-end-of-prefix))
3014 (and last-ascended allout-recent-depth
))))
3015 ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
3016 (defun allout-ascend (&optional dont-move-if-unsuccessful
)
3017 "Ascend one level, returning resulting depth if successful, nil if not.
3019 Point is left at the beginning of the level whether or not
3020 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
3021 which case point is returned to its original starting location."
3022 (if dont-move-if-unsuccessful
3023 (setq dont-move-if-unsuccessful
(point)))
3025 (if (allout-beginning-of-level)
3026 (let ((bolevel (point))
3027 (bolevel-depth allout-recent-depth
))
3028 (allout-previous-heading)
3029 (cond ((< allout-recent-depth bolevel-depth
)
3030 allout-recent-depth
)
3031 ((= allout-recent-depth bolevel-depth
)
3032 (if dont-move-if-unsuccessful
3033 (goto-char dont-move-if-unsuccessful
))
3037 ;; some topic after very first is lower depth than first:
3041 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3042 ;;;_ > allout-descend-to-depth (depth)
3043 (defun allout-descend-to-depth (depth)
3044 "Descend to depth DEPTH within current topic.
3046 Returning depth if successful, nil if not."
3047 (let ((start-point (point))
3048 (start-depth (allout-depth)))
3050 (and (> (allout-depth) 0)
3051 (not (= depth allout-recent-depth
)) ; ... not there yet
3052 (allout-next-heading) ; ... go further
3053 (< start-depth allout-recent-depth
))) ; ... still in topic
3054 (if (and (> (allout-depth) 0)
3055 (= allout-recent-depth depth
))
3057 (goto-char start-point
)
3060 ;;;_ > allout-up-current-level (arg)
3061 (defun allout-up-current-level (arg)
3062 "Move out ARG levels from current visible topic."
3064 (let ((start-point (point)))
3065 (allout-back-to-current-heading)
3066 (if (not (allout-ascend))
3067 (progn (goto-char start-point
)
3068 (error "Can't ascend past outermost level"))
3069 (if (allout-called-interactively-p) (allout-end-of-prefix))
3070 allout-recent-prefix-beginning
)))
3073 ;;;_ > allout-next-sibling (&optional depth backward)
3074 (defun allout-next-sibling (&optional depth backward
)
3075 "Like `allout-forward-current-level', but respects invisible topics.
3077 Traverse at optional DEPTH, or current depth if none specified.
3079 Go backward if optional arg BACKWARD is non-nil.
3081 Return the start point of the new topic if successful, nil otherwise."
3083 (if (if backward
(bobp) (eobp))
3085 (let ((target-depth (or depth
(allout-depth)))
3086 (start-point (point))
3087 (start-prefix-beginning allout-recent-prefix-beginning
)
3092 ;; done too few single steps to resort to the leap routine:
3095 (not (if backward
(bobp) (eobp)))
3096 ;; still traversable:
3097 (if backward
(allout-previous-heading) (allout-next-heading))
3098 ;; we're below the target depth
3099 (> (setq last-depth allout-recent-depth
) target-depth
))
3100 (setq count
(1+ count
))
3101 (if (> count
7) ; lists are commonly 7 +- 2, right?-)
3104 (or (allout-next-sibling-leap target-depth backward
)
3106 (goto-char start-point
)
3107 (if depth
(allout-depth) target-depth
)
3110 (and (> (or last-depth
(allout-depth)) 0)
3111 (= allout-recent-depth target-depth
))
3112 (not (= start-prefix-beginning
3113 allout-recent-prefix-beginning
)))
3114 allout-recent-prefix-beginning
)
3116 (goto-char start-point
)
3117 (if depth
(allout-depth) target-depth
)
3119 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3120 (defun allout-next-sibling-leap (&optional depth backward
)
3121 "Like `allout-next-sibling', but by direct search for topic at depth.
3123 Traverse at optional DEPTH, or current depth if none specified.
3125 Go backward if optional arg BACKWARD is non-nil.
3127 Return the start point of the new topic if successful, nil otherwise.
3129 Costs more than regular `allout-next-sibling' for short traversals:
3131 - we have to check the prior (next, if traveling backwards)
3132 item to confirm connectivity with the prior topic, and
3133 - if confirmed, we have to reestablish the allout-recent-* settings with
3134 some extra navigation
3135 - if confirmation fails, we have to do more work to recover
3137 It is an increasingly big win when there are many intervening
3138 offspring before the next sibling, however, so
3139 `allout-next-sibling' resorts to this if it finds itself in that
3142 (if (if backward
(bobp) (eobp))
3144 (let* ((start-point (point))
3145 (target-depth (or depth
(allout-depth)))
3146 (search-whitespace-regexp nil
)
3147 (depth-biased (- target-depth
2))
3148 (expression (if (<= target-depth
1)
3149 allout-depth-one-regexp
3150 (format allout-depth-specific-regexp
3151 depth-biased depth-biased
)))
3155 (setq found
(save-match-data
3157 (re-search-backward expression nil
'to-limit
)
3159 (re-search-forward expression nil
'to-limit
))))
3160 (if (and found
(allout-aberrant-container-p))
3162 (setq done
(or found
(if backward
(bobp) (eobp)))))
3164 (progn (goto-char start-point
)
3166 ;; rationale: if any intervening items were at a lower depth, we
3167 ;; would now be on the first offspring at the target depth -- ie,
3168 ;; the preceding item (per the search direction) must be at a
3169 ;; lesser depth. that's all we need to check.
3170 (if backward
(allout-next-heading) (allout-previous-heading))
3171 (if (< allout-recent-depth target-depth
)
3172 ;; return to start and reestablish allout-recent-*:
3174 (goto-char start-point
)
3178 ;; locate cursor and set allout-recent-*:
3179 (allout-goto-prefix))))))
3180 ;;;_ > allout-previous-sibling (&optional depth backward)
3181 (defun allout-previous-sibling (&optional depth backward
)
3182 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3184 Optional DEPTH specifies depth to traverse, default current depth.
3186 Optional BACKWARD reverses direction.
3188 Return depth if successful, nil otherwise."
3189 (allout-next-sibling depth
(not backward
))
3191 ;;;_ > allout-snug-back ()
3192 (defun allout-snug-back ()
3193 "Position cursor at end of previous topic.
3195 Presumes point is at the start of a topic prefix."
3196 (if (or (bobp) (eobp))
3199 (if (or (bobp) (not (= ?
\n (preceding-char))))
3203 ;;;_ > allout-beginning-of-level ()
3204 (defun allout-beginning-of-level ()
3205 "Go back to the first sibling at this level, visible or not."
3206 (allout-end-of-level 'backward
))
3207 ;;;_ > allout-end-of-level (&optional backward)
3208 (defun allout-end-of-level (&optional backward
)
3209 "Go to the last sibling at this level, visible or not."
3211 (let ((depth (allout-depth)))
3212 (while (allout-previous-sibling depth nil
))
3213 (prog1 allout-recent-depth
3214 (if (allout-called-interactively-p) (allout-end-of-prefix)))))
3215 ;;;_ > allout-next-visible-heading (arg)
3216 (defun allout-next-visible-heading (arg)
3217 "Move to the next ARGth visible heading line, backward if ARG is negative.
3219 Move to buffer limit in indicated direction if headings are exhausted."
3222 (let* ((inhibit-field-text-motion t
)
3223 (backward (if (< arg
0) (setq arg
(* -
1 arg
))))
3224 (step (if backward -
1 1))
3225 (progress (allout-current-bullet-pos))
3230 ;; Boundary condition:
3231 (not (if backward
(bobp)(eobp)))
3232 ;; Move, skipping over all concealed lines in one fell swoop:
3233 (prog1 (condition-case nil
(or (line-move step
) t
)
3235 (allout-beginning-of-current-line)
3236 ;; line-move can wind up on the same line if long.
3237 ;; when moving forward, that would yield no-progress
3238 (when (and (not backward
)
3239 (<= (point) progress
))
3240 ;; ensure progress by doing line-move from end-of-line:
3242 (condition-case nil
(or (line-move step
) t
)
3244 (allout-beginning-of-current-line)
3245 (setq progress
(point))))
3246 ;; Deal with apparent header line:
3248 (if (not (looking-at allout-regexp
))
3249 ;; not a header line, keep looking:
3251 (allout-prefix-data)
3252 (if (and (allout-do-doublecheck)
3253 (allout-aberrant-container-p))
3254 ;; skip this aberrant prospective header line:
3256 ;; this prospective headerline qualifies -- register:
3257 (setq got allout-recent-prefix-beginning
)
3258 ;; and break the loop:
3260 ;; Register this got, it may be the last:
3261 (if got
(setq prev got
))
3262 (setq arg
(1- arg
)))
3263 (cond (got ; Last move was to a prefix:
3264 (allout-end-of-prefix))
3265 (prev ; Last move wasn't, but prev was:
3267 (allout-end-of-prefix))
3268 ((not backward
) (end-of-line) nil
))))
3269 ;;;_ > allout-previous-visible-heading (arg)
3270 (defun allout-previous-visible-heading (arg)
3271 "Move to the previous heading line.
3273 With argument, repeats or can move forward if negative.
3274 A heading line is one that starts with a `*' (or that `allout-regexp'
3277 (prog1 (allout-next-visible-heading (- arg
))
3278 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3279 ;;;_ > allout-forward-current-level (arg)
3280 (defun allout-forward-current-level (arg)
3281 "Position point at the next heading of the same level.
3283 Takes optional repeat-count, goes backward if count is negative.
3285 Returns resulting position, else nil if none found."
3287 (let ((start-depth (allout-current-depth))
3289 (backward (> 0 arg
)))
3290 (if (= 0 start-depth
)
3291 (error "No siblings, not in a topic..."))
3292 (if backward
(setq arg
(* -
1 arg
)))
3293 (allout-back-to-current-heading)
3294 (while (and (not (zerop arg
))
3296 (allout-previous-sibling)
3297 (allout-next-sibling)))
3298 (setq arg
(1- arg
)))
3299 (if (not (allout-called-interactively-p))
3301 (allout-end-of-prefix)
3302 (if (not (zerop arg
))
3303 (error "Hit %s level %d topic, traversed %d of %d requested"
3304 (if backward
"first" "last")
3306 (- (abs start-arg
) arg
)
3307 (abs start-arg
))))))
3308 ;;;_ > allout-backward-current-level (arg)
3309 (defun allout-backward-current-level (arg)
3310 "Inverse of `allout-forward-current-level'."
3312 (if (allout-called-interactively-p)
3313 (let ((current-prefix-arg (* -
1 arg
)))
3314 (call-interactively 'allout-forward-current-level
))
3315 (allout-forward-current-level (* -
1 arg
))))
3320 ;;;_ = allout-post-goto-bullet
3321 (defvar allout-post-goto-bullet nil
3322 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3324 When set, tells post-processing to reposition on topic bullet, and
3325 then unset it. Set by `allout-pre-command-business' when implementing
3326 hot-spot operation, where literal characters typed over a topic bullet
3327 are mapped to the command of the corresponding control-key on the
3328 `allout-mode-map-value'.")
3329 (make-variable-buffer-local 'allout-post-goto-bullet
)
3330 ;;;_ = allout-command-counter
3331 (defvar allout-command-counter
0
3332 "Counter that monotonically increases in allout-mode buffers.
3334 Set by `allout-pre-command-business', to support allout addons in
3335 coordinating with allout activity.")
3336 (make-variable-buffer-local 'allout-command-counter
)
3337 ;;;_ = allout-this-command-hid-text
3338 (defvar allout-this-command-hid-text nil
3339 "True if the most recent allout-mode command hid any text.")
3340 (make-variable-buffer-local 'allout-this-command-hid-text
)
3341 ;;;_ > allout-post-command-business ()
3342 (defun allout-post-command-business ()
3343 "Outline `post-command-hook' function.
3345 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3348 - Move the cursor to the beginning of the entry if it is hidden
3349 and collapsing activity just happened.
3351 - If the command we're following was an undo, check for change in
3352 the status of encrypted items and adjust auto-save inhibitions
3355 - Decrypt topic currently being edited if it was encrypted for a save."
3357 (if (not (allout-mode-p)) ; In allout-mode.
3360 (when allout-just-did-undo
3361 (setq allout-just-did-undo nil
)
3362 (run-hooks 'allout-post-undo-hook
)
3363 (cond ((and (= buffer-saved-size -
1)
3364 allout-auto-save-temporarily-disabled
)
3365 ;; user possibly undid a decryption, disinhibit auto-save:
3366 (allout-maybe-resume-auto-save-info-after-encryption))
3370 (goto-char (point-min))
3371 (not (allout-next-topic-pending-encryption))))
3372 ;; plain-text encrypted items are present, inhibit auto-save:
3373 (allout-inhibit-auto-save-info-for-decryption (buffer-size)))))
3375 (if (and (boundp 'allout-after-save-decrypt
)
3376 allout-after-save-decrypt
)
3377 (allout-after-saves-handler))
3379 ;; Implement allout-post-goto-bullet, if set:
3380 (if (and allout-post-goto-bullet
3381 (allout-current-bullet-pos))
3382 (progn (goto-char (allout-current-bullet-pos))
3383 (setq allout-post-goto-bullet nil
))
3384 (when (and (allout-hidden-p) allout-this-command-hid-text
)
3385 (allout-beginning-of-current-entry)))))
3386 ;;;_ > allout-pre-command-business ()
3387 (defun allout-pre-command-business ()
3388 "Outline `pre-command-hook' function for outline buffers.
3390 Among other things, implements special behavior when the cursor is on the
3391 topic bullet character.
3393 When the cursor is on the bullet character, self-insert
3394 characters are reinterpreted as the corresponding
3395 control-character in the `allout-mode-map-value'. The
3396 `allout-mode' `post-command-hook' insures that the cursor which
3397 has moved as a result of such reinterpretation is positioned on
3398 the bullet character of the destination topic.
3400 The upshot is that you can get easy, single (ie, unmodified) key
3401 outline maneuvering operations by positioning the cursor on the bullet
3402 char. When in this mode you can use regular cursor-positioning
3403 command/keystrokes to relocate the cursor off of a bullet character to
3404 return to regular interpretation of self-insert characters."
3406 (if (not (allout-mode-p))
3408 (setq allout-command-counter
(1+ allout-command-counter
))
3409 (setq allout-this-command-hid-text nil
)
3410 ;; Do hot-spot navigation.
3411 (if (and (eq this-command
'self-insert-command
)
3412 (eq (point)(allout-current-bullet-pos)))
3413 (allout-hotspot-key-handler))))
3414 ;;;_ > allout-hotspot-key-handler ()
3415 (defun allout-hotspot-key-handler ()
3416 "Catchall handling of key bindings in hot-spots.
3418 Translates unmodified keystrokes to corresponding allout commands, when
3419 they would qualify if prefixed with the `allout-command-prefix', and sets
3420 `this-command' accordingly.
3422 Returns the qualifying command, if any, else nil."
3424 (let* ((modified (event-modifiers last-command-event
))
3425 (key-num (cond ((numberp last-command-event
) last-command-event
)
3426 ;; for XEmacs character type:
3427 ((and (fboundp 'characterp
)
3428 (apply 'characterp
(list last-command-event
)))
3429 (apply 'char-to-int
(list last-command-event
)))
3437 ;; exclude control chars and escape:
3440 (setq mapped-binding
3442 ;; try control-modified versions of keys:
3443 (key-binding (vconcat allout-command-prefix
3445 (if (and (<= 97 key-num
) ; "a"
3446 (>= 122 key-num
)) ; "z"
3447 (- key-num
96) key-num
)))
3449 ;; try non-modified versions of keys:
3450 (key-binding (vconcat allout-command-prefix
3453 ;; Qualified as an allout command -- do hot-spot operation.
3454 (setq allout-post-goto-bullet t
)
3455 ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
3456 (setq mapped-binding
(key-binding (vector key-num
))))
3458 (while (keymapp mapped-binding
)
3459 (setq mapped-binding
3460 (lookup-key mapped-binding
(vector (read-char)))))
3462 (when mapped-binding
3463 (setq this-command mapped-binding
)))))
3465 ;;;_ > allout-find-file-hook ()
3466 (defun allout-find-file-hook ()
3467 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3469 See `allout-auto-activation' for setup instructions."
3470 (if (and allout-auto-activation
3471 (not (allout-mode-p))
3475 ;;;_ - Topic Format Assessment
3476 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3477 (defun allout-solicit-alternate-bullet (depth &optional current-bullet
)
3479 "Prompt for and return a bullet char as an alternative to the current one.
3481 Offer one suitable for current depth DEPTH as default."
3483 (let* ((default-bullet (or (and (stringp current-bullet
) current-bullet
)
3484 (allout-bullet-for-depth depth
)))
3485 (sans-escapes (regexp-sans-escapes allout-bullets-string
))
3488 (goto-char (allout-current-bullet-pos))
3489 (setq choice
(solicit-char-in-string
3490 (format "Select bullet: %s ('%s' default): "
3492 (allout-substring-no-properties default-bullet
))
3496 (if (string= choice
"") default-bullet choice
))
3498 ;;;_ > allout-distinctive-bullet (bullet)
3499 (defun allout-distinctive-bullet (bullet)
3500 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3501 (string-match (regexp-quote bullet
) allout-distinctive-bullets-string
))
3502 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3503 (defun allout-numbered-type-prefix (&optional prefix
)
3504 "True if current header prefix bullet is numbered bullet."
3505 (and allout-numbered-bullet
3506 (string= allout-numbered-bullet
3508 (allout-get-prefix-bullet prefix
)
3509 (allout-get-bullet)))))
3510 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3511 (defun allout-encrypted-type-prefix (&optional prefix
)
3512 "True if current header prefix bullet is for an encrypted entry (body)."
3513 (and allout-topic-encryption-bullet
3514 (string= allout-topic-encryption-bullet
3516 (allout-get-prefix-bullet prefix
)
3517 (allout-get-bullet)))))
3518 ;;;_ > allout-bullet-for-depth (&optional depth)
3519 (defun allout-bullet-for-depth (&optional depth
)
3520 "Return outline topic bullet suited to optional DEPTH, or current depth."
3521 ;; Find bullet in plain-bullets-string modulo DEPTH.
3522 (if allout-stylish-prefixes
3523 (char-to-string (aref allout-plain-bullets-string
3524 (%
(max 0 (- depth
2))
3525 allout-plain-bullets-string-len
)))
3526 allout-primary-bullet
)
3529 ;;;_ - Topic Production
3530 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3531 (defun allout-make-topic-prefix (&optional prior-bullet
3537 ;; Depth null means use current depth, non-null means we're either
3538 ;; opening a new topic after current topic, lower or higher, or we're
3539 ;; changing level of current topic.
3540 ;; Instead dominates specified bullet-char.
3542 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3544 All the arguments are optional.
3546 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3547 nil if none. This bullet may be preserved (other options
3548 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3551 Second arg NEW indicates that a new topic is being opened after the
3552 topic at point, if non-nil. Default bullet for new topics, eg, may
3553 be set (contingent to other args) to numbered bullets if previous
3554 sibling is one. The implication otherwise is that the current topic
3555 is being adjusted -- shifted or rebulleted -- and we don't consider
3556 bullet or previous sibling.
3558 Third arg DEPTH forces the topic prefix to that depth, regardless of
3559 the current topics' depth.
3563 - nil, then the bullet char for the context is used, per distinction or depth
3564 - a (numeric) character, then character's string representation is used
3565 - a string, then the user is asked for bullet with the first char as default
3566 - anything else, the user is solicited with bullet char per context as default
3568 \(INSTEAD overrides other options, including, eg, a distinctive
3571 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3572 is non-nil *and* no specific INSTEAD was specified. Then
3573 NUMBER-CONTROL non-nil forces prefix to either numbered or
3574 unnumbered format, depending on the value of the sixth arg, INDEX.
3576 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3578 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3579 the prefix of the topic is forced to be numbered. Non-nil
3580 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3581 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3582 that the index for the numbered prefix will be derived, by counting
3583 siblings back to start of level. If INDEX is a number, then that
3584 number is used as the index for the numbered prefix (allowing, eg,
3585 sequential renumbering to not require this function counting back the
3586 index for each successive sibling)."
3588 ;; The options are ordered in likely frequency of use, most common
3589 ;; highest, least lowest. Ie, more likely to be doing prefix
3590 ;; adjustments than soliciting, and yet more than numbering.
3591 ;; Current prefix is least dominant, but most likely to be commonly
3597 (depth (or depth
(allout-depth)))
3598 (header-lead allout-header-prefix
)
3601 ;; Getting value for bullet char is practically the whole job:
3604 ; Simplest situation -- level 1:
3605 ((<= depth
1) (setq header-lead
"") allout-primary-bullet
)
3606 ; Simple, too: all asterisks:
3607 (allout-old-style-prefixes
3608 ;; Cheat -- make body the whole thing, null out header-lead and
3610 (setq body
(make-string depth
3611 (string-to-char allout-primary-bullet
)))
3612 (setq header-lead
"")
3615 ;; (Neither level 1 nor old-style, so we're space padding.
3616 ;; Sneak it in the condition of the next case, whatever it is.)
3618 ;; Solicitation overrides numbering and other cases:
3619 ((progn (setq body
(make-string (- depth
2) ?\
))
3620 ;; The actual condition:
3622 (let ((got (cond ((stringp instead
)
3623 (if (> (length instead
) 0)
3624 (allout-solicit-alternate-bullet
3625 depth
(substring instead
0 1))))
3626 ((characterp instead
) (char-to-string instead
))
3627 (t (allout-solicit-alternate-bullet depth
)))))
3628 ;; Gotta check whether we're numbering and got a numbered bullet:
3629 (setq numbering
(and allout-numbered-bullet
3630 (not (and number-control
(not index
)))
3631 (string= got allout-numbered-bullet
)))
3632 ;; Now return what we got, regardless:
3635 ;; Numbering invoked through args:
3636 ((and allout-numbered-bullet number-control
)
3637 (if (setq numbering
(not (setq denumbering
(not index
))))
3638 allout-numbered-bullet
3639 (if (and prior-bullet
3640 (not (string= allout-numbered-bullet
3643 (allout-bullet-for-depth depth
))))
3645 ;;; Neither soliciting nor controlled numbering ;;;
3646 ;;; (may be controlled denumbering, tho) ;;;
3648 ;; Check wrt previous sibling:
3649 ((and new
; only check for new prefixes
3650 (<= depth
(allout-depth))
3651 allout-numbered-bullet
; ... & numbering enabled
3653 (let ((sibling-bullet
3655 ;; Locate correct sibling:
3656 (or (>= depth
(allout-depth))
3657 (allout-ascend-to-depth depth
))
3658 (allout-get-bullet))))
3659 (if (and sibling-bullet
3660 (string= allout-numbered-bullet sibling-bullet
))
3661 (setq numbering sibling-bullet
)))))
3663 ;; Distinctive prior bullet?
3665 (allout-distinctive-bullet prior-bullet
)
3666 ;; Either non-numbered:
3667 (or (not (and allout-numbered-bullet
3668 (string= prior-bullet allout-numbered-bullet
)))
3669 ;; or numbered, and not denumbering:
3670 (setq numbering
(not denumbering
)))
3674 ;; Else, standard bullet per depth:
3675 ((allout-bullet-for-depth depth
)))))
3681 (format "%d" (cond ((and index
(numberp index
)) index
)
3682 (new (1+ (allout-sibling-index depth
)))
3683 ((allout-sibling-index))))))
3686 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3687 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet
)
3688 "Open a new topic at depth DEPTH.
3690 New topic is situated after current one, unless optional flag BEFORE
3691 is non-nil, or unless current line is completely empty -- lacking even
3692 whitespace -- in which case open is done on the current line.
3694 When adding an offspring, it will be added immediately after the parent if
3695 the other offspring are exposed, or after the last child if the offspring
3696 are hidden. (The intervening offspring will be exposed in the latter
3699 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3703 - Creation of new topics is with respect to the visible topic
3704 containing the cursor, regardless of intervening concealed ones.
3706 - New headers are generally created after/before the body of a
3707 topic. However, they are created right at cursor location if the
3708 cursor is on a blank line, even if that breaks the current topic
3709 body. This is intentional, to provide a simple means for
3710 deliberately dividing topic bodies.
3712 - Double spacing of topic lists is preserved. Also, the first
3713 level two topic is created double-spaced (and so would be
3714 subsequent siblings, if that's left intact). Otherwise,
3715 single-spacing is used.
3717 - Creation of sibling or nested topics is with respect to the topic
3718 you're starting from, even when creating backwards. This way you
3719 can easily create a sibling in front of the current topic without
3720 having to go to its preceding sibling, and then open forward
3723 (allout-beginning-of-current-line)
3725 (let* ((inhibit-field-text-motion t
)
3726 (depth (+ (allout-current-depth) relative-depth
))
3727 (opening-on-blank (if (looking-at "^\$")
3728 (not (setq before nil
))))
3729 ;; bunch o vars set while computing ref-topic
3733 (ref-topic (save-excursion
3734 (cond ((< relative-depth
0)
3735 (allout-ascend-to-depth depth
))
3736 ((>= relative-depth
1) nil
)
3737 (t (allout-back-to-current-heading)))
3738 (setq ref-depth allout-recent-depth
)
3740 (if (> allout-recent-prefix-end
1)
3741 (allout-recent-bullet)
3743 (setq opening-numbered
3745 (and allout-numbered-bullet
3746 (or (<= relative-depth
0)
3747 (allout-descend-to-depth depth
))
3748 (if (allout-numbered-type-prefix)
3749 allout-numbered-bullet
))))
3755 (if (not opening-on-blank
)
3756 ; Positioning and vertical
3757 ; padding -- only if not
3760 (goto-char ref-topic
)
3761 (setq dbl-space
; Determine double space action:
3762 (or (and (<= relative-depth
0) ; not descending;
3764 ;; at b-o-b or preceded by a blank line?
3765 (or (> 0 (forward-line -
1))
3766 (looking-at "^\\s-*$")
3769 ;; succeeded by a blank line?
3770 (allout-end-of-current-subtree)
3771 (looking-at "\n\n")))
3772 (and (= ref-depth
1)
3776 ;; Don't already have following
3777 ;; vertical padding:
3778 (not (allout-pre-next-prefix)))))))
3780 ;; Position to prior heading, if inserting backwards, and not
3782 (if (and before
(>= relative-depth
0))
3783 (progn (allout-back-to-current-heading)
3784 (setq doing-beginning
(bobp))
3786 (allout-previous-heading)))
3787 (if (and before
(bobp))
3790 (if (<= relative-depth
0)
3791 ;; Not going inwards, don't snug up:
3797 (progn (end-of-line)
3798 (allout-pre-next-prefix)
3799 (while (and (= ?
\n (following-char))
3804 (if (not (looking-at "^$"))
3806 (allout-end-of-current-subtree)
3807 (if (looking-at "\n\n") (forward-char 1))))
3808 ;; Going inwards -- double-space if first offspring is
3809 ;; double-spaced, otherwise snug up.
3810 (allout-end-of-entry)
3814 (allout-beginning-of-current-line)
3817 ;; Blank lines between current header body and next
3818 ;; header -- get to last substantive (non-white-space)
3820 (progn (setq dbl-space t
)
3821 (re-search-backward "[^ \t\n]" nil t
)))
3822 (if (looking-at "\n\n")
3825 (allout-next-heading)
3826 (when (> allout-recent-depth ref-depth
)
3827 ;; This is an offspring.
3829 (looking-at "^\\s-*$")))
3830 (progn (forward-line 1)
3833 (allout-end-of-current-line))
3835 ;;(if doing-beginning (goto-char doing-beginning))
3837 ;; We insert a newline char rather than using open-line to
3838 ;; avoid rear-stickiness inheritance of read-only property.
3839 (progn (if (and (not (> depth ref-depth
))
3842 (if (and (not dbl-space
) (> depth ref-depth
))
3848 (if (and dbl-space
(not (> relative-depth
0)))
3850 (if (and (not (eobp))
3853 ;; bolp doesn't detect concealed
3854 ;; trailing newlines, compensate:
3857 (allout-hidden-p)))))
3860 (setq start
(point))
3861 (insert (concat (allout-make-topic-prefix opening-numbered t depth
)
3863 (setq end
(1+ (point)))
3865 (allout-rebullet-heading (and offer-recent-bullet ref-bullet
)
3867 (if (> relative-depth
0)
3868 (save-excursion (goto-char ref-topic
)
3869 (allout-show-children)))
3872 (run-hook-with-args 'allout-structure-added-functions start end
)
3876 ;;;_ > allout-open-subtopic (arg)
3877 (defun allout-open-subtopic (arg)
3878 "Open new topic header at deeper level than the current one.
3880 Negative universal ARG means to open deeper, but place the new topic
3881 prior to the current one."
3883 (allout-open-topic 1 (> 0 arg
) (< 1 arg
)))
3884 ;;;_ > allout-open-sibtopic (arg)
3885 (defun allout-open-sibtopic (arg)
3886 "Open new topic header at same level as the current one.
3888 Positive universal ARG means to use the bullet of the prior sibling.
3890 Negative universal ARG means to place the new topic prior to the current
3893 (allout-open-topic 0 (> 0 arg
) (not (= 1 arg
))))
3894 ;;;_ > allout-open-supertopic (arg)
3895 (defun allout-open-supertopic (arg)
3896 "Open new topic header at shallower level than the current one.
3898 Negative universal ARG means to open shallower, but place the new
3899 topic prior to the current one."
3902 (allout-open-topic -
1 (> 0 arg
) (< 1 arg
)))
3904 ;;;_ - Outline Alteration
3905 ;;;_ : Topic Modification
3906 ;;;_ = allout-former-auto-filler
3907 (defvar allout-former-auto-filler nil
3908 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3909 ;;;_ > allout-auto-fill ()
3910 (defun allout-auto-fill ()
3911 "`allout-mode' autofill function.
3913 Maintains outline hanging topic indentation if
3914 `allout-use-hanging-indents' is set."
3916 (when (and (not allout-inhibit-auto-fill
)
3917 (or (not allout-inhibit-auto-fill-on-headline
)
3918 (not (allout-on-current-heading-p))))
3919 (let ((fill-prefix (if allout-use-hanging-indents
3920 ;; Check for topic header indentation:
3924 (if (looking-at allout-regexp
)
3925 ;; ... construct indentation to account for
3926 ;; length of topic prefix:
3927 (make-string (progn (allout-end-of-prefix)
3930 (use-auto-fill-function
3931 (if (and (eq allout-outside-normal-auto-fill-function
3933 (eq auto-fill-function
'allout-auto-fill
))
3935 (or allout-outside-normal-auto-fill-function
3936 auto-fill-function
))))
3937 (if (or allout-former-auto-filler allout-use-hanging-indents
)
3938 (funcall use-auto-fill-function
)))))
3939 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3940 (defun allout-reindent-body (old-depth new-depth
&optional number
)
3941 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3943 Optional arg NUMBER indicates numbering is being added, and it must
3946 Note that refill of indented paragraphs is not done."
3949 (allout-end-of-prefix)
3950 (let* ((new-margin (current-column))
3951 excess old-indent-begin old-indent-end
3952 ;; We want the column where the header-prefix text started
3953 ;; *before* the prefix was changed, so we infer it relative
3954 ;; to the new margin and the shift in depth:
3955 (old-margin (+ old-depth
(- new-margin new-depth
))))
3957 ;; Process lines up to (but excluding) next topic header:
3961 (and (re-search-forward "\n\\(\\s-*\\)"
3964 ;; Register the indent data, before we reset the
3965 ;; match data with a subsequent `looking-at':
3966 (setq old-indent-begin
(match-beginning 1)
3967 old-indent-end
(match-end 1))
3968 (not (looking-at allout-regexp
)))
3969 (if (> 0 (setq excess
(- (- old-indent-end old-indent-begin
)
3971 ;; Text starts left of old margin -- don't adjust:
3973 ;; Text was hanging at or right of old left margin --
3974 ;; reindent it, preserving its existing indentation
3975 ;; beyond the old margin:
3976 (delete-region old-indent-begin old-indent-end
)
3977 (indent-to (+ new-margin excess
(current-column))))))))))
3978 ;;;_ > allout-rebullet-current-heading (arg)
3979 (defun allout-rebullet-current-heading (arg)
3980 "Solicit new bullet for current visible heading."
3982 (let ((initial-col (current-column))
3983 (on-bullet (eq (point)(allout-current-bullet-pos)))
3985 (backwards (if (< arg
0)
3986 (setq arg
(* arg -
1)))))
3988 (save-excursion (allout-back-to-current-heading)
3989 (allout-end-of-prefix)
3990 (setq from allout-recent-prefix-beginning
3991 to allout-recent-prefix-end
)
3992 (allout-rebullet-heading t
;;; instead
3994 nil
;;; number-control
3996 t
) ;;; do-successors
3997 (run-hook-with-args 'allout-exposure-change-functions
4002 (setq initial-col nil
) ; Override positioning back to init col
4004 (allout-next-visible-heading 1)
4005 (allout-goto-prefix-doublechecked)
4006 (allout-next-visible-heading -
1))))
4008 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
4009 (initial-col (move-to-column initial-col
)))))
4010 ;;;_ > allout-rebullet-heading (&optional instead ...)
4011 (defun allout-rebullet-heading (&optional instead
4017 "Adjust bullet of current topic prefix.
4019 All args are optional.
4022 - nil, then the bullet char for the context is used, per distinction or depth
4023 - a (numeric) character, then character's string representation is used
4024 - a string, then the user is asked for bullet with the first char as default
4025 - anything else, the user is solicited with bullet char per context as default
4027 Second arg DEPTH forces the topic prefix to that depth, regardless
4028 of the topic's current depth.
4030 Third arg NUMBER-CONTROL can force the prefix to or away from
4031 numbered form. It has effect only if `allout-numbered-bullet' is
4032 non-nil and soliciting was not explicitly invoked (via first arg).
4033 Its effect, numbering or denumbering, then depends on the setting
4034 of the fourth arg, INDEX.
4036 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
4037 prefix of the topic is forced to be non-numbered. Null index and
4038 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
4039 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
4040 INDEX is a number, then that number is used for the numbered
4041 prefix. Non-nil and non-number means that the index for the
4042 numbered prefix will be derived by allout-make-topic-prefix.
4044 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
4047 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
4048 and `allout-numbered-bullet', which all affect the behavior of
4051 (let* ((current-depth (allout-depth))
4052 (new-depth (or new-depth current-depth
))
4053 (mb allout-recent-prefix-beginning
)
4054 (me allout-recent-prefix-end
)
4055 (current-bullet (buffer-substring-no-properties (- me
1) me
))
4056 (has-annotation (get-text-property mb
'allout-was-hidden
))
4057 (new-prefix (allout-make-topic-prefix current-bullet
4064 ;; Is new one identical to old?
4065 (if (and (= current-depth new-depth
)
4066 (string= current-bullet
4067 (substring new-prefix
(1- (length new-prefix
)))))
4071 ;; New prefix probably different from old:
4072 ; get rid of old one:
4073 (allout-unprotected (delete-region mb me
))
4075 ; Dispense with number if
4076 ; numbered-bullet prefix:
4078 (if (and allout-numbered-bullet
4079 (string= allout-numbered-bullet current-bullet
)
4080 (looking-at "[0-9]+"))
4082 (delete-region (match-beginning 0)(match-end 0)))))
4084 ;; convey 'allout-was-hidden annotation, if original had it:
4086 (put-text-property 0 (length new-prefix
) 'allout-was-hidden t
4089 ; Put in new prefix:
4090 (allout-unprotected (insert new-prefix
))
4092 ;; Reindent the body if elected, margin changed, and not encrypted body:
4093 (if (and allout-reindent-bodies
4094 (not (= new-depth current-depth
))
4095 (not (allout-encrypted-topic-p)))
4096 (allout-reindent-body current-depth new-depth
))
4098 (run-hook-with-args 'allout-exposure-change-functions mb me nil
)
4100 ;; Recursively rectify successive siblings of orig topic if
4101 ;; caller elected for it:
4104 (while (allout-next-sibling new-depth nil
)
4106 (cond ((numberp index
) (1+ index
))
4107 ((not number-control
) (allout-sibling-index))))
4108 (if (allout-numbered-type-prefix)
4109 (allout-rebullet-heading nil
;;; instead
4110 new-depth
;;; new-depth
4111 number-control
;;; number-control
4113 nil
))))) ;;;(dont!)do-successors
4114 ) ; (if (and (= current-depth new-depth)...))
4115 ) ; let* ((current-depth (allout-depth))...)
4117 ;;;_ > allout-rebullet-topic (arg)
4118 (defun allout-rebullet-topic (arg &optional sans-offspring
)
4119 "Rebullet the visible topic containing point and all contained subtopics.
4121 Descends into invisible as well as visible topics, however.
4123 When optional SANS-OFFSPRING is non-nil, subtopics are not
4124 shifted. (Shifting a topic outwards without shifting its
4125 offspring is disallowed, since this would create a \"containment
4126 discontinuity\", where the depth difference between a topic and
4127 its immediate offspring is greater than one.)
4129 With repeat count, shift topic depth by that amount."
4131 (let ((start-col (current-column)))
4134 (cond ((null arg
) (setq arg
0))
4135 ((listp arg
) (setq arg
(car arg
))))
4136 ;; Fill the user in, in case we're shifting a big topic:
4137 (if (not (zerop arg
)) (message "Shifting..."))
4138 (allout-back-to-current-heading)
4139 (if (<= (+ allout-recent-depth arg
) 0)
4140 (error "Attempt to shift topic below level 1"))
4141 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring
)
4142 (if (not (zerop arg
)) (message "Shifting... done.")))
4143 (move-to-column (max 0 (+ start-col arg
)))))
4144 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4145 (defun allout-rebullet-topic-grunt (&optional relative-depth
4151 "Like `allout-rebullet-topic', but on nearest containing topic
4154 See `allout-rebullet-heading' for rebulleting behavior.
4156 All arguments are optional.
4158 First arg RELATIVE-DEPTH means to shift the depth of the entire
4161 Several subsequent args are for internal recursive use by the function
4162 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4164 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4165 are not shifted. (Shifting a topic outwards without shifting
4166 its offspring is disallowed, since this would create a
4167 \"containment discontinuity\", where the depth difference between
4168 a topic and its immediate offspring is greater than one.)"
4170 ;; XXX the recursion here is peculiar, and in general the routine may
4171 ;; need simplification with refactoring.
4173 (if (and sans-offspring
4175 (< relative-depth
0))
4176 (error (concat "Attempt to shift topic outwards without offspring,"
4177 " would cause containment discontinuity.")))
4179 (let* ((relative-depth (or relative-depth
0))
4180 (new-depth (allout-depth))
4181 (starting-depth (or starting-depth new-depth
))
4182 (on-starting-call (null starting-point
))
4184 ;; Leave index null on starting call, so rebullet-heading
4185 ;; calculates it at what might be new depth:
4186 (and (or (zerop relative-depth
)
4187 (not on-starting-call
))
4188 (allout-sibling-index))))
4189 (starting-index index
)
4190 (moving-outwards (< 0 relative-depth
))
4191 (starting-point (or starting-point
(point)))
4192 (local-point (point)))
4194 ;; Sanity check for excessive promotion done only on starting call:
4195 (and on-starting-call
4197 (> 0 (+ starting-depth relative-depth
))
4198 (error "Attempt to shift topic out beyond level 1"))
4200 (cond ((= starting-depth new-depth
)
4201 ;; We're at depth to work on this one.
4203 ;; When shifting out we work on the children before working on
4204 ;; the parent to avoid interim `allout-aberrant-container-p'
4205 ;; aberrancy, and vice-versa when shifting in:
4206 (if (>= relative-depth
0)
4207 (allout-rebullet-heading nil
4208 (+ starting-depth relative-depth
)
4211 nil
)) ;;; do-successors
4212 (when (not sans-offspring
)
4213 ;; ... and work on subsequent ones which are at greater depth:
4215 (allout-next-heading)
4216 (while (and (not (eobp))
4217 (< starting-depth
(allout-depth)))
4218 (setq index
(1+ index
))
4219 (allout-rebullet-topic-grunt relative-depth
4223 (when (< relative-depth
0)
4225 (goto-char local-point
)
4226 (allout-rebullet-heading nil
;;; instead
4227 (+ starting-depth relative-depth
)
4230 nil
)))) ;;; do-successors
4232 ((< starting-depth new-depth
)
4233 ;; Rare case -- subtopic more than one level deeper than parent.
4234 ;; Treat this one at an even deeper level:
4235 (allout-rebullet-topic-grunt relative-depth
4241 (if on-starting-call
4243 ;; Rectify numbering of former siblings of the adjusted topic,
4244 ;; if topic has changed depth
4245 (if (or do-successors
4246 (and (not (zerop relative-depth
))
4247 (or (= allout-recent-depth starting-depth
)
4248 (= allout-recent-depth
(+ starting-depth
4250 (allout-rebullet-heading nil nil nil nil t
))
4251 ;; Now rectify numbering of new siblings of the adjusted topic,
4252 ;; if depth has been changed:
4253 (progn (goto-char starting-point
)
4254 (if (not (zerop relative-depth
))
4255 (allout-rebullet-heading nil nil nil nil t
)))))
4258 ;;;_ > allout-renumber-to-depth (&optional depth)
4259 (defun allout-renumber-to-depth (&optional depth
)
4260 "Renumber siblings at current depth.
4262 Affects superior topics if optional arg DEPTH is less than current depth.
4264 Returns final depth."
4266 ;; Proceed by level, processing subsequent siblings on each,
4267 ;; ascending until we get shallower than the start depth:
4269 (let ((ascender (allout-depth))
4271 (while (and (not (eobp))
4273 (>= allout-recent-depth depth
)
4274 (>= ascender depth
))
4275 ; Skip over all topics at
4276 ; lesser depths, which can not
4277 ; have been disturbed:
4278 (while (and (not (setq was-eobp
(eobp)))
4279 (> allout-recent-depth ascender
))
4280 (allout-next-heading))
4281 ; Prime ascender for ascension:
4282 (setq ascender
(1- allout-recent-depth
))
4283 (if (>= allout-recent-depth depth
)
4284 (allout-rebullet-heading nil
;;; instead
4286 nil
;;; number-control
4288 t
)) ;;; do-successors
4289 (if was-eobp
(goto-char (point-max)))))
4290 allout-recent-depth
)
4291 ;;;_ > allout-number-siblings (&optional denumber)
4292 (defun allout-number-siblings (&optional denumber
)
4293 "Assign numbered topic prefix to this topic and its siblings.
4295 With universal argument, denumber -- assign default bullet to this
4296 topic and its siblings.
4298 With repeated universal argument (`^U^U'), solicit bullet for each
4299 rebulleting each topic at this level."
4304 (allout-back-to-current-heading)
4305 (allout-beginning-of-level)
4306 (let ((depth allout-recent-depth
)
4307 (index (if (not denumber
) 1))
4308 (use-bullet (equal '(16) denumber
))
4311 (allout-rebullet-heading use-bullet
;;; instead
4313 t
;;; number-control
4315 nil
) ;;; do-successors
4316 (if index
(setq index
(1+ index
)))
4317 (setq more
(allout-next-sibling depth nil
))))))
4318 ;;;_ > allout-shift-in (arg)
4319 (defun allout-shift-in (arg)
4320 "Increase depth of current heading and any items collapsed within it.
4322 With a negative argument, the item is shifted out using
4323 `allout-shift-out', instead.
4325 With an argument greater than one, shift-in the item but not its
4326 offspring, making the item into a sibling of its former children,
4327 and a child of sibling that formerly preceded it.
4329 You are not allowed to shift the first offspring of a topic
4330 inwards, because that would yield a \"containment
4331 discontinuity\", where the depth difference between a topic and
4332 its immediate offspring is greater than one. The first topic in
4333 the file can be adjusted to any positive depth, however."
4337 (allout-shift-out (* arg -
1))
4338 ;; refuse to create a containment discontinuity:
4340 (allout-back-to-current-heading)
4342 (let* ((current-depth allout-recent-depth
)
4343 (start-point (point))
4344 (predecessor-depth (progn
4346 (allout-goto-prefix-doublechecked)
4347 (if (< (point) start-point
)
4350 (if (and (> predecessor-depth
0)
4351 (> (1+ current-depth
)
4352 (1+ predecessor-depth
)))
4353 (error (concat "Disallowed shift deeper than"
4354 " containing topic's children."))
4355 (allout-back-to-current-heading)
4356 (if (< allout-recent-depth
(1+ current-depth
))
4357 (allout-show-children))))))
4358 (let ((where (point)))
4359 (allout-rebullet-topic 1 (and (> arg
1) 'sans-offspring
))
4360 (run-hook-with-args 'allout-structure-shifted-functions arg where
))))
4361 ;;;_ > allout-shift-out (arg)
4362 (defun allout-shift-out (arg)
4363 "Decrease depth of current heading and any topics collapsed within it.
4364 This will make the item a sibling of its former container.
4366 With a negative argument, the item is shifted in using
4367 `allout-shift-in', instead.
4369 With an argument greater than one, shift-out the item's offspring
4370 but not the item itself, making the former children siblings of
4373 With an argument greater than 1, the item's offspring are shifted
4374 out without shifting the item. This will make the immediate
4375 subtopics into siblings of the item."
4378 (allout-shift-in (* arg -
1))
4379 ;; Get proper exposure in this area:
4380 (save-excursion (if (allout-ascend)
4381 (allout-show-children)))
4382 ;; Show collapsed children if there's a successor which will become
4384 (if (and (allout-current-topic-collapsed-p)
4385 (save-excursion (allout-next-sibling)))
4386 (allout-show-children))
4387 (let ((where (and (allout-depth) allout-recent-prefix-beginning
)))
4390 ;; Shift the offspring but not the topic:
4391 (let ((children-chart (allout-chart-subtree 1)))
4392 (if (listp (car children-chart
))
4394 (setq children-chart
(allout-flatten children-chart
)))
4396 (dolist (child-point children-chart
)
4397 (goto-char child-point
)
4398 (allout-shift-out 1))))
4399 (allout-rebullet-topic (* arg -
1))))
4400 (run-hook-with-args 'allout-structure-shifted-functions
(* arg -
1) where
))))
4401 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4402 ;;;_ > allout-kill-line (&optional arg)
4403 (defun allout-kill-line (&optional arg
)
4404 "Kill line, adjusting subsequent lines suitably for outline mode."
4408 (if (or (not (allout-mode-p))
4410 (not (save-match-data (looking-at allout-regexp
))))
4411 ;; Just do a regular kill:
4413 ;; Ah, have to watch out for adjustments:
4414 (let* ((beg (point))
4416 (beg-hidden (allout-hidden-p))
4417 (end-hidden (save-excursion (allout-end-of-current-line)
4420 (depth (allout-depth)))
4422 (allout-annotate-hidden beg end
)
4424 (if (and (not beg-hidden
) (not end-hidden
))
4425 (allout-unprotected (kill-line arg
))
4427 (run-hooks 'allout-after-copy-or-kill-hook
)
4428 (allout-deannotate-hidden beg end
)
4430 (if allout-numbered-bullet
4431 (save-excursion ; Renumber subsequent topics if needed:
4432 (if (not (save-match-data (looking-at allout-regexp
)))
4433 (allout-next-heading))
4434 (allout-renumber-to-depth depth
)))
4435 (run-hook-with-args 'allout-structure-deleted-functions depth
(point))))))
4436 ;;;_ > allout-copy-line-as-kill ()
4437 (defun allout-copy-line-as-kill ()
4438 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4440 (let ((buffer-read-only t
))
4443 (buffer-read-only nil
))))
4444 ;;;_ > allout-kill-topic ()
4445 (defun allout-kill-topic ()
4446 "Kill topic together with subtopics.
4448 Trailing whitespace is killed with a topic if that whitespace:
4450 - would separate the topic from a subsequent sibling
4451 - would separate the topic from the end of buffer
4452 - would not be added to whitespace already separating the topic from the
4455 Topic exposure is marked with text-properties, to be used by
4456 `allout-yank-processing' for exposure recovery."
4459 (let* ((inhibit-field-text-motion t
)
4460 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4462 (depth allout-recent-depth
))
4463 (allout-end-of-current-subtree)
4464 (if (and (/= (current-column) 0) (not (eobp)))
4467 (if (and (save-match-data (looking-at "\n"))
4469 (or (not (allout-next-heading))
4470 (= depth allout-recent-depth
)))
4471 (and (> (- beg
(point-min)) 3)
4472 (string= (buffer-substring (- beg
2) beg
) "\n\n"))))
4475 (allout-annotate-hidden beg
(setq end
(point)))
4476 (unwind-protect ; for possible barf-if-buffer-read-only.
4477 (allout-unprotected (kill-region beg end
))
4478 (allout-deannotate-hidden beg end
)
4479 (run-hooks 'allout-after-copy-or-kill-hook
)
4482 (allout-renumber-to-depth depth
))
4483 (run-hook-with-args 'allout-structure-deleted-functions depth
(point)))))
4484 ;;;_ > allout-copy-topic-as-kill ()
4485 (defun allout-copy-topic-as-kill ()
4486 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4488 (let ((buffer-read-only t
))
4491 (buffer-read-only (message "Topic copied...")))))
4492 ;;;_ > allout-annotate-hidden (begin end)
4493 (defun allout-annotate-hidden (begin end
)
4494 "Qualify text with properties to indicate exposure status."
4496 (let ((was-modified (buffer-modified-p))
4497 (buffer-read-only nil
))
4498 (allout-deannotate-hidden begin end
)
4501 (let (done next prev overlay
)
4503 ;; at or advance to start of next hidden region:
4504 (if (not (allout-hidden-p))
4507 (allout-next-single-char-property-change (point)
4510 (if (or (not next
) (eq prev next
))
4511 ;; still not at start of hidden area -- must not be any left.
4515 (if (not (allout-hidden-p))
4516 ;; still not at start of hidden area.
4518 (setq overlay
(allout-get-invisibility-overlay))
4519 (setq next
(overlay-end overlay
)
4521 ;; advance to end of this hidden area:
4525 (let ((buffer-undo-list t
))
4526 (put-text-property (overlay-start overlay
) next
4527 'allout-was-hidden t
)))))))))
4528 (set-buffer-modified-p was-modified
)))
4529 ;;;_ > allout-deannotate-hidden (begin end)
4530 (defun allout-deannotate-hidden (begin end
)
4531 "Remove allout hidden-text annotation between BEGIN and END."
4534 (let ((inhibit-read-only t
)
4535 (buffer-undo-list t
))
4536 (remove-text-properties begin
(min end
(point-max))
4537 '(allout-was-hidden t
)))))
4538 ;;;_ > allout-hide-by-annotation (begin end)
4539 (defun allout-hide-by-annotation (begin end
)
4540 "Translate text properties indicating exposure status into actual exposure."
4543 (let ((was-modified (buffer-modified-p))
4546 ;; at or advance to start of next annotation:
4547 (if (not (get-text-property (point) 'allout-was-hidden
))
4548 (setq next
(allout-next-single-char-property-change
4549 (point) 'allout-was-hidden nil end
)))
4550 (if (or (not next
) (eq prev next
))
4551 ;; no more or not advancing -- must not be any left.
4555 (if (not (get-text-property (point) 'allout-was-hidden
))
4556 ;; still not at start of annotation.
4558 ;; advance to just after end of this annotation:
4559 (setq next
(allout-next-single-char-property-change
4560 (point) 'allout-was-hidden nil end
))
4561 (let ((o (make-overlay prev next nil
'front-advance
)))
4562 (overlay-put o
'category
'allout-exposure-category
)
4563 (overlay-put o
'evaporate t
))
4564 (allout-deannotate-hidden prev next
)
4566 (if next
(goto-char next
)))))
4567 (set-buffer-modified-p was-modified
))))
4568 ;;;_ > allout-yank-processing ()
4569 (defun allout-yank-processing (&optional arg
)
4571 "Incidental allout-specific business to be done just after text yanks.
4573 Does depth adjustment of yanked topics, when:
4575 1 the stuff being yanked starts with a valid outline header prefix, and
4576 2 it is being yanked at the end of a line which consists of only a valid
4579 Also, adjusts numbering of subsequent siblings when appropriate.
4581 Depth adjustment alters the depth of all the topics being yanked
4582 the amount it takes to make the first topic have the depth of the
4583 header into which it's being yanked.
4585 The point is left in front of yanked, adjusted topics, rather than
4586 at the end (and vice-versa with the mark). Non-adjusted yanks,
4587 however, are left exactly like normal, non-allout-specific yanks."
4590 ; Get to beginning, leaving
4591 ; region around subject:
4592 (if (< (allout-mark-marker t
) (point))
4593 (exchange-point-and-mark))
4595 (let* ((subj-beg (point))
4597 (subj-end (allout-mark-marker t
))
4598 ;; 'resituate' if yanking an entire topic into topic header:
4599 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t
))
4600 (allout-e-o-prefix-p))
4601 (looking-at allout-regexp
)
4602 (allout-prefix-data)))
4603 ;; `rectify-numbering' if resituating (where several topics may
4604 ;; be resituating) or yanking a topic into a topic slot (bol):
4605 (rectify-numbering (or resituate
4606 (and into-bol
(looking-at allout-regexp
)))))
4608 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4609 (let* ((inhibit-field-text-motion t
)
4610 (prefix-len (if (not (match-end 1))
4612 (- (match-end 1) subj-beg
)))
4613 (subj-depth allout-recent-depth
)
4614 (prefix-bullet (allout-recent-bullet))
4616 ;; Nil if adjustment unnecessary, otherwise depth to which
4617 ;; adjustment should be made:
4619 (and (goto-char subj-end
)
4621 (goto-char subj-beg
)
4622 (and (looking-at allout-regexp
)
4625 (not (= (point) subj-beg
)))
4626 (looking-at allout-regexp
)
4627 (allout-prefix-data))
4628 allout-recent-depth
)))
4630 (setq rectify-numbering allout-numbered-bullet
)
4632 ; Do the adjustment:
4635 (narrow-to-region subj-beg subj-end
)
4636 ; Trim off excessive blank
4637 ; line at end, if any:
4638 (goto-char (point-max))
4639 (if (looking-at "^$")
4640 (allout-unprotected (delete-char -
1)))
4641 ; Work backwards, with each
4643 ; successively excluding the
4644 ; last processed topic from
4645 ; the narrow region:
4647 (allout-back-to-current-heading)
4648 ; go as high as we can in each bunch:
4649 (while (allout-ascend t
))
4652 (allout-rebullet-topic-grunt (- adjust-to-depth
4655 (if (setq more
(not (bobp)))
4658 (narrow-to-region subj-beg
(point))))))
4659 ;; Remove new heading prefix:
4662 (delete-region (point) (+ (point)
4666 ; and delete residual subj
4667 ; prefix digits and space:
4668 (while (looking-at "[0-9]") (delete-char 1))
4672 ;; Assert new topic's bullet - minimal effort if unchanged:
4673 (allout-rebullet-heading (string-to-char prefix-bullet
)))
4674 (exchange-point-and-mark))))
4675 (if rectify-numbering
4678 ; Give some preliminary feedback:
4679 (message "... reconciling numbers")
4680 ; ... and renumber, in case necessary:
4681 (goto-char subj-beg
)
4682 (if (allout-goto-prefix-doublechecked)
4684 (allout-rebullet-heading nil
;;; instead
4685 (allout-depth) ;;; depth
4686 nil
;;; number-control
4690 (if (or into-bol resituate
)
4691 (allout-hide-by-annotation (point) (allout-mark-marker t
))
4692 (allout-deannotate-hidden (allout-mark-marker t
) (point)))
4694 (exchange-point-and-mark))
4695 (run-hook-with-args 'allout-structure-added-functions subj-beg subj-end
))))
4696 ;;;_ > allout-yank (&optional arg)
4697 (defun allout-yank (&optional arg
)
4698 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4700 Non-topic yanks work no differently than normal yanks.
4702 If a topic is being yanked into a bare topic prefix, the depth of the
4703 yanked topic is adjusted to the depth of the topic prefix.
4705 1 we're yanking in an `allout-mode' buffer
4706 2 the stuff being yanked starts with a valid outline header prefix, and
4707 3 it is being yanked at the end of a line which consists of only a valid
4710 If these conditions hold then the depth of the yanked topics are all
4711 adjusted the amount it takes to make the first one at the depth of the
4712 header into which it's being yanked.
4714 The point is left in front of yanked, adjusted topics, rather than
4715 at the end (and vice-versa with the mark). Non-adjusted yanks,
4716 however, (ones that don't qualify for adjustment) are handled
4717 exactly like normal yanks.
4719 Numbering of yanked topics, and the successive siblings at the depth
4720 into which they're being yanked, is adjusted.
4722 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4723 works with normal `yank' in non-outline buffers."
4726 (setq this-command
'yank
)
4730 (allout-yank-processing)))
4731 ;;;_ > allout-yank-pop (&optional arg)
4732 (defun allout-yank-pop (&optional arg
)
4733 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4735 Adapts level of popped topics to level of fresh prefix.
4737 Note -- prefix changes to distinctive bullets will stick, if followed
4738 by pops to non-distinctive yanks. Bug..."
4741 (setq this-command
'yank
)
4744 (allout-yank-processing)))
4746 ;;;_ - Specialty bullet functions
4747 ;;;_ : File Cross references
4748 ;;;_ > allout-resolve-xref ()
4749 (defun allout-resolve-xref ()
4750 "Pop to file associated with current heading, if it has an xref bullet.
4752 \(Works according to setting of `allout-file-xref-bullet')."
4754 (if (not allout-file-xref-bullet
)
4756 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4757 (if (not (string= (allout-current-bullet) allout-file-xref-bullet
))
4758 (error "Current heading lacks cross-reference bullet `%s'"
4759 allout-file-xref-bullet
)
4760 (let ((inhibit-field-text-motion t
)
4764 (let* ((text-start allout-recent-prefix-end
)
4765 (heading-end (point-at-eol)))
4766 (goto-char text-start
)
4768 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
4769 (buffer-substring (match-beginning 1)
4771 (setq file-name
(expand-file-name file-name
))
4772 (if (or (file-exists-p file-name
)
4773 (if (file-writable-p file-name
)
4774 (y-or-n-p (format "%s not there, create one? "
4776 (error "%s not found and can't be created" file-name
)))
4777 (condition-case failure
4778 (find-file-other-window file-name
)
4780 (error "%s not found" file-name
))
4786 ;;;_ #6 Exposure Control
4789 ;;;_ > allout-flag-region (from to flag)
4790 (defun allout-flag-region (from to flag
)
4791 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4792 After the exposure changes are made, run the abnormal hook
4793 `allout-exposure-change-functions' with the same arguments as
4796 ;; We use outline invisibility spec.
4797 (remove-overlays from to
'category
'allout-exposure-category
)
4799 (let ((o (make-overlay from to nil
'front-advance
)))
4800 (overlay-put o
'category
'allout-exposure-category
)
4801 (overlay-put o
'evaporate t
)
4802 (when (featurep 'xemacs
)
4803 (let ((props (symbol-plist 'allout-exposure-category
)))
4806 ;; as of 2008-02-27, xemacs lacks modification-hooks
4807 (overlay-put o
(pop props
) (pop props
))
4809 (setq allout-this-command-hid-text t
))
4810 (run-hook-with-args 'allout-exposure-change-functions from to flag
))
4811 ;;;_ > allout-flag-current-subtree (flag)
4812 (defun allout-flag-current-subtree (flag)
4813 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4816 (allout-back-to-current-heading)
4817 (let ((inhibit-field-text-motion t
))
4819 (allout-flag-region (point)
4820 ;; Exposing must not leave trailing blanks hidden,
4821 ;; but can leave them exposed when hiding, so we
4822 ;; can use flag's inverse as the
4823 ;; include-trailing-blank cue:
4824 (allout-end-of-current-subtree (not flag
))
4827 ;;;_ - Topic-specific
4828 ;;;_ > allout-show-entry ()
4829 (defun allout-show-entry ()
4830 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4832 This is a way to give restricted peek at a concealed locality without the
4833 expense of exposing its context, but can leave the outline with aberrant
4834 exposure. `allout-show-offshoot' should be used after the peek to rectify
4840 (allout-goto-prefix-doublechecked)
4841 (setq beg
(if (allout-hidden-p) (1- (point)) (point)))
4842 (setq end
(allout-pre-next-prefix))
4843 (allout-flag-region beg end nil
)
4845 ;;;_ > allout-show-children (&optional level strict)
4846 (defun allout-show-children (&optional level strict
)
4848 "If point is visible, show all direct subheadings of this heading.
4850 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4852 Optional LEVEL specifies how many levels below the current level
4853 should be shown, or all levels if t. Default is 1.
4855 Optional STRICT means don't resort to -show-to-offshoot, no matter
4856 what. This is basically so -show-to-offshoot, which is called by
4857 this function, can employ the pure offspring-revealing capabilities of
4860 Returns point at end of subtree that was opened, if any. (May get a
4861 point of non-opened subtree?)"
4864 (let ((start-point (point)))
4865 (if (and (not strict
)
4868 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4870 ;; Then recurse, but with "strict" set so we don't
4871 ;; infinite regress:
4872 (allout-show-children level t
))
4875 (allout-beginning-of-current-line)
4878 ;; translate the level spec for this routine to the ones
4879 ;; used by -chart-subtree and -chart-to-reveal:
4880 (chart-level (cond ((not level
) 1)
4883 (chart (allout-chart-subtree chart-level
))
4884 (to-reveal (or (allout-chart-to-reveal chart chart-level
)
4885 ;; interactive, show discontinuous children:
4887 (allout-called-interactively-p)
4889 (allout-back-to-current-heading)
4890 (setq depth
(allout-current-depth))
4891 (and (allout-next-heading)
4892 (> allout-recent-depth
4895 "Discontinuous offspring; use `%s %s'%s."
4896 (substitute-command-keys
4897 "\\[universal-argument]")
4898 (substitute-command-keys
4899 "\\[allout-shift-out]")
4900 " to elevate them.")
4901 (allout-chart-to-reveal
4902 chart
(- allout-recent-depth depth
))))))
4903 (goto-char start-point
)
4904 (when (and strict
(allout-hidden-p))
4905 ;; Concealed root would already have been taken care of,
4906 ;; unless strict was set.
4907 (allout-flag-region (point) (allout-snug-back) nil
)
4908 (when allout-show-bodies
4909 (goto-char (car to-reveal
))
4910 (allout-show-current-entry)))
4912 (goto-char (car to-reveal
))
4913 (allout-flag-region (save-excursion (allout-snug-back) (point))
4914 (progn (search-forward "\n" nil t
)
4917 (when allout-show-bodies
4918 (goto-char (car to-reveal
))
4919 (allout-show-current-entry))
4920 (setq to-reveal
(cdr to-reveal
)))))))
4921 ;; Compensate for `save-excursion's maintenance of point
4922 ;; within invisible text:
4923 (goto-char start-point
)))
4924 ;;;_ > allout-show-to-offshoot ()
4925 (defun allout-show-to-offshoot ()
4926 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4928 Useful for coherently exposing to a random point in a hidden region."
4931 (let ((inhibit-field-text-motion t
)
4933 (orig-pref (allout-goto-prefix-doublechecked))
4936 (while (or (> bag-it
1) (allout-hidden-p))
4937 (while (allout-hidden-p)
4938 (move-beginning-of-line 1)
4939 (if (allout-hidden-p) (forward-char -
1)))
4940 (if (= last-at
(setq last-at
(point)))
4941 ;; Oops, we're not making any progress! Show the current topic
4942 ;; completely, and try one more time here, if we haven't already.
4943 (progn (beginning-of-line)
4944 (allout-show-current-subtree)
4946 (setq bag-it
(1+ bag-it
))
4948 (error "allout-show-to-offshoot: %s"
4949 "Stumped by aberrant nesting.")))
4950 (if (> bag-it
0) (setq bag-it
0))
4951 (allout-show-children)
4952 (goto-char orig-pref
)))
4953 (goto-char orig-pt
)))
4954 (if (allout-hidden-p)
4955 (allout-show-entry)))
4956 ;;;_ > allout-hide-current-entry ()
4957 (defun allout-hide-current-entry ()
4958 "Hide the body directly following this heading."
4960 (allout-back-to-current-heading)
4962 (let ((inhibit-field-text-motion t
))
4964 (allout-flag-region (point)
4965 (progn (allout-end-of-entry) (point))
4967 ;;;_ > allout-show-current-entry (&optional arg)
4968 (defun allout-show-current-entry (&optional arg
)
4969 "Show body following current heading, or hide entry with universal argument."
4973 (allout-hide-current-entry)
4974 (save-excursion (allout-show-to-offshoot))
4976 (allout-flag-region (point)
4977 (progn (allout-end-of-entry t
) (point))
4980 ;;;_ > allout-show-current-subtree (&optional arg)
4981 (defun allout-show-current-subtree (&optional arg
)
4982 "Show everything within the current topic.
4983 With a repeat-count, expose this topic and its siblings."
4986 (if (<= (allout-current-depth) 0)
4987 ;; Outside any topics -- try to get to the first:
4988 (if (not (allout-next-heading))
4990 ;; got to first, outermost topic -- set to expose it and siblings:
4991 (message "Above outermost topic -- exposing all.")
4992 (allout-flag-region (point-min)(point-max) nil
))
4993 (allout-beginning-of-current-line)
4995 (allout-flag-current-subtree nil
)
4996 (allout-beginning-of-level)
4997 (allout-expose-topic '(* :))))))
4998 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4999 (defun allout-current-topic-collapsed-p (&optional include-single-liners
)
5000 "True if the currently visible containing topic is already collapsed.
5002 Single line topics intrinsically can be considered as being both
5003 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
5004 true, then single-line topics are considered to be collapsed. By
5005 default, they are treated as being uncollapsed."
5009 ;; Is the topic all on one line (allowing for trailing blank line)?
5010 (>= (progn (allout-back-to-current-heading)
5011 (let ((inhibit-field-text-motion t
))
5012 (move-end-of-line 1))
5014 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
5016 (or include-single-liners
5017 (progn (backward-char 1) (allout-hidden-p)))))))
5018 ;;;_ > allout-hide-current-subtree (&optional just-close)
5019 (defun allout-hide-current-subtree (&optional just-close
)
5020 "Close the current topic, or containing topic if this one is already closed.
5022 If this topic is closed and it's a top level topic, close this topic
5025 If optional arg JUST-CLOSE is non-nil, do not close the parent or
5026 siblings, even if the target topic is already closed."
5029 (let* ((from (point))
5030 (sibs-msg "Top-level topic already closed -- closing siblings...")
5031 (current-exposed (not (allout-current-topic-collapsed-p t
))))
5032 (cond (current-exposed (allout-flag-current-subtree t
))
5034 ((allout-ascend) (allout-hide-current-subtree))
5037 (allout-goto-prefix-doublechecked)
5038 (allout-expose-topic '(0 :))
5039 (message (concat sibs-msg
" Done."))))
5041 ;;;_ > allout-toggle-current-subtree-exposure
5042 (defun allout-toggle-current-subtree-exposure ()
5043 "Show or hide the current subtree depending on its current state."
5044 ;; thanks to tassilo for suggesting this.
5047 (allout-back-to-heading)
5048 (if (allout-hidden-p (point-at-eol))
5049 (allout-show-current-subtree)
5050 (allout-hide-current-subtree))))
5051 ;;;_ > allout-show-current-branches ()
5052 (defun allout-show-current-branches ()
5053 "Show all subheadings of this heading, but not their bodies."
5055 (let ((inhibit-field-text-motion t
))
5056 (beginning-of-line))
5057 (allout-show-children t
))
5058 ;;;_ > allout-hide-current-leaves ()
5059 (defun allout-hide-current-leaves ()
5060 "Hide the bodies of the current topic and all its offspring."
5062 (allout-back-to-current-heading)
5063 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
5066 ;;;_ - Region and beyond
5067 ;;;_ > allout-show-all ()
5068 (defun allout-show-all ()
5069 "Show all of the text in the buffer."
5071 (message "Exposing entire buffer...")
5072 (allout-flag-region (point-min) (point-max) nil
)
5073 (message "Exposing entire buffer... Done."))
5074 ;;;_ > allout-hide-bodies ()
5075 (defun allout-hide-bodies ()
5076 "Hide all of buffer except headings."
5078 (allout-hide-region-body (point-min) (point-max)))
5079 ;;;_ > allout-hide-region-body (start end)
5080 (defun allout-hide-region-body (start end
)
5081 "Hide all body lines in the region, but not headings."
5085 (narrow-to-region start end
)
5086 (goto-char (point-min))
5087 (let ((inhibit-field-text-motion t
))
5090 (allout-flag-region (point) (allout-end-of-entry) t
)
5093 (if (looking-at "\n\n")
5096 ;;;_ > allout-expose-topic (spec)
5097 (defun allout-expose-topic (spec)
5098 "Apply exposure specs to successive outline topic items.
5100 Use the more convenient frontend, `allout-new-exposure', if you don't
5101 need evaluation of the arguments, or even better, the `allout-layout'
5102 variable-keyed mode-activation/auto-exposure feature of allout outline
5103 mode. See the respective documentation strings for more details.
5105 Cursor is left at start position.
5107 SPEC is either a number or a list.
5109 Successive specs on a list are applied to successive sibling topics.
5111 A simple spec (either a number, one of a few symbols, or the null
5112 list) dictates the exposure for the corresponding topic.
5114 Non-null lists recursively designate exposure specs for respective
5115 subtopics of the current topic.
5117 The `:' repeat spec is used to specify exposure for any number of
5118 successive siblings, up to the trailing ones for which there are
5119 explicit specs following the `:'.
5121 Simple (numeric and null-list) specs are interpreted as follows:
5123 Numbers indicate the relative depth to open the corresponding topic.
5124 - negative numbers force the topic to be closed before opening to the
5125 absolute value of the number, so all siblings are open only to
5127 - positive numbers open to the relative depth indicated by the
5128 number, but do not force already opened subtopics to be closed.
5129 - 0 means to close topic -- hide all offspring.
5131 apply prior element to all siblings at current level, *up to*
5132 those siblings that would be covered by specs following the `:'
5133 on the list. Ie, apply to all topics at level but the last
5134 ones. (Only first of multiple colons at same level is
5135 respected -- subsequent ones are discarded.)
5136 * - completely opens the topic, including bodies.
5137 + - shows all the sub headers, but not the bodies
5138 - - exposes the body of the corresponding topic.
5141 \(allout-expose-topic '(-1 : 0))
5142 Close this and all following topics at current level, exposing
5143 only their immediate children, but close down the last topic
5144 at this current level completely.
5145 \(allout-expose-topic '(-1 () : 1 0))
5146 Close current topic so only the immediate subtopics are shown;
5147 show the children in the second to last topic, and completely
5149 \(allout-expose-topic '(-2 : -1 *))
5150 Expose children and grandchildren of all topics at current
5151 level except the last two; expose children of the second to
5152 last and completely open the last one."
5154 (interactive "xExposure spec: ")
5155 (if (not (listp spec
))
5157 (let ((depth (allout-depth))
5162 (setq prev-elem curr-elem
5163 curr-elem
(car spec
)
5165 (cond ; Do current element:
5166 ((null curr-elem
) nil
)
5167 ((symbolp curr-elem
)
5168 (cond ((eq curr-elem
'*) (allout-show-current-subtree)
5169 (if (> allout-recent-end-of-subtree max-pos
)
5170 (setq max-pos allout-recent-end-of-subtree
)))
5172 (if (not (allout-hidden-p))
5173 (save-excursion (allout-hide-current-subtree t
)))
5174 (allout-show-current-branches)
5175 (if (> allout-recent-end-of-subtree max-pos
)
5176 (setq max-pos allout-recent-end-of-subtree
)))
5177 ((eq curr-elem
'-
) (allout-show-current-entry))
5180 ;; Expand the `repeat' spec to an explicit version,
5181 ;; w.r.t. remaining siblings:
5182 (let ((residue ; = # of sibs not covered by remaining spec
5183 ;; Dang, could be nice to make use of the chart, sigh:
5184 (- (length (allout-chart-siblings))
5187 ;; Some residue -- cover it with prev-elem:
5188 (setq spec
(append (make-list residue prev-elem
)
5190 ((numberp curr-elem
)
5191 (if (and (>= 0 curr-elem
) (not (allout-hidden-p)))
5192 (save-excursion (allout-hide-current-subtree t
)
5195 (if (> allout-recent-end-of-subtree max-pos
)
5197 allout-recent-end-of-subtree
)))))
5198 (if (> (abs curr-elem
) 0)
5199 (progn (allout-show-children (abs curr-elem
))
5200 (if (> allout-recent-end-of-subtree max-pos
)
5201 (setq max-pos allout-recent-end-of-subtree
)))))
5203 (if (allout-descend-to-depth (1+ depth
))
5204 (let ((got (allout-expose-topic curr-elem
)))
5205 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
5206 (cond (stay (setq stay nil
))
5207 ((listp (car spec
)) nil
)
5208 ((> max-pos
(point))
5209 ;; Capitalize on max-pos state to get us nearer next sibling:
5210 (progn (goto-char (min (point-max) max-pos
))
5211 (allout-next-heading)))
5212 ((allout-next-sibling depth
))))
5214 ;;;_ > allout-old-expose-topic (spec &rest followers)
5215 (defun allout-old-expose-topic (spec &rest followers
)
5217 "Deprecated. Use `allout-expose-topic' (with different schema
5220 Dictate wholesale exposure scheme for current topic, according to SPEC.
5222 SPEC is either a number or a list. Optional successive args
5223 dictate exposure for subsequent siblings of current topic.
5225 A simple spec (either a number, a special symbol, or the null list)
5226 dictates the overall exposure for a topic. Non null lists are
5227 composite specs whose first element dictates the overall exposure for
5228 a topic, with the subsequent elements in the list interpreted as specs
5229 that dictate the exposure for the successive offspring of the topic.
5231 Simple (numeric and null-list) specs are interpreted as follows:
5233 - Numbers indicate the relative depth to open the corresponding topic:
5234 - negative numbers force the topic to be close before opening to the
5235 absolute value of the number.
5236 - positive numbers just open to the relative depth indicated by the number.
5238 - `*' completely opens the topic, including bodies.
5239 - `+' shows all the sub headers, but not the bodies
5240 - `-' exposes the body and immediate offspring of the corresponding topic.
5242 If the spec is a list, the first element must be a number, which
5243 dictates the exposure depth of the topic as a whole. Subsequent
5244 elements of the list are nested SPECs, dictating the specific exposure
5245 for the corresponding offspring of the topic.
5247 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5249 (interactive "xExposure spec: ")
5250 (let ((inhibit-field-text-motion t
)
5251 (depth (allout-current-depth))
5253 (cond ((null spec
) nil
)
5255 (if (eq spec
'*) (allout-show-current-subtree))
5256 (if (eq spec
'+) (allout-show-current-branches))
5257 (if (eq spec
'-
) (allout-show-current-entry)))
5260 (save-excursion (allout-hide-current-subtree t
)
5262 (if (or (not max-pos
)
5263 (> (point) max-pos
))
5264 (setq max-pos
(point)))
5266 (setq spec
(* -
1 spec
)))))
5268 (allout-show-children spec
)))
5270 ;(let ((got (allout-old-expose-topic (car spec))))
5271 ; (if (and got (or (not max-pos) (> got max-pos)))
5272 ; (setq max-pos got)))
5273 (let ((new-depth (+ (allout-current-depth) 1))
5275 (setq max-pos
(allout-old-expose-topic (car spec
)))
5276 (setq spec
(cdr spec
))
5278 (allout-descend-to-depth new-depth
)
5279 (not (allout-hidden-p)))
5280 (progn (setq got
(apply 'allout-old-expose-topic spec
))
5281 (if (and got
(or (not max-pos
) (> got max-pos
)))
5282 (setq max-pos got
)))))))
5283 (while (and followers
5284 (progn (if (and max-pos
(< (point) max-pos
))
5285 (progn (goto-char max-pos
)
5286 (setq max-pos nil
)))
5288 (allout-next-sibling depth
)))
5289 (allout-old-expose-topic (car followers
))
5290 (setq followers
(cdr followers
)))
5292 ;;;_ > allout-new-exposure '()
5293 (defmacro allout-new-exposure
(&rest spec
)
5294 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5295 Some arguments that would need to be quoted in `allout-expose-topic'
5296 need not be quoted in `allout-new-exposure'.
5298 Cursor is left at start position.
5300 Use this instead of obsolete `allout-exposure'.
5303 \(allout-new-exposure (-1 () () () 1) 0)
5304 Close current topic at current level so only the immediate
5305 subtopics are shown, except also show the children of the
5306 third subtopic; and close the next topic at the current level.
5307 \(allout-new-exposure : -1 0)
5308 Close all topics at current level to expose only their
5309 immediate children, except for the last topic at the current
5310 level, in which even its immediate children are hidden.
5311 \(allout-new-exposure -2 : -1 *)
5312 Expose children and grandchildren of first topic at current
5313 level, and expose children of subsequent topics at current
5314 level *except* for the last, which should be opened completely."
5315 (list 'save-excursion
5316 '(if (not (or (allout-goto-prefix-doublechecked)
5317 (allout-next-heading)))
5318 (error "allout-new-exposure: Can't find any outline topics"))
5319 (list 'allout-expose-topic
(list 'quote spec
))))
5321 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5323 ;;;_ - Mapping and processing of topics
5324 ;;;_ ( See also Subtree Charting, in Navigation code.)
5325 ;;;_ > allout-stringify-flat-index (flat-index)
5326 (defun allout-stringify-flat-index (flat-index &optional context
)
5327 "Convert list representing section/subsection/... to document string.
5329 Optional arg CONTEXT indicates interior levels to include."
5333 (context-depth (or (and context
2) 1)))
5334 ;; Take care of the explicit context:
5335 (while (> context-depth
0)
5336 (setq numstr
(int-to-string (car flat-index
))
5337 flat-index
(cdr flat-index
)
5338 result
(if flat-index
5339 (cons delim
(cons numstr result
))
5340 (cons numstr result
))
5341 context-depth
(if flat-index
(1- context-depth
) 0)))
5343 ;; Take care of the indentation:
5350 (1+ (truncate (if (zerop (car flat-index
))
5352 (log10 (car flat-index
)))))
5355 (setq flat-index
(cdr flat-index
)))
5356 ;; Dispose of single extra delim:
5357 (setq result
(cdr result
))))
5358 (apply 'concat result
)))
5359 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5360 (defun allout-stringify-flat-index-plain (flat-index)
5361 "Convert list representing section/subsection/... to document string."
5365 (setq result
(cons (int-to-string (car flat-index
))
5367 (cons delim result
))))
5368 (setq flat-index
(cdr flat-index
)))
5369 (apply 'concat result
)))
5370 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5371 (defun allout-stringify-flat-index-indented (flat-index)
5372 "Convert list representing section/subsection/... to document string."
5376 ;; Take care of the explicit context:
5377 (setq numstr
(int-to-string (car flat-index
))
5378 flat-index
(cdr flat-index
)
5379 result
(if flat-index
5380 (cons delim
(cons numstr result
))
5381 (cons numstr result
)))
5383 ;; Take care of the indentation:
5390 (1+ (truncate (if (zerop (car flat-index
))
5392 (log10 (car flat-index
)))))
5395 (setq flat-index
(cdr flat-index
)))
5396 ;; Dispose of single extra delim:
5397 (setq result
(cdr result
))))
5398 (apply 'concat result
)))
5399 ;;;_ > allout-listify-exposed (&optional start end format)
5400 (defun allout-listify-exposed (&optional start end format
)
5402 "Produce a list representing exposed topics in current region.
5404 This list can then be used by `allout-process-exposed' to manipulate
5407 Optional START and END indicate bounds of region.
5409 Optional arg, FORMAT, designates an alternate presentation form for
5412 list -- Present prefix as numeric section.subsection..., starting with
5413 section indicated by the list, innermost nesting first.
5414 `indent' (symbol) -- Convert header prefixes to all white space,
5415 except for distinctive bullets.
5417 The elements of the list produced are lists that represents a topic
5418 header and body. The elements of that list are:
5420 - a number representing the depth of the topic,
5421 - a string representing the header-prefix, including trailing whitespace and
5423 - a string representing the bullet character,
5424 - and a series of strings, each containing one line of the exposed
5425 portion of the topic entry."
5430 ((inhibit-field-text-motion t
)
5432 strings prefix result depth new-depth out gone-out bullet beg
5437 ;; Goto initial topic, and register preceding stuff, if any:
5438 (if (> (allout-goto-prefix-doublechecked) start
)
5439 ;; First topic follows beginning point -- register preliminary stuff:
5441 (list (list 0 "" nil
5442 (buffer-substring-no-properties start
5444 (while (and (not done
)
5445 (not (eobp)) ; Loop until we've covered the region.
5446 (not (> (point) end
)))
5447 (setq depth allout-recent-depth
; Current topics depth,
5448 bullet
(allout-recent-bullet) ; ... bullet,
5449 prefix
(allout-recent-prefix)
5450 beg
(progn (allout-end-of-prefix t
) (point))) ; and beginning.
5451 (setq done
; The boundary for the current topic:
5452 (not (allout-next-visible-heading 1)))
5453 (setq new-depth allout-recent-depth
)
5455 out
(< new-depth depth
))
5460 (while (> next
(point)) ; Get all the exposed text in
5462 (cons (buffer-substring-no-properties
5464 ;To hidden text or end of line:
5467 (allout-back-to-visible-text)))
5469 (when (< (point) next
) ; Resume from after hid text, if any.
5471 (beginning-of-line))
5473 ;; Accumulate list for this topic:
5474 (setq strings
(nreverse strings
))
5478 (let ((special (if (string-match
5479 (regexp-quote bullet
)
5480 allout-distinctive-bullets-string
)
5482 (cond ((listp format
)
5484 (if allout-flattened-numbering-abbreviation
5485 (allout-stringify-flat-index format
5487 (allout-stringify-flat-index-plain
5491 ((eq format
'indent
)
5494 (concat (make-string (1+ depth
) ?
)
5495 (substring prefix -
1))
5498 (make-string depth ?
)
5500 (t (error "allout-listify-exposed: %s %s"
5501 "invalid format" format
))))
5502 (list depth prefix strings
))
5504 ;; Reassess format, if any:
5505 (if (and format
(listp format
))
5506 (cond ((= new-depth depth
)
5507 (setq format
(cons (1+ (car format
))
5509 ((> new-depth depth
) ; descending -- assume by 1:
5510 (setq format
(cons 1 format
)))
5513 (while (< new-depth depth
)
5514 (setq format
(cdr format
))
5515 (setq depth
(1- depth
)))
5516 ; And increment the current one:
5518 (cons (1+ (or (car format
)
5521 ;; Put the list with first at front, to last at back:
5522 (nreverse result
))))
5523 ;;;_ > allout-region-active-p ()
5524 (defmacro allout-region-active-p
()
5525 (cond ((fboundp 'use-region-p
) '(use-region-p))
5526 ((fboundp 'region-active-p
) '(region-active-p))
5528 ;;_ > allout-process-exposed (&optional func from to frombuf
5530 (defun allout-process-exposed (&optional func from to frombuf tobuf
5532 "Map function on exposed parts of current topic; results to another buffer.
5534 All args are options; default values itemized below.
5536 Apply FUNCTION to exposed portions FROM position TO position in buffer
5537 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5538 alternate presentation form:
5540 `flat' -- Present prefix as numeric section.subsection..., starting with
5541 section indicated by the START-NUM, innermost nesting first.
5542 X`flat-indented' -- Prefix is like `flat' for first topic at each
5543 X level, but subsequent topics have only leaf topic
5544 X number, padded with blanks to line up with first.
5545 `indent' (symbol) -- Convert header prefixes to all white space,
5546 except for distinctive bullets.
5549 FUNCTION: `allout-insert-listified'
5550 FROM: region start, if region active, else start of buffer
5551 TO: region end, if region active, else end of buffer
5552 FROMBUF: current buffer
5553 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5556 ; Resolve arguments,
5557 ; defaulting if necessary:
5558 (if (not func
) (setq func
'allout-insert-listified
))
5559 (if (not (and from to
))
5560 (if (allout-region-active-p)
5561 (setq from
(region-beginning) to
(region-end))
5562 (setq from
(point-min) to
(point-max))))
5564 (if (not (bufferp frombuf
))
5565 ;; Specified but not a buffer -- get it:
5566 (let ((got (get-buffer frombuf
)))
5568 (error (concat "allout-process-exposed: source buffer "
5571 (setq frombuf got
))))
5572 ;; not specified -- default it:
5573 (setq frombuf
(current-buffer)))
5575 (if (not (bufferp tobuf
))
5576 (setq tobuf
(get-buffer-create tobuf
)))
5577 ;; not specified -- default it:
5578 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
5583 (progn (set-buffer frombuf
)
5584 (allout-listify-exposed from to format
))))
5586 (mapc func listified
)
5587 (pop-to-buffer tobuf
)))
5590 ;;;_ > allout-insert-listified (listified)
5591 (defun allout-insert-listified (listified)
5592 "Insert contents of listified outline portion in current buffer.
5594 LISTIFIED is a list representing each topic header and body:
5596 \`(depth prefix text)'
5598 or \`(depth prefix text bullet-plus)'
5600 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5601 (setq listified
(cdr listified
))
5602 (let ((prefix (prog1
5604 (setq listified
(cdr listified
))))
5607 (setq listified
(cdr listified
))))
5608 (bullet-plus (car listified
)))
5610 (if bullet-plus
(insert (concat " " bullet-plus
)))
5613 (if (setq text
(cdr text
))
5616 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5617 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format
)
5618 "Duplicate exposed portions of current outline to another buffer.
5620 Other buffer has current buffers name with \" exposed\" appended to it.
5622 With repeat count, copy the exposed parts of only the current topic.
5624 Optional second arg TOBUF is target buffer name.
5626 Optional third arg FORMAT, if non-nil, symbolically designates an
5627 alternate presentation format for the outline:
5629 `flat' - Convert topic header prefixes to numeric
5630 section.subsection... identifiers.
5631 `indent' - Convert header prefixes to all white space, except for
5632 distinctive bullets.
5633 `indent-flat' - The best of both - only the first of each level has
5634 the full path, the rest have only the section number
5635 of the leaf, preceded by the right amount of indentation."
5639 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5640 (let* ((start-pt (point))
5641 (beg (if arg
(allout-back-to-current-heading) (point-min)))
5642 (end (if arg
(allout-end-of-current-subtree) (point-max)))
5643 (buf (current-buffer))
5645 (if (eq format
'flat
)
5646 (setq format
(if arg
(save-excursion
5648 (allout-topic-flat-index))
5650 (with-current-buffer tobuf
(erase-buffer))
5651 (allout-process-exposed 'allout-insert-listified
5657 (goto-char (point-min))
5659 (goto-char start-pt
)))
5660 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5661 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf
)
5662 "Present numeric outline of outline's exposed portions in another buffer.
5664 The resulting outline is not compatible with outline mode -- use
5665 `allout-copy-exposed-to-buffer' if you want that.
5667 Use `allout-indented-exposed-to-buffer' for indented presentation.
5669 With repeat count, copy the exposed portions of only current topic.
5671 Other buffer has current buffer's name with \" exposed\" appended to
5672 it, unless optional second arg TOBUF is specified, in which case it is
5675 (allout-copy-exposed-to-buffer arg tobuf
'flat
))
5676 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5677 (defun allout-indented-exposed-to-buffer (&optional arg tobuf
)
5678 "Present indented outline of outline's exposed portions in another buffer.
5680 The resulting outline is not compatible with outline mode -- use
5681 `allout-copy-exposed-to-buffer' if you want that.
5683 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5685 With repeat count, copy the exposed portions of only current topic.
5687 Other buffer has current buffer's name with \" exposed\" appended to
5688 it, unless optional second arg TOBUF is specified, in which case it is
5691 (allout-copy-exposed-to-buffer arg tobuf
'indent
))
5693 ;;;_ - LaTeX formatting
5694 ;;;_ > allout-latex-verb-quote (string &optional flow)
5695 (defun allout-latex-verb-quote (string &optional flow
)
5696 "Return copy of STRING for literal reproduction across LaTeX processing.
5697 Expresses the original characters (including carriage returns) of the
5698 string across LaTeX processing."
5699 (mapconcat (function
5701 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
5702 (concat "\\char" (number-to-string char
) "{}"))
5703 ((= char ?
\n) "\\\\")
5704 (t (char-to-string char
)))))
5707 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5708 (defun allout-latex-verbatim-quote-curr-line ()
5709 "Express line for exact (literal) representation across LaTeX processing.
5711 Adjust line contents so it is unaltered (from the original line)
5712 across LaTeX processing, within the context of a `verbatim'
5713 environment. Leaves point at the end of the line."
5714 (let ((inhibit-field-text-motion t
))
5717 (end (point-at-eol)))
5719 (while (re-search-forward "\\\\"
5720 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5721 end
; bounded by end-of-line
5722 1) ; no matches, move to end & return nil
5723 (goto-char (match-beginning 2))
5726 (goto-char (1+ (match-end 2))))))))
5727 ;;;_ > allout-insert-latex-header (buffer)
5728 (defun allout-insert-latex-header (buffer)
5729 "Insert initial LaTeX commands at point in BUFFER."
5730 ;; Much of this is being derived from the stuff in appendix of E in
5731 ;; the TeXBook, pg 421.
5733 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5735 (page-numbering (if allout-number-pages
5736 "\\pagestyle{empty}\n"
5738 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5739 allout-title-style
))
5740 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5741 allout-label-style
))
5742 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5743 allout-head-line-style
))
5744 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5745 allout-body-line-style
))
5746 (setlength (format "%s%s%s%s"
5747 "\\newlength{\\stepsize}\n"
5748 "\\setlength{\\stepsize}{"
5751 (oneheadline (format "%s%s%s%s%s%s%s"
5752 "\\newcommand{\\OneHeadLine}[3]{%\n"
5754 "\\hspace*{#2\\stepsize}%\n"
5755 "\\labelcmd{#1}\\hspace*{.2cm}"
5756 "\\headlinecmd{#3}\\\\["
5759 (onebodyline (format "%s%s%s%s%s%s"
5760 "\\newcommand{\\OneBodyLine}[2]{%\n"
5762 "\\hspace*{#1\\stepsize}%\n"
5763 "\\bodylinecmd{#2}\\\\["
5766 (begindoc "\\begin{document}\n\\begin{center}\n")
5767 (title (format "%s%s%s%s"
5769 (allout-latex-verb-quote (if allout-title
5772 (error "<unnamed buffer>"))
5775 "\\end{center}\n\n"))
5776 (hsize "\\hsize = 7.5 true in\n")
5777 (hoffset "\\hoffset = -1.5 true in\n")
5778 (vspace "\\vspace{.1cm}\n\n"))
5779 (insert (concat doc-style
5794 ;;;_ > allout-insert-latex-trailer (buffer)
5795 (defun allout-insert-latex-trailer (buffer)
5796 "Insert concluding LaTeX commands at point in BUFFER."
5798 (insert "\n\\end{document}\n"))
5799 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5800 (defun allout-latexify-one-item (depth prefix bullet text
)
5801 "Insert LaTeX commands for formatting one outline item.
5803 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5804 BULLET string, and a list of TEXT strings for the body."
5805 (let* ((head-line (if text
(car text
)))
5806 (body-lines (cdr text
))
5810 (insert (concat "\\OneHeadLine{\\verb\1 "
5811 (allout-latex-verb-quote bullet
)
5816 (allout-latex-verb-quote head-line
)
5819 (if (not body-lines
)
5821 ;;(insert "\\beginlines\n")
5822 (insert "\\begin{verbatim}\n")
5824 (setq curr-line
(car body-lines
))
5825 (if (and (not body-content
)
5826 (not (string-match "^\\s-*$" curr-line
)))
5827 (setq body-content t
))
5828 ; Mangle any occurrences of
5829 ; "\end{verbatim}" in text,
5831 (if (and body-content
5832 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
5833 (setq curr-line
(concat (substring curr-line
0 bop
)
5835 (substring curr-line bop
))))
5836 ;;(insert "|" (car body-lines) "|")
5838 (allout-latex-verbatim-quote-curr-line)
5840 (setq body-lines
(cdr body-lines
)))
5842 (setq body-content nil
)
5846 ;;(insert "\\endlines\n")
5847 (insert "\\end{verbatim}\n")
5849 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5850 (defun allout-latexify-exposed (arg &optional tobuf
)
5851 "Format current topics exposed portions to TOBUF for LaTeX processing.
5852 TOBUF defaults to a buffer named the same as the current buffer, but
5853 with \"*\" prepended and \" latex-formed*\" appended.
5855 With repeat count, copy the exposed portions of entire buffer."
5860 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5861 (let* ((start-pt (point))
5862 (beg (if arg
(point-min) (allout-back-to-current-heading)))
5863 (end (if arg
(point-max) (allout-end-of-current-subtree)))
5864 (buf (current-buffer)))
5867 (allout-insert-latex-header tobuf
)
5868 (goto-char (point-max))
5869 (allout-process-exposed 'allout-latexify-one-item
5874 (goto-char (point-max))
5875 (allout-insert-latex-trailer tobuf
)
5876 (goto-char (point-min))
5878 (goto-char start-pt
)))
5881 ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue)
5882 (defun allout-toggle-current-subtree-encryption (&optional keymode-cue
)
5883 "Encrypt clear or decrypt encoded topic text.
5885 Allout uses Emacs 'epg' library to perform encryption. Symmetric
5886 and keypair encryption are supported. All encryption is ascii
5889 Entry encryption defaults to symmetric key mode unless keypair
5890 recipients are associated with the file (see
5891 `epa-file-encrypt-to') or the function is invoked with a
5892 \(KEYMODE-CUE) universal argument greater than 1.
5894 When encrypting, KEYMODE-CUE universal argument greater than 1
5895 causes prompting for recipients for public-key keypair
5896 encryption. Selecting no recipients results in symmetric key
5899 Further, encrypting with a KEYMODE-CUE universal argument greater
5900 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5901 the specified recipients with the file, replacing those currently
5902 associated with it. This can be used to dissociate any
5903 recipients with the file, by selecting no recipients in the
5906 Encrypted topic's bullets are set to a `~' to signal that the
5907 contents of the topic (body and subtopics, but not heading) is
5908 pending encryption or encrypted. `*' asterisk immediately after
5909 the bullet signals that the body is encrypted, its absence means
5910 the topic is meant to be encrypted but is not currently. When a
5911 file with topics pending encryption is saved, topics pending
5912 encryption are encrypted. See `allout-encrypt-unencrypted-on-saves'
5913 for auto-encryption specifics.
5915 \*NOTE WELL* that automatic encryption that happens during saves will
5916 default to symmetric encryption -- you must deliberately (re)encrypt key-pair
5917 encrypted topics if you want them to continue to use the key-pair cipher.
5919 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5920 encrypted. If you want to encrypt the contents of a top-level topic, use
5921 \\[allout-shift-in] to increase its depth."
5924 (allout-back-to-current-heading)
5925 (allout-toggle-subtree-encryption keymode-cue
)))
5926 ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue)
5927 (defun allout-toggle-subtree-encryption (&optional keymode-cue
)
5928 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5930 Entry encryption defaults to symmetric key mode unless keypair
5931 recipients are associated with the file (see
5932 `epa-file-encrypt-to') or the function is invoked with a
5933 \(KEYMODE-CUE) universal argument greater than 1.
5935 When encrypting, KEYMODE-CUE universal argument greater than 1
5936 causes prompting for recipients for public-key keypair
5937 encryption. Selecting no recipients results in symmetric key
5940 Further, encrypting with a KEYMODE-CUE universal argument greater
5941 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5942 the specified recipients with the file, replacing those currently
5943 associated with it. This can be used to dissociate any
5944 recipients with the file, by selecting no recipients in the
5947 Encryption and decryption uses the Emacs 'epg' library.
5949 Encrypted text will be ascii-armored.
5951 See `allout-toggle-current-subtree-encryption' for more details."
5955 (allout-end-of-prefix t
)
5957 (if (= allout-recent-depth
1)
5958 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5959 " shift it in to make it encryptable")))
5961 (let* ((allout-buffer (current-buffer))
5962 ;; for use with allout-auto-save-temporarily-disabled, if necessary:
5963 (was-buffer-saved-size buffer-saved-size
)
5965 (bullet-pos allout-recent-prefix-beginning
)
5966 (after-bullet-pos (point))
5968 (progn (if (= (point-max) after-bullet-pos
)
5969 (error "no body to encrypt"))
5970 (allout-encrypted-topic-p)))
5971 (was-collapsed (if (not (search-forward "\n" nil t
))
5975 (subtree-beg (1+ (point)))
5976 (subtree-end (allout-end-of-subtree))
5977 (subject-text (buffer-substring-no-properties subtree-beg
5979 (subtree-end-char (char-after (1- subtree-end
)))
5980 (subtree-trailing-char (char-after subtree-end
))
5981 ;; kluge -- result-text needs to be nil, but we also want to
5982 ;; check for the error condition
5983 (result-text (if (or (string= "" subject-text
)
5984 (string= "\n" subject-text
))
5985 (error "No topic contents to %scrypt"
5986 (if was-encrypted
"de" "en"))
5988 ;; Assess key parameters:
5989 (was-coding-system buffer-file-coding-system
))
5991 (when (not was-encrypted
)
5992 ;; ensure that non-ascii chars pending encryption are noticed before
5993 ;; they're encrypted, so the coding system is set to accommodate
5995 (setq buffer-file-coding-system
5996 (allout-select-safe-coding-system subtree-beg subtree-end
))
5997 ;; if the coding system for the text being encrypted is different
5998 ;; than that prevailing, then there a real risk that the coding
5999 ;; system can't be noticed by emacs when the file is visited. to
6000 ;; mitigate that, offer to preserve the coding system using a file
6002 (if (and (not (equal buffer-file-coding-system
6005 (format (concat "Register coding system %s as file local"
6006 " var? Necessary when only encrypted text"
6007 " is in that coding system. ")
6008 buffer-file-coding-system
)))
6009 (allout-adjust-file-variable "buffer-file-coding-system"
6010 buffer-file-coding-system
)))
6013 (allout-encrypt-string subject-text was-encrypted
6014 (current-buffer) keymode-cue
))
6016 ;; Replace the subtree with the processed product.
6019 (set-buffer allout-buffer
)
6020 (delete-region subtree-beg subtree-end
)
6021 (insert result-text
)
6023 (allout-flag-region (1- subtree-beg
) (point) t
))
6024 ;; adjust trailing-blank-lines to preserve topic spacing:
6025 (if (not was-encrypted
)
6026 (if (and (= subtree-end-char ?
\n)
6027 (= subtree-trailing-char ?
\n))
6028 (insert subtree-trailing-char
)))
6029 ;; Ensure that the item has an encrypted-entry bullet:
6030 (if (not (string= (buffer-substring-no-properties
6031 (1- after-bullet-pos
) after-bullet-pos
)
6032 allout-topic-encryption-bullet
))
6033 (progn (goto-char (1- after-bullet-pos
))
6035 (insert allout-topic-encryption-bullet
)))
6037 ;; Remove the is-encrypted bullet qualifier:
6038 (progn (goto-char after-bullet-pos
)
6040 ;; Add the is-encrypted bullet qualifier:
6041 (goto-char after-bullet-pos
)
6044 ;; adjust buffer's auto-save eligibility:
6046 (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size
)
6047 (allout-maybe-resume-auto-save-info-after-encryption))
6049 (run-hook-with-args 'allout-structure-added-functions
6050 bullet-pos subtree-end
))))
6051 ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
6052 ;;; &optional rejected)
6053 (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue
6055 "Encrypt or decrypt message TEXT.
6057 Returns the resulting string, or nil if the transformation fails.
6059 If DECRYPT is true (default false), then decrypt instead of encrypt.
6061 ALLOUT-BUFFER identifies the buffer containing the text.
6063 Entry encryption defaults to symmetric key mode unless keypair
6064 recipients are associated with the file (see
6065 `epa-file-encrypt-to') or the function is invoked with a
6066 \(KEYMODE-CUE) universal argument greater than 1.
6068 When encrypting, KEYMODE-CUE universal argument greater than 1
6069 causes prompting for recipients for public-key keypair
6070 encryption. Selecting no recipients results in symmetric key
6073 Further, encrypting with a KEYMODE-CUE universal argument greater
6074 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
6075 the specified recipients with the file, replacing those currently
6076 associated with it. This can be used to dissociate any
6077 recipients with the file, by selecting no recipients in the
6080 Optional REJECTED is for internal use, to convey the number of
6081 rejections due to matches against
6082 `allout-encryption-ciphertext-rejection-regexps', as limited by
6083 `allout-encryption-ciphertext-rejection-ceiling'.
6085 NOTE: A few GnuPG v2 versions improperly preserve incorrect
6086 symmetric decryption keys, preventing entry of the correct key on
6087 subsequent decryption attempts until the cache times-out. That
6088 can take several minutes. (Decryption of other entries is not
6089 affected.) Upgrade your EasyPG version, if you can, and you can
6090 deliberately clear your gpg-agent's cache by sending it a '-HUP'
6096 (let* ((epg-context (let* ((context (epg-make-context nil t
)))
6097 (epg-context-set-passphrase-callback
6098 context
#'epa-passphrase-callback-function
)
6101 (encoding (with-current-buffer allout-buffer
6102 buffer-file-coding-system
))
6103 (multibyte (with-current-buffer allout-buffer
6104 enable-multibyte-characters
))
6105 ;; "sanitization" avoids encryption results that are outline structure.
6106 (sani-regexps 'allout-encryption-plaintext-sanitization-regexps
)
6107 (strip-plaintext-regexps (if (not decrypt
)
6108 (allout-get-configvar-values
6110 (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps
)
6111 (reject-ciphertext-regexps (if (not decrypt
)
6112 (allout-get-configvar-values
6113 rejection-regexps
)))
6114 (rejected (or rejected
0))
6115 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6117 (keypair-mode (cond (decrypt 'decrypting
)
6118 ((<= (prefix-numeric-value keymode-cue
) 1)
6120 ((<= (prefix-numeric-value keymode-cue
) 4)
6122 ((> (prefix-numeric-value keymode-cue
) 4)
6124 (keypair-message (concat "Select encryption recipients.\n"
6125 "Symmetric encryption is done if no"
6126 " recipients are selected. "))
6127 (encrypt-to (and (boundp 'epa-file-encrypt-to
) epa-file-encrypt-to
))
6133 ;; Massage the subject text for encoding and filtering.
6136 ;; convey the text characteristics of the original buffer:
6137 (set-buffer-multibyte multibyte
)
6139 (set-buffer-file-coding-system encoding
)
6141 (encode-coding-region (point-min) (point-max) encoding
)))
6143 ;; remove sanitization regexps matches before encrypting:
6144 (when (and strip-plaintext-regexps
(not decrypt
))
6145 (dolist (re strip-plaintext-regexps
)
6146 (let ((re (if (listp re
) (car re
) re
))
6147 (replacement (if (listp re
) (cadr re
) "")))
6148 (goto-char (point-min))
6150 (while (re-search-forward re nil t
)
6151 (replace-match replacement nil nil
))))))
6152 (setq massaged-text
(buffer-substring-no-properties (point-min)
6154 ;; determine key mode and, if keypair, recipients:
6160 (default (if encrypt-to
(epg-list-keys epg-context encrypt-to
)))
6162 ((prompt prompt-save
)
6163 (save-window-excursion
6164 (epa-select-keys epg-context keypair-message
)))))
6169 (epg-decrypt-string epg-context
6170 (encode-coding-string massaged-text
6171 (or encoding
'utf-8
)))
6174 (cons (concat (cadr err
) " - gpg version problem?")
6176 (replace-regexp-in-string "\n$" ""
6177 (epg-encrypt-string epg-context
6178 (encode-coding-string massaged-text
6179 (or encoding
'utf-8
))
6182 ;; validate result -- non-empty
6183 (if (not result-text
)
6184 (error "%scryption failed." (if decrypt
"De" "En")))
6187 (when (eq keypair-mode
'prompt-save
)
6188 ;; set epa-file-encrypt-to in the buffer:
6189 (setq epa-file-encrypt-to
(mapcar (lambda (key)
6191 (car (epg-key-user-id-list key
))))
6193 ;; change the file variable:
6194 (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to
))
6197 ;; Retry (within limit) if ciphertext contains rejections:
6199 ;; Check for disqualification of this ciphertext:
6200 (let ((regexps reject-ciphertext-regexps
)
6202 (while (and regexps
(not reject-it
))
6203 (setq reject-it
(string-match (car regexps
) result-text
))
6206 (setq rejections-left
(1- rejections-left
))
6207 (if (<= rejections-left
0)
6208 (error (concat "Ciphertext rejected too many times"
6210 allout-encryption-ciphertext-rejection-ceiling
6211 'allout-encryption-ciphertext-rejection-regexps
)
6212 ;; try again (gpg-agent may have the key cached):
6213 (allout-encrypt-string text decrypt allout-buffer keypair-mode
6216 ;; Barf if encryption yields extraordinary control chars:
6218 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6220 (error (concat "Encryption produced non-armored text, which"
6221 "conflicts with allout mode -- reconfigure!")))
6223 ;;;_ > allout-inhibit-auto-save-info-for-decryption
6224 (defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size)
6225 "Temporarily prevent auto-saves in this buffer when an item is decrypted.
6227 WAS-BUFFER-SAVED-SIZE is the value of `buffer-saved-size' *before*
6229 (when (not (or (= buffer-saved-size -
1) (= was-buffer-saved-size -
1)))
6230 (setq allout-auto-save-temporarily-disabled was-buffer-saved-size
6231 buffer-saved-size -
1)))
6232 ;;;_ > allout-maybe-resume-auto-save-info-after-encryption ()
6233 (defun allout-maybe-resume-auto-save-info-after-encryption ()
6234 "Restore auto-save info, *if* there are no topics pending encryption."
6235 (when (and allout-auto-save-temporarily-disabled
6236 (= buffer-saved-size -
1)
6240 (goto-char (point-min))
6241 (not (allout-next-topic-pending-encryption)))))
6242 (setq buffer-saved-size allout-auto-save-temporarily-disabled
6243 allout-auto-save-temporarily-disabled nil
)))
6245 ;;;_ > allout-encrypted-topic-p ()
6246 (defun allout-encrypted-topic-p ()
6247 "True if the current topic is encryptable and encrypted."
6249 (allout-end-of-prefix t
)
6250 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6251 allout-topic-encryption-bullet
)
6252 (save-match-data (looking-at "\\*")))
6255 ;;;_ > allout-next-topic-pending-encryption ()
6256 (defun allout-next-topic-pending-encryption ()
6257 "Return the point of the next topic pending encryption, or nil if none.
6259 Such a topic has the `allout-topic-encryption-bullet' without an
6260 immediately following '*' that would mark the topic as being encrypted.
6261 It must also have content."
6262 (let (done got content-beg
)
6266 (if (not (re-search-forward
6267 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6268 (regexp-quote allout-header-prefix
)
6269 (regexp-quote allout-topic-encryption-bullet
))
6273 (goto-char (setq got
(match-beginning 0)))
6274 (if (save-match-data (looking-at "\n"))
6281 ((not (search-forward "\n"))
6290 (setq content-beg
(point))
6292 (allout-end-of-subtree)
6293 (if (<= (point) content-beg
)
6305 ;;;_ > allout-encrypt-decrypted ()
6306 (defun allout-encrypt-decrypted ()
6307 "Encrypt topics pending encryption except those containing exemption point.
6309 If a topic that is currently being edited was encrypted, we return a list
6310 containing the location of the topic and the location of the cursor just
6311 before the topic was encrypted. This can be used, eg, to decrypt the topic
6312 and exactly resituate the cursor if this is being done as part of a file
6313 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6318 (let* ((current-mark (point-marker))
6319 (current-mark-position (marker-position current-mark
))
6322 editing-topic editing-point
)
6323 (goto-char (point-min))
6324 (while (allout-next-topic-pending-encryption)
6325 (setq was-modified
(buffer-modified-p))
6326 (when (save-excursion
6327 (and (boundp 'allout-encrypt-unencrypted-on-saves
)
6328 allout-encrypt-unencrypted-on-saves
6329 (setq bo-subtree
(re-search-forward "$"))
6330 (not (allout-hidden-p))
6331 (>= current-mark
(point))
6332 (allout-end-of-current-subtree)
6333 (<= current-mark
(point))))
6334 (setq editing-topic
(point)
6335 ;; we had to wait for this 'til now so prior topics are
6336 ;; encrypted, any relevant text shifts are in place:
6337 editing-point
(- current-mark-position
6338 (count-trailing-whitespace-region
6339 bo-subtree current-mark-position
))))
6340 (allout-toggle-subtree-encryption)
6341 (if (not was-modified
)
6342 (set-buffer-modified-p nil
))
6344 (if (not was-modified
)
6345 (set-buffer-modified-p nil
))
6346 (if editing-topic
(list editing-topic editing-point
))
6352 ;;;_ #9 miscellaneous
6354 ;;;_ > outlineify-sticky ()
6355 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6357 (defalias 'outlinify-sticky
'outlineify-sticky
)
6359 (defun outlineify-sticky (&optional arg
)
6360 "Activate outline mode and establish file var so it is started subsequently.
6362 See `allout-layout' and customization of `allout-auto-activation'
6363 for details on preparing Emacs for automatic allout activation."
6367 (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
6371 (goto-char (point-min))
6372 (if (allout-goto-prefix)
6374 (allout-open-topic 2)
6375 (insert (concat "Dummy outline topic header -- see"
6376 "`allout-mode' docstring: `^Hm'."))
6377 (allout-adjust-file-variable
6378 "allout-layout" (or allout-layout
'(-1 : 0))))))
6379 ;;;_ > allout-file-vars-section-data ()
6380 (defun allout-file-vars-section-data ()
6381 "Return data identifying the file-vars section, or nil if none.
6383 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6384 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6385 (let (beg prefix suffix
)
6387 (goto-char (point-max))
6388 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move
)
6389 (if (let ((case-fold-search t
))
6390 (not (search-forward "Local Variables:" nil t
)))
6392 (setq beg
(- (point) 16))
6393 (setq suffix
(buffer-substring-no-properties
6395 (progn (if (search-forward "\n" nil t
)
6398 (setq prefix
(buffer-substring-no-properties
6399 (progn (if (search-backward "\n" nil t
)
6403 (list beg prefix suffix
))
6407 ;;;_ > allout-adjust-file-variable (varname value)
6408 (defun allout-adjust-file-variable (varname value
)
6409 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6411 This activity is inhibited if either `enable-local-variables' or
6412 `allout-enable-file-variable-adjustment' are nil.
6414 When enabled, an entry for the variable is created if not already present,
6415 or changed if established with a different value. The section for the file
6416 variables, itself, is created if not already present. When created, the
6417 section lines (including the section line) exist as second-level topics in
6418 a top-level topic at the end of the file.
6420 `enable-local-variables' must be true for any of this to happen."
6421 (if (not (and enable-local-variables
6422 allout-enable-file-variable-adjustment
))
6425 (let ((inhibit-field-text-motion t
)
6426 (section-data (allout-file-vars-section-data))
6429 (setq beg
(car section-data
)
6430 prefix
(cadr section-data
)
6431 suffix
(car (cddr section-data
)))
6432 ;; create the section
6433 (goto-char (point-max))
6435 (allout-open-topic 0)
6437 (insert "Local emacs vars.\n")
6438 (allout-open-topic 1)
6441 prefix
(buffer-substring-no-properties (progn
6446 (insert "Local variables:\n")
6447 (allout-open-topic 0)
6450 ;; look for existing entry or create one, leaving point for insertion
6453 (allout-show-to-offshoot)
6454 (if (search-forward (concat "\n" prefix varname
":") nil t
)
6455 (let* ((value-beg (point))
6456 (line-end (progn (if (search-forward "\n" nil t
)
6459 (value-end (- line-end
(length suffix
))))
6460 (if (> value-end value-beg
)
6461 (delete-region value-beg value-end
)))
6465 (insert (concat prefix varname
":")))
6466 (insert (format " %S%s" value suffix
))
6471 ;;;_ > allout-get-configvar-values (varname)
6472 (defun allout-get-configvar-values (configvar-name)
6473 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6475 The user is prompted for removal of symbols that are unbound, and they
6476 otherwise are ignored.
6478 CONFIGVAR-NAME should be the name of the configuration variable,
6481 (let ((configvar-value (symbol-value configvar-name
))
6483 (dolist (sym configvar-value
)
6484 (if (not (boundp sym
))
6485 (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? "
6486 configvar-name sym
))
6487 (delq sym
(symbol-value configvar-name
)))
6488 (push (symbol-value sym
) got
)))
6491 ;;;_ > allout-mark-topic ()
6492 (defun allout-mark-topic ()
6493 "Put the region around topic currently containing point."
6495 (let ((inhibit-field-text-motion t
))
6496 (beginning-of-line))
6497 (allout-goto-prefix-doublechecked)
6499 (allout-end-of-current-subtree)
6500 (exchange-point-and-mark))
6502 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6503 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
6504 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6506 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6508 (let ((new-prompt prompt
)
6512 (message "%s" new-prompt
)
6514 ;; We do our own reading here, so we can circumvent, eg, special
6515 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6517 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
6520 (cond ((string-match (regexp-quote got
) string
) got
)
6521 ((and do-defaulting
(string= got
"\r"))
6522 ;; Return empty string to default:
6524 ((string= got
"\C-g") (signal 'quit nil
))
6526 (setq new-prompt
(concat prompt
6532 ;; got something out of loop -- return it:
6536 ;;;_ > regexp-sans-escapes (string)
6537 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
6538 "Return a copy of REGEXP with all character escapes stripped out.
6540 Representations of actual backslashes -- '\\\\\\\\' -- are left as a
6543 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6545 (if (string= regexp
"")
6547 ;; Set successive-backslashes to number if current char is
6548 ;; backslash, or else to nil:
6549 (setq successive-backslashes
6550 (if (= (aref regexp
0) ?
\\)
6551 (if successive-backslashes
(1+ successive-backslashes
) 1)
6553 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
6554 ;; Include first char:
6555 (concat (substring regexp
0 1)
6556 (regexp-sans-escapes (substring regexp
1)))
6557 ;; Exclude first char, but maintain count:
6558 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
6559 ;;;_ > count-trailing-whitespace-region (beg end)
6560 (defun count-trailing-whitespace-region (beg end
)
6561 "Return number of trailing whitespace chars between BEG and END.
6563 If BEG is bigger than END we return 0."
6570 (while (re-search-forward "[ ][ ]*$" end t
)
6571 (goto-char (1+ (match-beginning 2)))
6572 (setq count
(1+ count
)))
6574 ;;;_ > allout-format-quote (string)
6575 (defun allout-format-quote (string)
6576 "Return a copy of string with all \"%\" characters doubled."
6578 (mapcar (lambda (char) (if (= char ?%
) "%%" (char-to-string char
)))
6581 ;;;_ > allout-flatten (list)
6582 (defun allout-flatten (list)
6583 "Return a list of all atoms in list."
6585 (cond ((null list
) nil
)
6586 ((atom (car list
)) (cons (car list
) (allout-flatten (cdr list
))))
6587 (t (append (allout-flatten (car list
)) (allout-flatten (cdr list
))))))
6588 ;;;_ : Compatibility:
6589 ;;;_ : xemacs undo-in-progress provision:
6590 (unless (boundp 'undo-in-progress
)
6591 (defvar undo-in-progress nil
6592 "Placeholder defvar for XEmacs compatibility from allout.el.")
6593 (defadvice undo-more
(around allout activate
)
6594 ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
6595 (let ((undo-in-progress t
)) ad-do-it
)))
6597 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6598 (defun allout-mark-marker (&optional force buffer
)
6599 "Accommodate the different signature for `mark-marker' across Emacsen.
6601 XEmacs takes two optional args, while Emacs does not,
6602 so pass them along when appropriate."
6603 (if (featurep 'xemacs
)
6604 (apply 'mark-marker force buffer
)
6606 ;;;_ > subst-char-in-string if necessary
6607 (if (not (fboundp 'subst-char-in-string
))
6608 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
6609 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6610 Unless optional argument INPLACE is non-nil, return a new string."
6611 (let ((i (length string
))
6612 (newstr (if inplace string
(copy-sequence string
))))
6615 (if (eq (aref newstr i
) fromchar
)
6616 (aset newstr i tochar
)))
6618 ;;;_ > wholenump if necessary
6619 (if (not (fboundp 'wholenump
))
6620 (defalias 'wholenump
'natnump
))
6621 ;;;_ > remove-overlays if necessary
6622 (if (not (fboundp 'remove-overlays
))
6623 (defun remove-overlays (&optional beg end name val
)
6624 "Clear BEG and END of overlays whose property NAME has value VAL.
6625 Overlays might be moved and/or split.
6626 BEG and END default respectively to the beginning and end of buffer."
6627 (unless beg
(setq beg
(point-min)))
6628 (unless end
(setq end
(point-max)))
6630 (setq beg
(prog1 end
(setq end beg
))))
6632 (dolist (o (overlays-in beg end
))
6633 (when (eq (overlay-get o name
) val
)
6634 ;; Either push this overlay outside beg...end
6635 ;; or split it to exclude beg...end
6636 ;; or delete it entirely (if it is contained in beg...end).
6637 (if (< (overlay-start o
) beg
)
6638 (if (> (overlay-end o
) end
)
6640 (move-overlay (copy-overlay o
)
6641 (overlay-start o
) beg
)
6642 (move-overlay o end
(overlay-end o
)))
6643 (move-overlay o
(overlay-start o
) beg
))
6644 (if (> (overlay-end o
) end
)
6645 (move-overlay o end
(overlay-end o
))
6646 (delete-overlay o
)))))))
6648 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6649 (if (not (fboundp 'copy-overlay
))
6650 (defun copy-overlay (o)
6651 "Return a copy of overlay O."
6652 (let ((o1 (make-overlay (overlay-start o
) (overlay-end o
)
6653 ;; FIXME: there's no easy way to find the
6654 ;; insertion-type of the two markers.
6655 (overlay-buffer o
)))
6656 (props (overlay-properties o
)))
6658 (overlay-put o1
(pop props
) (pop props
)))
6660 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6661 (if (not (fboundp 'add-to-invisibility-spec
))
6662 (defun add-to-invisibility-spec (element)
6663 "Add ELEMENT to `buffer-invisibility-spec'.
6664 See documentation for `buffer-invisibility-spec' for the kind of elements
6666 (if (eq buffer-invisibility-spec t
)
6667 (setq buffer-invisibility-spec
(list t
)))
6668 (setq buffer-invisibility-spec
6669 (cons element buffer-invisibility-spec
))))
6670 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6671 (if (not (fboundp 'remove-from-invisibility-spec
))
6672 (defun remove-from-invisibility-spec (element)
6673 "Remove ELEMENT from `buffer-invisibility-spec'."
6674 (if (consp buffer-invisibility-spec
)
6675 (setq buffer-invisibility-spec
(delete element
6676 buffer-invisibility-spec
)))))
6677 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6678 (if (not (fboundp 'move-beginning-of-line
))
6679 (defun move-beginning-of-line (arg)
6680 "Move point to beginning of current line as displayed.
6681 \(This disregards invisible newlines such as those
6682 which are part of the text that an image rests on.)
6684 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6685 If point reaches the beginning or end of buffer, it stops there.
6686 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6688 (or arg
(setq arg
1))
6690 (condition-case nil
(line-move (1- arg
)) (error nil
)))
6692 ;; Move to beginning-of-line, ignoring fields and invisible text.
6693 (skip-chars-backward "^\n")
6694 (while (and (not (bobp))
6696 (get-char-property (1- (point)) 'invisible
)))
6697 (if (eq buffer-invisibility-spec t
)
6699 (or (memq prop buffer-invisibility-spec
)
6700 (assq prop buffer-invisibility-spec
)))))
6701 (goto-char (if (featurep 'xemacs
)
6702 (previous-property-change (point))
6703 (previous-char-property-change (point))))
6704 (skip-chars-backward "^\n"))
6705 (vertical-motion 0))
6707 ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
6708 (if (not (fboundp 'move-end-of-line
))
6709 (defun move-end-of-line (arg)
6710 "Move point to end of current line as displayed.
6711 \(This disregards invisible newlines such as those
6712 which are part of the text that an image rests on.)
6714 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6715 If point reaches the beginning or end of buffer, it stops there.
6716 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6718 (or arg
(setq arg
1))
6723 (let ((goal-column 0))
6724 (and (condition-case nil
6725 (or (line-move arg
) t
)
6733 (get-char-property (1- (point))
6735 (if (eq buffer-invisibility-spec t
)
6738 buffer-invisibility-spec
)
6740 buffer-invisibility-spec
)))))
6742 (previous-char-property-change (point))))
6746 (if (and (> (point) newpos
)
6747 (eq (preceding-char) ?
\n))
6749 (if (and (> (point) newpos
) (not (eobp))
6750 (not (eq (following-char) ?
\n)))
6751 ;; If we skipped something intangible
6752 ;; and now we're not really at eol,
6757 ;;;_ > allout-next-single-char-property-change -- alias unless lacking
6758 (defalias 'allout-next-single-char-property-change
6759 (if (fboundp 'next-single-char-property-change
)
6760 'next-single-char-property-change
6761 'next-single-property-change
)
6762 ;; No docstring because xemacs defalias doesn't support it.
6764 ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
6765 (defalias 'allout-previous-single-char-property-change
6766 (if (fboundp 'previous-single-char-property-change
)
6767 'previous-single-char-property-change
6768 'previous-single-property-change
)
6769 ;; No docstring because xemacs defalias doesn't support it.
6771 ;;;_ > allout-select-safe-coding-system
6772 (defalias 'allout-select-safe-coding-system
6773 (if (fboundp 'select-safe-coding-system
)
6774 'select-safe-coding-system
6775 'detect-coding-region
)
6777 ;;;_ > allout-substring-no-properties
6778 ;; define as alias first, so byte compiler is happy.
6779 (defalias 'allout-substring-no-properties
'substring-no-properties
)
6780 ;; then supplant with definition if underlying alias absent.
6781 (if (not (fboundp 'substring-no-properties
))
6782 (defun allout-substring-no-properties (string &optional start end
)
6783 (substring string
(or start
0) end
))
6787 ;;;_ > allout-bullet-isearch (&optional bullet)
6788 (defun allout-bullet-isearch (&optional bullet
)
6789 "Isearch (regexp) for topic with bullet BULLET."
6792 (setq bullet
(solicit-char-in-string
6793 "ISearch for topic with bullet: "
6794 (regexp-sans-escapes allout-bullets-string
))))
6796 (let ((isearch-regexp t
)
6797 (isearch-string (concat "^"
6798 allout-header-prefix
6801 (isearch-repeat 'forward
)
6804 ;;;_ #11 Unit tests -- this should be last item before "Provide"
6805 ;;;_ > allout-run-unit-tests ()
6806 (defun allout-run-unit-tests ()
6807 "Run the various allout unit tests."
6808 (message "Running allout tests...")
6809 (allout-test-resumptions)
6810 (message "Running allout tests... Done.")
6812 ;;;_ : test resumptions:
6813 ;;;_ > allout-tests-obliterate-variable (name)
6814 (defun allout-tests-obliterate-variable (name)
6815 "Completely unbind variable with NAME."
6816 (if (local-variable-p name
(current-buffer)) (kill-local-variable name
))
6817 (while (boundp name
) (makunbound name
)))
6818 ;;;_ > allout-test-resumptions ()
6819 (defvar allout-tests-globally-unbound nil
6820 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6821 (defvar allout-tests-globally-true nil
6822 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6823 (defvar allout-tests-locally-true nil
6824 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6825 (defun allout-test-resumptions ()
6826 "Exercise allout resumptions."
6827 ;; for each resumption case, we also test that the right local/global
6828 ;; scopes are affected during resumption effects:
6830 ;; ensure that previously unbound variables return to the unbound state.
6832 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6833 (allout-add-resumptions '(allout-tests-globally-unbound t
))
6834 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6835 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6836 (assert (boundp 'allout-tests-globally-unbound
))
6837 (assert (equal allout-tests-globally-unbound t
))
6838 (allout-do-resumptions)
6839 (assert (not (local-variable-p 'allout-tests-globally-unbound
6841 (assert (not (boundp 'allout-tests-globally-unbound
))))
6843 ;; ensure that variable with prior global value is resumed
6845 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6846 (setq allout-tests-globally-true t
)
6847 (allout-add-resumptions '(allout-tests-globally-true nil
))
6848 (assert (equal (default-value 'allout-tests-globally-true
) t
))
6849 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6850 (assert (equal allout-tests-globally-true nil
))
6851 (allout-do-resumptions)
6852 (assert (not (local-variable-p 'allout-tests-globally-true
6854 (assert (boundp 'allout-tests-globally-true
))
6855 (assert (equal allout-tests-globally-true t
)))
6857 ;; ensure that prior local value is resumed
6859 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6860 (set (make-local-variable 'allout-tests-locally-true
) t
)
6861 (assert (not (default-boundp 'allout-tests-locally-true
))
6862 nil
(concat "Test setup mistake -- variable supposed to"
6863 " not have global binding, but it does."))
6864 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer))
6865 nil
(concat "Test setup mistake -- variable supposed to have"
6866 " local binding, but it lacks one."))
6867 (allout-add-resumptions '(allout-tests-locally-true nil
))
6868 (assert (not (default-boundp 'allout-tests-locally-true
)))
6869 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6870 (assert (equal allout-tests-locally-true nil
))
6871 (allout-do-resumptions)
6872 (assert (boundp 'allout-tests-locally-true
))
6873 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6874 (assert (equal allout-tests-locally-true t
))
6875 (assert (not (default-boundp 'allout-tests-locally-true
))))
6877 ;; ensure that last of multiple resumptions holds, for various scopes.
6879 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6880 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6881 (setq allout-tests-globally-true t
)
6882 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6883 (set (make-local-variable 'allout-tests-locally-true
) t
)
6884 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6885 '(allout-tests-globally-true nil
)
6886 '(allout-tests-locally-true nil
))
6887 (allout-add-resumptions '(allout-tests-globally-unbound 2)
6888 '(allout-tests-globally-true 3)
6889 '(allout-tests-locally-true 4))
6890 ;; reestablish many of the basic conditions are maintained after re-add:
6891 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6892 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6893 (assert (equal allout-tests-globally-unbound
2))
6894 (assert (default-boundp 'allout-tests-globally-true
))
6895 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6896 (assert (equal allout-tests-globally-true
3))
6897 (assert (not (default-boundp 'allout-tests-locally-true
)))
6898 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6899 (assert (equal allout-tests-locally-true
4))
6900 (allout-do-resumptions)
6901 (assert (not (local-variable-p 'allout-tests-globally-unbound
6903 (assert (not (boundp 'allout-tests-globally-unbound
)))
6904 (assert (not (local-variable-p 'allout-tests-globally-true
6906 (assert (boundp 'allout-tests-globally-true
))
6907 (assert (equal allout-tests-globally-true t
))
6908 (assert (boundp 'allout-tests-locally-true
))
6909 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6910 (assert (equal allout-tests-locally-true t
))
6911 (assert (not (default-boundp 'allout-tests-locally-true
))))
6913 ;; ensure that deliberately unbinding registered variables doesn't foul things
6915 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6916 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6917 (setq allout-tests-globally-true t
)
6918 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6919 (set (make-local-variable 'allout-tests-locally-true
) t
)
6920 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6921 '(allout-tests-globally-true nil
)
6922 '(allout-tests-locally-true nil
))
6923 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6924 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6925 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6926 (allout-do-resumptions))
6928 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
6929 (when allout-run-unit-tests-on-load
6930 (allout-run-unit-tests))
6935 ;;;_* Local emacs vars.
6936 ;; The following `allout-layout' local variable setting:
6937 ;; - closes all topics from the first topic to just before the third-to-last,
6938 ;; - shows the children of the third to last (config vars)
6939 ;; - and the second to last (code section),
6940 ;; - and closes the last topic (this local-variables section).
6942 ;;allout-layout: (0 : -1 -1 0)
6945 ;;; allout.el ends here