1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992-1994, 2001-2015 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 (declare-function epa-passphrase-callback-function
78 "epa" (context key-id handback
))
80 ;;;_* Dependency loads
83 ;; `cl' is required for `assert'. `assert' is not covered by a standard
84 ;; autoload, but it is a macro, so that eval-when-compile is sufficient
85 ;; to byte-compile it in, or to do the require when the buffer evalled.
89 ;;;_* USER CUSTOMIZATION VARIABLES:
91 ;;;_ > defgroup allout, allout-keybindings
93 "Extensive outline minor-mode, for use stand-alone and with other modes.
95 See Allout Auto Activation for automatic activation."
98 (defgroup allout-keybindings nil
99 "Allout outline mode keyboard bindings configuration."
102 ;;;_ + Layout, Mode, and Topic Header Configuration
104 (defvar allout-command-prefix
) ; defined below
106 ;;;_ > allout-keybindings incidentals:
107 ;;;_ : internal key binding stuff - in this section for load-order.
108 ;;;_ = allout-mode-map
109 (defvar allout-mode-map
'allout-mode-map
110 "Keybindings place-holder for (allout) outline minor mode.
112 Do NOT set the value of this variable. Instead, customize
113 `allout-command-prefix', `allout-prefixed-keybindings', and
114 `allout-unprefixed-keybindings'.")
115 ;;;_ = allout-mode-map-value
116 (defvar allout-mode-map-value nil
117 "Keymap for allout outline minor mode.
119 Do NOT set the value of this variable. Instead, customize
120 `allout-command-prefix', `allout-prefixed-keybindings', and
121 `allout-unprefixed-keybindings'.")
122 ;;;_ = make allout-mode-map-value an alias for allout-mode-map:
123 ;; this needs to be revised when the value is changed, sigh.
124 (defalias 'allout-mode-map allout-mode-map-value
)
125 ;;;_ > allout-compose-and-institute-keymap (&optional varname value)
126 (defun allout-compose-and-institute-keymap (&optional varname value
)
127 "Create the allout keymap according to the keybinding specs, and set it.
129 Useful standalone or to effect customizations of the
130 respective allout-mode keybinding variables, `allout-command-prefix',
131 `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'"
132 ;; Set the customization variable, if any:
134 (set-default varname value
))
135 (let ((map (make-sparse-keymap)))
136 (when (boundp 'allout-prefixed-keybindings
)
137 ;; tolerate first definitions of the variables:
138 (dolist (entry allout-prefixed-keybindings
)
140 ;; XXX vector vs non-vector key descriptions?
141 (vconcat allout-command-prefix
142 (car (read-from-string (car entry
))))
144 (when (boundp 'allout-unprefixed-keybindings
)
145 (dolist (entry allout-unprefixed-keybindings
)
146 (define-key map
(car (read-from-string (car entry
))) (cadr entry
))))
147 (substitute-key-definition 'beginning-of-line
'allout-beginning-of-line
149 (substitute-key-definition 'move-beginning-of-line
'allout-beginning-of-line
151 (substitute-key-definition 'end-of-line
'allout-end-of-line
153 (substitute-key-definition 'move-end-of-line
'allout-end-of-line
155 (allout-institute-keymap map
)))
156 ;;;_ > allout-institute-keymap (map)
157 (defun allout-institute-keymap (map)
158 "Associate allout-mode bindings with allout as a minor mode."
160 ;; allout-mode-map var is a keymap by virtue of being a defalias for
161 ;; allout-mode-map-value, which has the actual keymap value.
162 ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be
163 ;; used in minor-mode-map-alist to indirect to the actual
164 ;; allout-mode-map-var value, which can be adjusted and reassigned.
166 ;; allout-mode-map-value for keymap reference in various places:
167 (setq allout-mode-map-value map
)
168 ;; the function value keymap of allout-mode-map is used in
169 ;; minor-mode-map-alist - update it:
170 (fset allout-mode-map allout-mode-map-value
))
171 ;;;_ * initialize the mode map:
172 ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
174 (allout-compose-and-institute-keymap)
175 ;;;_ = allout-command-prefix
176 (defcustom allout-command-prefix
"\C-c "
177 "Key sequence to be used as prefix for outline mode command key bindings.
179 Default is `\C-c<space>'; just `\C-c' is more short-and-sweet, if you're
180 willing to let allout use a bunch of \C-c keybindings."
182 :group
'allout-keybindings
183 :set
'allout-compose-and-institute-keymap
)
184 ;;;_ = allout-keybindings-binding
185 (define-widget 'allout-keybindings-binding
'lazy
186 "Structure of allout keybindings customization items."
188 (list (string :tag
"Key" :value
"[(meta control shift ?f)]")
189 (function :tag
"Function name"
190 :value allout-forward-current-level
))))
191 ;;;_ = allout-prefixed-keybindings
192 (defcustom allout-prefixed-keybindings
193 '(("[(control ?n)]" allout-next-visible-heading
)
194 ("[(control ?p)]" allout-previous-visible-heading
)
195 ("[(control ?u)]" allout-up-current-level
)
196 ("[(control ?f)]" allout-forward-current-level
)
197 ("[(control ?b)]" allout-backward-current-level
)
198 ("[(control ?a)]" allout-beginning-of-current-entry
)
199 ("[(control ?e)]" allout-end-of-entry
)
200 ("[(control ?i)]" allout-show-children
)
201 ("[(control ?s)]" allout-show-current-subtree
)
202 ("[(control ?t)]" allout-toggle-current-subtree-exposure
)
203 ;; Let user customize if they want to preempt describe-prefix-bindings ^h use.
204 ;; ("[(control ?h)]" allout-hide-current-subtree)
205 ("[?h]" allout-hide-current-subtree
)
206 ("[(control ?o)]" allout-show-current-entry
)
207 ("[?!]" allout-show-all
)
208 ("[?x]" allout-toggle-current-subtree-encryption
)
209 ("[? ]" allout-open-sibtopic
)
210 ("[?.]" allout-open-subtopic
)
211 ("[?,]" allout-open-supertopic
)
212 ("[?']" allout-shift-in
)
213 ("[?>]" allout-shift-in
)
214 ("[?<]" allout-shift-out
)
215 ("[(control ?m)]" allout-rebullet-topic
)
216 ("[?*]" allout-rebullet-current-heading
)
217 ("[?#]" allout-number-siblings
)
218 ("[(control ?k)]" allout-kill-topic
)
219 ("[(meta ?k)]" allout-copy-topic-as-kill
)
220 ("[?@]" allout-resolve-xref
)
221 ("[?=?c]" allout-copy-exposed-to-buffer
)
222 ("[?=?i]" allout-indented-exposed-to-buffer
)
223 ("[?=?t]" allout-latexify-exposed
)
224 ("[?=?p]" allout-flatten-exposed-to-buffer
)
226 "Allout-mode key bindings that are prefixed with `allout-command-prefix'.
228 See `allout-unprefixed-keybindings' for the list of keybindings
229 that are not prefixed.
231 Use vector format for the keys:
232 - put literal keys after a ‘?’ question mark, eg: ‘?a’, ‘?.’
233 - enclose control, shift, or meta-modified keys as sequences within
234 parentheses, with the literal key, as above, preceded by the name(s)
235 of the modifiers, eg: [(control ?a)]
236 See the existing keys for examples.
238 Functions can be bound to multiple keys, but binding keys to
239 multiple functions will not work - the last binding for a key
242 :type
'allout-keybindings-binding
243 :group
'allout-keybindings
244 :set
'allout-compose-and-institute-keymap
246 ;;;_ = allout-unprefixed-keybindings
247 (defcustom allout-unprefixed-keybindings
248 '(("[(control ?k)]" allout-kill-line
)
249 ("[(meta ?k)]" allout-copy-line-as-kill
)
250 ("[(control ?y)]" allout-yank
)
251 ("[(meta ?y)]" allout-yank-pop
)
253 "Allout-mode functions bound to keys without any added prefix.
255 This is in contrast to the majority of allout-mode bindings on
256 `allout-prefixed-bindings', whose bindings are created with a
257 preceding command key.
259 Use vector format for the keys:
260 - put literal keys after a ‘?’ question mark, eg: ‘?a’, ‘?.’
261 - enclose control, shift, or meta-modified keys as sequences within
262 parentheses, with the literal key, as above, preceded by the name(s)
263 of the modifiers, eg: [(control ?a)]
264 See the existing keys for examples."
266 :type
'allout-keybindings-binding
267 :group
'allout-keybindings
268 :set
'allout-compose-and-institute-keymap
271 ;;;_ > allout-auto-activation-helper (var value)
273 (defun allout-auto-activation-helper (var value
)
274 "Institute `allout-auto-activation'.
276 Intended to be used as the `allout-auto-activation' :set function."
277 (set-default var value
)
279 ;;;_ > allout-setup ()
281 (defun allout-setup ()
282 "Do fundamental Emacs session for allout auto-activation.
284 Establishes allout processing as part of visiting a file if
285 `allout-auto-activation' is non-nil, or removes it otherwise.
287 The proper way to use this is through customizing the setting of
288 `allout-auto-activation'."
289 (if (not allout-auto-activation
)
290 (remove-hook 'find-file-hook
'allout-find-file-hook
)
291 (add-hook 'find-file-hook
'allout-find-file-hook
)))
292 ;;;_ = allout-auto-activation
294 (defcustom allout-auto-activation nil
295 "Configure allout outline mode auto-activation.
297 Control whether and how allout outline mode is automatically
298 activated when files are visited with non-nil buffer-specific
299 file variable `allout-layout'.
301 When allout-auto-activation is \"On\" (t), allout mode is
302 activated in buffers with non-nil `allout-layout', and the
303 specified layout is applied.
305 With value \"ask\", auto-mode-activation is enabled, and endorsement for
306 performing auto-layout is asked of the user each time.
308 With value \"activate\", only auto-mode-activation is enabled.
311 With value nil, inhibit any automatic allout-mode activation."
312 :set
'allout-auto-activation-helper
313 ;; FIXME: Using strings here is unusual and less efficient than symbols.
314 :type
'(choice (const :tag
"On" t
)
315 (const :tag
"Ask about layout" "ask")
316 (const :tag
"Mode only" "activate")
317 (const :tag
"Off" nil
))
320 ;;;_ = allout-default-layout
321 (defcustom allout-default-layout
'(-2 : 0)
322 "Default allout outline layout specification.
324 This setting specifies the outline exposure to use when
325 `allout-layout' has the local value t. This docstring describes the
326 layout specifications.
328 A list value specifies a default layout for the current buffer,
329 to be applied upon activation of `allout-mode'. Any non-nil
330 value will automatically trigger `allout-mode', provided
331 `allout-auto-activation' has been customized to enable it.
333 The types of elements in the layout specification are:
335 INTEGER -- dictate the relative depth to open the corresponding topic(s),
337 -- negative numbers force the topic to be closed before opening
338 to the absolute value of the number, so all siblings are open
340 -- positive numbers open to the relative depth indicated by the
341 number, but do not force already opened subtopics to be closed.
342 -- 0 means to close topic -- hide all subitems.
343 : -- repeat spec -- apply the preceding element to all siblings at
344 current level, *up to* those siblings that would be covered by specs
345 following the `:' on the list. Ie, apply to all topics at level but
346 trailing ones accounted for by trailing specs. (Only the first of
347 multiple colons at the same level is honored -- later ones are ignored.)
348 * -- completely exposes the topic, including bodies
349 + -- exposes all subtopics, but not the bodies
350 - -- exposes the body of the corresponding topic, but not subtopics
351 LIST -- a nested layout spec, to be applied intricately to its
352 corresponding item(s)
356 Collapse the top-level topics to show their children and
357 grandchildren, but completely collapse the final top-level topic.
359 Close the first topic so only the immediate subtopics are shown,
360 leave the subsequent topics exposed as they are until the second
361 second to last topic, which is exposed at least one level, and
362 completely close the last topic.
364 Expose children and grandchildren of all topics at current
365 level except the last two; expose children of the second to
366 last and completely expose the last one, including its subtopics.
368 See `allout-expose-topic' for more about the exposure process.
370 Also, allout's mode-specific provisions will make topic prefixes default
371 to the comment-start string, if any, of the language of the file. This
372 is modulo the setting of `allout-use-mode-specific-leader', which see."
373 :type
'allout-layout-type
375 ;;;_ : allout-layout-type
376 (define-widget 'allout-layout-type
'lazy
377 "Allout layout format customization basic building blocks."
379 (choice (integer :tag
"integer (<= zero is strict)")
380 (const :tag
": (repeat prior)" :)
381 (const :tag
"* (completely expose)" *)
382 (const :tag
"+ (expose all offspring, headlines only)" +)
383 (const :tag
"- (expose topic body but not offspring)" -
)
384 (allout-layout-type :tag
"<Nested layout>"))))
386 ;;;_ = allout-inhibit-auto-fill
387 (defcustom allout-inhibit-auto-fill nil
388 "If non-nil, auto-fill will be inhibited in the allout buffers.
390 You can customize this setting to set it for all allout buffers, or set it
391 in individual buffers if you want to inhibit auto-fill only in particular
392 buffers. (You could use a function on `allout-mode-hook' to inhibit
393 auto-fill according, eg, to the major mode.)
395 If you don't set this and auto-fill-mode is enabled, allout will use the
396 value that `normal-auto-fill-function', if any, when allout mode starts, or
397 else allout's special hanging-indent maintaining auto-fill function,
401 (make-variable-buffer-local 'allout-inhibit-auto-fill
)
402 ;;;_ = allout-inhibit-auto-fill-on-headline
403 (defcustom allout-inhibit-auto-fill-on-headline nil
404 "If non-nil, auto-fill will be inhibited while on topic's header line."
408 (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline
)
409 ;;;_ = allout-use-hanging-indents
410 (defcustom allout-use-hanging-indents t
411 "If non-nil, topic body text auto-indent defaults to indent of the header.
412 Ie, it is indented to be just past the header prefix. This is
413 relevant mostly for use with `indented-text-mode', or other situations
414 where auto-fill occurs."
417 (make-variable-buffer-local 'allout-use-hanging-indents
)
419 (put 'allout-use-hanging-indents
'safe-local-variable
420 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
421 ;;;_ = allout-reindent-bodies
422 (defcustom allout-reindent-bodies
(if allout-use-hanging-indents
424 "Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
426 When active, topic body lines that are indented even with or beyond
427 their topic header are reindented to correspond with depth shifts of
430 A value of t enables reindent in non-programming-code buffers, ie
431 those that do not have the variable `comment-start' set. A value of
432 `force' enables reindent whether or not `comment-start' is set."
433 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
436 (make-variable-buffer-local 'allout-reindent-bodies
)
438 (put 'allout-reindent-bodies
'safe-local-variable
439 (lambda (x) (memq x
'(nil t text force
))))
441 ;;;_ = allout-show-bodies
442 (defcustom allout-show-bodies nil
443 "If non-nil, show entire body when exposing a topic, rather than
447 (make-variable-buffer-local 'allout-show-bodies
)
449 (put 'allout-show-bodies
'safe-local-variable
450 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
452 ;;;_ = allout-beginning-of-line-cycles
453 (defcustom allout-beginning-of-line-cycles t
454 "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
456 Cycling only happens on when the command is repeated, not when it
457 follows a different command.
459 Smart-placement means that repeated calls to this function will
462 - if the cursor is on a non-headline body line and not on the first column:
463 then it goes to the first column
464 - if the cursor is on the first column of a non-headline body line:
465 then it goes to the start of the headline within the item body
466 - if the cursor is on the headline and not the start of the headline:
467 then it goes to the start of the headline
468 - if the cursor is on the start of the headline:
469 then it goes to the bullet character (for hotspot navigation)
470 - if the cursor is on the bullet character:
471 then it goes to the first column of that line (the headline)
472 - if the cursor is on the first column of the headline:
473 then it goes to the start of the headline within the item body.
475 In this fashion, you can use the beginning-of-line command to do
476 its normal job and then, when repeated, advance through the
477 entry, cycling back to start.
479 If this configuration variable is nil, then the cursor is just
480 advanced to the beginning of the line and remains there on
482 :type
'boolean
:group
'allout
)
483 ;;;_ = allout-end-of-line-cycles
484 (defcustom allout-end-of-line-cycles t
485 "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
487 Cycling only happens on when the command is repeated, not when it
488 follows a different command.
490 Smart placement means that repeated calls to this function will
493 - if the cursor is not on the end-of-line,
494 then it goes to the end-of-line
495 - if the cursor is on the end-of-line but not the end-of-entry,
496 then it goes to the end-of-entry, exposing it if necessary
497 - if the cursor is on the end-of-entry,
498 then it goes to the end of the head line
500 In this fashion, you can use the end-of-line command to do its
501 normal job and then, when repeated, advance through the entry,
502 cycling back to start.
504 If this configuration variable is nil, then the cursor is just
505 advanced to the end of the line and remains there on repeated
507 :type
'boolean
:group
'allout
)
509 ;;;_ = allout-header-prefix
510 (defcustom allout-header-prefix
"."
511 ;; this string is treated as literal match. it will be `regexp-quote'd, so
512 ;; one cannot use regular expressions to match varying header prefixes.
513 "Leading string which helps distinguish topic headers.
515 Outline topic header lines are identified by a leading topic
516 header prefix, which mostly have the value of this var at their front.
517 Level 1 topics are exceptions. They consist of only a single
518 character, which is typically set to the `allout-primary-bullet'."
521 (make-variable-buffer-local 'allout-header-prefix
)
523 (put 'allout-header-prefix
'safe-local-variable
'stringp
)
524 ;;;_ = allout-primary-bullet
525 (defcustom allout-primary-bullet
"*"
526 "Bullet used for top-level outline topics.
528 Outline topic header lines are identified by a leading topic header
529 prefix, which is concluded by bullets that includes the value of this
530 var and the respective allout-*-bullets-string vars.
532 The value of an asterisk (`*') provides for backwards compatibility
533 with the original Emacs outline mode. See `allout-plain-bullets-string'
534 and `allout-distinctive-bullets-string' for the range of available
538 (make-variable-buffer-local 'allout-primary-bullet
)
540 (put 'allout-primary-bullet
'safe-local-variable
'stringp
)
541 ;;;_ = allout-plain-bullets-string
542 (defcustom allout-plain-bullets-string
".,"
543 "The bullets normally used in outline topic prefixes.
545 See `allout-distinctive-bullets-string' for the other kind of
548 DO NOT include the close-square-bracket, `]', as a bullet.
550 Outline mode has to be reactivated in order for changes to the value
551 of this var to take effect."
554 (make-variable-buffer-local 'allout-plain-bullets-string
)
556 (put 'allout-plain-bullets-string
'safe-local-variable
'stringp
)
557 ;;;_ = allout-distinctive-bullets-string
558 (defcustom allout-distinctive-bullets-string
"*+-=>()[{}&!?#%\"X@$~_\\:;^"
559 "Persistent outline header bullets used to distinguish special topics.
561 These bullets are distinguish topics with particular character.
562 They are not used by default in the topic creation routines, but
563 are offered as options when you modify topic creation with a
564 universal argument (\\[universal-argument]), or during rebulleting (\\[allout-rebullet-current-heading]).
566 Distinctive bullets are not cycled when topics are shifted or
567 otherwise automatically rebulleted, so their marking is
568 persistent until deliberately changed. Their significance is
569 purely by convention, however. Some conventions suggest
572 `(' - open paren -- an aside or incidental point
573 `?' - question mark -- uncertain or outright question
574 `!' - exclamation point/bang -- emphatic
575 `[' - open square bracket -- meta-note, about item instead of item's subject
576 `\"' - double quote -- a quotation or other citation
577 `=' - equal sign -- an assignment, some kind of definition
578 `^' - carat -- relates to something above
580 Some are more elusive, but their rationale may be recognizable:
582 `+' - plus -- pending consideration, completion
583 `_' - underscore -- done, completed
584 `&' - ampersand -- addendum, furthermore
586 \(Some other non-plain bullets have special meaning to the
587 software. By default:
589 `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
590 `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
592 See `allout-plain-bullets-string' for the standard, alternating
595 You must run `set-allout-regexp' in order for outline mode to
596 adopt changes of this value.
598 DO NOT include the close-square-bracket, `]', on either of the bullet
602 (make-variable-buffer-local 'allout-distinctive-bullets-string
)
604 (put 'allout-distinctive-bullets-string
'safe-local-variable
'stringp
)
606 ;;;_ = allout-use-mode-specific-leader
607 (defcustom allout-use-mode-specific-leader t
608 "When non-nil, use mode-specific topic-header prefixes.
610 Allout outline mode will use the mode-specific `allout-mode-leaders' or
611 comment-start string, if any, to lead the topic prefix string, so topic
612 headers look like comments in the programming language. It will also use
613 the comment-start string, with an `_' appended, for `allout-primary-bullet'.
615 String values are used as literals, not regular expressions, so
616 do not escape any regular-expression characters.
618 Value t means to first check for assoc value in `allout-mode-leaders'
619 alist, then use comment-start string, if any, then use default (`.').
620 \(See note about use of comment-start strings, below.)
622 Set to the symbol for either of `allout-mode-leaders' or
623 `comment-start' to use only one of them, respectively.
625 Value nil means to always use the default (`.') and leave
626 `allout-primary-bullet' unaltered.
628 comment-start strings that do not end in spaces are tripled in
629 the header-prefix, and an `_' underscore is tacked on the end, to
630 distinguish them from regular comment strings. comment-start
631 strings that do end in spaces are not tripled, but an underscore
632 is substituted for the space. [This presumes that the space is
633 for appearance, not comment syntax. You can use
634 `allout-mode-leaders' to override this behavior, when
636 :type
'(choice (const t
) (const nil
) string
637 (const allout-mode-leaders
)
638 (const comment-start
))
641 (put 'allout-use-mode-specific-leader
'safe-local-variable
642 (lambda (x) (or (memq x
'(t nil allout-mode-leaders comment-start
))
644 ;;;_ = allout-mode-leaders
645 (defvar allout-mode-leaders
'()
646 "Specific allout-prefix leading strings per major modes.
648 Use this if the mode's comment-start string isn't what you
649 prefer, or if the mode lacks a comment-start string. See
650 `allout-use-mode-specific-leader' for more details.
652 If you're constructing a string that will comment-out outline
653 structuring so it can be included in program code, append an extra
654 character, like an \"_\" underscore, to distinguish the lead string
655 from regular comments that start at the beginning-of-line.")
657 ;;;_ = allout-old-style-prefixes
658 (defcustom allout-old-style-prefixes nil
659 "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
661 Non-nil restricts the topic creation and modification
662 functions to asterix-padded prefixes, so they look exactly
663 like the original Emacs-outline style prefixes.
665 Whatever the setting of this variable, both old and new style prefixes
666 are always respected by the topic maneuvering functions."
669 (make-variable-buffer-local 'allout-old-style-prefixes
)
671 (put 'allout-old-style-prefixes
'safe-local-variable
672 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
673 ;;;_ = allout-stylish-prefixes -- alternating bullets
674 (defcustom allout-stylish-prefixes t
675 "Do fancy stuff with topic prefix bullets according to level, etc.
677 Non-nil enables topic creation, modification, and repositioning
678 functions to vary the topic bullet char (the char that marks the topic
679 depth) just preceding the start of the topic text) according to level.
680 Otherwise, only asterisks (`*') and distinctive bullets are used.
682 This is how an outline can look (but sans indentation) with stylish
687 . + One level 3 subtopic
688 . . One level 4 subtopic
689 . . A second 4 subtopic
690 . + Another level 3 subtopic
691 . #1 A numbered level 4 subtopic
693 . ! Another level 4 subtopic with a different distinctive bullet
694 . #4 And another numbered level 4 subtopic
696 This would be an outline with stylish prefixes inhibited (but the
697 numbered and other distinctive bullets retained):
701 . * One level 3 subtopic
702 . * One level 4 subtopic
703 . * A second 4 subtopic
704 . * Another level 3 subtopic
705 . #1 A numbered level 4 subtopic
707 . ! Another level 4 subtopic with a different distinctive bullet
708 . #4 And another numbered level 4 subtopic
710 Stylish and constant prefixes (as well as old-style prefixes) are
711 always respected by the topic maneuvering functions, regardless of
712 this variable setting.
714 The setting of this var is not relevant when `allout-old-style-prefixes'
718 (make-variable-buffer-local 'allout-stylish-prefixes
)
720 (put 'allout-stylish-prefixes
'safe-local-variable
721 (if (fboundp 'booleanp
) 'booleanp
(lambda (x) (member x
'(t nil
)))))
723 ;;;_ = allout-numbered-bullet
724 (defcustom allout-numbered-bullet
"#"
725 "String designating bullet of topics that have auto-numbering; nil for none.
727 Topics having this bullet have automatic maintenance of a sibling
728 sequence-number tacked on, just after the bullet. Conventionally set
729 to \"#\", you can set it to a bullet of your choice. A nil value
730 disables numbering maintenance."
731 :type
'(choice (const nil
) string
)
733 (make-variable-buffer-local 'allout-numbered-bullet
)
735 (put 'allout-numbered-bullet
'safe-local-variable
736 (if (fboundp 'string-or-null-p
)
738 (lambda (x) (or (stringp x
) (null x
)))))
739 ;;;_ = allout-file-xref-bullet
740 (defcustom allout-file-xref-bullet
"@"
741 "Bullet signifying file cross-references, for `allout-resolve-xref'.
743 Set this var to the bullet you want to use for file cross-references."
744 :type
'(choice (const nil
) string
)
747 (put 'allout-file-xref-bullet
'safe-local-variable
748 (if (fboundp 'string-or-null-p
)
750 (lambda (x) (or (stringp x
) (null x
)))))
751 ;;;_ = allout-presentation-padding
752 (defcustom allout-presentation-padding
2
753 "Presentation-format white-space padding factor, for greater indent."
757 (make-variable-buffer-local 'allout-presentation-padding
)
759 (put 'allout-presentation-padding
'safe-local-variable
'integerp
)
761 ;;;_ = allout-flattened-numbering-abbreviation
762 (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering
763 'allout-flattened-numbering-abbreviation
"24.1")
764 (defcustom allout-flattened-numbering-abbreviation nil
765 "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
766 numbers to minimal amount with some context. Otherwise, entire
767 numbers are always used."
772 ;;;_ + LaTeX formatting
773 ;;;_ - allout-number-pages
774 (defcustom allout-number-pages nil
775 "Non-nil turns on page numbering for LaTeX formatting of an outline."
778 ;;;_ - allout-label-style
779 (defcustom allout-label-style
"\\large\\bf"
780 "Font and size of labels for LaTeX formatting of an outline."
783 ;;;_ - allout-head-line-style
784 (defcustom allout-head-line-style
"\\large\\sl "
785 "Font and size of entries for LaTeX formatting of an outline."
788 ;;;_ - allout-body-line-style
789 (defcustom allout-body-line-style
" "
790 "Font and size of entries for LaTeX formatting of an outline."
793 ;;;_ - allout-title-style
794 (defcustom allout-title-style
"\\Large\\bf"
795 "Font and size of titles for LaTeX formatting of an outline."
799 (defcustom allout-title
'(or buffer-file-name
(buffer-name))
800 "Expression to be evaluated to determine the title for LaTeX
804 ;;;_ - allout-line-skip
805 (defcustom allout-line-skip
".05cm"
806 "Space between lines for LaTeX formatting of an outline."
810 (defcustom allout-indent
".3cm"
811 "LaTeX formatted depth-indent spacing."
815 ;;;_ + Topic encryption
816 ;;;_ = allout-encryption group
817 (defgroup allout-encryption nil
818 "Settings for topic encryption features of allout outliner."
820 ;;;_ = allout-topic-encryption-bullet
821 (defcustom allout-topic-encryption-bullet
"~"
822 "Bullet signifying encryption of the entry's body."
823 :type
'(choice (const nil
) string
)
825 :group
'allout-encryption
)
826 ;;;_ = allout-encrypt-unencrypted-on-saves
827 (defcustom allout-encrypt-unencrypted-on-saves t
828 "If non-nil, topics pending encryption are encrypted during buffer saves.
830 This prevents file-system exposure of un-encrypted contents of
831 items marked for encryption.
833 When non-nil, if the topic currently being edited is decrypted,
834 it will be encrypted for saving but automatically decrypted
835 before any subsequent user interaction, so it is once again clear
836 text for editing though the file system copy is encrypted.
838 \(Auto-saves are handled differently. Buffers with plain-text
839 exposed encrypted topics are exempted from auto saves until all
840 such topics are encrypted.)"
844 :group
'allout-encryption
)
845 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves
)
846 (defvar allout-auto-save-temporarily-disabled nil
847 "True while topic encryption is pending and auto-saving was active.
849 The value of `buffer-saved-size' at the time of decryption is used,
850 for restoring when all encryptions are established.")
851 (defvar allout-just-did-undo nil
852 "True just after undo commands, until allout-post-command-business.")
853 (make-variable-buffer-local 'allout-just-did-undo
)
856 ;;;_ = allout-developer group
857 (defgroup allout-developer nil
858 "Allout settings developers care about, including topic encryption and more."
860 ;;;_ = allout-run-unit-tests-on-load
861 (defcustom allout-run-unit-tests-on-load nil
862 "When non-nil, unit tests will be run at end of loading the allout module.
864 Generally, allout code developers are the only ones who'll want to set this.
866 \(If set, this makes it an even better practice to exercise changes by
867 doing byte-compilation with a repeat count, so the file is loaded after
870 See `allout-run-unit-tests' to see what's run."
872 :group
'allout-developer
)
874 ;;;_ + Miscellaneous customization
876 ;;;_ = allout-enable-file-variable-adjustment
877 (defcustom allout-enable-file-variable-adjustment t
878 "If non-nil, some allout outline actions edit Emacs local file var text.
880 This can range from changes to existing entries, addition of new ones,
881 and creation of a new local variables section when necessary.
883 Emacs file variables adjustments are also inhibited if `enable-local-variables'
886 Operations potentially causing edits include allout encryption routines.
887 For details, see `allout-toggle-current-subtree-encryption's docstring."
890 (make-variable-buffer-local 'allout-enable-file-variable-adjustment
)
892 ;;;_* CODE -- no user customizations below.
894 ;;;_ #1 Internal Outline Formatting and Configuration
896 ;;;_ = allout-version
897 (defvar allout-version
"2.3"
898 "Version of currently loaded outline package. (allout.el)")
899 ;;;_ > allout-version
900 (defun allout-version (&optional here
)
901 "Return string describing the loaded outline version."
903 (let ((msg (concat "Allout Outline Mode v " allout-version
)))
904 (if here
(insert msg
))
907 ;;;_ : Mode activation (defined here because it's referenced early)
909 (defvar allout-mode nil
"Allout outline mode minor-mode flag.")
910 (make-variable-buffer-local 'allout-mode
)
911 ;;;_ = allout-layout nil
912 (defvar allout-layout nil
; LEAVE GLOBAL VALUE NIL -- see docstring.
913 "Buffer-specific setting for allout layout.
915 In buffers where this is non-nil (and if `allout-auto-activation'
916 has been customized to enable this behavior), `allout-mode' will be
917 automatically activated. The layout dictated by the value will be used to
918 set the initial exposure when `allout-mode' is activated.
920 \*You should not setq-default this variable non-nil unless you want every
921 visited file to be treated as an allout file.*
923 The value would typically be set by a file local variable. For
924 example, the following lines at the bottom of an Emacs Lisp file:
927 ;;;allout-layout: (0 : -1 -1 0)
930 dictate activation of `allout-mode' mode when the file is visited
931 \(presuming proper `allout-auto-activation' customization),
932 followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'.
933 \(This is the layout used for the allout.el source file.)
935 `allout-default-layout' describes the specification format.
936 `allout-layout' can additionally have the value t, in which
937 case the value of `allout-default-layout' is used.")
938 (make-variable-buffer-local 'allout-layout
)
940 (put 'allout-layout
'safe-local-variable
941 (lambda (x) (or (numberp x
) (listp x
) (memq x
'(: * + -
)))))
943 ;;;_ : Topic header format
945 (defvar allout-regexp
""
946 "Regular expression to match the beginning of a heading line.
948 Any line whose beginning matches this regexp is considered a
949 heading. This var is set according to the user configuration vars
950 by `set-allout-regexp'.")
951 (make-variable-buffer-local 'allout-regexp
)
952 ;;;_ = allout-bullets-string
953 (defvar allout-bullets-string
""
954 "A string dictating the valid set of outline topic bullets.
956 This var should *not* be set by the user -- it is set by `set-allout-regexp',
957 and is produced from the elements of `allout-plain-bullets-string'
958 and `allout-distinctive-bullets-string'.")
959 (make-variable-buffer-local 'allout-bullets-string
)
960 ;;;_ = allout-bullets-string-len
961 (defvar allout-bullets-string-len
0
962 "Length of current buffers' `allout-plain-bullets-string'.")
963 (make-variable-buffer-local 'allout-bullets-string-len
)
964 ;;;_ = allout-depth-specific-regexp
965 (defvar allout-depth-specific-regexp
""
966 "Regular expression to match a heading line prefix for a particular depth.
968 This expression is used to search for depth-specific topic
969 headers at depth 2 and greater. Use `allout-depth-one-regexp'
970 for to seek topics at depth one.
972 This var is set according to the user configuration vars by
973 `set-allout-regexp'. It is prepared with format strings for two
974 decimal numbers, which should each be one less than the depth of the
975 topic prefix to be matched.")
976 (make-variable-buffer-local 'allout-depth-specific-regexp
)
977 ;;;_ = allout-depth-one-regexp
978 (defvar allout-depth-one-regexp
""
979 "Regular expression to match a heading line prefix for depth one.
981 This var is set according to the user configuration vars by
982 `set-allout-regexp'. It is prepared with format strings for two
983 decimal numbers, which should each be one less than the depth of the
984 topic prefix to be matched.")
985 (make-variable-buffer-local 'allout-depth-one-regexp
)
986 ;;;_ = allout-line-boundary-regexp
987 (defvar allout-line-boundary-regexp
()
988 "`allout-regexp' prepended with a newline for the search target.
990 This is properly set by `set-allout-regexp'.")
991 (make-variable-buffer-local 'allout-line-boundary-regexp
)
992 ;;;_ = allout-bob-regexp
993 (defvar allout-bob-regexp
()
994 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
995 (make-variable-buffer-local 'allout-bob-regexp
)
996 ;;;_ = allout-header-subtraction
997 (defvar allout-header-subtraction
(1- (length allout-header-prefix
))
998 "Allout-header prefix length to subtract when computing topic depth.")
999 (make-variable-buffer-local 'allout-header-subtraction
)
1000 ;;;_ = allout-plain-bullets-string-len
1001 (defvar allout-plain-bullets-string-len
(length allout-plain-bullets-string
)
1002 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
1003 (make-variable-buffer-local 'allout-plain-bullets-string-len
)
1005 ;;;_ = allout-doublecheck-at-and-shallower
1006 (defconst allout-doublecheck-at-and-shallower
3
1007 "Validate apparent topics of this depth and shallower as being non-aberrant.
1009 Verified with `allout-aberrant-container-p'. The usefulness of
1010 this check is limited to shallow depths, because the
1011 determination of aberrance is according to the mistaken item
1012 being followed by a legitimate item of excessively greater depth.
1014 The classic example of a mistaken item, for a standard allout
1015 outline configuration, is a body line that begins with an ‘...’
1016 ellipsis. This happens to contain a legitimate depth-2 header
1017 prefix, constituted by two ‘..’ dots at the beginning of the
1018 line. The only thing that can distinguish it *in principle* from
1019 a legitimate one is if the following real header is at a depth
1020 that is discontinuous from the depth of 2 implied by the
1021 ellipsis, ie depth 4 or more. As the depth being tested gets
1022 greater, the likelihood of this kind of disqualification is
1023 lower, and the usefulness of this test is lower.
1025 Extending the depth of the doublecheck increases the amount it is
1026 applied, increasing the cost of the test - on casual estimation,
1027 for outlines with many deep topics, geometrically (O(n)?).
1028 Taken together with decreasing likelihood that the test will be
1029 useful at greater depths, more modest doublecheck limits are more
1030 suitably economical.")
1031 ;;;_ X allout-reset-header-lead (header-lead)
1032 (defun allout-reset-header-lead (header-lead)
1033 "Reset the leading string used to identify topic headers."
1034 (interactive "sNew lead string: ")
1035 (setq allout-header-prefix header-lead
)
1036 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1037 (set-allout-regexp))
1038 ;;;_ X allout-lead-with-comment-string (header-lead)
1039 (defun allout-lead-with-comment-string (&optional header-lead
)
1040 "Set the topic-header leading string to specified string.
1042 Useful for encapsulating outline structure in programming
1043 language comments. Returns the leading string."
1046 (if (not (stringp header-lead
))
1047 (setq header-lead
(read-string
1048 "String prefix for topic headers: ")))
1049 (setq allout-reindent-bodies nil
)
1050 (allout-reset-header-lead header-lead
)
1052 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
1053 (defun allout-infer-header-lead-and-primary-bullet ()
1054 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
1056 Works according to settings of:
1059 `allout-header-prefix' (default)
1060 `allout-use-mode-specific-leader'
1061 and `allout-mode-leaders'.
1063 Apply this via (re)activation of `allout-mode', rather than
1064 invoking it directly."
1065 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader
)
1066 (if (or (stringp allout-use-mode-specific-leader
)
1067 (memq allout-use-mode-specific-leader
1068 '(allout-mode-leaders
1071 allout-use-mode-specific-leader
1072 ;; Oops -- garbled value, equate with effect of t:
1076 ((not use-leader
) nil
)
1077 ;; Use the explicitly designated leader:
1078 ((stringp use-leader
) use-leader
)
1079 (t (or (and (memq use-leader
'(t allout-mode-leaders
))
1080 ;; Get it from outline mode leaders?
1081 (cdr (assq major-mode allout-mode-leaders
)))
1082 ;; ... didn't get from allout-mode-leaders...
1083 (and (memq use-leader
'(t comment-start
))
1085 ;; Use comment-start, maybe tripled, and with
1089 (substring comment-start
1090 (1- (length comment-start
))))
1091 ;; Use comment-start, sans trailing space:
1092 (substring comment-start
0 -
1)
1093 (concat comment-start comment-start comment-start
))
1094 ;; ... and append underscore, whichever:
1098 (setq allout-header-prefix leader
)
1099 (if (not allout-old-style-prefixes
)
1100 ;; setting allout-primary-bullet makes the top level topics use --
1101 ;; actually, be -- the special prefix:
1102 (setq allout-primary-bullet leader
))
1103 allout-header-prefix
)))
1104 (defalias 'allout-infer-header-lead
1105 'allout-infer-header-lead-and-primary-bullet
)
1106 ;;;_ > allout-infer-body-reindent ()
1107 (defun allout-infer-body-reindent ()
1108 "Determine proper setting for `allout-reindent-bodies'.
1110 Depends on default setting of `allout-reindent-bodies' (which see)
1111 and presence of setting for `comment-start', to tell whether the
1112 file is programming code."
1113 (if (and allout-reindent-bodies
1115 (not (eq 'force allout-reindent-bodies
)))
1116 (setq allout-reindent-bodies nil
)))
1117 ;;;_ > set-allout-regexp ()
1118 (defun set-allout-regexp ()
1119 "Generate proper topic-header regexp form for outline functions.
1121 Works with respect to `allout-plain-bullets-string' and
1122 `allout-distinctive-bullets-string'.
1124 Also refresh various data structures that hinge on the regexp."
1127 ;; Derive allout-bullets-string from user configured components:
1128 (setq allout-bullets-string
"")
1129 (let ((strings (list 'allout-plain-bullets-string
1130 'allout-distinctive-bullets-string
1131 'allout-primary-bullet
))
1138 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
1139 (while (< index cur-len
)
1140 (setq cur-char
(aref cur-string index
))
1141 (setq allout-bullets-string
1142 (concat allout-bullets-string
1144 ; Single dash would denote a
1145 ; sequence, repeated denotes
1147 ((eq cur-char ?-
) "--")
1148 ; literal close-square-bracket
1149 ; doesn't work right in the
1151 ((eq cur-char ?\
]) "")
1152 (t (regexp-quote (char-to-string cur-char
))))))
1153 (setq index
(1+ index
)))
1154 (setq strings
(cdr strings
)))
1156 ;; Derive next for repeated use in allout-pending-bullet:
1157 (setq allout-plain-bullets-string-len
(length allout-plain-bullets-string
))
1158 (setq allout-header-subtraction
(1- (length allout-header-prefix
)))
1160 (let (new-part old-part formfeed-part
)
1161 (setq new-part
(concat "\\("
1162 (regexp-quote allout-header-prefix
)
1164 ;; already regexp-quoted in a custom way:
1165 "[" allout-bullets-string
"]"
1167 old-part
(concat "\\("
1168 (regexp-quote allout-primary-bullet
)
1170 (regexp-quote allout-header-prefix
)
1173 " ?[^" allout-primary-bullet
"]")
1174 formfeed-part
"\\(\^L\\)"
1176 allout-regexp
(concat new-part
1182 allout-line-boundary-regexp
(concat "\n" new-part
1188 allout-bob-regexp
(concat "\\`" new-part
1195 (setq allout-depth-specific-regexp
1196 (concat "\\(^\\|\\`\\)"
1199 ;; new-style spacers-then-bullet string:
1201 (allout-format-quote (regexp-quote allout-header-prefix
))
1203 "[" (allout-format-quote allout-bullets-string
) "]"
1206 ;; old-style all-bullets string, if primary not multi-char:
1207 (if (< 0 allout-header-subtraction
)
1210 (allout-format-quote
1211 (regexp-quote allout-primary-bullet
))
1212 (allout-format-quote
1213 (regexp-quote allout-primary-bullet
))
1214 (allout-format-quote
1215 (regexp-quote allout-primary-bullet
))
1217 ;; disqualify greater depths:
1219 (allout-format-quote allout-primary-bullet
)
1224 (setq allout-depth-one-regexp
1225 (concat "\\(^\\|\\`\\)"
1229 (regexp-quote allout-header-prefix
)
1230 ;; disqualify any bullet char following any amount of
1231 ;; intervening whitespace:
1233 (concat "[^ " allout-bullets-string
"]")
1235 (if (< 0 allout-header-subtraction
)
1236 ;; Need not support anything like the old
1237 ;; bullet style if the prefix is multi-char.
1240 (regexp-quote allout-primary-bullet
)
1241 ;; disqualify deeper primary-bullet sequences:
1242 "[^" allout-primary-bullet
"]"))
1246 (defvar allout-mode-exposure-menu
)
1247 (defvar allout-mode-editing-menu
)
1248 (defvar allout-mode-navigation-menu
)
1249 (defvar allout-mode-misc-menu
)
1250 (defun produce-allout-mode-menubar-entries ()
1252 (easy-menu-define allout-mode-exposure-menu
1253 allout-mode-map-value
1254 "Allout outline exposure menu."
1256 ["Show Entry" allout-show-current-entry t
]
1257 ["Show Children" allout-show-children t
]
1258 ["Show Subtree" allout-show-current-subtree t
]
1259 ["Hide Subtree" allout-hide-current-subtree t
]
1260 ["Hide Leaves" allout-hide-current-leaves t
]
1262 ["Show All" allout-show-all t
]))
1263 (easy-menu-define allout-mode-editing-menu
1264 allout-mode-map-value
1265 "Allout outline editing menu."
1267 ["Open Sibling" allout-open-sibtopic t
]
1268 ["Open Subtopic" allout-open-subtopic t
]
1269 ["Open Supertopic" allout-open-supertopic t
]
1271 ["Shift Topic In" allout-shift-in t
]
1272 ["Shift Topic Out" allout-shift-out t
]
1273 ["Rebullet Topic" allout-rebullet-topic t
]
1274 ["Rebullet Heading" allout-rebullet-current-heading t
]
1275 ["Number Siblings" allout-number-siblings t
]
1277 ["Toggle Topic Encryption"
1278 allout-toggle-current-subtree-encryption
1279 (> (allout-current-depth) 1)]))
1280 (easy-menu-define allout-mode-navigation-menu
1281 allout-mode-map-value
1282 "Allout outline navigation menu."
1284 ["Next Visible Heading" allout-next-visible-heading t
]
1285 ["Previous Visible Heading"
1286 allout-previous-visible-heading t
]
1288 ["Up Level" allout-up-current-level t
]
1289 ["Forward Current Level" allout-forward-current-level t
]
1290 ["Backward Current Level"
1291 allout-backward-current-level t
]
1293 ["Beginning of Entry"
1294 allout-beginning-of-current-entry t
]
1295 ["End of Entry" allout-end-of-entry t
]
1296 ["End of Subtree" allout-end-of-current-subtree t
]))
1297 (easy-menu-define allout-mode-misc-menu
1298 allout-mode-map-value
1299 "Allout outlines miscellaneous bindings."
1301 ["Version" allout-version t
]
1303 ["Duplicate Exposed" allout-copy-exposed-to-buffer t
]
1304 ["Duplicate Exposed, numbered"
1305 allout-flatten-exposed-to-buffer t
]
1306 ["Duplicate Exposed, indented"
1307 allout-indented-exposed-to-buffer t
]
1309 ["Set Header Lead" allout-reset-header-lead t
]
1310 ["Set New Exposure" allout-expose-topic t
])))
1311 ;;;_ : Allout Modal-Variables Utilities
1312 ;;;_ = allout-mode-prior-settings
1313 (defvar allout-mode-prior-settings nil
1314 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1316 See `allout-add-resumptions' and `allout-do-resumptions'.")
1317 (make-variable-buffer-local 'allout-mode-prior-settings
)
1318 ;;;_ > allout-add-resumptions (&rest pairs)
1319 (defun allout-add-resumptions (&rest pairs
)
1320 "Set name/value PAIRS.
1322 Old settings are preserved for later resumption using `allout-do-resumptions'.
1324 The new values are set as a buffer local. On resumption, the prior buffer
1325 scope of the variable is restored along with its value. If it was a void
1326 buffer-local value, then it is left as nil on resumption.
1328 The pairs are lists whose car is the name of the variable and car of the
1329 cdr is the new value: `(some-var some-value)'. The pairs can actually be
1330 triples, where the third element qualifies the disposition of the setting,
1331 as described further below.
1333 If the optional third element is the symbol `extend', then the new value
1334 created by `cons'ing the second element of the pair onto the front of the
1337 If the optional third element is the symbol `append', then the new value is
1338 extended from the existing one by `append'ing a list containing the second
1339 element of the pair onto the end of the existing value.
1341 Extension, and resumptions in general, should not be used for hook
1342 functions -- use the `local' mode of `add-hook' for that, instead.
1344 The settings are stored on `allout-mode-prior-settings'."
1346 (let* ((pair (pop pairs
))
1349 (qualifier (if (> (length pair
) 2)
1352 (if (not (symbolp name
))
1353 (error "Pair's name, %S, must be a symbol, not %s"
1354 name
(type-of name
)))
1355 (setq prior-value
(condition-case nil
1357 (void-variable nil
)))
1358 (when (not (assoc name allout-mode-prior-settings
))
1359 ;; Not already added as a resumption, create the prior setting entry.
1360 (if (local-variable-p name
(current-buffer))
1361 ;; is already local variable -- preserve the prior value:
1362 (push (list name prior-value
) allout-mode-prior-settings
)
1363 ;; wasn't local variable, indicate so for resumption by killing
1364 ;; local value, and make it local:
1365 (push (list name
) allout-mode-prior-settings
)
1366 (make-local-variable name
)))
1368 (cond ((eq qualifier
'extend
)
1369 (if (not (listp prior-value
))
1370 (error "extension of non-list prior value attempted")
1371 (set name
(cons value prior-value
))))
1372 ((eq qualifier
'append
)
1373 (if (not (listp prior-value
))
1374 (error "appending of non-list prior value attempted")
1375 (set name
(append prior-value
(list value
)))))
1376 (t (error "unrecognized setting qualifier `%s' encountered"
1378 (set name value
)))))
1379 ;;;_ > allout-do-resumptions ()
1380 (defun allout-do-resumptions ()
1381 "Resume all name/value settings registered by `allout-add-resumptions'.
1383 This is used when concluding allout-mode, to resume selected variables to
1384 their settings before allout-mode was started."
1386 (while allout-mode-prior-settings
1387 (let* ((pair (pop allout-mode-prior-settings
))
1389 (value-cell (cdr pair
)))
1390 (if (not value-cell
)
1391 ;; Prior value was global:
1392 (kill-local-variable name
)
1393 ;; Prior value was explicit:
1394 (set name
(car value-cell
))))))
1395 ;;;_ : Mode-specific incidentals
1396 ;;;_ > allout-unprotected (expr)
1397 (defmacro allout-unprotected
(expr)
1398 "Enable internal outline operations to alter invisible text."
1399 `(let ((inhibit-read-only (if (not buffer-read-only
) t
))
1400 (inhibit-field-text-motion t
))
1402 ;;;_ = allout-mode-hook
1403 (defvar allout-mode-hook nil
1404 "Hook run when allout mode starts.")
1405 ;;;_ = allout-mode-deactivate-hook
1406 (define-obsolete-variable-alias 'allout-mode-deactivate-hook
1407 'allout-mode-off-hook
"24.1")
1408 (defvar allout-mode-deactivate-hook nil
1409 "Hook run when allout mode ends.")
1410 ;;;_ = allout-exposure-category
1411 (defvar allout-exposure-category nil
1412 "Symbol for use as allout invisible-text overlay category.")
1414 ;;;_ = allout-exposure-change-functions
1415 (define-obsolete-variable-alias 'allout-exposure-change-hook
1416 'allout-exposure-change-functions
"24.3")
1417 (defcustom allout-exposure-change-functions nil
1418 "Abnormal hook run after allout outline subtree exposure changes.
1419 It is run at the conclusion of `allout-flag-region'.
1421 Functions on the hook must take three arguments:
1423 - FROM -- integer indicating the point at the start of the change.
1424 - TO -- integer indicating the point of the end of the change.
1425 - FLAG -- change mode: nil for exposure, otherwise concealment.
1427 This hook might be invoked multiple times by a single command."
1432 ;;;_ = allout-structure-added-functions
1433 (define-obsolete-variable-alias 'allout-structure-added-hook
1434 'allout-structure-added-functions
"24.3")
1435 (defcustom allout-structure-added-functions nil
1436 "Abnormal hook run after adding items to an Allout outline.
1437 Functions on the hook should take two arguments:
1439 - NEW-START -- integer indicating position of start of the first new item.
1440 - NEW-END -- integer indicating position of end of the last new item.
1442 This hook might be invoked multiple times by a single command."
1447 ;;;_ = allout-structure-deleted-functions
1448 (define-obsolete-variable-alias 'allout-structure-deleted-hook
1449 'allout-structure-deleted-functions
"24.3")
1450 (defcustom allout-structure-deleted-functions nil
1451 "Abnormal hook run after deleting subtrees from an Allout outline.
1452 Functions on the hook must take two arguments:
1454 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1455 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1457 Some edits that remove or invalidate items may be missed by this hook:
1458 specifically edits that native allout routines do not control.
1460 This hook might be invoked multiple times by a single command."
1465 ;;;_ = allout-structure-shifted-functions
1466 (define-obsolete-variable-alias 'allout-structure-shifted-hook
1467 'allout-structure-shifted-functions
"24.3")
1468 (defcustom allout-structure-shifted-functions nil
1469 "Abnormal hook run after shifting items in an Allout outline.
1470 Functions on the hook should take two arguments:
1472 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1473 - START -- integer indicating the start point of the shifted parent item.
1475 Some edits that shift items can be missed by this hook: specifically edits
1476 that native allout routines do not control.
1478 This hook might be invoked multiple times by a single command."
1483 ;;;_ = allout-after-copy-or-kill-hook
1484 (defcustom allout-after-copy-or-kill-hook nil
1485 "Normal hook run after copying outline text.."
1490 ;;;_ = allout-post-undo-hook
1491 (defcustom allout-post-undo-hook nil
1492 "Normal hook run after undo activity.
1493 The item that's current when the hook is run *may* be the one
1494 that was affected by the undo.."
1499 ;;;_ = allout-outside-normal-auto-fill-function
1500 (defvar allout-outside-normal-auto-fill-function nil
1501 "Value of `normal-auto-fill-function' outside of allout mode.
1503 Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function'
1504 wrapped within allout's automatic `fill-prefix' setting.")
1505 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function
)
1506 ;;;_ = prevent redundant activation by desktop mode:
1507 (add-to-list 'desktop-minor-mode-handlers
'(allout-mode . nil
))
1508 ;;;_ = allout-passphrase-verifier-string
1509 (defvar allout-passphrase-verifier-string nil
1510 "Setting used to test solicited encryption passphrases against the one
1511 already associated with a file.
1513 It consists of an encrypted random string useful only to verify that a
1514 passphrase entered by the user is effective for decryption. The passphrase
1515 itself is \*not* recorded in the file anywhere, and the encrypted contents
1516 are random binary characters to avoid exposing greater susceptibility to
1519 The verifier string is retained as an Emacs file variable, as well as in
1520 the Emacs buffer state, if file variable adjustments are enabled. See
1521 `allout-enable-file-variable-adjustment' for details about that.")
1522 (make-variable-buffer-local 'allout-passphrase-verifier-string
)
1523 (make-obsolete-variable 'allout-passphrase-verifier-string
1524 'allout-passphrase-verifier-string
"23.3")
1526 (put 'allout-passphrase-verifier-string
'safe-local-variable
'stringp
)
1527 ;;;_ = allout-passphrase-hint-string
1528 (defvar allout-passphrase-hint-string
""
1529 "Variable used to retain reminder string for file's encryption passphrase.
1531 See the description of `allout-passphrase-hint-handling' for details about how
1532 the reminder is deployed.
1534 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1535 state, if file variable adjustments are enabled. See
1536 `allout-enable-file-variable-adjustment' for details about that.")
1537 (make-variable-buffer-local 'allout-passphrase-hint-string
)
1538 (setq-default allout-passphrase-hint-string
"")
1539 (make-obsolete-variable 'allout-passphrase-hint-string
1540 'allout-passphrase-hint-string
"23.3")
1542 (put 'allout-passphrase-hint-string
'safe-local-variable
'stringp
)
1543 ;;;_ = allout-after-save-decrypt
1544 (defvar allout-after-save-decrypt nil
1545 "Internal variable, is nil or has the value of two points:
1547 - the location of a topic to be decrypted after saving is done
1548 - where to situate the cursor after the decryption is performed
1550 This is used to decrypt the topic that was currently being edited, if it
1551 was encrypted automatically as part of a file write or autosave.")
1552 (make-variable-buffer-local 'allout-after-save-decrypt
)
1553 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1554 (defvar allout-encryption-plaintext-sanitization-regexps nil
1555 "List of regexps whose matches are removed from plaintext before encryption.
1557 This is for the sake of removing artifacts, like escapes, that are added on
1558 and not actually part of the original plaintext. The removal is done just
1559 prior to encryption.
1561 Entries must be symbols that are bound to the desired values.
1563 Each value can be a regexp or a list with a regexp followed by a
1564 substitution string. If it's just a regexp, all its matches are removed
1565 before the text is encrypted. If it's a regexp and a substitution, the
1566 substitution is used against the regexp matches, a la `replace-match'.")
1567 (make-variable-buffer-local 'allout-encryption-plaintext-sanitization-regexps
)
1568 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1569 (defvar allout-encryption-ciphertext-rejection-regexps nil
1570 "Variable for regexps matching plaintext to remove before encryption.
1572 This is used to detect strings in encryption results that would
1573 register as allout mode structural elements, for example, as a
1576 Entries must be symbols that are bound to the desired regexp values.
1578 Encryptions that result in matches will be retried, up to
1579 `allout-encryption-ciphertext-rejection-limit' times, after which
1580 an error is raised.")
1582 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps
)
1583 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1584 (defvar allout-encryption-ciphertext-rejection-ceiling
5
1585 "Limit on number of times encryption ciphertext is rejected.
1587 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1588 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling
)
1589 ;;;_ > allout-mode-p ()
1590 ;; Must define this macro above any uses, or byte compilation will lack
1591 ;; proper def, if file isn't loaded -- eg, during emacs build!
1593 (defmacro allout-mode-p
()
1594 "Return t if `allout-mode' is active in current buffer."
1596 ;;;_ > allout-write-contents-hook-handler ()
1597 (defun allout-write-contents-hook-handler ()
1598 "Implement `allout-encrypt-unencrypted-on-saves' for file writes
1600 Return nil if all goes smoothly, or else return an informative
1601 message if an error is encountered. The message will serve as a
1602 non-nil return on `write-contents-functions' to prevent saving of
1603 the buffer while it has decrypted content.
1605 This behavior depends on Emacs versions that implement the
1606 `write-contents-functions' hook."
1608 (if (or (not (allout-mode-p))
1609 (not (boundp 'allout-encrypt-unencrypted-on-saves
))
1610 (not allout-encrypt-unencrypted-on-saves
))
1612 (if (save-excursion (goto-char (point-min))
1613 (allout-next-topic-pending-encryption))
1615 (message "auto-encrypting pending topics")
1617 (condition-case failure
1619 (setq allout-after-save-decrypt
1620 (allout-encrypt-decrypted))
1621 ;; aok - return nil:
1624 ;; whoops - probably some still-decrypted items, return non-nil:
1625 (let ((text (format (concat "%s contents write inhibited due to"
1626 " encrypted topic encryption error:"
1628 (buffer-name (current-buffer))
1630 (message text
)(sit-for 2)
1633 ;;;_ > allout-after-saves-handler ()
1634 (defun allout-after-saves-handler ()
1635 "Decrypt topic encrypted for save, if it's currently being edited.
1637 Ie, if it was pending encryption and contained the point in its body before
1640 We use values stored in `allout-after-save-decrypt' to locate the topic
1641 and the place for the cursor after the decryption is done."
1642 (if (not (and (allout-mode-p)
1643 (boundp 'allout-after-save-decrypt
)
1644 allout-after-save-decrypt
))
1646 (goto-char (car allout-after-save-decrypt
))
1647 (let ((was-modified (buffer-modified-p)))
1648 (allout-toggle-subtree-encryption)
1649 (if (not was-modified
)
1650 (set-buffer-modified-p nil
)))
1651 (goto-char (cadr allout-after-save-decrypt
))
1652 (setq allout-after-save-decrypt nil
))
1654 ;;;_ > allout-called-interactively-p ()
1655 (defmacro allout-called-interactively-p
()
1656 "A version of `called-interactively-p' independent of Emacs version."
1657 ;; ... to ease maintenance of allout without betraying deprecation.
1658 (if (ignore-errors (called-interactively-p 'interactive
) t
)
1659 '(called-interactively-p 'interactive
)
1660 '(called-interactively-p)))
1661 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1662 ;; In some exceptional moments, disparate topic depths need to be allowed
1663 ;; momentarily, eg when one topic is being yanked into another and they're
1664 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1665 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1666 ;; processing to happen in the presence of such discrepancies. It should
1667 ;; almost never be needed, however.
1668 (defvar allout-inhibit-aberrance-doublecheck nil
1669 "Internal state, for momentarily inhibits aberrance doublecheck.
1671 This should only be momentarily let-bound non-nil, not set
1672 non-nil in a lasting way.")
1674 ;;;_ #2 Mode environment and activation
1675 ;;;_ = allout-explicitly-deactivated
1676 (defvar allout-explicitly-deactivated nil
1677 "If t, `allout-mode's last deactivation was deliberate.
1678 So `allout-post-command-business' should not reactivate it...")
1679 (make-variable-buffer-local 'allout-explicitly-deactivated
)
1680 ;;;_ > allout-init (mode)
1681 (defun allout-init (mode)
1682 "DEPRECATED - configure allout activation by customizing
1683 `allout-auto-activation'. This function remains around, limited
1684 from what it did before, for backwards compatibility.
1686 MODE is the activation mode - see `allout-auto-activation' for
1688 (declare (obsolete allout-auto-activation
"23.3"))
1689 (custom-set-variables (list 'allout-auto-activation
(format "%s" mode
)))
1692 ;;;_ > allout-setup-menubar ()
1693 (defun allout-setup-menubar ()
1694 "Populate the current buffer's menubar with `allout-mode' stuff."
1695 (let ((menus (list allout-mode-exposure-menu
1696 allout-mode-editing-menu
1697 allout-mode-navigation-menu
1698 allout-mode-misc-menu
))
1701 (setq cur
(car menus
)
1703 (easy-menu-add cur
))))
1704 ;;;_ > allout-overlay-preparations
1705 (defun allout-overlay-preparations ()
1706 "Set the properties of the allout invisible-text overlay and others."
1707 (setplist 'allout-exposure-category nil
)
1708 (put 'allout-exposure-category
'invisible
'allout
)
1709 (put 'allout-exposure-category
'evaporate t
)
1710 ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
1711 ;; latter would be sufficient, but it seems that a separate behavior --
1712 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1713 ;; presence of the isearch-open-invisible property -- even though this
1714 ;; property controls the isearch _arrival_ behavior. This is the case at
1715 ;; least in emacs 21, 22.1, and xemacs 21.4.
1716 (put 'allout-exposure-category
'isearch-open-invisible
1717 'allout-isearch-end-handler
)
1718 (if (featurep 'xemacs
)
1719 (put 'allout-exposure-category
'start-open t
)
1720 (put 'allout-exposure-category
'insert-in-front-hooks
1721 '(allout-overlay-insert-in-front-handler)))
1722 (put 'allout-exposure-category
'modification-hooks
1723 '(allout-overlay-interior-modification-handler)))
1724 ;;;_ > define-minor-mode allout-mode
1727 (define-minor-mode allout-mode
1729 "Toggle Allout outline mode.
1730 With a prefix argument ARG, enable Allout outline mode if ARG is
1731 positive, and disable it otherwise. If called from Lisp, enable
1732 the mode if ARG is omitted or nil.
1734 \\<allout-mode-map-value>
1735 Allout outline mode is a minor mode that provides extensive
1736 outline oriented formatting and manipulation. It enables
1737 structural editing of outlines, as well as navigation and
1738 exposure. It also is specifically aimed at accommodating
1739 syntax-sensitive text like programming languages. (For example,
1740 see the allout code itself, which is organized as an allout
1743 In addition to typical outline navigation and exposure, allout includes:
1745 - topic-oriented authoring, including keystroke-based topic creation,
1746 repositioning, promotion/demotion, cut, and paste
1747 - incremental search with dynamic exposure and reconcealment of hidden text
1748 - adjustable format, so programming code can be developed in outline-structure
1749 - easy topic encryption and decryption, symmetric or key-pair
1750 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1751 - integral outline layout, for automatic initial exposure when visiting a file
1752 - independent extensibility, using comprehensive exposure and authoring hooks
1754 and many other features.
1756 Below is a description of the key bindings, and then description
1757 of special `allout-mode' features and terminology. See also the
1758 outline menubar additions for quick reference to many of the
1759 features. Customize `allout-auto-activation' to prepare your
1760 Emacs session for automatic activation of `allout-mode'.
1762 The bindings are those listed in `allout-prefixed-keybindings'
1763 and `allout-unprefixed-keybindings'. We recommend customizing
1764 `allout-command-prefix' to use just `\\C-c' as the command
1765 prefix, if the allout bindings don't conflict with any personal
1766 bindings you have on \\C-c. In any case, outline structure
1767 navigation and authoring is simplified by positioning the cursor
1768 on an item's bullet character, the \"hot-spot\" -- then you can
1769 invoke allout commands with just the un-prefixed,
1770 un-control-shifted command letters. This is described further in
1771 the HOT-SPOT Operation section.
1775 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1776 \\[allout-show-children] `allout-show-children'
1777 \\[allout-show-current-subtree] `allout-show-current-subtree'
1778 \\[allout-show-current-entry] `allout-show-current-entry'
1779 \\[allout-show-all] `allout-show-all'
1783 \\[allout-next-visible-heading] `allout-next-visible-heading'
1784 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1785 \\[allout-up-current-level] `allout-up-current-level'
1786 \\[allout-forward-current-level] `allout-forward-current-level'
1787 \\[allout-backward-current-level] `allout-backward-current-level'
1788 \\[allout-end-of-entry] `allout-end-of-entry'
1789 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1790 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1791 if immediately repeated cycles to the beginning of the current item
1792 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1795 Topic Header Production:
1796 -----------------------
1797 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1798 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1799 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1801 Topic Level and Prefix Adjustment:
1802 ---------------------------------
1803 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1804 \\[allout-shift-out] `allout-shift-out' ... less deep
1805 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1807 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1808 its offspring -- distinctive bullets are not changed, others
1809 are alternated according to nesting depth.
1810 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1811 the offspring are not affected.
1812 With repeat count, revoke numbering.
1814 Topic-oriented Killing and Yanking:
1815 ----------------------------------
1816 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1817 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1818 \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure.
1819 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1820 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1821 depth of heading if yanking into bare topic
1822 heading (ie, prefix sans text).
1823 \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'.
1825 Topic-oriented Encryption:
1826 -------------------------
1827 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1828 Encrypt/Decrypt topic content
1832 M-x outlineify-sticky Activate outline mode for current buffer,
1833 and establish a default file-var setting
1834 for `allout-layout'.
1835 \\[allout-mark-topic] `allout-mark-topic'
1836 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1837 Duplicate outline, sans concealed text, to
1838 buffer with name derived from derived from that
1839 of current buffer -- \"*BUFFERNAME exposed*\".
1840 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1841 Like above `copy-exposed', but convert topic
1842 prefixes to section.subsection... numeric
1844 \\[customize-variable] allout-auto-activation
1845 Prepare Emacs session for allout outline mode
1850 Outline mode supports gpg encryption of topics, with support for
1851 symmetric and key-pair modes, and auto-encryption of topics
1852 pending encryption on save.
1854 Topics pending encryption are, by default, automatically
1855 encrypted during file saves, including checkpoint saves, to avoid
1856 exposing the plain text of encrypted topics in the file system.
1857 If the content of the topic containing the cursor was encrypted
1858 for a save, it is automatically decrypted for continued editing.
1860 NOTE: A few GnuPG v2 versions improperly preserve incorrect
1861 symmetric decryption keys, preventing entry of the correct key on
1862 subsequent decryption attempts until the cache times-out. That
1863 can take several minutes. (Decryption of other entries is not
1864 affected.) Upgrade your EasyPG version, if you can, and you can
1865 deliberately clear your gpg-agent's cache by sending it a `-HUP'
1868 See `allout-toggle-current-subtree-encryption' function docstring
1869 and `allout-encrypt-unencrypted-on-saves' customization variable
1874 Hot-spot operation provides a means for easy, single-keystroke outline
1875 navigation and exposure control.
1877 When the text cursor is positioned directly on the bullet character of
1878 a topic, regular characters (a to z) invoke the commands of the
1879 corresponding allout-mode keymap control chars. For example, \"f\"
1880 would invoke the command typically bound to \"C-c<space>C-f\"
1881 \(\\[allout-forward-current-level] `allout-forward-current-level').
1883 Thus, by positioning the cursor on a topic bullet, you can
1884 execute the outline navigation and manipulation commands with a
1885 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1886 this special translation, so you can use them to get out of the
1887 hot-spot and back to normal editing operation.
1889 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
1890 replaced with one that makes it easy to get to the hot-spot. If you
1891 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1892 is set) to the beginning of the item and then, if you hit it again
1893 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1894 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1895 at the beginning of the current entry.
1899 Allout exposure and authoring activities all have associated
1900 hooks, by which independent code can cooperate with allout
1901 without changes to the allout core. Here are key ones:
1904 `allout-mode-deactivate-hook' (deprecated)
1905 `allout-mode-off-hook'
1906 `allout-exposure-change-functions'
1907 `allout-structure-added-functions'
1908 `allout-structure-deleted-functions'
1909 `allout-structure-shifted-functions'
1910 `allout-after-copy-or-kill-hook'
1911 `allout-post-undo-hook'
1915 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1917 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1918 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1919 and with no intervening items of lower DEPTH than the container.
1921 The visible ITEM most immediately containing the cursor.
1922 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1923 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1925 LEVEL: The same as DEPTH.
1928 Those ITEMs whose TOPICs contain an ITEM.
1929 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1932 The ITEMs contained within an ITEM's TOPIC.
1934 An OFFSPRING of its ANCESTOR TOPICs.
1936 An immediate SUBTOPIC of its PARENT.
1938 TOPICs having the same PARENT and DEPTH.
1940 Topic text constituents:
1942 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1944 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1945 the HEADER text and distinct from the ITEM PREFIX.
1946 BODY: Same as ENTRY.
1947 PREFIX: The leading text of an ITEM which distinguishes it from normal
1948 ENTRY text. Allout recognizes the outline structure according
1949 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1950 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1951 number, indicating the ordinal number of the topic among its
1952 siblings, or an asterisk indicating encryption, plus an optional
1953 space. After that is the ITEM HEADER text, which is not part of
1956 The relative length of the PREFIX determines the nesting DEPTH
1959 The string at the beginning of a HEADER PREFIX, by default a `.'.
1960 It can be customized by changing the setting of
1961 `allout-header-prefix' and then reinitializing `allout-mode'.
1963 When the PREFIX-LEAD is set to the comment-string of a
1964 programming language, outline structuring can be embedded in
1965 program code without interfering with processing of the text
1966 (by Emacs or the language processor) as program code. This
1967 setting happens automatically when allout mode is used in
1968 programming-mode buffers. See `allout-use-mode-specific-leader'
1969 docstring for more detail.
1971 Spaces or asterisks which separate the PREFIX-LEAD and the
1972 bullet, determining the ITEM's DEPTH.
1973 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1974 the characters listed on `allout-plain-bullets-string' or
1975 `allout-distinctive-bullets-string'. When creating a TOPIC,
1976 plain BULLETs are by default used, according to the DEPTH of the
1977 TOPIC. Choice among the distinctive BULLETs is offered when you
1978 provide a universal argument (\\[universal-argument]) to the
1979 TOPIC creation command, or when explicitly rebulleting a TOPIC. The
1980 significance of the various distinctive bullets is purely by
1981 convention. See the documentation for the above bullet strings for
1984 The state of a TOPIC which determines the on-screen visibility
1985 of its OFFSPRING and contained ENTRY text.
1987 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1988 text is represented by \"...\" ellipses.
1990 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1991 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1992 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1995 :keymap
'allout-mode-map
1997 (let ((use-layout (if (listp allout-layout
)
1999 allout-default-layout
)))
2001 (if (not (allout-mode-p))
2005 ; Activation not explicitly
2006 ; requested, and either in
2007 ; active state or *de*activation
2008 ; specifically requested:
2009 (allout-do-resumptions)
2011 (remove-from-invisibility-spec '(allout . t
))
2012 (remove-hook 'pre-command-hook
'allout-pre-command-business t
)
2013 (remove-hook 'post-command-hook
'allout-post-command-business t
)
2014 (remove-hook 'before-change-functions
'allout-before-change-handler t
)
2015 (remove-hook 'isearch-mode-end-hook
'allout-isearch-end-handler t
)
2016 (remove-hook 'write-contents-functions
2017 'allout-write-contents-hook-handler t
)
2019 (remove-overlays (point-min) (point-max)
2020 'category
'allout-exposure-category
))
2023 (if allout-old-style-prefixes
2024 ;; Inhibit all the fancy formatting:
2025 (allout-add-resumptions '(allout-primary-bullet "*")))
2027 (allout-overlay-preparations) ; Doesn't hurt to redo this.
2029 (allout-infer-header-lead-and-primary-bullet)
2030 (allout-infer-body-reindent)
2033 (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
2034 allout-line-boundary-regexp
2036 '(allout-encryption-ciphertext-rejection-regexps
2040 (allout-compose-and-institute-keymap)
2041 (produce-allout-mode-menubar-entries)
2043 (add-to-invisibility-spec '(allout . t
))
2045 (allout-add-resumptions '(line-move-ignore-invisible t
))
2046 (add-hook 'pre-command-hook
'allout-pre-command-business nil t
)
2047 (add-hook 'post-command-hook
'allout-post-command-business nil t
)
2048 (add-hook 'before-change-functions
'allout-before-change-handler nil t
)
2049 (add-hook 'isearch-mode-end-hook
'allout-isearch-end-handler nil t
)
2050 (add-hook 'write-contents-functions
'allout-write-contents-hook-handler
2053 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2054 ;; func will be used if auto-fill is active or activated. (The
2055 ;; custom func respects topic headline, maintains hanging-indents,
2057 (allout-add-resumptions (list 'allout-former-auto-filler
2059 ;; Register allout-auto-fill to be used if
2060 ;; filling is active:
2061 (list 'allout-outside-normal-auto-fill-function
2062 normal-auto-fill-function
)
2063 '(normal-auto-fill-function allout-auto-fill
)
2064 ;; Paragraphs are broken by topic headlines.
2065 (list 'paragraph-start
2066 (concat paragraph-start
"\\|^\\("
2067 allout-regexp
"\\)"))
2068 (list 'paragraph-separate
2069 (concat paragraph-separate
"\\|^\\("
2070 allout-regexp
"\\)")))
2071 (if (and auto-fill-function
(not allout-inhibit-auto-fill
))
2072 ;; allout-auto-fill will use the stashed values and so forth.
2073 (allout-add-resumptions '(auto-fill-function allout-auto-fill
)))
2075 (allout-setup-menubar)
2077 ;; Do auto layout if warranted:
2078 (when (and allout-layout
2079 allout-auto-activation
2081 (and (not (string= allout-auto-activation
"activate"))
2082 (if (string= allout-auto-activation
"ask")
2083 (if (y-or-n-p (format-message
2084 "Expose %s with layout ‘%s’? "
2085 (buffer-name) use-layout
))
2087 (message "Skipped %s layout." (buffer-name))
2091 (message "Adjusting ‘%s’ exposure..." (buffer-name))
2093 (allout-this-or-next-heading)
2096 (apply 'allout-expose-topic
(list use-layout
))
2097 (message "Adjusting ‘%s’ exposure... done."
2099 ;; Problem applying exposure -- notify user, but don't
2100 ;; interrupt, eg, file visit:
2101 (error (message "%s" (car (cdr err
)))
2103 ) ; when allout-layout
2104 ) ; if (allout-mode-p)
2106 ) ; define-minor-mode
2107 ;;;_ > allout-minor-mode alias
2108 (defalias 'allout-minor-mode
'allout-mode
)
2109 ;;;_ > allout-unload-function
2110 (defun allout-unload-function ()
2111 "Unload the allout outline library."
2112 (save-current-buffer
2113 (dolist (buffer (buffer-list))
2115 (when (allout-mode-p) (allout-mode -
1))))
2116 ;; continue standard unloading
2119 ;;;_ - Position Assessment
2120 ;;;_ > allout-hidden-p (&optional pos)
2121 (defsubst allout-hidden-p
(&optional pos
)
2122 "Non-nil if the character after point was made invisible by allout."
2123 (eq (get-char-property (or pos
(point)) 'invisible
) 'allout
))
2125 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2126 ;;; &optional prelen)
2127 (defun allout-overlay-insert-in-front-handler (ol after beg _end
2129 "Shift the overlay so stuff inserted in front of it is excluded."
2131 ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
2132 ;; front-advance on the overlay worked as expected?
2133 (move-overlay ol
(1+ beg
) (overlay-end ol
))))
2134 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2135 ;;; &optional prelen)
2136 (defun allout-overlay-interior-modification-handler (ol after beg end
2138 "Get confirmation before making arbitrary changes to invisible text.
2140 We expose the invisible text and ask for confirmation. Refusal or
2141 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2142 reclosing the opened text.
2144 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2145 internal functions use this feature cohesively bunch changes."
2147 (when (and (not inhibit-read-only
) (not after
))
2148 (let ((start (point))
2149 (ol-start (overlay-start ol
))
2150 (ol-end (overlay-end ol
))
2153 (while (< (point) end
)
2154 (when (allout-hidden-p)
2155 (allout-show-to-offshoot)
2156 (if (allout-hidden-p)
2157 (save-excursion (forward-char 1)
2158 (allout-show-to-offshoot)))
2160 (setq first
(point))))
2161 (goto-char (if (featurep 'xemacs
)
2162 (next-property-change (1+ (point)) nil end
)
2163 (next-char-property-change (1+ (point)) end
))))
2169 (substitute-command-keys
2170 (concat "Modify concealed text? (\"no\" just aborts,"
2171 " \\[keyboard-quit] also reconceals) "))))
2172 (progn (goto-char start
)
2173 (error "Concealed-text change refused")))
2174 (quit (allout-flag-region ol-start ol-end nil
)
2175 (allout-flag-region ol-start ol-end t
)
2176 (error "Concealed-text change abandoned, text reconcealed"))))
2177 (goto-char start
))))
2178 ;;;_ > allout-before-change-handler (beg end)
2179 (defun allout-before-change-handler (beg end
)
2180 "Protect against changes to invisible text.
2182 See `allout-overlay-interior-modification-handler' for details."
2184 (when (and (allout-mode-p) undo-in-progress
)
2185 (setq allout-just-did-undo t
)
2186 (if (allout-hidden-p)
2187 (allout-show-children)))
2189 ;; allout-overlay-interior-modification-handler on an overlay handles
2190 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2191 (when (and (featurep 'xemacs
) (allout-mode-p))
2192 ;; process all of the pending overlays:
2195 (let ((overlay (allout-get-invisibility-overlay)))
2197 (allout-overlay-interior-modification-handler
2198 overlay nil beg end nil
))))))
2199 ;;;_ > allout-isearch-end-handler (&optional overlay)
2200 (defun allout-isearch-end-handler (&optional _overlay
)
2201 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2203 Optional OVERLAY parameter is for when this function is used by
2204 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2205 function can also be used as an `isearch-mode-end-hook'."
2207 (if (and (allout-mode-p) (allout-hidden-p))
2208 (allout-show-to-offshoot)))
2210 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2211 ;; All the basic outline functions that directly do string matches to
2212 ;; evaluate heading prefix location set the variables
2213 ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2214 ;; when successful. Functions starting with `allout-recent-' all
2215 ;; use this state, providing the means to avoid redundant searches
2216 ;; for just-established data. This optimization can provide
2217 ;; significant speed improvement, but it must be employed carefully.
2218 ;;;_ = allout-recent-prefix-beginning
2219 (defvar allout-recent-prefix-beginning
0
2220 "Buffer point of the start of the last topic prefix encountered.")
2221 (make-variable-buffer-local 'allout-recent-prefix-beginning
)
2222 ;;;_ = allout-recent-prefix-end
2223 (defvar allout-recent-prefix-end
0
2224 "Buffer point of the end of the last topic prefix encountered.")
2225 (make-variable-buffer-local 'allout-recent-prefix-end
)
2226 ;;;_ = allout-recent-depth
2227 (defvar allout-recent-depth
0
2228 "Depth of the last topic prefix encountered.")
2229 (make-variable-buffer-local 'allout-recent-depth
)
2230 ;;;_ = allout-recent-end-of-subtree
2231 (defvar allout-recent-end-of-subtree
0
2232 "Buffer point last returned by `allout-end-of-current-subtree'.")
2233 (make-variable-buffer-local 'allout-recent-end-of-subtree
)
2234 ;;;_ > allout-prefix-data ()
2235 (defsubst allout-prefix-data
()
2236 "Register allout-prefix state data.
2238 For reference by `allout-recent' funcs. Return
2239 the new value of `allout-recent-prefix-beginning'."
2240 (setq allout-recent-prefix-end
(or (match-end 1) (match-end 2) (match-end 3))
2241 allout-recent-prefix-beginning
(or (match-beginning 1)
2243 (match-beginning 3))
2244 allout-recent-depth
(max 1 (- allout-recent-prefix-end
2245 allout-recent-prefix-beginning
2246 allout-header-subtraction
)))
2247 allout-recent-prefix-beginning
)
2248 ;;;_ > nullify-allout-prefix-data ()
2249 (defsubst nullify-allout-prefix-data
()
2250 "Mark allout prefix data as being uninformative."
2251 (setq allout-recent-prefix-end
(point)
2252 allout-recent-prefix-beginning
(point)
2253 allout-recent-depth
0)
2254 allout-recent-prefix-beginning
)
2255 ;;;_ > allout-recent-depth ()
2256 (defsubst allout-recent-depth
()
2257 "Return depth of last heading encountered by an outline maneuvering function.
2259 All outline functions which directly do string matches to assess
2260 headings set the variables `allout-recent-prefix-beginning' and
2261 `allout-recent-prefix-end' if successful. This function uses those settings
2262 to return the current depth."
2264 allout-recent-depth
)
2265 ;;;_ > allout-recent-prefix ()
2266 (defsubst allout-recent-prefix
()
2267 "Like `allout-recent-depth', but returns text of last encountered prefix.
2269 All outline functions which directly do string matches to assess
2270 headings set the variables `allout-recent-prefix-beginning' and
2271 `allout-recent-prefix-end' if successful. This function uses those settings
2272 to return the current prefix."
2273 (buffer-substring-no-properties allout-recent-prefix-beginning
2274 allout-recent-prefix-end
))
2275 ;;;_ > allout-recent-bullet ()
2276 (defmacro allout-recent-bullet
()
2277 "Like `allout-recent-prefix', but returns bullet of last encountered prefix.
2279 All outline functions which directly do string matches to assess
2280 headings set the variables `allout-recent-prefix-beginning' and
2281 `allout-recent-prefix-end' if successful. This function uses those settings
2282 to return the current depth of the most recently matched topic."
2283 '(buffer-substring-no-properties (1- allout-recent-prefix-end
)
2284 allout-recent-prefix-end
))
2288 ;;;_ - Position Assessment
2289 ;;;_ : Location Predicates
2290 ;;;_ > allout-do-doublecheck ()
2291 (defsubst allout-do-doublecheck
()
2292 "True if current item conditions qualify for checking on topic aberrance."
2294 ;; presume integrity of outline and yanked content during yank -- necessary
2295 ;; to allow for level disparity of yank location and yanked text:
2296 (not allout-inhibit-aberrance-doublecheck
)
2297 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2298 (<= allout-recent-depth allout-doublecheck-at-and-shallower
)))
2299 ;;;_ > allout-aberrant-container-p ()
2300 (defun allout-aberrant-container-p ()
2301 "True if topic, or next sibling with children, contains them discontinuously.
2303 Discontinuous means an immediate offspring that is nested more
2304 than one level deeper than the topic.
2306 If topic has no offspring, then the next sibling with offspring will
2307 determine whether or not this one is determined to be aberrant.
2309 If true, then the allout-recent-* settings are calibrated on the
2310 offspring that qualifies it as aberrant, ie with depth that
2311 exceeds the topic by more than one."
2313 ;; This is most clearly understood when considering standard-prefix-leader
2314 ;; low-level topics, which can all too easily match text not intended as
2315 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2316 ;; following bullet qualifies without this protection. (A sequence of
2317 ;; them can occur naturally, eg a typical textual bullet list.) We
2318 ;; disqualify such low-level sequences when they are followed by a
2319 ;; discontinuously contained child, inferring that the sequences are not
2320 ;; actually connected with their prospective context.
2322 (let ((depth (allout-depth))
2323 (start-point (point))
2327 (while (and (not done
)
2328 (re-search-forward allout-line-boundary-regexp nil
0))
2329 (allout-prefix-data)
2330 (goto-char allout-recent-prefix-beginning
)
2332 ;; sibling -- continue:
2333 ((eq allout-recent-depth depth
))
2334 ;; first offspring is excessive -- aberrant:
2335 ((> allout-recent-depth
(1+ depth
))
2336 (setq done t aberrant t
))
2337 ;; next non-sibling is lower-depth -- not aberrant:
2338 (t (setq done t
))))))
2341 (goto-char start-point
)
2342 ;; recalibrate allout-recent-*
2345 ;;;_ > allout-on-current-heading-p ()
2346 (defun allout-on-current-heading-p ()
2347 "Return non-nil if point is on current visible topics' header line.
2349 Actually, returns prefix beginning point."
2351 (allout-beginning-of-current-line)
2353 (and (looking-at allout-regexp
)
2354 (allout-prefix-data)
2355 (or (not (allout-do-doublecheck))
2356 (not (allout-aberrant-container-p)))))))
2357 ;;;_ > allout-on-heading-p ()
2358 (defalias 'allout-on-heading-p
'allout-on-current-heading-p
)
2359 ;;;_ > allout-e-o-prefix-p ()
2360 (defun allout-e-o-prefix-p ()
2361 "True if point is located where current topic prefix ends, heading begins."
2362 (and (save-match-data
2363 (save-excursion (let ((inhibit-field-text-motion t
))
2364 (beginning-of-line))
2365 (looking-at allout-regexp
))
2366 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2367 ;;;_ : Location attributes
2368 ;;;_ > allout-depth ()
2369 (defun allout-depth ()
2370 "Return depth of topic most immediately containing point.
2372 Does not do doublecheck for aberrant topic header.
2374 Return zero if point is not within any topic.
2376 Like `allout-current-depth', but respects hidden as well as visible topics."
2378 (let ((start-point (point)))
2379 (if (and (allout-goto-prefix)
2380 (not (< start-point
(point))))
2383 ;; Oops, no prefix, nullify it:
2384 (nullify-allout-prefix-data)
2385 ;; ... and return 0:
2387 ;;;_ > allout-current-depth ()
2388 (defun allout-current-depth ()
2389 "Return depth of visible topic most immediately containing point.
2391 Return zero if point is not within any topic."
2393 (if (allout-back-to-current-heading)
2395 (- allout-recent-prefix-end
2396 allout-recent-prefix-beginning
2397 allout-header-subtraction
))
2399 ;;;_ > allout-get-current-prefix ()
2400 (defun allout-get-current-prefix ()
2401 "Topic prefix of the current topic."
2403 (if (allout-goto-prefix)
2404 (allout-recent-prefix))))
2405 ;;;_ > allout-get-bullet ()
2406 (defun allout-get-bullet ()
2407 "Return bullet of containing topic (visible or not)."
2409 (and (allout-goto-prefix)
2410 (allout-recent-bullet))))
2411 ;;;_ > allout-current-bullet ()
2412 (defun allout-current-bullet ()
2413 "Return bullet of current (visible) topic heading, or none if none found."
2416 (allout-back-to-current-heading)
2417 (buffer-substring-no-properties (- allout-recent-prefix-end
1)
2418 allout-recent-prefix-end
))
2419 ;; Quick and dirty provision, ostensibly for missing bullet:
2420 (args-out-of-range nil
))
2422 ;;;_ > allout-get-prefix-bullet (prefix)
2423 (defun allout-get-prefix-bullet (prefix)
2424 "Return the bullet of the header prefix string PREFIX."
2425 ;; Doesn't make sense if we're old-style prefixes, but this just
2426 ;; oughtn't be called then, so forget about it...
2427 (if (string-match allout-regexp prefix
)
2428 (substring prefix
(1- (match-end 2)) (match-end 2))))
2429 ;;;_ > allout-sibling-index (&optional depth)
2430 (defun allout-sibling-index (&optional depth
)
2431 "Item number of this prospective topic among its siblings.
2433 If optional arg DEPTH is greater than current depth, then we're
2434 opening a new level, and return 0.
2436 If less than this depth, ascend to that depth and count..."
2439 (cond ((and depth
(<= depth
0) 0))
2440 ((or (null depth
) (= depth
(allout-depth)))
2442 (while (allout-previous-sibling allout-recent-depth nil
)
2443 (setq index
(1+ index
)))
2445 ((< depth allout-recent-depth
)
2446 (allout-ascend-to-depth depth
)
2447 (allout-sibling-index))
2449 ;;;_ > allout-topic-flat-index ()
2450 (defun allout-topic-flat-index ()
2451 "Return a list indicating point's numeric section.subsect.subsubsect...
2452 Outermost is first."
2453 (let* ((depth (allout-depth))
2454 (next-index (allout-sibling-index depth
))
2456 (while (> next-index
0)
2457 (setq rev-sibls
(cons next-index rev-sibls
))
2458 (setq depth
(1- depth
))
2459 (setq next-index
(allout-sibling-index depth
)))
2463 ;;;_ - Navigation routines
2464 ;;;_ > allout-beginning-of-current-line ()
2465 (defun allout-beginning-of-current-line ()
2466 "Like beginning of line, but to visible text."
2468 ;; This combination of move-beginning-of-line and beginning-of-line is
2469 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2470 (let ((inhibit-field-text-motion t
))
2471 (move-beginning-of-line 1)
2473 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2475 (if (or (allout-hidden-p) (not (bolp)))
2476 (forward-char -
1)))))
2477 ;;;_ > allout-end-of-current-line ()
2478 (defun allout-end-of-current-line ()
2479 "Move to the end of line, past concealed text if any."
2480 ;; This is for symmetry with `allout-beginning-of-current-line' --
2481 ;; `move-end-of-line' doesn't suffer the same problem as
2482 ;; `move-beginning-of-line'.
2483 (let ((inhibit-field-text-motion t
))
2485 (while (allout-hidden-p)
2487 (if (allout-hidden-p) (forward-char 1)))))
2488 ;;;_ > allout-beginning-of-line ()
2489 (defun allout-beginning-of-line ()
2490 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2494 (if (or (not allout-beginning-of-line-cycles
)
2495 (not (equal last-command this-command
)))
2497 (if (and (not (bolp))
2498 (allout-hidden-p (1- (point))))
2499 (goto-char (allout-previous-single-char-property-change
2500 (1- (point)) 'invisible
)))
2501 (move-beginning-of-line 1))
2503 (let ((beginning-of-body
2505 (while (and (allout-do-doublecheck)
2506 (allout-aberrant-container-p)
2507 (allout-previous-visible-heading 1)))
2508 (allout-beginning-of-current-entry)
2510 (cond ((= (current-column) 0)
2511 (goto-char beginning-of-body
))
2512 ((< (point) beginning-of-body
)
2513 (allout-beginning-of-current-line))
2514 ((= (point) beginning-of-body
)
2515 (goto-char (allout-current-bullet-pos)))
2516 (t (allout-beginning-of-current-line)
2517 (if (< (point) beginning-of-body
)
2518 ;; we were on the headline after its start:
2519 (goto-char beginning-of-body
)))))))
2520 ;;;_ > allout-end-of-line ()
2521 (defun allout-end-of-line ()
2522 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2526 (if (or (not allout-end-of-line-cycles
)
2527 (not (equal last-command this-command
)))
2528 (allout-end-of-current-line)
2529 (let ((end-of-entry (save-excursion
2530 (allout-end-of-entry)
2533 (allout-end-of-current-line))
2534 ((or (allout-hidden-p) (save-excursion
2537 (allout-back-to-current-heading)
2538 (allout-show-current-entry)
2539 (allout-show-children)
2540 (allout-end-of-entry))
2541 ((>= (point) end-of-entry
)
2542 (allout-back-to-current-heading)
2543 (allout-end-of-current-line))
2545 (if (not (allout-mark-active-p))
2547 (allout-end-of-entry))))))
2548 ;;;_ > allout-mark-active-p ()
2549 (defun allout-mark-active-p ()
2550 "True if the mark is currently or always active."
2551 ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
2552 ;; provisions, at least in GNU Emacs to prevent warnings about lack of,
2553 ;; eg, region-active-p.
2554 (cond ((boundp 'mark-active
)
2556 ((fboundp 'region-active-p
)
2559 ;;;_ > allout-next-heading ()
2560 (defsubst allout-next-heading
()
2561 "Move to the heading for the topic (possibly invisible) after this one.
2563 Returns the location of the heading, or nil if none found.
2565 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2568 (if (looking-at allout-regexp
)
2571 (when (re-search-forward allout-line-boundary-regexp nil
0)
2572 (allout-prefix-data)
2573 (goto-char allout-recent-prefix-beginning
)
2576 (and (allout-do-doublecheck)
2577 ;; this will set allout-recent-* on the first non-aberrant topic,
2578 ;; whether it's the current one or one that disqualifies it:
2579 (allout-aberrant-container-p))
2580 ;; this may or may not be the same as above depending on doublecheck:
2581 (goto-char allout-recent-prefix-beginning
))))
2582 ;;;_ > allout-this-or-next-heading
2583 (defun allout-this-or-next-heading ()
2584 "Position cursor on current or next heading."
2585 ;; A throwaway non-macro that is defined after allout-next-heading
2586 ;; and usable by allout-mode.
2587 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2588 ;;;_ > allout-previous-heading ()
2589 (defun allout-previous-heading ()
2590 "Move to the prior (possibly invisible) heading line.
2592 Return the location of the beginning of the heading, or nil if not found.
2594 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2598 (let ((start-point (point)))
2599 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2600 (allout-goto-prefix)
2602 (when (or (re-search-backward allout-line-boundary-regexp nil
0)
2603 (looking-at allout-bob-regexp
))
2604 (goto-char (allout-prefix-data))
2605 (if (and (allout-do-doublecheck)
2606 (allout-aberrant-container-p))
2607 (or (allout-previous-heading)
2608 (and (goto-char start-point
)
2609 ;; recalibrate allout-recent-*:
2613 ;;;_ > allout-get-invisibility-overlay ()
2614 (defun allout-get-invisibility-overlay ()
2615 "Return the overlay at point that dictates allout invisibility."
2616 (let ((overlays (overlays-at (point)))
2618 (while (and overlays
(not got
))
2619 (if (equal (overlay-get (car overlays
) 'invisible
) 'allout
)
2620 (setq got
(car overlays
))
2623 ;;;_ > allout-back-to-visible-text ()
2624 (defun allout-back-to-visible-text ()
2625 "Move to most recent prior character that is visible, and return point."
2626 (if (allout-hidden-p)
2627 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2630 ;;;_ - Subtree Charting
2631 ;;;_ " These routines either produce or assess charts, which are
2632 ;;; nested lists of the locations of topics within a subtree.
2634 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2635 ;;; for elaborate, compound assessment and adjustment of a subtree.
2637 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2638 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth
)
2639 "Produce a location \"chart\" of subtopics of the containing topic.
2641 Optional argument LEVELS specifies a depth limit (relative to start
2642 depth) for the chart. Null LEVELS means no limit.
2644 When optional argument VISIBLE is non-nil, the chart includes
2645 only the visible subelements of the charted subjects.
2647 The remaining optional args are for internal use by the function.
2649 Point is left at the end of the subtree.
2651 Charts are used to capture outline structure, so that outline-altering
2652 routines need to assess the structure only once, and then use the chart
2653 for their elaborate manipulations.
2655 The chart entries for the topics are in reverse order, so the
2656 last topic is listed first. The entry for each topic consists of
2657 an integer indicating the point at the beginning of the topic
2658 prefix. Charts for offspring consist of a list containing,
2659 recursively, the charts for the respective subtopics. The chart
2660 for a topics' offspring precedes the entry for the topic itself.
2662 The other function parameters are for internal recursion, and should
2663 not be specified by external callers. ORIG-DEPTH is depth of topic at
2664 starting point, and PREV-DEPTH is depth of prior topic."
2666 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
2669 (if original
; Just starting?
2670 ; Register initial settings and
2671 ; position to first offspring:
2672 (progn (setq orig-depth
(allout-depth))
2673 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
2675 (allout-next-visible-heading 1)
2676 (allout-next-heading))))
2678 ;; Loop over the current levels' siblings. Besides being more
2679 ;; efficient than tail-recursing over a level, it avoids exceeding
2680 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2682 ;; Probably would speed things up to implement loop-based stack
2683 ;; operation rather than recursing for lower levels. Bah.
2685 (while (and (not (eobp))
2686 ; Still within original topic?
2687 (< orig-depth
(setq curr-depth allout-recent-depth
))
2688 (cond ((= prev-depth curr-depth
)
2689 ;; Register this one and move on:
2690 (setq chart
(cons allout-recent-prefix-beginning chart
))
2691 (if (and levels
(<= levels
1))
2692 ;; At depth limit -- skip sublevels:
2693 (or (allout-next-sibling curr-depth
)
2694 ;; or no more siblings -- proceed to
2695 ;; next heading at lesser depth:
2696 (while (and (<= curr-depth
2697 allout-recent-depth
)
2699 (allout-next-visible-heading 1)
2700 (allout-next-heading)))))
2702 (allout-next-visible-heading 1)
2703 (allout-next-heading))))
2705 ((and (< prev-depth curr-depth
)
2708 ;; Recurse on deeper level of curr topic:
2710 (cons (allout-chart-subtree (and levels
2716 ;; ... then continue with this one.
2719 ;; ... else nil if we've ascended back to prev-depth.
2723 (if original
; We're at the last sibling on
2724 ; the original level. Position
2726 (progn (and (not (eobp)) (forward-char -
1))
2727 (and (= (preceding-char) ?
\n)
2728 (= (aref (buffer-substring (max 1 (- (point) 3))
2733 (setq allout-recent-end-of-subtree
(point))))
2735 chart
; (nreverse chart) not necessary,
2736 ; and maybe not preferable.
2738 ;;;_ > allout-chart-siblings (&optional start end)
2739 (defun allout-chart-siblings (&optional _start _end
)
2740 "Produce a list of locations of this and succeeding sibling topics.
2741 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2742 for an explanation of charts."
2744 (when (allout-goto-prefix-doublechecked)
2745 (let ((chart (list (point))))
2746 (while (allout-next-sibling)
2747 (setq chart
(cons (point) chart
)))
2748 (if chart
(setq chart
(nreverse chart
)))))))
2749 ;;;_ > allout-chart-to-reveal (chart depth)
2750 (defun allout-chart-to-reveal (chart depth
)
2752 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2754 If DEPTH is nil, include hidden points at any depth.
2756 Note that point can be left at any of the points on chart, or at the
2760 (while (and (or (null depth
) (> depth
0))
2762 (setq here
(car chart
))
2764 (let ((further (allout-chart-to-reveal here
(if (null depth
)
2767 ;; We're on the start of a subtree -- recurse with it, if there's
2768 ;; more depth to go:
2769 (if further
(setq result
(append further result
)))
2770 (setq chart
(cdr chart
)))
2772 (if (allout-hidden-p)
2773 (setq result
(cons here result
)))
2774 (setq chart
(cdr chart
))))
2776 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2777 ;; (defun allout-chart-spec (chart spec &optional exposing)
2778 ;; "Not yet (if ever) implemented.
2780 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2782 ;; Exposure spec indicates the locations to be exposed and the prescribed
2783 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2784 ;; indicating pending concealment, anything higher indicating depth to
2785 ;; which subtopic headers should be exposed, and negative numbers
2786 ;; indicating (negative of) the depth to which subtopic headers and
2787 ;; bodies should be exposed.
2789 ;; The produced list can have two types of entries. Bare numbers
2790 ;; indicate points in the buffer where topic headers that should be
2793 ;; - bare negative numbers indicates that the topic starting at the
2794 ;; point which is the negative of the number should be opened,
2795 ;; including their entries.
2796 ;; - bare positive values indicate that this topic header should be
2798 ;; - Lists signify the beginning and end points of regions that should
2799 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2802 ;; (cond ((listp spec)
2805 ;; (setq spec (cdr spec)))
2809 ;;;_ > allout-goto-prefix ()
2810 (defun allout-goto-prefix ()
2811 "Put point at beginning of immediately containing outline topic.
2813 Goes to most immediate subsequent topic if none immediately containing.
2815 Not sensitive to topic visibility.
2817 Returns the point at the beginning of the prefix, or nil if none."
2821 (while (and (not done
)
2822 (search-backward "\n" nil
1))
2824 (if (looking-at allout-regexp
)
2825 (setq done
(allout-prefix-data))
2828 (cond ((looking-at allout-regexp
)
2829 (allout-prefix-data))
2830 ((allout-next-heading))
2833 ;;;_ > allout-goto-prefix-doublechecked ()
2834 (defun allout-goto-prefix-doublechecked ()
2835 "Put point at beginning of immediately containing outline topic.
2837 Like `allout-goto-prefix', but shallow topics (according to
2838 `allout-doublecheck-at-and-shallower') are checked and
2839 disqualified for child containment discontinuity, according to
2840 `allout-aberrant-container-p'."
2841 (if (allout-goto-prefix)
2842 (if (and (allout-do-doublecheck)
2843 (allout-aberrant-container-p))
2844 (allout-previous-heading)
2847 ;;;_ > allout-end-of-prefix ()
2848 (defun allout-end-of-prefix (&optional ignore-decorations
)
2849 "Position cursor at beginning of header text.
2851 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2852 otherwise skip white space between bullet and ensuing text."
2854 (if (not (allout-goto-prefix-doublechecked))
2856 (goto-char allout-recent-prefix-end
)
2858 (if ignore-decorations
2860 (while (looking-at "[0-9]") (forward-char 1))
2861 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2862 ;; Reestablish where we are:
2863 (allout-current-depth)))
2864 ;;;_ > allout-current-bullet-pos ()
2865 (defun allout-current-bullet-pos ()
2866 "Return position of current (visible) topic's bullet."
2868 (if (not (allout-current-depth))
2870 (1- allout-recent-prefix-end
)))
2871 ;;;_ > allout-back-to-current-heading (&optional interactive)
2872 (defun allout-back-to-current-heading (&optional interactive
)
2873 "Move to heading line of current topic, or beginning if not in a topic.
2875 If interactive, we position at the end of the prefix.
2877 Return value of resulting point, unless we started outside
2878 of (before any) topics, in which case we return nil."
2882 (allout-beginning-of-current-line)
2883 (let ((bol-point (point)))
2884 (when (allout-goto-prefix-doublechecked)
2885 (if (<= (point) bol-point
)
2887 (setq bol-point
(point))
2888 (allout-beginning-of-current-line)
2889 (if (not (= bol-point
(point)))
2890 (if (looking-at allout-regexp
)
2891 (allout-prefix-data)))
2893 (allout-end-of-prefix)
2895 (goto-char (point-min))
2897 ;;;_ > allout-back-to-heading ()
2898 (defalias 'allout-back-to-heading
'allout-back-to-current-heading
)
2899 ;;;_ > allout-pre-next-prefix ()
2900 (defun allout-pre-next-prefix ()
2901 "Skip forward to just before the next heading line.
2903 Returns that character position."
2905 (if (allout-next-heading)
2906 (goto-char (1- allout-recent-prefix-beginning
))))
2907 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2908 (defun allout-end-of-subtree (&optional current include-trailing-blank
)
2909 "Put point at the end of the last leaf in the containing topic.
2911 Optional CURRENT means put point at the end of the containing
2914 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2915 any, as part of the subtree. Otherwise, that trailing blank will be
2916 excluded as delimiting whitespace between topics.
2918 Returns the value of point."
2921 (allout-back-to-current-heading)
2922 (allout-goto-prefix-doublechecked))
2923 (let ((level allout-recent-depth
))
2924 (allout-next-heading)
2925 (while (and (not (eobp))
2926 (> allout-recent-depth level
))
2927 (allout-next-heading))
2929 (allout-end-of-entry)
2931 (if (and (not include-trailing-blank
) (= ?
\n (preceding-char)))
2933 (setq allout-recent-end-of-subtree
(point))))
2934 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2935 (defun allout-end-of-current-subtree (&optional include-trailing-blank
)
2937 "Put point at end of last leaf in currently visible containing topic.
2939 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2940 any, as part of the subtree. Otherwise, that trailing blank will be
2941 excluded as delimiting whitespace between topics.
2943 Returns the value of point."
2945 (allout-end-of-subtree t include-trailing-blank
))
2946 ;;;_ > allout-beginning-of-current-entry (&optional interactive)
2947 (defun allout-beginning-of-current-entry (&optional interactive
)
2948 "When not already there, position point at beginning of current topic header.
2950 If already there, move cursor to bullet for hot-spot operation.
2951 \(See `allout-mode' doc string for details of hot-spot operation.)"
2953 (let ((start-point (point)))
2954 (move-beginning-of-line 1)
2955 (if (< 0 (allout-current-depth))
2956 (goto-char allout-recent-prefix-end
)
2957 (goto-char (point-min)))
2958 (allout-end-of-prefix)
2959 (if (and interactive
2960 (= (point) start-point
))
2961 (goto-char (allout-current-bullet-pos)))))
2962 ;;;_ > allout-end-of-entry (&optional inclusive)
2963 (defun allout-end-of-entry (&optional inclusive
)
2964 "Position the point at the end of the current topics' entry.
2966 Optional INCLUSIVE means also include trailing empty line, if any. When
2967 unset, whitespace between items separates them even when the items are
2970 (allout-pre-next-prefix)
2971 (if (and (not inclusive
) (not (bobp)) (= ?
\n (preceding-char)))
2974 ;;;_ > allout-end-of-current-heading ()
2975 (defun allout-end-of-current-heading ()
2977 (allout-beginning-of-current-entry)
2978 (search-forward "\n" nil t
)
2980 (defalias 'allout-end-of-heading
'allout-end-of-current-heading
)
2981 ;;;_ > allout-get-body-text ()
2982 (defun allout-get-body-text ()
2983 "Return the unmangled body text of the topic immediately containing point."
2985 (allout-end-of-prefix)
2986 (if (not (search-forward "\n" nil t
))
2989 (let ((pre-body (point)))
2992 (allout-end-of-entry t
)
2993 (if (not (= pre-body
(point)))
2994 (buffer-substring-no-properties (1+ pre-body
) (point))))
3001 ;;;_ > allout-ascend-to-depth (depth)
3002 (defun allout-ascend-to-depth (depth)
3003 "Ascend to depth DEPTH, returning depth if successful, nil if not."
3004 (if (and (> depth
0)(<= depth
(allout-depth)))
3005 (let (last-ascended)
3006 (while (and (< depth allout-recent-depth
)
3007 (setq last-ascended
(allout-ascend))))
3008 (goto-char allout-recent-prefix-beginning
)
3009 (if (allout-called-interactively-p) (allout-end-of-prefix))
3010 (and last-ascended allout-recent-depth
))))
3011 ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
3012 (defun allout-ascend (&optional dont-move-if-unsuccessful
)
3013 "Ascend one level, returning resulting depth if successful, nil if not.
3015 Point is left at the beginning of the level whether or not
3016 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
3017 which case point is returned to its original starting location."
3018 (if dont-move-if-unsuccessful
3019 (setq dont-move-if-unsuccessful
(point)))
3021 (if (allout-beginning-of-level)
3022 (let ((bolevel (point))
3023 (bolevel-depth allout-recent-depth
))
3024 (allout-previous-heading)
3025 (cond ((< allout-recent-depth bolevel-depth
)
3026 allout-recent-depth
)
3027 ((= allout-recent-depth bolevel-depth
)
3028 (if dont-move-if-unsuccessful
3029 (goto-char dont-move-if-unsuccessful
))
3033 ;; some topic after very first is lower depth than first:
3037 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3038 ;;;_ > allout-descend-to-depth (depth)
3039 (defun allout-descend-to-depth (depth)
3040 "Descend to depth DEPTH within current topic.
3042 Returning depth if successful, nil if not."
3043 (let ((start-point (point))
3044 (start-depth (allout-depth)))
3046 (and (> (allout-depth) 0)
3047 (not (= depth allout-recent-depth
)) ; ... not there yet
3048 (allout-next-heading) ; ... go further
3049 (< start-depth allout-recent-depth
))) ; ... still in topic
3050 (if (and (> (allout-depth) 0)
3051 (= allout-recent-depth depth
))
3053 (goto-char start-point
)
3056 ;;;_ > allout-up-current-level (arg)
3057 (defun allout-up-current-level (_arg)
3058 "Move out ARG levels from current visible topic."
3060 (let ((start-point (point)))
3061 (allout-back-to-current-heading)
3062 (if (not (allout-ascend))
3063 (progn (goto-char start-point
)
3064 (error "Can't ascend past outermost level"))
3065 (if (allout-called-interactively-p) (allout-end-of-prefix))
3066 allout-recent-prefix-beginning
)))
3069 ;;;_ > allout-next-sibling (&optional depth backward)
3070 (defun allout-next-sibling (&optional depth backward
)
3071 "Like `allout-forward-current-level', but respects invisible topics.
3073 Traverse at optional DEPTH, or current depth if none specified.
3075 Go backward if optional arg BACKWARD is non-nil.
3077 Return the start point of the new topic if successful, nil otherwise."
3079 (if (if backward
(bobp) (eobp))
3081 (let ((target-depth (or depth
(allout-depth)))
3082 (start-point (point))
3083 (start-prefix-beginning allout-recent-prefix-beginning
)
3088 ;; done too few single steps to resort to the leap routine:
3091 (not (if backward
(bobp) (eobp)))
3092 ;; still traversable:
3093 (if backward
(allout-previous-heading) (allout-next-heading))
3094 ;; we're below the target depth
3095 (> (setq last-depth allout-recent-depth
) target-depth
))
3096 (setq count
(1+ count
))
3097 (if (> count
7) ; lists are commonly 7 +- 2, right?-)
3100 (or (allout-next-sibling-leap target-depth backward
)
3102 (goto-char start-point
)
3103 (if depth
(allout-depth) target-depth
)
3106 (and (> (or last-depth
(allout-depth)) 0)
3107 (= allout-recent-depth target-depth
))
3108 (not (= start-prefix-beginning
3109 allout-recent-prefix-beginning
)))
3110 allout-recent-prefix-beginning
)
3112 (goto-char start-point
)
3113 (if depth
(allout-depth) target-depth
)
3115 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3116 (defun allout-next-sibling-leap (&optional depth backward
)
3117 "Like `allout-next-sibling', but by direct search for topic at depth.
3119 Traverse at optional DEPTH, or current depth if none specified.
3121 Go backward if optional arg BACKWARD is non-nil.
3123 Return the start point of the new topic if successful, nil otherwise.
3125 Costs more than regular `allout-next-sibling' for short traversals:
3127 - we have to check the prior (next, if traveling backwards)
3128 item to confirm connectivity with the prior topic, and
3129 - if confirmed, we have to reestablish the allout-recent-* settings with
3130 some extra navigation
3131 - if confirmation fails, we have to do more work to recover
3133 It is an increasingly big win when there are many intervening
3134 offspring before the next sibling, however, so
3135 `allout-next-sibling' resorts to this if it finds itself in that
3138 (if (if backward
(bobp) (eobp))
3140 (let* ((start-point (point))
3141 (target-depth (or depth
(allout-depth)))
3142 (search-whitespace-regexp nil
)
3143 (depth-biased (- target-depth
2))
3144 (expression (if (<= target-depth
1)
3145 allout-depth-one-regexp
3146 (format allout-depth-specific-regexp
3147 depth-biased depth-biased
)))
3151 (setq found
(save-match-data
3153 (re-search-backward expression nil
'to-limit
)
3155 (re-search-forward expression nil
'to-limit
))))
3156 (if (and found
(allout-aberrant-container-p))
3158 (setq done
(or found
(if backward
(bobp) (eobp)))))
3160 (progn (goto-char start-point
)
3162 ;; rationale: if any intervening items were at a lower depth, we
3163 ;; would now be on the first offspring at the target depth -- ie,
3164 ;; the preceding item (per the search direction) must be at a
3165 ;; lesser depth. that's all we need to check.
3166 (if backward
(allout-next-heading) (allout-previous-heading))
3167 (if (< allout-recent-depth target-depth
)
3168 ;; return to start and reestablish allout-recent-*:
3170 (goto-char start-point
)
3174 ;; locate cursor and set allout-recent-*:
3175 (allout-goto-prefix))))))
3176 ;;;_ > allout-previous-sibling (&optional depth backward)
3177 (defun allout-previous-sibling (&optional depth backward
)
3178 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3180 Optional DEPTH specifies depth to traverse, default current depth.
3182 Optional BACKWARD reverses direction.
3184 Return depth if successful, nil otherwise."
3185 (allout-next-sibling depth
(not backward
))
3187 ;;;_ > allout-snug-back ()
3188 (defun allout-snug-back ()
3189 "Position cursor at end of previous topic.
3191 Presumes point is at the start of a topic prefix."
3192 (if (or (bobp) (eobp))
3195 (if (or (bobp) (not (= ?
\n (preceding-char))))
3199 ;;;_ > allout-beginning-of-level ()
3200 (defun allout-beginning-of-level ()
3201 "Go back to the first sibling at this level, visible or not."
3202 (allout-end-of-level 'backward
))
3203 ;;;_ > allout-end-of-level (&optional backward)
3204 (defun allout-end-of-level (&optional _backward
)
3205 "Go to the last sibling at this level, visible or not."
3207 (let ((depth (allout-depth)))
3208 (while (allout-previous-sibling depth nil
))
3209 (prog1 allout-recent-depth
3210 (if (allout-called-interactively-p) (allout-end-of-prefix)))))
3211 ;;;_ > allout-next-visible-heading (arg)
3212 (defun allout-next-visible-heading (arg)
3213 "Move to the next ARGth visible heading line, backward if ARG is negative.
3215 Move to buffer limit in indicated direction if headings are exhausted."
3218 (let* ((inhibit-field-text-motion t
)
3219 (backward (if (< arg
0) (setq arg
(* -
1 arg
))))
3220 (step (if backward -
1 1))
3221 (progress (allout-current-bullet-pos))
3226 ;; Boundary condition:
3227 (not (if backward
(bobp)(eobp)))
3228 ;; Move, skipping over all concealed lines in one fell swoop:
3229 (prog1 (condition-case nil
(or (line-move step
) t
)
3231 (allout-beginning-of-current-line)
3232 ;; line-move can wind up on the same line if long.
3233 ;; when moving forward, that would yield no-progress
3234 (when (and (not backward
)
3235 (<= (point) progress
))
3236 ;; ensure progress by doing line-move from end-of-line:
3238 (condition-case nil
(or (line-move step
) t
)
3240 (allout-beginning-of-current-line)
3241 (setq progress
(point))))
3242 ;; Deal with apparent header line:
3244 (if (not (looking-at allout-regexp
))
3245 ;; not a header line, keep looking:
3247 (allout-prefix-data)
3248 (if (and (allout-do-doublecheck)
3249 (allout-aberrant-container-p))
3250 ;; skip this aberrant prospective header line:
3252 ;; this prospective headerline qualifies -- register:
3253 (setq got allout-recent-prefix-beginning
)
3254 ;; and break the loop:
3256 ;; Register this got, it may be the last:
3257 (if got
(setq prev got
))
3258 (setq arg
(1- arg
)))
3259 (cond (got ; Last move was to a prefix:
3260 (allout-end-of-prefix))
3261 (prev ; Last move wasn't, but prev was:
3263 (allout-end-of-prefix))
3264 ((not backward
) (end-of-line) nil
))))
3265 ;;;_ > allout-previous-visible-heading (arg)
3266 (defun allout-previous-visible-heading (arg)
3267 "Move to the previous heading line.
3269 With argument, repeats or can move forward if negative.
3270 A heading line is one that starts with a `*' (or that `allout-regexp'
3273 (prog1 (allout-next-visible-heading (- arg
))
3274 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3275 ;;;_ > allout-forward-current-level (arg)
3276 (defun allout-forward-current-level (arg)
3277 "Position point at the next heading of the same level.
3279 Takes optional repeat-count, goes backward if count is negative.
3281 Returns resulting position, else nil if none found."
3283 (let ((start-depth (allout-current-depth))
3285 (backward (> 0 arg
)))
3286 (if (= 0 start-depth
)
3287 (error "No siblings, not in a topic..."))
3288 (if backward
(setq arg
(* -
1 arg
)))
3289 (allout-back-to-current-heading)
3290 (while (and (not (zerop arg
))
3292 (allout-previous-sibling)
3293 (allout-next-sibling)))
3294 (setq arg
(1- arg
)))
3295 (if (not (allout-called-interactively-p))
3297 (allout-end-of-prefix)
3298 (if (not (zerop arg
))
3299 (error "Hit %s level %d topic, traversed %d of %d requested"
3300 (if backward
"first" "last")
3302 (- (abs start-arg
) arg
)
3303 (abs start-arg
))))))
3304 ;;;_ > allout-backward-current-level (arg)
3305 (defun allout-backward-current-level (arg)
3306 "Inverse of `allout-forward-current-level'."
3308 (if (allout-called-interactively-p)
3309 (let ((current-prefix-arg (* -
1 arg
)))
3310 (call-interactively 'allout-forward-current-level
))
3311 (allout-forward-current-level (* -
1 arg
))))
3316 ;;;_ = allout-post-goto-bullet
3317 (defvar allout-post-goto-bullet nil
3318 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3320 When set, tells post-processing to reposition on topic bullet, and
3321 then unset it. Set by `allout-pre-command-business' when implementing
3322 hot-spot operation, where literal characters typed over a topic bullet
3323 are mapped to the command of the corresponding control-key on the
3324 `allout-mode-map-value'.")
3325 (make-variable-buffer-local 'allout-post-goto-bullet
)
3326 ;;;_ = allout-command-counter
3327 (defvar allout-command-counter
0
3328 "Counter that monotonically increases in allout-mode buffers.
3330 Set by `allout-pre-command-business', to support allout addons in
3331 coordinating with allout activity.")
3332 (make-variable-buffer-local 'allout-command-counter
)
3333 ;;;_ = allout-this-command-hid-text
3334 (defvar allout-this-command-hid-text nil
3335 "True if the most recent allout-mode command hid any text.")
3336 (make-variable-buffer-local 'allout-this-command-hid-text
)
3337 ;;;_ > allout-post-command-business ()
3338 (defun allout-post-command-business ()
3339 "Outline `post-command-hook' function.
3341 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3344 - Move the cursor to the beginning of the entry if it is hidden
3345 and collapsing activity just happened.
3347 - If the command we're following was an undo, check for change in
3348 the status of encrypted items and adjust auto-save inhibitions
3351 - Decrypt topic currently being edited if it was encrypted for a save."
3353 (if (not (allout-mode-p)) ; In allout-mode.
3356 (when allout-just-did-undo
3357 (setq allout-just-did-undo nil
)
3358 (run-hooks 'allout-post-undo-hook
)
3359 (cond ((and (= buffer-saved-size -
1)
3360 allout-auto-save-temporarily-disabled
)
3361 ;; user possibly undid a decryption, disinhibit auto-save:
3362 (allout-maybe-resume-auto-save-info-after-encryption))
3366 (goto-char (point-min))
3367 (not (allout-next-topic-pending-encryption))))
3368 ;; plain-text encrypted items are present, inhibit auto-save:
3369 (allout-inhibit-auto-save-info-for-decryption (buffer-size)))))
3371 (if (and (boundp 'allout-after-save-decrypt
)
3372 allout-after-save-decrypt
)
3373 (allout-after-saves-handler))
3375 ;; Implement allout-post-goto-bullet, if set:
3376 (if (and allout-post-goto-bullet
3377 (allout-current-bullet-pos))
3378 (progn (goto-char (allout-current-bullet-pos))
3379 (setq allout-post-goto-bullet nil
))
3380 (when (and (allout-hidden-p) allout-this-command-hid-text
)
3381 (allout-beginning-of-current-entry)))))
3382 ;;;_ > allout-pre-command-business ()
3383 (defun allout-pre-command-business ()
3384 "Outline `pre-command-hook' function for outline buffers.
3386 Among other things, implements special behavior when the cursor is on the
3387 topic bullet character.
3389 When the cursor is on the bullet character, self-insert
3390 characters are reinterpreted as the corresponding
3391 control-character in the `allout-mode-map-value'. The
3392 `allout-mode' `post-command-hook' insures that the cursor which
3393 has moved as a result of such reinterpretation is positioned on
3394 the bullet character of the destination topic.
3396 The upshot is that you can get easy, single (ie, unmodified) key
3397 outline maneuvering operations by positioning the cursor on the bullet
3398 char. When in this mode you can use regular cursor-positioning
3399 command/keystrokes to relocate the cursor off of a bullet character to
3400 return to regular interpretation of self-insert characters."
3402 (if (not (allout-mode-p))
3404 (setq allout-command-counter
(1+ allout-command-counter
))
3405 (setq allout-this-command-hid-text nil
)
3406 ;; Do hot-spot navigation.
3407 (if (and (eq this-command
'self-insert-command
)
3408 (eq (point)(allout-current-bullet-pos)))
3409 (allout-hotspot-key-handler))))
3410 ;;;_ > allout-hotspot-key-handler ()
3411 (defun allout-hotspot-key-handler ()
3412 "Catchall handling of key bindings in hot-spots.
3414 Translates unmodified keystrokes to corresponding allout commands, when
3415 they would qualify if prefixed with the `allout-command-prefix', and sets
3416 `this-command' accordingly.
3418 Returns the qualifying command, if any, else nil."
3420 (let* ((modified (event-modifiers last-command-event
))
3421 (key-num (cond ((numberp last-command-event
) last-command-event
)
3422 ;; for XEmacs character type:
3423 ((and (fboundp 'characterp
)
3424 (apply 'characterp
(list last-command-event
)))
3425 (apply 'char-to-int
(list last-command-event
)))
3433 ;; exclude control chars and escape:
3436 (setq mapped-binding
3438 ;; try control-modified versions of keys:
3439 (key-binding (vconcat allout-command-prefix
3441 (if (and (<= 97 key-num
) ; "a"
3442 (>= 122 key-num
)) ; "z"
3443 (- key-num
96) key-num
)))
3445 ;; try non-modified versions of keys:
3446 (key-binding (vconcat allout-command-prefix
3449 ;; Qualified as an allout command -- do hot-spot operation.
3450 (setq allout-post-goto-bullet t
)
3451 ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
3452 (setq mapped-binding
(key-binding (vector key-num
))))
3454 (while (keymapp mapped-binding
)
3455 (setq mapped-binding
3456 (lookup-key mapped-binding
(vector (read-char)))))
3458 (when mapped-binding
3459 (setq this-command mapped-binding
)))))
3461 ;;;_ > allout-find-file-hook ()
3462 (defun allout-find-file-hook ()
3463 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3465 See `allout-auto-activation' for setup instructions."
3466 (if (and allout-auto-activation
3467 (not (allout-mode-p))
3471 ;;;_ - Topic Format Assessment
3472 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3473 (defun allout-solicit-alternate-bullet (depth &optional current-bullet
)
3475 "Prompt for and return a bullet char as an alternative to the current one.
3477 Offer one suitable for current depth DEPTH as default."
3479 (let* ((default-bullet (or (and (stringp current-bullet
) current-bullet
)
3480 (allout-bullet-for-depth depth
)))
3481 (sans-escapes (regexp-sans-escapes allout-bullets-string
))
3484 (goto-char (allout-current-bullet-pos))
3485 (setq choice
(solicit-char-in-string
3487 "Select bullet: %s (‘%s’ default): "
3489 (allout-substring-no-properties default-bullet
))
3493 (if (string= choice
"") default-bullet choice
))
3495 ;;;_ > allout-distinctive-bullet (bullet)
3496 (defun allout-distinctive-bullet (bullet)
3497 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3498 (string-match (regexp-quote bullet
) allout-distinctive-bullets-string
))
3499 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3500 (defun allout-numbered-type-prefix (&optional prefix
)
3501 "True if current header prefix bullet is numbered bullet."
3502 (and allout-numbered-bullet
3503 (string= allout-numbered-bullet
3505 (allout-get-prefix-bullet prefix
)
3506 (allout-get-bullet)))))
3507 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3508 (defun allout-encrypted-type-prefix (&optional prefix
)
3509 "True if current header prefix bullet is for an encrypted entry (body)."
3510 (and allout-topic-encryption-bullet
3511 (string= allout-topic-encryption-bullet
3513 (allout-get-prefix-bullet prefix
)
3514 (allout-get-bullet)))))
3515 ;;;_ > allout-bullet-for-depth (&optional depth)
3516 (defun allout-bullet-for-depth (&optional depth
)
3517 "Return outline topic bullet suited to optional DEPTH, or current depth."
3518 ;; Find bullet in plain-bullets-string modulo DEPTH.
3519 (if allout-stylish-prefixes
3520 (char-to-string (aref allout-plain-bullets-string
3521 (%
(max 0 (- depth
2))
3522 allout-plain-bullets-string-len
)))
3523 allout-primary-bullet
)
3526 ;;;_ - Topic Production
3527 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3528 (defun allout-make-topic-prefix (&optional prior-bullet
3534 ;; Depth null means use current depth, non-null means we're either
3535 ;; opening a new topic after current topic, lower or higher, or we're
3536 ;; changing level of current topic.
3537 ;; Instead dominates specified bullet-char.
3539 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3541 All the arguments are optional.
3543 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3544 nil if none. This bullet may be preserved (other options
3545 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3548 Second arg NEW indicates that a new topic is being opened after the
3549 topic at point, if non-nil. Default bullet for new topics, eg, may
3550 be set (contingent to other args) to numbered bullets if previous
3551 sibling is one. The implication otherwise is that the current topic
3552 is being adjusted -- shifted or rebulleted -- and we don't consider
3553 bullet or previous sibling.
3555 Third arg DEPTH forces the topic prefix to that depth, regardless of
3556 the current topics' depth.
3560 - nil, then the bullet char for the context is used, per distinction or depth
3561 - a (numeric) character, then character's string representation is used
3562 - a string, then the user is asked for bullet with the first char as default
3563 - anything else, the user is solicited with bullet char per context as default
3565 \(INSTEAD overrides other options, including, eg, a distinctive
3568 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3569 is non-nil *and* no specific INSTEAD was specified. Then
3570 NUMBER-CONTROL non-nil forces prefix to either numbered or
3571 unnumbered format, depending on the value of the sixth arg, INDEX.
3573 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3575 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3576 the prefix of the topic is forced to be numbered. Non-nil
3577 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3578 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3579 that the index for the numbered prefix will be derived, by counting
3580 siblings back to start of level. If INDEX is a number, then that
3581 number is used as the index for the numbered prefix (allowing, eg,
3582 sequential renumbering to not require this function counting back the
3583 index for each successive sibling)."
3585 ;; The options are ordered in likely frequency of use, most common
3586 ;; highest, least lowest. Ie, more likely to be doing prefix
3587 ;; adjustments than soliciting, and yet more than numbering.
3588 ;; Current prefix is least dominant, but most likely to be commonly
3594 (depth (or depth
(allout-depth)))
3595 (header-lead allout-header-prefix
)
3598 ;; Getting value for bullet char is practically the whole job:
3601 ; Simplest situation -- level 1:
3602 ((<= depth
1) (setq header-lead
"") allout-primary-bullet
)
3603 ; Simple, too: all asterisks:
3604 (allout-old-style-prefixes
3605 ;; Cheat -- make body the whole thing, null out header-lead and
3607 (setq body
(make-string depth
3608 (string-to-char allout-primary-bullet
)))
3609 (setq header-lead
"")
3612 ;; (Neither level 1 nor old-style, so we're space padding.
3613 ;; Sneak it in the condition of the next case, whatever it is.)
3615 ;; Solicitation overrides numbering and other cases:
3616 ((progn (setq body
(make-string (- depth
2) ?\
))
3617 ;; The actual condition:
3619 (let ((got (cond ((stringp instead
)
3620 (if (> (length instead
) 0)
3621 (allout-solicit-alternate-bullet
3622 depth
(substring instead
0 1))))
3623 ((characterp instead
) (char-to-string instead
))
3624 (t (allout-solicit-alternate-bullet depth
)))))
3625 ;; Gotta check whether we're numbering and got a numbered bullet:
3626 (setq numbering
(and allout-numbered-bullet
3627 (not (and number-control
(not index
)))
3628 (string= got allout-numbered-bullet
)))
3629 ;; Now return what we got, regardless:
3632 ;; Numbering invoked through args:
3633 ((and allout-numbered-bullet number-control
)
3634 (if (setq numbering
(not (setq denumbering
(not index
))))
3635 allout-numbered-bullet
3636 (if (and prior-bullet
3637 (not (string= allout-numbered-bullet
3640 (allout-bullet-for-depth depth
))))
3642 ;;; Neither soliciting nor controlled numbering ;;;
3643 ;;; (may be controlled denumbering, tho) ;;;
3645 ;; Check wrt previous sibling:
3646 ((and new
; only check for new prefixes
3647 (<= depth
(allout-depth))
3648 allout-numbered-bullet
; ... & numbering enabled
3650 (let ((sibling-bullet
3652 ;; Locate correct sibling:
3653 (or (>= depth
(allout-depth))
3654 (allout-ascend-to-depth depth
))
3655 (allout-get-bullet))))
3656 (if (and sibling-bullet
3657 (string= allout-numbered-bullet sibling-bullet
))
3658 (setq numbering sibling-bullet
)))))
3660 ;; Distinctive prior bullet?
3662 (allout-distinctive-bullet prior-bullet
)
3663 ;; Either non-numbered:
3664 (or (not (and allout-numbered-bullet
3665 (string= prior-bullet allout-numbered-bullet
)))
3666 ;; or numbered, and not denumbering:
3667 (setq numbering
(not denumbering
)))
3671 ;; Else, standard bullet per depth:
3672 ((allout-bullet-for-depth depth
)))))
3678 (format "%d" (cond ((and index
(numberp index
)) index
)
3679 (new (1+ (allout-sibling-index depth
)))
3680 ((allout-sibling-index))))))
3683 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3684 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet
)
3685 "Open a new topic at depth DEPTH.
3687 New topic is situated after current one, unless optional flag BEFORE
3688 is non-nil, or unless current line is completely empty -- lacking even
3689 whitespace -- in which case open is done on the current line.
3691 When adding an offspring, it will be added immediately after the parent if
3692 the other offspring are exposed, or after the last child if the offspring
3693 are hidden. (The intervening offspring will be exposed in the latter
3696 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3700 - Creation of new topics is with respect to the visible topic
3701 containing the cursor, regardless of intervening concealed ones.
3703 - New headers are generally created after/before the body of a
3704 topic. However, they are created right at cursor location if the
3705 cursor is on a blank line, even if that breaks the current topic
3706 body. This is intentional, to provide a simple means for
3707 deliberately dividing topic bodies.
3709 - Double spacing of topic lists is preserved. Also, the first
3710 level two topic is created double-spaced (and so would be
3711 subsequent siblings, if that's left intact). Otherwise,
3712 single-spacing is used.
3714 - Creation of sibling or nested topics is with respect to the topic
3715 you're starting from, even when creating backwards. This way you
3716 can easily create a sibling in front of the current topic without
3717 having to go to its preceding sibling, and then open forward
3720 (allout-beginning-of-current-line)
3722 (let* ((inhibit-field-text-motion t
)
3723 (depth (+ (allout-current-depth) relative-depth
))
3724 (opening-on-blank (if (looking-at "^\$")
3725 (not (setq before nil
))))
3726 ;; bunch o vars set while computing ref-topic
3730 (ref-topic (save-excursion
3731 (cond ((< relative-depth
0)
3732 (allout-ascend-to-depth depth
))
3733 ((>= relative-depth
1) nil
)
3734 (t (allout-back-to-current-heading)))
3735 (setq ref-depth allout-recent-depth
)
3737 (if (> allout-recent-prefix-end
1)
3738 (allout-recent-bullet)
3740 (setq opening-numbered
3742 (and allout-numbered-bullet
3743 (or (<= relative-depth
0)
3744 (allout-descend-to-depth depth
))
3745 (if (allout-numbered-type-prefix)
3746 allout-numbered-bullet
))))
3752 (if (not opening-on-blank
)
3753 ; Positioning and vertical
3754 ; padding -- only if not
3757 (goto-char ref-topic
)
3758 (setq dbl-space
; Determine double space action:
3759 (or (and (<= relative-depth
0) ; not descending;
3761 ;; at b-o-b or preceded by a blank line?
3762 (or (> 0 (forward-line -
1))
3763 (looking-at "^\\s-*$")
3766 ;; succeeded by a blank line?
3767 (allout-end-of-current-subtree)
3768 (looking-at "\n\n")))
3769 (and (= ref-depth
1)
3773 ;; Don't already have following
3774 ;; vertical padding:
3775 (not (allout-pre-next-prefix)))))))
3777 ;; Position to prior heading, if inserting backwards, and not
3779 (if (and before
(>= relative-depth
0))
3780 (progn (allout-back-to-current-heading)
3781 (setq doing-beginning
(bobp))
3783 (allout-previous-heading)))
3784 (if (and before
(bobp))
3787 (if (<= relative-depth
0)
3788 ;; Not going inwards, don't snug up:
3794 (progn (end-of-line)
3795 (allout-pre-next-prefix)
3796 (while (and (= ?
\n (following-char))
3801 (if (not (looking-at "^$"))
3803 (allout-end-of-current-subtree)
3804 (if (looking-at "\n\n") (forward-char 1))))
3805 ;; Going inwards -- double-space if first offspring is
3806 ;; double-spaced, otherwise snug up.
3807 (allout-end-of-entry)
3811 (allout-beginning-of-current-line)
3814 ;; Blank lines between current header body and next
3815 ;; header -- get to last substantive (non-white-space)
3817 (progn (setq dbl-space t
)
3818 (re-search-backward "[^ \t\n]" nil t
)))
3819 (if (looking-at "\n\n")
3822 (allout-next-heading)
3823 (when (> allout-recent-depth ref-depth
)
3824 ;; This is an offspring.
3826 (looking-at "^\\s-*$")))
3827 (progn (forward-line 1)
3830 (allout-end-of-current-line))
3832 ;;(if doing-beginning (goto-char doing-beginning))
3834 ;; We insert a newline char rather than using open-line to
3835 ;; avoid rear-stickiness inheritance of read-only property.
3836 (progn (if (and (not (> depth ref-depth
))
3839 (if (and (not dbl-space
) (> depth ref-depth
))
3845 (if (and dbl-space
(not (> relative-depth
0)))
3847 (if (and (not (eobp))
3850 ;; bolp doesn't detect concealed
3851 ;; trailing newlines, compensate:
3854 (allout-hidden-p)))))
3857 (setq start
(point))
3858 (insert (concat (allout-make-topic-prefix opening-numbered t depth
)
3860 (setq end
(1+ (point)))
3862 (allout-rebullet-heading (and offer-recent-bullet ref-bullet
)
3864 (if (> relative-depth
0)
3865 (save-excursion (goto-char ref-topic
)
3866 (allout-show-children)))
3869 (run-hook-with-args 'allout-structure-added-functions start end
)
3873 ;;;_ > allout-open-subtopic (arg)
3874 (defun allout-open-subtopic (arg)
3875 "Open new topic header at deeper level than the current one.
3877 Negative universal ARG means to open deeper, but place the new topic
3878 prior to the current one."
3880 (allout-open-topic 1 (> 0 arg
) (< 1 arg
)))
3881 ;;;_ > allout-open-sibtopic (arg)
3882 (defun allout-open-sibtopic (arg)
3883 "Open new topic header at same level as the current one.
3885 Positive universal ARG means to use the bullet of the prior sibling.
3887 Negative universal ARG means to place the new topic prior to the current
3890 (allout-open-topic 0 (> 0 arg
) (not (= 1 arg
))))
3891 ;;;_ > allout-open-supertopic (arg)
3892 (defun allout-open-supertopic (arg)
3893 "Open new topic header at shallower level than the current one.
3895 Negative universal ARG means to open shallower, but place the new
3896 topic prior to the current one."
3899 (allout-open-topic -
1 (> 0 arg
) (< 1 arg
)))
3901 ;;;_ - Outline Alteration
3902 ;;;_ : Topic Modification
3903 ;;;_ = allout-former-auto-filler
3904 (defvar allout-former-auto-filler nil
3905 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3906 ;;;_ > allout-auto-fill ()
3907 (defun allout-auto-fill ()
3908 "`allout-mode' autofill function.
3910 Maintains outline hanging topic indentation if
3911 `allout-use-hanging-indents' is set."
3913 (when (and (not allout-inhibit-auto-fill
)
3914 (or (not allout-inhibit-auto-fill-on-headline
)
3915 (not (allout-on-current-heading-p))))
3916 (let ((fill-prefix (if allout-use-hanging-indents
3917 ;; Check for topic header indentation:
3921 (if (looking-at allout-regexp
)
3922 ;; ... construct indentation to account for
3923 ;; length of topic prefix:
3924 (make-string (progn (allout-end-of-prefix)
3927 (use-auto-fill-function
3928 (if (and (eq allout-outside-normal-auto-fill-function
3930 (eq auto-fill-function
'allout-auto-fill
))
3932 (or allout-outside-normal-auto-fill-function
3933 auto-fill-function
))))
3934 (if (or allout-former-auto-filler allout-use-hanging-indents
)
3935 (funcall use-auto-fill-function
)))))
3936 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3937 (defun allout-reindent-body (old-depth new-depth
&optional _number
)
3938 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3940 Optional arg NUMBER indicates numbering is being added, and it must
3943 Note that refill of indented paragraphs is not done."
3946 (allout-end-of-prefix)
3947 (let* ((new-margin (current-column))
3948 excess old-indent-begin old-indent-end
3949 ;; We want the column where the header-prefix text started
3950 ;; *before* the prefix was changed, so we infer it relative
3951 ;; to the new margin and the shift in depth:
3952 (old-margin (+ old-depth
(- new-margin new-depth
))))
3954 ;; Process lines up to (but excluding) next topic header:
3958 (and (re-search-forward "\n\\(\\s-*\\)"
3961 ;; Register the indent data, before we reset the
3962 ;; match data with a subsequent `looking-at':
3963 (setq old-indent-begin
(match-beginning 1)
3964 old-indent-end
(match-end 1))
3965 (not (looking-at allout-regexp
)))
3966 (if (> 0 (setq excess
(- (- old-indent-end old-indent-begin
)
3968 ;; Text starts left of old margin -- don't adjust:
3970 ;; Text was hanging at or right of old left margin --
3971 ;; reindent it, preserving its existing indentation
3972 ;; beyond the old margin:
3973 (delete-region old-indent-begin old-indent-end
)
3974 (indent-to (+ new-margin excess
(current-column))))))))))
3975 ;;;_ > allout-rebullet-current-heading (arg)
3976 (defun allout-rebullet-current-heading (arg)
3977 "Solicit new bullet for current visible heading."
3979 (let ((initial-col (current-column))
3980 (on-bullet (eq (point)(allout-current-bullet-pos)))
3982 (backwards (if (< arg
0)
3983 (setq arg
(* arg -
1)))))
3985 (save-excursion (allout-back-to-current-heading)
3986 (allout-end-of-prefix)
3987 (setq from allout-recent-prefix-beginning
3988 to allout-recent-prefix-end
)
3989 (allout-rebullet-heading t
;;; instead
3991 nil
;;; number-control
3993 t
) ;;; do-successors
3994 (run-hook-with-args 'allout-exposure-change-functions
3999 (setq initial-col nil
) ; Override positioning back to init col
4001 (allout-next-visible-heading 1)
4002 (allout-goto-prefix-doublechecked)
4003 (allout-next-visible-heading -
1))))
4005 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
4006 (initial-col (move-to-column initial-col
)))))
4007 ;;;_ > allout-rebullet-heading (&optional instead ...)
4008 (defun allout-rebullet-heading (&optional instead
4014 "Adjust bullet of current topic prefix.
4016 All args are optional.
4019 - nil, then the bullet char for the context is used, per distinction or depth
4020 - a (numeric) character, then character's string representation is used
4021 - a string, then the user is asked for bullet with the first char as default
4022 - anything else, the user is solicited with bullet char per context as default
4024 Second arg DEPTH forces the topic prefix to that depth, regardless
4025 of the topic's current depth.
4027 Third arg NUMBER-CONTROL can force the prefix to or away from
4028 numbered form. It has effect only if `allout-numbered-bullet' is
4029 non-nil and soliciting was not explicitly invoked (via first arg).
4030 Its effect, numbering or denumbering, then depends on the setting
4031 of the fourth arg, INDEX.
4033 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
4034 prefix of the topic is forced to be non-numbered. Null index and
4035 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
4036 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
4037 INDEX is a number, then that number is used for the numbered
4038 prefix. Non-nil and non-number means that the index for the
4039 numbered prefix will be derived by allout-make-topic-prefix.
4041 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
4044 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
4045 and `allout-numbered-bullet', which all affect the behavior of
4048 (let* ((current-depth (allout-depth))
4049 (new-depth (or new-depth current-depth
))
4050 (mb allout-recent-prefix-beginning
)
4051 (me allout-recent-prefix-end
)
4052 (current-bullet (buffer-substring-no-properties (- me
1) me
))
4053 (has-annotation (get-text-property mb
'allout-was-hidden
))
4054 (new-prefix (allout-make-topic-prefix current-bullet
4061 ;; Is new one identical to old?
4062 (if (and (= current-depth new-depth
)
4063 (string= current-bullet
4064 (substring new-prefix
(1- (length new-prefix
)))))
4068 ;; New prefix probably different from old:
4069 ; get rid of old one:
4070 (allout-unprotected (delete-region mb me
))
4072 ; Dispense with number if
4073 ; numbered-bullet prefix:
4075 (if (and allout-numbered-bullet
4076 (string= allout-numbered-bullet current-bullet
)
4077 (looking-at "[0-9]+"))
4079 (delete-region (match-beginning 0)(match-end 0)))))
4081 ;; convey 'allout-was-hidden annotation, if original had it:
4083 (put-text-property 0 (length new-prefix
) 'allout-was-hidden t
4086 ; Put in new prefix:
4087 (allout-unprotected (insert new-prefix
))
4089 ;; Reindent the body if elected, margin changed, and not encrypted body:
4090 (if (and allout-reindent-bodies
4091 (not (= new-depth current-depth
))
4092 (not (allout-encrypted-topic-p)))
4093 (allout-reindent-body current-depth new-depth
))
4095 (run-hook-with-args 'allout-exposure-change-functions mb me nil
)
4097 ;; Recursively rectify successive siblings of orig topic if
4098 ;; caller elected for it:
4101 (while (allout-next-sibling new-depth nil
)
4103 (cond ((numberp index
) (1+ index
))
4104 ((not number-control
) (allout-sibling-index))))
4105 (if (allout-numbered-type-prefix)
4106 (allout-rebullet-heading nil
;;; instead
4107 new-depth
;;; new-depth
4108 number-control
;;; number-control
4110 nil
))))) ;;;(dont!)do-successors
4111 ) ; (if (and (= current-depth new-depth)...))
4112 ) ; let* ((current-depth (allout-depth))...)
4114 ;;;_ > allout-rebullet-topic (arg)
4115 (defun allout-rebullet-topic (arg &optional sans-offspring
)
4116 "Rebullet the visible topic containing point and all contained subtopics.
4118 Descends into invisible as well as visible topics, however.
4120 When optional SANS-OFFSPRING is non-nil, subtopics are not
4121 shifted. (Shifting a topic outwards without shifting its
4122 offspring is disallowed, since this would create a \"containment
4123 discontinuity\", where the depth difference between a topic and
4124 its immediate offspring is greater than one.)
4126 With repeat count, shift topic depth by that amount."
4128 (let ((start-col (current-column)))
4131 (cond ((null arg
) (setq arg
0))
4132 ((listp arg
) (setq arg
(car arg
))))
4133 ;; Fill the user in, in case we're shifting a big topic:
4134 (if (not (zerop arg
)) (message "Shifting..."))
4135 (allout-back-to-current-heading)
4136 (if (<= (+ allout-recent-depth arg
) 0)
4137 (error "Attempt to shift topic below level 1"))
4138 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring
)
4139 (if (not (zerop arg
)) (message "Shifting... done.")))
4140 (move-to-column (max 0 (+ start-col arg
)))))
4141 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4142 (defun allout-rebullet-topic-grunt (&optional relative-depth
4148 "Like `allout-rebullet-topic', but on nearest containing topic
4151 See `allout-rebullet-heading' for rebulleting behavior.
4153 All arguments are optional.
4155 First arg RELATIVE-DEPTH means to shift the depth of the entire
4158 Several subsequent args are for internal recursive use by the function
4159 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4161 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4162 are not shifted. (Shifting a topic outwards without shifting
4163 its offspring is disallowed, since this would create a
4164 \"containment discontinuity\", where the depth difference between
4165 a topic and its immediate offspring is greater than one.)"
4167 ;; XXX the recursion here is peculiar, and in general the routine may
4168 ;; need simplification with refactoring.
4170 (if (and sans-offspring
4172 (< relative-depth
0))
4173 (error (concat "Attempt to shift topic outwards without offspring,"
4174 " would cause containment discontinuity.")))
4176 (let* ((relative-depth (or relative-depth
0))
4177 (new-depth (allout-depth))
4178 (starting-depth (or starting-depth new-depth
))
4179 (on-starting-call (null starting-point
))
4181 ;; Leave index null on starting call, so rebullet-heading
4182 ;; calculates it at what might be new depth:
4183 (and (or (zerop relative-depth
)
4184 (not on-starting-call
))
4185 (allout-sibling-index))))
4186 (starting-index index
)
4187 (moving-outwards (< 0 relative-depth
))
4188 (starting-point (or starting-point
(point)))
4189 (local-point (point)))
4191 ;; Sanity check for excessive promotion done only on starting call:
4192 (and on-starting-call
4194 (> 0 (+ starting-depth relative-depth
))
4195 (error "Attempt to shift topic out beyond level 1"))
4197 (cond ((= starting-depth new-depth
)
4198 ;; We're at depth to work on this one.
4200 ;; When shifting out we work on the children before working on
4201 ;; the parent to avoid interim `allout-aberrant-container-p'
4202 ;; aberrancy, and vice-versa when shifting in:
4203 (if (>= relative-depth
0)
4204 (allout-rebullet-heading nil
4205 (+ starting-depth relative-depth
)
4208 nil
)) ;;; do-successors
4209 (when (not sans-offspring
)
4210 ;; ... and work on subsequent ones which are at greater depth:
4212 (allout-next-heading)
4213 (while (and (not (eobp))
4214 (< starting-depth
(allout-depth)))
4215 (setq index
(1+ index
))
4216 (allout-rebullet-topic-grunt relative-depth
4220 (when (< relative-depth
0)
4222 (goto-char local-point
)
4223 (allout-rebullet-heading nil
;;; instead
4224 (+ starting-depth relative-depth
)
4227 nil
)))) ;;; do-successors
4229 ((< starting-depth new-depth
)
4230 ;; Rare case -- subtopic more than one level deeper than parent.
4231 ;; Treat this one at an even deeper level:
4232 (allout-rebullet-topic-grunt relative-depth
4238 (if on-starting-call
4240 ;; Rectify numbering of former siblings of the adjusted topic,
4241 ;; if topic has changed depth
4242 (if (or do-successors
4243 (and (not (zerop relative-depth
))
4244 (or (= allout-recent-depth starting-depth
)
4245 (= allout-recent-depth
(+ starting-depth
4247 (allout-rebullet-heading nil nil nil nil t
))
4248 ;; Now rectify numbering of new siblings of the adjusted topic,
4249 ;; if depth has been changed:
4250 (progn (goto-char starting-point
)
4251 (if (not (zerop relative-depth
))
4252 (allout-rebullet-heading nil nil nil nil t
)))))
4255 ;;;_ > allout-renumber-to-depth (&optional depth)
4256 (defun allout-renumber-to-depth (&optional depth
)
4257 "Renumber siblings at current depth.
4259 Affects superior topics if optional arg DEPTH is less than current depth.
4261 Returns final depth."
4263 ;; Proceed by level, processing subsequent siblings on each,
4264 ;; ascending until we get shallower than the start depth:
4266 (let ((ascender (allout-depth))
4268 (while (and (not (eobp))
4270 (>= allout-recent-depth depth
)
4271 (>= ascender depth
))
4272 ; Skip over all topics at
4273 ; lesser depths, which can not
4274 ; have been disturbed:
4275 (while (and (not (setq was-eobp
(eobp)))
4276 (> allout-recent-depth ascender
))
4277 (allout-next-heading))
4278 ; Prime ascender for ascension:
4279 (setq ascender
(1- allout-recent-depth
))
4280 (if (>= allout-recent-depth depth
)
4281 (allout-rebullet-heading nil
;;; instead
4283 nil
;;; number-control
4285 t
)) ;;; do-successors
4286 (if was-eobp
(goto-char (point-max)))))
4287 allout-recent-depth
)
4288 ;;;_ > allout-number-siblings (&optional denumber)
4289 (defun allout-number-siblings (&optional denumber
)
4290 "Assign numbered topic prefix to this topic and its siblings.
4292 With universal argument, denumber -- assign default bullet to this
4293 topic and its siblings.
4295 With repeated universal argument (`^U^U'), solicit bullet for each
4296 rebulleting each topic at this level."
4301 (allout-back-to-current-heading)
4302 (allout-beginning-of-level)
4303 (let ((depth allout-recent-depth
)
4304 (index (if (not denumber
) 1))
4305 (use-bullet (equal '(16) denumber
))
4308 (allout-rebullet-heading use-bullet
;;; instead
4310 t
;;; number-control
4312 nil
) ;;; do-successors
4313 (if index
(setq index
(1+ index
)))
4314 (setq more
(allout-next-sibling depth nil
))))))
4315 ;;;_ > allout-shift-in (arg)
4316 (defun allout-shift-in (arg)
4317 "Increase depth of current heading and any items collapsed within it.
4319 With a negative argument, the item is shifted out using
4320 `allout-shift-out', instead.
4322 With an argument greater than one, shift-in the item but not its
4323 offspring, making the item into a sibling of its former children,
4324 and a child of sibling that formerly preceded it.
4326 You are not allowed to shift the first offspring of a topic
4327 inwards, because that would yield a \"containment
4328 discontinuity\", where the depth difference between a topic and
4329 its immediate offspring is greater than one. The first topic in
4330 the file can be adjusted to any positive depth, however."
4334 (allout-shift-out (* arg -
1))
4335 ;; refuse to create a containment discontinuity:
4337 (allout-back-to-current-heading)
4339 (let* ((current-depth allout-recent-depth
)
4340 (start-point (point))
4341 (predecessor-depth (progn
4343 (allout-goto-prefix-doublechecked)
4344 (if (< (point) start-point
)
4347 (if (and (> predecessor-depth
0)
4348 (> (1+ current-depth
)
4349 (1+ predecessor-depth
)))
4350 (error (concat "Disallowed shift deeper than"
4351 " containing topic's children."))
4352 (allout-back-to-current-heading)
4353 (if (< allout-recent-depth
(1+ current-depth
))
4354 (allout-show-children))))))
4355 (let ((where (point)))
4356 (allout-rebullet-topic 1 (and (> arg
1) 'sans-offspring
))
4357 (run-hook-with-args 'allout-structure-shifted-functions arg where
))))
4358 ;;;_ > allout-shift-out (arg)
4359 (defun allout-shift-out (arg)
4360 "Decrease depth of current heading and any topics collapsed within it.
4361 This will make the item a sibling of its former container.
4363 With a negative argument, the item is shifted in using
4364 `allout-shift-in', instead.
4366 With an argument greater than one, shift-out the item's offspring
4367 but not the item itself, making the former children siblings of
4370 With an argument greater than 1, the item's offspring are shifted
4371 out without shifting the item. This will make the immediate
4372 subtopics into siblings of the item."
4375 (allout-shift-in (* arg -
1))
4376 ;; Get proper exposure in this area:
4377 (save-excursion (if (allout-ascend)
4378 (allout-show-children)))
4379 ;; Show collapsed children if there's a successor which will become
4381 (if (and (allout-current-topic-collapsed-p)
4382 (save-excursion (allout-next-sibling)))
4383 (allout-show-children))
4384 (let ((where (and (allout-depth) allout-recent-prefix-beginning
)))
4387 ;; Shift the offspring but not the topic:
4388 (let ((children-chart (allout-chart-subtree 1)))
4389 (if (listp (car children-chart
))
4391 (setq children-chart
(allout-flatten children-chart
)))
4393 (dolist (child-point children-chart
)
4394 (goto-char child-point
)
4395 (allout-shift-out 1))))
4396 (allout-rebullet-topic (* arg -
1))))
4397 (run-hook-with-args 'allout-structure-shifted-functions
(* arg -
1) where
))))
4398 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4399 ;;;_ > allout-kill-line (&optional arg)
4400 (defun allout-kill-line (&optional arg
)
4401 "Kill line, adjusting subsequent lines suitably for outline mode."
4405 (if (or (not (allout-mode-p))
4407 (not (save-match-data (looking-at allout-regexp
))))
4408 ;; Just do a regular kill:
4410 ;; Ah, have to watch out for adjustments:
4411 (let* ((beg (point))
4413 (beg-hidden (allout-hidden-p))
4414 (end-hidden (save-excursion (allout-end-of-current-line)
4417 (depth (allout-depth)))
4419 (allout-annotate-hidden beg end
)
4421 (if (and (not beg-hidden
) (not end-hidden
))
4422 (allout-unprotected (kill-line arg
))
4424 (run-hooks 'allout-after-copy-or-kill-hook
)
4425 (allout-deannotate-hidden beg end
)
4427 (if allout-numbered-bullet
4428 (save-excursion ; Renumber subsequent topics if needed:
4429 (if (not (save-match-data (looking-at allout-regexp
)))
4430 (allout-next-heading))
4431 (allout-renumber-to-depth depth
)))
4432 (run-hook-with-args 'allout-structure-deleted-functions depth
(point))))))
4433 ;;;_ > allout-copy-line-as-kill ()
4434 (defun allout-copy-line-as-kill ()
4435 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4437 (let ((buffer-read-only t
))
4440 (buffer-read-only nil
))))
4441 ;;;_ > allout-kill-topic ()
4442 (defun allout-kill-topic ()
4443 "Kill topic together with subtopics.
4445 Trailing whitespace is killed with a topic if that whitespace:
4447 - would separate the topic from a subsequent sibling
4448 - would separate the topic from the end of buffer
4449 - would not be added to whitespace already separating the topic from the
4452 Topic exposure is marked with text-properties, to be used by
4453 `allout-yank-processing' for exposure recovery."
4456 (let* ((inhibit-field-text-motion t
)
4457 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4459 (depth allout-recent-depth
))
4460 (allout-end-of-current-subtree)
4461 (if (and (/= (current-column) 0) (not (eobp)))
4464 (if (and (save-match-data (looking-at "\n"))
4466 (or (not (allout-next-heading))
4467 (= depth allout-recent-depth
)))
4468 (and (> (- beg
(point-min)) 3)
4469 (string= (buffer-substring (- beg
2) beg
) "\n\n"))))
4472 (allout-annotate-hidden beg
(setq end
(point)))
4473 (unwind-protect ; for possible barf-if-buffer-read-only.
4474 (allout-unprotected (kill-region beg end
))
4475 (allout-deannotate-hidden beg end
)
4476 (run-hooks 'allout-after-copy-or-kill-hook
)
4479 (allout-renumber-to-depth depth
))
4480 (run-hook-with-args 'allout-structure-deleted-functions depth
(point)))))
4481 ;;;_ > allout-copy-topic-as-kill ()
4482 (defun allout-copy-topic-as-kill ()
4483 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4485 (let ((buffer-read-only t
))
4488 (buffer-read-only (message "Topic copied...")))))
4489 ;;;_ > allout-annotate-hidden (begin end)
4490 (defun allout-annotate-hidden (begin end
)
4491 "Qualify text with properties to indicate exposure status."
4493 (let ((was-modified (buffer-modified-p))
4494 (buffer-read-only nil
))
4495 (allout-deannotate-hidden begin end
)
4498 (let (done next prev overlay
)
4500 ;; at or advance to start of next hidden region:
4501 (if (not (allout-hidden-p))
4504 (allout-next-single-char-property-change (point)
4507 (if (or (not next
) (eq prev next
))
4508 ;; still not at start of hidden area -- must not be any left.
4512 (if (not (allout-hidden-p))
4513 ;; still not at start of hidden area.
4515 (setq overlay
(allout-get-invisibility-overlay))
4516 (setq next
(overlay-end overlay
)
4518 ;; advance to end of this hidden area:
4522 (let ((buffer-undo-list t
))
4523 (put-text-property (overlay-start overlay
) next
4524 'allout-was-hidden t
)))))))))
4525 (set-buffer-modified-p was-modified
)))
4526 ;;;_ > allout-deannotate-hidden (begin end)
4527 (defun allout-deannotate-hidden (begin end
)
4528 "Remove allout hidden-text annotation between BEGIN and END."
4531 (let ((inhibit-read-only t
)
4532 (buffer-undo-list t
))
4533 (remove-text-properties begin
(min end
(point-max))
4534 '(allout-was-hidden t
)))))
4535 ;;;_ > allout-hide-by-annotation (begin end)
4536 (defun allout-hide-by-annotation (begin end
)
4537 "Translate text properties indicating exposure status into actual exposure."
4540 (let ((was-modified (buffer-modified-p))
4543 ;; at or advance to start of next annotation:
4544 (if (not (get-text-property (point) 'allout-was-hidden
))
4545 (setq next
(allout-next-single-char-property-change
4546 (point) 'allout-was-hidden nil end
)))
4547 (if (or (not next
) (eq prev next
))
4548 ;; no more or not advancing -- must not be any left.
4552 (if (not (get-text-property (point) 'allout-was-hidden
))
4553 ;; still not at start of annotation.
4555 ;; advance to just after end of this annotation:
4556 (setq next
(allout-next-single-char-property-change
4557 (point) 'allout-was-hidden nil end
))
4558 (let ((o (make-overlay prev next nil
'front-advance
)))
4559 (overlay-put o
'category
'allout-exposure-category
)
4560 (overlay-put o
'evaporate t
))
4561 (allout-deannotate-hidden prev next
)
4563 (if next
(goto-char next
)))))
4564 (set-buffer-modified-p was-modified
))))
4565 ;;;_ > allout-yank-processing ()
4566 (defun allout-yank-processing (&optional _arg
)
4568 "Incidental allout-specific business to be done just after text yanks.
4570 Does depth adjustment of yanked topics, when:
4572 1 the stuff being yanked starts with a valid outline header prefix, and
4573 2 it is being yanked at the end of a line which consists of only a valid
4576 Also, adjusts numbering of subsequent siblings when appropriate.
4578 Depth adjustment alters the depth of all the topics being yanked
4579 the amount it takes to make the first topic have the depth of the
4580 header into which it's being yanked.
4582 The point is left in front of yanked, adjusted topics, rather than
4583 at the end (and vice-versa with the mark). Non-adjusted yanks,
4584 however, are left exactly like normal, non-allout-specific yanks."
4587 ; Get to beginning, leaving
4588 ; region around subject:
4589 (if (< (allout-mark-marker t
) (point))
4590 (exchange-point-and-mark))
4592 (let* ((subj-beg (point))
4594 (subj-end (allout-mark-marker t
))
4595 ;; 'resituate' if yanking an entire topic into topic header:
4596 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t
))
4597 (allout-e-o-prefix-p))
4598 (looking-at allout-regexp
)
4599 (allout-prefix-data)))
4600 ;; `rectify-numbering' if resituating (where several topics may
4601 ;; be resituating) or yanking a topic into a topic slot (bol):
4602 (rectify-numbering (or resituate
4603 (and into-bol
(looking-at allout-regexp
)))))
4605 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4606 (let* ((inhibit-field-text-motion t
)
4607 (prefix-len (if (not (match-end 1))
4609 (- (match-end 1) subj-beg
)))
4610 (subj-depth allout-recent-depth
)
4611 (prefix-bullet (allout-recent-bullet))
4613 ;; Nil if adjustment unnecessary, otherwise depth to which
4614 ;; adjustment should be made:
4616 (and (goto-char subj-end
)
4618 (goto-char subj-beg
)
4619 (and (looking-at allout-regexp
)
4622 (not (= (point) subj-beg
)))
4623 (looking-at allout-regexp
)
4624 (allout-prefix-data))
4625 allout-recent-depth
)))
4627 (setq rectify-numbering allout-numbered-bullet
)
4629 ; Do the adjustment:
4632 (narrow-to-region subj-beg subj-end
)
4633 ; Trim off excessive blank
4634 ; line at end, if any:
4635 (goto-char (point-max))
4636 (if (looking-at "^$")
4637 (allout-unprotected (delete-char -
1)))
4638 ; Work backwards, with each
4640 ; successively excluding the
4641 ; last processed topic from
4642 ; the narrow region:
4644 (allout-back-to-current-heading)
4645 ; go as high as we can in each bunch:
4646 (while (allout-ascend t
))
4649 (allout-rebullet-topic-grunt (- adjust-to-depth
4652 (if (setq more
(not (bobp)))
4655 (narrow-to-region subj-beg
(point))))))
4656 ;; Remove new heading prefix:
4659 (delete-region (point) (+ (point)
4663 ; and delete residual subj
4664 ; prefix digits and space:
4665 (while (looking-at "[0-9]") (delete-char 1))
4669 ;; Assert new topic's bullet - minimal effort if unchanged:
4670 (allout-rebullet-heading (string-to-char prefix-bullet
)))
4671 (exchange-point-and-mark))))
4672 (if rectify-numbering
4675 ; Give some preliminary feedback:
4676 (message "... reconciling numbers")
4677 ; ... and renumber, in case necessary:
4678 (goto-char subj-beg
)
4679 (if (allout-goto-prefix-doublechecked)
4681 (allout-rebullet-heading nil
;;; instead
4682 (allout-depth) ;;; depth
4683 nil
;;; number-control
4687 (if (or into-bol resituate
)
4688 (allout-hide-by-annotation (point) (allout-mark-marker t
))
4689 (allout-deannotate-hidden (allout-mark-marker t
) (point)))
4691 (exchange-point-and-mark))
4692 (run-hook-with-args 'allout-structure-added-functions subj-beg subj-end
))))
4693 ;;;_ > allout-yank (&optional arg)
4694 (defun allout-yank (&optional arg
)
4695 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4697 Non-topic yanks work no differently than normal yanks.
4699 If a topic is being yanked into a bare topic prefix, the depth of the
4700 yanked topic is adjusted to the depth of the topic prefix.
4702 1 we're yanking in an `allout-mode' buffer
4703 2 the stuff being yanked starts with a valid outline header prefix, and
4704 3 it is being yanked at the end of a line which consists of only a valid
4707 If these conditions hold then the depth of the yanked topics are all
4708 adjusted the amount it takes to make the first one at the depth of the
4709 header into which it's being yanked.
4711 The point is left in front of yanked, adjusted topics, rather than
4712 at the end (and vice-versa with the mark). Non-adjusted yanks,
4713 however, (ones that don't qualify for adjustment) are handled
4714 exactly like normal yanks.
4716 Numbering of yanked topics, and the successive siblings at the depth
4717 into which they're being yanked, is adjusted.
4719 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4720 works with normal `yank' in non-outline buffers."
4723 (setq this-command
'yank
)
4727 (allout-yank-processing)))
4728 ;;;_ > allout-yank-pop (&optional arg)
4729 (defun allout-yank-pop (&optional arg
)
4730 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4732 Adapts level of popped topics to level of fresh prefix.
4734 Note -- prefix changes to distinctive bullets will stick, if followed
4735 by pops to non-distinctive yanks. Bug..."
4738 (setq this-command
'yank
)
4741 (allout-yank-processing)))
4743 ;;;_ - Specialty bullet functions
4744 ;;;_ : File Cross references
4745 ;;;_ > allout-resolve-xref ()
4746 (defun allout-resolve-xref ()
4747 "Pop to file associated with current heading, if it has an xref bullet.
4749 \(Works according to setting of `allout-file-xref-bullet')."
4751 (if (not allout-file-xref-bullet
)
4753 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4754 (if (not (string= (allout-current-bullet) allout-file-xref-bullet
))
4755 (error "Current heading lacks cross-reference bullet `%s'"
4756 allout-file-xref-bullet
)
4757 (let ((inhibit-field-text-motion t
)
4761 (let* ((text-start allout-recent-prefix-end
)
4762 (heading-end (point-at-eol)))
4763 (goto-char text-start
)
4765 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
4766 (buffer-substring (match-beginning 1)
4768 (setq file-name
(expand-file-name file-name
))
4769 (if (or (file-exists-p file-name
)
4770 (if (file-writable-p file-name
)
4771 (y-or-n-p (format "%s not there, create one? "
4773 (error "%s not found and can't be created" file-name
)))
4774 (condition-case failure
4775 (find-file-other-window file-name
)
4777 (error "%s not found" file-name
))
4783 ;;;_ #6 Exposure Control
4786 ;;;_ > allout-flag-region (from to flag)
4787 (defun allout-flag-region (from to flag
)
4788 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4789 After the exposure changes are made, run the abnormal hook
4790 `allout-exposure-change-functions' with the same arguments as
4793 ;; We use outline invisibility spec.
4794 (remove-overlays from to
'category
'allout-exposure-category
)
4796 (let ((o (make-overlay from to nil
'front-advance
)))
4797 (overlay-put o
'category
'allout-exposure-category
)
4798 (overlay-put o
'evaporate t
)
4799 (when (featurep 'xemacs
)
4800 (let ((props (symbol-plist 'allout-exposure-category
)))
4803 ;; as of 2008-02-27, xemacs lacks modification-hooks
4804 (overlay-put o
(pop props
) (pop props
))
4806 (setq allout-this-command-hid-text t
))
4807 (run-hook-with-args 'allout-exposure-change-functions from to flag
))
4808 ;;;_ > allout-flag-current-subtree (flag)
4809 (defun allout-flag-current-subtree (flag)
4810 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4813 (allout-back-to-current-heading)
4814 (let ((inhibit-field-text-motion t
))
4816 (allout-flag-region (point)
4817 ;; Exposing must not leave trailing blanks hidden,
4818 ;; but can leave them exposed when hiding, so we
4819 ;; can use flag's inverse as the
4820 ;; include-trailing-blank cue:
4821 (allout-end-of-current-subtree (not flag
))
4824 ;;;_ - Topic-specific
4825 ;;;_ > allout-show-entry ()
4826 (defun allout-show-entry ()
4827 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4829 This is a way to give restricted peek at a concealed locality without the
4830 expense of exposing its context, but can leave the outline with aberrant
4831 exposure. `allout-show-offshoot' should be used after the peek to rectify
4837 (allout-goto-prefix-doublechecked)
4838 (setq beg
(if (allout-hidden-p) (1- (point)) (point)))
4839 (setq end
(allout-pre-next-prefix))
4840 (allout-flag-region beg end nil
)
4842 ;;;_ > allout-show-children (&optional level strict)
4843 (defun allout-show-children (&optional level strict
)
4845 "If point is visible, show all direct subheadings of this heading.
4847 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4849 Optional LEVEL specifies how many levels below the current level
4850 should be shown, or all levels if t. Default is 1.
4852 Optional STRICT means don't resort to -show-to-offshoot, no matter
4853 what. This is basically so -show-to-offshoot, which is called by
4854 this function, can employ the pure offspring-revealing capabilities of
4857 Returns point at end of subtree that was opened, if any. (May get a
4858 point of non-opened subtree?)"
4861 (let ((start-point (point)))
4862 (if (and (not strict
)
4865 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4867 ;; Then recurse, but with "strict" set so we don't
4868 ;; infinite regress:
4869 (allout-show-children level t
))
4872 (allout-beginning-of-current-line)
4875 ;; translate the level spec for this routine to the ones
4876 ;; used by -chart-subtree and -chart-to-reveal:
4877 (chart-level (cond ((not level
) 1)
4880 (chart (allout-chart-subtree chart-level
))
4881 (to-reveal (or (allout-chart-to-reveal chart chart-level
)
4882 ;; interactive, show discontinuous children:
4884 (allout-called-interactively-p)
4886 (allout-back-to-current-heading)
4887 (setq depth
(allout-current-depth))
4888 (and (allout-next-heading)
4889 (> allout-recent-depth
4892 "Discontinuous offspring; use `%s %s'%s."
4893 (substitute-command-keys
4894 "\\[universal-argument]")
4895 (substitute-command-keys
4896 "\\[allout-shift-out]")
4897 " to elevate them.")
4898 (allout-chart-to-reveal
4899 chart
(- allout-recent-depth depth
))))))
4900 (goto-char start-point
)
4901 (when (and strict
(allout-hidden-p))
4902 ;; Concealed root would already have been taken care of,
4903 ;; unless strict was set.
4904 (allout-flag-region (point) (allout-snug-back) nil
)
4905 (when allout-show-bodies
4906 (goto-char (car to-reveal
))
4907 (allout-show-current-entry)))
4909 (goto-char (car to-reveal
))
4910 (allout-flag-region (save-excursion (allout-snug-back) (point))
4911 (progn (search-forward "\n" nil t
)
4914 (when allout-show-bodies
4915 (goto-char (car to-reveal
))
4916 (allout-show-current-entry))
4917 (setq to-reveal
(cdr to-reveal
)))))))
4918 ;; Compensate for `save-excursion's maintenance of point
4919 ;; within invisible text:
4920 (goto-char start-point
)))
4921 ;;;_ > allout-show-to-offshoot ()
4922 (defun allout-show-to-offshoot ()
4923 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4925 Useful for coherently exposing to a random point in a hidden region."
4928 (let ((inhibit-field-text-motion t
)
4930 (orig-pref (allout-goto-prefix-doublechecked))
4933 (while (or (> bag-it
1) (allout-hidden-p))
4934 (while (allout-hidden-p)
4935 (move-beginning-of-line 1)
4936 (if (allout-hidden-p) (forward-char -
1)))
4937 (if (= last-at
(setq last-at
(point)))
4938 ;; Oops, we're not making any progress! Show the current topic
4939 ;; completely, and try one more time here, if we haven't already.
4940 (progn (beginning-of-line)
4941 (allout-show-current-subtree)
4943 (setq bag-it
(1+ bag-it
))
4945 (error "allout-show-to-offshoot: %s"
4946 "Stumped by aberrant nesting.")))
4947 (if (> bag-it
0) (setq bag-it
0))
4948 (allout-show-children)
4949 (goto-char orig-pref
)))
4950 (goto-char orig-pt
)))
4951 (if (allout-hidden-p)
4952 (allout-show-entry)))
4953 ;;;_ > allout-hide-current-entry ()
4954 (defun allout-hide-current-entry ()
4955 "Hide the body directly following this heading."
4957 (allout-back-to-current-heading)
4959 (let ((inhibit-field-text-motion t
))
4961 (allout-flag-region (point)
4962 (progn (allout-end-of-entry) (point))
4964 ;;;_ > allout-show-current-entry (&optional arg)
4965 (defun allout-show-current-entry (&optional arg
)
4966 "Show body following current heading, or hide entry with universal argument."
4970 (allout-hide-current-entry)
4971 (save-excursion (allout-show-to-offshoot))
4973 (allout-flag-region (point)
4974 (progn (allout-end-of-entry t
) (point))
4977 ;;;_ > allout-show-current-subtree (&optional arg)
4978 (defun allout-show-current-subtree (&optional arg
)
4979 "Show everything within the current topic.
4980 With a repeat-count, expose this topic and its siblings."
4983 (if (<= (allout-current-depth) 0)
4984 ;; Outside any topics -- try to get to the first:
4985 (if (not (allout-next-heading))
4987 ;; got to first, outermost topic -- set to expose it and siblings:
4988 (message "Above outermost topic -- exposing all.")
4989 (allout-flag-region (point-min)(point-max) nil
))
4990 (allout-beginning-of-current-line)
4992 (allout-flag-current-subtree nil
)
4993 (allout-beginning-of-level)
4994 (allout-expose-topic '(* :))))))
4995 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4996 (defun allout-current-topic-collapsed-p (&optional include-single-liners
)
4997 "True if the currently visible containing topic is already collapsed.
4999 Single line topics intrinsically can be considered as being both
5000 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
5001 true, then single-line topics are considered to be collapsed. By
5002 default, they are treated as being uncollapsed."
5006 ;; Is the topic all on one line (allowing for trailing blank line)?
5007 (>= (progn (allout-back-to-current-heading)
5008 (let ((inhibit-field-text-motion t
))
5009 (move-end-of-line 1))
5011 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
5013 (or include-single-liners
5014 (progn (backward-char 1) (allout-hidden-p)))))))
5015 ;;;_ > allout-hide-current-subtree (&optional just-close)
5016 (defun allout-hide-current-subtree (&optional just-close
)
5017 "Close the current topic, or containing topic if this one is already closed.
5019 If this topic is closed and it's a top level topic, close this topic
5022 If optional arg JUST-CLOSE is non-nil, do not close the parent or
5023 siblings, even if the target topic is already closed."
5026 (let* ((from (point))
5027 (sibs-msg "Top-level topic already closed -- closing siblings...")
5028 (current-exposed (not (allout-current-topic-collapsed-p t
))))
5029 (cond (current-exposed (allout-flag-current-subtree t
))
5031 ((allout-ascend) (allout-hide-current-subtree))
5034 (allout-goto-prefix-doublechecked)
5035 (allout-expose-topic '(0 :))
5036 (message (concat sibs-msg
" Done."))))
5038 ;;;_ > allout-toggle-current-subtree-exposure
5039 (defun allout-toggle-current-subtree-exposure ()
5040 "Show or hide the current subtree depending on its current state."
5041 ;; thanks to tassilo for suggesting this.
5044 (allout-back-to-heading)
5045 (if (allout-hidden-p (point-at-eol))
5046 (allout-show-current-subtree)
5047 (allout-hide-current-subtree))))
5048 ;;;_ > allout-show-current-branches ()
5049 (defun allout-show-current-branches ()
5050 "Show all subheadings of this heading, but not their bodies."
5052 (let ((inhibit-field-text-motion t
))
5053 (beginning-of-line))
5054 (allout-show-children t
))
5055 ;;;_ > allout-hide-current-leaves ()
5056 (defun allout-hide-current-leaves ()
5057 "Hide the bodies of the current topic and all its offspring."
5059 (allout-back-to-current-heading)
5060 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
5063 ;;;_ - Region and beyond
5064 ;;;_ > allout-show-all ()
5065 (defun allout-show-all ()
5066 "Show all of the text in the buffer."
5068 (message "Exposing entire buffer...")
5069 (allout-flag-region (point-min) (point-max) nil
)
5070 (message "Exposing entire buffer... Done."))
5071 ;;;_ > allout-hide-bodies ()
5072 (defun allout-hide-bodies ()
5073 "Hide all of buffer except headings."
5075 (allout-hide-region-body (point-min) (point-max)))
5076 ;;;_ > allout-hide-region-body (start end)
5077 (defun allout-hide-region-body (start end
)
5078 "Hide all body lines in the region, but not headings."
5082 (narrow-to-region start end
)
5083 (goto-char (point-min))
5084 (let ((inhibit-field-text-motion t
))
5087 (allout-flag-region (point) (allout-end-of-entry) t
)
5090 (if (looking-at "\n\n")
5093 ;;;_ > allout-expose-topic (spec)
5094 (defun allout-expose-topic (spec)
5095 "Apply exposure specs to successive outline topic items.
5097 Use the more convenient frontend, `allout-new-exposure', if you don't
5098 need evaluation of the arguments, or even better, the `allout-layout'
5099 variable-keyed mode-activation/auto-exposure feature of allout outline
5100 mode. See the respective documentation strings for more details.
5102 Cursor is left at start position.
5104 SPEC is either a number or a list.
5106 Successive specs on a list are applied to successive sibling topics.
5108 A simple spec (either a number, one of a few symbols, or the null
5109 list) dictates the exposure for the corresponding topic.
5111 Non-null lists recursively designate exposure specs for respective
5112 subtopics of the current topic.
5114 The `:' repeat spec is used to specify exposure for any number of
5115 successive siblings, up to the trailing ones for which there are
5116 explicit specs following the `:'.
5118 Simple (numeric and null-list) specs are interpreted as follows:
5120 Numbers indicate the relative depth to open the corresponding topic.
5121 - negative numbers force the topic to be closed before opening to the
5122 absolute value of the number, so all siblings are open only to
5124 - positive numbers open to the relative depth indicated by the
5125 number, but do not force already opened subtopics to be closed.
5126 - 0 means to close topic -- hide all offspring.
5128 apply prior element to all siblings at current level, *up to*
5129 those siblings that would be covered by specs following the `:'
5130 on the list. Ie, apply to all topics at level but the last
5131 ones. (Only first of multiple colons at same level is
5132 respected -- subsequent ones are discarded.)
5133 * - completely opens the topic, including bodies.
5134 + - shows all the sub headers, but not the bodies
5135 - - exposes the body of the corresponding topic.
5138 \(allout-expose-topic \\='(-1 : 0))
5139 Close this and all following topics at current level, exposing
5140 only their immediate children, but close down the last topic
5141 at this current level completely.
5142 \(allout-expose-topic \\='(-1 () : 1 0))
5143 Close current topic so only the immediate subtopics are shown;
5144 show the children in the second to last topic, and completely
5146 \(allout-expose-topic \\='(-2 : -1 *))
5147 Expose children and grandchildren of all topics at current
5148 level except the last two; expose children of the second to
5149 last and completely open the last one."
5151 (interactive "xExposure spec: ")
5152 (if (not (listp spec
))
5154 (let ((depth (allout-depth))
5159 (setq prev-elem curr-elem
5160 curr-elem
(car spec
)
5162 (cond ; Do current element:
5163 ((null curr-elem
) nil
)
5164 ((symbolp curr-elem
)
5165 (cond ((eq curr-elem
'*) (allout-show-current-subtree)
5166 (if (> allout-recent-end-of-subtree max-pos
)
5167 (setq max-pos allout-recent-end-of-subtree
)))
5169 (if (not (allout-hidden-p))
5170 (save-excursion (allout-hide-current-subtree t
)))
5171 (allout-show-current-branches)
5172 (if (> allout-recent-end-of-subtree max-pos
)
5173 (setq max-pos allout-recent-end-of-subtree
)))
5174 ((eq curr-elem
'-
) (allout-show-current-entry))
5177 ;; Expand the `repeat' spec to an explicit version,
5178 ;; w.r.t. remaining siblings:
5179 (let ((residue ; = # of sibs not covered by remaining spec
5180 ;; Dang, could be nice to make use of the chart, sigh:
5181 (- (length (allout-chart-siblings))
5184 ;; Some residue -- cover it with prev-elem:
5185 (setq spec
(append (make-list residue prev-elem
)
5187 ((numberp curr-elem
)
5188 (if (and (>= 0 curr-elem
) (not (allout-hidden-p)))
5189 (save-excursion (allout-hide-current-subtree t
)
5192 (if (> allout-recent-end-of-subtree max-pos
)
5194 allout-recent-end-of-subtree
)))))
5195 (if (> (abs curr-elem
) 0)
5196 (progn (allout-show-children (abs curr-elem
))
5197 (if (> allout-recent-end-of-subtree max-pos
)
5198 (setq max-pos allout-recent-end-of-subtree
)))))
5200 (if (allout-descend-to-depth (1+ depth
))
5201 (let ((got (allout-expose-topic curr-elem
)))
5202 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
5203 (cond (stay (setq stay nil
))
5204 ((listp (car spec
)) nil
)
5205 ((> max-pos
(point))
5206 ;; Capitalize on max-pos state to get us nearer next sibling:
5207 (progn (goto-char (min (point-max) max-pos
))
5208 (allout-next-heading)))
5209 ((allout-next-sibling depth
))))
5211 ;;;_ > allout-old-expose-topic (spec &rest followers)
5212 (defun allout-old-expose-topic (spec &rest followers
)
5214 "Deprecated. Use `allout-expose-topic' (with different schema
5217 Dictate wholesale exposure scheme for current topic, according to SPEC.
5219 SPEC is either a number or a list. Optional successive args
5220 dictate exposure for subsequent siblings of current topic.
5222 A simple spec (either a number, a special symbol, or the null list)
5223 dictates the overall exposure for a topic. Non null lists are
5224 composite specs whose first element dictates the overall exposure for
5225 a topic, with the subsequent elements in the list interpreted as specs
5226 that dictate the exposure for the successive offspring of the topic.
5228 Simple (numeric and null-list) specs are interpreted as follows:
5230 - Numbers indicate the relative depth to open the corresponding topic:
5231 - negative numbers force the topic to be close before opening to the
5232 absolute value of the number.
5233 - positive numbers just open to the relative depth indicated by the number.
5235 - `*' completely opens the topic, including bodies.
5236 - `+' shows all the sub headers, but not the bodies
5237 - `-' exposes the body and immediate offspring of the corresponding topic.
5239 If the spec is a list, the first element must be a number, which
5240 dictates the exposure depth of the topic as a whole. Subsequent
5241 elements of the list are nested SPECs, dictating the specific exposure
5242 for the corresponding offspring of the topic.
5244 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5246 (interactive "xExposure spec: ")
5247 (let ((inhibit-field-text-motion t
)
5248 (depth (allout-current-depth))
5250 (cond ((null spec
) nil
)
5252 (if (eq spec
'*) (allout-show-current-subtree))
5253 (if (eq spec
'+) (allout-show-current-branches))
5254 (if (eq spec
'-
) (allout-show-current-entry)))
5257 (save-excursion (allout-hide-current-subtree t
)
5259 (if (or (not max-pos
)
5260 (> (point) max-pos
))
5261 (setq max-pos
(point)))
5263 (setq spec
(* -
1 spec
)))))
5265 (allout-show-children spec
)))
5267 ;(let ((got (allout-old-expose-topic (car spec))))
5268 ; (if (and got (or (not max-pos) (> got max-pos)))
5269 ; (setq max-pos got)))
5270 (let ((new-depth (+ (allout-current-depth) 1))
5272 (setq max-pos
(allout-old-expose-topic (car spec
)))
5273 (setq spec
(cdr spec
))
5275 (allout-descend-to-depth new-depth
)
5276 (not (allout-hidden-p)))
5277 (progn (setq got
(apply 'allout-old-expose-topic spec
))
5278 (if (and got
(or (not max-pos
) (> got max-pos
)))
5279 (setq max-pos got
)))))))
5280 (while (and followers
5281 (progn (if (and max-pos
(< (point) max-pos
))
5282 (progn (goto-char max-pos
)
5283 (setq max-pos nil
)))
5285 (allout-next-sibling depth
)))
5286 (allout-old-expose-topic (car followers
))
5287 (setq followers
(cdr followers
)))
5289 ;;;_ > allout-new-exposure '()
5290 (defmacro allout-new-exposure
(&rest spec
)
5291 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5292 Some arguments that would need to be quoted in `allout-expose-topic'
5293 need not be quoted in `allout-new-exposure'.
5295 Cursor is left at start position.
5297 Use this instead of obsolete `allout-exposure'.
5300 \(allout-new-exposure (-1 () () () 1) 0)
5301 Close current topic at current level so only the immediate
5302 subtopics are shown, except also show the children of the
5303 third subtopic; and close the next topic at the current level.
5304 \(allout-new-exposure : -1 0)
5305 Close all topics at current level to expose only their
5306 immediate children, except for the last topic at the current
5307 level, in which even its immediate children are hidden.
5308 \(allout-new-exposure -2 : -1 *)
5309 Expose children and grandchildren of first topic at current
5310 level, and expose children of subsequent topics at current
5311 level *except* for the last, which should be opened completely."
5313 (if (not (or (allout-goto-prefix-doublechecked)
5314 (allout-next-heading)))
5315 (error "allout-new-exposure: Can't find any outline topics"))
5316 (allout-expose-topic ',spec
)))
5318 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5320 ;;;_ - Mapping and processing of topics
5321 ;;;_ ( See also Subtree Charting, in Navigation code.)
5322 ;;;_ > allout-stringify-flat-index (flat-index)
5323 (defun allout-stringify-flat-index (flat-index &optional context
)
5324 "Convert list representing section/subsection/... to document string.
5326 Optional arg CONTEXT indicates interior levels to include."
5330 (context-depth (or (and context
2) 1)))
5331 ;; Take care of the explicit context:
5332 (while (> context-depth
0)
5333 (setq numstr
(int-to-string (car flat-index
))
5334 flat-index
(cdr flat-index
)
5335 result
(if flat-index
5336 (cons delim
(cons numstr result
))
5337 (cons numstr result
))
5338 context-depth
(if flat-index
(1- context-depth
) 0)))
5340 ;; Take care of the indentation:
5347 (1+ (truncate (if (zerop (car flat-index
))
5349 (log (car flat-index
) 10))))
5352 (setq flat-index
(cdr flat-index
)))
5353 ;; Dispose of single extra delim:
5354 (setq result
(cdr result
))))
5355 (apply 'concat result
)))
5356 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5357 (defun allout-stringify-flat-index-plain (flat-index)
5358 "Convert list representing section/subsection/... to document string."
5362 (setq result
(cons (int-to-string (car flat-index
))
5364 (cons delim result
))))
5365 (setq flat-index
(cdr flat-index
)))
5366 (apply 'concat result
)))
5367 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5368 (defun allout-stringify-flat-index-indented (flat-index)
5369 "Convert list representing section/subsection/... to document string."
5373 ;; Take care of the explicit context:
5374 (setq numstr
(int-to-string (car flat-index
))
5375 flat-index
(cdr flat-index
)
5376 result
(if flat-index
5377 (cons delim
(cons numstr result
))
5378 (cons numstr result
)))
5380 ;; Take care of the indentation:
5387 (1+ (truncate (if (zerop (car flat-index
))
5389 (log (car flat-index
) 10))))
5392 (setq flat-index
(cdr flat-index
)))
5393 ;; Dispose of single extra delim:
5394 (setq result
(cdr result
))))
5395 (apply 'concat result
)))
5396 ;;;_ > allout-listify-exposed (&optional start end format)
5397 (defun allout-listify-exposed (&optional start end format
)
5399 "Produce a list representing exposed topics in current region.
5401 This list can then be used by `allout-process-exposed' to manipulate
5404 Optional START and END indicate bounds of region.
5406 Optional arg, FORMAT, designates an alternate presentation form for
5409 list -- Present prefix as numeric section.subsection..., starting with
5410 section indicated by the list, innermost nesting first.
5411 `indent' (symbol) -- Convert header prefixes to all white space,
5412 except for distinctive bullets.
5414 The elements of the list produced are lists that represents a topic
5415 header and body. The elements of that list are:
5417 - a number representing the depth of the topic,
5418 - a string representing the header-prefix, including trailing whitespace and
5420 - a string representing the bullet character,
5421 - and a series of strings, each containing one line of the exposed
5422 portion of the topic entry."
5427 ((inhibit-field-text-motion t
)
5429 strings prefix result depth new-depth out gone-out bullet beg
5434 ;; Goto initial topic, and register preceding stuff, if any:
5435 (if (> (allout-goto-prefix-doublechecked) start
)
5436 ;; First topic follows beginning point -- register preliminary stuff:
5438 (list (list 0 "" nil
5439 (buffer-substring-no-properties start
5441 (while (and (not done
)
5442 (not (eobp)) ; Loop until we've covered the region.
5443 (not (> (point) end
)))
5444 (setq depth allout-recent-depth
; Current topics depth,
5445 bullet
(allout-recent-bullet) ; ... bullet,
5446 prefix
(allout-recent-prefix)
5447 beg
(progn (allout-end-of-prefix t
) (point))) ; and beginning.
5448 (setq done
; The boundary for the current topic:
5449 (not (allout-next-visible-heading 1)))
5450 (setq new-depth allout-recent-depth
)
5452 out
(< new-depth depth
))
5457 (while (> next
(point)) ; Get all the exposed text in
5459 (cons (buffer-substring-no-properties
5461 ;To hidden text or end of line:
5464 (allout-back-to-visible-text)))
5466 (when (< (point) next
) ; Resume from after hid text, if any.
5468 (beginning-of-line))
5470 ;; Accumulate list for this topic:
5471 (setq strings
(nreverse strings
))
5475 (let ((special (if (string-match
5476 (regexp-quote bullet
)
5477 allout-distinctive-bullets-string
)
5479 (cond ((listp format
)
5481 (if allout-flattened-numbering-abbreviation
5482 (allout-stringify-flat-index format
5484 (allout-stringify-flat-index-plain
5488 ((eq format
'indent
)
5491 (concat (make-string (1+ depth
) ?
)
5492 (substring prefix -
1))
5495 (make-string depth ?
)
5497 (t (error "allout-listify-exposed: %s %s"
5498 "invalid format" format
))))
5499 (list depth prefix strings
))
5501 ;; Reassess format, if any:
5502 (if (and format
(listp format
))
5503 (cond ((= new-depth depth
)
5504 (setq format
(cons (1+ (car format
))
5506 ((> new-depth depth
) ; descending -- assume by 1:
5507 (setq format
(cons 1 format
)))
5510 (while (< new-depth depth
)
5511 (setq format
(cdr format
))
5512 (setq depth
(1- depth
)))
5513 ; And increment the current one:
5515 (cons (1+ (or (car format
)
5518 ;; Put the list with first at front, to last at back:
5519 (nreverse result
))))
5520 ;;;_ > allout-region-active-p ()
5521 (defmacro allout-region-active-p
()
5522 (cond ((fboundp 'use-region-p
) '(use-region-p))
5523 ((fboundp 'region-active-p
) '(region-active-p))
5525 ;;_ > allout-process-exposed (&optional func from to frombuf
5527 (defun allout-process-exposed (&optional func from to frombuf tobuf
5529 "Map function on exposed parts of current topic; results to another buffer.
5531 All args are options; default values itemized below.
5533 Apply FUNCTION to exposed portions FROM position TO position in buffer
5534 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5535 alternate presentation form:
5537 `flat' -- Present prefix as numeric section.subsection..., starting with
5538 section indicated by the START-NUM, innermost nesting first.
5539 X`flat-indented' -- Prefix is like `flat' for first topic at each
5540 X level, but subsequent topics have only leaf topic
5541 X number, padded with blanks to line up with first.
5542 `indent' (symbol) -- Convert header prefixes to all white space,
5543 except for distinctive bullets.
5546 FUNCTION: `allout-insert-listified'
5547 FROM: region start, if region active, else start of buffer
5548 TO: region end, if region active, else end of buffer
5549 FROMBUF: current buffer
5550 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5553 ; Resolve arguments,
5554 ; defaulting if necessary:
5555 (if (not func
) (setq func
'allout-insert-listified
))
5556 (if (not (and from to
))
5557 (if (allout-region-active-p)
5558 (setq from
(region-beginning) to
(region-end))
5559 (setq from
(point-min) to
(point-max))))
5561 (if (not (bufferp frombuf
))
5562 ;; Specified but not a buffer -- get it:
5563 (let ((got (get-buffer frombuf
)))
5565 (error (concat "allout-process-exposed: source buffer "
5568 (setq frombuf got
))))
5569 ;; not specified -- default it:
5570 (setq frombuf
(current-buffer)))
5572 (if (not (bufferp tobuf
))
5573 (setq tobuf
(get-buffer-create tobuf
)))
5574 ;; not specified -- default it:
5575 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
5580 (progn (set-buffer frombuf
)
5581 (allout-listify-exposed from to format
))))
5583 (mapc func listified
)
5584 (pop-to-buffer tobuf
)))
5587 ;;;_ > allout-insert-listified (listified)
5588 (defun allout-insert-listified (listified)
5589 "Insert contents of listified outline portion in current buffer.
5591 LISTIFIED is a list representing each topic header and body:
5593 `(depth prefix text)'
5595 or `(depth prefix text bullet-plus)'
5597 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5598 (setq listified
(cdr listified
))
5599 (let ((prefix (prog1
5601 (setq listified
(cdr listified
))))
5604 (setq listified
(cdr listified
))))
5605 (bullet-plus (car listified
)))
5607 (if bullet-plus
(insert (concat " " bullet-plus
)))
5610 (if (setq text
(cdr text
))
5613 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5614 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format
)
5615 "Duplicate exposed portions of current outline to another buffer.
5617 Other buffer has current buffers name with \" exposed\" appended to it.
5619 With repeat count, copy the exposed parts of only the current topic.
5621 Optional second arg TOBUF is target buffer name.
5623 Optional third arg FORMAT, if non-nil, symbolically designates an
5624 alternate presentation format for the outline:
5626 `flat' - Convert topic header prefixes to numeric
5627 section.subsection... identifiers.
5628 `indent' - Convert header prefixes to all white space, except for
5629 distinctive bullets.
5630 `indent-flat' - The best of both - only the first of each level has
5631 the full path, the rest have only the section number
5632 of the leaf, preceded by the right amount of indentation."
5636 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5637 (let* ((start-pt (point))
5638 (beg (if arg
(allout-back-to-current-heading) (point-min)))
5639 (end (if arg
(allout-end-of-current-subtree) (point-max)))
5640 (buf (current-buffer))
5642 (if (eq format
'flat
)
5643 (setq format
(if arg
(save-excursion
5645 (allout-topic-flat-index))
5647 (with-current-buffer tobuf
(erase-buffer))
5648 (allout-process-exposed 'allout-insert-listified
5654 (goto-char (point-min))
5656 (goto-char start-pt
)))
5657 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5658 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf
)
5659 "Present numeric outline of outline's exposed portions in another buffer.
5661 The resulting outline is not compatible with outline mode -- use
5662 `allout-copy-exposed-to-buffer' if you want that.
5664 Use `allout-indented-exposed-to-buffer' for indented presentation.
5666 With repeat count, copy the exposed portions of only current topic.
5668 Other buffer has current buffer's name with \" exposed\" appended to
5669 it, unless optional second arg TOBUF is specified, in which case it is
5672 (allout-copy-exposed-to-buffer arg tobuf
'flat
))
5673 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5674 (defun allout-indented-exposed-to-buffer (&optional arg tobuf
)
5675 "Present indented outline of outline's exposed portions in another buffer.
5677 The resulting outline is not compatible with outline mode -- use
5678 `allout-copy-exposed-to-buffer' if you want that.
5680 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5682 With repeat count, copy the exposed portions of only current topic.
5684 Other buffer has current buffer's name with \" exposed\" appended to
5685 it, unless optional second arg TOBUF is specified, in which case it is
5688 (allout-copy-exposed-to-buffer arg tobuf
'indent
))
5690 ;;;_ - LaTeX formatting
5691 ;;;_ > allout-latex-verb-quote (string &optional flow)
5692 (defun allout-latex-verb-quote (string &optional _flow
)
5693 "Return copy of STRING for literal reproduction across LaTeX processing.
5694 Expresses the original characters (including carriage returns) of the
5695 string across LaTeX processing."
5696 (mapconcat (function
5698 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
5699 (concat "\\char" (number-to-string char
) "{}"))
5700 ((= char ?
\n) "\\\\")
5701 (t (char-to-string char
)))))
5704 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5705 (defun allout-latex-verbatim-quote-curr-line ()
5706 "Express line for exact (literal) representation across LaTeX processing.
5708 Adjust line contents so it is unaltered (from the original line)
5709 across LaTeX processing, within the context of a `verbatim'
5710 environment. Leaves point at the end of the line."
5711 (let ((inhibit-field-text-motion t
))
5713 (let (;(beg (point))
5714 (end (point-at-eol)))
5716 (while (re-search-forward "\\\\"
5717 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5718 end
; bounded by end-of-line
5719 1) ; no matches, move to end & return nil
5720 (goto-char (match-beginning 2))
5723 (goto-char (1+ (match-end 2))))))))
5724 ;;;_ > allout-insert-latex-header (buffer)
5725 (defun allout-insert-latex-header (buffer)
5726 "Insert initial LaTeX commands at point in BUFFER."
5727 ;; Much of this is being derived from the stuff in appendix of E in
5728 ;; the TeXBook, pg 421.
5730 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5732 (page-numbering (if allout-number-pages
5733 "\\pagestyle{empty}\n"
5735 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5736 allout-title-style
))
5737 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5738 allout-label-style
))
5739 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5740 allout-head-line-style
))
5741 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5742 allout-body-line-style
))
5743 (setlength (format "%s%s%s%s"
5744 "\\newlength{\\stepsize}\n"
5745 "\\setlength{\\stepsize}{"
5748 (oneheadline (format "%s%s%s%s%s%s%s"
5749 "\\newcommand{\\OneHeadLine}[3]{%\n"
5751 "\\hspace*{#2\\stepsize}%\n"
5752 "\\labelcmd{#1}\\hspace*{.2cm}"
5753 "\\headlinecmd{#3}\\\\["
5756 (onebodyline (format "%s%s%s%s%s%s"
5757 "\\newcommand{\\OneBodyLine}[2]{%\n"
5759 "\\hspace*{#1\\stepsize}%\n"
5760 "\\bodylinecmd{#2}\\\\["
5763 (begindoc "\\begin{document}\n\\begin{center}\n")
5764 (title (format "%s%s%s%s"
5766 (allout-latex-verb-quote (if allout-title
5769 (error "<unnamed buffer>"))
5772 "\\end{center}\n\n"))
5773 (hsize "\\hsize = 7.5 true in\n")
5774 (hoffset "\\hoffset = -1.5 true in\n")
5775 (vspace "\\vspace{.1cm}\n\n"))
5776 (insert (concat doc-style
5791 ;;;_ > allout-insert-latex-trailer (buffer)
5792 (defun allout-insert-latex-trailer (buffer)
5793 "Insert concluding LaTeX commands at point in BUFFER."
5795 (insert "\n\\end{document}\n"))
5796 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5797 (defun allout-latexify-one-item (depth _prefix bullet text
)
5798 "Insert LaTeX commands for formatting one outline item.
5800 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5801 BULLET string, and a list of TEXT strings for the body."
5802 (let* ((head-line (if text
(car text
)))
5803 (body-lines (cdr text
))
5807 (insert (concat "\\OneHeadLine{\\verb\1 "
5808 (allout-latex-verb-quote bullet
)
5813 (allout-latex-verb-quote head-line
)
5816 (if (not body-lines
)
5818 ;;(insert "\\beginlines\n")
5819 (insert "\\begin{verbatim}\n")
5821 (setq curr-line
(car body-lines
))
5822 (if (and (not body-content
)
5823 (not (string-match "^\\s-*$" curr-line
)))
5824 (setq body-content t
))
5825 ; Mangle any occurrences of
5826 ; "\end{verbatim}" in text,
5828 (if (and body-content
5829 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
5830 (setq curr-line
(concat (substring curr-line
0 bop
)
5832 (substring curr-line bop
))))
5833 ;;(insert "|" (car body-lines) "|")
5835 (allout-latex-verbatim-quote-curr-line)
5837 (setq body-lines
(cdr body-lines
)))
5839 (setq body-content nil
)
5843 ;;(insert "\\endlines\n")
5844 (insert "\\end{verbatim}\n")
5846 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5847 (defun allout-latexify-exposed (arg &optional tobuf
)
5848 "Format current topics exposed portions to TOBUF for LaTeX processing.
5849 TOBUF defaults to a buffer named the same as the current buffer, but
5850 with \"*\" prepended and \" latex-formed*\" appended.
5852 With repeat count, copy the exposed portions of entire buffer."
5857 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5858 (let* ((start-pt (point))
5859 (beg (if arg
(point-min) (allout-back-to-current-heading)))
5860 (end (if arg
(point-max) (allout-end-of-current-subtree)))
5861 (buf (current-buffer)))
5864 (allout-insert-latex-header tobuf
)
5865 (goto-char (point-max))
5866 (allout-process-exposed 'allout-latexify-one-item
5871 (goto-char (point-max))
5872 (allout-insert-latex-trailer tobuf
)
5873 (goto-char (point-min))
5875 (goto-char start-pt
)))
5878 ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue)
5879 (defun allout-toggle-current-subtree-encryption (&optional keymode-cue
)
5880 "Encrypt clear or decrypt encoded topic text.
5882 Allout uses Emacs ‘epg’ library to perform encryption. Symmetric
5883 and keypair encryption are supported. All encryption is ascii
5886 Entry encryption defaults to symmetric key mode unless keypair
5887 recipients are associated with the file (see
5888 `epa-file-encrypt-to') or the function is invoked with a
5889 \(KEYMODE-CUE) universal argument greater than 1.
5891 When encrypting, KEYMODE-CUE universal argument greater than 1
5892 causes prompting for recipients for public-key keypair
5893 encryption. Selecting no recipients results in symmetric key
5896 Further, encrypting with a KEYMODE-CUE universal argument greater
5897 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5898 the specified recipients with the file, replacing those currently
5899 associated with it. This can be used to dissociate any
5900 recipients with the file, by selecting no recipients in the
5903 Encrypted topic's bullets are set to a `~' to signal that the
5904 contents of the topic (body and subtopics, but not heading) is
5905 pending encryption or encrypted. `*' asterisk immediately after
5906 the bullet signals that the body is encrypted, its absence means
5907 the topic is meant to be encrypted but is not currently. When a
5908 file with topics pending encryption is saved, topics pending
5909 encryption are encrypted. See `allout-encrypt-unencrypted-on-saves'
5910 for auto-encryption specifics.
5912 \*NOTE WELL* that automatic encryption that happens during saves will
5913 default to symmetric encryption -- you must deliberately (re)encrypt key-pair
5914 encrypted topics if you want them to continue to use the key-pair cipher.
5916 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5917 encrypted. If you want to encrypt the contents of a top-level topic, use
5918 \\[allout-shift-in] to increase its depth."
5921 (allout-back-to-current-heading)
5922 (allout-toggle-subtree-encryption keymode-cue
)))
5923 ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue)
5924 (defun allout-toggle-subtree-encryption (&optional keymode-cue
)
5925 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5927 Entry encryption defaults to symmetric key mode unless keypair
5928 recipients are associated with the file (see
5929 `epa-file-encrypt-to') or the function is invoked with a
5930 \(KEYMODE-CUE) universal argument greater than 1.
5932 When encrypting, KEYMODE-CUE universal argument greater than 1
5933 causes prompting for recipients for public-key keypair
5934 encryption. Selecting no recipients results in symmetric key
5937 Further, encrypting with a KEYMODE-CUE universal argument greater
5938 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5939 the specified recipients with the file, replacing those currently
5940 associated with it. This can be used to dissociate any
5941 recipients with the file, by selecting no recipients in the
5944 Encryption and decryption uses the Emacs ‘epg’ library.
5946 Encrypted text will be ascii-armored.
5948 See `allout-toggle-current-subtree-encryption' for more details."
5952 (allout-end-of-prefix t
)
5954 (if (= allout-recent-depth
1)
5955 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5956 " shift it in to make it encryptable")))
5958 (let* ((allout-buffer (current-buffer))
5959 ;; for use with allout-auto-save-temporarily-disabled, if necessary:
5960 (was-buffer-saved-size buffer-saved-size
)
5962 (bullet-pos allout-recent-prefix-beginning
)
5963 (after-bullet-pos (point))
5965 (progn (if (= (point-max) after-bullet-pos
)
5966 (error "no body to encrypt"))
5967 (allout-encrypted-topic-p)))
5968 (was-collapsed (if (not (search-forward "\n" nil t
))
5972 (subtree-beg (1+ (point)))
5973 (subtree-end (allout-end-of-subtree))
5974 (subject-text (buffer-substring-no-properties subtree-beg
5976 (subtree-end-char (char-after (1- subtree-end
)))
5977 (subtree-trailing-char (char-after subtree-end
))
5978 ;; kluge -- result-text needs to be nil, but we also want to
5979 ;; check for the error condition
5980 (result-text (if (or (string= "" subject-text
)
5981 (string= "\n" subject-text
))
5982 (error "No topic contents to %scrypt"
5983 (if was-encrypted
"de" "en"))
5985 ;; Assess key parameters:
5986 (was-coding-system buffer-file-coding-system
))
5988 (when (not was-encrypted
)
5989 ;; ensure that non-ascii chars pending encryption are noticed before
5990 ;; they're encrypted, so the coding system is set to accommodate
5992 (setq buffer-file-coding-system
5993 (allout-select-safe-coding-system subtree-beg subtree-end
))
5994 ;; if the coding system for the text being encrypted is different
5995 ;; than that prevailing, then there a real risk that the coding
5996 ;; system can't be noticed by emacs when the file is visited. to
5997 ;; mitigate that, offer to preserve the coding system using a file
5999 (if (and (not (equal buffer-file-coding-system
6002 (format (concat "Register coding system %s as file local"
6003 " var? Necessary when only encrypted text"
6004 " is in that coding system. ")
6005 buffer-file-coding-system
)))
6006 (allout-adjust-file-variable "buffer-file-coding-system"
6007 buffer-file-coding-system
)))
6010 (allout-encrypt-string subject-text was-encrypted
6011 (current-buffer) keymode-cue
))
6013 ;; Replace the subtree with the processed product.
6016 (set-buffer allout-buffer
)
6017 (delete-region subtree-beg subtree-end
)
6018 (insert result-text
)
6020 (allout-flag-region (1- subtree-beg
) (point) t
))
6021 ;; adjust trailing-blank-lines to preserve topic spacing:
6022 (if (not was-encrypted
)
6023 (if (and (= subtree-end-char ?
\n)
6024 (= subtree-trailing-char ?
\n))
6025 (insert subtree-trailing-char
)))
6026 ;; Ensure that the item has an encrypted-entry bullet:
6027 (if (not (string= (buffer-substring-no-properties
6028 (1- after-bullet-pos
) after-bullet-pos
)
6029 allout-topic-encryption-bullet
))
6030 (progn (goto-char (1- after-bullet-pos
))
6032 (insert allout-topic-encryption-bullet
)))
6034 ;; Remove the is-encrypted bullet qualifier:
6035 (progn (goto-char after-bullet-pos
)
6037 ;; Add the is-encrypted bullet qualifier:
6038 (goto-char after-bullet-pos
)
6041 ;; adjust buffer's auto-save eligibility:
6043 (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size
)
6044 (allout-maybe-resume-auto-save-info-after-encryption))
6046 (run-hook-with-args 'allout-structure-added-functions
6047 bullet-pos subtree-end
))))
6049 (declare-function epg-context-set-passphrase-callback
"epg"
6050 (context passphrase-callback
))
6051 (declare-function epg-list-keys
"epg" (context &optional name mode
))
6052 (declare-function epg-decrypt-string
"epg" (context cipher
))
6053 (declare-function epg-encrypt-string
"epg"
6054 (context plain recipients
&optional sign always-trust
))
6055 (declare-function epg-user-id-string
"epg" (user-id) t
)
6056 (declare-function epg-key-user-id-list
"epg" (key) t
)
6058 ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
6059 ;;; &optional rejected)
6060 (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue
6062 "Encrypt or decrypt message TEXT.
6064 Returns the resulting string, or nil if the transformation fails.
6066 If DECRYPT is true (default false), then decrypt instead of encrypt.
6068 ALLOUT-BUFFER identifies the buffer containing the text.
6070 Entry encryption defaults to symmetric key mode unless keypair
6071 recipients are associated with the file (see
6072 `epa-file-encrypt-to') or the function is invoked with a
6073 \(KEYMODE-CUE) universal argument greater than 1.
6075 When encrypting, KEYMODE-CUE universal argument greater than 1
6076 causes prompting for recipients for public-key keypair
6077 encryption. Selecting no recipients results in symmetric key
6080 Further, encrypting with a KEYMODE-CUE universal argument greater
6081 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
6082 the specified recipients with the file, replacing those currently
6083 associated with it. This can be used to dissociate any
6084 recipients with the file, by selecting no recipients in the
6087 Optional REJECTED is for internal use, to convey the number of
6088 rejections due to matches against
6089 `allout-encryption-ciphertext-rejection-regexps', as limited by
6090 `allout-encryption-ciphertext-rejection-ceiling'.
6092 NOTE: A few GnuPG v2 versions improperly preserve incorrect
6093 symmetric decryption keys, preventing entry of the correct key on
6094 subsequent decryption attempts until the cache times-out. That
6095 can take several minutes. (Decryption of other entries is not
6096 affected.) Upgrade your EasyPG version, if you can, and you can
6097 deliberately clear your gpg-agent's cache by sending it a `-HUP'
6103 (let* ((epg-context (let* ((context (epg-make-context nil t
)))
6104 (epg-context-set-passphrase-callback
6105 context
#'epa-passphrase-callback-function
)
6108 (encoding (with-current-buffer allout-buffer
6109 buffer-file-coding-system
))
6110 (multibyte (with-current-buffer allout-buffer
6111 enable-multibyte-characters
))
6112 ;; "sanitization" avoids encryption results that are outline structure.
6113 (sani-regexps 'allout-encryption-plaintext-sanitization-regexps
)
6114 (strip-plaintext-regexps (if (not decrypt
)
6115 (allout-get-configvar-values
6117 (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps
)
6118 (reject-ciphertext-regexps (if (not decrypt
)
6119 (allout-get-configvar-values
6120 rejection-regexps
)))
6121 (rejected (or rejected
0))
6122 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6124 (keypair-mode (cond (decrypt 'decrypting
)
6125 ((<= (prefix-numeric-value keymode-cue
) 1)
6127 ((<= (prefix-numeric-value keymode-cue
) 4)
6129 ((> (prefix-numeric-value keymode-cue
) 4)
6131 (keypair-message (concat "Select encryption recipients.\n"
6132 "Symmetric encryption is done if no"
6133 " recipients are selected. "))
6134 (encrypt-to (and (boundp 'epa-file-encrypt-to
) epa-file-encrypt-to
))
6140 ;; Massage the subject text for encoding and filtering.
6143 ;; convey the text characteristics of the original buffer:
6144 (set-buffer-multibyte multibyte
)
6146 (set-buffer-file-coding-system encoding
)
6148 (encode-coding-region (point-min) (point-max) encoding
)))
6150 ;; remove sanitization regexps matches before encrypting:
6151 (when (and strip-plaintext-regexps
(not decrypt
))
6152 (dolist (re strip-plaintext-regexps
)
6153 (let ((re (if (listp re
) (car re
) re
))
6154 (replacement (if (listp re
) (cadr re
) "")))
6155 (goto-char (point-min))
6157 (while (re-search-forward re nil t
)
6158 (replace-match replacement nil nil
))))))
6159 (setq massaged-text
(buffer-substring-no-properties (point-min)
6161 ;; determine key mode and, if keypair, recipients:
6167 (default (if encrypt-to
(epg-list-keys epg-context encrypt-to
)))
6169 ((prompt prompt-save
)
6170 (save-window-excursion
6171 (epa-select-keys epg-context keypair-message
)))))
6176 (epg-decrypt-string epg-context
6177 (encode-coding-string massaged-text
6178 (or encoding
'utf-8
)))
6181 (cons (concat (cadr err
) " - gpg version problem?")
6183 (replace-regexp-in-string "\n$" ""
6184 (epg-encrypt-string epg-context
6185 (encode-coding-string massaged-text
6186 (or encoding
'utf-8
))
6189 ;; validate result -- non-empty
6190 (if (not result-text
)
6191 (error "%scryption failed." (if decrypt
"De" "En")))
6194 (when (eq keypair-mode
'prompt-save
)
6195 ;; set epa-file-encrypt-to in the buffer:
6196 (setq epa-file-encrypt-to
(mapcar (lambda (key)
6198 (car (epg-key-user-id-list key
))))
6200 ;; change the file variable:
6201 (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to
))
6204 ;; Retry (within limit) if ciphertext contains rejections:
6206 ;; Check for disqualification of this ciphertext:
6207 (let ((regexps reject-ciphertext-regexps
)
6209 (while (and regexps
(not reject-it
))
6210 (setq reject-it
(string-match (car regexps
) result-text
))
6213 (setq rejections-left
(1- rejections-left
))
6214 (if (<= rejections-left
0)
6215 (error (concat "Ciphertext rejected too many times"
6217 allout-encryption-ciphertext-rejection-ceiling
6218 'allout-encryption-ciphertext-rejection-regexps
)
6219 ;; try again (gpg-agent may have the key cached):
6220 (allout-encrypt-string text decrypt allout-buffer keypair-mode
6223 ;; Barf if encryption yields extraordinary control chars:
6225 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6227 (error (concat "Encryption produced non-armored text, which"
6228 "conflicts with allout mode -- reconfigure!")))
6230 ;;;_ > allout-inhibit-auto-save-info-for-decryption
6231 (defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size)
6232 "Temporarily prevent auto-saves in this buffer when an item is decrypted.
6234 WAS-BUFFER-SAVED-SIZE is the value of `buffer-saved-size' *before*
6236 (when (not (or (= buffer-saved-size -
1) (= was-buffer-saved-size -
1)))
6237 (setq allout-auto-save-temporarily-disabled was-buffer-saved-size
6238 buffer-saved-size -
1)))
6239 ;;;_ > allout-maybe-resume-auto-save-info-after-encryption ()
6240 (defun allout-maybe-resume-auto-save-info-after-encryption ()
6241 "Restore auto-save info, *if* there are no topics pending encryption."
6242 (when (and allout-auto-save-temporarily-disabled
6243 (= buffer-saved-size -
1)
6247 (goto-char (point-min))
6248 (not (allout-next-topic-pending-encryption)))))
6249 (setq buffer-saved-size allout-auto-save-temporarily-disabled
6250 allout-auto-save-temporarily-disabled nil
)))
6252 ;;;_ > allout-encrypted-topic-p ()
6253 (defun allout-encrypted-topic-p ()
6254 "True if the current topic is encryptable and encrypted."
6256 (allout-end-of-prefix t
)
6257 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6258 allout-topic-encryption-bullet
)
6259 (save-match-data (looking-at "\\*")))
6262 ;;;_ > allout-next-topic-pending-encryption ()
6263 (defun allout-next-topic-pending-encryption ()
6264 "Return the point of the next topic pending encryption, or nil if none.
6266 Such a topic has the `allout-topic-encryption-bullet' without an
6267 immediately following `*' that would mark the topic as being encrypted.
6268 It must also have content."
6269 (let (done got content-beg
)
6273 (if (not (re-search-forward
6274 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6275 (regexp-quote allout-header-prefix
)
6276 (regexp-quote allout-topic-encryption-bullet
))
6280 (goto-char (setq got
(match-beginning 0)))
6281 (if (save-match-data (looking-at "\n"))
6288 ((not (search-forward "\n"))
6297 (setq content-beg
(point))
6299 (allout-end-of-subtree)
6300 (if (<= (point) content-beg
)
6312 ;;;_ > allout-encrypt-decrypted ()
6313 (defun allout-encrypt-decrypted ()
6314 "Encrypt topics pending encryption except those containing exemption point.
6316 If a topic that is currently being edited was encrypted, we return a list
6317 containing the location of the topic and the location of the cursor just
6318 before the topic was encrypted. This can be used, eg, to decrypt the topic
6319 and exactly resituate the cursor if this is being done as part of a file
6320 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6325 (let* ((current-mark (point-marker))
6326 (current-mark-position (marker-position current-mark
))
6329 editing-topic editing-point
)
6330 (goto-char (point-min))
6331 (while (allout-next-topic-pending-encryption)
6332 (setq was-modified
(buffer-modified-p))
6333 (when (save-excursion
6334 (and (boundp 'allout-encrypt-unencrypted-on-saves
)
6335 allout-encrypt-unencrypted-on-saves
6336 (setq bo-subtree
(re-search-forward "$"))
6337 (not (allout-hidden-p))
6338 (>= current-mark
(point))
6339 (allout-end-of-current-subtree)
6340 (<= current-mark
(point))))
6341 (setq editing-topic
(point)
6342 ;; we had to wait for this 'til now so prior topics are
6343 ;; encrypted, any relevant text shifts are in place:
6344 editing-point
(- current-mark-position
6345 (count-trailing-whitespace-region
6346 bo-subtree current-mark-position
))))
6347 (allout-toggle-subtree-encryption)
6348 (if (not was-modified
)
6349 (set-buffer-modified-p nil
))
6351 (if (not was-modified
)
6352 (set-buffer-modified-p nil
))
6353 (if editing-topic
(list editing-topic editing-point
))
6359 ;;;_ #9 miscellaneous
6361 ;;;_ > outlineify-sticky ()
6362 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6364 (defalias 'outlinify-sticky
'outlineify-sticky
)
6366 (defun outlineify-sticky (&optional _arg
)
6367 "Activate outline mode and establish file var so it is started subsequently.
6369 See `allout-layout' and customization of `allout-auto-activation'
6370 for details on preparing Emacs for automatic allout activation."
6374 (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
6378 (goto-char (point-min))
6379 (if (allout-goto-prefix)
6381 (allout-open-topic 2)
6382 (insert (substitute-command-keys
6383 (concat "Dummy outline topic header -- see"
6384 " ‘allout-mode’ docstring: ‘\\[describe-mode]’.")))
6385 (allout-adjust-file-variable
6386 "allout-layout" (or allout-layout
'(-1 : 0))))))
6387 ;;;_ > allout-file-vars-section-data ()
6388 (defun allout-file-vars-section-data ()
6389 "Return data identifying the file-vars section, or nil if none.
6391 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6392 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6393 (let (beg prefix suffix
)
6395 (goto-char (point-max))
6396 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move
)
6397 (if (let ((case-fold-search t
))
6398 (not (search-forward "Local Variables:" nil t
)))
6400 (setq beg
(- (point) 16))
6401 (setq suffix
(buffer-substring-no-properties
6403 (progn (if (search-forward "\n" nil t
)
6406 (setq prefix
(buffer-substring-no-properties
6407 (progn (if (search-backward "\n" nil t
)
6411 (list beg prefix suffix
))
6415 ;;;_ > allout-adjust-file-variable (varname value)
6416 (defun allout-adjust-file-variable (varname value
)
6417 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6419 This activity is inhibited if either `enable-local-variables' or
6420 `allout-enable-file-variable-adjustment' are nil.
6422 When enabled, an entry for the variable is created if not already present,
6423 or changed if established with a different value. The section for the file
6424 variables, itself, is created if not already present. When created, the
6425 section lines (including the section line) exist as second-level topics in
6426 a top-level topic at the end of the file.
6428 `enable-local-variables' must be true for any of this to happen."
6429 (if (not (and enable-local-variables
6430 allout-enable-file-variable-adjustment
))
6433 (let ((inhibit-field-text-motion t
)
6434 (section-data (allout-file-vars-section-data))
6437 (setq beg
(car section-data
)
6438 prefix
(cadr section-data
)
6439 suffix
(car (cddr section-data
)))
6440 ;; create the section
6441 (goto-char (point-max))
6443 (allout-open-topic 0)
6445 (insert "Local emacs vars.\n")
6446 (allout-open-topic 1)
6449 prefix
(buffer-substring-no-properties (progn
6454 (insert "Local variables:\n")
6455 (allout-open-topic 0)
6458 ;; look for existing entry or create one, leaving point for insertion
6461 (allout-show-to-offshoot)
6462 (if (search-forward (concat "\n" prefix varname
":") nil t
)
6463 (let* ((value-beg (point))
6464 (line-end (progn (if (search-forward "\n" nil t
)
6467 (value-end (- line-end
(length suffix
))))
6468 (if (> value-end value-beg
)
6469 (delete-region value-beg value-end
)))
6473 (insert (concat prefix varname
":")))
6474 (insert (format " %S%s" value suffix
))
6479 ;;;_ > allout-get-configvar-values (varname)
6480 (defun allout-get-configvar-values (configvar-name)
6481 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6483 The user is prompted for removal of symbols that are unbound, and they
6484 otherwise are ignored.
6486 CONFIGVAR-NAME should be the name of the configuration variable,
6489 (let ((configvar-value (symbol-value configvar-name
))
6491 (dolist (sym configvar-value
)
6492 (if (not (boundp sym
))
6493 (if (yes-or-no-p (format-message
6494 "%s entry `%s' is unbound -- remove it? "
6495 configvar-name sym
))
6496 (delq sym
(symbol-value configvar-name
)))
6497 (push (symbol-value sym
) got
)))
6500 ;;;_ > allout-mark-topic ()
6501 (defun allout-mark-topic ()
6502 "Put the region around topic currently containing point."
6504 (let ((inhibit-field-text-motion t
))
6505 (beginning-of-line))
6506 (allout-goto-prefix-doublechecked)
6508 (allout-end-of-current-subtree)
6509 (exchange-point-and-mark))
6511 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6512 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
6513 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6515 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6517 (let ((new-prompt prompt
)
6521 (message "%s" new-prompt
)
6523 ;; We do our own reading here, so we can circumvent, eg, special
6524 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6526 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
6529 (cond ((string-match (regexp-quote got
) string
) got
)
6530 ((and do-defaulting
(string= got
"\r"))
6531 ;; Return empty string to default:
6533 ((string= got
"\C-g") (signal 'quit nil
))
6535 (setq new-prompt
(concat prompt
6541 ;; got something out of loop -- return it:
6545 ;;;_ > regexp-sans-escapes (string)
6546 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
6547 "Return a copy of REGEXP with all character escapes stripped out.
6549 Representations of actual backslashes -- ‘\\\\\\\\’ -- are left as a
6552 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6554 (if (string= regexp
"")
6556 ;; Set successive-backslashes to number if current char is
6557 ;; backslash, or else to nil:
6558 (setq successive-backslashes
6559 (if (= (aref regexp
0) ?
\\)
6560 (if successive-backslashes
(1+ successive-backslashes
) 1)
6562 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
6563 ;; Include first char:
6564 (concat (substring regexp
0 1)
6565 (regexp-sans-escapes (substring regexp
1)))
6566 ;; Exclude first char, but maintain count:
6567 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
6568 ;;;_ > count-trailing-whitespace-region (beg end)
6569 (defun count-trailing-whitespace-region (beg end
)
6570 "Return number of trailing whitespace chars between BEG and END.
6572 If BEG is bigger than END we return 0."
6579 (while (re-search-forward "[ ][ ]*$" end t
)
6580 (goto-char (1+ (match-beginning 2)))
6581 (setq count
(1+ count
)))
6583 ;;;_ > allout-format-quote (string)
6584 (defun allout-format-quote (string)
6585 "Return a copy of string with all \"%\" characters doubled."
6587 (mapcar (lambda (char) (if (= char ?%
) "%%" (char-to-string char
)))
6590 ;;;_ > allout-flatten (list)
6591 (defun allout-flatten (list)
6592 "Return a list of all atoms in list."
6594 (cond ((null list
) nil
)
6595 ((atom (car list
)) (cons (car list
) (allout-flatten (cdr list
))))
6596 (t (append (allout-flatten (car list
)) (allout-flatten (cdr list
))))))
6597 ;;;_ : Compatibility:
6598 ;;;_ : xemacs undo-in-progress provision:
6599 (unless (boundp 'undo-in-progress
)
6600 (defvar undo-in-progress nil
6601 "Placeholder defvar for XEmacs compatibility from allout.el.")
6602 (defadvice undo-more
(around allout activate
)
6603 ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
6604 (let ((undo-in-progress t
)) ad-do-it
)))
6606 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6607 (defun allout-mark-marker (&optional force buffer
)
6608 "Accommodate the different signature for `mark-marker' across Emacsen.
6610 XEmacs takes two optional args, while Emacs does not,
6611 so pass them along when appropriate."
6612 (if (featurep 'xemacs
)
6613 (apply 'mark-marker force buffer
)
6615 ;;;_ > subst-char-in-string if necessary
6616 (if (not (fboundp 'subst-char-in-string
))
6617 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
6618 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6619 Unless optional argument INPLACE is non-nil, return a new string."
6620 (let ((i (length string
))
6621 (newstr (if inplace string
(copy-sequence string
))))
6624 (if (eq (aref newstr i
) fromchar
)
6625 (aset newstr i tochar
)))
6627 ;;;_ > wholenump if necessary
6628 (if (not (fboundp 'wholenump
))
6629 (defalias 'wholenump
'natnump
))
6630 ;;;_ > remove-overlays if necessary
6631 (if (not (fboundp 'remove-overlays
))
6632 (defun remove-overlays (&optional beg end name val
)
6633 "Clear BEG and END of overlays whose property NAME has value VAL.
6634 Overlays might be moved and/or split.
6635 BEG and END default respectively to the beginning and end of buffer."
6636 (unless beg
(setq beg
(point-min)))
6637 (unless end
(setq end
(point-max)))
6639 (setq beg
(prog1 end
(setq end beg
))))
6641 (dolist (o (overlays-in beg end
))
6642 (when (eq (overlay-get o name
) val
)
6643 ;; Either push this overlay outside beg...end
6644 ;; or split it to exclude beg...end
6645 ;; or delete it entirely (if it is contained in beg...end).
6646 (if (< (overlay-start o
) beg
)
6647 (if (> (overlay-end o
) end
)
6649 (move-overlay (copy-overlay o
)
6650 (overlay-start o
) beg
)
6651 (move-overlay o end
(overlay-end o
)))
6652 (move-overlay o
(overlay-start o
) beg
))
6653 (if (> (overlay-end o
) end
)
6654 (move-overlay o end
(overlay-end o
))
6655 (delete-overlay o
)))))))
6657 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6658 (if (not (fboundp 'copy-overlay
))
6659 (defun copy-overlay (o)
6660 "Return a copy of overlay O."
6661 (let ((o1 (make-overlay (overlay-start o
) (overlay-end o
)
6662 ;; FIXME: there's no easy way to find the
6663 ;; insertion-type of the two markers.
6664 (overlay-buffer o
)))
6665 (props (overlay-properties o
)))
6667 (overlay-put o1
(pop props
) (pop props
)))
6669 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6670 (if (not (fboundp 'add-to-invisibility-spec
))
6671 (defun add-to-invisibility-spec (element)
6672 "Add ELEMENT to `buffer-invisibility-spec'.
6673 See documentation for `buffer-invisibility-spec' for the kind of elements
6675 (if (eq buffer-invisibility-spec t
)
6676 (setq buffer-invisibility-spec
(list t
)))
6677 (setq buffer-invisibility-spec
6678 (cons element buffer-invisibility-spec
))))
6679 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6680 (if (not (fboundp 'remove-from-invisibility-spec
))
6681 (defun remove-from-invisibility-spec (element)
6682 "Remove ELEMENT from `buffer-invisibility-spec'."
6683 (if (consp buffer-invisibility-spec
)
6684 (setq buffer-invisibility-spec
(delete element
6685 buffer-invisibility-spec
)))))
6686 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6687 (if (not (fboundp 'move-beginning-of-line
))
6688 (defun move-beginning-of-line (arg)
6689 "Move point to beginning of current line as displayed.
6690 \(This disregards invisible newlines such as those
6691 which are part of the text that an image rests on.)
6693 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6694 If point reaches the beginning or end of buffer, it stops there.
6695 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6697 (or arg
(setq arg
1))
6699 (condition-case nil
(line-move (1- arg
)) (error nil
)))
6701 ;; Move to beginning-of-line, ignoring fields and invisible text.
6702 (skip-chars-backward "^\n")
6703 (while (and (not (bobp))
6705 (get-char-property (1- (point)) 'invisible
)))
6706 (if (eq buffer-invisibility-spec t
)
6708 (or (memq prop buffer-invisibility-spec
)
6709 (assq prop buffer-invisibility-spec
)))))
6710 (goto-char (if (featurep 'xemacs
)
6711 (previous-property-change (point))
6712 (previous-char-property-change (point))))
6713 (skip-chars-backward "^\n"))
6714 (vertical-motion 0))
6716 ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
6717 (if (not (fboundp 'move-end-of-line
))
6718 (defun move-end-of-line (arg)
6719 "Move point to end of current line as displayed.
6720 \(This disregards invisible newlines such as those
6721 which are part of the text that an image rests on.)
6723 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6724 If point reaches the beginning or end of buffer, it stops there.
6725 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6727 (or arg
(setq arg
1))
6732 (let ((goal-column 0))
6733 (and (condition-case nil
6734 (or (line-move arg
) t
)
6742 (get-char-property (1- (point))
6744 (if (eq buffer-invisibility-spec t
)
6747 buffer-invisibility-spec
)
6749 buffer-invisibility-spec
)))))
6751 (previous-char-property-change (point))))
6755 (if (and (> (point) newpos
)
6756 (eq (preceding-char) ?
\n))
6758 (if (and (> (point) newpos
) (not (eobp))
6759 (not (eq (following-char) ?
\n)))
6760 ;; If we skipped something intangible
6761 ;; and now we're not really at eol,
6766 ;;;_ > allout-next-single-char-property-change -- alias unless lacking
6767 (defalias 'allout-next-single-char-property-change
6768 (if (fboundp 'next-single-char-property-change
)
6769 'next-single-char-property-change
6770 'next-single-property-change
)
6771 ;; No docstring because xemacs defalias doesn't support it.
6773 ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
6774 (defalias 'allout-previous-single-char-property-change
6775 (if (fboundp 'previous-single-char-property-change
)
6776 'previous-single-char-property-change
6777 'previous-single-property-change
)
6778 ;; No docstring because xemacs defalias doesn't support it.
6780 ;;;_ > allout-select-safe-coding-system
6781 (defalias 'allout-select-safe-coding-system
6782 (if (fboundp 'select-safe-coding-system
)
6783 'select-safe-coding-system
6784 'detect-coding-region
)
6786 ;;;_ > allout-substring-no-properties
6787 ;; define as alias first, so byte compiler is happy.
6788 (defalias 'allout-substring-no-properties
'substring-no-properties
)
6789 ;; then supplant with definition if underlying alias absent.
6790 (if (not (fboundp 'substring-no-properties
))
6791 (defun allout-substring-no-properties (string &optional start end
)
6792 (substring string
(or start
0) end
))
6796 ;;;_ > allout-bullet-isearch (&optional bullet)
6797 (defun allout-bullet-isearch (&optional bullet
)
6798 "Isearch (regexp) for topic with bullet BULLET."
6801 (setq bullet
(solicit-char-in-string
6802 "ISearch for topic with bullet: "
6803 (regexp-sans-escapes allout-bullets-string
))))
6805 (let ((isearch-regexp t
)
6806 (isearch-string (concat "^"
6807 allout-header-prefix
6810 (isearch-repeat 'forward
)
6813 ;;;_ #11 Unit tests -- this should be last item before "Provide"
6814 ;;;_ > allout-run-unit-tests ()
6815 (defun allout-run-unit-tests ()
6816 "Run the various allout unit tests."
6817 (message "Running allout tests...")
6818 (allout-test-resumptions)
6819 (message "Running allout tests... Done.")
6821 ;;;_ : test resumptions:
6822 ;;;_ > allout-tests-obliterate-variable (name)
6823 (defun allout-tests-obliterate-variable (name)
6824 "Completely unbind variable with NAME."
6825 (if (local-variable-p name
(current-buffer)) (kill-local-variable name
))
6826 (while (boundp name
) (makunbound name
)))
6827 ;;;_ > allout-test-resumptions ()
6828 (defvar allout-tests-globally-unbound nil
6829 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6830 (defvar allout-tests-globally-true nil
6831 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6832 (defvar allout-tests-locally-true nil
6833 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6834 (defun allout-test-resumptions ()
6835 "Exercise allout resumptions."
6836 ;; for each resumption case, we also test that the right local/global
6837 ;; scopes are affected during resumption effects:
6839 ;; ensure that previously unbound variables return to the unbound state.
6841 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6842 (allout-add-resumptions '(allout-tests-globally-unbound t
))
6843 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6844 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6845 (assert (boundp 'allout-tests-globally-unbound
))
6846 (assert (equal allout-tests-globally-unbound t
))
6847 (allout-do-resumptions)
6848 (assert (not (local-variable-p 'allout-tests-globally-unbound
6850 (assert (not (boundp 'allout-tests-globally-unbound
))))
6852 ;; ensure that variable with prior global value is resumed
6854 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6855 (setq allout-tests-globally-true t
)
6856 (allout-add-resumptions '(allout-tests-globally-true nil
))
6857 (assert (equal (default-value 'allout-tests-globally-true
) t
))
6858 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6859 (assert (equal allout-tests-globally-true nil
))
6860 (allout-do-resumptions)
6861 (assert (not (local-variable-p 'allout-tests-globally-true
6863 (assert (boundp 'allout-tests-globally-true
))
6864 (assert (equal allout-tests-globally-true t
)))
6866 ;; ensure that prior local value is resumed
6868 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6869 (set (make-local-variable 'allout-tests-locally-true
) t
)
6870 (assert (not (default-boundp 'allout-tests-locally-true
))
6871 nil
(concat "Test setup mistake -- variable supposed to"
6872 " not have global binding, but it does."))
6873 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer))
6874 nil
(concat "Test setup mistake -- variable supposed to have"
6875 " local binding, but it lacks one."))
6876 (allout-add-resumptions '(allout-tests-locally-true nil
))
6877 (assert (not (default-boundp 'allout-tests-locally-true
)))
6878 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6879 (assert (equal allout-tests-locally-true nil
))
6880 (allout-do-resumptions)
6881 (assert (boundp 'allout-tests-locally-true
))
6882 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6883 (assert (equal allout-tests-locally-true t
))
6884 (assert (not (default-boundp 'allout-tests-locally-true
))))
6886 ;; ensure that last of multiple resumptions holds, for various scopes.
6888 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6889 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6890 (setq allout-tests-globally-true t
)
6891 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6892 (set (make-local-variable 'allout-tests-locally-true
) t
)
6893 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6894 '(allout-tests-globally-true nil
)
6895 '(allout-tests-locally-true nil
))
6896 (allout-add-resumptions '(allout-tests-globally-unbound 2)
6897 '(allout-tests-globally-true 3)
6898 '(allout-tests-locally-true 4))
6899 ;; reestablish many of the basic conditions are maintained after re-add:
6900 (assert (not (default-boundp 'allout-tests-globally-unbound
)))
6901 (assert (local-variable-p 'allout-tests-globally-unbound
(current-buffer)))
6902 (assert (equal allout-tests-globally-unbound
2))
6903 (assert (default-boundp 'allout-tests-globally-true
))
6904 (assert (local-variable-p 'allout-tests-globally-true
(current-buffer)))
6905 (assert (equal allout-tests-globally-true
3))
6906 (assert (not (default-boundp 'allout-tests-locally-true
)))
6907 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6908 (assert (equal allout-tests-locally-true
4))
6909 (allout-do-resumptions)
6910 (assert (not (local-variable-p 'allout-tests-globally-unbound
6912 (assert (not (boundp 'allout-tests-globally-unbound
)))
6913 (assert (not (local-variable-p 'allout-tests-globally-true
6915 (assert (boundp 'allout-tests-globally-true
))
6916 (assert (equal allout-tests-globally-true t
))
6917 (assert (boundp 'allout-tests-locally-true
))
6918 (assert (local-variable-p 'allout-tests-locally-true
(current-buffer)))
6919 (assert (equal allout-tests-locally-true t
))
6920 (assert (not (default-boundp 'allout-tests-locally-true
))))
6922 ;; ensure that deliberately unbinding registered variables doesn't foul things
6924 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6925 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6926 (setq allout-tests-globally-true t
)
6927 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6928 (set (make-local-variable 'allout-tests-locally-true
) t
)
6929 (allout-add-resumptions '(allout-tests-globally-unbound t
)
6930 '(allout-tests-globally-true nil
)
6931 '(allout-tests-locally-true nil
))
6932 (allout-tests-obliterate-variable 'allout-tests-globally-unbound
)
6933 (allout-tests-obliterate-variable 'allout-tests-globally-true
)
6934 (allout-tests-obliterate-variable 'allout-tests-locally-true
)
6935 (allout-do-resumptions))
6937 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
6938 (when allout-run-unit-tests-on-load
6939 (allout-run-unit-tests))
6944 ;;;_* Local emacs vars.
6945 ;; The following `allout-layout' local variable setting:
6946 ;; - closes all topics from the first topic to just before the third-to-last,
6947 ;; - shows the children of the third to last (config vars)
6948 ;; - and the second to last (code section),
6949 ;; - and closes the last topic (this local-variables section).
6951 ;;allout-layout: (0 : -1 -1 0)
6954 ;;; allout.el ends here