Warn if --without-pop is now the default
[emacs.git] / lisp / allout.el
blobd0be847aa79e1b0c3600ef3342c7a0608ca3a109
1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992-1994, 2001-2017 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
8 ;; Version: 2.3
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 <https://www.gnu.org/licenses/>.
27 ;;; Commentary:
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
44 ;; docstring.
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
49 ;; outline styles
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.
55 ;; and more.
57 ;; See the `allout-mode' function's docstring for an introduction to the
58 ;; mode.
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)
75 ;;; Code:
77 (declare-function epa-passphrase-callback-function
78 "epa" (context key-id handback))
80 ;;;_* Dependency loads
81 (require 'overlay)
82 (eval-when-compile
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.
86 (require 'cl)
89 ;;;_* USER CUSTOMIZATION VARIABLES:
91 ;;;_ > defgroup allout, allout-keybindings
92 (defgroup allout nil
93 "Extensive outline minor-mode, for use stand-alone and with other modes.
95 See Allout Auto Activation for automatic activation."
96 :prefix "allout-"
97 :group 'outlines)
98 (defgroup allout-keybindings nil
99 "Allout outline mode keyboard bindings configuration."
100 :group 'allout)
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:
133 (when varname
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)
139 (define-key map
140 ;; XXX vector vs non-vector key descriptions?
141 (vconcat allout-command-prefix
142 (car (read-from-string (car entry))))
143 (cadr 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
148 map global-map)
149 (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line
150 map global-map)
151 (substitute-key-definition 'end-of-line 'allout-end-of-line
152 map global-map)
153 (substitute-key-definition 'move-end-of-line 'allout-end-of-line
154 map global-map)
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."
159 ;; Architecture:
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
173 ;; been invoked:
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."
181 :type 'string
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."
187 :type '(repeat
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
240 prevails."
241 :version "24.1"
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."
265 :version "24.1"
266 :type 'allout-keybindings-binding
267 :group 'allout-keybindings
268 :set 'allout-compose-and-institute-keymap
271 ;;;_ > allout-auto-activation-helper (var value)
272 ;;;###autoload
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)
278 (allout-setup))
279 ;;;_ > allout-setup ()
280 ;;;###autoload
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
293 ;;;###autoload
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.
309 Auto-layout is not.
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))
318 :group 'allout)
319 (allout-setup)
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),
336 where:
337 -- negative numbers force the topic to be closed before opening
338 to the absolute value of the number, so all siblings are open
339 only to that level.
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)
354 Examples:
355 (-2 : 0)
356 Collapse the top-level topics to show their children and
357 grandchildren, but completely collapse the final top-level topic.
358 (-1 () : 1 0)
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.
363 (-2 : -1 *)
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
374 :group 'allout)
375 ;;;_ : allout-layout-type
376 (define-widget 'allout-layout-type 'lazy
377 "Allout layout format customization basic building blocks."
378 :type '(repeat
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,
398 `allout-auto-fill'."
399 :type 'boolean
400 :group 'allout)
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."
405 :version "24.1"
406 :type 'boolean
407 :group 'allout)
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."
415 :type 'boolean
416 :group 'allout)
417 (make-variable-buffer-local 'allout-use-hanging-indents)
418 ;;;###autoload
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
423 'text)
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
428 the header.
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))
434 :group 'allout)
436 (make-variable-buffer-local 'allout-reindent-bodies)
437 ;;;###autoload
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
444 just the header."
445 :type 'boolean
446 :group 'allout)
447 (make-variable-buffer-local 'allout-show-bodies)
448 ;;;###autoload
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
460 advance as follows:
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
481 repeated calls."
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
491 advance as follows:
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
506 calls."
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'."
519 :type 'string
520 :group 'allout)
521 (make-variable-buffer-local 'allout-header-prefix)
522 ;;;###autoload
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
535 bullets."
536 :type 'string
537 :group 'allout)
538 (make-variable-buffer-local 'allout-primary-bullet)
539 ;;;###autoload
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
546 bullets.
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."
552 :type 'string
553 :group 'allout)
554 (make-variable-buffer-local 'allout-plain-bullets-string)
555 ;;;###autoload
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
570 themselves:
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
593 bullets.
595 You must run `allout-set-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
599 strings."
600 :type 'string
601 :group 'allout)
602 (make-variable-buffer-local 'allout-distinctive-bullets-string)
603 ;;;###autoload
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
635 undesired.]"
636 :type '(choice (const t) (const nil) string
637 (const allout-mode-leaders)
638 (const comment-start))
639 :group 'allout)
640 ;;;###autoload
641 (put 'allout-use-mode-specific-leader 'safe-local-variable
642 (lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start))
643 (stringp x))))
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."
667 :type 'boolean
668 :group 'allout)
669 (make-variable-buffer-local 'allout-old-style-prefixes)
670 ;;;###autoload
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
683 prefixes:
685 * Top level
686 .* A topic
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
692 . #2 Another
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):
699 * Top level
700 .* A topic
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
706 . #2 Another
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'
715 is non-nil."
716 :type 'boolean
717 :group 'allout)
718 (make-variable-buffer-local 'allout-stylish-prefixes)
719 ;;;###autoload
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)
732 :group 'allout)
733 (make-variable-buffer-local 'allout-numbered-bullet)
734 ;;;###autoload
735 (put 'allout-numbered-bullet 'safe-local-variable
736 (if (fboundp 'string-or-null-p)
737 '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)
745 :group 'allout)
746 ;;;###autoload
747 (put 'allout-file-xref-bullet 'safe-local-variable
748 (if (fboundp 'string-or-null-p)
749 '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."
754 :type 'integer
755 :group 'allout)
757 (make-variable-buffer-local 'allout-presentation-padding)
758 ;;;###autoload
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."
768 :version "24.1"
769 :type 'boolean
770 :group 'allout)
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."
776 :type 'boolean
777 :group 'allout)
778 ;;;_ - allout-label-style
779 (defcustom allout-label-style "\\large\\bf"
780 "Font and size of labels for LaTeX formatting of an outline."
781 :type 'string
782 :group 'allout)
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."
786 :type 'string
787 :group 'allout)
788 ;;;_ - allout-body-line-style
789 (defcustom allout-body-line-style " "
790 "Font and size of entries for LaTeX formatting of an outline."
791 :type 'string
792 :group 'allout)
793 ;;;_ - allout-title-style
794 (defcustom allout-title-style "\\Large\\bf"
795 "Font and size of titles for LaTeX formatting of an outline."
796 :type 'string
797 :group 'allout)
798 ;;;_ - allout-title
799 (defcustom allout-title '(or buffer-file-name (buffer-name))
800 "Expression to evaluate to determine the title for LaTeX formatted copy."
801 :type 'sexp
802 :risky t
803 :group 'allout)
804 ;;;_ - allout-line-skip
805 (defcustom allout-line-skip ".05cm"
806 "Space between lines for LaTeX formatting of an outline."
807 :type 'string
808 :group 'allout)
809 ;;;_ - allout-indent
810 (defcustom allout-indent ".3cm"
811 "LaTeX formatted depth-indent spacing."
812 :type 'string
813 :group 'allout)
815 ;;;_ + Topic encryption
816 ;;;_ = allout-encryption group
817 (defgroup allout-encryption nil
818 "Settings for topic encryption features of allout outliner."
819 :group 'allout)
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)
824 :version "22.1"
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.)"
842 :type 'boolean
843 :version "23.1"
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)
855 ;;;_ + Developer
856 ;;;_ = allout-developer group
857 (defgroup allout-developer nil
858 "Allout settings developers care about, including topic encryption and more."
859 :group 'allout)
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
868 compilation.)
870 See `allout-run-unit-tests' to see what's run."
871 :type 'boolean
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'
884 is nil.
886 Operations potentially causing edits include allout encryption routines.
887 For details, see `allout-toggle-current-subtree-encryption's docstring."
888 :type 'boolean
889 :group 'allout)
890 (make-variable-buffer-local 'allout-enable-file-variable-adjustment)
892 ;;;_* CODE -- no user customizations below.
894 ;;;_ #1 Internal Outline Formatting and Configuration
895 ;;;_ : Version
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."
902 (interactive "P")
903 (let ((msg (concat "Allout Outline Mode v " allout-version)))
904 (if here (insert msg))
905 (message "%s" msg)
906 msg))
907 ;;;_ : Mode activation (defined here because it's referenced early)
908 ;;;_ = allout-mode
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:
926 ;;;Local variables:
927 ;;;allout-layout: (0 : -1 -1 0)
928 ;;;End:
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)
939 ;;;###autoload
940 (put 'allout-layout 'safe-local-variable
941 (lambda (x) (or (numberp x) (listp x) (memq x '(: * + -)))))
943 ;;;_ : Topic header format
944 ;;;_ = allout-regexp
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 `allout-set-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 `allout-set-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 `allout-set-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 `allout-set-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 `allout-set-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 `allout-set-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 (allout-set-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."
1045 (interactive "P")
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)
1051 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:
1058 `comment-start'
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
1069 comment-start
1070 t)))
1071 allout-use-mode-specific-leader
1072 ;; Oops -- garbled value, equate with effect of t:
1073 t)))
1074 (leader
1075 (cond
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))
1084 comment-start
1085 ;; Use comment-start, maybe tripled, and with
1086 ;; underscore:
1087 (concat
1088 (if (string= " "
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:
1095 "_")))))))
1096 (if (not leader)
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
1114 comment-start
1115 (not (eq 'force allout-reindent-bodies)))
1116 (setq allout-reindent-bodies nil)))
1117 ;;;_ > allout-set-regexp ()
1118 (defun allout-set-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."
1126 (interactive)
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))
1132 cur-string
1133 cur-len
1134 cur-char
1135 index)
1136 (while strings
1137 (setq index 0)
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
1143 (cond
1144 ; Single dash would denote a
1145 ; sequence, repeated denotes
1146 ; a dash:
1147 ((eq cur-char ?-) "--")
1148 ; literal close-square-bracket
1149 ; doesn't work right in the
1150 ; expr, exclude it:
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)
1163 "[ \t]*"
1164 ;; already regexp-quoted in a custom way:
1165 "[" allout-bullets-string "]"
1166 "\\)")
1167 old-part (concat "\\("
1168 (regexp-quote allout-primary-bullet)
1169 "\\|"
1170 (regexp-quote allout-header-prefix)
1171 "\\)"
1173 " ?[^" allout-primary-bullet "]")
1174 formfeed-part "\\(\^L\\)"
1176 allout-regexp (concat new-part
1177 "\\|"
1178 old-part
1179 "\\|"
1180 formfeed-part)
1182 allout-line-boundary-regexp (concat "\n" new-part
1183 "\\|"
1184 "\n" old-part
1185 "\\|"
1186 "\n" formfeed-part)
1188 allout-bob-regexp (concat "\\`" new-part
1189 "\\|"
1190 "\\`" old-part
1191 "\\|"
1192 "\\`" formfeed-part
1195 (setq allout-depth-specific-regexp
1196 (concat "\\(^\\|\\`\\)"
1197 "\\("
1199 ;; new-style spacers-then-bullet string:
1200 "\\("
1201 (allout-format-quote (regexp-quote allout-header-prefix))
1202 " \\{%s\\}"
1203 "[" (allout-format-quote allout-bullets-string) "]"
1204 "\\)"
1206 ;; old-style all-bullets string, if primary not multi-char:
1207 (if (< 0 allout-header-subtraction)
1209 (concat "\\|\\("
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))
1216 "\\{%s\\}"
1217 ;; disqualify greater depths:
1218 "[^"
1219 (allout-format-quote allout-primary-bullet)
1220 "]\\)"
1222 "\\)"
1224 (setq allout-depth-one-regexp
1225 (concat "\\(^\\|\\`\\)"
1226 "\\("
1228 "\\("
1229 (regexp-quote allout-header-prefix)
1230 ;; disqualify any bullet char following any amount of
1231 ;; intervening whitespace:
1232 " *"
1233 (concat "[^ " allout-bullets-string "]")
1234 "\\)"
1235 (if (< 0 allout-header-subtraction)
1236 ;; Need not support anything like the old
1237 ;; bullet style if the prefix is multi-char.
1239 (concat "\\|"
1240 (regexp-quote allout-primary-bullet)
1241 ;; disqualify deeper primary-bullet sequences:
1242 "[^" allout-primary-bullet "]"))
1243 "\\)"
1244 ))))
1245 (define-obsolete-function-alias 'set-allout-regexp 'allout-set-regexp "26.1")
1246 ;;;_ : Menu bar
1247 (defvar allout-mode-exposure-menu)
1248 (defvar allout-mode-editing-menu)
1249 (defvar allout-mode-navigation-menu)
1250 (defvar allout-mode-misc-menu)
1251 (defun allout-produce-mode-menubar-entries ()
1252 (require 'easymenu)
1253 (easy-menu-define allout-mode-exposure-menu
1254 allout-mode-map-value
1255 "Allout outline exposure menu."
1256 '("Exposure"
1257 ["Show Entry" allout-show-current-entry t]
1258 ["Show Children" allout-show-children t]
1259 ["Show Subtree" allout-show-current-subtree t]
1260 ["Hide Subtree" allout-hide-current-subtree t]
1261 ["Hide Leaves" allout-hide-current-leaves t]
1262 "----"
1263 ["Show All" allout-show-all t]))
1264 (easy-menu-define allout-mode-editing-menu
1265 allout-mode-map-value
1266 "Allout outline editing menu."
1267 '("Headings"
1268 ["Open Sibling" allout-open-sibtopic t]
1269 ["Open Subtopic" allout-open-subtopic t]
1270 ["Open Supertopic" allout-open-supertopic t]
1271 "----"
1272 ["Shift Topic In" allout-shift-in t]
1273 ["Shift Topic Out" allout-shift-out t]
1274 ["Rebullet Topic" allout-rebullet-topic t]
1275 ["Rebullet Heading" allout-rebullet-current-heading t]
1276 ["Number Siblings" allout-number-siblings t]
1277 "----"
1278 ["Toggle Topic Encryption"
1279 allout-toggle-current-subtree-encryption
1280 (> (allout-current-depth) 1)]))
1281 (easy-menu-define allout-mode-navigation-menu
1282 allout-mode-map-value
1283 "Allout outline navigation menu."
1284 '("Navigation"
1285 ["Next Visible Heading" allout-next-visible-heading t]
1286 ["Previous Visible Heading"
1287 allout-previous-visible-heading t]
1288 "----"
1289 ["Up Level" allout-up-current-level t]
1290 ["Forward Current Level" allout-forward-current-level t]
1291 ["Backward Current Level"
1292 allout-backward-current-level t]
1293 "----"
1294 ["Beginning of Entry"
1295 allout-beginning-of-current-entry t]
1296 ["End of Entry" allout-end-of-entry t]
1297 ["End of Subtree" allout-end-of-current-subtree t]))
1298 (easy-menu-define allout-mode-misc-menu
1299 allout-mode-map-value
1300 "Allout outlines miscellaneous bindings."
1301 '("Misc"
1302 ["Version" allout-version t]
1303 "----"
1304 ["Duplicate Exposed" allout-copy-exposed-to-buffer t]
1305 ["Duplicate Exposed, numbered"
1306 allout-flatten-exposed-to-buffer t]
1307 ["Duplicate Exposed, indented"
1308 allout-indented-exposed-to-buffer t]
1309 "----"
1310 ["Set Header Lead" allout-reset-header-lead t]
1311 ["Set New Exposure" allout-expose-topic t])))
1312 ;;;_ : Allout Modal-Variables Utilities
1313 ;;;_ = allout-mode-prior-settings
1314 (defvar allout-mode-prior-settings nil
1315 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1317 See `allout-add-resumptions' and `allout-do-resumptions'.")
1318 (make-variable-buffer-local 'allout-mode-prior-settings)
1319 ;;;_ > allout-add-resumptions (&rest pairs)
1320 (defun allout-add-resumptions (&rest pairs)
1321 "Set name/value PAIRS.
1323 Old settings are preserved for later resumption using `allout-do-resumptions'.
1325 The new values are set as a buffer local. On resumption, the prior buffer
1326 scope of the variable is restored along with its value. If it was a void
1327 buffer-local value, then it is left as nil on resumption.
1329 The pairs are lists whose car is the name of the variable and car of the
1330 cdr is the new value: `(some-var some-value)'. The pairs can actually be
1331 triples, where the third element qualifies the disposition of the setting,
1332 as described further below.
1334 If the optional third element is the symbol `extend', then the new value
1335 created by `cons'ing the second element of the pair onto the front of the
1336 existing value.
1338 If the optional third element is the symbol `append', then the new value is
1339 extended from the existing one by `append'ing a list containing the second
1340 element of the pair onto the end of the existing value.
1342 Extension, and resumptions in general, should not be used for hook
1343 functions -- use the `local' mode of `add-hook' for that, instead.
1345 The settings are stored on `allout-mode-prior-settings'."
1346 (while pairs
1347 (let* ((pair (pop pairs))
1348 (name (car pair))
1349 (value (cadr pair))
1350 (qualifier (if (> (length pair) 2)
1351 (caddr pair)))
1352 prior-value)
1353 (if (not (symbolp name))
1354 (error "Pair's name, %S, must be a symbol, not %s"
1355 name (type-of name)))
1356 (setq prior-value (condition-case nil
1357 (symbol-value name)
1358 (void-variable nil)))
1359 (when (not (assoc name allout-mode-prior-settings))
1360 ;; Not already added as a resumption, create the prior setting entry.
1361 (if (local-variable-p name (current-buffer))
1362 ;; is already local variable -- preserve the prior value:
1363 (push (list name prior-value) allout-mode-prior-settings)
1364 ;; wasn't local variable, indicate so for resumption by killing
1365 ;; local value, and make it local:
1366 (push (list name) allout-mode-prior-settings)
1367 (make-local-variable name)))
1368 (if qualifier
1369 (cond ((eq qualifier 'extend)
1370 (if (not (listp prior-value))
1371 (error "extension of non-list prior value attempted")
1372 (set name (cons value prior-value))))
1373 ((eq qualifier 'append)
1374 (if (not (listp prior-value))
1375 (error "appending of non-list prior value attempted")
1376 (set name (append prior-value (list value)))))
1377 (t (error "unrecognized setting qualifier `%s' encountered"
1378 qualifier)))
1379 (set name value)))))
1380 ;;;_ > allout-do-resumptions ()
1381 (defun allout-do-resumptions ()
1382 "Resume all name/value settings registered by `allout-add-resumptions'.
1384 This is used when concluding allout-mode, to resume selected variables to
1385 their settings before allout-mode was started."
1387 (while allout-mode-prior-settings
1388 (let* ((pair (pop allout-mode-prior-settings))
1389 (name (car pair))
1390 (value-cell (cdr pair)))
1391 (if (not value-cell)
1392 ;; Prior value was global:
1393 (kill-local-variable name)
1394 ;; Prior value was explicit:
1395 (set name (car value-cell))))))
1396 ;;;_ : Mode-specific incidentals
1397 ;;;_ > allout-unprotected (expr)
1398 (defmacro allout-unprotected (expr)
1399 "Enable internal outline operations to alter invisible text."
1400 `(let ((inhibit-read-only (if (not buffer-read-only) t))
1401 (inhibit-field-text-motion t))
1402 ,expr))
1403 ;;;_ = allout-mode-hook
1404 (defvar allout-mode-hook nil
1405 "Hook run when allout mode starts.")
1406 ;;;_ = allout-mode-deactivate-hook
1407 (define-obsolete-variable-alias 'allout-mode-deactivate-hook
1408 'allout-mode-off-hook "24.1")
1409 (defvar allout-mode-deactivate-hook nil
1410 "Hook run when allout mode ends.")
1411 ;;;_ = allout-exposure-category
1412 (defvar allout-exposure-category nil
1413 "Symbol for use as allout invisible-text overlay category.")
1415 ;;;_ = allout-exposure-change-functions
1416 (define-obsolete-variable-alias 'allout-exposure-change-hook
1417 'allout-exposure-change-functions "24.3")
1418 (defcustom allout-exposure-change-functions nil
1419 "Abnormal hook run after allout outline subtree exposure changes.
1420 It is run at the conclusion of `allout-flag-region'.
1422 Functions on the hook must take three arguments:
1424 - FROM -- integer indicating the point at the start of the change.
1425 - TO -- integer indicating the point of the end of the change.
1426 - FLAG -- change mode: nil for exposure, otherwise concealment.
1428 This hook might be invoked multiple times by a single command."
1429 :type 'hook
1430 :group 'allout
1431 :version "24.3")
1433 ;;;_ = allout-structure-added-functions
1434 (define-obsolete-variable-alias 'allout-structure-added-hook
1435 'allout-structure-added-functions "24.3")
1436 (defcustom allout-structure-added-functions nil
1437 "Abnormal hook run after adding items to an Allout outline.
1438 Functions on the hook should take two arguments:
1440 - NEW-START -- integer indicating position of start of the first new item.
1441 - NEW-END -- integer indicating position of end of the last new item.
1443 This hook might be invoked multiple times by a single command."
1444 :type 'hook
1445 :group 'allout
1446 :version "24.3")
1448 ;;;_ = allout-structure-deleted-functions
1449 (define-obsolete-variable-alias 'allout-structure-deleted-hook
1450 'allout-structure-deleted-functions "24.3")
1451 (defcustom allout-structure-deleted-functions nil
1452 "Abnormal hook run after deleting subtrees from an Allout outline.
1453 Functions on the hook must take two arguments:
1455 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1456 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1458 Some edits that remove or invalidate items may be missed by this hook:
1459 specifically edits that native allout routines do not control.
1461 This hook might be invoked multiple times by a single command."
1462 :type 'hook
1463 :group 'allout
1464 :version "24.3")
1466 ;;;_ = allout-structure-shifted-functions
1467 (define-obsolete-variable-alias 'allout-structure-shifted-hook
1468 'allout-structure-shifted-functions "24.3")
1469 (defcustom allout-structure-shifted-functions nil
1470 "Abnormal hook run after shifting items in an Allout outline.
1471 Functions on the hook should take two arguments:
1473 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1474 - START -- integer indicating the start point of the shifted parent item.
1476 Some edits that shift items can be missed by this hook: specifically edits
1477 that native allout routines do not control.
1479 This hook might be invoked multiple times by a single command."
1480 :type 'hook
1481 :group 'allout
1482 :version "24.3")
1484 ;;;_ = allout-after-copy-or-kill-hook
1485 (defcustom allout-after-copy-or-kill-hook nil
1486 "Normal hook run after copying outline text.."
1487 :type 'hook
1488 :group 'allout
1489 :version "24.3")
1491 ;;;_ = allout-post-undo-hook
1492 (defcustom allout-post-undo-hook nil
1493 "Normal hook run after undo activity.
1494 The item that's current when the hook is run *may* be the one
1495 that was affected by the undo.."
1496 :type 'hook
1497 :group 'allout
1498 :version "24.3")
1500 ;;;_ = allout-outside-normal-auto-fill-function
1501 (defvar allout-outside-normal-auto-fill-function nil
1502 "Value of `normal-auto-fill-function' outside of allout mode.
1504 Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function'
1505 wrapped within allout's automatic `fill-prefix' setting.")
1506 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function)
1507 ;;;_ = prevent redundant activation by desktop mode:
1508 (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil))
1509 ;;;_ = allout-passphrase-verifier-string
1510 (defvar allout-passphrase-verifier-string nil
1511 "Setting used to test solicited encryption passphrases against the one
1512 already associated with a file.
1514 It consists of an encrypted random string useful only to verify that a
1515 passphrase entered by the user is effective for decryption. The passphrase
1516 itself is *not* recorded in the file anywhere, and the encrypted contents
1517 are random binary characters to avoid exposing greater susceptibility to
1518 search attacks.
1520 The verifier string is retained as an Emacs file variable, as well as in
1521 the Emacs buffer state, if file variable adjustments are enabled. See
1522 `allout-enable-file-variable-adjustment' for details about that.")
1523 (make-variable-buffer-local 'allout-passphrase-verifier-string)
1524 (make-obsolete-variable 'allout-passphrase-verifier-string
1525 'allout-passphrase-verifier-string "23.3")
1526 ;;;###autoload
1527 (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp)
1528 ;;;_ = allout-passphrase-hint-string
1529 (defvar allout-passphrase-hint-string ""
1530 "Variable used to retain reminder string for file's encryption passphrase.
1532 See the description of `allout-passphrase-hint-handling' for details about how
1533 the reminder is deployed.
1535 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1536 state, if file variable adjustments are enabled. See
1537 `allout-enable-file-variable-adjustment' for details about that.")
1538 (make-variable-buffer-local 'allout-passphrase-hint-string)
1539 (setq-default allout-passphrase-hint-string "")
1540 (make-obsolete-variable 'allout-passphrase-hint-string
1541 'allout-passphrase-hint-string "23.3")
1542 ;;;###autoload
1543 (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp)
1544 ;;;_ = allout-after-save-decrypt
1545 (defvar allout-after-save-decrypt nil
1546 "Internal variable, is nil or has the value of two points:
1548 - the location of a topic to be decrypted after saving is done
1549 - where to situate the cursor after the decryption is performed
1551 This is used to decrypt the topic that was currently being edited, if it
1552 was encrypted automatically as part of a file write or autosave.")
1553 (make-variable-buffer-local 'allout-after-save-decrypt)
1554 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1555 (defvar allout-encryption-plaintext-sanitization-regexps nil
1556 "List of regexps whose matches are removed from plaintext before encryption.
1558 This is for the sake of removing artifacts, like escapes, that are added on
1559 and not actually part of the original plaintext. The removal is done just
1560 prior to encryption.
1562 Entries must be symbols that are bound to the desired values.
1564 Each value can be a regexp or a list with a regexp followed by a
1565 substitution string. If it's just a regexp, all its matches are removed
1566 before the text is encrypted. If it's a regexp and a substitution, the
1567 substitution is used against the regexp matches, a la `replace-match'.")
1568 (make-variable-buffer-local 'allout-encryption-plaintext-sanitization-regexps)
1569 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1570 (defvar allout-encryption-ciphertext-rejection-regexps nil
1571 "Variable for regexps matching plaintext to remove before encryption.
1573 This is used to detect strings in encryption results that would
1574 register as allout mode structural elements, for example, as a
1575 topic prefix.
1577 Entries must be symbols that are bound to the desired regexp values.
1579 Encryptions that result in matches will be retried, up to
1580 `allout-encryption-ciphertext-rejection-limit' times, after which
1581 an error is raised.")
1583 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps)
1584 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1585 (defvar allout-encryption-ciphertext-rejection-ceiling 5
1586 "Limit on number of times encryption ciphertext is rejected.
1588 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1589 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling)
1590 ;;;_ > allout-mode-p ()
1591 ;; Must define this macro above any uses, or byte compilation will lack
1592 ;; proper def, if file isn't loaded -- eg, during emacs build!
1593 ;;;###autoload
1594 (defmacro allout-mode-p ()
1595 "Return t if `allout-mode' is active in current buffer."
1596 'allout-mode)
1597 ;;;_ > allout-write-contents-hook-handler ()
1598 (defun allout-write-contents-hook-handler ()
1599 "Implement `allout-encrypt-unencrypted-on-saves' for file writes
1601 Return nil if all goes smoothly, or else return an informative
1602 message if an error is encountered. The message will serve as a
1603 non-nil return on `write-contents-functions' to prevent saving of
1604 the buffer while it has decrypted content.
1606 This behavior depends on Emacs versions that implement the
1607 `write-contents-functions' hook."
1609 (if (or (not (allout-mode-p))
1610 (not (boundp 'allout-encrypt-unencrypted-on-saves))
1611 (not allout-encrypt-unencrypted-on-saves))
1613 (if (save-excursion (goto-char (point-min))
1614 (allout-next-topic-pending-encryption))
1615 (progn
1616 (message "auto-encrypting pending topics")
1617 (sit-for 0)
1618 (condition-case failure
1619 (progn
1620 (setq allout-after-save-decrypt
1621 (allout-encrypt-decrypted))
1622 ;; aok - return nil:
1623 nil)
1624 (error
1625 ;; whoops - probably some still-decrypted items, return non-nil:
1626 (let ((text (format (concat "%s contents write inhibited due to"
1627 " encrypted topic encryption error:"
1628 " %s")
1629 (buffer-name (current-buffer))
1630 failure)))
1631 (message text)(sit-for 2)
1632 text)))))
1634 ;;;_ > allout-after-saves-handler ()
1635 (defun allout-after-saves-handler ()
1636 "Decrypt topic encrypted for save, if it's currently being edited.
1638 Ie, if it was pending encryption and contained the point in its body before
1639 the save.
1641 We use values stored in `allout-after-save-decrypt' to locate the topic
1642 and the place for the cursor after the decryption is done."
1643 (if (not (and (allout-mode-p)
1644 (boundp 'allout-after-save-decrypt)
1645 allout-after-save-decrypt))
1647 (goto-char (car allout-after-save-decrypt))
1648 (let ((was-modified (buffer-modified-p)))
1649 (allout-toggle-subtree-encryption)
1650 (if (not was-modified)
1651 (set-buffer-modified-p nil)))
1652 (goto-char (cadr allout-after-save-decrypt))
1653 (setq allout-after-save-decrypt nil))
1655 ;;;_ > allout-called-interactively-p ()
1656 (defmacro allout-called-interactively-p ()
1657 "A version of `called-interactively-p' independent of Emacs version."
1658 ;; ... to ease maintenance of allout without betraying deprecation.
1659 (if (ignore-errors (called-interactively-p 'interactive) t)
1660 '(called-interactively-p 'interactive)
1661 '(called-interactively-p)))
1662 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1663 ;; In some exceptional moments, disparate topic depths need to be allowed
1664 ;; momentarily, eg when one topic is being yanked into another and they're
1665 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1666 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1667 ;; processing to happen in the presence of such discrepancies. It should
1668 ;; almost never be needed, however.
1669 (defvar allout-inhibit-aberrance-doublecheck nil
1670 "Internal state, for momentarily inhibits aberrance doublecheck.
1672 This should only be momentarily let-bound non-nil, not set
1673 non-nil in a lasting way.")
1675 ;;;_ #2 Mode environment and activation
1676 ;;;_ = allout-explicitly-deactivated
1677 (defvar allout-explicitly-deactivated nil
1678 "If t, `allout-mode's last deactivation was deliberate.
1679 So `allout-post-command-business' should not reactivate it...")
1680 (make-variable-buffer-local 'allout-explicitly-deactivated)
1681 ;;;_ > allout-init (mode)
1682 (defun allout-init (mode)
1683 "DEPRECATED - configure allout activation by customizing
1684 `allout-auto-activation'. This function remains around, limited
1685 from what it did before, for backwards compatibility.
1687 MODE is the activation mode - see `allout-auto-activation' for
1688 valid values."
1689 (declare (obsolete allout-auto-activation "23.3"))
1690 (custom-set-variables (list 'allout-auto-activation (format "%s" mode)))
1691 (format "%s" mode))
1693 ;;;_ > allout-setup-menubar ()
1694 (defun allout-setup-menubar ()
1695 "Populate the current buffer's menubar with `allout-mode' stuff."
1696 (let ((menus (list allout-mode-exposure-menu
1697 allout-mode-editing-menu
1698 allout-mode-navigation-menu
1699 allout-mode-misc-menu))
1700 cur)
1701 (while menus
1702 (setq cur (car menus)
1703 menus (cdr menus))
1704 (easy-menu-add cur))))
1705 ;;;_ > allout-overlay-preparations
1706 (defun allout-overlay-preparations ()
1707 "Set the properties of the allout invisible-text overlay and others."
1708 (setplist 'allout-exposure-category nil)
1709 (put 'allout-exposure-category 'invisible 'allout)
1710 (put 'allout-exposure-category 'evaporate t)
1711 ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
1712 ;; latter would be sufficient, but it seems that a separate behavior --
1713 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1714 ;; presence of the isearch-open-invisible property -- even though this
1715 ;; property controls the isearch _arrival_ behavior. This is the case at
1716 ;; least in emacs 21, 22.1, and xemacs 21.4.
1717 (put 'allout-exposure-category 'isearch-open-invisible
1718 'allout-isearch-end-handler)
1719 (if (featurep 'xemacs)
1720 (put 'allout-exposure-category 'start-open t)
1721 (put 'allout-exposure-category 'insert-in-front-hooks
1722 '(allout-overlay-insert-in-front-handler)))
1723 (put 'allout-exposure-category 'modification-hooks
1724 '(allout-overlay-interior-modification-handler)))
1725 ;;;_ > define-minor-mode allout-mode
1726 ;;;_ : Defun:
1727 ;;;###autoload
1728 (define-minor-mode allout-mode
1729 ;;;_ . Doc string:
1730 "Toggle Allout outline mode.
1731 With a prefix argument ARG, enable Allout outline mode if ARG is
1732 positive, and disable it otherwise. If called from Lisp, enable
1733 the mode if ARG is omitted or nil.
1735 \\<allout-mode-map-value>
1736 Allout outline mode is a minor mode that provides extensive
1737 outline oriented formatting and manipulation. It enables
1738 structural editing of outlines, as well as navigation and
1739 exposure. It also is specifically aimed at accommodating
1740 syntax-sensitive text like programming languages. (For example,
1741 see the allout code itself, which is organized as an allout
1742 outline.)
1744 In addition to typical outline navigation and exposure, allout includes:
1746 - topic-oriented authoring, including keystroke-based topic creation,
1747 repositioning, promotion/demotion, cut, and paste
1748 - incremental search with dynamic exposure and reconcealment of hidden text
1749 - adjustable format, so programming code can be developed in outline-structure
1750 - easy topic encryption and decryption, symmetric or key-pair
1751 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1752 - integral outline layout, for automatic initial exposure when visiting a file
1753 - independent extensibility, using comprehensive exposure and authoring hooks
1755 and many other features.
1757 Below is a description of the key bindings, and then description
1758 of special `allout-mode' features and terminology. See also the
1759 outline menubar additions for quick reference to many of the
1760 features. Customize `allout-auto-activation' to prepare your
1761 Emacs session for automatic activation of `allout-mode'.
1763 The bindings are those listed in `allout-prefixed-keybindings'
1764 and `allout-unprefixed-keybindings'. We recommend customizing
1765 `allout-command-prefix' to use just `\\C-c' as the command
1766 prefix, if the allout bindings don't conflict with any personal
1767 bindings you have on \\C-c. In any case, outline structure
1768 navigation and authoring is simplified by positioning the cursor
1769 on an item's bullet character, the \"hot-spot\" -- then you can
1770 invoke allout commands with just the un-prefixed,
1771 un-control-shifted command letters. This is described further in
1772 the HOT-SPOT Operation section.
1774 Exposure Control:
1775 ----------------
1776 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1777 \\[allout-show-children] `allout-show-children'
1778 \\[allout-show-current-subtree] `allout-show-current-subtree'
1779 \\[allout-show-current-entry] `allout-show-current-entry'
1780 \\[allout-show-all] `allout-show-all'
1782 Navigation:
1783 ----------
1784 \\[allout-next-visible-heading] `allout-next-visible-heading'
1785 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1786 \\[allout-up-current-level] `allout-up-current-level'
1787 \\[allout-forward-current-level] `allout-forward-current-level'
1788 \\[allout-backward-current-level] `allout-backward-current-level'
1789 \\[allout-end-of-entry] `allout-end-of-entry'
1790 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1791 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1792 if immediately repeated cycles to the beginning of the current item
1793 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1796 Topic Header Production:
1797 -----------------------
1798 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1799 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1800 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1802 Topic Level and Prefix Adjustment:
1803 ---------------------------------
1804 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1805 \\[allout-shift-out] `allout-shift-out' ... less deep
1806 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1807 current topic
1808 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1809 its offspring -- distinctive bullets are not changed, others
1810 are alternated according to nesting depth.
1811 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1812 the offspring are not affected.
1813 With repeat count, revoke numbering.
1815 Topic-oriented Killing and Yanking:
1816 ----------------------------------
1817 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1818 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1819 \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure.
1820 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1821 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1822 depth of heading if yanking into bare topic
1823 heading (ie, prefix sans text).
1824 \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'.
1826 Topic-oriented Encryption:
1827 -------------------------
1828 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1829 Encrypt/Decrypt topic content
1831 Misc commands:
1832 -------------
1833 M-x outlineify-sticky Activate outline mode for current buffer,
1834 and establish a default file-var setting
1835 for `allout-layout'.
1836 \\[allout-mark-topic] `allout-mark-topic'
1837 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1838 Duplicate outline, sans concealed text, to
1839 buffer with name derived from derived from that
1840 of current buffer -- \"*BUFFERNAME exposed*\".
1841 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1842 Like above `copy-exposed', but convert topic
1843 prefixes to section.subsection... numeric
1844 format.
1845 \\[customize-variable] allout-auto-activation
1846 Prepare Emacs session for allout outline mode
1847 auto-activation.
1849 Topic Encryption
1851 Outline mode supports gpg encryption of topics, with support for
1852 symmetric and key-pair modes, and auto-encryption of topics
1853 pending encryption on save.
1855 Topics pending encryption are, by default, automatically
1856 encrypted during file saves, including checkpoint saves, to avoid
1857 exposing the plain text of encrypted topics in the file system.
1858 If the content of the topic containing the cursor was encrypted
1859 for a save, it is automatically decrypted for continued editing.
1861 NOTE: A few GnuPG v2 versions improperly preserve incorrect
1862 symmetric decryption keys, preventing entry of the correct key on
1863 subsequent decryption attempts until the cache times-out. That
1864 can take several minutes. (Decryption of other entries is not
1865 affected.) Upgrade your EasyPG version, if you can, and you can
1866 deliberately clear your gpg-agent's cache by sending it a `-HUP'
1867 signal.
1869 See `allout-toggle-current-subtree-encryption' function docstring
1870 and `allout-encrypt-unencrypted-on-saves' customization variable
1871 for details.
1873 HOT-SPOT Operation
1875 Hot-spot operation provides a means for easy, single-keystroke outline
1876 navigation and exposure control.
1878 When the text cursor is positioned directly on the bullet character of
1879 a topic, regular characters (a to z) invoke the commands of the
1880 corresponding allout-mode keymap control chars. For example, \"f\"
1881 would invoke the command typically bound to \"C-c<space>C-f\"
1882 \(\\[allout-forward-current-level] `allout-forward-current-level').
1884 Thus, by positioning the cursor on a topic bullet, you can
1885 execute the outline navigation and manipulation commands with a
1886 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1887 this special translation, so you can use them to get out of the
1888 hot-spot and back to normal editing operation.
1890 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
1891 replaced with one that makes it easy to get to the hot-spot. If you
1892 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1893 is set) to the beginning of the item and then, if you hit it again
1894 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1895 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1896 at the beginning of the current entry.
1898 Extending Allout
1900 Allout exposure and authoring activities all have associated
1901 hooks, by which independent code can cooperate with allout
1902 without changes to the allout core. Here are key ones:
1904 `allout-mode-hook'
1905 `allout-mode-deactivate-hook' (deprecated)
1906 `allout-mode-off-hook'
1907 `allout-exposure-change-functions'
1908 `allout-structure-added-functions'
1909 `allout-structure-deleted-functions'
1910 `allout-structure-shifted-functions'
1911 `allout-after-copy-or-kill-hook'
1912 `allout-post-undo-hook'
1914 Terminology
1916 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1918 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1919 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1920 and with no intervening items of lower DEPTH than the container.
1921 CURRENT ITEM:
1922 The visible ITEM most immediately containing the cursor.
1923 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1924 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1925 called the:
1926 LEVEL: The same as DEPTH.
1928 ANCESTORS:
1929 Those ITEMs whose TOPICs contain an ITEM.
1930 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1931 of the ITEM.
1932 OFFSPRING:
1933 The ITEMs contained within an ITEM's TOPIC.
1934 SUBTOPIC:
1935 An OFFSPRING of its ANCESTOR TOPICs.
1936 CHILD:
1937 An immediate SUBTOPIC of its PARENT.
1938 SIBLINGS:
1939 TOPICs having the same PARENT and DEPTH.
1941 Topic text constituents:
1943 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1944 text.
1945 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1946 the HEADER text and distinct from the ITEM PREFIX.
1947 BODY: Same as ENTRY.
1948 PREFIX: The leading text of an ITEM which distinguishes it from normal
1949 ENTRY text. Allout recognizes the outline structure according
1950 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1951 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1952 number, indicating the ordinal number of the topic among its
1953 siblings, or an asterisk indicating encryption, plus an optional
1954 space. After that is the ITEM HEADER text, which is not part of
1955 the PREFIX.
1957 The relative length of the PREFIX determines the nesting DEPTH
1958 of the ITEM.
1959 PREFIX-LEAD:
1960 The string at the beginning of a HEADER PREFIX, by default a `.'.
1961 It can be customized by changing the setting of
1962 `allout-header-prefix' and then reinitializing `allout-mode'.
1964 When the PREFIX-LEAD is set to the comment-string of a
1965 programming language, outline structuring can be embedded in
1966 program code without interfering with processing of the text
1967 (by Emacs or the language processor) as program code. This
1968 setting happens automatically when allout mode is used in
1969 programming-mode buffers. See `allout-use-mode-specific-leader'
1970 docstring for more detail.
1971 PREFIX-PADDING:
1972 Spaces or asterisks which separate the PREFIX-LEAD and the
1973 bullet, determining the ITEM's DEPTH.
1974 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1975 the characters listed on `allout-plain-bullets-string' or
1976 `allout-distinctive-bullets-string'. When creating a TOPIC,
1977 plain BULLETs are by default used, according to the DEPTH of the
1978 TOPIC. Choice among the distinctive BULLETs is offered when you
1979 provide a universal argument (\\[universal-argument]) to the
1980 TOPIC creation command, or when explicitly rebulleting a TOPIC. The
1981 significance of the various distinctive bullets is purely by
1982 convention. See the documentation for the above bullet strings for
1983 more details.
1984 EXPOSURE:
1985 The state of a TOPIC which determines the on-screen visibility
1986 of its OFFSPRING and contained ENTRY text.
1987 CONCEALED:
1988 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1989 text is represented by \"...\" ellipses.
1991 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1992 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1993 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1994 ;;;_ . Code
1995 :lighter " Allout"
1996 :keymap 'allout-mode-map
1998 (let ((use-layout (if (listp allout-layout)
1999 allout-layout
2000 allout-default-layout)))
2002 (if (not (allout-mode-p))
2003 (progn
2004 ;; Deactivation:
2006 ; Activation not explicitly
2007 ; requested, and either in
2008 ; active state or *de*activation
2009 ; specifically requested:
2010 (allout-do-resumptions)
2012 (remove-from-invisibility-spec '(allout . t))
2013 (remove-hook 'pre-command-hook 'allout-pre-command-business t)
2014 (remove-hook 'post-command-hook 'allout-post-command-business t)
2015 (remove-hook 'before-change-functions 'allout-before-change-handler t)
2016 (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t)
2017 (remove-hook 'write-contents-functions
2018 'allout-write-contents-hook-handler t)
2020 (remove-overlays (point-min) (point-max)
2021 'category 'allout-exposure-category))
2023 ;; Activating:
2024 (if allout-old-style-prefixes
2025 ;; Inhibit all the fancy formatting:
2026 (allout-add-resumptions '(allout-primary-bullet "*")))
2028 (allout-overlay-preparations) ; Doesn't hurt to redo this.
2030 (allout-infer-header-lead-and-primary-bullet)
2031 (allout-infer-body-reindent)
2033 (allout-set-regexp)
2034 (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
2035 allout-line-boundary-regexp
2036 extend)
2037 '(allout-encryption-ciphertext-rejection-regexps
2038 allout-bob-regexp
2039 extend))
2041 (allout-compose-and-institute-keymap)
2042 (allout-produce-mode-menubar-entries)
2044 (add-to-invisibility-spec '(allout . t))
2046 (allout-add-resumptions '(line-move-ignore-invisible t))
2047 (add-hook 'pre-command-hook 'allout-pre-command-business nil t)
2048 (add-hook 'post-command-hook 'allout-post-command-business nil t)
2049 (add-hook 'before-change-functions 'allout-before-change-handler nil t)
2050 (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t)
2051 (add-hook 'write-contents-functions 'allout-write-contents-hook-handler
2052 nil t)
2054 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2055 ;; func will be used if auto-fill is active or activated. (The
2056 ;; custom func respects topic headline, maintains hanging-indents,
2057 ;; etc.)
2058 (allout-add-resumptions (list 'allout-former-auto-filler
2059 auto-fill-function)
2060 ;; Register allout-auto-fill to be used if
2061 ;; filling is active:
2062 (list 'allout-outside-normal-auto-fill-function
2063 normal-auto-fill-function)
2064 '(normal-auto-fill-function allout-auto-fill)
2065 ;; Paragraphs are broken by topic headlines.
2066 (list 'paragraph-start
2067 (concat paragraph-start "\\|^\\("
2068 allout-regexp "\\)"))
2069 (list 'paragraph-separate
2070 (concat paragraph-separate "\\|^\\("
2071 allout-regexp "\\)")))
2072 (if (and auto-fill-function (not allout-inhibit-auto-fill))
2073 ;; allout-auto-fill will use the stashed values and so forth.
2074 (allout-add-resumptions '(auto-fill-function allout-auto-fill)))
2076 (allout-setup-menubar)
2078 ;; Do auto layout if warranted:
2079 (when (and allout-layout
2080 allout-auto-activation
2081 use-layout
2082 (and (not (string= allout-auto-activation "activate"))
2083 (if (string= allout-auto-activation "ask")
2084 (if (y-or-n-p (format-message
2085 "Expose %s with layout `%s'? "
2086 (buffer-name) use-layout))
2088 (message "Skipped %s layout." (buffer-name))
2089 nil)
2090 t)))
2091 (save-excursion
2092 (message "Adjusting `%s' exposure..." (buffer-name))
2093 (goto-char 0)
2094 (allout-this-or-next-heading)
2095 (condition-case err
2096 (progn
2097 (apply 'allout-expose-topic (list use-layout))
2098 (message "Adjusting `%s' exposure... done."
2099 (buffer-name)))
2100 ;; Problem applying exposure -- notify user, but don't
2101 ;; interrupt, eg, file visit:
2102 (error (message "%s" (car (cdr err)))
2103 (sit-for 1))))
2104 ) ; when allout-layout
2105 ) ; if (allout-mode-p)
2106 ) ; let (())
2107 ) ; define-minor-mode
2108 ;;;_ > allout-minor-mode alias
2109 (defalias 'allout-minor-mode 'allout-mode)
2110 ;;;_ > allout-unload-function
2111 (defun allout-unload-function ()
2112 "Unload the allout outline library."
2113 (save-current-buffer
2114 (dolist (buffer (buffer-list))
2115 (set-buffer buffer)
2116 (when (allout-mode-p) (allout-mode -1))))
2117 ;; continue standard unloading
2118 nil)
2120 ;;;_ - Position Assessment
2121 ;;;_ > allout-hidden-p (&optional pos)
2122 (defsubst allout-hidden-p (&optional pos)
2123 "Non-nil if the character after point was made invisible by allout."
2124 (eq (get-char-property (or pos (point)) 'invisible) 'allout))
2126 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2127 ;;; &optional prelen)
2128 (defun allout-overlay-insert-in-front-handler (ol after beg _end
2129 &optional _prelen)
2130 "Shift the overlay so stuff inserted in front of it is excluded."
2131 (if after
2132 ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
2133 ;; front-advance on the overlay worked as expected?
2134 (move-overlay ol (1+ beg) (overlay-end ol))))
2135 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2136 ;;; &optional prelen)
2137 (defun allout-overlay-interior-modification-handler (ol after beg end
2138 &optional _prelen)
2139 "Get confirmation before making arbitrary changes to invisible text.
2141 We expose the invisible text and ask for confirmation. Refusal or
2142 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2143 reclosing the opened text.
2145 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2146 internal functions use this feature cohesively bunch changes."
2148 (when (and (not inhibit-read-only) (not after))
2149 (let ((start (point))
2150 (ol-start (overlay-start ol))
2151 (ol-end (overlay-end ol))
2152 first)
2153 (goto-char beg)
2154 (while (< (point) end)
2155 (when (allout-hidden-p)
2156 (allout-show-to-offshoot)
2157 (if (allout-hidden-p)
2158 (save-excursion (forward-char 1)
2159 (allout-show-to-offshoot)))
2160 (when (not first)
2161 (setq first (point))))
2162 (goto-char (if (featurep 'xemacs)
2163 (next-property-change (1+ (point)) nil end)
2164 (next-char-property-change (1+ (point)) end))))
2165 (when first
2166 (goto-char first)
2167 (condition-case nil
2168 (if (not
2169 (yes-or-no-p
2170 (substitute-command-keys
2171 (concat "Modify concealed text? (\"no\" just aborts,"
2172 " \\[keyboard-quit] also reconceals) "))))
2173 (progn (goto-char start)
2174 (error "Concealed-text change refused")))
2175 (quit (allout-flag-region ol-start ol-end nil)
2176 (allout-flag-region ol-start ol-end t)
2177 (error "Concealed-text change abandoned, text reconcealed"))))
2178 (goto-char start))))
2179 ;;;_ > allout-before-change-handler (beg end)
2180 (defun allout-before-change-handler (beg end)
2181 "Protect against changes to invisible text.
2183 See `allout-overlay-interior-modification-handler' for details."
2185 (when (and (allout-mode-p) undo-in-progress)
2186 (setq allout-just-did-undo t)
2187 (if (allout-hidden-p)
2188 (allout-show-children)))
2190 ;; allout-overlay-interior-modification-handler on an overlay handles
2191 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2192 (when (and (featurep 'xemacs) (allout-mode-p))
2193 ;; process all of the pending overlays:
2194 (save-excursion
2195 (goto-char beg)
2196 (let ((overlay (allout-get-invisibility-overlay)))
2197 (if overlay
2198 (allout-overlay-interior-modification-handler
2199 overlay nil beg end nil))))))
2200 ;;;_ > allout-isearch-end-handler (&optional overlay)
2201 (defun allout-isearch-end-handler (&optional _overlay)
2202 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2204 Optional OVERLAY parameter is for when this function is used by
2205 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2206 function can also be used as an `isearch-mode-end-hook'."
2208 (if (and (allout-mode-p) (allout-hidden-p))
2209 (allout-show-to-offshoot)))
2211 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2212 ;; All the basic outline functions that directly do string matches to
2213 ;; evaluate heading prefix location set the variables
2214 ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2215 ;; when successful. Functions starting with `allout-recent-' all
2216 ;; use this state, providing the means to avoid redundant searches
2217 ;; for just-established data. This optimization can provide
2218 ;; significant speed improvement, but it must be employed carefully.
2219 ;;;_ = allout-recent-prefix-beginning
2220 (defvar allout-recent-prefix-beginning 0
2221 "Buffer point of the start of the last topic prefix encountered.")
2222 (make-variable-buffer-local 'allout-recent-prefix-beginning)
2223 ;;;_ = allout-recent-prefix-end
2224 (defvar allout-recent-prefix-end 0
2225 "Buffer point of the end of the last topic prefix encountered.")
2226 (make-variable-buffer-local 'allout-recent-prefix-end)
2227 ;;;_ = allout-recent-depth
2228 (defvar allout-recent-depth 0
2229 "Depth of the last topic prefix encountered.")
2230 (make-variable-buffer-local 'allout-recent-depth)
2231 ;;;_ = allout-recent-end-of-subtree
2232 (defvar allout-recent-end-of-subtree 0
2233 "Buffer point last returned by `allout-end-of-current-subtree'.")
2234 (make-variable-buffer-local 'allout-recent-end-of-subtree)
2235 ;;;_ > allout-prefix-data ()
2236 (defsubst allout-prefix-data ()
2237 "Register allout-prefix state data.
2239 For reference by `allout-recent' funcs. Return
2240 the new value of `allout-recent-prefix-beginning'."
2241 (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3))
2242 allout-recent-prefix-beginning (or (match-beginning 1)
2243 (match-beginning 2)
2244 (match-beginning 3))
2245 allout-recent-depth (max 1 (- allout-recent-prefix-end
2246 allout-recent-prefix-beginning
2247 allout-header-subtraction)))
2248 allout-recent-prefix-beginning)
2249 ;;;_ > allout-nullify-prefix-data ()
2250 (defsubst allout-nullify-prefix-data ()
2251 "Mark allout prefix data as being uninformative."
2252 (setq allout-recent-prefix-end (point)
2253 allout-recent-prefix-beginning (point)
2254 allout-recent-depth 0)
2255 allout-recent-prefix-beginning)
2256 ;;;_ > allout-recent-depth ()
2257 (defsubst allout-recent-depth ()
2258 "Return depth of last heading encountered by an outline maneuvering function.
2260 All outline functions which directly do string matches to assess
2261 headings set the variables `allout-recent-prefix-beginning' and
2262 `allout-recent-prefix-end' if successful. This function uses those settings
2263 to return the current depth."
2265 allout-recent-depth)
2266 ;;;_ > allout-recent-prefix ()
2267 (defsubst allout-recent-prefix ()
2268 "Like `allout-recent-depth', but returns text of last encountered prefix.
2270 All outline functions which directly do string matches to assess
2271 headings set the variables `allout-recent-prefix-beginning' and
2272 `allout-recent-prefix-end' if successful. This function uses those settings
2273 to return the current prefix."
2274 (buffer-substring-no-properties allout-recent-prefix-beginning
2275 allout-recent-prefix-end))
2276 ;;;_ > allout-recent-bullet ()
2277 (defmacro allout-recent-bullet ()
2278 "Like `allout-recent-prefix', but returns bullet of last encountered prefix.
2280 All outline functions which directly do string matches to assess
2281 headings set the variables `allout-recent-prefix-beginning' and
2282 `allout-recent-prefix-end' if successful. This function uses those settings
2283 to return the current depth of the most recently matched topic."
2284 '(buffer-substring-no-properties (1- allout-recent-prefix-end)
2285 allout-recent-prefix-end))
2287 ;;;_ #4 Navigation
2289 ;;;_ - Position Assessment
2290 ;;;_ : Location Predicates
2291 ;;;_ > allout-do-doublecheck ()
2292 (defsubst allout-do-doublecheck ()
2293 "True if current item conditions qualify for checking on topic aberrance."
2294 (and
2295 ;; presume integrity of outline and yanked content during yank -- necessary
2296 ;; to allow for level disparity of yank location and yanked text:
2297 (not allout-inhibit-aberrance-doublecheck)
2298 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2299 (<= allout-recent-depth allout-doublecheck-at-and-shallower)))
2300 ;;;_ > allout-aberrant-container-p ()
2301 (defun allout-aberrant-container-p ()
2302 "True if topic, or next sibling with children, contains them discontinuously.
2304 Discontinuous means an immediate offspring that is nested more
2305 than one level deeper than the topic.
2307 If topic has no offspring, then the next sibling with offspring will
2308 determine whether or not this one is determined to be aberrant.
2310 If true, then the allout-recent-* settings are calibrated on the
2311 offspring that qualifies it as aberrant, ie with depth that
2312 exceeds the topic by more than one."
2314 ;; This is most clearly understood when considering standard-prefix-leader
2315 ;; low-level topics, which can all too easily match text not intended as
2316 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2317 ;; following bullet qualifies without this protection. (A sequence of
2318 ;; them can occur naturally, eg a typical textual bullet list.) We
2319 ;; disqualify such low-level sequences when they are followed by a
2320 ;; discontinuously contained child, inferring that the sequences are not
2321 ;; actually connected with their prospective context.
2323 (let ((depth (allout-depth))
2324 (start-point (point))
2325 done aberrant)
2326 (save-match-data
2327 (save-excursion
2328 (while (and (not done)
2329 (re-search-forward allout-line-boundary-regexp nil 0))
2330 (allout-prefix-data)
2331 (goto-char allout-recent-prefix-beginning)
2332 (cond
2333 ;; sibling -- continue:
2334 ((eq allout-recent-depth depth))
2335 ;; first offspring is excessive -- aberrant:
2336 ((> allout-recent-depth (1+ depth))
2337 (setq done t aberrant t))
2338 ;; next non-sibling is lower-depth -- not aberrant:
2339 (t (setq done t))))))
2340 (if aberrant
2341 aberrant
2342 (goto-char start-point)
2343 ;; recalibrate allout-recent-*
2344 (allout-depth)
2345 nil)))
2346 ;;;_ > allout-on-current-heading-p ()
2347 (defun allout-on-current-heading-p ()
2348 "Return non-nil if point is on current visible topics' header line.
2350 Actually, returns prefix beginning point."
2351 (save-excursion
2352 (allout-beginning-of-current-line)
2353 (save-match-data
2354 (and (looking-at allout-regexp)
2355 (allout-prefix-data)
2356 (or (not (allout-do-doublecheck))
2357 (not (allout-aberrant-container-p)))))))
2358 ;;;_ > allout-on-heading-p ()
2359 (defalias 'allout-on-heading-p 'allout-on-current-heading-p)
2360 ;;;_ > allout-e-o-prefix-p ()
2361 (defun allout-e-o-prefix-p ()
2362 "True if point is located where current topic prefix ends, heading begins."
2363 (and (save-match-data
2364 (save-excursion (let ((inhibit-field-text-motion t))
2365 (beginning-of-line))
2366 (looking-at allout-regexp))
2367 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2368 ;;;_ : Location attributes
2369 ;;;_ > allout-depth ()
2370 (defun allout-depth ()
2371 "Return depth of topic most immediately containing point.
2373 Does not do doublecheck for aberrant topic header.
2375 Return zero if point is not within any topic.
2377 Like `allout-current-depth', but respects hidden as well as visible topics."
2378 (save-excursion
2379 (let ((start-point (point)))
2380 (if (and (allout-goto-prefix)
2381 (not (< start-point (point))))
2382 allout-recent-depth
2383 (progn
2384 ;; Oops, no prefix, nullify it:
2385 (allout-nullify-prefix-data)
2386 ;; ... and return 0:
2387 0)))))
2388 ;;;_ > allout-current-depth ()
2389 (defun allout-current-depth ()
2390 "Return depth of visible topic most immediately containing point.
2392 Return zero if point is not within any topic."
2393 (save-excursion
2394 (if (allout-back-to-current-heading)
2395 (max 1
2396 (- allout-recent-prefix-end
2397 allout-recent-prefix-beginning
2398 allout-header-subtraction))
2399 0)))
2400 ;;;_ > allout-get-current-prefix ()
2401 (defun allout-get-current-prefix ()
2402 "Topic prefix of the current topic."
2403 (save-excursion
2404 (if (allout-goto-prefix)
2405 (allout-recent-prefix))))
2406 ;;;_ > allout-get-bullet ()
2407 (defun allout-get-bullet ()
2408 "Return bullet of containing topic (visible or not)."
2409 (save-excursion
2410 (and (allout-goto-prefix)
2411 (allout-recent-bullet))))
2412 ;;;_ > allout-current-bullet ()
2413 (defun allout-current-bullet ()
2414 "Return bullet of current (visible) topic heading, or none if none found."
2415 (condition-case nil
2416 (save-excursion
2417 (allout-back-to-current-heading)
2418 (buffer-substring-no-properties (- allout-recent-prefix-end 1)
2419 allout-recent-prefix-end))
2420 ;; Quick and dirty provision, ostensibly for missing bullet:
2421 (args-out-of-range nil))
2423 ;;;_ > allout-get-prefix-bullet (prefix)
2424 (defun allout-get-prefix-bullet (prefix)
2425 "Return the bullet of the header prefix string PREFIX."
2426 ;; Doesn't make sense if we're old-style prefixes, but this just
2427 ;; oughtn't be called then, so forget about it...
2428 (if (string-match allout-regexp prefix)
2429 (substring prefix (1- (match-end 2)) (match-end 2))))
2430 ;;;_ > allout-sibling-index (&optional depth)
2431 (defun allout-sibling-index (&optional depth)
2432 "Item number of this prospective topic among its siblings.
2434 If optional arg DEPTH is greater than current depth, then we're
2435 opening a new level, and return 0.
2437 If less than this depth, ascend to that depth and count..."
2439 (save-excursion
2440 (cond ((and depth (<= depth 0) 0))
2441 ((or (null depth) (= depth (allout-depth)))
2442 (let ((index 1))
2443 (while (allout-previous-sibling allout-recent-depth nil)
2444 (setq index (1+ index)))
2445 index))
2446 ((< depth allout-recent-depth)
2447 (allout-ascend-to-depth depth)
2448 (allout-sibling-index))
2449 (0))))
2450 ;;;_ > allout-topic-flat-index ()
2451 (defun allout-topic-flat-index ()
2452 "Return a list indicating point's numeric section.subsect.subsubsect...
2453 Outermost is first."
2454 (let* ((depth (allout-depth))
2455 (next-index (allout-sibling-index depth))
2456 (rev-sibls nil))
2457 (while (> next-index 0)
2458 (setq rev-sibls (cons next-index rev-sibls))
2459 (setq depth (1- depth))
2460 (setq next-index (allout-sibling-index depth)))
2461 rev-sibls)
2464 ;;;_ - Navigation routines
2465 ;;;_ > allout-beginning-of-current-line ()
2466 (defun allout-beginning-of-current-line ()
2467 "Like beginning of line, but to visible text."
2469 ;; This combination of move-beginning-of-line and beginning-of-line is
2470 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2471 (let ((inhibit-field-text-motion t))
2472 (move-beginning-of-line 1)
2473 (beginning-of-line)
2474 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2475 (beginning-of-line)
2476 (if (or (allout-hidden-p) (not (bolp)))
2477 (forward-char -1)))))
2478 ;;;_ > allout-end-of-current-line ()
2479 (defun allout-end-of-current-line ()
2480 "Move to the end of line, past concealed text if any."
2481 ;; This is for symmetry with `allout-beginning-of-current-line' --
2482 ;; `move-end-of-line' doesn't suffer the same problem as
2483 ;; `move-beginning-of-line'.
2484 (let ((inhibit-field-text-motion t))
2485 (end-of-line)
2486 (while (allout-hidden-p)
2487 (end-of-line)
2488 (if (allout-hidden-p) (forward-char 1)))))
2489 ;;;_ > allout-beginning-of-line ()
2490 (defun allout-beginning-of-line ()
2491 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2493 (interactive)
2495 (if (or (not allout-beginning-of-line-cycles)
2496 (not (equal last-command this-command)))
2497 (progn
2498 (if (and (not (bolp))
2499 (allout-hidden-p (1- (point))))
2500 (goto-char (allout-previous-single-char-property-change
2501 (1- (point)) 'invisible)))
2502 (move-beginning-of-line 1))
2503 (allout-depth)
2504 (let ((beginning-of-body
2505 (save-excursion
2506 (while (and (allout-do-doublecheck)
2507 (allout-aberrant-container-p)
2508 (allout-previous-visible-heading 1)))
2509 (allout-beginning-of-current-entry)
2510 (point))))
2511 (cond ((= (current-column) 0)
2512 (goto-char beginning-of-body))
2513 ((< (point) beginning-of-body)
2514 (allout-beginning-of-current-line))
2515 ((= (point) beginning-of-body)
2516 (goto-char (allout-current-bullet-pos)))
2517 (t (allout-beginning-of-current-line)
2518 (if (< (point) beginning-of-body)
2519 ;; we were on the headline after its start:
2520 (goto-char beginning-of-body)))))))
2521 ;;;_ > allout-end-of-line ()
2522 (defun allout-end-of-line ()
2523 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2525 (interactive)
2527 (if (or (not allout-end-of-line-cycles)
2528 (not (equal last-command this-command)))
2529 (allout-end-of-current-line)
2530 (let ((end-of-entry (save-excursion
2531 (allout-end-of-entry)
2532 (point))))
2533 (cond ((not (eolp))
2534 (allout-end-of-current-line))
2535 ((or (allout-hidden-p) (save-excursion
2536 (forward-char -1)
2537 (allout-hidden-p)))
2538 (allout-back-to-current-heading)
2539 (allout-show-current-entry)
2540 (allout-show-children)
2541 (allout-end-of-entry))
2542 ((>= (point) end-of-entry)
2543 (allout-back-to-current-heading)
2544 (allout-end-of-current-line))
2546 (if (not (allout-mark-active-p))
2547 (push-mark))
2548 (allout-end-of-entry))))))
2549 ;;;_ > allout-mark-active-p ()
2550 (defun allout-mark-active-p ()
2551 "True if the mark is currently or always active."
2552 ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
2553 ;; provisions, at least in GNU Emacs to prevent warnings about lack of,
2554 ;; eg, region-active-p.
2555 (cond ((boundp 'mark-active)
2556 mark-active)
2557 ((fboundp 'region-active-p)
2558 (region-active-p))
2559 (t)))
2560 ;;;_ > allout-next-heading ()
2561 (defsubst allout-next-heading ()
2562 "Move to the heading for the topic (possibly invisible) after this one.
2564 Returns the location of the heading, or nil if none found.
2566 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2567 (save-match-data
2569 (if (looking-at allout-regexp)
2570 (forward-char 1))
2572 (when (re-search-forward allout-line-boundary-regexp nil 0)
2573 (allout-prefix-data)
2574 (goto-char allout-recent-prefix-beginning)
2575 (while (not (bolp))
2576 (forward-char -1))
2577 (and (allout-do-doublecheck)
2578 ;; this will set allout-recent-* on the first non-aberrant topic,
2579 ;; whether it's the current one or one that disqualifies it:
2580 (allout-aberrant-container-p))
2581 ;; this may or may not be the same as above depending on doublecheck:
2582 (goto-char allout-recent-prefix-beginning))))
2583 ;;;_ > allout-this-or-next-heading
2584 (defun allout-this-or-next-heading ()
2585 "Position cursor on current or next heading."
2586 ;; A throwaway non-macro that is defined after allout-next-heading
2587 ;; and usable by allout-mode.
2588 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2589 ;;;_ > allout-previous-heading ()
2590 (defun allout-previous-heading ()
2591 "Move to the prior (possibly invisible) heading line.
2593 Return the location of the beginning of the heading, or nil if not found.
2595 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2597 (if (bobp)
2599 (let ((start-point (point)))
2600 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2601 (allout-goto-prefix)
2602 (save-match-data
2603 (when (or (re-search-backward allout-line-boundary-regexp nil 0)
2604 (looking-at allout-bob-regexp))
2605 (goto-char (allout-prefix-data))
2606 (if (and (allout-do-doublecheck)
2607 (allout-aberrant-container-p))
2608 (or (allout-previous-heading)
2609 (and (goto-char start-point)
2610 ;; recalibrate allout-recent-*:
2611 (allout-depth)
2612 nil))
2613 (point)))))))
2614 ;;;_ > allout-get-invisibility-overlay ()
2615 (defun allout-get-invisibility-overlay ()
2616 "Return the overlay at point that dictates allout invisibility."
2617 (let ((overlays (overlays-at (point)))
2618 got)
2619 (while (and overlays (not got))
2620 (if (equal (overlay-get (car overlays) 'invisible) 'allout)
2621 (setq got (car overlays))
2622 (pop overlays)))
2623 got))
2624 ;;;_ > allout-back-to-visible-text ()
2625 (defun allout-back-to-visible-text ()
2626 "Move to most recent prior character that is visible, and return point."
2627 (if (allout-hidden-p)
2628 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2629 (point))
2631 ;;;_ - Subtree Charting
2632 ;;;_ " These routines either produce or assess charts, which are
2633 ;;; nested lists of the locations of topics within a subtree.
2635 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2636 ;;; for elaborate, compound assessment and adjustment of a subtree.
2638 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2639 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2640 "Produce a location \"chart\" of subtopics of the containing topic.
2642 Optional argument LEVELS specifies a depth limit (relative to start
2643 depth) for the chart. Null LEVELS means no limit.
2645 When optional argument VISIBLE is non-nil, the chart includes
2646 only the visible subelements of the charted subjects.
2648 The remaining optional args are for internal use by the function.
2650 Point is left at the end of the subtree.
2652 Charts are used to capture outline structure, so that outline-altering
2653 routines need to assess the structure only once, and then use the chart
2654 for their elaborate manipulations.
2656 The chart entries for the topics are in reverse order, so the
2657 last topic is listed first. The entry for each topic consists of
2658 an integer indicating the point at the beginning of the topic
2659 prefix. Charts for offspring consist of a list containing,
2660 recursively, the charts for the respective subtopics. The chart
2661 for a topics' offspring precedes the entry for the topic itself.
2663 The other function parameters are for internal recursion, and should
2664 not be specified by external callers. ORIG-DEPTH is depth of topic at
2665 starting point, and PREV-DEPTH is depth of prior topic."
2667 (let ((original (not orig-depth)) ; `orig-depth' set only in recursion.
2668 chart curr-depth)
2670 (if original ; Just starting?
2671 ; Register initial settings and
2672 ; position to first offspring:
2673 (progn (setq orig-depth (allout-depth))
2674 (or prev-depth (setq prev-depth (1+ orig-depth)))
2675 (if visible
2676 (allout-next-visible-heading 1)
2677 (allout-next-heading))))
2679 ;; Loop over the current levels' siblings. Besides being more
2680 ;; efficient than tail-recursing over a level, it avoids exceeding
2681 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2683 ;; Probably would speed things up to implement loop-based stack
2684 ;; operation rather than recursing for lower levels. Bah.
2686 (while (and (not (eobp))
2687 ; Still within original topic?
2688 (< orig-depth (setq curr-depth allout-recent-depth))
2689 (cond ((= prev-depth curr-depth)
2690 ;; Register this one and move on:
2691 (setq chart (cons allout-recent-prefix-beginning chart))
2692 (if (and levels (<= levels 1))
2693 ;; At depth limit -- skip sublevels:
2694 (or (allout-next-sibling curr-depth)
2695 ;; or no more siblings -- proceed to
2696 ;; next heading at lesser depth:
2697 (while (and (<= curr-depth
2698 allout-recent-depth)
2699 (if visible
2700 (allout-next-visible-heading 1)
2701 (allout-next-heading)))))
2702 (if visible
2703 (allout-next-visible-heading 1)
2704 (allout-next-heading))))
2706 ((and (< prev-depth curr-depth)
2707 (or (not levels)
2708 (> levels 0)))
2709 ;; Recurse on deeper level of curr topic:
2710 (setq chart
2711 (cons (allout-chart-subtree (and levels
2712 (1- levels))
2713 visible
2714 orig-depth
2715 curr-depth)
2716 chart))
2717 ;; ... then continue with this one.
2720 ;; ... else nil if we've ascended back to prev-depth.
2724 (if original ; We're at the last sibling on
2725 ; the original level. Position
2726 ; to the end of it:
2727 (progn (and (not (eobp)) (forward-char -1))
2728 (and (= (preceding-char) ?\n)
2729 (= (aref (buffer-substring (max 1 (- (point) 3))
2730 (point))
2732 ?\n)
2733 (forward-char -1))
2734 (setq allout-recent-end-of-subtree (point))))
2736 chart ; (nreverse chart) not necessary,
2737 ; and maybe not preferable.
2739 ;;;_ > allout-chart-siblings (&optional start end)
2740 (defun allout-chart-siblings (&optional _start _end)
2741 "Produce a list of locations of this and succeeding sibling topics.
2742 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2743 for an explanation of charts."
2744 (save-excursion
2745 (when (allout-goto-prefix-doublechecked)
2746 (let ((chart (list (point))))
2747 (while (allout-next-sibling)
2748 (setq chart (cons (point) chart)))
2749 (if chart (setq chart (nreverse chart)))))))
2750 ;;;_ > allout-chart-to-reveal (chart depth)
2751 (defun allout-chart-to-reveal (chart depth)
2753 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2755 If DEPTH is nil, include hidden points at any depth.
2757 Note that point can be left at any of the points on chart, or at the
2758 start point."
2760 (let (result here)
2761 (while (and (or (null depth) (> depth 0))
2762 chart)
2763 (setq here (car chart))
2764 (if (listp here)
2765 (let ((further (allout-chart-to-reveal here (if (null depth)
2766 depth
2767 (1- depth)))))
2768 ;; We're on the start of a subtree -- recurse with it, if there's
2769 ;; more depth to go:
2770 (if further (setq result (append further result)))
2771 (setq chart (cdr chart)))
2772 (goto-char here)
2773 (if (allout-hidden-p)
2774 (setq result (cons here result)))
2775 (setq chart (cdr chart))))
2776 result))
2777 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2778 ;; (defun allout-chart-spec (chart spec &optional exposing)
2779 ;; "Not yet (if ever) implemented.
2781 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2783 ;; Exposure spec indicates the locations to be exposed and the prescribed
2784 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2785 ;; indicating pending concealment, anything higher indicating depth to
2786 ;; which subtopic headers should be exposed, and negative numbers
2787 ;; indicating (negative of) the depth to which subtopic headers and
2788 ;; bodies should be exposed.
2790 ;; The produced list can have two types of entries. Bare numbers
2791 ;; indicate points in the buffer where topic headers that should be
2792 ;; exposed reside.
2794 ;; - bare negative numbers indicates that the topic starting at the
2795 ;; point which is the negative of the number should be opened,
2796 ;; including their entries.
2797 ;; - bare positive values indicate that this topic header should be
2798 ;; opened.
2799 ;; - Lists signify the beginning and end points of regions that should
2800 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2801 ;; exposure:"
2802 ;; (while spec
2803 ;; (cond ((listp spec)
2804 ;; )
2805 ;; )
2806 ;; (setq spec (cdr spec)))
2807 ;; )
2809 ;;;_ - Within Topic
2810 ;;;_ > allout-goto-prefix ()
2811 (defun allout-goto-prefix ()
2812 "Put point at beginning of immediately containing outline topic.
2814 Goes to most immediate subsequent topic if none immediately containing.
2816 Not sensitive to topic visibility.
2818 Returns the point at the beginning of the prefix, or nil if none."
2820 (save-match-data
2821 (let (done)
2822 (while (and (not done)
2823 (search-backward "\n" nil 1))
2824 (forward-char 1)
2825 (if (looking-at allout-regexp)
2826 (setq done (allout-prefix-data))
2827 (forward-char -1)))
2828 (if (bobp)
2829 (cond ((looking-at allout-regexp)
2830 (allout-prefix-data))
2831 ((allout-next-heading))
2832 (done))
2833 done))))
2834 ;;;_ > allout-goto-prefix-doublechecked ()
2835 (defun allout-goto-prefix-doublechecked ()
2836 "Put point at beginning of immediately containing outline topic.
2838 Like `allout-goto-prefix', but shallow topics (according to
2839 `allout-doublecheck-at-and-shallower') are checked and
2840 disqualified for child containment discontinuity, according to
2841 `allout-aberrant-container-p'."
2842 (if (allout-goto-prefix)
2843 (if (and (allout-do-doublecheck)
2844 (allout-aberrant-container-p))
2845 (allout-previous-heading)
2846 (point))))
2848 ;;;_ > allout-end-of-prefix ()
2849 (defun allout-end-of-prefix (&optional ignore-decorations)
2850 "Position cursor at beginning of header text.
2852 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2853 otherwise skip white space between bullet and ensuing text."
2855 (if (not (allout-goto-prefix-doublechecked))
2857 (goto-char allout-recent-prefix-end)
2858 (save-match-data
2859 (if ignore-decorations
2861 (while (looking-at "[0-9]") (forward-char 1))
2862 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2863 ;; Reestablish where we are:
2864 (allout-current-depth)))
2865 ;;;_ > allout-current-bullet-pos ()
2866 (defun allout-current-bullet-pos ()
2867 "Return position of current (visible) topic's bullet."
2869 (if (not (allout-current-depth))
2871 (1- allout-recent-prefix-end)))
2872 ;;;_ > allout-back-to-current-heading (&optional interactive)
2873 (defun allout-back-to-current-heading (&optional interactive)
2874 "Move to heading line of current topic, or beginning if not in a topic.
2876 If interactive, we position at the end of the prefix.
2878 Return value of resulting point, unless we started outside
2879 of (before any) topics, in which case we return nil."
2881 (interactive "p")
2883 (allout-beginning-of-current-line)
2884 (let ((bol-point (point)))
2885 (when (allout-goto-prefix-doublechecked)
2886 (if (<= (point) bol-point)
2887 (progn
2888 (setq bol-point (point))
2889 (allout-beginning-of-current-line)
2890 (if (not (= bol-point (point)))
2891 (if (looking-at allout-regexp)
2892 (allout-prefix-data)))
2893 (if interactive
2894 (allout-end-of-prefix)
2895 (point)))
2896 (goto-char (point-min))
2897 nil))))
2898 ;;;_ > allout-back-to-heading ()
2899 (defalias 'allout-back-to-heading 'allout-back-to-current-heading)
2900 ;;;_ > allout-pre-next-prefix ()
2901 (defun allout-pre-next-prefix ()
2902 "Skip forward to just before the next heading line.
2904 Returns that character position."
2906 (if (allout-next-heading)
2907 (goto-char (1- allout-recent-prefix-beginning))))
2908 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2909 (defun allout-end-of-subtree (&optional current include-trailing-blank)
2910 "Put point at the end of the last leaf in the containing topic.
2912 Optional CURRENT means put point at the end of the containing
2913 visible topic.
2915 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2916 any, as part of the subtree. Otherwise, that trailing blank will be
2917 excluded as delimiting whitespace between topics.
2919 Returns the value of point."
2920 (interactive "P")
2921 (if current
2922 (allout-back-to-current-heading)
2923 (allout-goto-prefix-doublechecked))
2924 (let ((level allout-recent-depth))
2925 (allout-next-heading)
2926 (while (and (not (eobp))
2927 (> allout-recent-depth level))
2928 (allout-next-heading))
2929 (if (eobp)
2930 (allout-end-of-entry)
2931 (forward-char -1))
2932 (if (and (not include-trailing-blank) (= ?\n (preceding-char)))
2933 (forward-char -1))
2934 (setq allout-recent-end-of-subtree (point))))
2935 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2936 (defun allout-end-of-current-subtree (&optional include-trailing-blank)
2938 "Put point at end of last leaf in currently visible containing topic.
2940 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2941 any, as part of the subtree. Otherwise, that trailing blank will be
2942 excluded as delimiting whitespace between topics.
2944 Returns the value of point."
2945 (interactive)
2946 (allout-end-of-subtree t include-trailing-blank))
2947 ;;;_ > allout-beginning-of-current-entry (&optional interactive)
2948 (defun allout-beginning-of-current-entry (&optional interactive)
2949 "When not already there, position point at beginning of current topic header.
2951 If already there, move cursor to bullet for hot-spot operation.
2952 \(See `allout-mode' doc string for details of hot-spot operation.)"
2953 (interactive "p")
2954 (let ((start-point (point)))
2955 (move-beginning-of-line 1)
2956 (if (< 0 (allout-current-depth))
2957 (goto-char allout-recent-prefix-end)
2958 (goto-char (point-min)))
2959 (allout-end-of-prefix)
2960 (if (and interactive
2961 (= (point) start-point))
2962 (goto-char (allout-current-bullet-pos)))))
2963 ;;;_ > allout-end-of-entry (&optional inclusive)
2964 (defun allout-end-of-entry (&optional inclusive)
2965 "Position the point at the end of the current topics' entry.
2967 Optional INCLUSIVE means also include trailing empty line, if any. When
2968 unset, whitespace between items separates them even when the items are
2969 collapsed."
2970 (interactive)
2971 (allout-pre-next-prefix)
2972 (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char)))
2973 (forward-char -1))
2974 (point))
2975 ;;;_ > allout-end-of-current-heading ()
2976 (defun allout-end-of-current-heading ()
2977 (interactive)
2978 (allout-beginning-of-current-entry)
2979 (search-forward "\n" nil t)
2980 (forward-char -1))
2981 (defalias 'allout-end-of-heading 'allout-end-of-current-heading)
2982 ;;;_ > allout-get-body-text ()
2983 (defun allout-get-body-text ()
2984 "Return the unmangled body text of the topic immediately containing point."
2985 (save-excursion
2986 (allout-end-of-prefix)
2987 (if (not (search-forward "\n" nil t))
2989 (backward-char 1)
2990 (let ((pre-body (point)))
2991 (if (not pre-body)
2993 (allout-end-of-entry t)
2994 (if (not (= pre-body (point)))
2995 (buffer-substring-no-properties (1+ pre-body) (point))))
3001 ;;;_ - Depth-wise
3002 ;;;_ > allout-ascend-to-depth (depth)
3003 (defun allout-ascend-to-depth (depth)
3004 "Ascend to depth DEPTH, returning depth if successful, nil if not."
3005 (if (and (> depth 0)(<= depth (allout-depth)))
3006 (let (last-ascended)
3007 (while (and (< depth allout-recent-depth)
3008 (setq last-ascended (allout-ascend))))
3009 (goto-char allout-recent-prefix-beginning)
3010 (if (allout-called-interactively-p) (allout-end-of-prefix))
3011 (and last-ascended allout-recent-depth))))
3012 ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
3013 (defun allout-ascend (&optional dont-move-if-unsuccessful)
3014 "Ascend one level, returning resulting depth if successful, nil if not.
3016 Point is left at the beginning of the level whether or not
3017 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
3018 which case point is returned to its original starting location."
3019 (if dont-move-if-unsuccessful
3020 (setq dont-move-if-unsuccessful (point)))
3021 (prog1
3022 (if (allout-beginning-of-level)
3023 (let ((bolevel (point))
3024 (bolevel-depth allout-recent-depth))
3025 (allout-previous-heading)
3026 (cond ((< allout-recent-depth bolevel-depth)
3027 allout-recent-depth)
3028 ((= allout-recent-depth bolevel-depth)
3029 (if dont-move-if-unsuccessful
3030 (goto-char dont-move-if-unsuccessful))
3031 (allout-depth)
3032 nil)
3034 ;; some topic after very first is lower depth than first:
3035 (goto-char bolevel)
3036 (allout-depth)
3037 nil))))
3038 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3039 ;;;_ > allout-descend-to-depth (depth)
3040 (defun allout-descend-to-depth (depth)
3041 "Descend to depth DEPTH within current topic.
3043 Returning depth if successful, nil if not."
3044 (let ((start-point (point))
3045 (start-depth (allout-depth)))
3046 (while
3047 (and (> (allout-depth) 0)
3048 (not (= depth allout-recent-depth)) ; ... not there yet
3049 (allout-next-heading) ; ... go further
3050 (< start-depth allout-recent-depth))) ; ... still in topic
3051 (if (and (> (allout-depth) 0)
3052 (= allout-recent-depth depth))
3053 depth
3054 (goto-char start-point)
3055 nil))
3057 ;;;_ > allout-up-current-level (arg)
3058 (defun allout-up-current-level (_arg)
3059 "Move out ARG levels from current visible topic."
3060 (interactive "p")
3061 (let ((start-point (point)))
3062 (allout-back-to-current-heading)
3063 (if (not (allout-ascend))
3064 (progn (goto-char start-point)
3065 (error "Can't ascend past outermost level"))
3066 (if (allout-called-interactively-p) (allout-end-of-prefix))
3067 allout-recent-prefix-beginning)))
3069 ;;;_ - Linear
3070 ;;;_ > allout-next-sibling (&optional depth backward)
3071 (defun allout-next-sibling (&optional depth backward)
3072 "Like `allout-forward-current-level', but respects invisible topics.
3074 Traverse at optional DEPTH, or current depth if none specified.
3076 Go backward if optional arg BACKWARD is non-nil.
3078 Return the start point of the new topic if successful, nil otherwise."
3080 (if (if backward (bobp) (eobp))
3082 (let ((target-depth (or depth (allout-depth)))
3083 (start-point (point))
3084 (start-prefix-beginning allout-recent-prefix-beginning)
3085 (count 0)
3086 leaping
3087 last-depth)
3088 (while (and
3089 ;; done too few single steps to resort to the leap routine:
3090 (not leaping)
3091 ;; not at limit:
3092 (not (if backward (bobp) (eobp)))
3093 ;; still traversable:
3094 (if backward (allout-previous-heading) (allout-next-heading))
3095 ;; we're below the target depth
3096 (> (setq last-depth allout-recent-depth) target-depth))
3097 (setq count (1+ count))
3098 (if (> count 7) ; lists are commonly 7 +- 2, right?-)
3099 (setq leaping t)))
3100 (cond (leaping
3101 (or (allout-next-sibling-leap target-depth backward)
3102 (progn
3103 (goto-char start-point)
3104 (if depth (allout-depth) target-depth)
3105 nil)))
3106 ((and (not (eobp))
3107 (and (> (or last-depth (allout-depth)) 0)
3108 (= allout-recent-depth target-depth))
3109 (not (= start-prefix-beginning
3110 allout-recent-prefix-beginning)))
3111 allout-recent-prefix-beginning)
3113 (goto-char start-point)
3114 (if depth (allout-depth) target-depth)
3115 nil)))))
3116 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3117 (defun allout-next-sibling-leap (&optional depth backward)
3118 "Like `allout-next-sibling', but by direct search for topic at depth.
3120 Traverse at optional DEPTH, or current depth if none specified.
3122 Go backward if optional arg BACKWARD is non-nil.
3124 Return the start point of the new topic if successful, nil otherwise.
3126 Costs more than regular `allout-next-sibling' for short traversals:
3128 - we have to check the prior (next, if traveling backwards)
3129 item to confirm connectivity with the prior topic, and
3130 - if confirmed, we have to reestablish the allout-recent-* settings with
3131 some extra navigation
3132 - if confirmation fails, we have to do more work to recover
3134 It is an increasingly big win when there are many intervening
3135 offspring before the next sibling, however, so
3136 `allout-next-sibling' resorts to this if it finds itself in that
3137 situation."
3139 (if (if backward (bobp) (eobp))
3141 (let* ((start-point (point))
3142 (target-depth (or depth (allout-depth)))
3143 (search-whitespace-regexp nil)
3144 (depth-biased (- target-depth 2))
3145 (expression (if (<= target-depth 1)
3146 allout-depth-one-regexp
3147 (format allout-depth-specific-regexp
3148 depth-biased depth-biased)))
3149 found
3150 done)
3151 (while (not done)
3152 (setq found (save-match-data
3153 (if backward
3154 (re-search-backward expression nil 'to-limit)
3155 (forward-char 1)
3156 (re-search-forward expression nil 'to-limit))))
3157 (if (and found (allout-aberrant-container-p))
3158 (setq found nil))
3159 (setq done (or found (if backward (bobp) (eobp)))))
3160 (if (not found)
3161 (progn (goto-char start-point)
3162 nil)
3163 ;; rationale: if any intervening items were at a lower depth, we
3164 ;; would now be on the first offspring at the target depth -- ie,
3165 ;; the preceding item (per the search direction) must be at a
3166 ;; lesser depth. that's all we need to check.
3167 (if backward (allout-next-heading) (allout-previous-heading))
3168 (if (< allout-recent-depth target-depth)
3169 ;; return to start and reestablish allout-recent-*:
3170 (progn
3171 (goto-char start-point)
3172 (allout-depth)
3173 nil)
3174 (goto-char found)
3175 ;; locate cursor and set allout-recent-*:
3176 (allout-goto-prefix))))))
3177 ;;;_ > allout-previous-sibling (&optional depth backward)
3178 (defun allout-previous-sibling (&optional depth backward)
3179 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3181 Optional DEPTH specifies depth to traverse, default current depth.
3183 Optional BACKWARD reverses direction.
3185 Return depth if successful, nil otherwise."
3186 (allout-next-sibling depth (not backward))
3188 ;;;_ > allout-snug-back ()
3189 (defun allout-snug-back ()
3190 "Position cursor at end of previous topic.
3192 Presumes point is at the start of a topic prefix."
3193 (if (or (bobp) (eobp))
3195 (forward-char -1))
3196 (if (or (bobp) (not (= ?\n (preceding-char))))
3198 (forward-char -1))
3199 (point))
3200 ;;;_ > allout-beginning-of-level ()
3201 (defun allout-beginning-of-level ()
3202 "Go back to the first sibling at this level, visible or not."
3203 (allout-end-of-level 'backward))
3204 ;;;_ > allout-end-of-level (&optional backward)
3205 (defun allout-end-of-level (&optional _backward)
3206 "Go to the last sibling at this level, visible or not."
3208 (let ((depth (allout-depth)))
3209 (while (allout-previous-sibling depth nil))
3210 (prog1 allout-recent-depth
3211 (if (allout-called-interactively-p) (allout-end-of-prefix)))))
3212 ;;;_ > allout-next-visible-heading (arg)
3213 (defun allout-next-visible-heading (arg)
3214 "Move to the next ARGth visible heading line, backward if ARG is negative.
3216 Move to buffer limit in indicated direction if headings are exhausted."
3218 (interactive "p")
3219 (let* ((inhibit-field-text-motion t)
3220 (backward (if (< arg 0) (setq arg (* -1 arg))))
3221 (step (if backward -1 1))
3222 (progress (allout-current-bullet-pos))
3223 prev got)
3225 (while (> arg 0)
3226 (while (and
3227 ;; Boundary condition:
3228 (not (if backward (bobp)(eobp)))
3229 ;; Move, skipping over all concealed lines in one fell swoop:
3230 (prog1 (condition-case nil (or (line-move step) t)
3231 (error nil))
3232 (allout-beginning-of-current-line)
3233 ;; line-move can wind up on the same line if long.
3234 ;; when moving forward, that would yield no-progress
3235 (when (and (not backward)
3236 (<= (point) progress))
3237 ;; ensure progress by doing line-move from end-of-line:
3238 (end-of-line)
3239 (condition-case nil (or (line-move step) t)
3240 (error nil))
3241 (allout-beginning-of-current-line)
3242 (setq progress (point))))
3243 ;; Deal with apparent header line:
3244 (save-match-data
3245 (if (not (looking-at allout-regexp))
3246 ;; not a header line, keep looking:
3248 (allout-prefix-data)
3249 (if (and (allout-do-doublecheck)
3250 (allout-aberrant-container-p))
3251 ;; skip this aberrant prospective header line:
3253 ;; this prospective headerline qualifies -- register:
3254 (setq got allout-recent-prefix-beginning)
3255 ;; and break the loop:
3256 nil)))))
3257 ;; Register this got, it may be the last:
3258 (if got (setq prev got))
3259 (setq arg (1- arg)))
3260 (cond (got ; Last move was to a prefix:
3261 (allout-end-of-prefix))
3262 (prev ; Last move wasn't, but prev was:
3263 (goto-char prev)
3264 (allout-end-of-prefix))
3265 ((not backward) (end-of-line) nil))))
3266 ;;;_ > allout-previous-visible-heading (arg)
3267 (defun allout-previous-visible-heading (arg)
3268 "Move to the previous heading line.
3270 With argument, repeats or can move forward if negative.
3271 A heading line is one that starts with a `*' (or that `allout-regexp'
3272 matches)."
3273 (interactive "p")
3274 (prog1 (allout-next-visible-heading (- arg))
3275 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3276 ;;;_ > allout-forward-current-level (arg)
3277 (defun allout-forward-current-level (arg)
3278 "Position point at the next heading of the same level.
3280 Takes optional repeat-count, goes backward if count is negative.
3282 Returns resulting position, else nil if none found."
3283 (interactive "p")
3284 (let ((start-depth (allout-current-depth))
3285 (start-arg arg)
3286 (backward (> 0 arg)))
3287 (if (= 0 start-depth)
3288 (error "No siblings, not in a topic..."))
3289 (if backward (setq arg (* -1 arg)))
3290 (allout-back-to-current-heading)
3291 (while (and (not (zerop arg))
3292 (if backward
3293 (allout-previous-sibling)
3294 (allout-next-sibling)))
3295 (setq arg (1- arg)))
3296 (if (not (allout-called-interactively-p))
3298 (allout-end-of-prefix)
3299 (if (not (zerop arg))
3300 (error "Hit %s level %d topic, traversed %d of %d requested"
3301 (if backward "first" "last")
3302 allout-recent-depth
3303 (- (abs start-arg) arg)
3304 (abs start-arg))))))
3305 ;;;_ > allout-backward-current-level (arg)
3306 (defun allout-backward-current-level (arg)
3307 "Inverse of `allout-forward-current-level'."
3308 (interactive "p")
3309 (if (allout-called-interactively-p)
3310 (let ((current-prefix-arg (* -1 arg)))
3311 (call-interactively 'allout-forward-current-level))
3312 (allout-forward-current-level (* -1 arg))))
3314 ;;;_ #5 Alteration
3316 ;;;_ - Fundamental
3317 ;;;_ = allout-post-goto-bullet
3318 (defvar allout-post-goto-bullet nil
3319 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3321 When set, tells post-processing to reposition on topic bullet, and
3322 then unset it. Set by `allout-pre-command-business' when implementing
3323 hot-spot operation, where literal characters typed over a topic bullet
3324 are mapped to the command of the corresponding control-key on the
3325 `allout-mode-map-value'.")
3326 (make-variable-buffer-local 'allout-post-goto-bullet)
3327 ;;;_ = allout-command-counter
3328 (defvar allout-command-counter 0
3329 "Counter that monotonically increases in allout-mode buffers.
3331 Set by `allout-pre-command-business', to support allout addons in
3332 coordinating with allout activity.")
3333 (make-variable-buffer-local 'allout-command-counter)
3334 ;;;_ = allout-this-command-hid-text
3335 (defvar allout-this-command-hid-text nil
3336 "True if the most recent allout-mode command hid any text.")
3337 (make-variable-buffer-local 'allout-this-command-hid-text)
3338 ;;;_ > allout-post-command-business ()
3339 (defun allout-post-command-business ()
3340 "Outline `post-command-hook' function.
3342 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3343 outline commands.
3345 - Move the cursor to the beginning of the entry if it is hidden
3346 and collapsing activity just happened.
3348 - If the command we're following was an undo, check for change in
3349 the status of encrypted items and adjust auto-save inhibitions
3350 accordingly.
3352 - Decrypt topic currently being edited if it was encrypted for a save."
3354 (if (not (allout-mode-p)) ; In allout-mode.
3357 (when allout-just-did-undo
3358 (setq allout-just-did-undo nil)
3359 (run-hooks 'allout-post-undo-hook)
3360 (cond ((and (= buffer-saved-size -1)
3361 allout-auto-save-temporarily-disabled)
3362 ;; user possibly undid a decryption, disinhibit auto-save:
3363 (allout-maybe-resume-auto-save-info-after-encryption))
3364 ((save-excursion
3365 (save-restriction
3366 (widen)
3367 (goto-char (point-min))
3368 (not (allout-next-topic-pending-encryption))))
3369 ;; plain-text encrypted items are present, inhibit auto-save:
3370 (allout-inhibit-auto-save-info-for-decryption (buffer-size)))))
3372 (if (and (boundp 'allout-after-save-decrypt)
3373 allout-after-save-decrypt)
3374 (allout-after-saves-handler))
3376 ;; Implement allout-post-goto-bullet, if set:
3377 (if (and allout-post-goto-bullet
3378 (allout-current-bullet-pos))
3379 (progn (goto-char (allout-current-bullet-pos))
3380 (setq allout-post-goto-bullet nil))
3381 (when (and (allout-hidden-p) allout-this-command-hid-text)
3382 (allout-beginning-of-current-entry)))))
3383 ;;;_ > allout-pre-command-business ()
3384 (defun allout-pre-command-business ()
3385 "Outline `pre-command-hook' function for outline buffers.
3387 Among other things, implements special behavior when the cursor is on the
3388 topic bullet character.
3390 When the cursor is on the bullet character, self-insert
3391 characters are reinterpreted as the corresponding
3392 control-character in the `allout-mode-map-value'. The
3393 `allout-mode' `post-command-hook' insures that the cursor which
3394 has moved as a result of such reinterpretation is positioned on
3395 the bullet character of the destination topic.
3397 The upshot is that you can get easy, single (ie, unmodified) key
3398 outline maneuvering operations by positioning the cursor on the bullet
3399 char. When in this mode you can use regular cursor-positioning
3400 command/keystrokes to relocate the cursor off of a bullet character to
3401 return to regular interpretation of self-insert characters."
3403 (if (not (allout-mode-p))
3405 (setq allout-command-counter (1+ allout-command-counter))
3406 (setq allout-this-command-hid-text nil)
3407 ;; Do hot-spot navigation.
3408 (if (and (eq this-command 'self-insert-command)
3409 (eq (point)(allout-current-bullet-pos)))
3410 (allout-hotspot-key-handler))))
3411 ;;;_ > allout-hotspot-key-handler ()
3412 (defun allout-hotspot-key-handler ()
3413 "Catchall handling of key bindings in hot-spots.
3415 Translates unmodified keystrokes to corresponding allout commands, when
3416 they would qualify if prefixed with the `allout-command-prefix', and sets
3417 `this-command' accordingly.
3419 Returns the qualifying command, if any, else nil."
3420 (interactive)
3421 (let* ((modified (event-modifiers last-command-event))
3422 (key-num (cond ((numberp last-command-event) last-command-event)
3423 ;; for XEmacs character type:
3424 ((and (fboundp 'characterp)
3425 (apply 'characterp (list last-command-event)))
3426 (apply 'char-to-int (list last-command-event)))
3427 (t 0)))
3428 mapped-binding)
3430 (if (zerop key-num)
3433 (if (and
3434 ;; exclude control chars and escape:
3435 (not modified)
3436 (<= 33 key-num)
3437 (setq mapped-binding
3439 ;; try control-modified versions of keys:
3440 (key-binding (vconcat allout-command-prefix
3441 (vector
3442 (if (and (<= 97 key-num) ; "a"
3443 (>= 122 key-num)) ; "z"
3444 (- key-num 96) key-num)))
3446 ;; try non-modified versions of keys:
3447 (key-binding (vconcat allout-command-prefix
3448 (vector key-num))
3449 t))))
3450 ;; Qualified as an allout command -- do hot-spot operation.
3451 (setq allout-post-goto-bullet t)
3452 ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
3453 (setq mapped-binding (key-binding (vector key-num))))
3455 (while (keymapp mapped-binding)
3456 (setq mapped-binding
3457 (lookup-key mapped-binding (vector (read-char)))))
3459 (when mapped-binding
3460 (setq this-command mapped-binding)))))
3462 ;;;_ > allout-find-file-hook ()
3463 (defun allout-find-file-hook ()
3464 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3466 See `allout-auto-activation' for setup instructions."
3467 (if (and allout-auto-activation
3468 (not (allout-mode-p))
3469 allout-layout)
3470 (allout-mode)))
3472 ;;;_ - Topic Format Assessment
3473 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3474 (defun allout-solicit-alternate-bullet (depth &optional current-bullet)
3476 "Prompt for and return a bullet char as an alternative to the current one.
3478 Offer one suitable for current depth DEPTH as default."
3480 (let* ((default-bullet (or (and (stringp current-bullet) current-bullet)
3481 (allout-bullet-for-depth depth)))
3482 (sans-escapes (allout-regexp-sans-escapes allout-bullets-string))
3483 choice)
3484 (save-excursion
3485 (goto-char (allout-current-bullet-pos))
3486 (setq choice (allout-solicit-char-in-string
3487 (format-message
3488 "Select bullet: %s (`%s' default): "
3489 sans-escapes
3490 (allout-substring-no-properties default-bullet))
3491 sans-escapes
3492 t)))
3493 (message "")
3494 (if (string= choice "") default-bullet choice))
3496 ;;;_ > allout-distinctive-bullet (bullet)
3497 (defun allout-distinctive-bullet (bullet)
3498 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3499 (string-match (regexp-quote bullet) allout-distinctive-bullets-string))
3500 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3501 (defun allout-numbered-type-prefix (&optional prefix)
3502 "True if current header prefix bullet is numbered bullet."
3503 (and allout-numbered-bullet
3504 (string= allout-numbered-bullet
3505 (if prefix
3506 (allout-get-prefix-bullet prefix)
3507 (allout-get-bullet)))))
3508 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3509 (defun allout-encrypted-type-prefix (&optional prefix)
3510 "True if current header prefix bullet is for an encrypted entry (body)."
3511 (and allout-topic-encryption-bullet
3512 (string= allout-topic-encryption-bullet
3513 (if prefix
3514 (allout-get-prefix-bullet prefix)
3515 (allout-get-bullet)))))
3516 ;;;_ > allout-bullet-for-depth (&optional depth)
3517 (defun allout-bullet-for-depth (&optional depth)
3518 "Return outline topic bullet suited to optional DEPTH, or current depth."
3519 ;; Find bullet in plain-bullets-string modulo DEPTH.
3520 (if allout-stylish-prefixes
3521 (char-to-string (aref allout-plain-bullets-string
3522 (% (max 0 (- depth 2))
3523 allout-plain-bullets-string-len)))
3524 allout-primary-bullet)
3527 ;;;_ - Topic Production
3528 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3529 (defun allout-make-topic-prefix (&optional prior-bullet
3531 depth
3532 instead
3533 number-control
3534 index)
3535 ;; Depth null means use current depth, non-null means we're either
3536 ;; opening a new topic after current topic, lower or higher, or we're
3537 ;; changing level of current topic.
3538 ;; Instead dominates specified bullet-char.
3539 ;;;_ . Doc string:
3540 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3542 All the arguments are optional.
3544 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3545 nil if none. This bullet may be preserved (other options
3546 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3547 for instance.
3549 Second arg NEW indicates that a new topic is being opened after the
3550 topic at point, if non-nil. Default bullet for new topics, eg, may
3551 be set (contingent to other args) to numbered bullets if previous
3552 sibling is one. The implication otherwise is that the current topic
3553 is being adjusted -- shifted or rebulleted -- and we don't consider
3554 bullet or previous sibling.
3556 Third arg DEPTH forces the topic prefix to that depth, regardless of
3557 the current topics' depth.
3559 If INSTEAD is:
3561 - nil, then the bullet char for the context is used, per distinction or depth
3562 - a (numeric) character, then character's string representation is used
3563 - a string, then the user is asked for bullet with the first char as default
3564 - anything else, the user is solicited with bullet char per context as default
3566 \(INSTEAD overrides other options, including, eg, a distinctive
3567 PRIOR-BULLET.)
3569 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3570 is non-nil *and* no specific INSTEAD was specified. Then
3571 NUMBER-CONTROL non-nil forces prefix to either numbered or
3572 unnumbered format, depending on the value of the sixth arg, INDEX.
3574 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3576 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3577 the prefix of the topic is forced to be numbered. Non-nil
3578 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3579 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3580 that the index for the numbered prefix will be derived, by counting
3581 siblings back to start of level. If INDEX is a number, then that
3582 number is used as the index for the numbered prefix (allowing, eg,
3583 sequential renumbering to not require this function counting back the
3584 index for each successive sibling)."
3585 ;;;_ . Code:
3586 ;; The options are ordered in likely frequency of use, most common
3587 ;; highest, least lowest. Ie, more likely to be doing prefix
3588 ;; adjustments than soliciting, and yet more than numbering.
3589 ;; Current prefix is least dominant, but most likely to be commonly
3590 ;; specified...
3592 (let* (body
3593 numbering
3594 denumbering
3595 (depth (or depth (allout-depth)))
3596 (header-lead allout-header-prefix)
3597 (bullet-char
3599 ;; Getting value for bullet char is practically the whole job:
3601 (cond
3602 ; Simplest situation -- level 1:
3603 ((<= depth 1) (setq header-lead "") allout-primary-bullet)
3604 ; Simple, too: all asterisks:
3605 (allout-old-style-prefixes
3606 ;; Cheat -- make body the whole thing, null out header-lead and
3607 ;; bullet-char:
3608 (setq body (make-string depth
3609 (string-to-char allout-primary-bullet)))
3610 (setq header-lead "")
3613 ;; (Neither level 1 nor old-style, so we're space padding.
3614 ;; Sneak it in the condition of the next case, whatever it is.)
3616 ;; Solicitation overrides numbering and other cases:
3617 ((progn (setq body (make-string (- depth 2) ?\ ))
3618 ;; The actual condition:
3619 instead)
3620 (let ((got (cond ((stringp instead)
3621 (if (> (length instead) 0)
3622 (allout-solicit-alternate-bullet
3623 depth (substring instead 0 1))))
3624 ((characterp instead) (char-to-string instead))
3625 (t (allout-solicit-alternate-bullet depth)))))
3626 ;; Gotta check whether we're numbering and got a numbered bullet:
3627 (setq numbering (and allout-numbered-bullet
3628 (not (and number-control (not index)))
3629 (string= got allout-numbered-bullet)))
3630 ;; Now return what we got, regardless:
3631 got))
3633 ;; Numbering invoked through args:
3634 ((and allout-numbered-bullet number-control)
3635 (if (setq numbering (not (setq denumbering (not index))))
3636 allout-numbered-bullet
3637 (if (and prior-bullet
3638 (not (string= allout-numbered-bullet
3639 prior-bullet)))
3640 prior-bullet
3641 (allout-bullet-for-depth depth))))
3643 ;;; Neither soliciting nor controlled numbering ;;;
3644 ;;; (may be controlled denumbering, tho) ;;;
3646 ;; Check wrt previous sibling:
3647 ((and new ; only check for new prefixes
3648 (<= depth (allout-depth))
3649 allout-numbered-bullet ; ... & numbering enabled
3650 (not denumbering)
3651 (let ((sibling-bullet
3652 (save-excursion
3653 ;; Locate correct sibling:
3654 (or (>= depth (allout-depth))
3655 (allout-ascend-to-depth depth))
3656 (allout-get-bullet))))
3657 (if (and sibling-bullet
3658 (string= allout-numbered-bullet sibling-bullet))
3659 (setq numbering sibling-bullet)))))
3661 ;; Distinctive prior bullet?
3662 ((and prior-bullet
3663 (allout-distinctive-bullet prior-bullet)
3664 ;; Either non-numbered:
3665 (or (not (and allout-numbered-bullet
3666 (string= prior-bullet allout-numbered-bullet)))
3667 ;; or numbered, and not denumbering:
3668 (setq numbering (not denumbering)))
3669 ;; Here 'tis:
3670 prior-bullet))
3672 ;; Else, standard bullet per depth:
3673 ((allout-bullet-for-depth depth)))))
3675 (concat header-lead
3676 body
3677 bullet-char
3678 (if numbering
3679 (format "%d" (cond ((and index (numberp index)) index)
3680 (new (1+ (allout-sibling-index depth)))
3681 ((allout-sibling-index))))))
3684 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3685 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet)
3686 "Open a new topic at depth DEPTH.
3688 New topic is situated after current one, unless optional flag BEFORE
3689 is non-nil, or unless current line is completely empty -- lacking even
3690 whitespace -- in which case open is done on the current line.
3692 When adding an offspring, it will be added immediately after the parent if
3693 the other offspring are exposed, or after the last child if the offspring
3694 are hidden. (The intervening offspring will be exposed in the latter
3695 case.)
3697 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3699 Nuances:
3701 - Creation of new topics is with respect to the visible topic
3702 containing the cursor, regardless of intervening concealed ones.
3704 - New headers are generally created after/before the body of a
3705 topic. However, they are created right at cursor location if the
3706 cursor is on a blank line, even if that breaks the current topic
3707 body. This is intentional, to provide a simple means for
3708 deliberately dividing topic bodies.
3710 - Double spacing of topic lists is preserved. Also, the first
3711 level two topic is created double-spaced (and so would be
3712 subsequent siblings, if that's left intact). Otherwise,
3713 single-spacing is used.
3715 - Creation of sibling or nested topics is with respect to the topic
3716 you're starting from, even when creating backwards. This way you
3717 can easily create a sibling in front of the current topic without
3718 having to go to its preceding sibling, and then open forward
3719 from there."
3721 (allout-beginning-of-current-line)
3722 (save-match-data
3723 (let* ((inhibit-field-text-motion t)
3724 (depth (+ (allout-current-depth) relative-depth))
3725 (opening-on-blank (if (looking-at "^$")
3726 (not (setq before nil))))
3727 ;; bunch o vars set while computing ref-topic
3728 opening-numbered
3729 ref-depth
3730 ref-bullet
3731 (ref-topic (save-excursion
3732 (cond ((< relative-depth 0)
3733 (allout-ascend-to-depth depth))
3734 ((>= relative-depth 1) nil)
3735 (t (allout-back-to-current-heading)))
3736 (setq ref-depth allout-recent-depth)
3737 (setq ref-bullet
3738 (if (> allout-recent-prefix-end 1)
3739 (allout-recent-bullet)
3740 ""))
3741 (setq opening-numbered
3742 (save-excursion
3743 (and allout-numbered-bullet
3744 (or (<= relative-depth 0)
3745 (allout-descend-to-depth depth))
3746 (if (allout-numbered-type-prefix)
3747 allout-numbered-bullet))))
3748 (point)))
3749 dbl-space
3750 doing-beginning
3751 start end)
3753 (if (not opening-on-blank)
3754 ; Positioning and vertical
3755 ; padding -- only if not
3756 ; opening-on-blank:
3757 (progn
3758 (goto-char ref-topic)
3759 (setq dbl-space ; Determine double space action:
3760 (or (and (<= relative-depth 0) ; not descending;
3761 (save-excursion
3762 ;; at b-o-b or preceded by a blank line?
3763 (or (> 0 (forward-line -1))
3764 (looking-at "^\\s-*$")
3765 (bobp)))
3766 (save-excursion
3767 ;; succeeded by a blank line?
3768 (allout-end-of-current-subtree)
3769 (looking-at "\n\n")))
3770 (and (= ref-depth 1)
3771 (or before
3772 (= depth 1)
3773 (save-excursion
3774 ;; Don't already have following
3775 ;; vertical padding:
3776 (not (allout-pre-next-prefix)))))))
3778 ;; Position to prior heading, if inserting backwards, and not
3779 ;; going outwards:
3780 (if (and before (>= relative-depth 0))
3781 (progn (allout-back-to-current-heading)
3782 (setq doing-beginning (bobp))
3783 (if (not (bobp))
3784 (allout-previous-heading)))
3785 (if (and before (bobp))
3786 (open-line 1)))
3788 (if (<= relative-depth 0)
3789 ;; Not going inwards, don't snug up:
3790 (if doing-beginning
3791 (if (not dbl-space)
3792 (open-line 1)
3793 (open-line 2))
3794 (if before
3795 (progn (end-of-line)
3796 (allout-pre-next-prefix)
3797 (while (and (= ?\n (following-char))
3798 (save-excursion
3799 (forward-char 1)
3800 (allout-hidden-p)))
3801 (forward-char 1))
3802 (if (not (looking-at "^$"))
3803 (open-line 1)))
3804 (allout-end-of-current-subtree)
3805 (if (looking-at "\n\n") (forward-char 1))))
3806 ;; Going inwards -- double-space if first offspring is
3807 ;; double-spaced, otherwise snug up.
3808 (allout-end-of-entry)
3809 (if (eobp)
3810 (newline 1)
3811 (line-move 1))
3812 (allout-beginning-of-current-line)
3813 (backward-char 1)
3814 (if (bolp)
3815 ;; Blank lines between current header body and next
3816 ;; header -- get to last substantive (non-white-space)
3817 ;; line in body:
3818 (progn (setq dbl-space t)
3819 (re-search-backward "[^ \t\n]" nil t)))
3820 (if (looking-at "\n\n")
3821 (setq dbl-space t))
3822 (if (save-excursion
3823 (allout-next-heading)
3824 (when (> allout-recent-depth ref-depth)
3825 ;; This is an offspring.
3826 (forward-line -1)
3827 (looking-at "^\\s-*$")))
3828 (progn (forward-line 1)
3829 (open-line 1)
3830 (forward-line 1)))
3831 (allout-end-of-current-line))
3833 ;;(if doing-beginning (goto-char doing-beginning))
3834 (if (not (bobp))
3835 ;; We insert a newline char rather than using open-line to
3836 ;; avoid rear-stickiness inheritance of read-only property.
3837 (progn (if (and (not (> depth ref-depth))
3838 (not before))
3839 (open-line 1)
3840 (if (and (not dbl-space) (> depth ref-depth))
3841 (newline 1)
3842 (if dbl-space
3843 (open-line 1)
3844 (if (not before)
3845 (newline 1)))))
3846 (if (and dbl-space (not (> relative-depth 0)))
3847 (newline 1))
3848 (if (and (not (eobp))
3849 (or (not (bolp))
3850 (and (not (bobp))
3851 ;; bolp doesn't detect concealed
3852 ;; trailing newlines, compensate:
3853 (save-excursion
3854 (forward-char -1)
3855 (allout-hidden-p)))))
3856 (forward-char 1))))
3858 (setq start (point))
3859 (insert (concat (allout-make-topic-prefix opening-numbered t depth)
3860 " "))
3861 (setq end (1+ (point)))
3863 (allout-rebullet-heading (and offer-recent-bullet ref-bullet)
3864 depth nil nil t)
3865 (if (> relative-depth 0)
3866 (save-excursion (goto-char ref-topic)
3867 (allout-show-children)))
3868 (end-of-line)
3870 (run-hook-with-args 'allout-structure-added-functions start end)
3874 ;;;_ > allout-open-subtopic (arg)
3875 (defun allout-open-subtopic (arg)
3876 "Open new topic header at deeper level than the current one.
3878 Negative universal ARG means to open deeper, but place the new topic
3879 prior to the current one."
3880 (interactive "p")
3881 (allout-open-topic 1 (> 0 arg) (< 1 arg)))
3882 ;;;_ > allout-open-sibtopic (arg)
3883 (defun allout-open-sibtopic (arg)
3884 "Open new topic header at same level as the current one.
3886 Positive universal ARG means to use the bullet of the prior sibling.
3888 Negative universal ARG means to place the new topic prior to the current
3889 one."
3890 (interactive "p")
3891 (allout-open-topic 0 (> 0 arg) (not (= 1 arg))))
3892 ;;;_ > allout-open-supertopic (arg)
3893 (defun allout-open-supertopic (arg)
3894 "Open new topic header at shallower level than the current one.
3896 Negative universal ARG means to open shallower, but place the new
3897 topic prior to the current one."
3899 (interactive "p")
3900 (allout-open-topic -1 (> 0 arg) (< 1 arg)))
3902 ;;;_ - Outline Alteration
3903 ;;;_ : Topic Modification
3904 ;;;_ = allout-former-auto-filler
3905 (defvar allout-former-auto-filler nil
3906 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3907 ;;;_ > allout-auto-fill ()
3908 (defun allout-auto-fill ()
3909 "`allout-mode' autofill function.
3911 Maintains outline hanging topic indentation if
3912 `allout-use-hanging-indents' is set."
3914 (when (and (not allout-inhibit-auto-fill)
3915 (or (not allout-inhibit-auto-fill-on-headline)
3916 (not (allout-on-current-heading-p))))
3917 (let ((fill-prefix (if allout-use-hanging-indents
3918 ;; Check for topic header indentation:
3919 (save-match-data
3920 (save-excursion
3921 (beginning-of-line)
3922 (if (looking-at allout-regexp)
3923 ;; ... construct indentation to account for
3924 ;; length of topic prefix:
3925 (make-string (progn (allout-end-of-prefix)
3926 (current-column))
3927 ?\ ))))))
3928 (use-auto-fill-function
3929 (if (and (eq allout-outside-normal-auto-fill-function
3930 'allout-auto-fill)
3931 (eq auto-fill-function 'allout-auto-fill))
3932 'do-auto-fill
3933 (or allout-outside-normal-auto-fill-function
3934 auto-fill-function))))
3935 (if (or allout-former-auto-filler allout-use-hanging-indents)
3936 (funcall use-auto-fill-function)))))
3937 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3938 (defun allout-reindent-body (old-depth new-depth &optional _number)
3939 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3941 Optional arg NUMBER indicates numbering is being added, and it must
3942 be accommodated.
3944 Note that refill of indented paragraphs is not done."
3946 (save-excursion
3947 (allout-end-of-prefix)
3948 (let* ((new-margin (current-column))
3949 excess old-indent-begin old-indent-end
3950 ;; We want the column where the header-prefix text started
3951 ;; *before* the prefix was changed, so we infer it relative
3952 ;; to the new margin and the shift in depth:
3953 (old-margin (+ old-depth (- new-margin new-depth))))
3955 ;; Process lines up to (but excluding) next topic header:
3956 (allout-unprotected
3957 (save-match-data
3958 (while
3959 (and (re-search-forward "\n\\(\\s-*\\)"
3962 ;; Register the indent data, before we reset the
3963 ;; match data with a subsequent `looking-at':
3964 (setq old-indent-begin (match-beginning 1)
3965 old-indent-end (match-end 1))
3966 (not (looking-at allout-regexp)))
3967 (if (> 0 (setq excess (- (- old-indent-end old-indent-begin)
3968 old-margin)))
3969 ;; Text starts left of old margin -- don't adjust:
3971 ;; Text was hanging at or right of old left margin --
3972 ;; reindent it, preserving its existing indentation
3973 ;; beyond the old margin:
3974 (delete-region old-indent-begin old-indent-end)
3975 (indent-to (+ new-margin excess (current-column))))))))))
3976 ;;;_ > allout-rebullet-current-heading (arg)
3977 (defun allout-rebullet-current-heading (arg)
3978 "Solicit new bullet for current visible heading."
3979 (interactive "p")
3980 (let ((initial-col (current-column))
3981 (on-bullet (eq (point)(allout-current-bullet-pos)))
3982 from to
3983 (backwards (if (< arg 0)
3984 (setq arg (* arg -1)))))
3985 (while (> arg 0)
3986 (save-excursion (allout-back-to-current-heading)
3987 (allout-end-of-prefix)
3988 (setq from allout-recent-prefix-beginning
3989 to allout-recent-prefix-end)
3990 (allout-rebullet-heading t ;;; instead
3991 nil ;;; depth
3992 nil ;;; number-control
3993 nil ;;; index
3994 t) ;;; do-successors
3995 (run-hook-with-args 'allout-exposure-change-functions
3996 from to t))
3997 (setq arg (1- arg))
3998 (if (<= arg 0)
4000 (setq initial-col nil) ; Override positioning back to init col
4001 (if (not backwards)
4002 (allout-next-visible-heading 1)
4003 (allout-goto-prefix-doublechecked)
4004 (allout-next-visible-heading -1))))
4005 (message "Done.")
4006 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
4007 (initial-col (move-to-column initial-col)))))
4008 ;;;_ > allout-rebullet-heading (&optional instead ...)
4009 (defun allout-rebullet-heading (&optional instead
4010 new-depth
4011 number-control
4012 index
4013 do-successors)
4015 "Adjust bullet of current topic prefix.
4017 All args are optional.
4019 If INSTEAD is:
4020 - nil, then the bullet char for the context is used, per distinction or depth
4021 - a (numeric) character, then character's string representation is used
4022 - a string, then the user is asked for bullet with the first char as default
4023 - anything else, the user is solicited with bullet char per context as default
4025 Second arg DEPTH forces the topic prefix to that depth, regardless
4026 of the topic's current depth.
4028 Third arg NUMBER-CONTROL can force the prefix to or away from
4029 numbered form. It has effect only if `allout-numbered-bullet' is
4030 non-nil and soliciting was not explicitly invoked (via first arg).
4031 Its effect, numbering or denumbering, then depends on the setting
4032 of the fourth arg, INDEX.
4034 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
4035 prefix of the topic is forced to be non-numbered. Null index and
4036 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
4037 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
4038 INDEX is a number, then that number is used for the numbered
4039 prefix. Non-nil and non-number means that the index for the
4040 numbered prefix will be derived by allout-make-topic-prefix.
4042 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
4043 siblings.
4045 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
4046 and `allout-numbered-bullet', which all affect the behavior of
4047 this function."
4049 (let* ((current-depth (allout-depth))
4050 (new-depth (or new-depth current-depth))
4051 (mb allout-recent-prefix-beginning)
4052 (me allout-recent-prefix-end)
4053 (current-bullet (buffer-substring-no-properties (- me 1) me))
4054 (has-annotation (get-text-property mb 'allout-was-hidden))
4055 (new-prefix (allout-make-topic-prefix current-bullet
4057 new-depth
4058 instead
4059 number-control
4060 index)))
4062 ;; Is new one identical to old?
4063 (if (and (= current-depth new-depth)
4064 (string= current-bullet
4065 (substring new-prefix (1- (length new-prefix)))))
4066 ;; Nothing to do:
4069 ;; New prefix probably different from old:
4070 ; get rid of old one:
4071 (allout-unprotected (delete-region mb me))
4072 (goto-char mb)
4073 ; Dispense with number if
4074 ; numbered-bullet prefix:
4075 (save-match-data
4076 (if (and allout-numbered-bullet
4077 (string= allout-numbered-bullet current-bullet)
4078 (looking-at "[0-9]+"))
4079 (allout-unprotected
4080 (delete-region (match-beginning 0)(match-end 0)))))
4082 ;; convey 'allout-was-hidden annotation, if original had it:
4083 (if has-annotation
4084 (put-text-property 0 (length new-prefix) 'allout-was-hidden t
4085 new-prefix))
4087 ; Put in new prefix:
4088 (allout-unprotected (insert new-prefix))
4090 ;; Reindent the body if elected, margin changed, and not encrypted body:
4091 (if (and allout-reindent-bodies
4092 (not (= new-depth current-depth))
4093 (not (allout-encrypted-topic-p)))
4094 (allout-reindent-body current-depth new-depth))
4096 (run-hook-with-args 'allout-exposure-change-functions mb me nil)
4098 ;; Recursively rectify successive siblings of orig topic if
4099 ;; caller elected for it:
4100 (if do-successors
4101 (save-excursion
4102 (while (allout-next-sibling new-depth nil)
4103 (setq index
4104 (cond ((numberp index) (1+ index))
4105 ((not number-control) (allout-sibling-index))))
4106 (if (allout-numbered-type-prefix)
4107 (allout-rebullet-heading nil ;;; instead
4108 new-depth ;;; new-depth
4109 number-control;;; number-control
4110 index ;;; index
4111 nil))))) ;;;(dont!)do-successors
4112 ) ; (if (and (= current-depth new-depth)...))
4113 ) ; let* ((current-depth (allout-depth))...)
4114 ) ; defun
4115 ;;;_ > allout-rebullet-topic (arg)
4116 (defun allout-rebullet-topic (arg &optional sans-offspring)
4117 "Rebullet the visible topic containing point and all contained subtopics.
4119 Descends into invisible as well as visible topics, however.
4121 When optional SANS-OFFSPRING is non-nil, subtopics are not
4122 shifted. (Shifting a topic outwards without shifting its
4123 offspring is disallowed, since this would create a \"containment
4124 discontinuity\", where the depth difference between a topic and
4125 its immediate offspring is greater than one.)
4127 With repeat count, shift topic depth by that amount."
4128 (interactive "P")
4129 (let ((start-col (current-column)))
4130 (save-excursion
4131 ;; Normalize arg:
4132 (cond ((null arg) (setq arg 0))
4133 ((listp arg) (setq arg (car arg))))
4134 ;; Fill the user in, in case we're shifting a big topic:
4135 (if (not (zerop arg)) (message "Shifting..."))
4136 (allout-back-to-current-heading)
4137 (if (<= (+ allout-recent-depth arg) 0)
4138 (error "Attempt to shift topic below level 1"))
4139 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring)
4140 (if (not (zerop arg)) (message "Shifting... done.")))
4141 (move-to-column (max 0 (+ start-col arg)))))
4142 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4143 (defun allout-rebullet-topic-grunt (&optional relative-depth
4144 starting-depth
4145 starting-point
4146 index
4147 do-successors
4148 sans-offspring)
4149 "Like `allout-rebullet-topic', but on nearest containing topic
4150 \(visible or not).
4152 See `allout-rebullet-heading' for rebulleting behavior.
4154 All arguments are optional.
4156 First arg RELATIVE-DEPTH means to shift the depth of the entire
4157 topic that amount.
4159 Several subsequent args are for internal recursive use by the function
4160 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4162 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4163 are not shifted. (Shifting a topic outwards without shifting
4164 its offspring is disallowed, since this would create a
4165 \"containment discontinuity\", where the depth difference between
4166 a topic and its immediate offspring is greater than one.)"
4168 ;; XXX the recursion here is peculiar, and in general the routine may
4169 ;; need simplification with refactoring.
4171 (if (and sans-offspring
4172 relative-depth
4173 (< relative-depth 0))
4174 (error (concat "Attempt to shift topic outwards without offspring,"
4175 " would cause containment discontinuity.")))
4177 (let* ((relative-depth (or relative-depth 0))
4178 (new-depth (allout-depth))
4179 (starting-depth (or starting-depth new-depth))
4180 (on-starting-call (null starting-point))
4181 (index (or index
4182 ;; Leave index null on starting call, so rebullet-heading
4183 ;; calculates it at what might be new depth:
4184 (and (or (zerop relative-depth)
4185 (not on-starting-call))
4186 (allout-sibling-index))))
4187 (starting-index index)
4188 (moving-outwards (< 0 relative-depth))
4189 (starting-point (or starting-point (point)))
4190 (local-point (point)))
4192 ;; Sanity check for excessive promotion done only on starting call:
4193 (and on-starting-call
4194 moving-outwards
4195 (> 0 (+ starting-depth relative-depth))
4196 (error "Attempt to shift topic out beyond level 1"))
4198 (cond ((= starting-depth new-depth)
4199 ;; We're at depth to work on this one.
4201 ;; When shifting out we work on the children before working on
4202 ;; the parent to avoid interim `allout-aberrant-container-p'
4203 ;; aberrancy, and vice-versa when shifting in:
4204 (if (>= relative-depth 0)
4205 (allout-rebullet-heading nil
4206 (+ starting-depth relative-depth)
4207 nil ;;; number
4208 index
4209 nil)) ;;; do-successors
4210 (when (not sans-offspring)
4211 ;; ... and work on subsequent ones which are at greater depth:
4212 (setq index 0)
4213 (allout-next-heading)
4214 (while (and (not (eobp))
4215 (< starting-depth (allout-depth)))
4216 (setq index (1+ index))
4217 (allout-rebullet-topic-grunt relative-depth
4218 (1+ starting-depth)
4219 starting-point
4220 index)))
4221 (when (< relative-depth 0)
4222 (save-excursion
4223 (goto-char local-point)
4224 (allout-rebullet-heading nil ;;; instead
4225 (+ starting-depth relative-depth)
4226 nil ;;; number
4227 starting-index
4228 nil)))) ;;; do-successors
4230 ((< starting-depth new-depth)
4231 ;; Rare case -- subtopic more than one level deeper than parent.
4232 ;; Treat this one at an even deeper level:
4233 (allout-rebullet-topic-grunt relative-depth
4234 new-depth
4235 starting-point
4236 index
4237 sans-offspring)))
4239 (if on-starting-call
4240 (progn
4241 ;; Rectify numbering of former siblings of the adjusted topic,
4242 ;; if topic has changed depth
4243 (if (or do-successors
4244 (and (not (zerop relative-depth))
4245 (or (= allout-recent-depth starting-depth)
4246 (= allout-recent-depth (+ starting-depth
4247 relative-depth)))))
4248 (allout-rebullet-heading nil nil nil nil t))
4249 ;; Now rectify numbering of new siblings of the adjusted topic,
4250 ;; if depth has been changed:
4251 (progn (goto-char starting-point)
4252 (if (not (zerop relative-depth))
4253 (allout-rebullet-heading nil nil nil nil t)))))
4256 ;;;_ > allout-renumber-to-depth (&optional depth)
4257 (defun allout-renumber-to-depth (&optional depth)
4258 "Renumber siblings at current depth.
4260 Affects superior topics if optional arg DEPTH is less than current depth.
4262 Returns final depth."
4264 ;; Proceed by level, processing subsequent siblings on each,
4265 ;; ascending until we get shallower than the start depth:
4267 (let ((ascender (allout-depth))
4268 was-eobp)
4269 (while (and (not (eobp))
4270 (allout-depth)
4271 (>= allout-recent-depth depth)
4272 (>= ascender depth))
4273 ; Skip over all topics at
4274 ; lesser depths, which can not
4275 ; have been disturbed:
4276 (while (and (not (setq was-eobp (eobp)))
4277 (> allout-recent-depth ascender))
4278 (allout-next-heading))
4279 ; Prime ascender for ascension:
4280 (setq ascender (1- allout-recent-depth))
4281 (if (>= allout-recent-depth depth)
4282 (allout-rebullet-heading nil ;;; instead
4283 nil ;;; depth
4284 nil ;;; number-control
4285 nil ;;; index
4286 t)) ;;; do-successors
4287 (if was-eobp (goto-char (point-max)))))
4288 allout-recent-depth)
4289 ;;;_ > allout-number-siblings (&optional denumber)
4290 (defun allout-number-siblings (&optional denumber)
4291 "Assign numbered topic prefix to this topic and its siblings.
4293 With universal argument, denumber -- assign default bullet to this
4294 topic and its siblings.
4296 With repeated universal argument (`^U^U'), solicit bullet for each
4297 rebulleting each topic at this level."
4299 (interactive "P")
4301 (save-excursion
4302 (allout-back-to-current-heading)
4303 (allout-beginning-of-level)
4304 (let ((depth allout-recent-depth)
4305 (index (if (not denumber) 1))
4306 (use-bullet (equal '(16) denumber))
4307 (more t))
4308 (while more
4309 (allout-rebullet-heading use-bullet ;;; instead
4310 depth ;;; depth
4311 t ;;; number-control
4312 index ;;; index
4313 nil) ;;; do-successors
4314 (if index (setq index (1+ index)))
4315 (setq more (allout-next-sibling depth nil))))))
4316 ;;;_ > allout-shift-in (arg)
4317 (defun allout-shift-in (arg)
4318 "Increase depth of current heading and any items collapsed within it.
4320 With a negative argument, the item is shifted out using
4321 `allout-shift-out', instead.
4323 With an argument greater than one, shift-in the item but not its
4324 offspring, making the item into a sibling of its former children,
4325 and a child of sibling that formerly preceded it.
4327 You are not allowed to shift the first offspring of a topic
4328 inwards, because that would yield a \"containment
4329 discontinuity\", where the depth difference between a topic and
4330 its immediate offspring is greater than one. The first topic in
4331 the file can be adjusted to any positive depth, however."
4333 (interactive "p")
4334 (if (< arg 0)
4335 (allout-shift-out (* arg -1))
4336 ;; refuse to create a containment discontinuity:
4337 (save-excursion
4338 (allout-back-to-current-heading)
4339 (if (not (bobp))
4340 (let* ((current-depth allout-recent-depth)
4341 (start-point (point))
4342 (predecessor-depth (progn
4343 (forward-char -1)
4344 (allout-goto-prefix-doublechecked)
4345 (if (< (point) start-point)
4346 allout-recent-depth
4347 0))))
4348 (if (and (> predecessor-depth 0)
4349 (> (1+ current-depth)
4350 (1+ predecessor-depth)))
4351 (error (concat "Disallowed shift deeper than"
4352 " containing topic's children."))
4353 (allout-back-to-current-heading)
4354 (if (< allout-recent-depth (1+ current-depth))
4355 (allout-show-children))))))
4356 (let ((where (point)))
4357 (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring))
4358 (run-hook-with-args 'allout-structure-shifted-functions arg where))))
4359 ;;;_ > allout-shift-out (arg)
4360 (defun allout-shift-out (arg)
4361 "Decrease depth of current heading and any topics collapsed within it.
4362 This will make the item a sibling of its former container.
4364 With a negative argument, the item is shifted in using
4365 `allout-shift-in', instead.
4367 With an argument greater than one, shift-out the item's offspring
4368 but not the item itself, making the former children siblings of
4369 the item.
4371 With an argument greater than 1, the item's offspring are shifted
4372 out without shifting the item. This will make the immediate
4373 subtopics into siblings of the item."
4374 (interactive "p")
4375 (if (< arg 0)
4376 (allout-shift-in (* arg -1))
4377 ;; Get proper exposure in this area:
4378 (save-excursion (if (allout-ascend)
4379 (allout-show-children)))
4380 ;; Show collapsed children if there's a successor which will become
4381 ;; their sibling:
4382 (if (and (allout-current-topic-collapsed-p)
4383 (save-excursion (allout-next-sibling)))
4384 (allout-show-children))
4385 (let ((where (and (allout-depth) allout-recent-prefix-beginning)))
4386 (save-excursion
4387 (if (> arg 1)
4388 ;; Shift the offspring but not the topic:
4389 (let ((children-chart (allout-chart-subtree 1)))
4390 (if (listp (car children-chart))
4391 ;; whoops:
4392 (setq children-chart (allout-flatten children-chart)))
4393 (save-excursion
4394 (dolist (child-point children-chart)
4395 (goto-char child-point)
4396 (allout-shift-out 1))))
4397 (allout-rebullet-topic (* arg -1))))
4398 (run-hook-with-args 'allout-structure-shifted-functions (* arg -1) where))))
4399 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4400 ;;;_ > allout-kill-line (&optional arg)
4401 (defun allout-kill-line (&optional arg)
4402 "Kill line, adjusting subsequent lines suitably for outline mode."
4404 (interactive "*P")
4406 (if (or (not (allout-mode-p))
4407 (not (bolp))
4408 (not (save-match-data (looking-at allout-regexp))))
4409 ;; Just do a regular kill:
4410 (kill-line arg)
4411 ;; Ah, have to watch out for adjustments:
4412 (let* ((beg (point))
4414 (beg-hidden (allout-hidden-p))
4415 (end-hidden (save-excursion (allout-end-of-current-line)
4416 (setq end (point))
4417 (allout-hidden-p)))
4418 (depth (allout-depth)))
4420 (allout-annotate-hidden beg end)
4421 (unwind-protect
4422 (if (and (not beg-hidden) (not end-hidden))
4423 (allout-unprotected (kill-line arg))
4424 (kill-line arg))
4425 (run-hooks 'allout-after-copy-or-kill-hook)
4426 (allout-deannotate-hidden beg end)
4428 (if allout-numbered-bullet
4429 (save-excursion ; Renumber subsequent topics if needed:
4430 (if (not (save-match-data (looking-at allout-regexp)))
4431 (allout-next-heading))
4432 (allout-renumber-to-depth depth)))
4433 (run-hook-with-args 'allout-structure-deleted-functions depth (point))))))
4434 ;;;_ > allout-copy-line-as-kill ()
4435 (defun allout-copy-line-as-kill ()
4436 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4437 (interactive)
4438 (let ((buffer-read-only t))
4439 (condition-case nil
4440 (allout-kill-line)
4441 (buffer-read-only nil))))
4442 ;;;_ > allout-kill-topic ()
4443 (defun allout-kill-topic ()
4444 "Kill topic together with subtopics.
4446 Trailing whitespace is killed with a topic if that whitespace:
4448 - would separate the topic from a subsequent sibling
4449 - would separate the topic from the end of buffer
4450 - would not be added to whitespace already separating the topic from the
4451 previous one.
4453 Topic exposure is marked with text-properties, to be used by
4454 `allout-yank-processing' for exposure recovery."
4456 (interactive)
4457 (let* ((inhibit-field-text-motion t)
4458 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4460 (depth allout-recent-depth))
4461 (allout-end-of-current-subtree)
4462 (if (and (/= (current-column) 0) (not (eobp)))
4463 (forward-char 1))
4464 (if (not (eobp))
4465 (if (and (= (following-char) ?\n)
4466 (or (save-excursion
4467 (or (not (allout-next-heading))
4468 (= depth allout-recent-depth)))
4469 (and (> (- beg (point-min)) 3)
4470 (string= (buffer-substring (- beg 2) beg) "\n\n"))))
4471 (forward-char 1)))
4473 (allout-annotate-hidden beg (setq end (point)))
4474 (unwind-protect ; for possible barf-if-buffer-read-only.
4475 (allout-unprotected (kill-region beg end))
4476 (allout-deannotate-hidden beg end)
4477 (run-hooks 'allout-after-copy-or-kill-hook)
4479 (save-excursion
4480 (allout-renumber-to-depth depth))
4481 (run-hook-with-args 'allout-structure-deleted-functions depth (point)))))
4482 ;;;_ > allout-copy-topic-as-kill ()
4483 (defun allout-copy-topic-as-kill ()
4484 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4485 (interactive)
4486 (let ((buffer-read-only t))
4487 (condition-case nil
4488 (allout-kill-topic)
4489 (buffer-read-only (message "Topic copied...")))))
4490 ;;;_ > allout-annotate-hidden (begin end)
4491 (defun allout-annotate-hidden (begin end)
4492 "Qualify text with properties to indicate exposure status."
4494 (let ((was-modified (buffer-modified-p))
4495 (buffer-read-only nil))
4496 (allout-deannotate-hidden begin end)
4497 (save-excursion
4498 (goto-char begin)
4499 (let (done next prev overlay)
4500 (while (not done)
4501 ;; at or advance to start of next hidden region:
4502 (if (not (allout-hidden-p))
4503 (setq next
4504 (max (1+ (point))
4505 (allout-next-single-char-property-change (point)
4506 'invisible
4507 nil end))))
4508 (if (or (not next) (eq prev next))
4509 ;; still not at start of hidden area -- must not be any left.
4510 (setq done t)
4511 (goto-char next)
4512 (setq prev next)
4513 (if (not (allout-hidden-p))
4514 ;; still not at start of hidden area.
4515 (setq done t)
4516 (setq overlay (allout-get-invisibility-overlay))
4517 (setq next (overlay-end overlay)
4518 prev next)
4519 ;; advance to end of this hidden area:
4520 (when next
4521 (goto-char next)
4522 (allout-unprotected
4523 (let ((buffer-undo-list t))
4524 (put-text-property (overlay-start overlay) next
4525 'allout-was-hidden t)))))))))
4526 (set-buffer-modified-p was-modified)))
4527 ;;;_ > allout-deannotate-hidden (begin end)
4528 (defun allout-deannotate-hidden (begin end)
4529 "Remove allout hidden-text annotation between BEGIN and END."
4531 (allout-unprotected
4532 (let ((inhibit-read-only t)
4533 (buffer-undo-list t))
4534 (remove-text-properties begin (min end (point-max))
4535 '(allout-was-hidden t)))))
4536 ;;;_ > allout-hide-by-annotation (begin end)
4537 (defun allout-hide-by-annotation (begin end)
4538 "Translate text properties indicating exposure status into actual exposure."
4539 (save-excursion
4540 (goto-char begin)
4541 (let ((was-modified (buffer-modified-p))
4542 done next prev)
4543 (while (not done)
4544 ;; at or advance to start of next annotation:
4545 (if (not (get-text-property (point) 'allout-was-hidden))
4546 (setq next (allout-next-single-char-property-change
4547 (point) 'allout-was-hidden nil end)))
4548 (if (or (not next) (eq prev next))
4549 ;; no more or not advancing -- must not be any left.
4550 (setq done t)
4551 (goto-char next)
4552 (setq prev next)
4553 (if (not (get-text-property (point) 'allout-was-hidden))
4554 ;; still not at start of annotation.
4555 (setq done t)
4556 ;; advance to just after end of this annotation:
4557 (setq next (allout-next-single-char-property-change
4558 (point) 'allout-was-hidden nil end))
4559 (let ((o (make-overlay prev next nil 'front-advance)))
4560 (overlay-put o 'category 'allout-exposure-category)
4561 (overlay-put o 'evaporate t))
4562 (allout-deannotate-hidden prev next)
4563 (setq prev next)
4564 (if next (goto-char next)))))
4565 (set-buffer-modified-p was-modified))))
4566 ;;;_ > allout-yank-processing ()
4567 (defun allout-yank-processing (&optional _arg)
4569 "Incidental allout-specific business to be done just after text yanks.
4571 Does depth adjustment of yanked topics, when:
4573 1 the stuff being yanked starts with a valid outline header prefix, and
4574 2 it is being yanked at the end of a line which consists of only a valid
4575 topic prefix.
4577 Also, adjusts numbering of subsequent siblings when appropriate.
4579 Depth adjustment alters the depth of all the topics being yanked
4580 the amount it takes to make the first topic have the depth of the
4581 header into which it's being yanked.
4583 The point is left in front of yanked, adjusted topics, rather than
4584 at the end (and vice-versa with the mark). Non-adjusted yanks,
4585 however, are left exactly like normal, non-allout-specific yanks."
4587 (interactive "*P")
4588 ; Get to beginning, leaving
4589 ; region around subject:
4590 (if (< (allout-mark-marker t) (point))
4591 (exchange-point-and-mark))
4592 (save-match-data
4593 (let* ((subj-beg (point))
4594 (into-bol (bolp))
4595 (subj-end (allout-mark-marker t))
4596 ;; 'resituate' if yanking an entire topic into topic header:
4597 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t))
4598 (allout-e-o-prefix-p))
4599 (looking-at allout-regexp)
4600 (allout-prefix-data)))
4601 ;; `rectify-numbering' if resituating (where several topics may
4602 ;; be resituating) or yanking a topic into a topic slot (bol):
4603 (rectify-numbering (or resituate
4604 (and into-bol (looking-at allout-regexp)))))
4605 (if resituate
4606 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4607 (let* ((inhibit-field-text-motion t)
4608 (prefix-len (if (not (match-end 1))
4610 (- (match-end 1) subj-beg)))
4611 (subj-depth allout-recent-depth)
4612 (prefix-bullet (allout-recent-bullet))
4613 (adjust-to-depth
4614 ;; Nil if adjustment unnecessary, otherwise depth to which
4615 ;; adjustment should be made:
4616 (save-excursion
4617 (and (goto-char subj-end)
4618 (eolp)
4619 (goto-char subj-beg)
4620 (and (looking-at allout-regexp)
4621 (progn
4622 (beginning-of-line)
4623 (not (= (point) subj-beg)))
4624 (looking-at allout-regexp)
4625 (allout-prefix-data))
4626 allout-recent-depth)))
4627 (more t))
4628 (setq rectify-numbering allout-numbered-bullet)
4629 (if adjust-to-depth
4630 ; Do the adjustment:
4631 (progn
4632 (save-restriction
4633 (narrow-to-region subj-beg subj-end)
4634 ; Trim off excessive blank
4635 ; line at end, if any:
4636 (goto-char (point-max))
4637 (if (looking-at "^$")
4638 (allout-unprotected (delete-char -1)))
4639 ; Work backwards, with each
4640 ; shallowest level,
4641 ; successively excluding the
4642 ; last processed topic from
4643 ; the narrow region:
4644 (while more
4645 (allout-back-to-current-heading)
4646 ; go as high as we can in each bunch:
4647 (while (allout-ascend t))
4648 (save-excursion
4649 (allout-unprotected
4650 (allout-rebullet-topic-grunt (- adjust-to-depth
4651 subj-depth)))
4652 (allout-depth))
4653 (if (setq more (not (bobp)))
4654 (progn (widen)
4655 (forward-char -1)
4656 (narrow-to-region subj-beg (point))))))
4657 ;; Remove new heading prefix:
4658 (allout-unprotected
4659 (progn
4660 (delete-region (point) (+ (point)
4661 prefix-len
4662 (- adjust-to-depth
4663 subj-depth)))
4664 ; and delete residual subj
4665 ; prefix digits and space:
4666 (while (looking-at "[0-9]") (delete-char 1))
4667 (delete-char -1)
4668 (if (not (eolp))
4669 (forward-char))))
4670 ;; Assert new topic's bullet - minimal effort if unchanged:
4671 (allout-rebullet-heading (string-to-char prefix-bullet)))
4672 (exchange-point-and-mark))))
4673 (if rectify-numbering
4674 (progn
4675 (save-excursion
4676 ; Give some preliminary feedback:
4677 (message "... reconciling numbers")
4678 ; ... and renumber, in case necessary:
4679 (goto-char subj-beg)
4680 (if (allout-goto-prefix-doublechecked)
4681 (allout-unprotected
4682 (allout-rebullet-heading nil ;;; instead
4683 (allout-depth) ;;; depth
4684 nil ;;; number-control
4685 nil ;;; index
4686 t)))
4687 (message ""))))
4688 (if (or into-bol resituate)
4689 (allout-hide-by-annotation (point) (allout-mark-marker t))
4690 (allout-deannotate-hidden (allout-mark-marker t) (point)))
4691 (if (not resituate)
4692 (exchange-point-and-mark))
4693 (run-hook-with-args 'allout-structure-added-functions subj-beg subj-end))))
4694 ;;;_ > allout-yank (&optional arg)
4695 (defun allout-yank (&optional arg)
4696 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4698 Non-topic yanks work no differently than normal yanks.
4700 If a topic is being yanked into a bare topic prefix, the depth of the
4701 yanked topic is adjusted to the depth of the topic prefix.
4703 1 we're yanking in an `allout-mode' buffer
4704 2 the stuff being yanked starts with a valid outline header prefix, and
4705 3 it is being yanked at the end of a line which consists of only a valid
4706 topic prefix.
4708 If these conditions hold then the depth of the yanked topics are all
4709 adjusted the amount it takes to make the first one at the depth of the
4710 header into which it's being yanked.
4712 The point is left in front of yanked, adjusted topics, rather than
4713 at the end (and vice-versa with the mark). Non-adjusted yanks,
4714 however, (ones that don't qualify for adjustment) are handled
4715 exactly like normal yanks.
4717 Numbering of yanked topics, and the successive siblings at the depth
4718 into which they're being yanked, is adjusted.
4720 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4721 works with normal `yank' in non-outline buffers."
4723 (interactive "*P")
4724 (setq this-command 'yank)
4725 (allout-unprotected
4726 (yank arg))
4727 (if (allout-mode-p)
4728 (allout-yank-processing)))
4729 ;;;_ > allout-yank-pop (&optional arg)
4730 (defun allout-yank-pop (&optional arg)
4731 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4733 Adapts level of popped topics to level of fresh prefix.
4735 Note -- prefix changes to distinctive bullets will stick, if followed
4736 by pops to non-distinctive yanks. Bug..."
4738 (interactive "*p")
4739 (setq this-command 'yank)
4740 (yank-pop arg)
4741 (if (allout-mode-p)
4742 (allout-yank-processing)))
4744 ;;;_ - Specialty bullet functions
4745 ;;;_ : File Cross references
4746 ;;;_ > allout-resolve-xref ()
4747 (defun allout-resolve-xref ()
4748 "Pop to file associated with current heading, if it has an xref bullet.
4750 \(Works according to setting of `allout-file-xref-bullet')."
4751 (interactive)
4752 (if (not allout-file-xref-bullet)
4753 (error
4754 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4755 (if (not (string= (allout-current-bullet) allout-file-xref-bullet))
4756 (error "Current heading lacks cross-reference bullet `%s'"
4757 allout-file-xref-bullet)
4758 (let ((inhibit-field-text-motion t)
4759 file-name)
4760 (save-match-data
4761 (save-excursion
4762 (let* ((text-start allout-recent-prefix-end)
4763 (heading-end (point-at-eol)))
4764 (goto-char text-start)
4765 (setq file-name
4766 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t)
4767 (buffer-substring (match-beginning 1)
4768 (match-end 1)))))))
4769 (setq file-name (expand-file-name file-name))
4770 (if (or (file-exists-p file-name)
4771 (if (file-writable-p file-name)
4772 (y-or-n-p (format "%s not there, create one? "
4773 file-name))
4774 (error "%s not found and can't be created" file-name)))
4775 (condition-case failure
4776 (find-file-other-window file-name)
4777 (error failure))
4778 (error "%s not found" file-name))
4784 ;;;_ #6 Exposure Control
4786 ;;;_ - Fundamental
4787 ;;;_ > allout-flag-region (from to flag)
4788 (defun allout-flag-region (from to flag)
4789 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4790 After the exposure changes are made, run the abnormal hook
4791 `allout-exposure-change-functions' with the same arguments as
4792 this function."
4794 ;; We use outline invisibility spec.
4795 (remove-overlays from to 'category 'allout-exposure-category)
4796 (when flag
4797 (let ((o (make-overlay from to nil 'front-advance)))
4798 (overlay-put o 'category 'allout-exposure-category)
4799 (overlay-put o 'evaporate t)
4800 (when (featurep 'xemacs)
4801 (let ((props (symbol-plist 'allout-exposure-category)))
4802 (while props
4803 (condition-case nil
4804 ;; as of 2008-02-27, xemacs lacks modification-hooks
4805 (overlay-put o (pop props) (pop props))
4806 (error nil))))))
4807 (setq allout-this-command-hid-text t))
4808 (run-hook-with-args 'allout-exposure-change-functions from to flag))
4809 ;;;_ > allout-flag-current-subtree (flag)
4810 (defun allout-flag-current-subtree (flag)
4811 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4813 (save-excursion
4814 (allout-back-to-current-heading)
4815 (let ((inhibit-field-text-motion t))
4816 (end-of-line))
4817 (allout-flag-region (point)
4818 ;; Exposing must not leave trailing blanks hidden,
4819 ;; but can leave them exposed when hiding, so we
4820 ;; can use flag's inverse as the
4821 ;; include-trailing-blank cue:
4822 (allout-end-of-current-subtree (not flag))
4823 flag)))
4825 ;;;_ - Topic-specific
4826 ;;;_ > allout-show-entry ()
4827 (defun allout-show-entry ()
4828 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4830 This is a way to give restricted peek at a concealed locality without the
4831 expense of exposing its context, but can leave the outline with aberrant
4832 exposure. `allout-show-offshoot' should be used after the peek to rectify
4833 the exposure."
4835 (interactive)
4836 (save-excursion
4837 (let (beg end)
4838 (allout-goto-prefix-doublechecked)
4839 (setq beg (if (allout-hidden-p) (1- (point)) (point)))
4840 (setq end (allout-pre-next-prefix))
4841 (allout-flag-region beg end nil)
4842 (list beg end))))
4843 ;;;_ > allout-show-children (&optional level strict)
4844 (defun allout-show-children (&optional level strict)
4846 "If point is visible, show all direct subheadings of this heading.
4848 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4850 Optional LEVEL specifies how many levels below the current level
4851 should be shown, or all levels if t. Default is 1.
4853 Optional STRICT means don't resort to -show-to-offshoot, no matter
4854 what. This is basically so -show-to-offshoot, which is called by
4855 this function, can employ the pure offspring-revealing capabilities of
4858 Returns point at end of subtree that was opened, if any. (May get a
4859 point of non-opened subtree?)"
4861 (interactive "p")
4862 (let ((start-point (point)))
4863 (if (and (not strict)
4864 (allout-hidden-p))
4866 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4867 ; expose it.
4868 ;; Then recurse, but with "strict" set so we don't
4869 ;; infinite regress:
4870 (allout-show-children level t))
4872 (save-excursion
4873 (allout-beginning-of-current-line)
4874 (save-restriction
4875 (let* (depth
4876 ;; translate the level spec for this routine to the ones
4877 ;; used by -chart-subtree and -chart-to-reveal:
4878 (chart-level (cond ((not level) 1)
4879 ((eq level t) nil)
4880 (t level)))
4881 (chart (allout-chart-subtree chart-level))
4882 (to-reveal (or (allout-chart-to-reveal chart chart-level)
4883 ;; interactive, show discontinuous children:
4884 (and chart
4885 (allout-called-interactively-p)
4886 (save-excursion
4887 (allout-back-to-current-heading)
4888 (setq depth (allout-current-depth))
4889 (and (allout-next-heading)
4890 (> allout-recent-depth
4891 (1+ depth))))
4892 (message
4893 "Discontinuous offspring; use `%s %s'%s."
4894 (substitute-command-keys
4895 "\\[universal-argument]")
4896 (substitute-command-keys
4897 "\\[allout-shift-out]")
4898 " to elevate them.")
4899 (allout-chart-to-reveal
4900 chart (- allout-recent-depth depth))))))
4901 (goto-char start-point)
4902 (when (and strict (allout-hidden-p))
4903 ;; Concealed root would already have been taken care of,
4904 ;; unless strict was set.
4905 (allout-flag-region (point) (allout-snug-back) nil)
4906 (when allout-show-bodies
4907 (goto-char (car to-reveal))
4908 (allout-show-current-entry)))
4909 (while to-reveal
4910 (goto-char (car to-reveal))
4911 (allout-flag-region (save-excursion (allout-snug-back) (point))
4912 (progn (search-forward "\n" nil t)
4913 (1- (point)))
4914 nil)
4915 (when allout-show-bodies
4916 (goto-char (car to-reveal))
4917 (allout-show-current-entry))
4918 (setq to-reveal (cdr to-reveal)))))))
4919 ;; Compensate for `save-excursion's maintenance of point
4920 ;; within invisible text:
4921 (goto-char start-point)))
4922 ;;;_ > allout-show-to-offshoot ()
4923 (defun allout-show-to-offshoot ()
4924 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4926 Useful for coherently exposing to a random point in a hidden region."
4927 (interactive)
4928 (save-excursion
4929 (let ((inhibit-field-text-motion t)
4930 (orig-pt (point))
4931 (orig-pref (allout-goto-prefix-doublechecked))
4932 (last-at (point))
4933 (bag-it 0))
4934 (while (or (> bag-it 1) (allout-hidden-p))
4935 (while (allout-hidden-p)
4936 (move-beginning-of-line 1)
4937 (if (allout-hidden-p) (forward-char -1)))
4938 (if (= last-at (setq last-at (point)))
4939 ;; Oops, we're not making any progress! Show the current topic
4940 ;; completely, and try one more time here, if we haven't already.
4941 (progn (beginning-of-line)
4942 (allout-show-current-subtree)
4943 (goto-char orig-pt)
4944 (setq bag-it (1+ bag-it))
4945 (if (> bag-it 1)
4946 (error "allout-show-to-offshoot: %s"
4947 "Stumped by aberrant nesting.")))
4948 (if (> bag-it 0) (setq bag-it 0))
4949 (allout-show-children)
4950 (goto-char orig-pref)))
4951 (goto-char orig-pt)))
4952 (if (allout-hidden-p)
4953 (allout-show-entry)))
4954 ;;;_ > allout-hide-current-entry ()
4955 (defun allout-hide-current-entry ()
4956 "Hide the body directly following this heading."
4957 (interactive)
4958 (allout-back-to-current-heading)
4959 (save-excursion
4960 (let ((inhibit-field-text-motion t))
4961 (end-of-line))
4962 (allout-flag-region (point)
4963 (progn (allout-end-of-entry) (point))
4964 t)))
4965 ;;;_ > allout-show-current-entry (&optional arg)
4966 (defun allout-show-current-entry (&optional arg)
4967 "Show body following current heading, or hide entry with universal argument."
4969 (interactive "P")
4970 (if arg
4971 (allout-hide-current-entry)
4972 (save-excursion (allout-show-to-offshoot))
4973 (save-excursion
4974 (allout-flag-region (point)
4975 (progn (allout-end-of-entry t) (point))
4976 nil)
4978 ;;;_ > allout-show-current-subtree (&optional arg)
4979 (defun allout-show-current-subtree (&optional arg)
4980 "Show everything within the current topic.
4981 With a repeat-count, expose this topic and its siblings."
4982 (interactive "P")
4983 (save-excursion
4984 (if (<= (allout-current-depth) 0)
4985 ;; Outside any topics -- try to get to the first:
4986 (if (not (allout-next-heading))
4987 (error "No topics")
4988 ;; got to first, outermost topic -- set to expose it and siblings:
4989 (message "Above outermost topic -- exposing all.")
4990 (allout-flag-region (point-min)(point-max) nil))
4991 (allout-beginning-of-current-line)
4992 (if (not arg)
4993 (allout-flag-current-subtree nil)
4994 (allout-beginning-of-level)
4995 (allout-expose-topic '(* :))))))
4996 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4997 (defun allout-current-topic-collapsed-p (&optional include-single-liners)
4998 "True if the currently visible containing topic is already collapsed.
5000 Single line topics intrinsically can be considered as being both
5001 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
5002 true, then single-line topics are considered to be collapsed. By
5003 default, they are treated as being uncollapsed."
5004 (save-match-data
5005 (save-excursion
5006 (and
5007 ;; Is the topic all on one line (allowing for trailing blank line)?
5008 (>= (progn (allout-back-to-current-heading)
5009 (let ((inhibit-field-text-motion t))
5010 (move-end-of-line 1))
5011 (point))
5012 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
5014 (or include-single-liners
5015 (progn (backward-char 1) (allout-hidden-p)))))))
5016 ;;;_ > allout-hide-current-subtree (&optional just-close)
5017 (defun allout-hide-current-subtree (&optional just-close)
5018 "Close the current topic, or containing topic if this one is already closed.
5020 If this topic is closed and it's a top level topic, close this topic
5021 and its siblings.
5023 If optional arg JUST-CLOSE is non-nil, do not close the parent or
5024 siblings, even if the target topic is already closed."
5026 (interactive)
5027 (let* ((from (point))
5028 (sibs-msg "Top-level topic already closed -- closing siblings...")
5029 (current-exposed (not (allout-current-topic-collapsed-p t))))
5030 (cond (current-exposed (allout-flag-current-subtree t))
5031 (just-close nil)
5032 ((allout-ascend) (allout-hide-current-subtree))
5033 (t (goto-char 0)
5034 (message sibs-msg)
5035 (allout-goto-prefix-doublechecked)
5036 (allout-expose-topic '(0 :))
5037 (message (concat sibs-msg " Done."))))
5038 (goto-char from)))
5039 ;;;_ > allout-toggle-current-subtree-exposure
5040 (defun allout-toggle-current-subtree-exposure ()
5041 "Show or hide the current subtree depending on its current state."
5042 ;; thanks to tassilo for suggesting this.
5043 (interactive)
5044 (save-excursion
5045 (allout-back-to-heading)
5046 (if (allout-hidden-p (point-at-eol))
5047 (allout-show-current-subtree)
5048 (allout-hide-current-subtree))))
5049 ;;;_ > allout-show-current-branches ()
5050 (defun allout-show-current-branches ()
5051 "Show all subheadings of this heading, but not their bodies."
5052 (interactive)
5053 (let ((inhibit-field-text-motion t))
5054 (beginning-of-line))
5055 (allout-show-children t))
5056 ;;;_ > allout-hide-current-leaves ()
5057 (defun allout-hide-current-leaves ()
5058 "Hide the bodies of the current topic and all its offspring."
5059 (interactive)
5060 (allout-back-to-current-heading)
5061 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
5062 (point))))
5064 ;;;_ - Region and beyond
5065 ;;;_ > allout-show-all ()
5066 (defun allout-show-all ()
5067 "Show all of the text in the buffer."
5068 (interactive)
5069 (message "Exposing entire buffer...")
5070 (allout-flag-region (point-min) (point-max) nil)
5071 (message "Exposing entire buffer... Done."))
5072 ;;;_ > allout-hide-bodies ()
5073 (defun allout-hide-bodies ()
5074 "Hide all of buffer except headings."
5075 (interactive)
5076 (allout-hide-region-body (point-min) (point-max)))
5077 ;;;_ > allout-hide-region-body (start end)
5078 (defun allout-hide-region-body (start end)
5079 "Hide all body lines in the region, but not headings."
5080 (save-match-data
5081 (save-excursion
5082 (save-restriction
5083 (narrow-to-region start end)
5084 (goto-char (point-min))
5085 (let ((inhibit-field-text-motion t))
5086 (while (not (eobp))
5087 (end-of-line)
5088 (allout-flag-region (point) (allout-end-of-entry) t)
5089 (if (not (eobp))
5090 (forward-char
5091 (if (looking-at "\n\n")
5092 2 1)))))))))
5094 ;;;_ > allout-expose-topic (spec)
5095 (defun allout-expose-topic (spec)
5096 "Apply exposure specs to successive outline topic items.
5098 Use the more convenient frontend, `allout-new-exposure', if you don't
5099 need evaluation of the arguments, or even better, the `allout-layout'
5100 variable-keyed mode-activation/auto-exposure feature of allout outline
5101 mode. See the respective documentation strings for more details.
5103 Cursor is left at start position.
5105 SPEC is either a number or a list.
5107 Successive specs on a list are applied to successive sibling topics.
5109 A simple spec (either a number, one of a few symbols, or the null
5110 list) dictates the exposure for the corresponding topic.
5112 Non-null lists recursively designate exposure specs for respective
5113 subtopics of the current topic.
5115 The `:' repeat spec is used to specify exposure for any number of
5116 successive siblings, up to the trailing ones for which there are
5117 explicit specs following the `:'.
5119 Simple (numeric and null-list) specs are interpreted as follows:
5121 Numbers indicate the relative depth to open the corresponding topic.
5122 - negative numbers force the topic to be closed before opening to the
5123 absolute value of the number, so all siblings are open only to
5124 that level.
5125 - positive numbers open to the relative depth indicated by the
5126 number, but do not force already opened subtopics to be closed.
5127 - 0 means to close topic -- hide all offspring.
5128 : - `repeat'
5129 apply prior element to all siblings at current level, *up to*
5130 those siblings that would be covered by specs following the `:'
5131 on the list. Ie, apply to all topics at level but the last
5132 ones. (Only first of multiple colons at same level is
5133 respected -- subsequent ones are discarded.)
5134 * - completely opens the topic, including bodies.
5135 + - shows all the sub headers, but not the bodies
5136 - - exposes the body of the corresponding topic.
5138 Examples:
5139 \(allout-expose-topic \\='(-1 : 0))
5140 Close this and all following topics at current level, exposing
5141 only their immediate children, but close down the last topic
5142 at this current level completely.
5143 \(allout-expose-topic \\='(-1 () : 1 0))
5144 Close current topic so only the immediate subtopics are shown;
5145 show the children in the second to last topic, and completely
5146 close the last one.
5147 \(allout-expose-topic \\='(-2 : -1 *))
5148 Expose children and grandchildren of all topics at current
5149 level except the last two; expose children of the second to
5150 last and completely open the last one."
5152 (interactive "xExposure spec: ")
5153 (if (not (listp spec))
5155 (let ((depth (allout-depth))
5156 (max-pos 0)
5157 prev-elem curr-elem
5158 stay)
5159 (while spec
5160 (setq prev-elem curr-elem
5161 curr-elem (car spec)
5162 spec (cdr spec))
5163 (cond ; Do current element:
5164 ((null curr-elem) nil)
5165 ((symbolp curr-elem)
5166 (cond ((eq curr-elem '*) (allout-show-current-subtree)
5167 (if (> allout-recent-end-of-subtree max-pos)
5168 (setq max-pos allout-recent-end-of-subtree)))
5169 ((eq curr-elem '+)
5170 (if (not (allout-hidden-p))
5171 (save-excursion (allout-hide-current-subtree t)))
5172 (allout-show-current-branches)
5173 (if (> allout-recent-end-of-subtree max-pos)
5174 (setq max-pos allout-recent-end-of-subtree)))
5175 ((eq curr-elem '-) (allout-show-current-entry))
5176 ((eq curr-elem ':)
5177 (setq stay t)
5178 ;; Expand the `repeat' spec to an explicit version,
5179 ;; w.r.t. remaining siblings:
5180 (let ((residue ; = # of sibs not covered by remaining spec
5181 ;; Dang, could be nice to make use of the chart, sigh:
5182 (- (length (allout-chart-siblings))
5183 (length spec))))
5184 (if (< 0 residue)
5185 ;; Some residue -- cover it with prev-elem:
5186 (setq spec (append (make-list residue prev-elem)
5187 spec)))))))
5188 ((numberp curr-elem)
5189 (if (and (>= 0 curr-elem) (not (allout-hidden-p)))
5190 (save-excursion (allout-hide-current-subtree t)
5191 (if (> 0 curr-elem)
5193 (if (> allout-recent-end-of-subtree max-pos)
5194 (setq max-pos
5195 allout-recent-end-of-subtree)))))
5196 (if (> (abs curr-elem) 0)
5197 (progn (allout-show-children (abs curr-elem))
5198 (if (> allout-recent-end-of-subtree max-pos)
5199 (setq max-pos allout-recent-end-of-subtree)))))
5200 ((listp curr-elem)
5201 (if (allout-descend-to-depth (1+ depth))
5202 (let ((got (allout-expose-topic curr-elem)))
5203 (if (and got (> got max-pos)) (setq max-pos got))))))
5204 (cond (stay (setq stay nil))
5205 ((listp (car spec)) nil)
5206 ((> max-pos (point))
5207 ;; Capitalize on max-pos state to get us nearer next sibling:
5208 (progn (goto-char (min (point-max) max-pos))
5209 (allout-next-heading)))
5210 ((allout-next-sibling depth))))
5211 max-pos)))
5212 ;;;_ > allout-old-expose-topic (spec &rest followers)
5213 (defun allout-old-expose-topic (spec &rest followers)
5215 "Deprecated. Use `allout-expose-topic' (with different schema
5216 format) instead.
5218 Dictate wholesale exposure scheme for current topic, according to SPEC.
5220 SPEC is either a number or a list. Optional successive args
5221 dictate exposure for subsequent siblings of current topic.
5223 A simple spec (either a number, a special symbol, or the null list)
5224 dictates the overall exposure for a topic. Non null lists are
5225 composite specs whose first element dictates the overall exposure for
5226 a topic, with the subsequent elements in the list interpreted as specs
5227 that dictate the exposure for the successive offspring of the topic.
5229 Simple (numeric and null-list) specs are interpreted as follows:
5231 - Numbers indicate the relative depth to open the corresponding topic:
5232 - negative numbers force the topic to be close before opening to the
5233 absolute value of the number.
5234 - positive numbers just open to the relative depth indicated by the number.
5235 - 0 just closes
5236 - `*' completely opens the topic, including bodies.
5237 - `+' shows all the sub headers, but not the bodies
5238 - `-' exposes the body and immediate offspring of the corresponding topic.
5240 If the spec is a list, the first element must be a number, which
5241 dictates the exposure depth of the topic as a whole. Subsequent
5242 elements of the list are nested SPECs, dictating the specific exposure
5243 for the corresponding offspring of the topic.
5245 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5247 (interactive "xExposure spec: ")
5248 (let ((inhibit-field-text-motion t)
5249 (depth (allout-current-depth))
5250 max-pos)
5251 (cond ((null spec) nil)
5252 ((symbolp spec)
5253 (if (eq spec '*) (allout-show-current-subtree))
5254 (if (eq spec '+) (allout-show-current-branches))
5255 (if (eq spec '-) (allout-show-current-entry)))
5256 ((numberp spec)
5257 (if (>= 0 spec)
5258 (save-excursion (allout-hide-current-subtree t)
5259 (end-of-line)
5260 (if (or (not max-pos)
5261 (> (point) max-pos))
5262 (setq max-pos (point)))
5263 (if (> 0 spec)
5264 (setq spec (* -1 spec)))))
5265 (if (> spec 0)
5266 (allout-show-children spec)))
5267 ((listp spec)
5268 ;(let ((got (allout-old-expose-topic (car spec))))
5269 ; (if (and got (or (not max-pos) (> got max-pos)))
5270 ; (setq max-pos got)))
5271 (let ((new-depth (+ (allout-current-depth) 1))
5272 got)
5273 (setq max-pos (allout-old-expose-topic (car spec)))
5274 (setq spec (cdr spec))
5275 (if (and spec
5276 (allout-descend-to-depth new-depth)
5277 (not (allout-hidden-p)))
5278 (progn (setq got (apply 'allout-old-expose-topic spec))
5279 (if (and got (or (not max-pos) (> got max-pos)))
5280 (setq max-pos got)))))))
5281 (while (and followers
5282 (progn (if (and max-pos (< (point) max-pos))
5283 (progn (goto-char max-pos)
5284 (setq max-pos nil)))
5285 (end-of-line)
5286 (allout-next-sibling depth)))
5287 (allout-old-expose-topic (car followers))
5288 (setq followers (cdr followers)))
5289 max-pos))
5290 ;;;_ > allout-new-exposure '()
5291 (defmacro allout-new-exposure (&rest spec)
5292 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5293 Some arguments that would need to be quoted in `allout-expose-topic'
5294 need not be quoted in `allout-new-exposure'.
5296 Cursor is left at start position.
5298 Use this instead of obsolete `allout-exposure'.
5300 Examples:
5301 \(allout-new-exposure (-1 () () () 1) 0)
5302 Close current topic at current level so only the immediate
5303 subtopics are shown, except also show the children of the
5304 third subtopic; and close the next topic at the current level.
5305 \(allout-new-exposure : -1 0)
5306 Close all topics at current level to expose only their
5307 immediate children, except for the last topic at the current
5308 level, in which even its immediate children are hidden.
5309 \(allout-new-exposure -2 : -1 *)
5310 Expose children and grandchildren of first topic at current
5311 level, and expose children of subsequent topics at current
5312 level *except* for the last, which should be opened completely."
5313 `(save-excursion
5314 (if (not (or (allout-goto-prefix-doublechecked)
5315 (allout-next-heading)))
5316 (error "allout-new-exposure: Can't find any outline topics"))
5317 (allout-expose-topic ',spec)))
5319 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5321 ;;;_ - Mapping and processing of topics
5322 ;;;_ ( See also Subtree Charting, in Navigation code.)
5323 ;;;_ > allout-stringify-flat-index (flat-index)
5324 (defun allout-stringify-flat-index (flat-index &optional context)
5325 "Convert list representing section/subsection/... to document string.
5327 Optional arg CONTEXT indicates interior levels to include."
5328 (let ((delim ".")
5329 result
5330 numstr
5331 (context-depth (or (and context 2) 1)))
5332 ;; Take care of the explicit context:
5333 (while (> context-depth 0)
5334 (setq numstr (int-to-string (car flat-index))
5335 flat-index (cdr flat-index)
5336 result (if flat-index
5337 (cons delim (cons numstr result))
5338 (cons numstr result))
5339 context-depth (if flat-index (1- context-depth) 0)))
5340 (setq delim " ")
5341 ;; Take care of the indentation:
5342 (if flat-index
5343 (progn
5344 (while flat-index
5345 (setq result
5346 (cons delim
5347 (cons (make-string
5348 (1+ (truncate (if (zerop (car flat-index))
5350 (log (car flat-index) 10))))
5352 result)))
5353 (setq flat-index (cdr flat-index)))
5354 ;; Dispose of single extra delim:
5355 (setq result (cdr result))))
5356 (apply 'concat result)))
5357 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5358 (defun allout-stringify-flat-index-plain (flat-index)
5359 "Convert list representing section/subsection/... to document string."
5360 (let ((delim ".")
5361 result)
5362 (while flat-index
5363 (setq result (cons (int-to-string (car flat-index))
5364 (if result
5365 (cons delim result))))
5366 (setq flat-index (cdr flat-index)))
5367 (apply 'concat result)))
5368 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5369 (defun allout-stringify-flat-index-indented (flat-index)
5370 "Convert list representing section/subsection/... to document string."
5371 (let ((delim ".")
5372 result
5373 numstr)
5374 ;; Take care of the explicit context:
5375 (setq numstr (int-to-string (car flat-index))
5376 flat-index (cdr flat-index)
5377 result (if flat-index
5378 (cons delim (cons numstr result))
5379 (cons numstr result)))
5380 (setq delim " ")
5381 ;; Take care of the indentation:
5382 (if flat-index
5383 (progn
5384 (while flat-index
5385 (setq result
5386 (cons delim
5387 (cons (make-string
5388 (1+ (truncate (if (zerop (car flat-index))
5390 (log (car flat-index) 10))))
5392 result)))
5393 (setq flat-index (cdr flat-index)))
5394 ;; Dispose of single extra delim:
5395 (setq result (cdr result))))
5396 (apply 'concat result)))
5397 ;;;_ > allout-listify-exposed (&optional start end format)
5398 (defun allout-listify-exposed (&optional start end format)
5400 "Produce a list representing exposed topics in current region.
5402 This list can then be used by `allout-process-exposed' to manipulate
5403 the subject region.
5405 Optional START and END indicate bounds of region.
5407 Optional arg, FORMAT, designates an alternate presentation form for
5408 the prefix:
5410 list -- Present prefix as numeric section.subsection..., starting with
5411 section indicated by the list, innermost nesting first.
5412 `indent' (symbol) -- Convert header prefixes to all white space,
5413 except for distinctive bullets.
5415 The elements of the list produced are lists that represents a topic
5416 header and body. The elements of that list are:
5418 - a number representing the depth of the topic,
5419 - a string representing the header-prefix, including trailing whitespace and
5420 bullet.
5421 - a string representing the bullet character,
5422 - and a series of strings, each containing one line of the exposed
5423 portion of the topic entry."
5425 (interactive "r")
5426 (save-excursion
5427 (let*
5428 ((inhibit-field-text-motion t)
5429 ;; state vars:
5430 strings prefix result depth new-depth out gone-out bullet beg
5431 next done)
5433 (goto-char start)
5434 (beginning-of-line)
5435 ;; Goto initial topic, and register preceding stuff, if any:
5436 (if (> (allout-goto-prefix-doublechecked) start)
5437 ;; First topic follows beginning point -- register preliminary stuff:
5438 (setq result
5439 (list (list 0 "" nil
5440 (buffer-substring-no-properties start
5441 (1- (point)))))))
5442 (while (and (not done)
5443 (not (eobp)) ; Loop until we've covered the region.
5444 (not (> (point) end)))
5445 (setq depth allout-recent-depth ; Current topics depth,
5446 bullet (allout-recent-bullet) ; ... bullet,
5447 prefix (allout-recent-prefix)
5448 beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
5449 (setq done ; The boundary for the current topic:
5450 (not (allout-next-visible-heading 1)))
5451 (setq new-depth allout-recent-depth)
5452 (setq gone-out out
5453 out (< new-depth depth))
5454 (beginning-of-line)
5455 (setq next (point))
5456 (goto-char beg)
5457 (setq strings nil)
5458 (while (> next (point)) ; Get all the exposed text in
5459 (setq strings
5460 (cons (buffer-substring-no-properties
5462 ;To hidden text or end of line:
5463 (progn
5464 (end-of-line)
5465 (allout-back-to-visible-text)))
5466 strings))
5467 (when (< (point) next) ; Resume from after hid text, if any.
5468 (line-move 1)
5469 (beginning-of-line))
5470 (setq beg (point)))
5471 ;; Accumulate list for this topic:
5472 (setq strings (nreverse strings))
5473 (setq result
5474 (cons
5475 (if format
5476 (let ((special (if (string-match
5477 (regexp-quote bullet)
5478 allout-distinctive-bullets-string)
5479 bullet)))
5480 (cond ((listp format)
5481 (list depth
5482 (if allout-flattened-numbering-abbreviation
5483 (allout-stringify-flat-index format
5484 gone-out)
5485 (allout-stringify-flat-index-plain
5486 format))
5487 strings
5488 special))
5489 ((eq format 'indent)
5490 (if special
5491 (list depth
5492 (concat (make-string (1+ depth) ? )
5493 (substring prefix -1))
5494 strings)
5495 (list depth
5496 (make-string depth ? )
5497 strings)))
5498 (t (error "allout-listify-exposed: %s %s"
5499 "invalid format" format))))
5500 (list depth prefix strings))
5501 result))
5502 ;; Reassess format, if any:
5503 (if (and format (listp format))
5504 (cond ((= new-depth depth)
5505 (setq format (cons (1+ (car format))
5506 (cdr format))))
5507 ((> new-depth depth) ; descending -- assume by 1:
5508 (setq format (cons 1 format)))
5510 ; Pop the residue:
5511 (while (< new-depth depth)
5512 (setq format (cdr format))
5513 (setq depth (1- depth)))
5514 ; And increment the current one:
5515 (setq format
5516 (cons (1+ (or (car format)
5517 -1))
5518 (cdr format)))))))
5519 ;; Put the list with first at front, to last at back:
5520 (nreverse result))))
5521 ;;;_ > allout-region-active-p ()
5522 (defmacro allout-region-active-p ()
5523 (cond ((fboundp 'use-region-p) '(use-region-p))
5524 ((fboundp 'region-active-p) '(region-active-p))
5525 (t 'mark-active)))
5526 ;;_ > allout-process-exposed (&optional func from to frombuf
5527 ;;; tobuf format)
5528 (defun allout-process-exposed (&optional func from to frombuf tobuf
5529 format _start-num)
5530 "Map function on exposed parts of current topic; results to another buffer.
5532 All args are options; default values itemized below.
5534 Apply FUNCTION to exposed portions FROM position TO position in buffer
5535 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5536 alternate presentation form:
5538 `flat' -- Present prefix as numeric section.subsection..., starting with
5539 section indicated by the START-NUM, innermost nesting first.
5540 X`flat-indented' -- Prefix is like `flat' for first topic at each
5541 X level, but subsequent topics have only leaf topic
5542 X number, padded with blanks to line up with first.
5543 `indent' (symbol) -- Convert header prefixes to all white space,
5544 except for distinctive bullets.
5546 Defaults:
5547 FUNCTION: `allout-insert-listified'
5548 FROM: region start, if region active, else start of buffer
5549 TO: region end, if region active, else end of buffer
5550 FROMBUF: current buffer
5551 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5552 FORMAT: nil"
5554 ; Resolve arguments,
5555 ; defaulting if necessary:
5556 (if (not func) (setq func 'allout-insert-listified))
5557 (if (not (and from to))
5558 (if (allout-region-active-p)
5559 (setq from (region-beginning) to (region-end))
5560 (setq from (point-min) to (point-max))))
5561 (if frombuf
5562 (if (not (bufferp frombuf))
5563 ;; Specified but not a buffer -- get it:
5564 (let ((got (get-buffer frombuf)))
5565 (if (not got)
5566 (error "allout-process-exposed: source buffer %s not found."
5567 frombuf)
5568 (setq frombuf got))))
5569 ;; not specified -- default it:
5570 (setq frombuf (current-buffer)))
5571 (if tobuf
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*")))
5576 (if (listp format)
5577 (nreverse format))
5579 (let* ((listified
5580 (progn (set-buffer frombuf)
5581 (allout-listify-exposed from to format))))
5582 (set-buffer tobuf)
5583 (mapc func listified)
5584 (pop-to-buffer tobuf)))
5586 ;;;_ - Copy exposed
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
5600 (car listified)
5601 (setq listified (cdr listified))))
5602 (text (prog1
5603 (car listified)
5604 (setq listified (cdr listified))))
5605 (bullet-plus (car listified)))
5606 (insert prefix)
5607 (if bullet-plus (insert (concat " " bullet-plus)))
5608 (while text
5609 (insert (car text))
5610 (if (setq text (cdr text))
5611 (insert "\n")))
5612 (insert "\n")))
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."
5634 (interactive "P")
5635 (if (not tobuf)
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))
5641 (start-list ()))
5642 (if (eq format 'flat)
5643 (setq format (if arg (save-excursion
5644 (goto-char beg)
5645 (allout-topic-flat-index))
5646 '(1))))
5647 (with-current-buffer tobuf (erase-buffer))
5648 (allout-process-exposed 'allout-insert-listified
5651 (current-buffer)
5652 tobuf
5653 format start-list)
5654 (goto-char (point-min))
5655 (pop-to-buffer buf)
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
5670 used verbatim."
5671 (interactive "P")
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
5686 used verbatim."
5687 (interactive "P")
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
5697 (lambda (char)
5698 (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
5699 (concat "\\char" (number-to-string char) "{}"))
5700 ((= char ?\n) "\\\\")
5701 (t (char-to-string char)))))
5702 string
5703 ""))
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))
5712 (beginning-of-line)
5713 (let (;(beg (point))
5714 (end (point-at-eol)))
5715 (save-match-data
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))
5721 (insert "\\")
5722 (setq end (1+ end))
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.
5729 (set-buffer buffer)
5730 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5731 "report"))
5732 (page-numbering (if allout-number-pages
5733 "\\pagestyle{empty}\n"
5734 ""))
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}{"
5746 allout-indent
5747 "}\n"))
5748 (oneheadline (format "%s%s%s%s%s%s%s"
5749 "\\newcommand{\\OneHeadLine}[3]{%\n"
5750 "\\noindent%\n"
5751 "\\hspace*{#2\\stepsize}%\n"
5752 "\\labelcmd{#1}\\hspace*{.2cm}"
5753 "\\headlinecmd{#3}\\\\["
5754 allout-line-skip
5755 "]\n}\n"))
5756 (onebodyline (format "%s%s%s%s%s%s"
5757 "\\newcommand{\\OneBodyLine}[2]{%\n"
5758 "\\noindent%\n"
5759 "\\hspace*{#1\\stepsize}%\n"
5760 "\\bodylinecmd{#2}\\\\["
5761 allout-line-skip
5762 "]\n}\n"))
5763 (begindoc "\\begin{document}\n\\begin{center}\n")
5764 (title (format "%s%s%s%s"
5765 "\\titlecmd{"
5766 (allout-latex-verb-quote (if allout-title
5767 (condition-case nil
5768 (eval allout-title)
5769 (error "<unnamed buffer>"))
5770 "Unnamed Outline"))
5771 "}\n"
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
5777 page-numbering
5778 titlecmd
5779 labelcmd
5780 headlinecmd
5781 bodylinecmd
5782 setlength
5783 oneheadline
5784 onebodyline
5785 begindoc
5786 title
5787 hsize
5788 hoffset
5789 vspace)
5791 ;;;_ > allout-insert-latex-trailer (buffer)
5792 (defun allout-insert-latex-trailer (buffer)
5793 "Insert concluding LaTeX commands at point in BUFFER."
5794 (set-buffer 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))
5804 (curr-line)
5805 body-content bop)
5806 ; Do the head line:
5807 (insert (concat "\\OneHeadLine{\\verb\1 "
5808 (allout-latex-verb-quote bullet)
5809 "\1}{"
5810 depth
5811 "}{\\verb\1 "
5812 (if head-line
5813 (allout-latex-verb-quote head-line)
5815 "\1}\n"))
5816 (if (not body-lines)
5818 ;;(insert "\\beginlines\n")
5819 (insert "\\begin{verbatim}\n")
5820 (while body-lines
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,
5827 ; it's special:
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) "|")
5834 (insert curr-line)
5835 (allout-latex-verbatim-quote-curr-line)
5836 (insert "\n")
5837 (setq body-lines (cdr body-lines)))
5838 (if body-content
5839 (setq body-content nil)
5840 (forward-char -1)
5841 (insert "\\ ")
5842 (forward-char 1))
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."
5854 (interactive "P")
5855 (if (not tobuf)
5856 (setq tobuf
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)))
5862 (set-buffer tobuf)
5863 (erase-buffer)
5864 (allout-insert-latex-header tobuf)
5865 (goto-char (point-max))
5866 (allout-process-exposed 'allout-latexify-one-item
5870 tobuf)
5871 (goto-char (point-max))
5872 (allout-insert-latex-trailer tobuf)
5873 (goto-char (point-min))
5874 (pop-to-buffer buf)
5875 (goto-char start-pt)))
5877 ;;;_ #8 Encryption
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
5884 armored.
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
5894 encryption.
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
5901 dialog.
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."
5919 (interactive "P")
5920 (save-excursion
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
5935 encryption.
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
5942 dialog.
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."
5950 (interactive "P")
5951 (save-excursion
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)
5961 ;; Assess location:
5962 (bullet-pos allout-recent-prefix-beginning)
5963 (after-bullet-pos (point))
5964 (was-encrypted
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))
5970 (backward-char 1)
5971 (allout-hidden-p)))
5972 (subtree-beg (1+ (point)))
5973 (subtree-end (allout-end-of-subtree))
5974 (subject-text (buffer-substring-no-properties subtree-beg
5975 subtree-end))
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"))
5984 nil))
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
5991 ;; them.
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
5998 ;; local variable.
5999 (if (and (not (equal buffer-file-coding-system
6000 was-coding-system))
6001 (yes-or-no-p
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)))
6009 (setq result-text
6010 (allout-encrypt-string subject-text was-encrypted
6011 (current-buffer) keymode-cue))
6013 ;; Replace the subtree with the processed product.
6014 (allout-unprotected
6015 (progn
6016 (set-buffer allout-buffer)
6017 (delete-region subtree-beg subtree-end)
6018 (insert result-text)
6019 (if was-collapsed
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))
6031 (delete-char 1)
6032 (insert allout-topic-encryption-bullet)))
6033 (if was-encrypted
6034 ;; Remove the is-encrypted bullet qualifier:
6035 (progn (goto-char after-bullet-pos)
6036 (delete-char 1))
6037 ;; Add the is-encrypted bullet qualifier:
6038 (goto-char after-bullet-pos)
6039 (insert "*"))))
6041 ;; adjust buffer's auto-save eligibility:
6042 (if was-encrypted
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
6061 &optional rejected)
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
6078 encryption.
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
6085 dialog.
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'
6098 signal."
6100 (require 'epg)
6101 (require 'epa)
6103 (let* ((epg-context (let* ((context (epg-make-context nil t)))
6104 (epg-context-set-passphrase-callback
6105 context #'epa-passphrase-callback-function)
6106 context))
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
6116 sani-regexps)))
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
6123 rejected))
6124 (keypair-mode (cond (decrypt 'decrypting)
6125 ((<= (prefix-numeric-value keymode-cue) 1)
6126 'default)
6127 ((<= (prefix-numeric-value keymode-cue) 4)
6128 'prompt)
6129 ((> (prefix-numeric-value keymode-cue) 4)
6130 'prompt-save)))
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))
6135 recipients
6136 massaged-text
6137 result-text
6140 ;; Massage the subject text for encoding and filtering.
6141 (with-temp-buffer
6142 (insert text)
6143 ;; convey the text characteristics of the original buffer:
6144 (set-buffer-multibyte multibyte)
6145 (when encoding
6146 (set-buffer-file-coding-system encoding)
6147 (if (not decrypt)
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))
6156 (save-match-data
6157 (while (re-search-forward re nil t)
6158 (replace-match replacement nil nil))))))
6159 (setq massaged-text (buffer-substring-no-properties (point-min)
6160 (point-max))))
6161 ;; determine key mode and, if keypair, recipients:
6162 (setq recipients
6163 (case keypair-mode
6165 (decrypting nil)
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)))))
6173 (setq result-text
6174 (if decrypt
6175 (condition-case err
6176 (epg-decrypt-string epg-context
6177 (encode-coding-string massaged-text
6178 (or encoding 'utf-8)))
6179 (epg-error
6180 (signal 'egp-error
6181 (cons (concat (cadr err) " - gpg version problem?")
6182 (cddr err)))))
6183 (replace-regexp-in-string "\n$" ""
6184 (epg-encrypt-string epg-context
6185 (encode-coding-string massaged-text
6186 (or encoding 'utf-8))
6187 recipients))))
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)
6197 (epg-user-id-string
6198 (car (epg-key-user-id-list key))))
6199 recipients))
6200 ;; change the file variable:
6201 (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to))
6203 (cond
6204 ;; Retry (within limit) if ciphertext contains rejections:
6205 ((and (not decrypt)
6206 ;; Check for disqualification of this ciphertext:
6207 (let ((regexps reject-ciphertext-regexps)
6208 reject-it)
6209 (while (and regexps (not reject-it))
6210 (setq reject-it (string-match (car regexps) result-text))
6211 (pop regexps))
6212 reject-it))
6213 (setq rejections-left (1- rejections-left))
6214 (if (<= rejections-left 0)
6215 (error (concat "Ciphertext rejected too many times"
6216 " (%s), per `%s'")
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
6221 (1+ rejected))))
6223 ;; Barf if encryption yields extraordinary control chars:
6224 ((and (not decrypt)
6225 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6226 result-text))
6227 (error (concat "Encryption produced non-armored text, which"
6228 "conflicts with allout mode -- reconfigure!")))
6229 (t result-text))))
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*
6235 the decryption."
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)
6244 (save-excursion
6245 (save-restriction
6246 (widen)
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."
6255 (save-excursion
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)
6270 (save-match-data
6271 (while (not done)
6273 (if (not (re-search-forward
6274 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6275 (regexp-quote allout-header-prefix)
6276 (regexp-quote allout-topic-encryption-bullet))
6277 nil t))
6278 (setq got nil
6279 done t)
6280 (goto-char (setq got (match-beginning 0)))
6281 (when (= (following-char) ?\n) (forward-char 1))
6282 (setq got (point)))
6284 (cond ((not got)
6285 (setq done t))
6287 ((not (search-forward "\n"))
6288 (setq got nil
6289 done t))
6291 ((eobp)
6292 (setq got nil
6293 done t))
6296 (setq content-beg (point))
6297 (backward-char 1)
6298 (allout-end-of-subtree)
6299 (if (<= (point) content-beg)
6300 ;; Continue looking
6301 (setq got nil)
6302 ;; Got it!
6303 (setq done t)))
6306 (if got
6307 (goto-char got))
6311 ;;;_ > allout-encrypt-decrypted ()
6312 (defun allout-encrypt-decrypted ()
6313 "Encrypt topics pending encryption except those containing exemption point.
6315 If a topic that is currently being edited was encrypted, we return a list
6316 containing the location of the topic and the location of the cursor just
6317 before the topic was encrypted. This can be used, eg, to decrypt the topic
6318 and exactly resituate the cursor if this is being done as part of a file
6319 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6321 (interactive "p")
6322 (save-match-data
6323 (save-excursion
6324 (let* ((current-mark (point-marker))
6325 (current-mark-position (marker-position current-mark))
6326 was-modified
6327 bo-subtree
6328 editing-topic editing-point)
6329 (goto-char (point-min))
6330 (while (allout-next-topic-pending-encryption)
6331 (setq was-modified (buffer-modified-p))
6332 (when (save-excursion
6333 (and (boundp 'allout-encrypt-unencrypted-on-saves)
6334 allout-encrypt-unencrypted-on-saves
6335 (setq bo-subtree (re-search-forward "$"))
6336 (not (allout-hidden-p))
6337 (>= current-mark (point))
6338 (allout-end-of-current-subtree)
6339 (<= current-mark (point))))
6340 (setq editing-topic (point)
6341 ;; we had to wait for this 'til now so prior topics are
6342 ;; encrypted, any relevant text shifts are in place:
6343 editing-point (- current-mark-position
6344 (allout-count-trailing-whitespace-region
6345 bo-subtree current-mark-position))))
6346 (allout-toggle-subtree-encryption)
6347 (if (not was-modified)
6348 (set-buffer-modified-p nil))
6350 (if (not was-modified)
6351 (set-buffer-modified-p nil))
6352 (if editing-topic (list editing-topic editing-point))
6358 ;;;_ #9 miscellaneous
6359 ;;;_ : Mode:
6360 ;;;_ > outlineify-sticky ()
6361 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6362 ;;;###autoload
6363 (defalias 'outlinify-sticky 'outlineify-sticky)
6364 ;;;###autoload
6365 (defun outlineify-sticky (&optional _arg)
6366 "Activate outline mode and establish file var so it is started subsequently.
6368 See `allout-layout' and customization of `allout-auto-activation'
6369 for details on preparing Emacs for automatic allout activation."
6371 (interactive "P")
6373 (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
6374 (allout-mode)
6376 (save-excursion
6377 (goto-char (point-min))
6378 (if (allout-goto-prefix)
6380 (allout-open-topic 2)
6381 (insert (substitute-command-keys
6382 (concat "Dummy outline topic header -- see"
6383 " `allout-mode' docstring: `\\[describe-mode]'.")))
6384 (allout-adjust-file-variable
6385 "allout-layout" (or allout-layout '(-1 : 0))))))
6386 ;;;_ > allout-file-vars-section-data ()
6387 (defun allout-file-vars-section-data ()
6388 "Return data identifying the file-vars section, or nil if none.
6390 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6391 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6392 (let (beg prefix suffix)
6393 (save-excursion
6394 (goto-char (point-max))
6395 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
6396 (if (let ((case-fold-search t))
6397 (not (search-forward "Local Variables:" nil t)))
6399 (setq beg (- (point) 16))
6400 (setq suffix (buffer-substring-no-properties
6401 (point)
6402 (progn (if (search-forward "\n" nil t)
6403 (forward-char -1))
6404 (point))))
6405 (setq prefix (buffer-substring-no-properties
6406 (progn (if (search-backward "\n" nil t)
6407 (forward-char 1))
6408 (point))
6409 beg))
6410 (list beg prefix suffix))
6414 ;;;_ > allout-adjust-file-variable (varname value)
6415 (defun allout-adjust-file-variable (varname value)
6416 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6418 This activity is inhibited if either `enable-local-variables' or
6419 `allout-enable-file-variable-adjustment' are nil.
6421 When enabled, an entry for the variable is created if not already present,
6422 or changed if established with a different value. The section for the file
6423 variables, itself, is created if not already present. When created, the
6424 section lines (including the section line) exist as second-level topics in
6425 a top-level topic at the end of the file.
6427 `enable-local-variables' must be true for any of this to happen."
6428 (if (not (and enable-local-variables
6429 allout-enable-file-variable-adjustment))
6431 (save-excursion
6432 (let ((inhibit-field-text-motion t)
6433 (section-data (allout-file-vars-section-data))
6434 beg prefix suffix)
6435 (if section-data
6436 (setq beg (car section-data)
6437 prefix (cadr section-data)
6438 suffix (car (cddr section-data)))
6439 ;; create the section
6440 (goto-char (point-max))
6441 (open-line 1)
6442 (allout-open-topic 0)
6443 (end-of-line)
6444 (insert "Local emacs vars.\n")
6445 (allout-open-topic 1)
6446 (setq beg (point)
6447 suffix ""
6448 prefix (buffer-substring-no-properties (progn
6449 (beginning-of-line)
6450 (point))
6451 beg))
6452 (goto-char beg)
6453 (insert "Local variables:\n")
6454 (allout-open-topic 0)
6455 (insert "End:\n")
6457 ;; look for existing entry or create one, leaving point for insertion
6458 ;; of new value:
6459 (goto-char beg)
6460 (allout-show-to-offshoot)
6461 (if (search-forward (concat "\n" prefix varname ":") nil t)
6462 (let* ((value-beg (point))
6463 (line-end (progn (if (search-forward "\n" nil t)
6464 (forward-char -1))
6465 (point)))
6466 (value-end (- line-end (length suffix))))
6467 (if (> value-end value-beg)
6468 (delete-region value-beg value-end)))
6469 (end-of-line)
6470 (open-line 1)
6471 (forward-line 1)
6472 (insert (concat prefix varname ":")))
6473 (insert (format " %S%s" value suffix))
6478 ;;;_ > allout-get-configvar-values (varname)
6479 (defun allout-get-configvar-values (configvar-name)
6480 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6482 The user is prompted for removal of symbols that are unbound, and they
6483 otherwise are ignored.
6485 CONFIGVAR-NAME should be the name of the configuration variable,
6486 not its value."
6488 (let ((configvar-value (symbol-value configvar-name))
6489 got)
6490 (dolist (sym configvar-value)
6491 (if (not (boundp sym))
6492 (if (yes-or-no-p (format-message
6493 "%s entry `%s' is unbound -- remove it? "
6494 configvar-name sym))
6495 (delq sym (symbol-value configvar-name)))
6496 (push (symbol-value sym) got)))
6497 (reverse got)))
6498 ;;;_ : Topics:
6499 ;;;_ > allout-mark-topic ()
6500 (defun allout-mark-topic ()
6501 "Put the region around topic currently containing point."
6502 (interactive)
6503 (let ((inhibit-field-text-motion t))
6504 (beginning-of-line))
6505 (allout-goto-prefix-doublechecked)
6506 (push-mark)
6507 (allout-end-of-current-subtree)
6508 (exchange-point-and-mark))
6509 ;;;_ : UI:
6510 ;;;_ > allout-solicit-char-in-string (prompt string &optional do-defaulting)
6511 (defun allout-solicit-char-in-string (prompt string &optional do-defaulting)
6512 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6514 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6516 (let ((new-prompt prompt)
6517 got)
6519 (while (not got)
6520 (message "%s" new-prompt)
6522 ;; We do our own reading here, so we can circumvent, eg, special
6523 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6524 (setq got
6525 (char-to-string (let ((cursor-in-echo-area nil)) (read-char))))
6527 (setq got
6528 (cond ((string-match (regexp-quote got) string) got)
6529 ((and do-defaulting (string= got "\r"))
6530 ;; Return empty string to default:
6532 ((string= got "\C-g") (signal 'quit nil))
6534 (setq new-prompt (concat prompt
6536 " ...pick from: "
6537 string
6538 ""))
6539 nil))))
6540 ;; got something out of loop -- return it:
6541 got)
6543 ;;;_ : Strings:
6544 ;;;_ > allout-regexp-sans-escapes (string)
6545 (defun allout-regexp-sans-escapes (regexp &optional successive-backslashes)
6546 "Return a copy of REGEXP with all character escapes stripped out.
6548 Representations of actual backslashes -- `\\\\\\\\' -- are left as a
6549 single backslash.
6551 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6553 (if (string= regexp "")
6555 ;; Set successive-backslashes to number if current char is
6556 ;; backslash, or else to nil:
6557 (setq successive-backslashes
6558 (if (= (aref regexp 0) ?\\)
6559 (if successive-backslashes (1+ successive-backslashes) 1)
6560 nil))
6561 (if (or (not successive-backslashes) (= 2 successive-backslashes))
6562 ;; Include first char:
6563 (concat (substring regexp 0 1)
6564 (allout-regexp-sans-escapes (substring regexp 1)))
6565 ;; Exclude first char, but maintain count:
6566 (allout-regexp-sans-escapes (substring regexp 1) successive-backslashes))))
6567 ;;;_ > allout-count-trailing-whitespace-region (beg end)
6568 (defun allout-count-trailing-whitespace-region (beg end)
6569 "Return number of trailing whitespace chars between BEG and END.
6571 If BEG is bigger than END we return 0."
6572 (if (> beg end)
6574 (save-match-data
6575 (save-excursion
6576 (goto-char beg)
6577 (let ((count 0))
6578 (while (re-search-forward "[ ][ ]*$" end t)
6579 (goto-char (1+ (match-beginning 2)))
6580 (setq count (1+ count)))
6581 count)))))
6582 ;;;_ > allout-format-quote (string)
6583 (defun allout-format-quote (string)
6584 "Return a copy of string with all \"%\" characters doubled."
6585 (apply 'concat
6586 (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char)))
6587 string)))
6588 ;;;_ : lists
6589 ;;;_ > allout-flatten (list)
6590 (defun allout-flatten (list)
6591 "Return a list of all atoms in list."
6592 ;; classic.
6593 (cond ((null list) nil)
6594 ((atom (car list)) (cons (car list) (allout-flatten (cdr list))))
6595 (t (append (allout-flatten (car list)) (allout-flatten (cdr list))))))
6596 ;;;_ : Compatibility:
6597 ;;;_ : xemacs undo-in-progress provision:
6598 (unless (boundp 'undo-in-progress)
6599 (defvar undo-in-progress nil
6600 "Placeholder defvar for XEmacs compatibility from allout.el.")
6601 (defadvice undo-more (around allout activate)
6602 ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
6603 (let ((undo-in-progress t)) ad-do-it)))
6605 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6606 (defun allout-mark-marker (&optional force buffer)
6607 "Accommodate the different signature for `mark-marker' across Emacsen.
6609 XEmacs takes two optional args, while Emacs does not,
6610 so pass them along when appropriate."
6611 (if (featurep 'xemacs)
6612 (apply 'mark-marker force buffer)
6613 (mark-marker)))
6614 ;;;_ > subst-char-in-string if necessary
6615 (if (not (fboundp 'subst-char-in-string))
6616 (defun subst-char-in-string (fromchar tochar string &optional inplace)
6617 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6618 Unless optional argument INPLACE is non-nil, return a new string."
6619 (let ((i (length string))
6620 (newstr (if inplace string (copy-sequence string))))
6621 (while (> i 0)
6622 (setq i (1- i))
6623 (if (eq (aref newstr i) fromchar)
6624 (aset newstr i tochar)))
6625 newstr)))
6626 ;;;_ > wholenump if necessary
6627 (if (not (fboundp 'wholenump))
6628 (defalias 'wholenump 'natnump))
6629 ;;;_ > remove-overlays if necessary
6630 (if (not (fboundp 'remove-overlays))
6631 (defun remove-overlays (&optional beg end name val)
6632 "Clear BEG and END of overlays whose property NAME has value VAL.
6633 Overlays might be moved and/or split.
6634 BEG and END default respectively to the beginning and end of buffer."
6635 (unless beg (setq beg (point-min)))
6636 (unless end (setq end (point-max)))
6637 (if (< end beg)
6638 (setq beg (prog1 end (setq end beg))))
6639 (save-excursion
6640 (dolist (o (overlays-in beg end))
6641 (when (eq (overlay-get o name) val)
6642 ;; Either push this overlay outside beg...end
6643 ;; or split it to exclude beg...end
6644 ;; or delete it entirely (if it is contained in beg...end).
6645 (if (< (overlay-start o) beg)
6646 (if (> (overlay-end o) end)
6647 (progn
6648 (move-overlay (copy-overlay o)
6649 (overlay-start o) beg)
6650 (move-overlay o end (overlay-end o)))
6651 (move-overlay o (overlay-start o) beg))
6652 (if (> (overlay-end o) end)
6653 (move-overlay o end (overlay-end o))
6654 (delete-overlay o)))))))
6656 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6657 (if (not (fboundp 'copy-overlay))
6658 (defun copy-overlay (o)
6659 "Return a copy of overlay O."
6660 (let ((o1 (make-overlay (overlay-start o) (overlay-end o)
6661 ;; FIXME: there's no easy way to find the
6662 ;; insertion-type of the two markers.
6663 (overlay-buffer o)))
6664 (props (overlay-properties o)))
6665 (while props
6666 (overlay-put o1 (pop props) (pop props)))
6667 o1)))
6668 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6669 (if (not (fboundp 'add-to-invisibility-spec))
6670 (defun add-to-invisibility-spec (element)
6671 "Add ELEMENT to `buffer-invisibility-spec'.
6672 See documentation for `buffer-invisibility-spec' for the kind of elements
6673 that can be added."
6674 (if (eq buffer-invisibility-spec t)
6675 (setq buffer-invisibility-spec (list t)))
6676 (setq buffer-invisibility-spec
6677 (cons element buffer-invisibility-spec))))
6678 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6679 (if (not (fboundp 'remove-from-invisibility-spec))
6680 (defun remove-from-invisibility-spec (element)
6681 "Remove ELEMENT from `buffer-invisibility-spec'."
6682 (if (consp buffer-invisibility-spec)
6683 (setq buffer-invisibility-spec (delete element
6684 buffer-invisibility-spec)))))
6685 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6686 (if (not (fboundp 'move-beginning-of-line))
6687 (defun move-beginning-of-line (arg)
6688 "Move point to beginning of current line as displayed.
6689 \(This disregards invisible newlines such as those
6690 which are part of the text that an image rests on.)
6692 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6693 If point reaches the beginning or end of buffer, it stops there.
6694 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6695 (interactive "p")
6696 (or arg (setq arg 1))
6697 (if (/= arg 1)
6698 (condition-case nil (line-move (1- arg)) (error nil)))
6700 ;; Move to beginning-of-line, ignoring fields and invisible text.
6701 (skip-chars-backward "^\n")
6702 (while (and (not (bobp))
6703 (let ((prop
6704 (get-char-property (1- (point)) 'invisible)))
6705 (if (eq buffer-invisibility-spec t)
6706 prop
6707 (or (memq prop buffer-invisibility-spec)
6708 (assq prop buffer-invisibility-spec)))))
6709 (goto-char (if (featurep 'xemacs)
6710 (previous-property-change (point))
6711 (previous-char-property-change (point))))
6712 (skip-chars-backward "^\n"))
6713 (vertical-motion 0))
6715 ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
6716 (if (not (fboundp 'move-end-of-line))
6717 (defun move-end-of-line (arg)
6718 "Move point to end of current line as displayed.
6719 \(This disregards invisible newlines such as those
6720 which are part of the text that an image rests on.)
6722 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6723 If point reaches the beginning or end of buffer, it stops there.
6724 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6725 (interactive "p")
6726 (or arg (setq arg 1))
6727 (let (done)
6728 (while (not done)
6729 (let ((newpos
6730 (save-excursion
6731 (let ((goal-column 0))
6732 (and (condition-case nil
6733 (or (line-move arg) t)
6734 (error nil))
6735 (not (bobp))
6736 (progn
6737 (while
6738 (and
6739 (not (bobp))
6740 (let ((prop
6741 (get-char-property (1- (point))
6742 'invisible)))
6743 (if (eq buffer-invisibility-spec t)
6744 prop
6745 (or (memq prop
6746 buffer-invisibility-spec)
6747 (assq prop
6748 buffer-invisibility-spec)))))
6749 (goto-char
6750 (previous-char-property-change (point))))
6751 (backward-char 1)))
6752 (point)))))
6753 (goto-char newpos)
6754 (if (and (> (point) newpos)
6755 (eq (preceding-char) ?\n))
6756 (backward-char 1)
6757 (if (and (> (point) newpos) (not (eobp))
6758 (not (eq (following-char) ?\n)))
6759 ;; If we skipped something intangible
6760 ;; and now we're not really at eol,
6761 ;; keep going.
6762 (setq arg 1)
6763 (setq done t)))))))
6765 ;;;_ > allout-next-single-char-property-change -- alias unless lacking
6766 (defalias 'allout-next-single-char-property-change
6767 (if (fboundp 'next-single-char-property-change)
6768 'next-single-char-property-change
6769 'next-single-property-change)
6770 ;; No docstring because xemacs defalias doesn't support it.
6772 ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
6773 (defalias 'allout-previous-single-char-property-change
6774 (if (fboundp 'previous-single-char-property-change)
6775 'previous-single-char-property-change
6776 'previous-single-property-change)
6777 ;; No docstring because xemacs defalias doesn't support it.
6779 ;;;_ > allout-select-safe-coding-system
6780 (defalias 'allout-select-safe-coding-system
6781 (if (fboundp 'select-safe-coding-system)
6782 'select-safe-coding-system
6783 'detect-coding-region)
6785 ;;;_ > allout-substring-no-properties
6786 ;; define as alias first, so byte compiler is happy.
6787 (defalias 'allout-substring-no-properties 'substring-no-properties)
6788 ;; then supplant with definition if underlying alias absent.
6789 (if (not (fboundp 'substring-no-properties))
6790 (defun allout-substring-no-properties (string &optional start end)
6791 (substring string (or start 0) end))
6794 ;;;_ #10 Unfinished
6795 ;;;_ > allout-bullet-isearch (&optional bullet)
6796 (defun allout-bullet-isearch (&optional bullet)
6797 "Isearch (regexp) for topic with bullet BULLET."
6798 (interactive)
6799 (if (not bullet)
6800 (setq bullet (allout-solicit-char-in-string
6801 "ISearch for topic with bullet: "
6802 (allout-regexp-sans-escapes allout-bullets-string))))
6804 (let ((isearch-regexp t)
6805 (isearch-string (concat "^"
6806 allout-header-prefix
6807 "[ \t]*"
6808 bullet)))
6809 (isearch-repeat 'forward)
6810 (isearch-mode t)))
6812 ;;;_ #11 Unit tests -- this should be last item before "Provide"
6813 ;;;_ > allout-run-unit-tests ()
6814 (defun allout-run-unit-tests ()
6815 "Run the various allout unit tests."
6816 (message "Running allout tests...")
6817 (allout-test-resumptions)
6818 (message "Running allout tests... Done.")
6819 (sit-for .5))
6820 ;;;_ : test resumptions:
6821 ;;;_ > allout-tests-obliterate-variable (name)
6822 (defun allout-tests-obliterate-variable (name)
6823 "Completely unbind variable with NAME."
6824 (if (local-variable-p name (current-buffer)) (kill-local-variable name))
6825 (while (boundp name) (makunbound name)))
6826 ;;;_ > allout-test-resumptions ()
6827 (defvar allout-tests-globally-unbound nil
6828 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6829 (defvar allout-tests-globally-true nil
6830 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6831 (defvar allout-tests-locally-true nil
6832 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6833 (defun allout-test-resumptions ()
6834 "Exercise allout resumptions."
6835 ;; for each resumption case, we also test that the right local/global
6836 ;; scopes are affected during resumption effects:
6838 ;; ensure that previously unbound variables return to the unbound state.
6839 (with-temp-buffer
6840 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6841 (allout-add-resumptions '(allout-tests-globally-unbound t))
6842 (assert (not (default-boundp 'allout-tests-globally-unbound)))
6843 (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6844 (assert (boundp 'allout-tests-globally-unbound))
6845 (assert (equal allout-tests-globally-unbound t))
6846 (allout-do-resumptions)
6847 (assert (not (local-variable-p 'allout-tests-globally-unbound
6848 (current-buffer))))
6849 (assert (not (boundp 'allout-tests-globally-unbound))))
6851 ;; ensure that variable with prior global value is resumed
6852 (with-temp-buffer
6853 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6854 (setq allout-tests-globally-true t)
6855 (allout-add-resumptions '(allout-tests-globally-true nil))
6856 (assert (equal (default-value 'allout-tests-globally-true) t))
6857 (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6858 (assert (equal allout-tests-globally-true nil))
6859 (allout-do-resumptions)
6860 (assert (not (local-variable-p 'allout-tests-globally-true
6861 (current-buffer))))
6862 (assert (boundp 'allout-tests-globally-true))
6863 (assert (equal allout-tests-globally-true t)))
6865 ;; ensure that prior local value is resumed
6866 (with-temp-buffer
6867 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6868 (set (make-local-variable 'allout-tests-locally-true) t)
6869 (assert (not (default-boundp 'allout-tests-locally-true))
6870 nil (concat "Test setup mistake -- variable supposed to"
6871 " not have global binding, but it does."))
6872 (assert (local-variable-p 'allout-tests-locally-true (current-buffer))
6873 nil (concat "Test setup mistake -- variable supposed to have"
6874 " local binding, but it lacks one."))
6875 (allout-add-resumptions '(allout-tests-locally-true nil))
6876 (assert (not (default-boundp 'allout-tests-locally-true)))
6877 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6878 (assert (equal allout-tests-locally-true nil))
6879 (allout-do-resumptions)
6880 (assert (boundp 'allout-tests-locally-true))
6881 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6882 (assert (equal allout-tests-locally-true t))
6883 (assert (not (default-boundp 'allout-tests-locally-true))))
6885 ;; ensure that last of multiple resumptions holds, for various scopes.
6886 (with-temp-buffer
6887 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6888 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6889 (setq allout-tests-globally-true t)
6890 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6891 (set (make-local-variable 'allout-tests-locally-true) t)
6892 (allout-add-resumptions '(allout-tests-globally-unbound t)
6893 '(allout-tests-globally-true nil)
6894 '(allout-tests-locally-true nil))
6895 (allout-add-resumptions '(allout-tests-globally-unbound 2)
6896 '(allout-tests-globally-true 3)
6897 '(allout-tests-locally-true 4))
6898 ;; reestablish many of the basic conditions are maintained after re-add:
6899 (assert (not (default-boundp 'allout-tests-globally-unbound)))
6900 (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6901 (assert (equal allout-tests-globally-unbound 2))
6902 (assert (default-boundp 'allout-tests-globally-true))
6903 (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6904 (assert (equal allout-tests-globally-true 3))
6905 (assert (not (default-boundp 'allout-tests-locally-true)))
6906 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6907 (assert (equal allout-tests-locally-true 4))
6908 (allout-do-resumptions)
6909 (assert (not (local-variable-p 'allout-tests-globally-unbound
6910 (current-buffer))))
6911 (assert (not (boundp 'allout-tests-globally-unbound)))
6912 (assert (not (local-variable-p 'allout-tests-globally-true
6913 (current-buffer))))
6914 (assert (boundp 'allout-tests-globally-true))
6915 (assert (equal allout-tests-globally-true t))
6916 (assert (boundp 'allout-tests-locally-true))
6917 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6918 (assert (equal allout-tests-locally-true t))
6919 (assert (not (default-boundp 'allout-tests-locally-true))))
6921 ;; ensure that deliberately unbinding registered variables doesn't foul things
6922 (with-temp-buffer
6923 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6924 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6925 (setq allout-tests-globally-true t)
6926 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6927 (set (make-local-variable 'allout-tests-locally-true) t)
6928 (allout-add-resumptions '(allout-tests-globally-unbound t)
6929 '(allout-tests-globally-true nil)
6930 '(allout-tests-locally-true nil))
6931 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6932 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6933 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6934 (allout-do-resumptions))
6936 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
6937 (when allout-run-unit-tests-on-load
6938 (allout-run-unit-tests))
6940 ;;;_ #12 Provide
6941 (provide 'allout)
6943 ;;;_* Local emacs vars.
6944 ;; The following `allout-layout' local variable setting:
6945 ;; - closes all topics from the first topic to just before the third-to-last,
6946 ;; - shows the children of the third to last (config vars)
6947 ;; - and the second to last (code section),
6948 ;; - and closes the last topic (this local-variables section).
6949 ;;Local variables:
6950 ;;allout-layout: (0 : -1 -1 0)
6951 ;;End:
6953 ;;; allout.el ends here