add-log font-lock fix for mutilple authors (bug#8644)
[emacs.git] / lisp / allout.el
blob16a816549d24865b6157a517781befd4350d1073
1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992-1994, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com>
6 ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com>
7 ;; Created: Dec 1991 -- first release to usenet
8 ;; Version: 2.3
9 ;; Keywords: outlines, wp, languages, PGP, GnuPG
10 ;; Website: http://myriadicity.net/Sundry/EmacsAllout
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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 ;;;_* Dependency loads
78 (require 'overlay)
79 (eval-when-compile
80 ;; Most of the requires here are for stuff covered by autoloads, which
81 ;; byte-compiling doesn't trigger.
82 (require 'epg)
83 (require 'epa)
84 (require 'overlay)
85 ;; `cl' is required for `assert'. `assert' is not covered by a standard
86 ;; autoload, but it is a macro, so that eval-when-compile is sufficient
87 ;; to byte-compile it in, or to do the require when the buffer evalled.
88 (require 'cl)
91 ;;;_* USER CUSTOMIZATION VARIABLES:
93 ;;;_ > defgroup allout, allout-keybindings
94 (defgroup allout nil
95 "Extensive outline minor-mode, for use stand-alone and with other modes.
97 See Allout Auto Activation for automatic activation."
98 :prefix "allout-"
99 :group 'outlines)
100 (defgroup allout-keybindings nil
101 "Allout outline mode keyboard bindings configuration."
102 :group 'allout)
104 ;;;_ + Layout, Mode, and Topic Header Configuration
106 (defvar allout-command-prefix) ; defined below
108 ;;;_ > allout-keybindings incidentals:
109 ;;;_ : internal key binding stuff - in this section for load-order.
110 ;;;_ = allout-mode-map
111 (defvar allout-mode-map 'allout-mode-map
112 "Keybindings place-holder for (allout) outline minor mode.
114 Do NOT set the value of this variable. Instead, customize
115 `allout-command-prefix', `allout-prefixed-keybindings', and
116 `allout-unprefixed-keybindings'.")
117 ;;;_ = allout-mode-map-value
118 (defvar allout-mode-map-value nil
119 "Keymap for allout outline minor mode.
121 Do NOT set the value of this variable. Instead, customize
122 `allout-command-prefix', `allout-prefixed-keybindings', and
123 `allout-unprefixed-keybindings'.")
124 ;;;_ = make allout-mode-map-value an alias for allout-mode-map:
125 ;; this needs to be revised when the value is changed, sigh.
126 (defalias 'allout-mode-map allout-mode-map-value)
127 ;;;_ > allout-compose-and-institute-keymap (&optional varname value)
128 (defun allout-compose-and-institute-keymap (&optional varname value)
129 "Create the allout keymap according to the keybinding specs, and set it.
131 Useful standalone or to effect customizations of the
132 respective allout-mode keybinding variables, `allout-command-prefix',
133 `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'"
134 ;; Set the customization variable, if any:
135 (when varname
136 (set-default varname value))
137 (let ((map (make-sparse-keymap)))
138 (when (boundp 'allout-prefixed-keybindings)
139 ;; tolerate first definitions of the variables:
140 (dolist (entry allout-prefixed-keybindings)
141 (define-key map
142 ;; XXX vector vs non-vector key descriptions?
143 (vconcat allout-command-prefix
144 (car (read-from-string (car entry))))
145 (cadr entry))))
146 (when (boundp 'allout-unprefixed-keybindings)
147 (dolist (entry allout-unprefixed-keybindings)
148 (define-key map (car (read-from-string (car entry))) (cadr entry))))
149 (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line
150 map global-map)
151 (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line
152 map global-map)
153 (substitute-key-definition 'end-of-line 'allout-end-of-line
154 map global-map)
155 (substitute-key-definition 'move-end-of-line 'allout-end-of-line
156 map global-map)
157 (allout-institute-keymap map)))
158 ;;;_ > allout-institute-keymap (map)
159 (defun allout-institute-keymap (map)
160 "Associate allout-mode bindings with allout as a minor mode."
161 ;; Architecture:
162 ;; allout-mode-map var is a keymap by virtue of being a defalias for
163 ;; allout-mode-map-value, which has the actual keymap value.
164 ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be
165 ;; used in minor-mode-map-alist to indirect to the actual
166 ;; allout-mode-map-var value, which can be adjusted and reassigned.
168 ;; allout-mode-map-value for keymap reference in various places:
169 (setq allout-mode-map-value map)
170 ;; the function value keymap of allout-mode-map is used in
171 ;; minor-mode-map-alist - update it:
172 (fset allout-mode-map allout-mode-map-value))
173 ;;;_ * intialize the mode map:
174 ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
175 ;; been invoked:
176 (allout-compose-and-institute-keymap)
177 ;;;_ = allout-command-prefix
178 (defcustom allout-command-prefix "\C-c "
179 "Key sequence to be used as prefix for outline mode command key bindings.
181 Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're
182 willing to let allout use a bunch of \C-c keybindings."
183 :type 'string
184 :group 'allout-keybindings
185 :set 'allout-compose-and-institute-keymap)
186 ;;;_ = allout-keybindings-binding
187 (define-widget 'allout-keybindings-binding 'lazy
188 "Structure of allout keybindings customization items."
189 :type '(repeat
190 (list (string :tag "Key" :value "[(meta control shift ?f)]")
191 (function :tag "Function name"
192 :value allout-forward-current-level))))
193 ;;;_ = allout-prefixed-keybindings
194 (defcustom allout-prefixed-keybindings
195 '(("[(control ?n)]" allout-next-visible-heading)
196 ("[(control ?p)]" allout-previous-visible-heading)
197 ("[(control ?u)]" allout-up-current-level)
198 ("[(control ?f)]" allout-forward-current-level)
199 ("[(control ?b)]" allout-backward-current-level)
200 ("[(control ?a)]" allout-beginning-of-current-entry)
201 ("[(control ?e)]" allout-end-of-entry)
202 ("[(control ?i)]" allout-show-children)
203 ("[(control ?s)]" allout-show-current-subtree)
204 ("[(control ?t)]" allout-toggle-current-subtree-exposure)
205 ;; Let user customize if they want to preempt describe-prefix-bindings ^h use.
206 ;; ("[(control ?h)]" allout-hide-current-subtree)
207 ("[?h]" allout-hide-current-subtree)
208 ("[(control ?o)]" allout-show-current-entry)
209 ("[?!]" allout-show-all)
210 ("[?x]" allout-toggle-current-subtree-encryption)
211 ("[? ]" allout-open-sibtopic)
212 ("[?.]" allout-open-subtopic)
213 ("[?,]" allout-open-supertopic)
214 ("[?']" allout-shift-in)
215 ("[?>]" allout-shift-in)
216 ("[?<]" allout-shift-out)
217 ("[(control ?m)]" allout-rebullet-topic)
218 ("[?*]" allout-rebullet-current-heading)
219 ("[?#]" allout-number-siblings)
220 ("[(control ?k)]" allout-kill-topic)
221 ("[(meta ?k)]" allout-copy-topic-as-kill)
222 ("[?@]" allout-resolve-xref)
223 ("[?=?c]" allout-copy-exposed-to-buffer)
224 ("[?=?i]" allout-indented-exposed-to-buffer)
225 ("[?=?t]" allout-latexify-exposed)
226 ("[?=?p]" allout-flatten-exposed-to-buffer)
228 "Allout-mode key bindings that are prefixed with `allout-command-prefix'.
230 See `allout-unprefixed-keybindings' for the list of keybindings
231 that are not prefixed.
233 Use vector format for the keys:
234 - put literal keys after a '?' question mark, eg: '?a', '?.'
235 - enclose control, shift, or meta-modified keys as sequences within
236 parentheses, with the literal key, as above, preceded by the name(s)
237 of the modifiers, eg: [(control ?a)]
238 See the existing keys for examples.
240 Functions can be bound to multiple keys, but binding keys to
241 multiple functions will not work - the last binding for a key
242 prevails."
243 :type 'allout-keybindings-binding
244 :group 'allout-keybindings
245 :set 'allout-compose-and-institute-keymap
247 ;;;_ = allout-unprefixed-keybindings
248 (defcustom allout-unprefixed-keybindings
249 '(("[(control ?k)]" allout-kill-line)
250 ("[(meta ?k)]" allout-copy-line-as-kill)
251 ("[(control ?y)]" allout-yank)
252 ("[(meta ?y)]" allout-yank-pop)
254 "Allout-mode functions bound to keys without any added prefix.
256 This is in contrast to the majority of allout-mode bindings on
257 `allout-prefixed-bindings', whose bindings are created with a
258 preceding command key.
260 Use vector format for the keys:
261 - put literal keys after a '?' question mark, eg: '?a', '?.'
262 - enclose control, shift, or meta-modified keys as sequences within
263 parentheses, with the literal key, as above, preceded by the name(s)
264 of the modifiers, eg: [(control ?a)]
265 See the existing keys for examples."
266 :type 'allout-keybindings-binding
267 :group 'allout-keybindings
268 :set 'allout-compose-and-institute-keymap
271 ;;;_ > allout-auto-activation-helper (var value)
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-use-hanging-indents
403 (defcustom allout-use-hanging-indents t
404 "If non-nil, topic body text auto-indent defaults to indent of the header.
405 Ie, it is indented to be just past the header prefix. This is
406 relevant mostly for use with `indented-text-mode', or other situations
407 where auto-fill occurs."
408 :type 'boolean
409 :group 'allout)
410 (make-variable-buffer-local 'allout-use-hanging-indents)
411 ;;;###autoload
412 (put 'allout-use-hanging-indents 'safe-local-variable
413 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
414 ;;;_ = allout-reindent-bodies
415 (defcustom allout-reindent-bodies (if allout-use-hanging-indents
416 'text)
417 "Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
419 When active, topic body lines that are indented even with or beyond
420 their topic header are reindented to correspond with depth shifts of
421 the header.
423 A value of t enables reindent in non-programming-code buffers, ie
424 those that do not have the variable `comment-start' set. A value of
425 `force' enables reindent whether or not `comment-start' is set."
426 :type '(choice (const nil) (const t) (const text) (const force))
427 :group 'allout)
429 (make-variable-buffer-local 'allout-reindent-bodies)
430 ;;;###autoload
431 (put 'allout-reindent-bodies 'safe-local-variable
432 '(lambda (x) (memq x '(nil t text force))))
434 ;;;_ = allout-show-bodies
435 (defcustom allout-show-bodies nil
436 "If non-nil, show entire body when exposing a topic, rather than
437 just the header."
438 :type 'boolean
439 :group 'allout)
440 (make-variable-buffer-local 'allout-show-bodies)
441 ;;;###autoload
442 (put 'allout-show-bodies 'safe-local-variable
443 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
445 ;;;_ = allout-beginning-of-line-cycles
446 (defcustom allout-beginning-of-line-cycles t
447 "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
449 Cycling only happens on when the command is repeated, not when it
450 follows a different command.
452 Smart-placement means that repeated calls to this function will
453 advance as follows:
455 - if the cursor is on a non-headline body line and not on the first column:
456 then it goes to the first column
457 - if the cursor is on the first column of a non-headline body line:
458 then it goes to the start of the headline within the item body
459 - if the cursor is on the headline and not the start of the headline:
460 then it goes to the start of the headline
461 - if the cursor is on the start of the headline:
462 then it goes to the bullet character (for hotspot navigation)
463 - if the cursor is on the bullet character:
464 then it goes to the first column of that line (the headline)
465 - if the cursor is on the first column of the headline:
466 then it goes to the start of the headline within the item body.
468 In this fashion, you can use the beginning-of-line command to do
469 its normal job and then, when repeated, advance through the
470 entry, cycling back to start.
472 If this configuration variable is nil, then the cursor is just
473 advanced to the beginning of the line and remains there on
474 repeated calls."
475 :type 'boolean :group 'allout)
476 ;;;_ = allout-end-of-line-cycles
477 (defcustom allout-end-of-line-cycles t
478 "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
480 Cycling only happens on when the command is repeated, not when it
481 follows a different command.
483 Smart placement means that repeated calls to this function will
484 advance as follows:
486 - if the cursor is not on the end-of-line,
487 then it goes to the end-of-line
488 - if the cursor is on the end-of-line but not the end-of-entry,
489 then it goes to the end-of-entry, exposing it if necessary
490 - if the cursor is on the end-of-entry,
491 then it goes to the end of the head line
493 In this fashion, you can use the end-of-line command to do its
494 normal job and then, when repeated, advance through the entry,
495 cycling back to start.
497 If this configuration variable is nil, then the cursor is just
498 advanced to the end of the line and remains there on repeated
499 calls."
500 :type 'boolean :group 'allout)
502 ;;;_ = allout-header-prefix
503 (defcustom allout-header-prefix "."
504 ;; this string is treated as literal match. it will be `regexp-quote'd, so
505 ;; one cannot use regular expressions to match varying header prefixes.
506 "Leading string which helps distinguish topic headers.
508 Outline topic header lines are identified by a leading topic
509 header prefix, which mostly have the value of this var at their front.
510 Level 1 topics are exceptions. They consist of only a single
511 character, which is typically set to the `allout-primary-bullet'."
512 :type 'string
513 :group 'allout)
514 (make-variable-buffer-local 'allout-header-prefix)
515 ;;;###autoload
516 (put 'allout-header-prefix 'safe-local-variable 'stringp)
517 ;;;_ = allout-primary-bullet
518 (defcustom allout-primary-bullet "*"
519 "Bullet used for top-level outline topics.
521 Outline topic header lines are identified by a leading topic header
522 prefix, which is concluded by bullets that includes the value of this
523 var and the respective allout-*-bullets-string vars.
525 The value of an asterisk (`*') provides for backwards compatibility
526 with the original Emacs outline mode. See `allout-plain-bullets-string'
527 and `allout-distinctive-bullets-string' for the range of available
528 bullets."
529 :type 'string
530 :group 'allout)
531 (make-variable-buffer-local 'allout-primary-bullet)
532 ;;;###autoload
533 (put 'allout-primary-bullet 'safe-local-variable 'stringp)
534 ;;;_ = allout-plain-bullets-string
535 (defcustom allout-plain-bullets-string ".,"
536 "The bullets normally used in outline topic prefixes.
538 See `allout-distinctive-bullets-string' for the other kind of
539 bullets.
541 DO NOT include the close-square-bracket, `]', as a bullet.
543 Outline mode has to be reactivated in order for changes to the value
544 of this var to take effect."
545 :type 'string
546 :group 'allout)
547 (make-variable-buffer-local 'allout-plain-bullets-string)
548 ;;;###autoload
549 (put 'allout-plain-bullets-string 'safe-local-variable 'stringp)
550 ;;;_ = allout-distinctive-bullets-string
551 (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^"
552 "Persistent outline header bullets used to distinguish special topics.
554 These bullets are distinguish topics with particular character.
555 They are not used by default in the topic creation routines, but
556 are offered as options when you modify topic creation with a
557 universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]).
559 Distinctive bullets are not cycled when topics are shifted or
560 otherwise automatically rebulleted, so their marking is
561 persistent until deliberately changed. Their significance is
562 purely by convention, however. Some conventions suggest
563 themselves:
565 `(' - open paren -- an aside or incidental point
566 `?' - question mark -- uncertain or outright question
567 `!' - exclamation point/bang -- emphatic
568 `[' - open square bracket -- meta-note, about item instead of item's subject
569 `\"' - double quote -- a quotation or other citation
570 `=' - equal sign -- an assignment, some kind of definition
571 `^' - carat -- relates to something above
573 Some are more elusive, but their rationale may be recognizable:
575 `+' - plus -- pending consideration, completion
576 `_' - underscore -- done, completed
577 `&' - ampersand -- addendum, furthermore
579 \(Some other non-plain bullets have special meaning to the
580 software. By default:
582 `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
583 `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
585 See `allout-plain-bullets-string' for the standard, alternating
586 bullets.
588 You must run `set-allout-regexp' in order for outline mode to
589 adopt changes of this value.
591 DO NOT include the close-square-bracket, `]', on either of the bullet
592 strings."
593 :type 'string
594 :group 'allout)
595 (make-variable-buffer-local 'allout-distinctive-bullets-string)
596 ;;;###autoload
597 (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp)
599 ;;;_ = allout-use-mode-specific-leader
600 (defcustom allout-use-mode-specific-leader t
601 "When non-nil, use mode-specific topic-header prefixes.
603 Allout outline mode will use the mode-specific `allout-mode-leaders' or
604 comment-start string, if any, to lead the topic prefix string, so topic
605 headers look like comments in the programming language. It will also use
606 the comment-start string, with an '_' appended, for `allout-primary-bullet'.
608 String values are used as literals, not regular expressions, so
609 do not escape any regulare-expression characters.
611 Value t means to first check for assoc value in `allout-mode-leaders'
612 alist, then use comment-start string, if any, then use default (`.').
613 \(See note about use of comment-start strings, below.)
615 Set to the symbol for either of `allout-mode-leaders' or
616 `comment-start' to use only one of them, respectively.
618 Value nil means to always use the default (`.') and leave
619 `allout-primary-bullet' unaltered.
621 comment-start strings that do not end in spaces are tripled in
622 the header-prefix, and an `_' underscore is tacked on the end, to
623 distinguish them from regular comment strings. comment-start
624 strings that do end in spaces are not tripled, but an underscore
625 is substituted for the space. [This presumes that the space is
626 for appearance, not comment syntax. You can use
627 `allout-mode-leaders' to override this behavior, when
628 undesired.]"
629 :type '(choice (const t) (const nil) string
630 (const allout-mode-leaders)
631 (const comment-start))
632 :group 'allout)
633 ;;;###autoload
634 (put 'allout-use-mode-specific-leader 'safe-local-variable
635 '(lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start))
636 (stringp x))))
637 ;;;_ = allout-mode-leaders
638 (defvar allout-mode-leaders '()
639 "Specific allout-prefix leading strings per major modes.
641 Use this if the mode's comment-start string isn't what you
642 prefer, or if the mode lacks a comment-start string. See
643 `allout-use-mode-specific-leader' for more details.
645 If you're constructing a string that will comment-out outline
646 structuring so it can be included in program code, append an extra
647 character, like an \"_\" underscore, to distinguish the lead string
648 from regular comments that start at the beginning-of-line.")
650 ;;;_ = allout-old-style-prefixes
651 (defcustom allout-old-style-prefixes nil
652 "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
654 Non-nil restricts the topic creation and modification
655 functions to asterix-padded prefixes, so they look exactly
656 like the original Emacs-outline style prefixes.
658 Whatever the setting of this variable, both old and new style prefixes
659 are always respected by the topic maneuvering functions."
660 :type 'boolean
661 :group 'allout)
662 (make-variable-buffer-local 'allout-old-style-prefixes)
663 ;;;###autoload
664 (put 'allout-old-style-prefixes 'safe-local-variable
665 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
666 ;;;_ = allout-stylish-prefixes -- alternating bullets
667 (defcustom allout-stylish-prefixes t
668 "Do fancy stuff with topic prefix bullets according to level, etc.
670 Non-nil enables topic creation, modification, and repositioning
671 functions to vary the topic bullet char (the char that marks the topic
672 depth) just preceding the start of the topic text) according to level.
673 Otherwise, only asterisks (`*') and distinctive bullets are used.
675 This is how an outline can look (but sans indentation) with stylish
676 prefixes:
678 * Top level
679 .* A topic
680 . + One level 3 subtopic
681 . . One level 4 subtopic
682 . . A second 4 subtopic
683 . + Another level 3 subtopic
684 . #1 A numbered level 4 subtopic
685 . #2 Another
686 . ! Another level 4 subtopic with a different distinctive bullet
687 . #4 And another numbered level 4 subtopic
689 This would be an outline with stylish prefixes inhibited (but the
690 numbered and other distinctive bullets retained):
692 * Top level
693 .* A topic
694 . * One level 3 subtopic
695 . * One level 4 subtopic
696 . * A second 4 subtopic
697 . * Another level 3 subtopic
698 . #1 A numbered level 4 subtopic
699 . #2 Another
700 . ! Another level 4 subtopic with a different distinctive bullet
701 . #4 And another numbered level 4 subtopic
703 Stylish and constant prefixes (as well as old-style prefixes) are
704 always respected by the topic maneuvering functions, regardless of
705 this variable setting.
707 The setting of this var is not relevant when `allout-old-style-prefixes'
708 is non-nil."
709 :type 'boolean
710 :group 'allout)
711 (make-variable-buffer-local 'allout-stylish-prefixes)
712 ;;;###autoload
713 (put 'allout-stylish-prefixes 'safe-local-variable
714 (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil)))))
716 ;;;_ = allout-numbered-bullet
717 (defcustom allout-numbered-bullet "#"
718 "String designating bullet of topics that have auto-numbering; nil for none.
720 Topics having this bullet have automatic maintenance of a sibling
721 sequence-number tacked on, just after the bullet. Conventionally set
722 to \"#\", you can set it to a bullet of your choice. A nil value
723 disables numbering maintenance."
724 :type '(choice (const nil) string)
725 :group 'allout)
726 (make-variable-buffer-local 'allout-numbered-bullet)
727 ;;;###autoload
728 (put 'allout-numbered-bullet 'safe-local-variable
729 (if (fboundp 'string-or-null-p)
730 'string-or-null-p
731 '(lambda (x) (or (stringp x) (null x)))))
732 ;;;_ = allout-file-xref-bullet
733 (defcustom allout-file-xref-bullet "@"
734 "Bullet signifying file cross-references, for `allout-resolve-xref'.
736 Set this var to the bullet you want to use for file cross-references."
737 :type '(choice (const nil) string)
738 :group 'allout)
739 ;;;###autoload
740 (put 'allout-file-xref-bullet 'safe-local-variable
741 (if (fboundp 'string-or-null-p)
742 'string-or-null-p
743 '(lambda (x) (or (stringp x) (null x)))))
744 ;;;_ = allout-presentation-padding
745 (defcustom allout-presentation-padding 2
746 "Presentation-format white-space padding factor, for greater indent."
747 :type 'integer
748 :group 'allout)
750 (make-variable-buffer-local 'allout-presentation-padding)
751 ;;;###autoload
752 (put 'allout-presentation-padding 'safe-local-variable 'integerp)
754 ;;;_ = allout-flattened-numbering-abbreviation
755 (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering
756 'allout-flattened-numbering-abbreviation "24.1")
757 (defcustom allout-flattened-numbering-abbreviation nil
758 "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
759 numbers to minimal amount with some context. Otherwise, entire
760 numbers are always used."
761 :type 'boolean
762 :group 'allout)
764 ;;;_ + LaTeX formatting
765 ;;;_ - allout-number-pages
766 (defcustom allout-number-pages nil
767 "Non-nil turns on page numbering for LaTeX formatting of an outline."
768 :type 'boolean
769 :group 'allout)
770 ;;;_ - allout-label-style
771 (defcustom allout-label-style "\\large\\bf"
772 "Font and size of labels for LaTeX formatting of an outline."
773 :type 'string
774 :group 'allout)
775 ;;;_ - allout-head-line-style
776 (defcustom allout-head-line-style "\\large\\sl "
777 "Font and size of entries for LaTeX formatting of an outline."
778 :type 'string
779 :group 'allout)
780 ;;;_ - allout-body-line-style
781 (defcustom allout-body-line-style " "
782 "Font and size of entries for LaTeX formatting of an outline."
783 :type 'string
784 :group 'allout)
785 ;;;_ - allout-title-style
786 (defcustom allout-title-style "\\Large\\bf"
787 "Font and size of titles for LaTeX formatting of an outline."
788 :type 'string
789 :group 'allout)
790 ;;;_ - allout-title
791 (defcustom allout-title '(or buffer-file-name (buffer-name))
792 "Expression to be evaluated to determine the title for LaTeX
793 formatted copy."
794 :type 'sexp
795 :group 'allout)
796 ;;;_ - allout-line-skip
797 (defcustom allout-line-skip ".05cm"
798 "Space between lines for LaTeX formatting of an outline."
799 :type 'string
800 :group 'allout)
801 ;;;_ - allout-indent
802 (defcustom allout-indent ".3cm"
803 "LaTeX formatted depth-indent spacing."
804 :type 'string
805 :group 'allout)
807 ;;;_ + Topic encryption
808 ;;;_ = allout-encryption group
809 (defgroup allout-encryption nil
810 "Settings for topic encryption features of allout outliner."
811 :group 'allout)
812 ;;;_ = allout-topic-encryption-bullet
813 (defcustom allout-topic-encryption-bullet "~"
814 "Bullet signifying encryption of the entry's body."
815 :type '(choice (const nil) string)
816 :version "22.1"
817 :group 'allout-encryption)
818 ;;;_ = allout-encrypt-unencrypted-on-saves
819 (defcustom allout-encrypt-unencrypted-on-saves t
820 "When saving, should topics pending encryption be encrypted?
822 The idea is to prevent file-system exposure of any un-encrypted stuff, and
823 mostly covers both deliberate file writes and auto-saves.
825 - Yes: encrypt all topics pending encryption, even if it's the one
826 currently being edited. (In that case, the currently edited topic
827 will be automatically decrypted before any user interaction, so they
828 can continue editing but the copy on the file system will be
829 encrypted.)
830 Auto-saves will use the \"All except current topic\" mode if this
831 one is selected, to avoid practical difficulties -- see below.
832 - All except current topic: skip the topic currently being edited, even if
833 it's pending encryption. This may expose the current topic on the
834 file sytem, but avoids the nuisance of prompts for the encryption
835 passphrase in the middle of editing for, eg, autosaves.
836 This mode is used for auto-saves for both this option and \"Yes\".
837 - No: leave it to the user to encrypt any unencrypted topics.
839 For practical reasons, auto-saves always use the 'except-current policy
840 when auto-encryption is enabled. (Otherwise, spurious passphrase prompts
841 and unavoidable timing collisions are too disruptive.) If security for a
842 file requires that even the current topic is never auto-saved in the clear,
843 disable auto-saves for that file."
845 :type '(choice (const :tag "Yes" t)
846 (const :tag "All except current topic" except-current)
847 (const :tag "No" nil))
848 :version "22.1"
849 :group 'allout-encryption)
850 (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves)
852 ;;;_ + Developer
853 ;;;_ = allout-developer group
854 (defgroup allout-developer nil
855 "Allout settings developers care about, including topic encryption and more."
856 :group 'allout)
857 ;;;_ = allout-run-unit-tests-on-load
858 (defcustom allout-run-unit-tests-on-load nil
859 "When non-nil, unit tests will be run at end of loading the allout module.
861 Generally, allout code developers are the only ones who'll want to set this.
863 \(If set, this makes it an even better practice to exercise changes by
864 doing byte-compilation with a repeat count, so the file is loaded after
865 compilation.)
867 See `allout-run-unit-tests' to see what's run."
868 :type 'boolean
869 :group 'allout-developer)
871 ;;;_ + Miscellaneous customization
873 ;;;_ = allout-enable-file-variable-adjustment
874 (defcustom allout-enable-file-variable-adjustment t
875 "If non-nil, some allout outline actions edit Emacs local file var text.
877 This can range from changes to existing entries, addition of new ones,
878 and creation of a new local variables section when necessary.
880 Emacs file variables adjustments are also inhibited if `enable-local-variables'
881 is nil.
883 Operations potentially causing edits include allout encryption routines.
884 For details, see `allout-toggle-current-subtree-encryption's docstring."
885 :type 'boolean
886 :group 'allout)
887 (make-variable-buffer-local 'allout-enable-file-variable-adjustment)
889 ;;;_* CODE -- no user customizations below.
891 ;;;_ #1 Internal Outline Formatting and Configuration
892 ;;;_ : Version
893 ;;;_ = allout-version
894 (defvar allout-version "2.3"
895 "Version of currently loaded outline package. (allout.el)")
896 ;;;_ > allout-version
897 (defun allout-version (&optional here)
898 "Return string describing the loaded outline version."
899 (interactive "P")
900 (let ((msg (concat "Allout Outline Mode v " allout-version)))
901 (if here (insert msg))
902 (message "%s" msg)
903 msg))
904 ;;;_ : Mode activation (defined here because it's referenced early)
905 ;;;_ = allout-mode
906 (defvar allout-mode nil "Allout outline mode minor-mode flag.")
907 (make-variable-buffer-local 'allout-mode)
908 ;;;_ = allout-layout nil
909 (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring.
910 "Buffer-specific setting for allout layout.
912 In buffers where this is non-nil \(and if `allout-auto-activation'
913 has been customized to enable this behavior), `allout-mode' will be
914 automatically activated. The layout dictated by the value will be used to
915 set the initial exposure when `allout-mode' is activated.
917 \*You should not setq-default this variable non-nil unless you want every
918 visited file to be treated as an allout file.*
920 The value would typically be set by a file local variable. For
921 example, the following lines at the bottom of an Emacs Lisp file:
923 ;;;Local variables:
924 ;;;allout-layout: (0 : -1 -1 0)
925 ;;;End:
927 dictate activation of `allout-mode' mode when the file is visited
928 \(presuming proper `allout-auto-activation' customization),
929 followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'.
930 \(This is the layout used for the allout.el source file.)
932 `allout-default-layout' describes the specification format.
933 `allout-layout' can additionally have the value `t', in which
934 case the value of `allout-default-layout' is used.")
935 (make-variable-buffer-local 'allout-layout)
936 ;;;###autoload
937 (put 'allout-layout 'safe-local-variable
938 '(lambda (x) (or (numberp x) (listp x) (memq x '(: * + -)))))
940 ;;;_ : Topic header format
941 ;;;_ = allout-regexp
942 (defvar allout-regexp ""
943 "*Regular expression to match the beginning of a heading line.
945 Any line whose beginning matches this regexp is considered a
946 heading. This var is set according to the user configuration vars
947 by `set-allout-regexp'.")
948 (make-variable-buffer-local 'allout-regexp)
949 ;;;_ = allout-bullets-string
950 (defvar allout-bullets-string ""
951 "A string dictating the valid set of outline topic bullets.
953 This var should *not* be set by the user -- it is set by `set-allout-regexp',
954 and is produced from the elements of `allout-plain-bullets-string'
955 and `allout-distinctive-bullets-string'.")
956 (make-variable-buffer-local 'allout-bullets-string)
957 ;;;_ = allout-bullets-string-len
958 (defvar allout-bullets-string-len 0
959 "Length of current buffers' `allout-plain-bullets-string'.")
960 (make-variable-buffer-local 'allout-bullets-string-len)
961 ;;;_ = allout-depth-specific-regexp
962 (defvar allout-depth-specific-regexp ""
963 "*Regular expression to match a heading line prefix for a particular depth.
965 This expression is used to search for depth-specific topic
966 headers at depth 2 and greater. Use `allout-depth-one-regexp'
967 for to seek topics at depth one.
969 This var is set according to the user configuration vars by
970 `set-allout-regexp'. It is prepared with format strings for two
971 decimal numbers, which should each be one less than the depth of the
972 topic prefix to be matched.")
973 (make-variable-buffer-local 'allout-depth-specific-regexp)
974 ;;;_ = allout-depth-one-regexp
975 (defvar allout-depth-one-regexp ""
976 "*Regular expression to match a heading line prefix for depth one.
978 This var is set according to the user configuration vars by
979 `set-allout-regexp'. It is prepared with format strings for two
980 decimal numbers, which should each be one less than the depth of the
981 topic prefix to be matched.")
982 (make-variable-buffer-local 'allout-depth-one-regexp)
983 ;;;_ = allout-line-boundary-regexp
984 (defvar allout-line-boundary-regexp ()
985 "`allout-regexp' prepended with a newline for the search target.
987 This is properly set by `set-allout-regexp'.")
988 (make-variable-buffer-local 'allout-line-boundary-regexp)
989 ;;;_ = allout-bob-regexp
990 (defvar allout-bob-regexp ()
991 "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
992 (make-variable-buffer-local 'allout-bob-regexp)
993 ;;;_ = allout-header-subtraction
994 (defvar allout-header-subtraction (1- (length allout-header-prefix))
995 "Allout-header prefix length to subtract when computing topic depth.")
996 (make-variable-buffer-local 'allout-header-subtraction)
997 ;;;_ = allout-plain-bullets-string-len
998 (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string)
999 "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
1000 (make-variable-buffer-local 'allout-plain-bullets-string-len)
1002 ;;;_ = allout-doublecheck-at-and-shallower
1003 (defconst allout-doublecheck-at-and-shallower 3
1004 "Validate apparent topics of this depth and shallower as being non-aberrant.
1006 Verified with `allout-aberrant-container-p'. The usefulness of
1007 this check is limited to shallow depths, because the
1008 determination of aberrance is according to the mistaken item
1009 being followed by a legitimate item of excessively greater depth.
1011 The classic example of a mistaken item, for a standard allout
1012 outline configuration, is a body line that begins with an '...'
1013 ellipsis. This happens to contain a legitimate depth-2 header
1014 prefix, constituted by two '..' dots at the beginning of the
1015 line. The only thing that can distinguish it *in principle* from
1016 a legitimate one is if the following real header is at a depth
1017 that is discontinuous from the depth of 2 implied by the
1018 ellipsis, ie depth 4 or more. As the depth being tested gets
1019 greater, the likelihood of this kind of disqualification is
1020 lower, and the usefulness of this test is lower.
1022 Extending the depth of the doublecheck increases the amount it is
1023 applied, increasing the cost of the test - on casual estimation,
1024 for outlines with many deep topics, geometrically (O(n)?).
1025 Taken together with decreasing likelihood that the test will be
1026 useful at greater depths, more modest doublecheck limits are more
1027 suitably economical.")
1028 ;;;_ X allout-reset-header-lead (header-lead)
1029 (defun allout-reset-header-lead (header-lead)
1030 "Reset the leading string used to identify topic headers."
1031 (interactive "sNew lead string: ")
1032 (setq allout-header-prefix header-lead)
1033 (setq allout-header-subtraction (1- (length allout-header-prefix)))
1034 (set-allout-regexp))
1035 ;;;_ X allout-lead-with-comment-string (header-lead)
1036 (defun allout-lead-with-comment-string (&optional header-lead)
1037 "Set the topic-header leading string to specified string.
1039 Useful when for encapsulating outline structure in programming
1040 language comments. Returns the leading string."
1042 (interactive "P")
1043 (if (not (stringp header-lead))
1044 (setq header-lead (read-string
1045 "String prefix for topic headers: ")))
1046 (setq allout-reindent-bodies nil)
1047 (allout-reset-header-lead header-lead)
1048 header-lead)
1049 ;;;_ > allout-infer-header-lead-and-primary-bullet ()
1050 (defun allout-infer-header-lead-and-primary-bullet ()
1051 "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
1053 Works according to settings of:
1055 `comment-start'
1056 `allout-header-prefix' (default)
1057 `allout-use-mode-specific-leader'
1058 and `allout-mode-leaders'.
1060 Apply this via (re)activation of `allout-mode', rather than
1061 invoking it directly."
1062 (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader)
1063 (if (or (stringp allout-use-mode-specific-leader)
1064 (memq allout-use-mode-specific-leader
1065 '(allout-mode-leaders
1066 comment-start
1067 t)))
1068 allout-use-mode-specific-leader
1069 ;; Oops -- garbled value, equate with effect of t:
1070 t)))
1071 (leader
1072 (cond
1073 ((not use-leader) nil)
1074 ;; Use the explicitly designated leader:
1075 ((stringp use-leader) use-leader)
1076 (t (or (and (memq use-leader '(t allout-mode-leaders))
1077 ;; Get it from outline mode leaders?
1078 (cdr (assq major-mode allout-mode-leaders)))
1079 ;; ... didn't get from allout-mode-leaders...
1080 (and (memq use-leader '(t comment-start))
1081 comment-start
1082 ;; Use comment-start, maybe tripled, and with
1083 ;; underscore:
1084 (concat
1085 (if (string= " "
1086 (substring comment-start
1087 (1- (length comment-start))))
1088 ;; Use comment-start, sans trailing space:
1089 (substring comment-start 0 -1)
1090 (concat comment-start comment-start comment-start))
1091 ;; ... and append underscore, whichever:
1092 "_")))))))
1093 (if (not leader)
1095 (setq allout-header-prefix leader)
1096 (if (not allout-old-style-prefixes)
1097 ;; setting allout-primary-bullet makes the top level topics use --
1098 ;; actually, be -- the special prefix:
1099 (setq allout-primary-bullet leader))
1100 allout-header-prefix)))
1101 (defalias 'allout-infer-header-lead
1102 'allout-infer-header-lead-and-primary-bullet)
1103 ;;;_ > allout-infer-body-reindent ()
1104 (defun allout-infer-body-reindent ()
1105 "Determine proper setting for `allout-reindent-bodies'.
1107 Depends on default setting of `allout-reindent-bodies' (which see)
1108 and presence of setting for `comment-start', to tell whether the
1109 file is programming code."
1110 (if (and allout-reindent-bodies
1111 comment-start
1112 (not (eq 'force allout-reindent-bodies)))
1113 (setq allout-reindent-bodies nil)))
1114 ;;;_ > set-allout-regexp ()
1115 (defun set-allout-regexp ()
1116 "Generate proper topic-header regexp form for outline functions.
1118 Works with respect to `allout-plain-bullets-string' and
1119 `allout-distinctive-bullets-string'.
1121 Also refresh various data structures that hinge on the regexp."
1123 (interactive)
1124 ;; Derive allout-bullets-string from user configured components:
1125 (setq allout-bullets-string "")
1126 (let ((strings (list 'allout-plain-bullets-string
1127 'allout-distinctive-bullets-string
1128 'allout-primary-bullet))
1129 cur-string
1130 cur-len
1131 cur-char
1132 index)
1133 (while strings
1134 (setq index 0)
1135 (setq cur-len (length (setq cur-string (symbol-value (car strings)))))
1136 (while (< index cur-len)
1137 (setq cur-char (aref cur-string index))
1138 (setq allout-bullets-string
1139 (concat allout-bullets-string
1140 (cond
1141 ; Single dash would denote a
1142 ; sequence, repeated denotes
1143 ; a dash:
1144 ((eq cur-char ?-) "--")
1145 ; literal close-square-bracket
1146 ; doesn't work right in the
1147 ; expr, exclude it:
1148 ((eq cur-char ?\]) "")
1149 (t (regexp-quote (char-to-string cur-char))))))
1150 (setq index (1+ index)))
1151 (setq strings (cdr strings)))
1153 ;; Derive next for repeated use in allout-pending-bullet:
1154 (setq allout-plain-bullets-string-len (length allout-plain-bullets-string))
1155 (setq allout-header-subtraction (1- (length allout-header-prefix)))
1157 (let (new-part old-part formfeed-part)
1158 (setq new-part (concat "\\("
1159 (regexp-quote allout-header-prefix)
1160 "[ \t]*"
1161 ;; already regexp-quoted in a custom way:
1162 "[" allout-bullets-string "]"
1163 "\\)")
1164 old-part (concat "\\("
1165 (regexp-quote allout-primary-bullet)
1166 "\\|"
1167 (regexp-quote allout-header-prefix)
1168 "\\)"
1170 " ?[^" allout-primary-bullet "]")
1171 formfeed-part "\\(\^L\\)"
1173 allout-regexp (concat new-part
1174 "\\|"
1175 old-part
1176 "\\|"
1177 formfeed-part)
1179 allout-line-boundary-regexp (concat "\n" new-part
1180 "\\|"
1181 "\n" old-part
1182 "\\|"
1183 "\n" formfeed-part)
1185 allout-bob-regexp (concat "\\`" new-part
1186 "\\|"
1187 "\\`" old-part
1188 "\\|"
1189 "\\`" formfeed-part
1192 (setq allout-depth-specific-regexp
1193 (concat "\\(^\\|\\`\\)"
1194 "\\("
1196 ;; new-style spacers-then-bullet string:
1197 "\\("
1198 (allout-format-quote (regexp-quote allout-header-prefix))
1199 " \\{%s\\}"
1200 "[" (allout-format-quote allout-bullets-string) "]"
1201 "\\)"
1203 ;; old-style all-bullets string, if primary not multi-char:
1204 (if (< 0 allout-header-subtraction)
1206 (concat "\\|\\("
1207 (allout-format-quote
1208 (regexp-quote allout-primary-bullet))
1209 (allout-format-quote
1210 (regexp-quote allout-primary-bullet))
1211 (allout-format-quote
1212 (regexp-quote allout-primary-bullet))
1213 "\\{%s\\}"
1214 ;; disqualify greater depths:
1215 "[^"
1216 (allout-format-quote allout-primary-bullet)
1217 "]\\)"
1219 "\\)"
1221 (setq allout-depth-one-regexp
1222 (concat "\\(^\\|\\`\\)"
1223 "\\("
1225 "\\("
1226 (regexp-quote allout-header-prefix)
1227 ;; disqualify any bullet char following any amount of
1228 ;; intervening whitespace:
1229 " *"
1230 (concat "[^ " allout-bullets-string "]")
1231 "\\)"
1232 (if (< 0 allout-header-subtraction)
1233 ;; Need not support anything like the old
1234 ;; bullet style if the prefix is multi-char.
1236 (concat "\\|"
1237 (regexp-quote allout-primary-bullet)
1238 ;; disqualify deeper primary-bullet sequences:
1239 "[^" allout-primary-bullet "]"))
1240 "\\)"
1241 ))))
1242 ;;;_ : Menu bar
1243 (defvar allout-mode-exposure-menu)
1244 (defvar allout-mode-editing-menu)
1245 (defvar allout-mode-navigation-menu)
1246 (defvar allout-mode-misc-menu)
1247 (defun produce-allout-mode-menubar-entries ()
1248 (require 'easymenu)
1249 (easy-menu-define allout-mode-exposure-menu
1250 allout-mode-map-value
1251 "Allout outline exposure menu."
1252 '("Exposure"
1253 ["Show Entry" allout-show-current-entry t]
1254 ["Show Children" allout-show-children t]
1255 ["Show Subtree" allout-show-current-subtree t]
1256 ["Hide Subtree" allout-hide-current-subtree t]
1257 ["Hide Leaves" allout-hide-current-leaves t]
1258 "----"
1259 ["Show All" allout-show-all t]))
1260 (easy-menu-define allout-mode-editing-menu
1261 allout-mode-map-value
1262 "Allout outline editing menu."
1263 '("Headings"
1264 ["Open Sibling" allout-open-sibtopic t]
1265 ["Open Subtopic" allout-open-subtopic t]
1266 ["Open Supertopic" allout-open-supertopic t]
1267 "----"
1268 ["Shift Topic In" allout-shift-in t]
1269 ["Shift Topic Out" allout-shift-out t]
1270 ["Rebullet Topic" allout-rebullet-topic t]
1271 ["Rebullet Heading" allout-rebullet-current-heading t]
1272 ["Number Siblings" allout-number-siblings t]
1273 "----"
1274 ["Toggle Topic Encryption"
1275 allout-toggle-current-subtree-encryption
1276 (> (allout-current-depth) 1)]))
1277 (easy-menu-define allout-mode-navigation-menu
1278 allout-mode-map-value
1279 "Allout outline navigation menu."
1280 '("Navigation"
1281 ["Next Visible Heading" allout-next-visible-heading t]
1282 ["Previous Visible Heading"
1283 allout-previous-visible-heading t]
1284 "----"
1285 ["Up Level" allout-up-current-level t]
1286 ["Forward Current Level" allout-forward-current-level t]
1287 ["Backward Current Level"
1288 allout-backward-current-level t]
1289 "----"
1290 ["Beginning of Entry"
1291 allout-beginning-of-current-entry t]
1292 ["End of Entry" allout-end-of-entry t]
1293 ["End of Subtree" allout-end-of-current-subtree t]))
1294 (easy-menu-define allout-mode-misc-menu
1295 allout-mode-map-value
1296 "Allout outlines miscellaneous bindings."
1297 '("Misc"
1298 ["Version" allout-version t]
1299 "----"
1300 ["Duplicate Exposed" allout-copy-exposed-to-buffer t]
1301 ["Duplicate Exposed, numbered"
1302 allout-flatten-exposed-to-buffer t]
1303 ["Duplicate Exposed, indented"
1304 allout-indented-exposed-to-buffer t]
1305 "----"
1306 ["Set Header Lead" allout-reset-header-lead t]
1307 ["Set New Exposure" allout-expose-topic t])))
1308 ;;;_ : Allout Modal-Variables Utilities
1309 ;;;_ = allout-mode-prior-settings
1310 (defvar allout-mode-prior-settings nil
1311 "Internal `allout-mode' use; settings to be resumed on mode deactivation.
1313 See `allout-add-resumptions' and `allout-do-resumptions'.")
1314 (make-variable-buffer-local 'allout-mode-prior-settings)
1315 ;;;_ > allout-add-resumptions (&rest pairs)
1316 (defun allout-add-resumptions (&rest pairs)
1317 "Set name/value PAIRS.
1319 Old settings are preserved for later resumption using `allout-do-resumptions'.
1321 The new values are set as a buffer local. On resumption, the prior buffer
1322 scope of the variable is restored along with its value. If it was a void
1323 buffer-local value, then it is left as nil on resumption.
1325 The pairs are lists whose car is the name of the variable and car of the
1326 cdr is the new value: '(some-var some-value)'. The pairs can actually be
1327 triples, where the third element qualifies the disposition of the setting,
1328 as described further below.
1330 If the optional third element is the symbol 'extend, then the new value
1331 created by `cons'ing the second element of the pair onto the front of the
1332 existing value.
1334 If the optional third element is the symbol 'append, then the new value is
1335 extended from the existing one by `append'ing a list containing the second
1336 element of the pair onto the end of the existing value.
1338 Extension, and resumptions in general, should not be used for hook
1339 functions -- use the 'local mode of `add-hook' for that, instead.
1341 The settings are stored on `allout-mode-prior-settings'."
1342 (while pairs
1343 (let* ((pair (pop pairs))
1344 (name (car pair))
1345 (value (cadr pair))
1346 (qualifier (if (> (length pair) 2)
1347 (caddr pair)))
1348 prior-value)
1349 (if (not (symbolp name))
1350 (error "Pair's name, %S, must be a symbol, not %s"
1351 name (type-of name)))
1352 (setq prior-value (condition-case nil
1353 (symbol-value name)
1354 (void-variable nil)))
1355 (when (not (assoc name allout-mode-prior-settings))
1356 ;; Not already added as a resumption, create the prior setting entry.
1357 (if (local-variable-p name (current-buffer))
1358 ;; is already local variable -- preserve the prior value:
1359 (push (list name prior-value) allout-mode-prior-settings)
1360 ;; wasn't local variable, indicate so for resumption by killing
1361 ;; local value, and make it local:
1362 (push (list name) allout-mode-prior-settings)
1363 (make-local-variable name)))
1364 (if qualifier
1365 (cond ((eq qualifier 'extend)
1366 (if (not (listp prior-value))
1367 (error "extension of non-list prior value attempted")
1368 (set name (cons value prior-value))))
1369 ((eq qualifier 'append)
1370 (if (not (listp prior-value))
1371 (error "appending of non-list prior value attempted")
1372 (set name (append prior-value (list value)))))
1373 (t (error "unrecognized setting qualifier `%s' encountered"
1374 qualifier)))
1375 (set name value)))))
1376 ;;;_ > allout-do-resumptions ()
1377 (defun allout-do-resumptions ()
1378 "Resume all name/value settings registered by `allout-add-resumptions'.
1380 This is used when concluding allout-mode, to resume selected variables to
1381 their settings before allout-mode was started."
1383 (while allout-mode-prior-settings
1384 (let* ((pair (pop allout-mode-prior-settings))
1385 (name (car pair))
1386 (value-cell (cdr pair)))
1387 (if (not value-cell)
1388 ;; Prior value was global:
1389 (kill-local-variable name)
1390 ;; Prior value was explicit:
1391 (set name (car value-cell))))))
1392 ;;;_ : Mode-specific incidentals
1393 ;;;_ > allout-unprotected (expr)
1394 (defmacro allout-unprotected (expr)
1395 "Enable internal outline operations to alter invisible text."
1396 `(let ((inhibit-read-only (if (not buffer-read-only) t))
1397 (inhibit-field-text-motion t))
1398 ,expr))
1399 ;;;_ = allout-mode-hook
1400 (defvar allout-mode-hook nil
1401 "*Hook that's run when allout mode starts.")
1402 ;;;_ = allout-mode-deactivate-hook
1403 (defvar allout-mode-deactivate-hook nil
1404 "*Hook that's run when allout mode ends.")
1405 (define-obsolete-variable-alias 'allout-mode-deactivate-hook
1406 'allout-mode-off-hook "24.1")
1407 ;;;_ = allout-exposure-category
1408 (defvar allout-exposure-category nil
1409 "Symbol for use as allout invisible-text overlay category.")
1410 ;;;_ = allout-exposure-change-hook
1411 (defvar allout-exposure-change-hook nil
1412 "*Hook that's run after allout outline subtree exposure changes.
1414 It is run at the conclusion of `allout-flag-region'.
1416 Functions on the hook must take three arguments:
1418 - FROM -- integer indicating the point at the start of the change.
1419 - TO -- integer indicating the point of the end of the change.
1420 - FLAG -- change mode: nil for exposure, otherwise concealment.
1422 This hook might be invoked multiple times by a single command.")
1423 ;;;_ = allout-structure-added-hook
1424 (defvar allout-structure-added-hook nil
1425 "*Hook that's run after addition of items to the outline.
1427 Functions on the hook should take two arguments:
1429 - NEW-START -- integer indicating position of start of the first new item.
1430 - NEW-END -- integer indicating position of end of the last new item.
1432 This hook might be invoked multiple times by a single command.")
1433 ;;;_ = allout-structure-deleted-hook
1434 (defvar allout-structure-deleted-hook nil
1435 "*Hook that's run after disciplined deletion of subtrees from the outline.
1437 Functions on the hook must take two arguments:
1439 - DEPTH -- integer indicating the depth of the subtree that was deleted.
1440 - REMOVED-FROM -- integer indicating the point where the subtree was removed.
1442 Some edits that remove or invalidate items may missed by this hook:
1443 specifically edits that native allout routines do not control.
1445 This hook might be invoked multiple times by a single command.")
1446 ;;;_ = allout-structure-shifted-hook
1447 (defvar allout-structure-shifted-hook nil
1448 "*Hook that's run after shifting of items in the outline.
1450 Functions on the hook should take two arguments:
1452 - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
1453 - START -- integer indicating the start point of the shifted parent item.
1455 Some edits that shift items can be missed by this hook: specifically edits
1456 that native allout routines do not control.
1458 This hook might be invoked multiple times by a single command.")
1459 ;;;_ = allout-after-copy-or-kill-hook
1460 (defvar allout-after-copy-or-kill-hook nil
1461 "*Hook that's run after copying outline text.
1463 Functions on the hook should not take any arguments.")
1464 ;;;_ = allout-outside-normal-auto-fill-function
1465 (defvar allout-outside-normal-auto-fill-function nil
1466 "Value of normal-auto-fill-function outside of allout mode.
1468 Used by allout-auto-fill to do the mandated normal-auto-fill-function
1469 wrapped within allout's automatic fill-prefix setting.")
1470 (make-variable-buffer-local 'allout-outside-normal-auto-fill-function)
1471 ;;;_ = prevent redundant activation by desktop mode:
1472 (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil))
1473 ;;;_ = allout-passphrase-verifier-string
1474 (defvar allout-passphrase-verifier-string nil
1475 "Setting used to test solicited encryption passphrases against the one
1476 already associated with a file.
1478 It consists of an encrypted random string useful only to verify that a
1479 passphrase entered by the user is effective for decryption. The passphrase
1480 itself is \*not* recorded in the file anywhere, and the encrypted contents
1481 are random binary characters to avoid exposing greater susceptibility to
1482 search attacks.
1484 The verifier string is retained as an Emacs file variable, as well as in
1485 the Emacs buffer state, if file variable adjustments are enabled. See
1486 `allout-enable-file-variable-adjustment' for details about that.")
1487 (make-variable-buffer-local 'allout-passphrase-verifier-string)
1488 (make-obsolete 'allout-passphrase-verifier-string
1489 'allout-passphrase-verifier-string "23.3")
1490 ;;;###autoload
1491 (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp)
1492 ;;;_ = allout-passphrase-hint-string
1493 (defvar allout-passphrase-hint-string ""
1494 "Variable used to retain reminder string for file's encryption passphrase.
1496 See the description of `allout-passphrase-hint-handling' for details about how
1497 the reminder is deployed.
1499 The hint is retained as an Emacs file variable, as well as in the Emacs buffer
1500 state, if file variable adjustments are enabled. See
1501 `allout-enable-file-variable-adjustment' for details about that.")
1502 (make-variable-buffer-local 'allout-passphrase-hint-string)
1503 (setq-default allout-passphrase-hint-string "")
1504 (make-obsolete 'allout-passphrase-hint-string
1505 'allout-passphrase-hint-string "23.3")
1506 ;;;###autoload
1507 (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp)
1508 ;;;_ = allout-after-save-decrypt
1509 (defvar allout-after-save-decrypt nil
1510 "Internal variable, is nil or has the value of two points:
1512 - the location of a topic to be decrypted after saving is done
1513 - where to situate the cursor after the decryption is performed
1515 This is used to decrypt the topic that was currently being edited, if it
1516 was encrypted automatically as part of a file write or autosave.")
1517 (make-variable-buffer-local 'allout-after-save-decrypt)
1518 ;;;_ = allout-encryption-plaintext-sanitization-regexps
1519 (defvar allout-encryption-plaintext-sanitization-regexps nil
1520 "List of regexps whose matches are removed from plaintext before encryption.
1522 This is for the sake of removing artifacts, like escapes, that are added on
1523 and not actually part of the original plaintext. The removal is done just
1524 prior to encryption.
1526 Entries must be symbols that are bound to the desired values.
1528 Each value can be a regexp or a list with a regexp followed by a
1529 substitution string. If it's just a regexp, all its matches are removed
1530 before the text is encrypted. If it's a regexp and a substitution, the
1531 substition is used against the regexp matches, a la `replace-match'.")
1532 (make-variable-buffer-local 'allout-encryption-text-removal-regexps)
1533 ;;;_ = allout-encryption-ciphertext-rejection-regexps
1534 (defvar allout-encryption-ciphertext-rejection-regexps nil
1535 "Variable for regexps matching plaintext to remove before encryption.
1537 This is used to detect strings in encryption results that would
1538 register as allout mode structural elements, for exmple, as a
1539 topic prefix.
1541 Entries must be symbols that are bound to the desired regexp values.
1543 Encryptions that result in matches will be retried, up to
1544 `allout-encryption-ciphertext-rejection-limit' times, after which
1545 an error is raised.")
1547 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps)
1548 ;;;_ = allout-encryption-ciphertext-rejection-ceiling
1549 (defvar allout-encryption-ciphertext-rejection-ceiling 5
1550 "Limit on number of times encryption ciphertext is rejected.
1552 See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1553 (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling)
1554 ;;;_ > allout-mode-p ()
1555 ;; Must define this macro above any uses, or byte compilation will lack
1556 ;; proper def, if file isn't loaded -- eg, during emacs build!
1557 ;;;###autoload
1558 (defmacro allout-mode-p ()
1559 "Return t if `allout-mode' is active in current buffer."
1560 'allout-mode)
1561 ;;;_ > allout-write-file-hook-handler ()
1562 (defun allout-write-file-hook-handler ()
1563 "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes."
1565 (if (or (not (allout-mode-p))
1566 (not (boundp 'allout-encrypt-unencrypted-on-saves))
1567 (not allout-encrypt-unencrypted-on-saves))
1569 (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves
1570 'except-current)
1571 (point-marker))))
1572 (if (save-excursion (goto-char (point-min))
1573 (allout-next-topic-pending-encryption except-mark))
1574 (progn
1575 (message "auto-encrypting pending topics")
1576 (sit-for 0)
1577 (condition-case failure
1578 (setq allout-after-save-decrypt
1579 (allout-encrypt-decrypted except-mark))
1580 (error (message
1581 "allout-write-file-hook-handler suppressing error %s"
1582 failure)
1583 (sit-for 2)))))
1585 nil)
1586 ;;;_ > allout-auto-save-hook-handler ()
1587 (defun allout-auto-save-hook-handler ()
1588 "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save."
1590 (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves)
1591 ;; Always implement 'except-current policy when enabled.
1592 (let ((allout-encrypt-unencrypted-on-saves 'except-current))
1593 (allout-write-file-hook-handler))))
1594 ;;;_ > allout-after-saves-handler ()
1595 (defun allout-after-saves-handler ()
1596 "Decrypt topic encrypted for save, if it's currently being edited.
1598 Ie, if it was pending encryption and contained the point in its body before
1599 the save.
1601 We use values stored in `allout-after-save-decrypt' to locate the topic
1602 and the place for the cursor after the decryption is done."
1603 (if (not (and (allout-mode-p)
1604 (boundp 'allout-after-save-decrypt)
1605 allout-after-save-decrypt))
1607 (goto-char (car allout-after-save-decrypt))
1608 (let ((was-modified (buffer-modified-p)))
1609 (allout-toggle-subtree-encryption)
1610 (if (not was-modified)
1611 (set-buffer-modified-p nil)))
1612 (goto-char (cadr allout-after-save-decrypt))
1613 (setq allout-after-save-decrypt nil))
1615 ;;;_ > allout-called-interactively-p ()
1616 (defmacro allout-called-interactively-p ()
1617 "A version of called-interactively-p independent of emacs version."
1618 ;; ... to ease maintenance of allout without betraying deprecation.
1619 (if (equal (subr-arity (symbol-function 'called-interactively-p))
1620 '(0 . 0))
1621 '(called-interactively-p)
1622 '(called-interactively-p 'interactive)))
1623 ;;;_ = allout-inhibit-aberrance-doublecheck nil
1624 ;; In some exceptional moments, disparate topic depths need to be allowed
1625 ;; momentarily, eg when one topic is being yanked into another and they're
1626 ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
1627 ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
1628 ;; processing to happen in the presence of such discrepancies. It should
1629 ;; almost never be needed, however.
1630 (defvar allout-inhibit-aberrance-doublecheck nil
1631 "Internal state, for momentarily inhibits aberrance doublecheck.
1633 This should only be momentarily let-bound non-nil, not set
1634 non-nil in a lasting way.")
1636 ;;;_ #2 Mode environment and activation
1637 ;;;_ = allout-explicitly-deactivated
1638 (defvar allout-explicitly-deactivated nil
1639 "If t, `allout-mode's last deactivation was deliberate.
1640 So `allout-post-command-business' should not reactivate it...")
1641 (make-variable-buffer-local 'allout-explicitly-deactivated)
1642 ;;;_ > allout-init (mode)
1643 (defun allout-init (mode)
1644 "DEPRECATED - configure allout activation by customizing
1645 `allout-auto-activation'. This function remains around, limited
1646 from what it did before, for backwards compatibility.
1648 MODE is the activation mode - see `allout-auto-activation' for
1649 valid values."
1651 (custom-set-variables (list 'allout-auto-activation (format "%s" mode)))
1652 (format "%s" mode))
1653 (make-obsolete 'allout-init
1654 "customize 'allout-auto-activation' instead." "23.3")
1655 ;;;_ > allout-setup-menubar ()
1656 (defun allout-setup-menubar ()
1657 "Populate the current buffer's menubar with `allout-mode' stuff."
1658 (let ((menus (list allout-mode-exposure-menu
1659 allout-mode-editing-menu
1660 allout-mode-navigation-menu
1661 allout-mode-misc-menu))
1662 cur)
1663 (while menus
1664 (setq cur (car menus)
1665 menus (cdr menus))
1666 (easy-menu-add cur))))
1667 ;;;_ > allout-overlay-preparations
1668 (defun allout-overlay-preparations ()
1669 "Set the properties of the allout invisible-text overlay and others."
1670 (setplist 'allout-exposure-category nil)
1671 (put 'allout-exposure-category 'invisible 'allout)
1672 (put 'allout-exposure-category 'evaporate t)
1673 ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
1674 ;; latter would be sufficient, but it seems that a separate behavior --
1675 ;; the _transient_ opening of invisible text during isearch -- is keyed to
1676 ;; presence of the isearch-open-invisible property -- even though this
1677 ;; property controls the isearch _arrival_ behavior. This is the case at
1678 ;; least in emacs 21, 22.1, and xemacs 21.4.
1679 (put 'allout-exposure-category 'isearch-open-invisible
1680 'allout-isearch-end-handler)
1681 (if (featurep 'xemacs)
1682 (put 'allout-exposure-category 'start-open t)
1683 (put 'allout-exposure-category 'insert-in-front-hooks
1684 '(allout-overlay-insert-in-front-handler)))
1685 (put 'allout-exposure-category 'modification-hooks
1686 '(allout-overlay-interior-modification-handler)))
1687 ;;;_ > define-minor-mode allout-mode
1688 ;;;_ : Defun:
1689 ;;;###autoload
1690 (define-minor-mode allout-mode
1691 ;;;_ . Doc string:
1692 "Toggle minor mode for controlling exposure and editing of text outlines.
1693 \\<allout-mode-map-value>
1695 Allout outline mode always runs as a minor mode.
1697 Allout outline mode provides extensive outline oriented
1698 formatting and manipulation. It enables structural editing of
1699 outlines, as well as navigation and exposure. It also is
1700 specifically aimed at accommodating syntax-sensitive text like
1701 programming languages. \(For example, see the allout code itself,
1702 which is organized as an allout outline.)
1704 In addition to typical outline navigation and exposure, allout includes:
1706 - topic-oriented authoring, including keystroke-based topic creation,
1707 repositioning, promotion/demotion, cut, and paste
1708 - incremental search with dynamic exposure and reconcealment of hidden text
1709 - adjustable format, so programming code can be developed in outline-structure
1710 - easy topic encryption and decryption, symmetric or key-pair
1711 - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
1712 - integral outline layout, for automatic initial exposure when visiting a file
1713 - independent extensibility, using comprehensive exposure and authoring hooks
1715 and many other features.
1717 Below is a description of the key bindings, and then description
1718 of special `allout-mode' features and terminology. See also the
1719 outline menubar additions for quick reference to many of the
1720 features. Customize `allout-auto-activation' to prepare your
1721 emacs session for automatic activation of `allout-mode'.
1723 The bindings are those listed in `allout-prefixed-keybindings'
1724 and `allout-unprefixed-keybindings'. We recommend customizing
1725 `allout-command-prefix' to use just `\\C-c' as the command
1726 prefix, if the allout bindings don't conflict with any personal
1727 bindings you have on \\C-c. In any case, outline structure
1728 navigation and authoring is simplified by positioning the cursor
1729 on an item's bullet character, the \"hot-spot\" -- then you can
1730 invoke allout commands with just the un-prefixed,
1731 un-control-shifted command letters. This is described further in
1732 the HOT-SPOT Operation section.
1734 Exposure Control:
1735 ----------------
1736 \\[allout-hide-current-subtree] `allout-hide-current-subtree'
1737 \\[allout-show-children] `allout-show-children'
1738 \\[allout-show-current-subtree] `allout-show-current-subtree'
1739 \\[allout-show-current-entry] `allout-show-current-entry'
1740 \\[allout-show-all] `allout-show-all'
1742 Navigation:
1743 ----------
1744 \\[allout-next-visible-heading] `allout-next-visible-heading'
1745 \\[allout-previous-visible-heading] `allout-previous-visible-heading'
1746 \\[allout-up-current-level] `allout-up-current-level'
1747 \\[allout-forward-current-level] `allout-forward-current-level'
1748 \\[allout-backward-current-level] `allout-backward-current-level'
1749 \\[allout-end-of-entry] `allout-end-of-entry'
1750 \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
1751 \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
1752 if immediately repeated cycles to the beginning of the current item
1753 and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
1756 Topic Header Production:
1757 -----------------------
1758 \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
1759 \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
1760 \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
1762 Topic Level and Prefix Adjustment:
1763 ---------------------------------
1764 \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
1765 \\[allout-shift-out] `allout-shift-out' ... less deep
1766 \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
1767 current topic
1768 \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
1769 its' offspring -- distinctive bullets are not changed, others
1770 are alternated according to nesting depth.
1771 \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
1772 the offspring are not affected.
1773 With repeat count, revoke numbering.
1775 Topic-oriented Killing and Yanking:
1776 ----------------------------------
1777 \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
1778 \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
1779 \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure.
1780 \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
1781 \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
1782 depth of heading if yanking into bare topic
1783 heading (ie, prefix sans text).
1784 \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank
1786 Topic-oriented Encryption:
1787 -------------------------
1788 \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
1789 Encrypt/Decrypt topic content
1791 Misc commands:
1792 -------------
1793 M-x outlineify-sticky Activate outline mode for current buffer,
1794 and establish a default file-var setting
1795 for `allout-layout'.
1796 \\[allout-mark-topic] `allout-mark-topic'
1797 \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
1798 Duplicate outline, sans concealed text, to
1799 buffer with name derived from derived from that
1800 of current buffer -- \"*BUFFERNAME exposed*\".
1801 \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
1802 Like above 'copy-exposed', but convert topic
1803 prefixes to section.subsection... numeric
1804 format.
1805 \\[customize-variable] allout-auto-activation
1806 Prepare Emacs session for allout outline mode
1807 auto-activation.
1809 Topic Encryption
1811 Outline mode supports gpg encryption of topics, with support for
1812 symmetric and key-pair modes, and auto-encryption of topics
1813 pending encryption on save.
1815 Topics pending encryption are, by default, automatically
1816 encrypted during file saves, including checkpoint saves, to avoid
1817 exposing the plain text of encrypted topics in the file system.
1818 If the content of the topic containing the cursor was encrypted
1819 for a save, it is automatically decrypted for continued editing.
1821 NOTE: A few GnuPG v2 versions improperly preserve incorrect
1822 symmetric decryption keys, preventing entry of the correct key on
1823 subsequent decryption attempts until the cache times-out. That
1824 can take several minutes. \(Decryption of other entries is not
1825 affected.) Upgrade your EasyPG version, if you can, and you can
1826 deliberately clear your gpg-agent's cache by sending it a '-HUP'
1827 signal.
1829 See `allout-toggle-current-subtree-encryption' function docstring
1830 and `allout-encrypt-unencrypted-on-saves' customization variable
1831 for details.
1833 HOT-SPOT Operation
1835 Hot-spot operation provides a means for easy, single-keystroke outline
1836 navigation and exposure control.
1838 When the text cursor is positioned directly on the bullet character of
1839 a topic, regular characters (a to z) invoke the commands of the
1840 corresponding allout-mode keymap control chars. For example, \"f\"
1841 would invoke the command typically bound to \"C-c<space>C-f\"
1842 \(\\[allout-forward-current-level] `allout-forward-current-level').
1844 Thus, by positioning the cursor on a topic bullet, you can
1845 execute the outline navigation and manipulation commands with a
1846 single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
1847 this special translation, so you can use them to get out of the
1848 hot-spot and back to normal editing operation.
1850 In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
1851 replaced with one that makes it easy to get to the hot-spot. If you
1852 repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
1853 is set) to the beginning of the item and then, if you hit it again
1854 immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
1855 \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
1856 at the beginning of the current entry.
1858 Extending Allout
1860 Allout exposure and authoring activites all have associated
1861 hooks, by which independent code can cooperate with allout
1862 without changes to the allout core. Here are key ones:
1864 `allout-mode-hook'
1865 `allout-mode-deactivate-hook' \(deprecated)
1866 `allout-mode-off-hook'
1867 `allout-exposure-change-hook'
1868 `allout-structure-added-hook'
1869 `allout-structure-deleted-hook'
1870 `allout-structure-shifted-hook'
1871 `allout-after-copy-or-kill-hook'
1873 Terminology
1875 Topic hierarchy constituents -- TOPICS and SUBTOPICS:
1877 ITEM: A unitary outline element, including the HEADER and ENTRY text.
1878 TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
1879 and with no intervening items of lower DEPTH than the container.
1880 CURRENT ITEM:
1881 The visible ITEM most immediately containing the cursor.
1882 DEPTH: The degree of nesting of an ITEM; it increases with containment.
1883 The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
1884 called the:
1885 LEVEL: The same as DEPTH.
1887 ANCESTORS:
1888 Those ITEMs whose TOPICs contain an ITEM.
1889 PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
1890 of the ITEM.
1891 OFFSPRING:
1892 The ITEMs contained within an ITEM's TOPIC.
1893 SUBTOPIC:
1894 An OFFSPRING of its ANCESTOR TOPICs.
1895 CHILD:
1896 An immediate SUBTOPIC of its PARENT.
1897 SIBLINGS:
1898 TOPICs having the same PARENT and DEPTH.
1900 Topic text constituents:
1902 HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
1903 text.
1904 ENTRY: The text content of an ITEM, before any OFFSPRING, but including
1905 the HEADER text and distinct from the ITEM PREFIX.
1906 BODY: Same as ENTRY.
1907 PREFIX: The leading text of an ITEM which distinguishes it from normal
1908 ENTRY text. Allout recognizes the outline structure according
1909 to the strict PREFIX format. It consists of a PREFIX-LEAD string,
1910 PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
1911 number, indicating the ordinal number of the topic among its
1912 siblings, or an asterisk indicating encryption, plus an optional
1913 space. After that is the ITEM HEADER text, which is not part of
1914 the PREFIX.
1916 The relative length of the PREFIX determines the nesting DEPTH
1917 of the ITEM.
1918 PREFIX-LEAD:
1919 The string at the beginning of a HEADER PREFIX, by default a `.'.
1920 It can be customized by changing the setting of
1921 `allout-header-prefix' and then reinitializing `allout-mode'.
1923 When the PREFIX-LEAD is set to the comment-string of a
1924 programming language, outline structuring can be embedded in
1925 program code without interfering with processing of the text
1926 (by emacs or the language processor) as program code. This
1927 setting happens automatically when allout mode is used in
1928 programming-mode buffers. See `allout-use-mode-specific-leader'
1929 docstring for more detail.
1930 PREFIX-PADDING:
1931 Spaces or asterisks which separate the PREFIX-LEAD and the
1932 bullet, determining the ITEM's DEPTH.
1933 BULLET: A character at the end of the ITEM PREFIX, it must be one of
1934 the characters listed on `allout-plain-bullets-string' or
1935 `allout-distinctive-bullets-string'. When creating a TOPIC,
1936 plain BULLETs are by default used, according to the DEPTH of the
1937 TOPIC. Choice among the distinctive BULLETs is offered when you
1938 provide a universal argugment \(\\[universal-argument]) to the
1939 TOPIC creation command, or when explictly rebulleting a TOPIC. The
1940 significance of the various distinctive bullets is purely by
1941 convention. See the documentation for the above bullet strings for
1942 more details.
1943 EXPOSURE:
1944 The state of a TOPIC which determines the on-screen visibility
1945 of its OFFSPRING and contained ENTRY text.
1946 CONCEALED:
1947 TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
1948 text is represented by \"...\" ellipses.
1950 CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
1951 CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
1952 OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1953 ;;;_ . Code
1954 :lighter " Allout"
1955 :keymap 'allout-mode-map
1957 (let ((write-file-hook-var-name (cond ((boundp 'write-file-functions)
1958 'write-file-functions)
1959 ((boundp 'write-file-hooks)
1960 'write-file-hooks)
1961 (t 'local-write-file-hooks)))
1962 (use-layout (if (listp allout-layout)
1963 allout-layout
1964 allout-default-layout)))
1966 (if (not (allout-mode-p))
1967 (progn
1968 ;; Deactivation:
1970 ; Activation not explicitly
1971 ; requested, and either in
1972 ; active state or *de*activation
1973 ; specifically requested:
1974 (allout-do-resumptions)
1976 (remove-from-invisibility-spec '(allout . t))
1977 (remove-hook 'pre-command-hook 'allout-pre-command-business t)
1978 (remove-hook 'post-command-hook 'allout-post-command-business t)
1979 (remove-hook 'before-change-functions 'allout-before-change-handler t)
1980 (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t)
1981 (remove-hook write-file-hook-var-name
1982 'allout-write-file-hook-handler t)
1983 (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t)
1985 (remove-overlays (point-min) (point-max)
1986 'category 'allout-exposure-category))
1988 ;; Activating:
1989 (if allout-old-style-prefixes
1990 ;; Inhibit all the fancy formatting:
1991 (allout-add-resumptions '(allout-primary-bullet "*")))
1993 (allout-overlay-preparations) ; Doesn't hurt to redo this.
1995 (allout-infer-header-lead-and-primary-bullet)
1996 (allout-infer-body-reindent)
1998 (set-allout-regexp)
1999 (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
2000 allout-line-boundary-regexp
2001 extend)
2002 '(allout-encryption-ciphertext-rejection-regexps
2003 allout-bob-regexp
2004 extend))
2006 (allout-compose-and-institute-keymap)
2007 (produce-allout-mode-menubar-entries)
2009 (add-to-invisibility-spec '(allout . t))
2011 (allout-add-resumptions '(line-move-ignore-invisible t))
2012 (add-hook 'pre-command-hook 'allout-pre-command-business nil t)
2013 (add-hook 'post-command-hook 'allout-post-command-business nil t)
2014 (add-hook 'before-change-functions 'allout-before-change-handler nil t)
2015 (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t)
2016 (add-hook write-file-hook-var-name 'allout-write-file-hook-handler
2017 nil t)
2018 (add-hook 'auto-save-hook 'allout-auto-save-hook-handler nil t)
2020 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2021 ;; func will be used if auto-fill is active or activated. (The
2022 ;; custom func respects topic headline, maintains hanging-indents,
2023 ;; etc.)
2024 (allout-add-resumptions (list 'allout-former-auto-filler
2025 auto-fill-function)
2026 ;; Register allout-auto-fill to be used if
2027 ;; filling is active:
2028 (list 'allout-outside-normal-auto-fill-function
2029 normal-auto-fill-function)
2030 '(normal-auto-fill-function allout-auto-fill)
2031 ;; Paragraphs are broken by topic headlines.
2032 (list 'paragraph-start
2033 (concat paragraph-start "\\|^\\("
2034 allout-regexp "\\)"))
2035 (list 'paragraph-separate
2036 (concat paragraph-separate "\\|^\\("
2037 allout-regexp "\\)")))
2038 (if (and auto-fill-function (not allout-inhibit-auto-fill))
2039 ;; allout-auto-fill will use the stashed values and so forth.
2040 (allout-add-resumptions '(auto-fill-function allout-auto-fill)))
2042 (allout-setup-menubar)
2044 ;; Do auto layout if warranted:
2045 (when (and allout-layout
2046 allout-auto-activation
2047 use-layout
2048 (and (not (string= allout-auto-activation "activate"))
2049 (if (string= allout-auto-activation "ask")
2050 (if (y-or-n-p (format "Expose %s with layout '%s'? "
2051 (buffer-name)
2052 use-layout))
2054 (message "Skipped %s layout." (buffer-name))
2055 nil)
2056 t)))
2057 (save-excursion
2058 (message "Adjusting '%s' exposure..." (buffer-name))
2059 (goto-char 0)
2060 (allout-this-or-next-heading)
2061 (condition-case err
2062 (progn
2063 (apply 'allout-expose-topic (list use-layout))
2064 (message "Adjusting '%s' exposure... done."
2065 (buffer-name)))
2066 ;; Problem applying exposure -- notify user, but don't
2067 ;; interrupt, eg, file visit:
2068 (error (message "%s" (car (cdr err)))
2069 (sit-for 1))))
2070 ) ; when allout-layout
2071 ) ; if (allout-mode-p)
2072 ) ; let (())
2073 ) ; define-minor-mode
2074 ;;;_ > allout-minor-mode alias
2075 (defalias 'allout-minor-mode 'allout-mode)
2076 ;;;_ > allout-unload-function
2077 (defun allout-unload-function ()
2078 "Unload the allout outline library."
2079 (save-current-buffer
2080 (dolist (buffer (buffer-list))
2081 (set-buffer buffer)
2082 (when (allout-mode-p) (allout-mode))))
2083 ;; continue standard unloading
2084 nil)
2086 ;;;_ - Position Assessment
2087 ;;;_ > allout-hidden-p (&optional pos)
2088 (defsubst allout-hidden-p (&optional pos)
2089 "Non-nil if the character after point was made invisible by allout."
2090 (eq (get-char-property (or pos (point)) 'invisible) 'allout))
2092 ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
2093 ;;; &optional prelen)
2094 (defun allout-overlay-insert-in-front-handler (ol after beg end
2095 &optional prelen)
2096 "Shift the overlay so stuff inserted in front of it is excluded."
2097 (if after
2098 ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
2099 ;; front-advance on the overlay worked as expected?
2100 (move-overlay ol (1+ beg) (overlay-end ol))))
2101 ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
2102 ;;; &optional prelen)
2103 (defun allout-overlay-interior-modification-handler (ol after beg end
2104 &optional prelen)
2105 "Get confirmation before making arbitrary changes to invisible text.
2107 We expose the invisible text and ask for confirmation. Refusal or
2108 `keyboard-quit' abandons the changes, with keyboard-quit additionally
2109 reclosing the opened text.
2111 No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
2112 internal functions use this feature cohesively bunch changes."
2114 (when (and (not inhibit-read-only) (not after))
2115 (let ((start (point))
2116 (ol-start (overlay-start ol))
2117 (ol-end (overlay-end ol))
2118 first)
2119 (goto-char beg)
2120 (while (< (point) end)
2121 (when (allout-hidden-p)
2122 (allout-show-to-offshoot)
2123 (if (allout-hidden-p)
2124 (save-excursion (forward-char 1)
2125 (allout-show-to-offshoot)))
2126 (when (not first)
2127 (setq first (point))))
2128 (goto-char (if (featurep 'xemacs)
2129 (next-property-change (1+ (point)) nil end)
2130 (next-char-property-change (1+ (point)) end))))
2131 (when first
2132 (goto-char first)
2133 (condition-case nil
2134 (if (not
2135 (yes-or-no-p
2136 (substitute-command-keys
2137 (concat "Modify concealed text? (\"no\" just aborts,"
2138 " \\[keyboard-quit] also reconceals) "))))
2139 (progn (goto-char start)
2140 (error "Concealed-text change refused")))
2141 (quit (allout-flag-region ol-start ol-end nil)
2142 (allout-flag-region ol-start ol-end t)
2143 (error "Concealed-text change abandoned, text reconcealed"))))
2144 (goto-char start))))
2145 ;;;_ > allout-before-change-handler (beg end)
2146 (defun allout-before-change-handler (beg end)
2147 "Protect against changes to invisible text.
2149 See `allout-overlay-interior-modification-handler' for details."
2151 (when (and (allout-mode-p) undo-in-progress (allout-hidden-p))
2152 (allout-show-children))
2154 ;; allout-overlay-interior-modification-handler on an overlay handles
2155 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
2156 (when (and (featurep 'xemacs) (allout-mode-p))
2157 ;; process all of the pending overlays:
2158 (save-excursion
2159 (goto-char beg)
2160 (let ((overlay (allout-get-invisibility-overlay)))
2161 (if overlay
2162 (allout-overlay-interior-modification-handler
2163 overlay nil beg end nil))))))
2164 ;;;_ > allout-isearch-end-handler (&optional overlay)
2165 (defun allout-isearch-end-handler (&optional overlay)
2166 "Reconcile allout outline exposure on arriving in hidden text after isearch.
2168 Optional OVERLAY parameter is for when this function is used by
2169 `isearch-open-invisible' overlay property. It is otherwise unused, so this
2170 function can also be used as an `isearch-mode-end-hook'."
2172 (if (and (allout-mode-p) (allout-hidden-p))
2173 (allout-show-to-offshoot)))
2175 ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
2176 ;; All the basic outline functions that directly do string matches to
2177 ;; evaluate heading prefix location set the variables
2178 ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
2179 ;; when successful. Functions starting with `allout-recent-' all
2180 ;; use this state, providing the means to avoid redundant searches
2181 ;; for just-established data. This optimization can provide
2182 ;; significant speed improvement, but it must be employed carefully.
2183 ;;;_ = allout-recent-prefix-beginning
2184 (defvar allout-recent-prefix-beginning 0
2185 "Buffer point of the start of the last topic prefix encountered.")
2186 (make-variable-buffer-local 'allout-recent-prefix-beginning)
2187 ;;;_ = allout-recent-prefix-end
2188 (defvar allout-recent-prefix-end 0
2189 "Buffer point of the end of the last topic prefix encountered.")
2190 (make-variable-buffer-local 'allout-recent-prefix-end)
2191 ;;;_ = allout-recent-depth
2192 (defvar allout-recent-depth 0
2193 "Depth of the last topic prefix encountered.")
2194 (make-variable-buffer-local 'allout-recent-depth)
2195 ;;;_ = allout-recent-end-of-subtree
2196 (defvar allout-recent-end-of-subtree 0
2197 "Buffer point last returned by `allout-end-of-current-subtree'.")
2198 (make-variable-buffer-local 'allout-recent-end-of-subtree)
2199 ;;;_ > allout-prefix-data ()
2200 (defsubst allout-prefix-data ()
2201 "Register allout-prefix state data.
2203 For reference by `allout-recent' funcs. Return
2204 the new value of `allout-recent-prefix-beginning'."
2205 (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3))
2206 allout-recent-prefix-beginning (or (match-beginning 1)
2207 (match-beginning 2)
2208 (match-beginning 3))
2209 allout-recent-depth (max 1 (- allout-recent-prefix-end
2210 allout-recent-prefix-beginning
2211 allout-header-subtraction)))
2212 allout-recent-prefix-beginning)
2213 ;;;_ > nullify-allout-prefix-data ()
2214 (defsubst nullify-allout-prefix-data ()
2215 "Mark allout prefix data as being uninformative."
2216 (setq allout-recent-prefix-end (point)
2217 allout-recent-prefix-beginning (point)
2218 allout-recent-depth 0)
2219 allout-recent-prefix-beginning)
2220 ;;;_ > allout-recent-depth ()
2221 (defsubst allout-recent-depth ()
2222 "Return depth of last heading encountered by an outline maneuvering function.
2224 All outline functions which directly do string matches to assess
2225 headings set the variables `allout-recent-prefix-beginning' and
2226 `allout-recent-prefix-end' if successful. This function uses those settings
2227 to return the current depth."
2229 allout-recent-depth)
2230 ;;;_ > allout-recent-prefix ()
2231 (defsubst allout-recent-prefix ()
2232 "Like `allout-recent-depth', but returns text of last encountered prefix.
2234 All outline functions which directly do string matches to assess
2235 headings set the variables `allout-recent-prefix-beginning' and
2236 `allout-recent-prefix-end' if successful. This function uses those settings
2237 to return the current prefix."
2238 (buffer-substring-no-properties allout-recent-prefix-beginning
2239 allout-recent-prefix-end))
2240 ;;;_ > allout-recent-bullet ()
2241 (defmacro allout-recent-bullet ()
2242 "Like allout-recent-prefix, but returns bullet of last encountered prefix.
2244 All outline functions which directly do string matches to assess
2245 headings set the variables `allout-recent-prefix-beginning' and
2246 `allout-recent-prefix-end' if successful. This function uses those settings
2247 to return the current depth of the most recently matched topic."
2248 '(buffer-substring-no-properties (1- allout-recent-prefix-end)
2249 allout-recent-prefix-end))
2251 ;;;_ #4 Navigation
2253 ;;;_ - Position Assessment
2254 ;;;_ : Location Predicates
2255 ;;;_ > allout-do-doublecheck ()
2256 (defsubst allout-do-doublecheck ()
2257 "True if current item conditions qualify for checking on topic aberrance."
2258 (and
2259 ;; presume integrity of outline and yanked content during yank -- necessary
2260 ;; to allow for level disparity of yank location and yanked text:
2261 (not allout-inhibit-aberrance-doublecheck)
2262 ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
2263 (<= allout-recent-depth allout-doublecheck-at-and-shallower)))
2264 ;;;_ > allout-aberrant-container-p ()
2265 (defun allout-aberrant-container-p ()
2266 "True if topic, or next sibling with children, contains them discontinuously.
2268 Discontinuous means an immediate offspring that is nested more
2269 than one level deeper than the topic.
2271 If topic has no offspring, then the next sibling with offspring will
2272 determine whether or not this one is determined to be aberrant.
2274 If true, then the allout-recent-* settings are calibrated on the
2275 offspring that qaulifies it as aberrant, ie with depth that
2276 exceeds the topic by more than one."
2278 ;; This is most clearly understood when considering standard-prefix-leader
2279 ;; low-level topics, which can all too easily match text not intended as
2280 ;; headers. For example, any line with a leading '.' or '*' and lacking a
2281 ;; following bullet qualifies without this protection. (A sequence of
2282 ;; them can occur naturally, eg a typical textual bullet list.) We
2283 ;; disqualify such low-level sequences when they are followed by a
2284 ;; discontinuously contained child, inferring that the sequences are not
2285 ;; actually connected with their prospective context.
2287 (let ((depth (allout-depth))
2288 (start-point (point))
2289 done aberrant)
2290 (save-match-data
2291 (save-excursion
2292 (while (and (not done)
2293 (re-search-forward allout-line-boundary-regexp nil 0))
2294 (allout-prefix-data)
2295 (goto-char allout-recent-prefix-beginning)
2296 (cond
2297 ;; sibling -- continue:
2298 ((eq allout-recent-depth depth))
2299 ;; first offspring is excessive -- aberrant:
2300 ((> allout-recent-depth (1+ depth))
2301 (setq done t aberrant t))
2302 ;; next non-sibling is lower-depth -- not aberrant:
2303 (t (setq done t))))))
2304 (if aberrant
2305 aberrant
2306 (goto-char start-point)
2307 ;; recalibrate allout-recent-*
2308 (allout-depth)
2309 nil)))
2310 ;;;_ > allout-on-current-heading-p ()
2311 (defun allout-on-current-heading-p ()
2312 "Return non-nil if point is on current visible topics' header line.
2314 Actually, returns prefix beginning point."
2315 (save-excursion
2316 (allout-beginning-of-current-line)
2317 (save-match-data
2318 (and (looking-at allout-regexp)
2319 (allout-prefix-data)
2320 (or (not (allout-do-doublecheck))
2321 (not (allout-aberrant-container-p)))))))
2322 ;;;_ > allout-on-heading-p ()
2323 (defalias 'allout-on-heading-p 'allout-on-current-heading-p)
2324 ;;;_ > allout-e-o-prefix-p ()
2325 (defun allout-e-o-prefix-p ()
2326 "True if point is located where current topic prefix ends, heading begins."
2327 (and (save-match-data
2328 (save-excursion (let ((inhibit-field-text-motion t))
2329 (beginning-of-line))
2330 (looking-at allout-regexp))
2331 (= (point) (save-excursion (allout-end-of-prefix)(point))))))
2332 ;;;_ : Location attributes
2333 ;;;_ > allout-depth ()
2334 (defun allout-depth ()
2335 "Return depth of topic most immediately containing point.
2337 Does not do doublecheck for aberrant topic header.
2339 Return zero if point is not within any topic.
2341 Like `allout-current-depth', but respects hidden as well as visible topics."
2342 (save-excursion
2343 (let ((start-point (point)))
2344 (if (and (allout-goto-prefix)
2345 (not (< start-point (point))))
2346 allout-recent-depth
2347 (progn
2348 ;; Oops, no prefix, nullify it:
2349 (nullify-allout-prefix-data)
2350 ;; ... and return 0:
2351 0)))))
2352 ;;;_ > allout-current-depth ()
2353 (defun allout-current-depth ()
2354 "Return depth of visible topic most immediately containing point.
2356 Return zero if point is not within any topic."
2357 (save-excursion
2358 (if (allout-back-to-current-heading)
2359 (max 1
2360 (- allout-recent-prefix-end
2361 allout-recent-prefix-beginning
2362 allout-header-subtraction))
2363 0)))
2364 ;;;_ > allout-get-current-prefix ()
2365 (defun allout-get-current-prefix ()
2366 "Topic prefix of the current topic."
2367 (save-excursion
2368 (if (allout-goto-prefix)
2369 (allout-recent-prefix))))
2370 ;;;_ > allout-get-bullet ()
2371 (defun allout-get-bullet ()
2372 "Return bullet of containing topic (visible or not)."
2373 (save-excursion
2374 (and (allout-goto-prefix)
2375 (allout-recent-bullet))))
2376 ;;;_ > allout-current-bullet ()
2377 (defun allout-current-bullet ()
2378 "Return bullet of current (visible) topic heading, or none if none found."
2379 (condition-case nil
2380 (save-excursion
2381 (allout-back-to-current-heading)
2382 (buffer-substring-no-properties (- allout-recent-prefix-end 1)
2383 allout-recent-prefix-end))
2384 ;; Quick and dirty provision, ostensibly for missing bullet:
2385 (args-out-of-range nil))
2387 ;;;_ > allout-get-prefix-bullet (prefix)
2388 (defun allout-get-prefix-bullet (prefix)
2389 "Return the bullet of the header prefix string PREFIX."
2390 ;; Doesn't make sense if we're old-style prefixes, but this just
2391 ;; oughtn't be called then, so forget about it...
2392 (if (string-match allout-regexp prefix)
2393 (substring prefix (1- (match-end 2)) (match-end 2))))
2394 ;;;_ > allout-sibling-index (&optional depth)
2395 (defun allout-sibling-index (&optional depth)
2396 "Item number of this prospective topic among its siblings.
2398 If optional arg DEPTH is greater than current depth, then we're
2399 opening a new level, and return 0.
2401 If less than this depth, ascend to that depth and count..."
2403 (save-excursion
2404 (cond ((and depth (<= depth 0) 0))
2405 ((or (null depth) (= depth (allout-depth)))
2406 (let ((index 1))
2407 (while (allout-previous-sibling allout-recent-depth nil)
2408 (setq index (1+ index)))
2409 index))
2410 ((< depth allout-recent-depth)
2411 (allout-ascend-to-depth depth)
2412 (allout-sibling-index))
2413 (0))))
2414 ;;;_ > allout-topic-flat-index ()
2415 (defun allout-topic-flat-index ()
2416 "Return a list indicating point's numeric section.subsect.subsubsect...
2417 Outermost is first."
2418 (let* ((depth (allout-depth))
2419 (next-index (allout-sibling-index depth))
2420 (rev-sibls nil))
2421 (while (> next-index 0)
2422 (setq rev-sibls (cons next-index rev-sibls))
2423 (setq depth (1- depth))
2424 (setq next-index (allout-sibling-index depth)))
2425 rev-sibls)
2428 ;;;_ - Navigation routines
2429 ;;;_ > allout-beginning-of-current-line ()
2430 (defun allout-beginning-of-current-line ()
2431 "Like beginning of line, but to visible text."
2433 ;; This combination of move-beginning-of-line and beginning-of-line is
2434 ;; deliberate, but the (beginning-of-line) may now be superfluous.
2435 (let ((inhibit-field-text-motion t))
2436 (move-beginning-of-line 1)
2437 (beginning-of-line)
2438 (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
2439 (beginning-of-line)
2440 (if (or (allout-hidden-p) (not (bolp)))
2441 (forward-char -1)))))
2442 ;;;_ > allout-end-of-current-line ()
2443 (defun allout-end-of-current-line ()
2444 "Move to the end of line, past concealed text if any."
2445 ;; This is for symmetry with `allout-beginning-of-current-line' --
2446 ;; `move-end-of-line' doesn't suffer the same problem as
2447 ;; `move-beginning-of-line'.
2448 (let ((inhibit-field-text-motion t))
2449 (end-of-line)
2450 (while (allout-hidden-p)
2451 (end-of-line)
2452 (if (allout-hidden-p) (forward-char 1)))))
2453 ;;;_ > allout-beginning-of-line ()
2454 (defun allout-beginning-of-line ()
2455 "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
2457 (interactive)
2459 (if (or (not allout-beginning-of-line-cycles)
2460 (not (equal last-command this-command)))
2461 (progn
2462 (if (and (not (bolp))
2463 (allout-hidden-p (1- (point))))
2464 (goto-char (allout-previous-single-char-property-change
2465 (1- (point)) 'invisible)))
2466 (move-beginning-of-line 1))
2467 (allout-depth)
2468 (let ((beginning-of-body
2469 (save-excursion
2470 (while (and (allout-do-doublecheck)
2471 (allout-aberrant-container-p)
2472 (allout-previous-visible-heading 1)))
2473 (allout-beginning-of-current-entry)
2474 (point))))
2475 (cond ((= (current-column) 0)
2476 (goto-char beginning-of-body))
2477 ((< (point) beginning-of-body)
2478 (allout-beginning-of-current-line))
2479 ((= (point) beginning-of-body)
2480 (goto-char (allout-current-bullet-pos)))
2481 (t (allout-beginning-of-current-line)
2482 (if (< (point) beginning-of-body)
2483 ;; we were on the headline after its start:
2484 (goto-char beginning-of-body)))))))
2485 ;;;_ > allout-end-of-line ()
2486 (defun allout-end-of-line ()
2487 "End-of-line with `allout-end-of-line-cycles' behavior, if set."
2489 (interactive)
2491 (if (or (not allout-end-of-line-cycles)
2492 (not (equal last-command this-command)))
2493 (allout-end-of-current-line)
2494 (let ((end-of-entry (save-excursion
2495 (allout-end-of-entry)
2496 (point))))
2497 (cond ((not (eolp))
2498 (allout-end-of-current-line))
2499 ((or (allout-hidden-p) (save-excursion
2500 (forward-char -1)
2501 (allout-hidden-p)))
2502 (allout-back-to-current-heading)
2503 (allout-show-current-entry)
2504 (allout-show-children)
2505 (allout-end-of-entry))
2506 ((>= (point) end-of-entry)
2507 (allout-back-to-current-heading)
2508 (allout-end-of-current-line))
2510 (if (not (allout-mark-active-p))
2511 (push-mark))
2512 (allout-end-of-entry))))))
2513 ;;;_ > allout-mark-active-p ()
2514 (defun allout-mark-active-p ()
2515 "True if the mark is currently or always active."
2516 ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
2517 ;; provisions, at least in fsf emacs to prevent warnings about lack of,
2518 ;; eg, region-active-p.
2519 (cond ((boundp 'mark-active)
2520 mark-active)
2521 ((fboundp 'region-active-p)
2522 (region-active-p))
2523 (t)))
2524 ;;;_ > allout-next-heading ()
2525 (defsubst allout-next-heading ()
2526 "Move to the heading for the topic (possibly invisible) after this one.
2528 Returns the location of the heading, or nil if none found.
2530 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2531 (save-match-data
2533 (if (looking-at allout-regexp)
2534 (forward-char 1))
2536 (when (re-search-forward allout-line-boundary-regexp nil 0)
2537 (allout-prefix-data)
2538 (goto-char allout-recent-prefix-beginning)
2539 (while (not (bolp))
2540 (forward-char -1))
2541 (and (allout-do-doublecheck)
2542 ;; this will set allout-recent-* on the first non-aberrant topic,
2543 ;; whether it's the current one or one that disqualifies it:
2544 (allout-aberrant-container-p))
2545 ;; this may or may not be the same as above depending on doublecheck:
2546 (goto-char allout-recent-prefix-beginning))))
2547 ;;;_ > allout-this-or-next-heading
2548 (defun allout-this-or-next-heading ()
2549 "Position cursor on current or next heading."
2550 ;; A throwaway non-macro that is defined after allout-next-heading
2551 ;; and usable by allout-mode.
2552 (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
2553 ;;;_ > allout-previous-heading ()
2554 (defun allout-previous-heading ()
2555 "Move to the prior (possibly invisible) heading line.
2557 Return the location of the beginning of the heading, or nil if not found.
2559 We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
2561 (if (bobp)
2563 (let ((start-point (point)))
2564 ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
2565 (allout-goto-prefix)
2566 (save-match-data
2567 (when (or (re-search-backward allout-line-boundary-regexp nil 0)
2568 (looking-at allout-bob-regexp))
2569 (goto-char (allout-prefix-data))
2570 (if (and (allout-do-doublecheck)
2571 (allout-aberrant-container-p))
2572 (or (allout-previous-heading)
2573 (and (goto-char start-point)
2574 ;; recalibrate allout-recent-*:
2575 (allout-depth)
2576 nil))
2577 (point)))))))
2578 ;;;_ > allout-get-invisibility-overlay ()
2579 (defun allout-get-invisibility-overlay ()
2580 "Return the overlay at point that dictates allout invisibility."
2581 (let ((overlays (overlays-at (point)))
2582 got)
2583 (while (and overlays (not got))
2584 (if (equal (overlay-get (car overlays) 'invisible) 'allout)
2585 (setq got (car overlays))
2586 (pop overlays)))
2587 got))
2588 ;;;_ > allout-back-to-visible-text ()
2589 (defun allout-back-to-visible-text ()
2590 "Move to most recent prior character that is visible, and return point."
2591 (if (allout-hidden-p)
2592 (goto-char (overlay-start (allout-get-invisibility-overlay))))
2593 (point))
2595 ;;;_ - Subtree Charting
2596 ;;;_ " These routines either produce or assess charts, which are
2597 ;;; nested lists of the locations of topics within a subtree.
2599 ;;; Charts enable efficient subtree navigation by providing a reusable basis
2600 ;;; for elaborate, compound assessment and adjustment of a subtree.
2602 ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2603 (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth)
2604 "Produce a location \"chart\" of subtopics of the containing topic.
2606 Optional argument LEVELS specifies a depth limit (relative to start
2607 depth) for the chart. Null LEVELS means no limit.
2609 When optional argument VISIBLE is non-nil, the chart includes
2610 only the visible subelements of the charted subjects.
2612 The remaining optional args are for internal use by the function.
2614 Point is left at the end of the subtree.
2616 Charts are used to capture outline structure, so that outline-altering
2617 routines need assess the structure only once, and then use the chart
2618 for their elaborate manipulations.
2620 The chart entries for the topics are in reverse order, so the
2621 last topic is listed first. The entry for each topic consists of
2622 an integer indicating the point at the beginning of the topic
2623 prefix. Charts for offspring consists of a list containing,
2624 recursively, the charts for the respective subtopics. The chart
2625 for a topics' offspring precedes the entry for the topic itself.
2627 The other function parameters are for internal recursion, and should
2628 not be specified by external callers. ORIG-DEPTH is depth of topic at
2629 starting point, and PREV-DEPTH is depth of prior topic."
2631 (let ((original (not orig-depth)) ; `orig-depth' set only in recursion.
2632 chart curr-depth)
2634 (if original ; Just starting?
2635 ; Register initial settings and
2636 ; position to first offspring:
2637 (progn (setq orig-depth (allout-depth))
2638 (or prev-depth (setq prev-depth (1+ orig-depth)))
2639 (if visible
2640 (allout-next-visible-heading 1)
2641 (allout-next-heading))))
2643 ;; Loop over the current levels' siblings. Besides being more
2644 ;; efficient than tail-recursing over a level, it avoids exceeding
2645 ;; the typically quite constrained Emacs max-lisp-eval-depth.
2647 ;; Probably would speed things up to implement loop-based stack
2648 ;; operation rather than recursing for lower levels. Bah.
2650 (while (and (not (eobp))
2651 ; Still within original topic?
2652 (< orig-depth (setq curr-depth allout-recent-depth))
2653 (cond ((= prev-depth curr-depth)
2654 ;; Register this one and move on:
2655 (setq chart (cons allout-recent-prefix-beginning chart))
2656 (if (and levels (<= levels 1))
2657 ;; At depth limit -- skip sublevels:
2658 (or (allout-next-sibling curr-depth)
2659 ;; or no more siblings -- proceed to
2660 ;; next heading at lesser depth:
2661 (while (and (<= curr-depth
2662 allout-recent-depth)
2663 (if visible
2664 (allout-next-visible-heading 1)
2665 (allout-next-heading)))))
2666 (if visible
2667 (allout-next-visible-heading 1)
2668 (allout-next-heading))))
2670 ((and (< prev-depth curr-depth)
2671 (or (not levels)
2672 (> levels 0)))
2673 ;; Recurse on deeper level of curr topic:
2674 (setq chart
2675 (cons (allout-chart-subtree (and levels
2676 (1- levels))
2677 visible
2678 orig-depth
2679 curr-depth)
2680 chart))
2681 ;; ... then continue with this one.
2684 ;; ... else nil if we've ascended back to prev-depth.
2688 (if original ; We're at the last sibling on
2689 ; the original level. Position
2690 ; to the end of it:
2691 (progn (and (not (eobp)) (forward-char -1))
2692 (and (= (preceding-char) ?\n)
2693 (= (aref (buffer-substring (max 1 (- (point) 3))
2694 (point))
2696 ?\n)
2697 (forward-char -1))
2698 (setq allout-recent-end-of-subtree (point))))
2700 chart ; (nreverse chart) not necessary,
2701 ; and maybe not preferable.
2703 ;;;_ > allout-chart-siblings (&optional start end)
2704 (defun allout-chart-siblings (&optional start end)
2705 "Produce a list of locations of this and succeeding sibling topics.
2706 Effectively a top-level chart of siblings. See `allout-chart-subtree'
2707 for an explanation of charts."
2708 (save-excursion
2709 (when (allout-goto-prefix-doublechecked)
2710 (let ((chart (list (point))))
2711 (while (allout-next-sibling)
2712 (setq chart (cons (point) chart)))
2713 (if chart (setq chart (nreverse chart)))))))
2714 ;;;_ > allout-chart-to-reveal (chart depth)
2715 (defun allout-chart-to-reveal (chart depth)
2717 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
2719 If DEPTH is nil, include hidden points at any depth.
2721 Note that point can be left at any of the points on chart, or at the
2722 start point."
2724 (let (result here)
2725 (while (and (or (null depth) (> depth 0))
2726 chart)
2727 (setq here (car chart))
2728 (if (listp here)
2729 (let ((further (allout-chart-to-reveal here (if (null depth)
2730 depth
2731 (1- depth)))))
2732 ;; We're on the start of a subtree -- recurse with it, if there's
2733 ;; more depth to go:
2734 (if further (setq result (append further result)))
2735 (setq chart (cdr chart)))
2736 (goto-char here)
2737 (if (allout-hidden-p)
2738 (setq result (cons here result)))
2739 (setq chart (cdr chart))))
2740 result))
2741 ;;;_ X allout-chart-spec (chart spec &optional exposing)
2742 ;; (defun allout-chart-spec (chart spec &optional exposing)
2743 ;; "Not yet (if ever) implemented.
2745 ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
2747 ;; Exposure spec indicates the locations to be exposed and the prescribed
2748 ;; exposure status. Optional arg EXPOSING is an integer, with 0
2749 ;; indicating pending concealment, anything higher indicating depth to
2750 ;; which subtopic headers should be exposed, and negative numbers
2751 ;; indicating (negative of) the depth to which subtopic headers and
2752 ;; bodies should be exposed.
2754 ;; The produced list can have two types of entries. Bare numbers
2755 ;; indicate points in the buffer where topic headers that should be
2756 ;; exposed reside.
2758 ;; - bare negative numbers indicates that the topic starting at the
2759 ;; point which is the negative of the number should be opened,
2760 ;; including their entries.
2761 ;; - bare positive values indicate that this topic header should be
2762 ;; opened.
2763 ;; - Lists signify the beginning and end points of regions that should
2764 ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
2765 ;; exposure:"
2766 ;; (while spec
2767 ;; (cond ((listp spec)
2768 ;; )
2769 ;; )
2770 ;; (setq spec (cdr spec)))
2771 ;; )
2773 ;;;_ - Within Topic
2774 ;;;_ > allout-goto-prefix ()
2775 (defun allout-goto-prefix ()
2776 "Put point at beginning of immediately containing outline topic.
2778 Goes to most immediate subsequent topic if none immediately containing.
2780 Not sensitive to topic visibility.
2782 Returns the point at the beginning of the prefix, or nil if none."
2784 (save-match-data
2785 (let (done)
2786 (while (and (not done)
2787 (search-backward "\n" nil 1))
2788 (forward-char 1)
2789 (if (looking-at allout-regexp)
2790 (setq done (allout-prefix-data))
2791 (forward-char -1)))
2792 (if (bobp)
2793 (cond ((looking-at allout-regexp)
2794 (allout-prefix-data))
2795 ((allout-next-heading))
2796 (done))
2797 done))))
2798 ;;;_ > allout-goto-prefix-doublechecked ()
2799 (defun allout-goto-prefix-doublechecked ()
2800 "Put point at beginning of immediately containing outline topic.
2802 Like `allout-goto-prefix', but shallow topics (according to
2803 `allout-doublecheck-at-and-shallower') are checked and
2804 disqualified for child containment discontinuity, according to
2805 `allout-aberrant-container-p'."
2806 (if (allout-goto-prefix)
2807 (if (and (allout-do-doublecheck)
2808 (allout-aberrant-container-p))
2809 (allout-previous-heading)
2810 (point))))
2812 ;;;_ > allout-end-of-prefix ()
2813 (defun allout-end-of-prefix (&optional ignore-decorations)
2814 "Position cursor at beginning of header text.
2816 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
2817 otherwise skip white space between bullet and ensuing text."
2819 (if (not (allout-goto-prefix-doublechecked))
2821 (goto-char allout-recent-prefix-end)
2822 (save-match-data
2823 (if ignore-decorations
2825 (while (looking-at "[0-9]") (forward-char 1))
2826 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
2827 ;; Reestablish where we are:
2828 (allout-current-depth)))
2829 ;;;_ > allout-current-bullet-pos ()
2830 (defun allout-current-bullet-pos ()
2831 "Return position of current (visible) topic's bullet."
2833 (if (not (allout-current-depth))
2835 (1- allout-recent-prefix-end)))
2836 ;;;_ > allout-back-to-current-heading (&optional interactive)
2837 (defun allout-back-to-current-heading (&optional interactive)
2838 "Move to heading line of current topic, or beginning if not in a topic.
2840 If interactive, we position at the end of the prefix.
2842 Return value of resulting point, unless we started outside
2843 of (before any) topics, in which case we return nil."
2845 (interactive "p")
2847 (allout-beginning-of-current-line)
2848 (let ((bol-point (point)))
2849 (when (allout-goto-prefix-doublechecked)
2850 (if (<= (point) bol-point)
2851 (progn
2852 (setq bol-point (point))
2853 (allout-beginning-of-current-line)
2854 (if (not (= bol-point (point)))
2855 (if (looking-at allout-regexp)
2856 (allout-prefix-data)))
2857 (if interactive
2858 (allout-end-of-prefix)
2859 (point)))
2860 (goto-char (point-min))
2861 nil))))
2862 ;;;_ > allout-back-to-heading ()
2863 (defalias 'allout-back-to-heading 'allout-back-to-current-heading)
2864 ;;;_ > allout-pre-next-prefix ()
2865 (defun allout-pre-next-prefix ()
2866 "Skip forward to just before the next heading line.
2868 Returns that character position."
2870 (if (allout-next-heading)
2871 (goto-char (1- allout-recent-prefix-beginning))))
2872 ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
2873 (defun allout-end-of-subtree (&optional current include-trailing-blank)
2874 "Put point at the end of the last leaf in the containing topic.
2876 Optional CURRENT means put point at the end of the containing
2877 visible topic.
2879 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2880 any, as part of the subtree. Otherwise, that trailing blank will be
2881 excluded as delimiting whitespace between topics.
2883 Returns the value of point."
2884 (interactive "P")
2885 (if current
2886 (allout-back-to-current-heading)
2887 (allout-goto-prefix-doublechecked))
2888 (let ((level allout-recent-depth))
2889 (allout-next-heading)
2890 (while (and (not (eobp))
2891 (> allout-recent-depth level))
2892 (allout-next-heading))
2893 (if (eobp)
2894 (allout-end-of-entry)
2895 (forward-char -1))
2896 (if (and (not include-trailing-blank) (= ?\n (preceding-char)))
2897 (forward-char -1))
2898 (setq allout-recent-end-of-subtree (point))))
2899 ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
2900 (defun allout-end-of-current-subtree (&optional include-trailing-blank)
2902 "Put point at end of last leaf in currently visible containing topic.
2904 Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
2905 any, as part of the subtree. Otherwise, that trailing blank will be
2906 excluded as delimiting whitespace between topics.
2908 Returns the value of point."
2909 (interactive)
2910 (allout-end-of-subtree t include-trailing-blank))
2911 ;;;_ > allout-beginning-of-current-entry (&optional interactive)
2912 (defun allout-beginning-of-current-entry (&optional interactive)
2913 "When not already there, position point at beginning of current topic header.
2915 If already there, move cursor to bullet for hot-spot operation.
2916 \(See `allout-mode' doc string for details of hot-spot operation.)"
2917 (interactive "p")
2918 (let ((start-point (point)))
2919 (move-beginning-of-line 1)
2920 (if (< 0 (allout-current-depth))
2921 (goto-char allout-recent-prefix-end)
2922 (goto-char (point-min)))
2923 (allout-end-of-prefix)
2924 (if (and interactive
2925 (= (point) start-point))
2926 (goto-char (allout-current-bullet-pos)))))
2927 ;;;_ > allout-end-of-entry (&optional inclusive)
2928 (defun allout-end-of-entry (&optional inclusive)
2929 "Position the point at the end of the current topics' entry.
2931 Optional INCLUSIVE means also include trailing empty line, if any. When
2932 unset, whitespace between items separates them even when the items are
2933 collapsed."
2934 (interactive)
2935 (allout-pre-next-prefix)
2936 (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char)))
2937 (forward-char -1))
2938 (point))
2939 ;;;_ > allout-end-of-current-heading ()
2940 (defun allout-end-of-current-heading ()
2941 (interactive)
2942 (allout-beginning-of-current-entry)
2943 (search-forward "\n" nil t)
2944 (forward-char -1))
2945 (defalias 'allout-end-of-heading 'allout-end-of-current-heading)
2946 ;;;_ > allout-get-body-text ()
2947 (defun allout-get-body-text ()
2948 "Return the unmangled body text of the topic immediately containing point."
2949 (save-excursion
2950 (allout-end-of-prefix)
2951 (if (not (search-forward "\n" nil t))
2953 (backward-char 1)
2954 (let ((pre-body (point)))
2955 (if (not pre-body)
2957 (allout-end-of-entry t)
2958 (if (not (= pre-body (point)))
2959 (buffer-substring-no-properties (1+ pre-body) (point))))
2965 ;;;_ - Depth-wise
2966 ;;;_ > allout-ascend-to-depth (depth)
2967 (defun allout-ascend-to-depth (depth)
2968 "Ascend to depth DEPTH, returning depth if successful, nil if not."
2969 (if (and (> depth 0)(<= depth (allout-depth)))
2970 (let (last-ascended)
2971 (while (and (< depth allout-recent-depth)
2972 (setq last-ascended (allout-ascend))))
2973 (goto-char allout-recent-prefix-beginning)
2974 (if (allout-called-interactively-p) (allout-end-of-prefix))
2975 (and last-ascended allout-recent-depth))))
2976 ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
2977 (defun allout-ascend (&optional dont-move-if-unsuccessful)
2978 "Ascend one level, returning resulting depth if successful, nil if not.
2980 Point is left at the beginning of the level whether or not
2981 successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
2982 which case point is returned to its original starting location."
2983 (if dont-move-if-unsuccessful
2984 (setq dont-move-if-unsuccessful (point)))
2985 (prog1
2986 (if (allout-beginning-of-level)
2987 (let ((bolevel (point))
2988 (bolevel-depth allout-recent-depth))
2989 (allout-previous-heading)
2990 (cond ((< allout-recent-depth bolevel-depth)
2991 allout-recent-depth)
2992 ((= allout-recent-depth bolevel-depth)
2993 (if dont-move-if-unsuccessful
2994 (goto-char dont-move-if-unsuccessful))
2995 (allout-depth)
2996 nil)
2998 ;; some topic after very first is lower depth than first:
2999 (goto-char bolevel)
3000 (allout-depth)
3001 nil))))
3002 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3003 ;;;_ > allout-descend-to-depth (depth)
3004 (defun allout-descend-to-depth (depth)
3005 "Descend to depth DEPTH within current topic.
3007 Returning depth if successful, nil if not."
3008 (let ((start-point (point))
3009 (start-depth (allout-depth)))
3010 (while
3011 (and (> (allout-depth) 0)
3012 (not (= depth allout-recent-depth)) ; ... not there yet
3013 (allout-next-heading) ; ... go further
3014 (< start-depth allout-recent-depth))) ; ... still in topic
3015 (if (and (> (allout-depth) 0)
3016 (= allout-recent-depth depth))
3017 depth
3018 (goto-char start-point)
3019 nil))
3021 ;;;_ > allout-up-current-level (arg)
3022 (defun allout-up-current-level (arg)
3023 "Move out ARG levels from current visible topic."
3024 (interactive "p")
3025 (let ((start-point (point)))
3026 (allout-back-to-current-heading)
3027 (if (not (allout-ascend))
3028 (progn (goto-char start-point)
3029 (error "Can't ascend past outermost level"))
3030 (if (allout-called-interactively-p) (allout-end-of-prefix))
3031 allout-recent-prefix-beginning)))
3033 ;;;_ - Linear
3034 ;;;_ > allout-next-sibling (&optional depth backward)
3035 (defun allout-next-sibling (&optional depth backward)
3036 "Like `allout-forward-current-level', but respects invisible topics.
3038 Traverse at optional DEPTH, or current depth if none specified.
3040 Go backward if optional arg BACKWARD is non-nil.
3042 Return the start point of the new topic if successful, nil otherwise."
3044 (if (if backward (bobp) (eobp))
3046 (let ((target-depth (or depth (allout-depth)))
3047 (start-point (point))
3048 (start-prefix-beginning allout-recent-prefix-beginning)
3049 (count 0)
3050 leaping
3051 last-depth)
3052 (while (and
3053 ;; done too few single steps to resort to the leap routine:
3054 (not leaping)
3055 ;; not at limit:
3056 (not (if backward (bobp) (eobp)))
3057 ;; still traversable:
3058 (if backward (allout-previous-heading) (allout-next-heading))
3059 ;; we're below the target depth
3060 (> (setq last-depth allout-recent-depth) target-depth))
3061 (setq count (1+ count))
3062 (if (> count 7) ; lists are commonly 7 +- 2, right?-)
3063 (setq leaping t)))
3064 (cond (leaping
3065 (or (allout-next-sibling-leap target-depth backward)
3066 (progn
3067 (goto-char start-point)
3068 (if depth (allout-depth) target-depth)
3069 nil)))
3070 ((and (not (eobp))
3071 (and (> (or last-depth (allout-depth)) 0)
3072 (= allout-recent-depth target-depth))
3073 (not (= start-prefix-beginning
3074 allout-recent-prefix-beginning)))
3075 allout-recent-prefix-beginning)
3077 (goto-char start-point)
3078 (if depth (allout-depth) target-depth)
3079 nil)))))
3080 ;;;_ > allout-next-sibling-leap (&optional depth backward)
3081 (defun allout-next-sibling-leap (&optional depth backward)
3082 "Like `allout-next-sibling', but by direct search for topic at depth.
3084 Traverse at optional DEPTH, or current depth if none specified.
3086 Go backward if optional arg BACKWARD is non-nil.
3088 Return the start point of the new topic if successful, nil otherwise.
3090 Costs more than regular `allout-next-sibling' for short traversals:
3092 - we have to check the prior (next, if travelling backwards)
3093 item to confirm connectivity with the prior topic, and
3094 - if confirmed, we have to reestablish the allout-recent-* settings with
3095 some extra navigation
3096 - if confirmation fails, we have to do more work to recover
3098 It is an increasingly big win when there are many intervening
3099 offspring before the next sibling, however, so
3100 `allout-next-sibling' resorts to this if it finds itself in that
3101 situation."
3103 (if (if backward (bobp) (eobp))
3105 (let* ((start-point (point))
3106 (target-depth (or depth (allout-depth)))
3107 (search-whitespace-regexp nil)
3108 (depth-biased (- target-depth 2))
3109 (expression (if (<= target-depth 1)
3110 allout-depth-one-regexp
3111 (format allout-depth-specific-regexp
3112 depth-biased depth-biased)))
3113 found
3114 done)
3115 (while (not done)
3116 (setq found (save-match-data
3117 (if backward
3118 (re-search-backward expression nil 'to-limit)
3119 (forward-char 1)
3120 (re-search-forward expression nil 'to-limit))))
3121 (if (and found (allout-aberrant-container-p))
3122 (setq found nil))
3123 (setq done (or found (if backward (bobp) (eobp)))))
3124 (if (not found)
3125 (progn (goto-char start-point)
3126 nil)
3127 ;; rationale: if any intervening items were at a lower depth, we
3128 ;; would now be on the first offspring at the target depth -- ie,
3129 ;; the preceding item (per the search direction) must be at a
3130 ;; lesser depth. that's all we need to check.
3131 (if backward (allout-next-heading) (allout-previous-heading))
3132 (if (< allout-recent-depth target-depth)
3133 ;; return to start and reestablish allout-recent-*:
3134 (progn
3135 (goto-char start-point)
3136 (allout-depth)
3137 nil)
3138 (goto-char found)
3139 ;; locate cursor and set allout-recent-*:
3140 (allout-goto-prefix))))))
3141 ;;;_ > allout-previous-sibling (&optional depth backward)
3142 (defun allout-previous-sibling (&optional depth backward)
3143 "Like `allout-forward-current-level' backwards, respecting invisible topics.
3145 Optional DEPTH specifies depth to traverse, default current depth.
3147 Optional BACKWARD reverses direction.
3149 Return depth if successful, nil otherwise."
3150 (allout-next-sibling depth (not backward))
3152 ;;;_ > allout-snug-back ()
3153 (defun allout-snug-back ()
3154 "Position cursor at end of previous topic.
3156 Presumes point is at the start of a topic prefix."
3157 (if (or (bobp) (eobp))
3159 (forward-char -1))
3160 (if (or (bobp) (not (= ?\n (preceding-char))))
3162 (forward-char -1))
3163 (point))
3164 ;;;_ > allout-beginning-of-level ()
3165 (defun allout-beginning-of-level ()
3166 "Go back to the first sibling at this level, visible or not."
3167 (allout-end-of-level 'backward))
3168 ;;;_ > allout-end-of-level (&optional backward)
3169 (defun allout-end-of-level (&optional backward)
3170 "Go to the last sibling at this level, visible or not."
3172 (let ((depth (allout-depth)))
3173 (while (allout-previous-sibling depth nil))
3174 (prog1 allout-recent-depth
3175 (if (allout-called-interactively-p) (allout-end-of-prefix)))))
3176 ;;;_ > allout-next-visible-heading (arg)
3177 (defun allout-next-visible-heading (arg)
3178 "Move to the next ARG'th visible heading line, backward if arg is negative.
3180 Move to buffer limit in indicated direction if headings are exhausted."
3182 (interactive "p")
3183 (let* ((inhibit-field-text-motion t)
3184 (backward (if (< arg 0) (setq arg (* -1 arg))))
3185 (step (if backward -1 1))
3186 (progress (allout-current-bullet-pos))
3187 prev got)
3189 (while (> arg 0)
3190 (while (and
3191 ;; Boundary condition:
3192 (not (if backward (bobp)(eobp)))
3193 ;; Move, skipping over all concealed lines in one fell swoop:
3194 (prog1 (condition-case nil (or (line-move step) t)
3195 (error nil))
3196 (allout-beginning-of-current-line)
3197 ;; line-move can wind up on the same line if long.
3198 ;; when moving forward, that would yield no-progress
3199 (when (and (not backward)
3200 (<= (point) progress))
3201 ;; ensure progress by doing line-move from end-of-line:
3202 (end-of-line)
3203 (condition-case nil (or (line-move step) t)
3204 (error nil))
3205 (allout-beginning-of-current-line)
3206 (setq progress (point))))
3207 ;; Deal with apparent header line:
3208 (save-match-data
3209 (if (not (looking-at allout-regexp))
3210 ;; not a header line, keep looking:
3212 (allout-prefix-data)
3213 (if (and (allout-do-doublecheck)
3214 (allout-aberrant-container-p))
3215 ;; skip this aberrant prospective header line:
3217 ;; this prospective headerline qualifies -- register:
3218 (setq got allout-recent-prefix-beginning)
3219 ;; and break the loop:
3220 nil)))))
3221 ;; Register this got, it may be the last:
3222 (if got (setq prev got))
3223 (setq arg (1- arg)))
3224 (cond (got ; Last move was to a prefix:
3225 (allout-end-of-prefix))
3226 (prev ; Last move wasn't, but prev was:
3227 (goto-char prev)
3228 (allout-end-of-prefix))
3229 ((not backward) (end-of-line) nil))))
3230 ;;;_ > allout-previous-visible-heading (arg)
3231 (defun allout-previous-visible-heading (arg)
3232 "Move to the previous heading line.
3234 With argument, repeats or can move forward if negative.
3235 A heading line is one that starts with a `*' (or that `allout-regexp'
3236 matches)."
3237 (interactive "p")
3238 (prog1 (allout-next-visible-heading (- arg))
3239 (if (allout-called-interactively-p) (allout-end-of-prefix))))
3240 ;;;_ > allout-forward-current-level (arg)
3241 (defun allout-forward-current-level (arg)
3242 "Position point at the next heading of the same level.
3244 Takes optional repeat-count, goes backward if count is negative.
3246 Returns resulting position, else nil if none found."
3247 (interactive "p")
3248 (let ((start-depth (allout-current-depth))
3249 (start-arg arg)
3250 (backward (> 0 arg)))
3251 (if (= 0 start-depth)
3252 (error "No siblings, not in a topic..."))
3253 (if backward (setq arg (* -1 arg)))
3254 (allout-back-to-current-heading)
3255 (while (and (not (zerop arg))
3256 (if backward
3257 (allout-previous-sibling)
3258 (allout-next-sibling)))
3259 (setq arg (1- arg)))
3260 (if (not (allout-called-interactively-p))
3262 (allout-end-of-prefix)
3263 (if (not (zerop arg))
3264 (error "Hit %s level %d topic, traversed %d of %d requested"
3265 (if backward "first" "last")
3266 allout-recent-depth
3267 (- (abs start-arg) arg)
3268 (abs start-arg))))))
3269 ;;;_ > allout-backward-current-level (arg)
3270 (defun allout-backward-current-level (arg)
3271 "Inverse of `allout-forward-current-level'."
3272 (interactive "p")
3273 (if (allout-called-interactively-p)
3274 (let ((current-prefix-arg (* -1 arg)))
3275 (call-interactively 'allout-forward-current-level))
3276 (allout-forward-current-level (* -1 arg))))
3278 ;;;_ #5 Alteration
3280 ;;;_ - Fundamental
3281 ;;;_ = allout-post-goto-bullet
3282 (defvar allout-post-goto-bullet nil
3283 "Outline internal var, for `allout-pre-command-business' hot-spot operation.
3285 When set, tells post-processing to reposition on topic bullet, and
3286 then unset it. Set by `allout-pre-command-business' when implementing
3287 hot-spot operation, where literal characters typed over a topic bullet
3288 are mapped to the command of the corresponding control-key on the
3289 `allout-mode-map-value'.")
3290 (make-variable-buffer-local 'allout-post-goto-bullet)
3291 ;;;_ = allout-command-counter
3292 (defvar allout-command-counter 0
3293 "Counter that monotonically increases in allout-mode buffers.
3295 Set by `allout-pre-command-business', to support allout addons in
3296 coordinating with allout activity.")
3297 (make-variable-buffer-local 'allout-command-counter)
3298 ;;;_ > allout-post-command-business ()
3299 (defun allout-post-command-business ()
3300 "Outline `post-command-hook' function.
3302 - Implement (and clear) `allout-post-goto-bullet', for hot-spot
3303 outline commands.
3305 - Decrypt topic currently being edited if it was encrypted for a save."
3307 ; Apply any external change func:
3308 (if (not (allout-mode-p)) ; In allout-mode.
3311 (if (and (boundp 'allout-after-save-decrypt)
3312 allout-after-save-decrypt)
3313 (allout-after-saves-handler))
3315 ;; Implement allout-post-goto-bullet, if set:
3316 (if (and allout-post-goto-bullet
3317 (allout-current-bullet-pos))
3318 (progn (goto-char (allout-current-bullet-pos))
3319 (setq allout-post-goto-bullet nil)))
3321 ;;;_ > allout-pre-command-business ()
3322 (defun allout-pre-command-business ()
3323 "Outline `pre-command-hook' function for outline buffers.
3325 Among other things, implements special behavior when the cursor is on the
3326 topic bullet character.
3328 When the cursor is on the bullet character, self-insert
3329 characters are reinterpreted as the corresponding
3330 control-character in the `allout-mode-map-value'. The
3331 `allout-mode' `post-command-hook' insures that the cursor which
3332 has moved as a result of such reinterpretation is positioned on
3333 the bullet character of the destination topic.
3335 The upshot is that you can get easy, single (ie, unmodified) key
3336 outline maneuvering operations by positioning the cursor on the bullet
3337 char. When in this mode you can use regular cursor-positioning
3338 command/keystrokes to relocate the cursor off of a bullet character to
3339 return to regular interpretation of self-insert characters."
3341 (if (not (allout-mode-p))
3343 ;; Increment allout-command-counter
3344 (setq allout-command-counter (1+ allout-command-counter))
3345 ;; Do hot-spot navigation.
3346 (if (and (eq this-command 'self-insert-command)
3347 (eq (point)(allout-current-bullet-pos)))
3348 (allout-hotspot-key-handler))))
3349 ;;;_ > allout-hotspot-key-handler ()
3350 (defun allout-hotspot-key-handler ()
3351 "Catchall handling of key bindings in hot-spots.
3353 Translates unmodified keystrokes to corresponding allout commands, when
3354 they would qualify if prefixed with the allout-command-prefix, and sets
3355 this-command accordingly.
3357 Returns the qualifying command, if any, else nil."
3358 (interactive)
3359 (let* ((modified (event-modifiers last-command-event))
3360 (key-num (cond ((numberp last-command-event) last-command-event)
3361 ;; for XEmacs character type:
3362 ((and (fboundp 'characterp)
3363 (apply 'characterp (list last-command-event)))
3364 (apply 'char-to-int (list last-command-event)))
3365 (t 0)))
3366 mapped-binding)
3368 (if (zerop key-num)
3371 (if (and
3372 ;; exclude control chars and escape:
3373 (not modified)
3374 (<= 33 key-num)
3375 (setq mapped-binding
3377 ;; try control-modified versions of keys:
3378 (key-binding (vconcat allout-command-prefix
3379 (vector
3380 (if (and (<= 97 key-num) ; "a"
3381 (>= 122 key-num)) ; "z"
3382 (- key-num 96) key-num)))
3384 ;; try non-modified versions of keys:
3385 (key-binding (vconcat allout-command-prefix
3386 (vector key-num))
3387 t))))
3388 ;; Qualified as an allout command -- do hot-spot operation.
3389 (setq allout-post-goto-bullet t)
3390 ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
3391 (setq mapped-binding (key-binding (vector key-num))))
3393 (while (keymapp mapped-binding)
3394 (setq mapped-binding
3395 (lookup-key mapped-binding (vector (read-char)))))
3397 (when mapped-binding
3398 (setq this-command mapped-binding)))))
3400 ;;;_ > allout-find-file-hook ()
3401 (defun allout-find-file-hook ()
3402 "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
3404 See `allout-auto-activation' for setup instructions."
3405 (if (and allout-auto-activation
3406 (not (allout-mode-p))
3407 allout-layout)
3408 (allout-mode)))
3410 ;;;_ - Topic Format Assessment
3411 ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
3412 (defun allout-solicit-alternate-bullet (depth &optional current-bullet)
3414 "Prompt for and return a bullet char as an alternative to the current one.
3416 Offer one suitable for current depth DEPTH as default."
3418 (let* ((default-bullet (or (and (stringp current-bullet) current-bullet)
3419 (allout-bullet-for-depth depth)))
3420 (sans-escapes (regexp-sans-escapes allout-bullets-string))
3421 choice)
3422 (save-excursion
3423 (goto-char (allout-current-bullet-pos))
3424 (setq choice (solicit-char-in-string
3425 (format "Select bullet: %s ('%s' default): "
3426 sans-escapes
3427 (allout-substring-no-properties default-bullet))
3428 sans-escapes
3429 t)))
3430 (message "")
3431 (if (string= choice "") default-bullet choice))
3433 ;;;_ > allout-distinctive-bullet (bullet)
3434 (defun allout-distinctive-bullet (bullet)
3435 "True if BULLET is one of those on `allout-distinctive-bullets-string'."
3436 (string-match (regexp-quote bullet) allout-distinctive-bullets-string))
3437 ;;;_ > allout-numbered-type-prefix (&optional prefix)
3438 (defun allout-numbered-type-prefix (&optional prefix)
3439 "True if current header prefix bullet is numbered bullet."
3440 (and allout-numbered-bullet
3441 (string= allout-numbered-bullet
3442 (if prefix
3443 (allout-get-prefix-bullet prefix)
3444 (allout-get-bullet)))))
3445 ;;;_ > allout-encrypted-type-prefix (&optional prefix)
3446 (defun allout-encrypted-type-prefix (&optional prefix)
3447 "True if current header prefix bullet is for an encrypted entry (body)."
3448 (and allout-topic-encryption-bullet
3449 (string= allout-topic-encryption-bullet
3450 (if prefix
3451 (allout-get-prefix-bullet prefix)
3452 (allout-get-bullet)))))
3453 ;;;_ > allout-bullet-for-depth (&optional depth)
3454 (defun allout-bullet-for-depth (&optional depth)
3455 "Return outline topic bullet suited to optional DEPTH, or current depth."
3456 ;; Find bullet in plain-bullets-string modulo DEPTH.
3457 (if allout-stylish-prefixes
3458 (char-to-string (aref allout-plain-bullets-string
3459 (% (max 0 (- depth 2))
3460 allout-plain-bullets-string-len)))
3461 allout-primary-bullet)
3464 ;;;_ - Topic Production
3465 ;;;_ > allout-make-topic-prefix (&optional prior-bullet
3466 (defun allout-make-topic-prefix (&optional prior-bullet
3468 depth
3469 instead
3470 number-control
3471 index)
3472 ;; Depth null means use current depth, non-null means we're either
3473 ;; opening a new topic after current topic, lower or higher, or we're
3474 ;; changing level of current topic.
3475 ;; Instead dominates specified bullet-char.
3476 ;;;_ . Doc string:
3477 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
3479 All the arguments are optional.
3481 PRIOR-BULLET indicates the bullet of the prefix being changed, or
3482 nil if none. This bullet may be preserved (other options
3483 notwithstanding) if it is on the `allout-distinctive-bullets-string',
3484 for instance.
3486 Second arg NEW indicates that a new topic is being opened after the
3487 topic at point, if non-nil. Default bullet for new topics, eg, may
3488 be set (contingent to other args) to numbered bullets if previous
3489 sibling is one. The implication otherwise is that the current topic
3490 is being adjusted -- shifted or rebulleted -- and we don't consider
3491 bullet or previous sibling.
3493 Third arg DEPTH forces the topic prefix to that depth, regardless of
3494 the current topics' depth.
3496 If INSTEAD is:
3498 - nil, then the bullet char for the context is used, per distinction or depth
3499 - a \(numeric) character, then character's string representation is used
3500 - a string, then the user is asked for bullet with the first char as default
3501 - anything else, the user is solicited with bullet char per context as default
3503 \(INSTEAD overrides other options, including, eg, a distinctive
3504 PRIOR-BULLET.)
3506 Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
3507 is non-nil *and* no specific INSTEAD was specified. Then
3508 NUMBER-CONTROL non-nil forces prefix to either numbered or
3509 denumbered format, depending on the value of the sixth arg, INDEX.
3511 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
3513 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
3514 the prefix of the topic is forced to be numbered. Non-nil
3515 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
3516 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
3517 that the index for the numbered prefix will be derived, by counting
3518 siblings back to start of level. If INDEX is a number, then that
3519 number is used as the index for the numbered prefix (allowing, eg,
3520 sequential renumbering to not require this function counting back the
3521 index for each successive sibling)."
3522 ;;;_ . Code:
3523 ;; The options are ordered in likely frequence of use, most common
3524 ;; highest, least lowest. Ie, more likely to be doing prefix
3525 ;; adjustments than soliciting, and yet more than numbering.
3526 ;; Current prefix is least dominant, but most likely to be commonly
3527 ;; specified...
3529 (let* (body
3530 numbering
3531 denumbering
3532 (depth (or depth (allout-depth)))
3533 (header-lead allout-header-prefix)
3534 (bullet-char
3536 ;; Getting value for bullet char is practically the whole job:
3538 (cond
3539 ; Simplest situation -- level 1:
3540 ((<= depth 1) (setq header-lead "") allout-primary-bullet)
3541 ; Simple, too: all asterisks:
3542 (allout-old-style-prefixes
3543 ;; Cheat -- make body the whole thing, null out header-lead and
3544 ;; bullet-char:
3545 (setq body (make-string depth
3546 (string-to-char allout-primary-bullet)))
3547 (setq header-lead "")
3550 ;; (Neither level 1 nor old-style, so we're space padding.
3551 ;; Sneak it in the condition of the next case, whatever it is.)
3553 ;; Solicitation overrides numbering and other cases:
3554 ((progn (setq body (make-string (- depth 2) ?\ ))
3555 ;; The actual condition:
3556 instead)
3557 (let ((got (cond ((stringp instead)
3558 (if (> (length instead) 0)
3559 (allout-solicit-alternate-bullet
3560 depth (substring instead 0 1))))
3561 ((characterp instead) (char-to-string instead))
3562 (t (allout-solicit-alternate-bullet depth)))))
3563 ;; Gotta check whether we're numbering and got a numbered bullet:
3564 (setq numbering (and allout-numbered-bullet
3565 (not (and number-control (not index)))
3566 (string= got allout-numbered-bullet)))
3567 ;; Now return what we got, regardless:
3568 got))
3570 ;; Numbering invoked through args:
3571 ((and allout-numbered-bullet number-control)
3572 (if (setq numbering (not (setq denumbering (not index))))
3573 allout-numbered-bullet
3574 (if (and prior-bullet
3575 (not (string= allout-numbered-bullet
3576 prior-bullet)))
3577 prior-bullet
3578 (allout-bullet-for-depth depth))))
3580 ;;; Neither soliciting nor controlled numbering ;;;
3581 ;;; (may be controlled denumbering, tho) ;;;
3583 ;; Check wrt previous sibling:
3584 ((and new ; only check for new prefixes
3585 (<= depth (allout-depth))
3586 allout-numbered-bullet ; ... & numbering enabled
3587 (not denumbering)
3588 (let ((sibling-bullet
3589 (save-excursion
3590 ;; Locate correct sibling:
3591 (or (>= depth (allout-depth))
3592 (allout-ascend-to-depth depth))
3593 (allout-get-bullet))))
3594 (if (and sibling-bullet
3595 (string= allout-numbered-bullet sibling-bullet))
3596 (setq numbering sibling-bullet)))))
3598 ;; Distinctive prior bullet?
3599 ((and prior-bullet
3600 (allout-distinctive-bullet prior-bullet)
3601 ;; Either non-numbered:
3602 (or (not (and allout-numbered-bullet
3603 (string= prior-bullet allout-numbered-bullet)))
3604 ;; or numbered, and not denumbering:
3605 (setq numbering (not denumbering)))
3606 ;; Here 'tis:
3607 prior-bullet))
3609 ;; Else, standard bullet per depth:
3610 ((allout-bullet-for-depth depth)))))
3612 (concat header-lead
3613 body
3614 bullet-char
3615 (if numbering
3616 (format "%d" (cond ((and index (numberp index)) index)
3617 (new (1+ (allout-sibling-index depth)))
3618 ((allout-sibling-index))))))
3621 ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
3622 (defun allout-open-topic (relative-depth &optional before offer-recent-bullet)
3623 "Open a new topic at depth DEPTH.
3625 New topic is situated after current one, unless optional flag BEFORE
3626 is non-nil, or unless current line is completely empty -- lacking even
3627 whitespace -- in which case open is done on the current line.
3629 When adding an offspring, it will be added immediately after the parent if
3630 the other offspring are exposed, or after the last child if the offspring
3631 are hidden. (The intervening offspring will be exposed in the latter
3632 case.)
3634 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
3636 Nuances:
3638 - Creation of new topics is with respect to the visible topic
3639 containing the cursor, regardless of intervening concealed ones.
3641 - New headers are generally created after/before the body of a
3642 topic. However, they are created right at cursor location if the
3643 cursor is on a blank line, even if that breaks the current topic
3644 body. This is intentional, to provide a simple means for
3645 deliberately dividing topic bodies.
3647 - Double spacing of topic lists is preserved. Also, the first
3648 level two topic is created double-spaced (and so would be
3649 subsequent siblings, if that's left intact). Otherwise,
3650 single-spacing is used.
3652 - Creation of sibling or nested topics is with respect to the topic
3653 you're starting from, even when creating backwards. This way you
3654 can easily create a sibling in front of the current topic without
3655 having to go to its preceding sibling, and then open forward
3656 from there."
3658 (allout-beginning-of-current-line)
3659 (save-match-data
3660 (let* ((inhibit-field-text-motion t)
3661 (depth (+ (allout-current-depth) relative-depth))
3662 (opening-on-blank (if (looking-at "^\$")
3663 (not (setq before nil))))
3664 ;; bunch o vars set while computing ref-topic
3665 opening-numbered
3666 ref-depth
3667 ref-bullet
3668 (ref-topic (save-excursion
3669 (cond ((< relative-depth 0)
3670 (allout-ascend-to-depth depth))
3671 ((>= relative-depth 1) nil)
3672 (t (allout-back-to-current-heading)))
3673 (setq ref-depth allout-recent-depth)
3674 (setq ref-bullet
3675 (if (> allout-recent-prefix-end 1)
3676 (allout-recent-bullet)
3677 ""))
3678 (setq opening-numbered
3679 (save-excursion
3680 (and allout-numbered-bullet
3681 (or (<= relative-depth 0)
3682 (allout-descend-to-depth depth))
3683 (if (allout-numbered-type-prefix)
3684 allout-numbered-bullet))))
3685 (point)))
3686 dbl-space
3687 doing-beginning
3688 start end)
3690 (if (not opening-on-blank)
3691 ; Positioning and vertical
3692 ; padding -- only if not
3693 ; opening-on-blank:
3694 (progn
3695 (goto-char ref-topic)
3696 (setq dbl-space ; Determine double space action:
3697 (or (and (<= relative-depth 0) ; not descending;
3698 (save-excursion
3699 ;; at b-o-b or preceded by a blank line?
3700 (or (> 0 (forward-line -1))
3701 (looking-at "^\\s-*$")
3702 (bobp)))
3703 (save-excursion
3704 ;; succeeded by a blank line?
3705 (allout-end-of-current-subtree)
3706 (looking-at "\n\n")))
3707 (and (= ref-depth 1)
3708 (or before
3709 (= depth 1)
3710 (save-excursion
3711 ;; Don't already have following
3712 ;; vertical padding:
3713 (not (allout-pre-next-prefix)))))))
3715 ;; Position to prior heading, if inserting backwards, and not
3716 ;; going outwards:
3717 (if (and before (>= relative-depth 0))
3718 (progn (allout-back-to-current-heading)
3719 (setq doing-beginning (bobp))
3720 (if (not (bobp))
3721 (allout-previous-heading)))
3722 (if (and before (bobp))
3723 (open-line 1)))
3725 (if (<= relative-depth 0)
3726 ;; Not going inwards, don't snug up:
3727 (if doing-beginning
3728 (if (not dbl-space)
3729 (open-line 1)
3730 (open-line 2))
3731 (if before
3732 (progn (end-of-line)
3733 (allout-pre-next-prefix)
3734 (while (and (= ?\n (following-char))
3735 (save-excursion
3736 (forward-char 1)
3737 (allout-hidden-p)))
3738 (forward-char 1))
3739 (if (not (looking-at "^$"))
3740 (open-line 1)))
3741 (allout-end-of-current-subtree)
3742 (if (looking-at "\n\n") (forward-char 1))))
3743 ;; Going inwards -- double-space if first offspring is
3744 ;; double-spaced, otherwise snug up.
3745 (allout-end-of-entry)
3746 (if (eobp)
3747 (newline 1)
3748 (line-move 1))
3749 (allout-beginning-of-current-line)
3750 (backward-char 1)
3751 (if (bolp)
3752 ;; Blank lines between current header body and next
3753 ;; header -- get to last substantive (non-white-space)
3754 ;; line in body:
3755 (progn (setq dbl-space t)
3756 (re-search-backward "[^ \t\n]" nil t)))
3757 (if (looking-at "\n\n")
3758 (setq dbl-space t))
3759 (if (save-excursion
3760 (allout-next-heading)
3761 (when (> allout-recent-depth ref-depth)
3762 ;; This is an offspring.
3763 (forward-line -1)
3764 (looking-at "^\\s-*$")))
3765 (progn (forward-line 1)
3766 (open-line 1)
3767 (forward-line 1)))
3768 (allout-end-of-current-line))
3770 ;;(if doing-beginning (goto-char doing-beginning))
3771 (if (not (bobp))
3772 ;; We insert a newline char rather than using open-line to
3773 ;; avoid rear-stickiness inheritence of read-only property.
3774 (progn (if (and (not (> depth ref-depth))
3775 (not before))
3776 (open-line 1)
3777 (if (and (not dbl-space) (> depth ref-depth))
3778 (newline 1)
3779 (if dbl-space
3780 (open-line 1)
3781 (if (not before)
3782 (newline 1)))))
3783 (if (and dbl-space (not (> relative-depth 0)))
3784 (newline 1))
3785 (if (and (not (eobp))
3786 (or (not (bolp))
3787 (and (not (bobp))
3788 ;; bolp doesnt detect concealed
3789 ;; trailing newlines, compensate:
3790 (save-excursion
3791 (forward-char -1)
3792 (allout-hidden-p)))))
3793 (forward-char 1))))
3795 (setq start (point))
3796 (insert (concat (allout-make-topic-prefix opening-numbered t depth)
3797 " "))
3798 (setq end (1+ (point)))
3800 (allout-rebullet-heading (and offer-recent-bullet ref-bullet)
3801 depth nil nil t)
3802 (if (> relative-depth 0)
3803 (save-excursion (goto-char ref-topic)
3804 (allout-show-children)))
3805 (end-of-line)
3807 (run-hook-with-args 'allout-structure-added-hook start end)
3811 ;;;_ > allout-open-subtopic (arg)
3812 (defun allout-open-subtopic (arg)
3813 "Open new topic header at deeper level than the current one.
3815 Negative universal arg means to open deeper, but place the new topic
3816 prior to the current one."
3817 (interactive "p")
3818 (allout-open-topic 1 (> 0 arg) (< 1 arg)))
3819 ;;;_ > allout-open-sibtopic (arg)
3820 (defun allout-open-sibtopic (arg)
3821 "Open new topic header at same level as the current one.
3823 Positive universal arg means to use the bullet of the prior sibling.
3825 Negative universal arg means to place the new topic prior to the current
3826 one."
3827 (interactive "p")
3828 (allout-open-topic 0 (> 0 arg) (not (= 1 arg))))
3829 ;;;_ > allout-open-supertopic (arg)
3830 (defun allout-open-supertopic (arg)
3831 "Open new topic header at shallower level than the current one.
3833 Negative universal arg means to open shallower, but place the new
3834 topic prior to the current one."
3836 (interactive "p")
3837 (allout-open-topic -1 (> 0 arg) (< 1 arg)))
3839 ;;;_ - Outline Alteration
3840 ;;;_ : Topic Modification
3841 ;;;_ = allout-former-auto-filler
3842 (defvar allout-former-auto-filler nil
3843 "Name of modal fill function being wrapped by `allout-auto-fill'.")
3844 ;;;_ > allout-auto-fill ()
3845 (defun allout-auto-fill ()
3846 "`allout-mode' autofill function.
3848 Maintains outline hanging topic indentation if
3849 `allout-use-hanging-indents' is set."
3851 (when (not allout-inhibit-auto-fill)
3852 (let ((fill-prefix (if allout-use-hanging-indents
3853 ;; Check for topic header indentation:
3854 (save-match-data
3855 (save-excursion
3856 (beginning-of-line)
3857 (if (looking-at allout-regexp)
3858 ;; ... construct indentation to account for
3859 ;; length of topic prefix:
3860 (make-string (progn (allout-end-of-prefix)
3861 (current-column))
3862 ?\ ))))))
3863 (use-auto-fill-function
3864 (if (and (eq allout-outside-normal-auto-fill-function
3865 'allout-auto-fill)
3866 (eq auto-fill-function 'allout-auto-fill))
3867 'do-auto-fill
3868 (or allout-outside-normal-auto-fill-function
3869 auto-fill-function))))
3870 (if (or allout-former-auto-filler allout-use-hanging-indents)
3871 (funcall use-auto-fill-function)))))
3872 ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
3873 (defun allout-reindent-body (old-depth new-depth &optional number)
3874 "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
3876 Optional arg NUMBER indicates numbering is being added, and it must
3877 be accommodated.
3879 Note that refill of indented paragraphs is not done."
3881 (save-excursion
3882 (allout-end-of-prefix)
3883 (let* ((new-margin (current-column))
3884 excess old-indent-begin old-indent-end
3885 ;; We want the column where the header-prefix text started
3886 ;; *before* the prefix was changed, so we infer it relative
3887 ;; to the new margin and the shift in depth:
3888 (old-margin (+ old-depth (- new-margin new-depth))))
3890 ;; Process lines up to (but excluding) next topic header:
3891 (allout-unprotected
3892 (save-match-data
3893 (while
3894 (and (re-search-forward "\n\\(\\s-*\\)"
3897 ;; Register the indent data, before we reset the
3898 ;; match data with a subsequent `looking-at':
3899 (setq old-indent-begin (match-beginning 1)
3900 old-indent-end (match-end 1))
3901 (not (looking-at allout-regexp)))
3902 (if (> 0 (setq excess (- (- old-indent-end old-indent-begin)
3903 old-margin)))
3904 ;; Text starts left of old margin -- don't adjust:
3906 ;; Text was hanging at or right of old left margin --
3907 ;; reindent it, preserving its existing indentation
3908 ;; beyond the old margin:
3909 (delete-region old-indent-begin old-indent-end)
3910 (indent-to (+ new-margin excess (current-column))))))))))
3911 ;;;_ > allout-rebullet-current-heading (arg)
3912 (defun allout-rebullet-current-heading (arg)
3913 "Solicit new bullet for current visible heading."
3914 (interactive "p")
3915 (let ((initial-col (current-column))
3916 (on-bullet (eq (point)(allout-current-bullet-pos)))
3917 from to
3918 (backwards (if (< arg 0)
3919 (setq arg (* arg -1)))))
3920 (while (> arg 0)
3921 (save-excursion (allout-back-to-current-heading)
3922 (allout-end-of-prefix)
3923 (setq from allout-recent-prefix-beginning
3924 to allout-recent-prefix-end)
3925 (allout-rebullet-heading t ;;; instead
3926 nil ;;; depth
3927 nil ;;; number-control
3928 nil ;;; index
3929 t) ;;; do-successors
3930 (run-hook-with-args 'allout-exposure-change-hook
3931 from to t))
3932 (setq arg (1- arg))
3933 (if (<= arg 0)
3935 (setq initial-col nil) ; Override positioning back to init col
3936 (if (not backwards)
3937 (allout-next-visible-heading 1)
3938 (allout-goto-prefix-doublechecked)
3939 (allout-next-visible-heading -1))))
3940 (message "Done.")
3941 (cond (on-bullet (goto-char (allout-current-bullet-pos)))
3942 (initial-col (move-to-column initial-col)))))
3943 ;;;_ > allout-rebullet-heading (&optional instead ...)
3944 (defun allout-rebullet-heading (&optional instead
3945 new-depth
3946 number-control
3947 index
3948 do-successors)
3950 "Adjust bullet of current topic prefix.
3952 All args are optional.
3954 If INSTEAD is:
3955 - nil, then the bullet char for the context is used, per distinction or depth
3956 - a \(numeric) character, then character's string representation is used
3957 - a string, then the user is asked for bullet with the first char as default
3958 - anything else, the user is solicited with bullet char per context as default
3960 Second arg DEPTH forces the topic prefix to that depth, regardless
3961 of the topic's current depth.
3963 Third arg NUMBER-CONTROL can force the prefix to or away from
3964 numbered form. It has effect only if `allout-numbered-bullet' is
3965 non-nil and soliciting was not explicitly invoked (via first arg).
3966 Its effect, numbering or denumbering, then depends on the setting
3967 of the fourth arg, INDEX.
3969 If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
3970 prefix of the topic is forced to be non-numbered. Null index and
3971 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
3972 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
3973 INDEX is a number, then that number is used for the numbered
3974 prefix. Non-nil and non-number means that the index for the
3975 numbered prefix will be derived by allout-make-topic-prefix.
3977 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
3978 siblings.
3980 Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
3981 and `allout-numbered-bullet', which all affect the behavior of
3982 this function."
3984 (let* ((current-depth (allout-depth))
3985 (new-depth (or new-depth current-depth))
3986 (mb allout-recent-prefix-beginning)
3987 (me allout-recent-prefix-end)
3988 (current-bullet (buffer-substring-no-properties (- me 1) me))
3989 (has-annotation (get-text-property mb 'allout-was-hidden))
3990 (new-prefix (allout-make-topic-prefix current-bullet
3992 new-depth
3993 instead
3994 number-control
3995 index)))
3997 ;; Is new one is identical to old?
3998 (if (and (= current-depth new-depth)
3999 (string= current-bullet
4000 (substring new-prefix (1- (length new-prefix)))))
4001 ;; Nothing to do:
4004 ;; New prefix probably different from old:
4005 ; get rid of old one:
4006 (allout-unprotected (delete-region mb me))
4007 (goto-char mb)
4008 ; Dispense with number if
4009 ; numbered-bullet prefix:
4010 (save-match-data
4011 (if (and allout-numbered-bullet
4012 (string= allout-numbered-bullet current-bullet)
4013 (looking-at "[0-9]+"))
4014 (allout-unprotected
4015 (delete-region (match-beginning 0)(match-end 0)))))
4017 ;; convey 'allout-was-hidden annotation, if original had it:
4018 (if has-annotation
4019 (put-text-property 0 (length new-prefix) 'allout-was-hidden t
4020 new-prefix))
4022 ; Put in new prefix:
4023 (allout-unprotected (insert new-prefix))
4025 ;; Reindent the body if elected, margin changed, and not encrypted body:
4026 (if (and allout-reindent-bodies
4027 (not (= new-depth current-depth))
4028 (not (allout-encrypted-topic-p)))
4029 (allout-reindent-body current-depth new-depth))
4031 ;; Recursively rectify successive siblings of orig topic if
4032 ;; caller elected for it:
4033 (if do-successors
4034 (save-excursion
4035 (while (allout-next-sibling new-depth nil)
4036 (setq index
4037 (cond ((numberp index) (1+ index))
4038 ((not number-control) (allout-sibling-index))))
4039 (if (allout-numbered-type-prefix)
4040 (allout-rebullet-heading nil ;;; instead
4041 new-depth ;;; new-depth
4042 number-control;;; number-control
4043 index ;;; index
4044 nil))))) ;;;(dont!)do-successors
4045 ) ; (if (and (= current-depth new-depth)...))
4046 ) ; let* ((current-depth (allout-depth))...)
4047 ) ; defun
4048 ;;;_ > allout-rebullet-topic (arg)
4049 (defun allout-rebullet-topic (arg &optional sans-offspring)
4050 "Rebullet the visible topic containing point and all contained subtopics.
4052 Descends into invisible as well as visible topics, however.
4054 When optional SANS-OFFSPRING is non-nil, subtopics are not
4055 shifted. (Shifting a topic outwards without shifting its
4056 offspring is disallowed, since this would create a \"containment
4057 discontinuity\", where the depth difference between a topic and
4058 its immediate offspring is greater than one.)
4060 With repeat count, shift topic depth by that amount."
4061 (interactive "P")
4062 (let ((start-col (current-column)))
4063 (save-excursion
4064 ;; Normalize arg:
4065 (cond ((null arg) (setq arg 0))
4066 ((listp arg) (setq arg (car arg))))
4067 ;; Fill the user in, in case we're shifting a big topic:
4068 (if (not (zerop arg)) (message "Shifting..."))
4069 (allout-back-to-current-heading)
4070 (if (<= (+ allout-recent-depth arg) 0)
4071 (error "Attempt to shift topic below level 1"))
4072 (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring)
4073 (if (not (zerop arg)) (message "Shifting... done.")))
4074 (move-to-column (max 0 (+ start-col arg)))))
4075 ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
4076 (defun allout-rebullet-topic-grunt (&optional relative-depth
4077 starting-depth
4078 starting-point
4079 index
4080 do-successors
4081 sans-offspring)
4082 "Like `allout-rebullet-topic', but on nearest containing topic
4083 \(visible or not).
4085 See `allout-rebullet-heading' for rebulleting behavior.
4087 All arguments are optional.
4089 First arg RELATIVE-DEPTH means to shift the depth of the entire
4090 topic that amount.
4092 Several subsequent args are for internal recursive use by the function
4093 itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
4095 Finally, if optional SANS-OFFSPRING is non-nil then the offspring
4096 are not shifted. (Shifting a topic outwards without shifting
4097 its offspring is disallowed, since this would create a
4098 \"containment discontinuity\", where the depth difference between
4099 a topic and its immediate offspring is greater than one.)"
4101 ;; XXX the recursion here is peculiar, and in general the routine may
4102 ;; need simplification with refactoring.
4104 (if (and sans-offspring
4105 relative-depth
4106 (< relative-depth 0))
4107 (error (concat "Attempt to shift topic outwards without offspring,"
4108 " would cause containment discontinuity.")))
4110 (let* ((relative-depth (or relative-depth 0))
4111 (new-depth (allout-depth))
4112 (starting-depth (or starting-depth new-depth))
4113 (on-starting-call (null starting-point))
4114 (index (or index
4115 ;; Leave index null on starting call, so rebullet-heading
4116 ;; calculates it at what might be new depth:
4117 (and (or (zerop relative-depth)
4118 (not on-starting-call))
4119 (allout-sibling-index))))
4120 (starting-index index)
4121 (moving-outwards (< 0 relative-depth))
4122 (starting-point (or starting-point (point)))
4123 (local-point (point)))
4125 ;; Sanity check for excessive promotion done only on starting call:
4126 (and on-starting-call
4127 moving-outwards
4128 (> 0 (+ starting-depth relative-depth))
4129 (error "Attempt to shift topic out beyond level 1"))
4131 (cond ((= starting-depth new-depth)
4132 ;; We're at depth to work on this one.
4134 ;; When shifting out we work on the children before working on
4135 ;; the parent to avoid interim `allout-aberrant-container-p'
4136 ;; aberrancy, and vice-versa when shifting in:
4137 (if (>= relative-depth 0)
4138 (allout-rebullet-heading nil
4139 (+ starting-depth relative-depth)
4140 nil ;;; number
4141 index
4142 nil)) ;;; do-successors
4143 (when (not sans-offspring)
4144 ;; ... and work on subsequent ones which are at greater depth:
4145 (setq index 0)
4146 (allout-next-heading)
4147 (while (and (not (eobp))
4148 (< starting-depth (allout-depth)))
4149 (setq index (1+ index))
4150 (allout-rebullet-topic-grunt relative-depth
4151 (1+ starting-depth)
4152 starting-point
4153 index)))
4154 (when (< relative-depth 0)
4155 (save-excursion
4156 (goto-char local-point)
4157 (allout-rebullet-heading nil ;;; instead
4158 (+ starting-depth relative-depth)
4159 nil ;;; number
4160 starting-index
4161 nil)))) ;;; do-successors
4163 ((< starting-depth new-depth)
4164 ;; Rare case -- subtopic more than one level deeper than parent.
4165 ;; Treat this one at an even deeper level:
4166 (allout-rebullet-topic-grunt relative-depth
4167 new-depth
4168 starting-point
4169 index
4170 sans-offspring)))
4172 (if on-starting-call
4173 (progn
4174 ;; Rectify numbering of former siblings of the adjusted topic,
4175 ;; if topic has changed depth
4176 (if (or do-successors
4177 (and (not (zerop relative-depth))
4178 (or (= allout-recent-depth starting-depth)
4179 (= allout-recent-depth (+ starting-depth
4180 relative-depth)))))
4181 (allout-rebullet-heading nil nil nil nil t))
4182 ;; Now rectify numbering of new siblings of the adjusted topic,
4183 ;; if depth has been changed:
4184 (progn (goto-char starting-point)
4185 (if (not (zerop relative-depth))
4186 (allout-rebullet-heading nil nil nil nil t)))))
4189 ;;;_ > allout-renumber-to-depth (&optional depth)
4190 (defun allout-renumber-to-depth (&optional depth)
4191 "Renumber siblings at current depth.
4193 Affects superior topics if optional arg DEPTH is less than current depth.
4195 Returns final depth."
4197 ;; Proceed by level, processing subsequent siblings on each,
4198 ;; ascending until we get shallower than the start depth:
4200 (let ((ascender (allout-depth))
4201 was-eobp)
4202 (while (and (not (eobp))
4203 (allout-depth)
4204 (>= allout-recent-depth depth)
4205 (>= ascender depth))
4206 ; Skip over all topics at
4207 ; lesser depths, which can not
4208 ; have been disturbed:
4209 (while (and (not (setq was-eobp (eobp)))
4210 (> allout-recent-depth ascender))
4211 (allout-next-heading))
4212 ; Prime ascender for ascension:
4213 (setq ascender (1- allout-recent-depth))
4214 (if (>= allout-recent-depth depth)
4215 (allout-rebullet-heading nil ;;; instead
4216 nil ;;; depth
4217 nil ;;; number-control
4218 nil ;;; index
4219 t)) ;;; do-successors
4220 (if was-eobp (goto-char (point-max)))))
4221 allout-recent-depth)
4222 ;;;_ > allout-number-siblings (&optional denumber)
4223 (defun allout-number-siblings (&optional denumber)
4224 "Assign numbered topic prefix to this topic and its siblings.
4226 With universal argument, denumber -- assign default bullet to this
4227 topic and its siblings.
4229 With repeated universal argument (`^U^U'), solicit bullet for each
4230 rebulleting each topic at this level."
4232 (interactive "P")
4234 (save-excursion
4235 (allout-back-to-current-heading)
4236 (allout-beginning-of-level)
4237 (let ((depth allout-recent-depth)
4238 (index (if (not denumber) 1))
4239 (use-bullet (equal '(16) denumber))
4240 (more t))
4241 (while more
4242 (allout-rebullet-heading use-bullet ;;; instead
4243 depth ;;; depth
4244 t ;;; number-control
4245 index ;;; index
4246 nil) ;;; do-successors
4247 (if index (setq index (1+ index)))
4248 (setq more (allout-next-sibling depth nil))))))
4249 ;;;_ > allout-shift-in (arg)
4250 (defun allout-shift-in (arg)
4251 "Increase depth of current heading and any items collapsed within it.
4253 With a negative argument, the item is shifted out using
4254 `allout-shift-out', instead.
4256 With an argument greater than one, shift-in the item but not its
4257 offspring, making the item into a sibling of its former children,
4258 and a child of sibling that formerly preceded it.
4260 You are not allowed to shift the first offspring of a topic
4261 inwards, because that would yield a \"containment
4262 discontinuity\", where the depth difference between a topic and
4263 its immediate offspring is greater than one. The first topic in
4264 the file can be adjusted to any positive depth, however."
4266 (interactive "p")
4267 (if (< arg 0)
4268 (allout-shift-out (* arg -1))
4269 ;; refuse to create a containment discontinuity:
4270 (save-excursion
4271 (allout-back-to-current-heading)
4272 (if (not (bobp))
4273 (let* ((current-depth allout-recent-depth)
4274 (start-point (point))
4275 (predecessor-depth (progn
4276 (forward-char -1)
4277 (allout-goto-prefix-doublechecked)
4278 (if (< (point) start-point)
4279 allout-recent-depth
4280 0))))
4281 (if (and (> predecessor-depth 0)
4282 (> (1+ current-depth)
4283 (1+ predecessor-depth)))
4284 (error (concat "Disallowed shift deeper than"
4285 " containing topic's children."))
4286 (allout-back-to-current-heading)
4287 (if (< allout-recent-depth (1+ current-depth))
4288 (allout-show-children))))))
4289 (let ((where (point)))
4290 (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring))
4291 (run-hook-with-args 'allout-structure-shifted-hook arg where))))
4292 ;;;_ > allout-shift-out (arg)
4293 (defun allout-shift-out (arg)
4294 "Decrease depth of current heading and any topics collapsed within it.
4295 This will make the item a sibling of its former container.
4297 With a negative argument, the item is shifted in using
4298 `allout-shift-in', instead.
4300 With an argument greater than one, shift-out the item's offspring
4301 but not the item itself, making the former children siblings of
4302 the item.
4304 With an argument greater than 1, the item's offspring are shifted
4305 out without shifting the item. This will make the immediate
4306 subtopics into siblings of the item."
4307 (interactive "p")
4308 (if (< arg 0)
4309 (allout-shift-in (* arg -1))
4310 ;; Get proper exposure in this area:
4311 (save-excursion (if (allout-ascend)
4312 (allout-show-children)))
4313 ;; Show collapsed children if there's a successor which will become
4314 ;; their sibling:
4315 (if (and (allout-current-topic-collapsed-p)
4316 (save-excursion (allout-next-sibling)))
4317 (allout-show-children))
4318 (let ((where (and (allout-depth) allout-recent-prefix-beginning)))
4319 (save-excursion
4320 (if (> arg 1)
4321 ;; Shift the offspring but not the topic:
4322 (let ((children-chart (allout-chart-subtree 1)))
4323 (if (listp (car children-chart))
4324 ;; whoops:
4325 (setq children-chart (allout-flatten children-chart)))
4326 (save-excursion
4327 (dolist (child-point children-chart)
4328 (goto-char child-point)
4329 (allout-shift-out 1))))
4330 (allout-rebullet-topic (* arg -1))))
4331 (run-hook-with-args 'allout-structure-shifted-hook (* arg -1) where))))
4332 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
4333 ;;;_ > allout-kill-line (&optional arg)
4334 (defun allout-kill-line (&optional arg)
4335 "Kill line, adjusting subsequent lines suitably for outline mode."
4337 (interactive "*P")
4339 (if (or (not (allout-mode-p))
4340 (not (bolp))
4341 (not (save-match-data (looking-at allout-regexp))))
4342 ;; Just do a regular kill:
4343 (kill-line arg)
4344 ;; Ah, have to watch out for adjustments:
4345 (let* ((beg (point))
4347 (beg-hidden (allout-hidden-p))
4348 (end-hidden (save-excursion (allout-end-of-current-line)
4349 (setq end (point))
4350 (allout-hidden-p)))
4351 (depth (allout-depth)))
4353 (allout-annotate-hidden beg end)
4354 (unwind-protect
4355 (if (and (not beg-hidden) (not end-hidden))
4356 (allout-unprotected (kill-line arg))
4357 (kill-line arg))
4358 (run-hooks 'allout-after-copy-or-kill-hook)
4359 (allout-deannotate-hidden beg end)
4361 (if allout-numbered-bullet
4362 (save-excursion ; Renumber subsequent topics if needed:
4363 (if (not (save-match-data (looking-at allout-regexp)))
4364 (allout-next-heading))
4365 (allout-renumber-to-depth depth)))
4366 (run-hook-with-args 'allout-structure-deleted-hook depth (point))))))
4367 ;;;_ > allout-copy-line-as-kill ()
4368 (defun allout-copy-line-as-kill ()
4369 "Like allout-kill-topic, but save to kill ring instead of deleting."
4370 (interactive)
4371 (let ((buffer-read-only t))
4372 (condition-case nil
4373 (allout-kill-line)
4374 (buffer-read-only nil))))
4375 ;;;_ > allout-kill-topic ()
4376 (defun allout-kill-topic ()
4377 "Kill topic together with subtopics.
4379 Trailing whitespace is killed with a topic if that whitespace:
4381 - would separate the topic from a subsequent sibling
4382 - would separate the topic from the end of buffer
4383 - would not be added to whitespace already separating the topic from the
4384 previous one.
4386 Topic exposure is marked with text-properties, to be used by
4387 `allout-yank-processing' for exposure recovery."
4389 (interactive)
4390 (let* ((inhibit-field-text-motion t)
4391 (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
4393 (depth allout-recent-depth))
4394 (allout-end-of-current-subtree)
4395 (if (and (/= (current-column) 0) (not (eobp)))
4396 (forward-char 1))
4397 (if (not (eobp))
4398 (if (and (save-match-data (looking-at "\n"))
4399 (or (save-excursion
4400 (or (not (allout-next-heading))
4401 (= depth allout-recent-depth)))
4402 (and (> (- beg (point-min)) 3)
4403 (string= (buffer-substring (- beg 2) beg) "\n\n"))))
4404 (forward-char 1)))
4406 (allout-annotate-hidden beg (setq end (point)))
4407 (unwind-protect ; for possible barf-if-buffer-read-only.
4408 (allout-unprotected (kill-region beg end))
4409 (allout-deannotate-hidden beg end)
4410 (run-hooks 'allout-after-copy-or-kill-hook)
4412 (save-excursion
4413 (allout-renumber-to-depth depth))
4414 (run-hook-with-args 'allout-structure-deleted-hook depth (point)))))
4415 ;;;_ > allout-copy-topic-as-kill ()
4416 (defun allout-copy-topic-as-kill ()
4417 "Like `allout-kill-topic', but save to kill ring instead of deleting."
4418 (interactive)
4419 (let ((buffer-read-only t))
4420 (condition-case nil
4421 (allout-kill-topic)
4422 (buffer-read-only (message "Topic copied...")))))
4423 ;;;_ > allout-annotate-hidden (begin end)
4424 (defun allout-annotate-hidden (begin end)
4425 "Qualify text with properties to indicate exposure status."
4427 (let ((was-modified (buffer-modified-p))
4428 (buffer-read-only nil))
4429 (allout-deannotate-hidden begin end)
4430 (save-excursion
4431 (goto-char begin)
4432 (let (done next prev overlay)
4433 (while (not done)
4434 ;; at or advance to start of next hidden region:
4435 (if (not (allout-hidden-p))
4436 (setq next
4437 (max (1+ (point))
4438 (allout-next-single-char-property-change (point)
4439 'invisible
4440 nil end))))
4441 (if (or (not next) (eq prev next))
4442 ;; still not at start of hidden area -- must not be any left.
4443 (setq done t)
4444 (goto-char next)
4445 (setq prev next)
4446 (if (not (allout-hidden-p))
4447 ;; still not at start of hidden area.
4448 (setq done t)
4449 (setq overlay (allout-get-invisibility-overlay))
4450 (setq next (overlay-end overlay)
4451 prev next)
4452 ;; advance to end of this hidden area:
4453 (when next
4454 (goto-char next)
4455 (allout-unprotected
4456 (let ((buffer-undo-list t))
4457 (put-text-property (overlay-start overlay) next
4458 'allout-was-hidden t)))))))))
4459 (set-buffer-modified-p was-modified)))
4460 ;;;_ > allout-deannotate-hidden (begin end)
4461 (defun allout-deannotate-hidden (begin end)
4462 "Remove allout hidden-text annotation between BEGIN and END."
4464 (allout-unprotected
4465 (let ((inhibit-read-only t)
4466 (buffer-undo-list t))
4467 (remove-text-properties begin (min end (point-max))
4468 '(allout-was-hidden t)))))
4469 ;;;_ > allout-hide-by-annotation (begin end)
4470 (defun allout-hide-by-annotation (begin end)
4471 "Translate text properties indicating exposure status into actual exposure."
4472 (save-excursion
4473 (goto-char begin)
4474 (let ((was-modified (buffer-modified-p))
4475 done next prev)
4476 (while (not done)
4477 ;; at or advance to start of next annotation:
4478 (if (not (get-text-property (point) 'allout-was-hidden))
4479 (setq next (allout-next-single-char-property-change
4480 (point) 'allout-was-hidden nil end)))
4481 (if (or (not next) (eq prev next))
4482 ;; no more or not advancing -- must not be any left.
4483 (setq done t)
4484 (goto-char next)
4485 (setq prev next)
4486 (if (not (get-text-property (point) 'allout-was-hidden))
4487 ;; still not at start of annotation.
4488 (setq done t)
4489 ;; advance to just after end of this annotation:
4490 (setq next (allout-next-single-char-property-change
4491 (point) 'allout-was-hidden nil end))
4492 (let ((o (make-overlay prev next nil 'front-advance)))
4493 (overlay-put o 'category 'allout-exposure-category)
4494 (overlay-put o 'evaporate t))
4495 (allout-deannotate-hidden prev next)
4496 (setq prev next)
4497 (if next (goto-char next)))))
4498 (set-buffer-modified-p was-modified))))
4499 ;;;_ > allout-yank-processing ()
4500 (defun allout-yank-processing (&optional arg)
4502 "Incidental allout-specific business to be done just after text yanks.
4504 Does depth adjustment of yanked topics, when:
4506 1 the stuff being yanked starts with a valid outline header prefix, and
4507 2 it is being yanked at the end of a line which consists of only a valid
4508 topic prefix.
4510 Also, adjusts numbering of subsequent siblings when appropriate.
4512 Depth adjustment alters the depth of all the topics being yanked
4513 the amount it takes to make the first topic have the depth of the
4514 header into which it's being yanked.
4516 The point is left in front of yanked, adjusted topics, rather than
4517 at the end (and vice-versa with the mark). Non-adjusted yanks,
4518 however, are left exactly like normal, non-allout-specific yanks."
4520 (interactive "*P")
4521 ; Get to beginning, leaving
4522 ; region around subject:
4523 (if (< (allout-mark-marker t) (point))
4524 (exchange-point-and-mark))
4525 (save-match-data
4526 (let* ((subj-beg (point))
4527 (into-bol (bolp))
4528 (subj-end (allout-mark-marker t))
4529 ;; 'resituate' if yanking an entire topic into topic header:
4530 (resituate (and (let ((allout-inhibit-aberrance-doublecheck t))
4531 (allout-e-o-prefix-p))
4532 (looking-at allout-regexp)
4533 (allout-prefix-data)))
4534 ;; `rectify-numbering' if resituating (where several topics may
4535 ;; be resituating) or yanking a topic into a topic slot (bol):
4536 (rectify-numbering (or resituate
4537 (and into-bol (looking-at allout-regexp)))))
4538 (if resituate
4539 ;; Yanking a topic into the start of a topic -- reconcile to fit:
4540 (let* ((inhibit-field-text-motion t)
4541 (prefix-len (if (not (match-end 1))
4543 (- (match-end 1) subj-beg)))
4544 (subj-depth allout-recent-depth)
4545 (prefix-bullet (allout-recent-bullet))
4546 (adjust-to-depth
4547 ;; Nil if adjustment unnecessary, otherwise depth to which
4548 ;; adjustment should be made:
4549 (save-excursion
4550 (and (goto-char subj-end)
4551 (eolp)
4552 (goto-char subj-beg)
4553 (and (looking-at allout-regexp)
4554 (progn
4555 (beginning-of-line)
4556 (not (= (point) subj-beg)))
4557 (looking-at allout-regexp)
4558 (allout-prefix-data))
4559 allout-recent-depth)))
4560 (more t))
4561 (setq rectify-numbering allout-numbered-bullet)
4562 (if adjust-to-depth
4563 ; Do the adjustment:
4564 (progn
4565 (save-restriction
4566 (narrow-to-region subj-beg subj-end)
4567 ; Trim off excessive blank
4568 ; line at end, if any:
4569 (goto-char (point-max))
4570 (if (looking-at "^$")
4571 (allout-unprotected (delete-char -1)))
4572 ; Work backwards, with each
4573 ; shallowest level,
4574 ; successively excluding the
4575 ; last processed topic from
4576 ; the narrow region:
4577 (while more
4578 (allout-back-to-current-heading)
4579 ; go as high as we can in each bunch:
4580 (while (allout-ascend t))
4581 (save-excursion
4582 (allout-unprotected
4583 (allout-rebullet-topic-grunt (- adjust-to-depth
4584 subj-depth)))
4585 (allout-depth))
4586 (if (setq more (not (bobp)))
4587 (progn (widen)
4588 (forward-char -1)
4589 (narrow-to-region subj-beg (point))))))
4590 ;; Remove new heading prefix:
4591 (allout-unprotected
4592 (progn
4593 (delete-region (point) (+ (point)
4594 prefix-len
4595 (- adjust-to-depth
4596 subj-depth)))
4597 ; and delete residual subj
4598 ; prefix digits and space:
4599 (while (looking-at "[0-9]") (delete-char 1))
4600 (if (looking-at " ")
4601 (delete-char 1))))
4602 ;; Assert new topic's bullet - minimal effort if unchanged:
4603 (allout-rebullet-heading (string-to-char prefix-bullet)))
4604 (exchange-point-and-mark))))
4605 (if rectify-numbering
4606 (progn
4607 (save-excursion
4608 ; Give some preliminary feedback:
4609 (message "... reconciling numbers")
4610 ; ... and renumber, in case necessary:
4611 (goto-char subj-beg)
4612 (if (allout-goto-prefix-doublechecked)
4613 (allout-unprotected
4614 (allout-rebullet-heading nil ;;; instead
4615 (allout-depth) ;;; depth
4616 nil ;;; number-control
4617 nil ;;; index
4618 t)))
4619 (message ""))))
4620 (if (or into-bol resituate)
4621 (allout-hide-by-annotation (point) (allout-mark-marker t))
4622 (allout-deannotate-hidden (allout-mark-marker t) (point)))
4623 (if (not resituate)
4624 (exchange-point-and-mark))
4625 (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end))))
4626 ;;;_ > allout-yank (&optional arg)
4627 (defun allout-yank (&optional arg)
4628 "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
4630 Non-topic yanks work no differently than normal yanks.
4632 If a topic is being yanked into a bare topic prefix, the depth of the
4633 yanked topic is adjusted to the depth of the topic prefix.
4635 1 we're yanking in an `allout-mode' buffer
4636 2 the stuff being yanked starts with a valid outline header prefix, and
4637 3 it is being yanked at the end of a line which consists of only a valid
4638 topic prefix.
4640 If these conditions hold then the depth of the yanked topics are all
4641 adjusted the amount it takes to make the first one at the depth of the
4642 header into which it's being yanked.
4644 The point is left in front of yanked, adjusted topics, rather than
4645 at the end (and vice-versa with the mark). Non-adjusted yanks,
4646 however, (ones that don't qualify for adjustment) are handled
4647 exactly like normal yanks.
4649 Numbering of yanked topics, and the successive siblings at the depth
4650 into which they're being yanked, is adjusted.
4652 `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
4653 works with normal `yank' in non-outline buffers."
4655 (interactive "*P")
4656 (setq this-command 'yank)
4657 (allout-unprotected
4658 (yank arg))
4659 (if (allout-mode-p)
4660 (allout-yank-processing)))
4661 ;;;_ > allout-yank-pop (&optional arg)
4662 (defun allout-yank-pop (&optional arg)
4663 "Yank-pop like `allout-yank' when popping to bare outline prefixes.
4665 Adapts level of popped topics to level of fresh prefix.
4667 Note -- prefix changes to distinctive bullets will stick, if followed
4668 by pops to non-distinctive yanks. Bug..."
4670 (interactive "*p")
4671 (setq this-command 'yank)
4672 (yank-pop arg)
4673 (if (allout-mode-p)
4674 (allout-yank-processing)))
4676 ;;;_ - Specialty bullet functions
4677 ;;;_ : File Cross references
4678 ;;;_ > allout-resolve-xref ()
4679 (defun allout-resolve-xref ()
4680 "Pop to file associated with current heading, if it has an xref bullet.
4682 \(Works according to setting of `allout-file-xref-bullet')."
4683 (interactive)
4684 (if (not allout-file-xref-bullet)
4685 (error
4686 "Outline cross references disabled -- no `allout-file-xref-bullet'")
4687 (if (not (string= (allout-current-bullet) allout-file-xref-bullet))
4688 (error "Current heading lacks cross-reference bullet `%s'"
4689 allout-file-xref-bullet)
4690 (let ((inhibit-field-text-motion t)
4691 file-name)
4692 (save-match-data
4693 (save-excursion
4694 (let* ((text-start allout-recent-prefix-end)
4695 (heading-end (point-at-eol)))
4696 (goto-char text-start)
4697 (setq file-name
4698 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t)
4699 (buffer-substring (match-beginning 1)
4700 (match-end 1)))))))
4701 (setq file-name (expand-file-name file-name))
4702 (if (or (file-exists-p file-name)
4703 (if (file-writable-p file-name)
4704 (y-or-n-p (format "%s not there, create one? "
4705 file-name))
4706 (error "%s not found and can't be created" file-name)))
4707 (condition-case failure
4708 (find-file-other-window file-name)
4709 (error failure))
4710 (error "%s not found" file-name))
4716 ;;;_ #6 Exposure Control
4718 ;;;_ - Fundamental
4719 ;;;_ > allout-flag-region (from to flag)
4720 (defun allout-flag-region (from to flag)
4721 "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
4723 Exposure-change hook `allout-exposure-change-hook' is run with the same
4724 arguments as this function, after the exposure changes are made."
4726 ;; We use outline invisibility spec.
4727 (remove-overlays from to 'category 'allout-exposure-category)
4728 (when flag
4729 (let ((o (make-overlay from to nil 'front-advance)))
4730 (overlay-put o 'category 'allout-exposure-category)
4731 (when (featurep 'xemacs)
4732 (let ((props (symbol-plist 'allout-exposure-category)))
4733 (while props
4734 (condition-case nil
4735 ;; as of 2008-02-27, xemacs lacks modification-hooks
4736 (overlay-put o (pop props) (pop props))
4737 (error nil)))))))
4738 (run-hook-with-args 'allout-exposure-change-hook from to flag))
4739 ;;;_ > allout-flag-current-subtree (flag)
4740 (defun allout-flag-current-subtree (flag)
4741 "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
4743 (save-excursion
4744 (allout-back-to-current-heading)
4745 (let ((inhibit-field-text-motion t))
4746 (end-of-line))
4747 (allout-flag-region (point)
4748 ;; Exposing must not leave trailing blanks hidden,
4749 ;; but can leave them exposed when hiding, so we
4750 ;; can use flag's inverse as the
4751 ;; include-trailing-blank cue:
4752 (allout-end-of-current-subtree (not flag))
4753 flag)))
4755 ;;;_ - Topic-specific
4756 ;;;_ > allout-show-entry ()
4757 (defun allout-show-entry ()
4758 "Like `allout-show-current-entry', but reveals entries in hidden topics.
4760 This is a way to give restricted peek at a concealed locality without the
4761 expense of exposing its context, but can leave the outline with aberrant
4762 exposure. `allout-show-offshoot' should be used after the peek to rectify
4763 the exposure."
4765 (interactive)
4766 (save-excursion
4767 (let (beg end)
4768 (allout-goto-prefix-doublechecked)
4769 (setq beg (if (allout-hidden-p) (1- (point)) (point)))
4770 (setq end (allout-pre-next-prefix))
4771 (allout-flag-region beg end nil)
4772 (list beg end))))
4773 ;;;_ > allout-show-children (&optional level strict)
4774 (defun allout-show-children (&optional level strict)
4776 "If point is visible, show all direct subheadings of this heading.
4778 Otherwise, do `allout-show-to-offshoot', and then show subheadings.
4780 Optional LEVEL specifies how many levels below the current level
4781 should be shown, or all levels if t. Default is 1.
4783 Optional STRICT means don't resort to -show-to-offshoot, no matter
4784 what. This is basically so -show-to-offshoot, which is called by
4785 this function, can employ the pure offspring-revealing capabilities of
4788 Returns point at end of subtree that was opened, if any. (May get a
4789 point of non-opened subtree?)"
4791 (interactive "p")
4792 (let ((start-point (point)))
4793 (if (and (not strict)
4794 (allout-hidden-p))
4796 (progn (allout-show-to-offshoot) ; Point's concealed, open to
4797 ; expose it.
4798 ;; Then recurse, but with "strict" set so we don't
4799 ;; infinite regress:
4800 (allout-show-children level t))
4802 (save-excursion
4803 (allout-beginning-of-current-line)
4804 (save-restriction
4805 (let* (depth
4806 ;; translate the level spec for this routine to the ones
4807 ;; used by -chart-subtree and -chart-to-reveal:
4808 (chart-level (cond ((not level) 1)
4809 ((eq level t) nil)
4810 (t level)))
4811 (chart (allout-chart-subtree chart-level))
4812 (to-reveal (or (allout-chart-to-reveal chart chart-level)
4813 ;; interactive, show discontinuous children:
4814 (and chart
4815 (allout-called-interactively-p)
4816 (save-excursion
4817 (allout-back-to-current-heading)
4818 (setq depth (allout-current-depth))
4819 (and (allout-next-heading)
4820 (> allout-recent-depth
4821 (1+ depth))))
4822 (message
4823 "Discontinuous offspring; use `%s %s'%s."
4824 (substitute-command-keys
4825 "\\[universal-argument]")
4826 (substitute-command-keys
4827 "\\[allout-shift-out]")
4828 " to elevate them.")
4829 (allout-chart-to-reveal
4830 chart (- allout-recent-depth depth))))))
4831 (goto-char start-point)
4832 (when (and strict (allout-hidden-p))
4833 ;; Concealed root would already have been taken care of,
4834 ;; unless strict was set.
4835 (allout-flag-region (point) (allout-snug-back) nil)
4836 (when allout-show-bodies
4837 (goto-char (car to-reveal))
4838 (allout-show-current-entry)))
4839 (while to-reveal
4840 (goto-char (car to-reveal))
4841 (allout-flag-region (save-excursion (allout-snug-back) (point))
4842 (progn (search-forward "\n" nil t)
4843 (1- (point)))
4844 nil)
4845 (when allout-show-bodies
4846 (goto-char (car to-reveal))
4847 (allout-show-current-entry))
4848 (setq to-reveal (cdr to-reveal)))))))
4849 ;; Compensate for `save-excursion's maintenance of point
4850 ;; within invisible text:
4851 (goto-char start-point)))
4852 ;;;_ > allout-show-to-offshoot ()
4853 (defun allout-show-to-offshoot ()
4854 "Like `allout-show-entry', but reveals all concealed ancestors, as well.
4856 Useful for coherently exposing to a random point in a hidden region."
4857 (interactive)
4858 (save-excursion
4859 (let ((inhibit-field-text-motion t)
4860 (orig-pt (point))
4861 (orig-pref (allout-goto-prefix-doublechecked))
4862 (last-at (point))
4863 (bag-it 0))
4864 (while (or (> bag-it 1) (allout-hidden-p))
4865 (while (allout-hidden-p)
4866 (move-beginning-of-line 1)
4867 (if (allout-hidden-p) (forward-char -1)))
4868 (if (= last-at (setq last-at (point)))
4869 ;; Oops, we're not making any progress! Show the current topic
4870 ;; completely, and try one more time here, if we haven't already.
4871 (progn (beginning-of-line)
4872 (allout-show-current-subtree)
4873 (goto-char orig-pt)
4874 (setq bag-it (1+ bag-it))
4875 (if (> bag-it 1)
4876 (error "allout-show-to-offshoot: %s"
4877 "Stumped by aberrant nesting.")))
4878 (if (> bag-it 0) (setq bag-it 0))
4879 (allout-show-children)
4880 (goto-char orig-pref)))
4881 (goto-char orig-pt)))
4882 (if (allout-hidden-p)
4883 (allout-show-entry)))
4884 ;;;_ > allout-hide-current-entry ()
4885 (defun allout-hide-current-entry ()
4886 "Hide the body directly following this heading."
4887 (interactive)
4888 (allout-back-to-current-heading)
4889 (save-excursion
4890 (let ((inhibit-field-text-motion t))
4891 (end-of-line))
4892 (allout-flag-region (point)
4893 (progn (allout-end-of-entry) (point))
4894 t)))
4895 ;;;_ > allout-show-current-entry (&optional arg)
4896 (defun allout-show-current-entry (&optional arg)
4897 "Show body following current heading, or hide entry with universal argument."
4899 (interactive "P")
4900 (if arg
4901 (allout-hide-current-entry)
4902 (save-excursion (allout-show-to-offshoot))
4903 (save-excursion
4904 (allout-flag-region (point)
4905 (progn (allout-end-of-entry t) (point))
4906 nil)
4908 ;;;_ > allout-show-current-subtree (&optional arg)
4909 (defun allout-show-current-subtree (&optional arg)
4910 "Show everything within the current topic.
4911 With a repeat-count, expose this topic and its siblings."
4912 (interactive "P")
4913 (save-excursion
4914 (if (<= (allout-current-depth) 0)
4915 ;; Outside any topics -- try to get to the first:
4916 (if (not (allout-next-heading))
4917 (error "No topics")
4918 ;; got to first, outermost topic -- set to expose it and siblings:
4919 (message "Above outermost topic -- exposing all.")
4920 (allout-flag-region (point-min)(point-max) nil))
4921 (allout-beginning-of-current-line)
4922 (if (not arg)
4923 (allout-flag-current-subtree nil)
4924 (allout-beginning-of-level)
4925 (allout-expose-topic '(* :))))))
4926 ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
4927 (defun allout-current-topic-collapsed-p (&optional include-single-liners)
4928 "True if the currently visible containing topic is already collapsed.
4930 Single line topics intrinsically can be considered as being both
4931 collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
4932 true, then single-line topics are considered to be collapsed. By
4933 default, they are treated as being uncollapsed."
4934 (save-match-data
4935 (save-excursion
4936 (and
4937 ;; Is the topic all on one line (allowing for trailing blank line)?
4938 (>= (progn (allout-back-to-current-heading)
4939 (let ((inhibit-field-text-motion t))
4940 (move-end-of-line 1))
4941 (point))
4942 (allout-end-of-current-subtree (not (looking-at "\n\n"))))
4944 (or include-single-liners
4945 (progn (backward-char 1) (allout-hidden-p)))))))
4946 ;;;_ > allout-hide-current-subtree (&optional just-close)
4947 (defun allout-hide-current-subtree (&optional just-close)
4948 "Close the current topic, or containing topic if this one is already closed.
4950 If this topic is closed and it's a top level topic, close this topic
4951 and its siblings.
4953 If optional arg JUST-CLOSE is non-nil, do not close the parent or
4954 siblings, even if the target topic is already closed."
4956 (interactive)
4957 (let* ((from (point))
4958 (sibs-msg "Top-level topic already closed -- closing siblings...")
4959 (current-exposed (not (allout-current-topic-collapsed-p t))))
4960 (cond (current-exposed (allout-flag-current-subtree t))
4961 (just-close nil)
4962 ((allout-ascend) (allout-hide-current-subtree))
4963 (t (goto-char 0)
4964 (message sibs-msg)
4965 (allout-goto-prefix-doublechecked)
4966 (allout-expose-topic '(0 :))
4967 (message (concat sibs-msg " Done."))))
4968 (goto-char from)))
4969 ;;;_ > allout-toggle-current-subtree-exposure
4970 (defun allout-toggle-current-subtree-exposure ()
4971 "Show or hide the current subtree depending on its current state."
4972 ;; thanks to tassilo for suggesting this.
4973 (interactive)
4974 (save-excursion
4975 (allout-back-to-heading)
4976 (if (allout-hidden-p (point-at-eol))
4977 (allout-show-current-subtree)
4978 (allout-hide-current-subtree))))
4979 ;;;_ > allout-show-current-branches ()
4980 (defun allout-show-current-branches ()
4981 "Show all subheadings of this heading, but not their bodies."
4982 (interactive)
4983 (let ((inhibit-field-text-motion t))
4984 (beginning-of-line))
4985 (allout-show-children t))
4986 ;;;_ > allout-hide-current-leaves ()
4987 (defun allout-hide-current-leaves ()
4988 "Hide the bodies of the current topic and all its offspring."
4989 (interactive)
4990 (allout-back-to-current-heading)
4991 (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
4992 (point))))
4994 ;;;_ - Region and beyond
4995 ;;;_ > allout-show-all ()
4996 (defun allout-show-all ()
4997 "Show all of the text in the buffer."
4998 (interactive)
4999 (message "Exposing entire buffer...")
5000 (allout-flag-region (point-min) (point-max) nil)
5001 (message "Exposing entire buffer... Done."))
5002 ;;;_ > allout-hide-bodies ()
5003 (defun allout-hide-bodies ()
5004 "Hide all of buffer except headings."
5005 (interactive)
5006 (allout-hide-region-body (point-min) (point-max)))
5007 ;;;_ > allout-hide-region-body (start end)
5008 (defun allout-hide-region-body (start end)
5009 "Hide all body lines in the region, but not headings."
5010 (save-match-data
5011 (save-excursion
5012 (save-restriction
5013 (narrow-to-region start end)
5014 (goto-char (point-min))
5015 (let ((inhibit-field-text-motion t))
5016 (while (not (eobp))
5017 (end-of-line)
5018 (allout-flag-region (point) (allout-end-of-entry) t)
5019 (if (not (eobp))
5020 (forward-char
5021 (if (looking-at "\n\n")
5022 2 1)))))))))
5024 ;;;_ > allout-expose-topic (spec)
5025 (defun allout-expose-topic (spec)
5026 "Apply exposure specs to successive outline topic items.
5028 Use the more convenient frontend, `allout-new-exposure', if you don't
5029 need evaluation of the arguments, or even better, the `allout-layout'
5030 variable-keyed mode-activation/auto-exposure feature of allout outline
5031 mode. See the respective documentation strings for more details.
5033 Cursor is left at start position.
5035 SPEC is either a number or a list.
5037 Successive specs on a list are applied to successive sibling topics.
5039 A simple spec (either a number, one of a few symbols, or the null
5040 list) dictates the exposure for the corresponding topic.
5042 Non-null lists recursively designate exposure specs for respective
5043 subtopics of the current topic.
5045 The `:' repeat spec is used to specify exposure for any number of
5046 successive siblings, up to the trailing ones for which there are
5047 explicit specs following the `:'.
5049 Simple (numeric and null-list) specs are interpreted as follows:
5051 Numbers indicate the relative depth to open the corresponding topic.
5052 - negative numbers force the topic to be closed before opening to the
5053 absolute value of the number, so all siblings are open only to
5054 that level.
5055 - positive numbers open to the relative depth indicated by the
5056 number, but do not force already opened subtopics to be closed.
5057 - 0 means to close topic -- hide all offspring.
5058 : - `repeat'
5059 apply prior element to all siblings at current level, *up to*
5060 those siblings that would be covered by specs following the `:'
5061 on the list. Ie, apply to all topics at level but the last
5062 ones. (Only first of multiple colons at same level is
5063 respected -- subsequent ones are discarded.)
5064 * - completely opens the topic, including bodies.
5065 + - shows all the sub headers, but not the bodies
5066 - - exposes the body of the corresponding topic.
5068 Examples:
5069 \(allout-expose-topic '(-1 : 0))
5070 Close this and all following topics at current level, exposing
5071 only their immediate children, but close down the last topic
5072 at this current level completely.
5073 \(allout-expose-topic '(-1 () : 1 0))
5074 Close current topic so only the immediate subtopics are shown;
5075 show the children in the second to last topic, and completely
5076 close the last one.
5077 \(allout-expose-topic '(-2 : -1 *))
5078 Expose children and grandchildren of all topics at current
5079 level except the last two; expose children of the second to
5080 last and completely open the last one."
5082 (interactive "xExposure spec: ")
5083 (if (not (listp spec))
5085 (let ((depth (allout-depth))
5086 (max-pos 0)
5087 prev-elem curr-elem
5088 stay)
5089 (while spec
5090 (setq prev-elem curr-elem
5091 curr-elem (car spec)
5092 spec (cdr spec))
5093 (cond ; Do current element:
5094 ((null curr-elem) nil)
5095 ((symbolp curr-elem)
5096 (cond ((eq curr-elem '*) (allout-show-current-subtree)
5097 (if (> allout-recent-end-of-subtree max-pos)
5098 (setq max-pos allout-recent-end-of-subtree)))
5099 ((eq curr-elem '+)
5100 (if (not (allout-hidden-p))
5101 (save-excursion (allout-hide-current-subtree t)))
5102 (allout-show-current-branches)
5103 (if (> allout-recent-end-of-subtree max-pos)
5104 (setq max-pos allout-recent-end-of-subtree)))
5105 ((eq curr-elem '-) (allout-show-current-entry))
5106 ((eq curr-elem ':)
5107 (setq stay t)
5108 ;; Expand the `repeat' spec to an explicit version,
5109 ;; w.r.t. remaining siblings:
5110 (let ((residue ; = # of sibs not covered by remaining spec
5111 ;; Dang, could be nice to make use of the chart, sigh:
5112 (- (length (allout-chart-siblings))
5113 (length spec))))
5114 (if (< 0 residue)
5115 ;; Some residue -- cover it with prev-elem:
5116 (setq spec (append (make-list residue prev-elem)
5117 spec)))))))
5118 ((numberp curr-elem)
5119 (if (and (>= 0 curr-elem) (not (allout-hidden-p)))
5120 (save-excursion (allout-hide-current-subtree t)
5121 (if (> 0 curr-elem)
5123 (if (> allout-recent-end-of-subtree max-pos)
5124 (setq max-pos
5125 allout-recent-end-of-subtree)))))
5126 (if (> (abs curr-elem) 0)
5127 (progn (allout-show-children (abs curr-elem))
5128 (if (> allout-recent-end-of-subtree max-pos)
5129 (setq max-pos allout-recent-end-of-subtree)))))
5130 ((listp curr-elem)
5131 (if (allout-descend-to-depth (1+ depth))
5132 (let ((got (allout-expose-topic curr-elem)))
5133 (if (and got (> got max-pos)) (setq max-pos got))))))
5134 (cond (stay (setq stay nil))
5135 ((listp (car spec)) nil)
5136 ((> max-pos (point))
5137 ;; Capitalize on max-pos state to get us nearer next sibling:
5138 (progn (goto-char (min (point-max) max-pos))
5139 (allout-next-heading)))
5140 ((allout-next-sibling depth))))
5141 max-pos)))
5142 ;;;_ > allout-old-expose-topic (spec &rest followers)
5143 (defun allout-old-expose-topic (spec &rest followers)
5145 "Deprecated. Use `allout-expose-topic' (with different schema
5146 format) instead.
5148 Dictate wholesale exposure scheme for current topic, according to SPEC.
5150 SPEC is either a number or a list. Optional successive args
5151 dictate exposure for subsequent siblings of current topic.
5153 A simple spec (either a number, a special symbol, or the null list)
5154 dictates the overall exposure for a topic. Non null lists are
5155 composite specs whose first element dictates the overall exposure for
5156 a topic, with the subsequent elements in the list interpreted as specs
5157 that dictate the exposure for the successive offspring of the topic.
5159 Simple (numeric and null-list) specs are interpreted as follows:
5161 - Numbers indicate the relative depth to open the corresponding topic:
5162 - negative numbers force the topic to be close before opening to the
5163 absolute value of the number.
5164 - positive numbers just open to the relative depth indicated by the number.
5165 - 0 just closes
5166 - `*' completely opens the topic, including bodies.
5167 - `+' shows all the sub headers, but not the bodies
5168 - `-' exposes the body and immediate offspring of the corresponding topic.
5170 If the spec is a list, the first element must be a number, which
5171 dictates the exposure depth of the topic as a whole. Subsequent
5172 elements of the list are nested SPECs, dictating the specific exposure
5173 for the corresponding offspring of the topic.
5175 Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
5177 (interactive "xExposure spec: ")
5178 (let ((inhibit-field-text-motion t)
5179 (depth (allout-current-depth))
5180 max-pos)
5181 (cond ((null spec) nil)
5182 ((symbolp spec)
5183 (if (eq spec '*) (allout-show-current-subtree))
5184 (if (eq spec '+) (allout-show-current-branches))
5185 (if (eq spec '-) (allout-show-current-entry)))
5186 ((numberp spec)
5187 (if (>= 0 spec)
5188 (save-excursion (allout-hide-current-subtree t)
5189 (end-of-line)
5190 (if (or (not max-pos)
5191 (> (point) max-pos))
5192 (setq max-pos (point)))
5193 (if (> 0 spec)
5194 (setq spec (* -1 spec)))))
5195 (if (> spec 0)
5196 (allout-show-children spec)))
5197 ((listp spec)
5198 ;(let ((got (allout-old-expose-topic (car spec))))
5199 ; (if (and got (or (not max-pos) (> got max-pos)))
5200 ; (setq max-pos got)))
5201 (let ((new-depth (+ (allout-current-depth) 1))
5202 got)
5203 (setq max-pos (allout-old-expose-topic (car spec)))
5204 (setq spec (cdr spec))
5205 (if (and spec
5206 (allout-descend-to-depth new-depth)
5207 (not (allout-hidden-p)))
5208 (progn (setq got (apply 'allout-old-expose-topic spec))
5209 (if (and got (or (not max-pos) (> got max-pos)))
5210 (setq max-pos got)))))))
5211 (while (and followers
5212 (progn (if (and max-pos (< (point) max-pos))
5213 (progn (goto-char max-pos)
5214 (setq max-pos nil)))
5215 (end-of-line)
5216 (allout-next-sibling depth)))
5217 (allout-old-expose-topic (car followers))
5218 (setq followers (cdr followers)))
5219 max-pos))
5220 ;;;_ > allout-new-exposure '()
5221 (defmacro allout-new-exposure (&rest spec)
5222 "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
5223 Some arguments that would need to be quoted in `allout-expose-topic'
5224 need not be quoted in `allout-new-exposure'.
5226 Cursor is left at start position.
5228 Use this instead of obsolete `allout-exposure'.
5230 Examples:
5231 \(allout-new-exposure (-1 () () () 1) 0)
5232 Close current topic at current level so only the immediate
5233 subtopics are shown, except also show the children of the
5234 third subtopic; and close the next topic at the current level.
5235 \(allout-new-exposure : -1 0)
5236 Close all topics at current level to expose only their
5237 immediate children, except for the last topic at the current
5238 level, in which even its immediate children are hidden.
5239 \(allout-new-exposure -2 : -1 *)
5240 Expose children and grandchildren of first topic at current
5241 level, and expose children of subsequent topics at current
5242 level *except* for the last, which should be opened completely."
5243 (list 'save-excursion
5244 '(if (not (or (allout-goto-prefix-doublechecked)
5245 (allout-next-heading)))
5246 (error "allout-new-exposure: Can't find any outline topics"))
5247 (list 'allout-expose-topic (list 'quote spec))))
5249 ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
5251 ;;;_ - Mapping and processing of topics
5252 ;;;_ ( See also Subtree Charting, in Navigation code.)
5253 ;;;_ > allout-stringify-flat-index (flat-index)
5254 (defun allout-stringify-flat-index (flat-index &optional context)
5255 "Convert list representing section/subsection/... to document string.
5257 Optional arg CONTEXT indicates interior levels to include."
5258 (let ((delim ".")
5259 result
5260 numstr
5261 (context-depth (or (and context 2) 1)))
5262 ;; Take care of the explicit context:
5263 (while (> context-depth 0)
5264 (setq numstr (int-to-string (car flat-index))
5265 flat-index (cdr flat-index)
5266 result (if flat-index
5267 (cons delim (cons numstr result))
5268 (cons numstr result))
5269 context-depth (if flat-index (1- context-depth) 0)))
5270 (setq delim " ")
5271 ;; Take care of the indentation:
5272 (if flat-index
5273 (progn
5274 (while flat-index
5275 (setq result
5276 (cons delim
5277 (cons (make-string
5278 (1+ (truncate (if (zerop (car flat-index))
5280 (log10 (car flat-index)))))
5282 result)))
5283 (setq flat-index (cdr flat-index)))
5284 ;; Dispose of single extra delim:
5285 (setq result (cdr result))))
5286 (apply 'concat result)))
5287 ;;;_ > allout-stringify-flat-index-plain (flat-index)
5288 (defun allout-stringify-flat-index-plain (flat-index)
5289 "Convert list representing section/subsection/... to document string."
5290 (let ((delim ".")
5291 result)
5292 (while flat-index
5293 (setq result (cons (int-to-string (car flat-index))
5294 (if result
5295 (cons delim result))))
5296 (setq flat-index (cdr flat-index)))
5297 (apply 'concat result)))
5298 ;;;_ > allout-stringify-flat-index-indented (flat-index)
5299 (defun allout-stringify-flat-index-indented (flat-index)
5300 "Convert list representing section/subsection/... to document string."
5301 (let ((delim ".")
5302 result
5303 numstr)
5304 ;; Take care of the explicit context:
5305 (setq numstr (int-to-string (car flat-index))
5306 flat-index (cdr flat-index)
5307 result (if flat-index
5308 (cons delim (cons numstr result))
5309 (cons numstr result)))
5310 (setq delim " ")
5311 ;; Take care of the indentation:
5312 (if flat-index
5313 (progn
5314 (while flat-index
5315 (setq result
5316 (cons delim
5317 (cons (make-string
5318 (1+ (truncate (if (zerop (car flat-index))
5320 (log10 (car flat-index)))))
5322 result)))
5323 (setq flat-index (cdr flat-index)))
5324 ;; Dispose of single extra delim:
5325 (setq result (cdr result))))
5326 (apply 'concat result)))
5327 ;;;_ > allout-listify-exposed (&optional start end format)
5328 (defun allout-listify-exposed (&optional start end format)
5330 "Produce a list representing exposed topics in current region.
5332 This list can then be used by `allout-process-exposed' to manipulate
5333 the subject region.
5335 Optional START and END indicate bounds of region.
5337 Optional arg, FORMAT, designates an alternate presentation form for
5338 the prefix:
5340 list -- Present prefix as numeric section.subsection..., starting with
5341 section indicated by the list, innermost nesting first.
5342 `indent' (symbol) -- Convert header prefixes to all white space,
5343 except for distinctive bullets.
5345 The elements of the list produced are lists that represents a topic
5346 header and body. The elements of that list are:
5348 - a number representing the depth of the topic,
5349 - a string representing the header-prefix, including trailing whitespace and
5350 bullet.
5351 - a string representing the bullet character,
5352 - and a series of strings, each containing one line of the exposed
5353 portion of the topic entry."
5355 (interactive "r")
5356 (save-excursion
5357 (let*
5358 ((inhibit-field-text-motion t)
5359 ;; state vars:
5360 strings prefix result depth new-depth out gone-out bullet beg
5361 next done)
5363 (goto-char start)
5364 (beginning-of-line)
5365 ;; Goto initial topic, and register preceding stuff, if any:
5366 (if (> (allout-goto-prefix-doublechecked) start)
5367 ;; First topic follows beginning point -- register preliminary stuff:
5368 (setq result
5369 (list (list 0 "" nil
5370 (buffer-substring-no-properties start
5371 (1- (point)))))))
5372 (while (and (not done)
5373 (not (eobp)) ; Loop until we've covered the region.
5374 (not (> (point) end)))
5375 (setq depth allout-recent-depth ; Current topics depth,
5376 bullet (allout-recent-bullet) ; ... bullet,
5377 prefix (allout-recent-prefix)
5378 beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
5379 (setq done ; The boundary for the current topic:
5380 (not (allout-next-visible-heading 1)))
5381 (setq new-depth allout-recent-depth)
5382 (setq gone-out out
5383 out (< new-depth depth))
5384 (beginning-of-line)
5385 (setq next (point))
5386 (goto-char beg)
5387 (setq strings nil)
5388 (while (> next (point)) ; Get all the exposed text in
5389 (setq strings
5390 (cons (buffer-substring-no-properties
5392 ;To hidden text or end of line:
5393 (progn
5394 (end-of-line)
5395 (allout-back-to-visible-text)))
5396 strings))
5397 (when (< (point) next) ; Resume from after hid text, if any.
5398 (line-move 1)
5399 (beginning-of-line))
5400 (setq beg (point)))
5401 ;; Accumulate list for this topic:
5402 (setq strings (nreverse strings))
5403 (setq result
5404 (cons
5405 (if format
5406 (let ((special (if (string-match
5407 (regexp-quote bullet)
5408 allout-distinctive-bullets-string)
5409 bullet)))
5410 (cond ((listp format)
5411 (list depth
5412 (if allout-flattened-numbering-abbreviation
5413 (allout-stringify-flat-index format
5414 gone-out)
5415 (allout-stringify-flat-index-plain
5416 format))
5417 strings
5418 special))
5419 ((eq format 'indent)
5420 (if special
5421 (list depth
5422 (concat (make-string (1+ depth) ? )
5423 (substring prefix -1))
5424 strings)
5425 (list depth
5426 (make-string depth ? )
5427 strings)))
5428 (t (error "allout-listify-exposed: %s %s"
5429 "invalid format" format))))
5430 (list depth prefix strings))
5431 result))
5432 ;; Reasses format, if any:
5433 (if (and format (listp format))
5434 (cond ((= new-depth depth)
5435 (setq format (cons (1+ (car format))
5436 (cdr format))))
5437 ((> new-depth depth) ; descending -- assume by 1:
5438 (setq format (cons 1 format)))
5440 ; Pop the residue:
5441 (while (< new-depth depth)
5442 (setq format (cdr format))
5443 (setq depth (1- depth)))
5444 ; And increment the current one:
5445 (setq format
5446 (cons (1+ (or (car format)
5447 -1))
5448 (cdr format)))))))
5449 ;; Put the list with first at front, to last at back:
5450 (nreverse result))))
5451 ;;;_ > allout-region-active-p ()
5452 (defmacro allout-region-active-p ()
5453 (cond ((fboundp 'use-region-p) '(use-region-p))
5454 ((fboundp 'region-active-p) '(region-active-p))
5455 (t 'mark-active)))
5456 ;;_ > allout-process-exposed (&optional func from to frombuf
5457 ;;; tobuf format)
5458 (defun allout-process-exposed (&optional func from to frombuf tobuf
5459 format start-num)
5460 "Map function on exposed parts of current topic; results to another buffer.
5462 All args are options; default values itemized below.
5464 Apply FUNCTION to exposed portions FROM position TO position in buffer
5465 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
5466 alternate presentation form:
5468 `flat' -- Present prefix as numeric section.subsection..., starting with
5469 section indicated by the START-NUM, innermost nesting first.
5470 X`flat-indented' -- Prefix is like `flat' for first topic at each
5471 X level, but subsequent topics have only leaf topic
5472 X number, padded with blanks to line up with first.
5473 `indent' (symbol) -- Convert header prefixes to all white space,
5474 except for distinctive bullets.
5476 Defaults:
5477 FUNCTION: `allout-insert-listified'
5478 FROM: region start, if region active, else start of buffer
5479 TO: region end, if region active, else end of buffer
5480 FROMBUF: current buffer
5481 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
5482 FORMAT: nil"
5484 ; Resolve arguments,
5485 ; defaulting if necessary:
5486 (if (not func) (setq func 'allout-insert-listified))
5487 (if (not (and from to))
5488 (if (allout-region-active-p)
5489 (setq from (region-beginning) to (region-end))
5490 (setq from (point-min) to (point-max))))
5491 (if frombuf
5492 (if (not (bufferp frombuf))
5493 ;; Specified but not a buffer -- get it:
5494 (let ((got (get-buffer frombuf)))
5495 (if (not got)
5496 (error (concat "allout-process-exposed: source buffer "
5497 frombuf
5498 " not found."))
5499 (setq frombuf got))))
5500 ;; not specified -- default it:
5501 (setq frombuf (current-buffer)))
5502 (if tobuf
5503 (if (not (bufferp tobuf))
5504 (setq tobuf (get-buffer-create tobuf)))
5505 ;; not specified -- default it:
5506 (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
5507 (if (listp format)
5508 (nreverse format))
5510 (let* ((listified
5511 (progn (set-buffer frombuf)
5512 (allout-listify-exposed from to format))))
5513 (set-buffer tobuf)
5514 (mapc func listified)
5515 (pop-to-buffer tobuf)))
5517 ;;;_ - Copy exposed
5518 ;;;_ > allout-insert-listified (listified)
5519 (defun allout-insert-listified (listified)
5520 "Insert contents of listified outline portion in current buffer.
5522 LISTIFIED is a list representing each topic header and body:
5524 \`(depth prefix text)'
5526 or \`(depth prefix text bullet-plus)'
5528 If `bullet-plus' is specified, it is inserted just after the entire prefix."
5529 (setq listified (cdr listified))
5530 (let ((prefix (prog1
5531 (car listified)
5532 (setq listified (cdr listified))))
5533 (text (prog1
5534 (car listified)
5535 (setq listified (cdr listified))))
5536 (bullet-plus (car listified)))
5537 (insert prefix)
5538 (if bullet-plus (insert (concat " " bullet-plus)))
5539 (while text
5540 (insert (car text))
5541 (if (setq text (cdr text))
5542 (insert "\n")))
5543 (insert "\n")))
5544 ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
5545 (defun allout-copy-exposed-to-buffer (&optional arg tobuf format)
5546 "Duplicate exposed portions of current outline to another buffer.
5548 Other buffer has current buffers name with \" exposed\" appended to it.
5550 With repeat count, copy the exposed parts of only the current topic.
5552 Optional second arg TOBUF is target buffer name.
5554 Optional third arg FORMAT, if non-nil, symbolically designates an
5555 alternate presentation format for the outline:
5557 `flat' - Convert topic header prefixes to numeric
5558 section.subsection... identifiers.
5559 `indent' - Convert header prefixes to all white space, except for
5560 distinctive bullets.
5561 `indent-flat' - The best of both - only the first of each level has
5562 the full path, the rest have only the section number
5563 of the leaf, preceded by the right amount of indentation."
5565 (interactive "P")
5566 (if (not tobuf)
5567 (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*"))))
5568 (let* ((start-pt (point))
5569 (beg (if arg (allout-back-to-current-heading) (point-min)))
5570 (end (if arg (allout-end-of-current-subtree) (point-max)))
5571 (buf (current-buffer))
5572 (start-list ()))
5573 (if (eq format 'flat)
5574 (setq format (if arg (save-excursion
5575 (goto-char beg)
5576 (allout-topic-flat-index))
5577 '(1))))
5578 (with-current-buffer tobuf (erase-buffer))
5579 (allout-process-exposed 'allout-insert-listified
5582 (current-buffer)
5583 tobuf
5584 format start-list)
5585 (goto-char (point-min))
5586 (pop-to-buffer buf)
5587 (goto-char start-pt)))
5588 ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
5589 (defun allout-flatten-exposed-to-buffer (&optional arg tobuf)
5590 "Present numeric outline of outline's exposed portions in another buffer.
5592 The resulting outline is not compatible with outline mode -- use
5593 `allout-copy-exposed-to-buffer' if you want that.
5595 Use `allout-indented-exposed-to-buffer' for indented presentation.
5597 With repeat count, copy the exposed portions of only current topic.
5599 Other buffer has current buffer's name with \" exposed\" appended to
5600 it, unless optional second arg TOBUF is specified, in which case it is
5601 used verbatim."
5602 (interactive "P")
5603 (allout-copy-exposed-to-buffer arg tobuf 'flat))
5604 ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
5605 (defun allout-indented-exposed-to-buffer (&optional arg tobuf)
5606 "Present indented outline of outline's exposed portions in another buffer.
5608 The resulting outline is not compatible with outline mode -- use
5609 `allout-copy-exposed-to-buffer' if you want that.
5611 Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
5613 With repeat count, copy the exposed portions of only current topic.
5615 Other buffer has current buffer's name with \" exposed\" appended to
5616 it, unless optional second arg TOBUF is specified, in which case it is
5617 used verbatim."
5618 (interactive "P")
5619 (allout-copy-exposed-to-buffer arg tobuf 'indent))
5621 ;;;_ - LaTeX formatting
5622 ;;;_ > allout-latex-verb-quote (string &optional flow)
5623 (defun allout-latex-verb-quote (string &optional flow)
5624 "Return copy of STRING for literal reproduction across LaTeX processing.
5625 Expresses the original characters (including carriage returns) of the
5626 string across LaTeX processing."
5627 (mapconcat (function
5628 (lambda (char)
5629 (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
5630 (concat "\\char" (number-to-string char) "{}"))
5631 ((= char ?\n) "\\\\")
5632 (t (char-to-string char)))))
5633 string
5634 ""))
5635 ;;;_ > allout-latex-verbatim-quote-curr-line ()
5636 (defun allout-latex-verbatim-quote-curr-line ()
5637 "Express line for exact (literal) representation across LaTeX processing.
5639 Adjust line contents so it is unaltered (from the original line)
5640 across LaTeX processing, within the context of a `verbatim'
5641 environment. Leaves point at the end of the line."
5642 (let ((inhibit-field-text-motion t))
5643 (beginning-of-line)
5644 (let ((beg (point))
5645 (end (point-at-eol)))
5646 (save-match-data
5647 (while (re-search-forward "\\\\"
5648 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
5649 end ; bounded by end-of-line
5650 1) ; no matches, move to end & return nil
5651 (goto-char (match-beginning 2))
5652 (insert "\\")
5653 (setq end (1+ end))
5654 (goto-char (1+ (match-end 2))))))))
5655 ;;;_ > allout-insert-latex-header (buffer)
5656 (defun allout-insert-latex-header (buffer)
5657 "Insert initial LaTeX commands at point in BUFFER."
5658 ;; Much of this is being derived from the stuff in appendix of E in
5659 ;; the TeXBook, pg 421.
5660 (set-buffer buffer)
5661 (let ((doc-style (format "\n\\documentstyle{%s}\n"
5662 "report"))
5663 (page-numbering (if allout-number-pages
5664 "\\pagestyle{empty}\n"
5665 ""))
5666 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
5667 allout-title-style))
5668 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
5669 allout-label-style))
5670 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
5671 allout-head-line-style))
5672 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
5673 allout-body-line-style))
5674 (setlength (format "%s%s%s%s"
5675 "\\newlength{\\stepsize}\n"
5676 "\\setlength{\\stepsize}{"
5677 allout-indent
5678 "}\n"))
5679 (oneheadline (format "%s%s%s%s%s%s%s"
5680 "\\newcommand{\\OneHeadLine}[3]{%\n"
5681 "\\noindent%\n"
5682 "\\hspace*{#2\\stepsize}%\n"
5683 "\\labelcmd{#1}\\hspace*{.2cm}"
5684 "\\headlinecmd{#3}\\\\["
5685 allout-line-skip
5686 "]\n}\n"))
5687 (onebodyline (format "%s%s%s%s%s%s"
5688 "\\newcommand{\\OneBodyLine}[2]{%\n"
5689 "\\noindent%\n"
5690 "\\hspace*{#1\\stepsize}%\n"
5691 "\\bodylinecmd{#2}\\\\["
5692 allout-line-skip
5693 "]\n}\n"))
5694 (begindoc "\\begin{document}\n\\begin{center}\n")
5695 (title (format "%s%s%s%s"
5696 "\\titlecmd{"
5697 (allout-latex-verb-quote (if allout-title
5698 (condition-case nil
5699 (eval allout-title)
5700 (error "<unnamed buffer>"))
5701 "Unnamed Outline"))
5702 "}\n"
5703 "\\end{center}\n\n"))
5704 (hsize "\\hsize = 7.5 true in\n")
5705 (hoffset "\\hoffset = -1.5 true in\n")
5706 (vspace "\\vspace{.1cm}\n\n"))
5707 (insert (concat doc-style
5708 page-numbering
5709 titlecmd
5710 labelcmd
5711 headlinecmd
5712 bodylinecmd
5713 setlength
5714 oneheadline
5715 onebodyline
5716 begindoc
5717 title
5718 hsize
5719 hoffset
5720 vspace)
5722 ;;;_ > allout-insert-latex-trailer (buffer)
5723 (defun allout-insert-latex-trailer (buffer)
5724 "Insert concluding LaTeX commands at point in BUFFER."
5725 (set-buffer buffer)
5726 (insert "\n\\end{document}\n"))
5727 ;;;_ > allout-latexify-one-item (depth prefix bullet text)
5728 (defun allout-latexify-one-item (depth prefix bullet text)
5729 "Insert LaTeX commands for formatting one outline item.
5731 Args are the topics numeric DEPTH, the header PREFIX lead string, the
5732 BULLET string, and a list of TEXT strings for the body."
5733 (let* ((head-line (if text (car text)))
5734 (body-lines (cdr text))
5735 (curr-line)
5736 body-content bop)
5737 ; Do the head line:
5738 (insert (concat "\\OneHeadLine{\\verb\1 "
5739 (allout-latex-verb-quote bullet)
5740 "\1}{"
5741 depth
5742 "}{\\verb\1 "
5743 (if head-line
5744 (allout-latex-verb-quote head-line)
5746 "\1}\n"))
5747 (if (not body-lines)
5749 ;;(insert "\\beginlines\n")
5750 (insert "\\begin{verbatim}\n")
5751 (while body-lines
5752 (setq curr-line (car body-lines))
5753 (if (and (not body-content)
5754 (not (string-match "^\\s-*$" curr-line)))
5755 (setq body-content t))
5756 ; Mangle any occurrences of
5757 ; "\end{verbatim}" in text,
5758 ; it's special:
5759 (if (and body-content
5760 (setq bop (string-match "\\end{verbatim}" curr-line)))
5761 (setq curr-line (concat (substring curr-line 0 bop)
5763 (substring curr-line bop))))
5764 ;;(insert "|" (car body-lines) "|")
5765 (insert curr-line)
5766 (allout-latex-verbatim-quote-curr-line)
5767 (insert "\n")
5768 (setq body-lines (cdr body-lines)))
5769 (if body-content
5770 (setq body-content nil)
5771 (forward-char -1)
5772 (insert "\\ ")
5773 (forward-char 1))
5774 ;;(insert "\\endlines\n")
5775 (insert "\\end{verbatim}\n")
5777 ;;;_ > allout-latexify-exposed (arg &optional tobuf)
5778 (defun allout-latexify-exposed (arg &optional tobuf)
5779 "Format current topics exposed portions to TOBUF for LaTeX processing.
5780 TOBUF defaults to a buffer named the same as the current buffer, but
5781 with \"*\" prepended and \" latex-formed*\" appended.
5783 With repeat count, copy the exposed portions of entire buffer."
5785 (interactive "P")
5786 (if (not tobuf)
5787 (setq tobuf
5788 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
5789 (let* ((start-pt (point))
5790 (beg (if arg (point-min) (allout-back-to-current-heading)))
5791 (end (if arg (point-max) (allout-end-of-current-subtree)))
5792 (buf (current-buffer)))
5793 (set-buffer tobuf)
5794 (erase-buffer)
5795 (allout-insert-latex-header tobuf)
5796 (goto-char (point-max))
5797 (allout-process-exposed 'allout-latexify-one-item
5801 tobuf)
5802 (goto-char (point-max))
5803 (allout-insert-latex-trailer tobuf)
5804 (goto-char (point-min))
5805 (pop-to-buffer buf)
5806 (goto-char start-pt)))
5808 ;;;_ #8 Encryption
5809 ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue)
5810 (defun allout-toggle-current-subtree-encryption (&optional keymode-cue)
5811 "Encrypt clear or decrypt encoded topic text.
5813 Allout uses emacs 'epg' libary to perform encryption. Symmetric
5814 and keypair encryption are supported. All encryption is ascii
5815 armored.
5817 Entry encryption defaults to symmetric key mode unless keypair
5818 recipients are associated with the file \(see
5819 `epa-file-encrypt-to') or the function is invoked with a
5820 \(KEYMODE-CUE) universal argument greater than 1.
5822 When encrypting, KEYMODE-CUE universal argument greater than 1
5823 causes prompting for recipients for public-key keypair
5824 encryption. Selecting no recipients results in symmetric key
5825 encryption.
5827 Further, encrypting with a KEYMODE-CUE universal argument greater
5828 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5829 the specified recipients with the file, replacing those currently
5830 associated with it. This can be used to deassociate any
5831 recipients with the file, by selecting no recipients in the
5832 dialog.
5834 Encrypted topic's bullets are set to a `~' to signal that the
5835 contents of the topic (body and subtopics, but not heading) is
5836 pending encryption or encrypted. `*' asterisk immediately after
5837 the bullet signals that the body is encrypted, its absence means
5838 the topic is meant to be encrypted but is not currently. When a
5839 file with topics pending encryption is saved, topics pending
5840 encryption are encrypted. See allout-encrypt-unencrypted-on-saves
5841 for auto-encryption specifics.
5843 \*NOTE WELL* that automatic encryption that happens during saves will
5844 default to symmetric encryption -- you must deliberately (re)encrypt key-pair
5845 encrypted topics if you want them to continue to use the key-pair cipher.
5847 Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
5848 encrypted. If you want to encrypt the contents of a top-level topic, use
5849 \\[allout-shift-in] to increase its depth."
5850 (interactive "P")
5851 (save-excursion
5852 (allout-back-to-current-heading)
5853 (allout-toggle-subtree-encryption keymode-cue)))
5854 ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue)
5855 (defun allout-toggle-subtree-encryption (&optional keymode-cue)
5856 "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
5858 Entry encryption defaults to symmetric key mode unless keypair
5859 recipients are associated with the file \(see
5860 `epa-file-encrypt-to') or the function is invoked with a
5861 \(KEYMODE-CUE) universal argument greater than 1.
5863 When encrypting, KEYMODE-CUE universal argument greater than 1
5864 causes prompting for recipients for public-key keypair
5865 encryption. Selecting no recipients results in symmetric key
5866 encryption.
5868 Further, encrypting with a KEYMODE-CUE universal argument greater
5869 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5870 the specified recipients with the file, replacing those currently
5871 associated with it. This can be used to deassociate any
5872 recipients with the file, by selecting no recipients in the
5873 dialog.
5875 Encryption and decryption uses the emacs epg library.
5877 Encrypted text will be ascii-armored.
5879 See `allout-toggle-current-subtree-encryption' for more details."
5881 (interactive "P")
5882 (save-excursion
5883 (allout-end-of-prefix t)
5885 (if (= allout-recent-depth 1)
5886 (error (concat "Cannot encrypt or decrypt level 1 topics -"
5887 " shift it in to make it encryptable")))
5889 (let* ((allout-buffer (current-buffer))
5890 ;; Assess location:
5891 (bullet-pos allout-recent-prefix-beginning)
5892 (after-bullet-pos (point))
5893 (was-encrypted
5894 (progn (if (= (point-max) after-bullet-pos)
5895 (error "no body to encrypt"))
5896 (allout-encrypted-topic-p)))
5897 (was-collapsed (if (not (search-forward "\n" nil t))
5899 (backward-char 1)
5900 (allout-hidden-p)))
5901 (subtree-beg (1+ (point)))
5902 (subtree-end (allout-end-of-subtree))
5903 (subject-text (buffer-substring-no-properties subtree-beg
5904 subtree-end))
5905 (subtree-end-char (char-after (1- subtree-end)))
5906 (subtree-trailing-char (char-after subtree-end))
5907 ;; kluge -- result-text needs to be nil, but we also want to
5908 ;; check for the error condition
5909 (result-text (if (or (string= "" subject-text)
5910 (string= "\n" subject-text))
5911 (error "No topic contents to %scrypt"
5912 (if was-encrypted "de" "en"))
5913 nil))
5914 ;; Assess key parameters:
5915 (was-coding-system buffer-file-coding-system))
5917 (when (not was-encrypted)
5918 ;; ensure that non-ascii chars pending encryption are noticed before
5919 ;; they're encrypted, so the coding system is set to accommodate
5920 ;; them.
5921 (setq buffer-file-coding-system
5922 (allout-select-safe-coding-system subtree-beg subtree-end))
5923 ;; if the coding system for the text being encrypted is different
5924 ;; than that prevailing, then there a real risk that the coding
5925 ;; system can't be noticed by emacs when the file is visited. to
5926 ;; mitigate that, offer to preserve the coding system using a file
5927 ;; local variable.
5928 (if (and (not (equal buffer-file-coding-system
5929 was-coding-system))
5930 (yes-or-no-p
5931 (format (concat "Register coding system %s as file local"
5932 " var? Necessary when only encrypted text"
5933 " is in that coding system. ")
5934 buffer-file-coding-system)))
5935 (allout-adjust-file-variable "buffer-file-coding-system"
5936 buffer-file-coding-system)))
5938 (setq result-text
5939 (allout-encrypt-string subject-text was-encrypted
5940 (current-buffer) keymode-cue))
5942 ;; Replace the subtree with the processed product.
5943 (allout-unprotected
5944 (progn
5945 (set-buffer allout-buffer)
5946 (delete-region subtree-beg subtree-end)
5947 (insert result-text)
5948 (if was-collapsed
5949 (allout-flag-region (1- subtree-beg) (point) t))
5950 ;; adjust trailing-blank-lines to preserve topic spacing:
5951 (if (not was-encrypted)
5952 (if (and (= subtree-end-char ?\n)
5953 (= subtree-trailing-char ?\n))
5954 (insert subtree-trailing-char)))
5955 ;; Ensure that the item has an encrypted-entry bullet:
5956 (if (not (string= (buffer-substring-no-properties
5957 (1- after-bullet-pos) after-bullet-pos)
5958 allout-topic-encryption-bullet))
5959 (progn (goto-char (1- after-bullet-pos))
5960 (delete-char 1)
5961 (insert allout-topic-encryption-bullet)))
5962 (if was-encrypted
5963 ;; Remove the is-encrypted bullet qualifier:
5964 (progn (goto-char after-bullet-pos)
5965 (delete-char 1))
5966 ;; Add the is-encrypted bullet qualifier:
5967 (goto-char after-bullet-pos)
5968 (insert "*"))))
5969 (run-hook-with-args 'allout-structure-added-hook
5970 bullet-pos subtree-end))))
5971 ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
5972 ;;; &optional rejected)
5973 (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue
5974 &optional rejected)
5975 "Encrypt or decrypt message TEXT.
5977 Returns the resulting string, or nil if the transformation fails.
5979 If DECRYPT is true (default false), then decrypt instead of encrypt.
5981 ALLOUT-BUFFER identifies the buffer containing the text.
5983 Entry encryption defaults to symmetric key mode unless keypair
5984 recipients are associated with the file \(see
5985 `epa-file-encrypt-to') or the function is invoked with a
5986 \(KEYMODE-CUE) universal argument greater than 1.
5988 When encrypting, KEYMODE-CUE universal argument greater than 1
5989 causes prompting for recipients for public-key keypair
5990 encryption. Selecting no recipients results in symmetric key
5991 encryption.
5993 Further, encrypting with a KEYMODE-CUE universal argument greater
5994 than 4 - eg, preceded by a doubled Ctrl-U - causes association of
5995 the specified recipients with the file, replacing those currently
5996 associated with it. This can be used to deassociate any
5997 recipients with the file, by selecting no recipients in the
5998 dialog.
6000 Optional REJECTED is for internal use, to convey the number of
6001 rejections due to matches against
6002 `allout-encryption-ciphertext-rejection-regexps', as limited by
6003 `allout-encryption-ciphertext-rejection-ceiling'.
6005 NOTE: A few GnuPG v2 versions improperly preserve incorrect
6006 symmetric decryption keys, preventing entry of the correct key on
6007 subsequent decryption attempts until the cache times-out. That
6008 can take several minutes. \(Decryption of other entries is not
6009 affected.) Upgrade your EasyPG version, if you can, and you can
6010 deliberately clear your gpg-agent's cache by sending it a '-HUP'
6011 signal."
6013 (require 'epg)
6014 (require 'epa)
6016 (let* ((epg-context (let* ((context (epg-make-context nil t)))
6017 (epg-context-set-passphrase-callback
6018 context #'epa-passphrase-callback-function)
6019 context))
6020 (encoding (with-current-buffer allout-buffer
6021 buffer-file-coding-system))
6022 (multibyte (with-current-buffer allout-buffer
6023 enable-multibyte-characters))
6024 ;; "sanitization" avoids encryption results that are outline structure.
6025 (sani-regexps 'allout-encryption-plaintext-sanitization-regexps)
6026 (strip-plaintext-regexps (if (not decrypt)
6027 (allout-get-configvar-values
6028 sani-regexps)))
6029 (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps)
6030 (reject-ciphertext-regexps (if (not decrypt)
6031 (allout-get-configvar-values
6032 rejection-regexps)))
6033 (rejected (or rejected 0))
6034 (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
6035 rejected))
6036 (keypair-mode (cond (decrypt 'decrypting)
6037 ((<= (prefix-numeric-value keymode-cue) 1)
6038 'default)
6039 ((<= (prefix-numeric-value keymode-cue) 4)
6040 'prompt)
6041 ((> (prefix-numeric-value keymode-cue) 4)
6042 'prompt-save)))
6043 (keypair-message (concat "Select encryption recipients.\n"
6044 "Symmetric encryption is done if no"
6045 " recipients are selected. "))
6046 (encrypt-to (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to))
6047 recipients
6048 massaged-text
6049 result-text
6052 ;; Massage the subject text for encoding and filtering.
6053 (with-temp-buffer
6054 (insert text)
6055 ;; convey the text characteristics of the original buffer:
6056 (set-buffer-multibyte multibyte)
6057 (when encoding
6058 (set-buffer-file-coding-system encoding)
6059 (if (not decrypt)
6060 (encode-coding-region (point-min) (point-max) encoding)))
6062 ;; remove sanitization regexps matches before encrypting:
6063 (when (and strip-plaintext-regexps (not decrypt))
6064 (dolist (re strip-plaintext-regexps)
6065 (let ((re (if (listp re) (car re) re))
6066 (replacement (if (listp re) (cadr re) "")))
6067 (goto-char (point-min))
6068 (save-match-data
6069 (while (re-search-forward re nil t)
6070 (replace-match replacement nil nil))))))
6071 (setq massaged-text (buffer-substring-no-properties (point-min)
6072 (point-max))))
6073 ;; determine key mode and, if keypair, recipients:
6074 (setq recipients
6075 (case keypair-mode
6077 (decrypting nil)
6079 (default (if encrypt-to (epg-list-keys epg-context encrypt-to)))
6081 ((prompt prompt-save)
6082 (save-window-excursion
6083 (epa-select-keys epg-context keypair-message)))))
6085 (setq result-text
6086 (if decrypt
6087 (condition-case err
6088 (epg-decrypt-string epg-context
6089 (encode-coding-string massaged-text
6090 (or encoding 'utf-8)))
6091 (epg-error
6092 (signal 'egp-error
6093 (cons (concat (cadr err) " - gpg version problem?")
6094 (cddr err)))))
6095 (replace-regexp-in-string "\n$" ""
6096 (epg-encrypt-string epg-context
6097 (encode-coding-string massaged-text
6098 (or encoding 'utf-8))
6099 recipients))))
6101 ;; validate result -- non-empty
6102 (if (not result-text)
6103 (error "%scryption failed." (if decrypt "De" "En")))
6106 (when (eq keypair-mode 'prompt-save)
6107 ;; set epa-file-encrypt-to in the buffer:
6108 (setq epa-file-encrypt-to (mapcar (lambda (key)
6109 (epg-user-id-string
6110 (car (epg-key-user-id-list key))))
6111 recipients))
6112 ;; change the file variable:
6113 (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to))
6115 (cond
6116 ;; Retry (within limit) if ciphertext contains rejections:
6117 ((and (not decrypt)
6118 ;; Check for disqualification of this ciphertext:
6119 (let ((regexps reject-ciphertext-regexps)
6120 reject-it)
6121 (while (and regexps (not reject-it))
6122 (setq reject-it (string-match (car regexps) result-text))
6123 (pop regexps))
6124 reject-it))
6125 (setq rejections-left (1- rejections-left))
6126 (if (<= rejections-left 0)
6127 (error (concat "Ciphertext rejected too many times"
6128 " (%s), per `%s'")
6129 allout-encryption-ciphertext-rejection-ceiling
6130 'allout-encryption-ciphertext-rejection-regexps)
6131 ;; try again (gpg-agent may have the key cached):
6132 (allout-encrypt-string text decrypt allout-buffer keypair-mode
6133 (1+ rejected))))
6135 ;; Barf if encryption yields extraordinary control chars:
6136 ((and (not decrypt)
6137 (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
6138 result-text))
6139 (error (concat "Encryption produced non-armored text, which"
6140 "conflicts with allout mode -- reconfigure!")))
6142 (t result-text))))
6143 ;;;_ > allout-encrypted-topic-p ()
6144 (defun allout-encrypted-topic-p ()
6145 "True if the current topic is encryptable and encrypted."
6146 (save-excursion
6147 (allout-end-of-prefix t)
6148 (and (string= (buffer-substring-no-properties (1- (point)) (point))
6149 allout-topic-encryption-bullet)
6150 (save-match-data (looking-at "\\*")))
6153 ;;;_ > allout-next-topic-pending-encryption (&optional except-mark)
6154 (defun allout-next-topic-pending-encryption (&optional except-mark)
6155 "Return the point of the next topic pending encryption, or nil if none.
6157 EXCEPT-MARK identifies a point whose containing topics should be excluded
6158 from encryption. This supports 'except-current mode of
6159 `allout-encrypt-unencrypted-on-saves'.
6161 Such a topic has the `allout-topic-encryption-bullet' without an
6162 immediately following '*' that would mark the topic as being encrypted. It
6163 must also have content."
6164 (let (done got content-beg)
6165 (save-match-data
6166 (while (not done)
6168 (if (not (re-search-forward
6169 (format "\\(\\`\\|\n\\)%s *%s[^*]"
6170 (regexp-quote allout-header-prefix)
6171 (regexp-quote allout-topic-encryption-bullet))
6172 nil t))
6173 (setq got nil
6174 done t)
6175 (goto-char (setq got (match-beginning 0)))
6176 (if (save-match-data (looking-at "\n"))
6177 (forward-char 1))
6178 (setq got (point)))
6180 (cond ((not got)
6181 (setq done t))
6183 ((not (search-forward "\n"))
6184 (setq got nil
6185 done t))
6187 ((eobp)
6188 (setq got nil
6189 done t))
6192 (setq content-beg (point))
6193 (backward-char 1)
6194 (allout-end-of-subtree)
6195 (if (or (<= (point) content-beg)
6196 (and except-mark
6197 (<= content-beg except-mark)
6198 (>= (point) except-mark)))
6199 ;; Continue looking
6200 (setq got nil)
6201 ;; Got it!
6202 (setq done t)))
6205 (if got
6206 (goto-char got))
6210 ;;;_ > allout-encrypt-decrypted (&optional except-mark)
6211 (defun allout-encrypt-decrypted (&optional except-mark)
6212 "Encrypt topics pending encryption except those containing exemption point.
6214 EXCEPT-MARK identifies a point whose containing topics should be excluded
6215 from encryption. This supports the `except-current' mode of
6216 `allout-encrypt-unencrypted-on-saves'.
6218 If a topic that is currently being edited was encrypted, we return a list
6219 containing the location of the topic and the location of the cursor just
6220 before the topic was encrypted. This can be used, eg, to decrypt the topic
6221 and exactly resituate the cursor if this is being done as part of a file
6222 save. See `allout-encrypt-unencrypted-on-saves' for more info."
6224 (interactive "p")
6225 (save-match-data
6226 (save-excursion
6227 (let* ((current-mark (point-marker))
6228 (current-mark-position (marker-position current-mark))
6229 was-modified
6230 bo-subtree
6231 editing-topic editing-point)
6232 (goto-char (point-min))
6233 (while (allout-next-topic-pending-encryption except-mark)
6234 (setq was-modified (buffer-modified-p))
6235 (when (save-excursion
6236 (and (boundp 'allout-encrypt-unencrypted-on-saves)
6237 allout-encrypt-unencrypted-on-saves
6238 (setq bo-subtree (re-search-forward "$"))
6239 (not (allout-hidden-p))
6240 (>= current-mark (point))
6241 (allout-end-of-current-subtree)
6242 (<= current-mark (point))))
6243 (setq editing-topic (point)
6244 ;; we had to wait for this 'til now so prior topics are
6245 ;; encrypted, any relevant text shifts are in place:
6246 editing-point (- current-mark-position
6247 (count-trailing-whitespace-region
6248 bo-subtree current-mark-position))))
6249 (allout-toggle-subtree-encryption)
6250 (if (not was-modified)
6251 (set-buffer-modified-p nil))
6253 (if (not was-modified)
6254 (set-buffer-modified-p nil))
6255 (if editing-topic (list editing-topic editing-point))
6261 ;;;_ #9 miscellaneous
6262 ;;;_ : Mode:
6263 ;;;_ > outlineify-sticky ()
6264 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
6265 ;;;###autoload
6266 (defalias 'outlinify-sticky 'outlineify-sticky)
6267 ;;;###autoload
6268 (defun outlineify-sticky (&optional arg)
6269 "Activate outline mode and establish file var so it is started subsequently.
6271 See `allout-layout' and customization of `allout-auto-activation'
6272 for details on preparing emacs for automatic allout activation."
6274 (interactive "P")
6276 (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
6277 (allout-mode)
6279 (save-excursion
6280 (goto-char (point-min))
6281 (if (allout-goto-prefix)
6283 (allout-open-topic 2)
6284 (insert (concat "Dummy outline topic header -- see"
6285 "`allout-mode' docstring: `^Hm'."))
6286 (allout-adjust-file-variable
6287 "allout-layout" (or allout-layout '(-1 : 0))))))
6288 ;;;_ > allout-file-vars-section-data ()
6289 (defun allout-file-vars-section-data ()
6290 "Return data identifying the file-vars section, or nil if none.
6292 Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
6293 ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
6294 (let (beg prefix suffix)
6295 (save-excursion
6296 (goto-char (point-max))
6297 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
6298 (if (let ((case-fold-search t))
6299 (not (search-forward "Local Variables:" nil t)))
6301 (setq beg (- (point) 16))
6302 (setq suffix (buffer-substring-no-properties
6303 (point)
6304 (progn (if (search-forward "\n" nil t)
6305 (forward-char -1))
6306 (point))))
6307 (setq prefix (buffer-substring-no-properties
6308 (progn (if (search-backward "\n" nil t)
6309 (forward-char 1))
6310 (point))
6311 beg))
6312 (list beg prefix suffix))
6316 ;;;_ > allout-adjust-file-variable (varname value)
6317 (defun allout-adjust-file-variable (varname value)
6318 "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
6320 This activity is inhibited if either `enable-local-variables'
6321 `allout-enable-file-variable-adjustment' are nil.
6323 When enabled, an entry for the variable is created if not already present,
6324 or changed if established with a different value. The section for the file
6325 variables, itself, is created if not already present. When created, the
6326 section lines (including the section line) exist as second-level topics in
6327 a top-level topic at the end of the file.
6329 `enable-local-variables' must be true for any of this to happen."
6330 (if (not (and enable-local-variables
6331 allout-enable-file-variable-adjustment))
6333 (save-excursion
6334 (let ((inhibit-field-text-motion t)
6335 (section-data (allout-file-vars-section-data))
6336 beg prefix suffix)
6337 (if section-data
6338 (setq beg (car section-data)
6339 prefix (cadr section-data)
6340 suffix (car (cddr section-data)))
6341 ;; create the section
6342 (goto-char (point-max))
6343 (open-line 1)
6344 (allout-open-topic 0)
6345 (end-of-line)
6346 (insert "Local emacs vars.\n")
6347 (allout-open-topic 1)
6348 (setq beg (point)
6349 suffix ""
6350 prefix (buffer-substring-no-properties (progn
6351 (beginning-of-line)
6352 (point))
6353 beg))
6354 (goto-char beg)
6355 (insert "Local variables:\n")
6356 (allout-open-topic 0)
6357 (insert "End:\n")
6359 ;; look for existing entry or create one, leaving point for insertion
6360 ;; of new value:
6361 (goto-char beg)
6362 (allout-show-to-offshoot)
6363 (if (search-forward (concat "\n" prefix varname ":") nil t)
6364 (let* ((value-beg (point))
6365 (line-end (progn (if (search-forward "\n" nil t)
6366 (forward-char -1))
6367 (point)))
6368 (value-end (- line-end (length suffix))))
6369 (if (> value-end value-beg)
6370 (delete-region value-beg value-end)))
6371 (end-of-line)
6372 (open-line 1)
6373 (forward-line 1)
6374 (insert (concat prefix varname ":")))
6375 (insert (format " %S%s" value suffix))
6380 ;;;_ > allout-get-configvar-values (varname)
6381 (defun allout-get-configvar-values (configvar-name)
6382 "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
6384 The user is prompted for removal of symbols that are unbound, and they
6385 otherwise are ignored.
6387 CONFIGVAR-NAME should be the name of the configuration variable,
6388 not its value."
6390 (let ((configvar-value (symbol-value configvar-name))
6391 got)
6392 (dolist (sym configvar-value)
6393 (if (not (boundp sym))
6394 (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? "
6395 configvar-name sym))
6396 (delq sym (symbol-value configvar-name)))
6397 (push (symbol-value sym) got)))
6398 (reverse got)))
6399 ;;;_ : Topics:
6400 ;;;_ > allout-mark-topic ()
6401 (defun allout-mark-topic ()
6402 "Put the region around topic currently containing point."
6403 (interactive)
6404 (let ((inhibit-field-text-motion t))
6405 (beginning-of-line))
6406 (allout-goto-prefix-doublechecked)
6407 (push-mark (point))
6408 (allout-end-of-current-subtree)
6409 (exchange-point-and-mark))
6410 ;;;_ : UI:
6411 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
6412 (defun solicit-char-in-string (prompt string &optional do-defaulting)
6413 "Solicit (with first arg PROMPT) choice of a character from string STRING.
6415 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
6417 (let ((new-prompt prompt)
6418 got)
6420 (while (not got)
6421 (message "%s" new-prompt)
6423 ;; We do our own reading here, so we can circumvent, eg, special
6424 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
6425 (setq got
6426 (char-to-string (let ((cursor-in-echo-area nil)) (read-char))))
6428 (setq got
6429 (cond ((string-match (regexp-quote got) string) got)
6430 ((and do-defaulting (string= got "\r"))
6431 ;; Return empty string to default:
6433 ((string= got "\C-g") (signal 'quit nil))
6435 (setq new-prompt (concat prompt
6437 " ...pick from: "
6438 string
6439 ""))
6440 nil))))
6441 ;; got something out of loop -- return it:
6442 got)
6444 ;;;_ : Strings:
6445 ;;;_ > regexp-sans-escapes (string)
6446 (defun regexp-sans-escapes (regexp &optional successive-backslashes)
6447 "Return a copy of REGEXP with all character escapes stripped out.
6449 Representations of actual backslashes -- '\\\\\\\\' -- are left as a
6450 single backslash.
6452 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
6454 (if (string= regexp "")
6456 ;; Set successive-backslashes to number if current char is
6457 ;; backslash, or else to nil:
6458 (setq successive-backslashes
6459 (if (= (aref regexp 0) ?\\)
6460 (if successive-backslashes (1+ successive-backslashes) 1)
6461 nil))
6462 (if (or (not successive-backslashes) (= 2 successive-backslashes))
6463 ;; Include first char:
6464 (concat (substring regexp 0 1)
6465 (regexp-sans-escapes (substring regexp 1)))
6466 ;; Exclude first char, but maintain count:
6467 (regexp-sans-escapes (substring regexp 1) successive-backslashes))))
6468 ;;;_ > count-trailing-whitespace-region (beg end)
6469 (defun count-trailing-whitespace-region (beg end)
6470 "Return number of trailing whitespace chars between BEG and END.
6472 If BEG is bigger than END we return 0."
6473 (if (> beg end)
6475 (save-match-data
6476 (save-excursion
6477 (goto-char beg)
6478 (let ((count 0))
6479 (while (re-search-forward "[ ][ ]*$" end t)
6480 (goto-char (1+ (match-beginning 2)))
6481 (setq count (1+ count)))
6482 count)))))
6483 ;;;_ > allout-format-quote (string)
6484 (defun allout-format-quote (string)
6485 "Return a copy of string with all \"%\" characters doubled."
6486 (apply 'concat
6487 (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char)))
6488 string)))
6489 ;;;_ : lists
6490 ;;;_ > allout-flatten (list)
6491 (defun allout-flatten (list)
6492 "Return a list of all atoms in list."
6493 ;; classic.
6494 (cond ((null list) nil)
6495 ((atom (car list)) (cons (car list) (allout-flatten (cdr list))))
6496 (t (append (allout-flatten (car list)) (allout-flatten (cdr list))))))
6497 ;;;_ : Compatibility:
6498 ;;;_ : xemacs undo-in-progress provision:
6499 (unless (boundp 'undo-in-progress)
6500 (defvar undo-in-progress nil
6501 "Placeholder defvar for XEmacs compatibility from allout.el.")
6502 (defadvice undo-more (around allout activate)
6503 ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
6504 (let ((undo-in-progress t)) ad-do-it)))
6506 ;;;_ > allout-mark-marker to accommodate divergent emacsen:
6507 (defun allout-mark-marker (&optional force buffer)
6508 "Accommodate the different signature for `mark-marker' across Emacsen.
6510 XEmacs takes two optional args, while Emacs does not,
6511 so pass them along when appropriate."
6512 (if (featurep 'xemacs)
6513 (apply 'mark-marker force buffer)
6514 (mark-marker)))
6515 ;;;_ > subst-char-in-string if necessary
6516 (if (not (fboundp 'subst-char-in-string))
6517 (defun subst-char-in-string (fromchar tochar string &optional inplace)
6518 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
6519 Unless optional argument INPLACE is non-nil, return a new string."
6520 (let ((i (length string))
6521 (newstr (if inplace string (copy-sequence string))))
6522 (while (> i 0)
6523 (setq i (1- i))
6524 (if (eq (aref newstr i) fromchar)
6525 (aset newstr i tochar)))
6526 newstr)))
6527 ;;;_ > wholenump if necessary
6528 (if (not (fboundp 'wholenump))
6529 (defalias 'wholenump 'natnump))
6530 ;;;_ > remove-overlays if necessary
6531 (if (not (fboundp 'remove-overlays))
6532 (defun remove-overlays (&optional beg end name val)
6533 "Clear BEG and END of overlays whose property NAME has value VAL.
6534 Overlays might be moved and/or split.
6535 BEG and END default respectively to the beginning and end of buffer."
6536 (unless beg (setq beg (point-min)))
6537 (unless end (setq end (point-max)))
6538 (if (< end beg)
6539 (setq beg (prog1 end (setq end beg))))
6540 (save-excursion
6541 (dolist (o (overlays-in beg end))
6542 (when (eq (overlay-get o name) val)
6543 ;; Either push this overlay outside beg...end
6544 ;; or split it to exclude beg...end
6545 ;; or delete it entirely (if it is contained in beg...end).
6546 (if (< (overlay-start o) beg)
6547 (if (> (overlay-end o) end)
6548 (progn
6549 (move-overlay (copy-overlay o)
6550 (overlay-start o) beg)
6551 (move-overlay o end (overlay-end o)))
6552 (move-overlay o (overlay-start o) beg))
6553 (if (> (overlay-end o) end)
6554 (move-overlay o end (overlay-end o))
6555 (delete-overlay o)))))))
6557 ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
6558 (if (not (fboundp 'copy-overlay))
6559 (defun copy-overlay (o)
6560 "Return a copy of overlay O."
6561 (let ((o1 (make-overlay (overlay-start o) (overlay-end o)
6562 ;; FIXME: there's no easy way to find the
6563 ;; insertion-type of the two markers.
6564 (overlay-buffer o)))
6565 (props (overlay-properties o)))
6566 (while props
6567 (overlay-put o1 (pop props) (pop props)))
6568 o1)))
6569 ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
6570 (if (not (fboundp 'add-to-invisibility-spec))
6571 (defun add-to-invisibility-spec (element)
6572 "Add ELEMENT to `buffer-invisibility-spec'.
6573 See documentation for `buffer-invisibility-spec' for the kind of elements
6574 that can be added."
6575 (if (eq buffer-invisibility-spec t)
6576 (setq buffer-invisibility-spec (list t)))
6577 (setq buffer-invisibility-spec
6578 (cons element buffer-invisibility-spec))))
6579 ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
6580 (if (not (fboundp 'remove-from-invisibility-spec))
6581 (defun remove-from-invisibility-spec (element)
6582 "Remove ELEMENT from `buffer-invisibility-spec'."
6583 (if (consp buffer-invisibility-spec)
6584 (setq buffer-invisibility-spec (delete element
6585 buffer-invisibility-spec)))))
6586 ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
6587 (if (not (fboundp 'move-beginning-of-line))
6588 (defun move-beginning-of-line (arg)
6589 "Move point to beginning of current line as displayed.
6590 \(This disregards invisible newlines such as those
6591 which are part of the text that an image rests on.)
6593 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6594 If point reaches the beginning or end of buffer, it stops there.
6595 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6596 (interactive "p")
6597 (or arg (setq arg 1))
6598 (if (/= arg 1)
6599 (condition-case nil (line-move (1- arg)) (error nil)))
6601 ;; Move to beginning-of-line, ignoring fields and invisibles.
6602 (skip-chars-backward "^\n")
6603 (while (and (not (bobp))
6604 (let ((prop
6605 (get-char-property (1- (point)) 'invisible)))
6606 (if (eq buffer-invisibility-spec t)
6607 prop
6608 (or (memq prop buffer-invisibility-spec)
6609 (assq prop buffer-invisibility-spec)))))
6610 (goto-char (if (featurep 'xemacs)
6611 (previous-property-change (point))
6612 (previous-char-property-change (point))))
6613 (skip-chars-backward "^\n"))
6614 (vertical-motion 0))
6616 ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
6617 (if (not (fboundp 'move-end-of-line))
6618 (defun move-end-of-line (arg)
6619 "Move point to end of current line as displayed.
6620 \(This disregards invisible newlines such as those
6621 which are part of the text that an image rests on.)
6623 With argument ARG not nil or 1, move forward ARG - 1 lines first.
6624 If point reaches the beginning or end of buffer, it stops there.
6625 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
6626 (interactive "p")
6627 (or arg (setq arg 1))
6628 (let (done)
6629 (while (not done)
6630 (let ((newpos
6631 (save-excursion
6632 (let ((goal-column 0))
6633 (and (condition-case nil
6634 (or (line-move arg) t)
6635 (error nil))
6636 (not (bobp))
6637 (progn
6638 (while
6639 (and
6640 (not (bobp))
6641 (let ((prop
6642 (get-char-property (1- (point))
6643 'invisible)))
6644 (if (eq buffer-invisibility-spec t)
6645 prop
6646 (or (memq prop
6647 buffer-invisibility-spec)
6648 (assq prop
6649 buffer-invisibility-spec)))))
6650 (goto-char
6651 (previous-char-property-change (point))))
6652 (backward-char 1)))
6653 (point)))))
6654 (goto-char newpos)
6655 (if (and (> (point) newpos)
6656 (eq (preceding-char) ?\n))
6657 (backward-char 1)
6658 (if (and (> (point) newpos) (not (eobp))
6659 (not (eq (following-char) ?\n)))
6660 ;; If we skipped something intangible
6661 ;; and now we're not really at eol,
6662 ;; keep going.
6663 (setq arg 1)
6664 (setq done t)))))))
6666 ;;;_ > allout-next-single-char-property-change -- alias unless lacking
6667 (defalias 'allout-next-single-char-property-change
6668 (if (fboundp 'next-single-char-property-change)
6669 'next-single-char-property-change
6670 'next-single-property-change)
6671 ;; No docstring because xemacs defalias doesn't support it.
6673 ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
6674 (defalias 'allout-previous-single-char-property-change
6675 (if (fboundp 'previous-single-char-property-change)
6676 'previous-single-char-property-change
6677 'previous-single-property-change)
6678 ;; No docstring because xemacs defalias doesn't support it.
6680 ;;;_ > allout-select-safe-coding-system
6681 (defalias 'allout-select-safe-coding-system
6682 (if (fboundp 'select-safe-coding-system)
6683 'select-safe-coding-system
6684 'detect-coding-region)
6686 ;;;_ > allout-substring-no-properties
6687 ;; define as alias first, so byte compiler is happy.
6688 (defalias 'allout-substring-no-properties 'substring-no-properties)
6689 ;; then supplant with definition if underlying alias absent.
6690 (if (not (fboundp 'substring-no-properties))
6691 (defun allout-substring-no-properties (string &optional start end)
6692 (substring string (or start 0) end))
6695 ;;;_ #10 Unfinished
6696 ;;;_ > allout-bullet-isearch (&optional bullet)
6697 (defun allout-bullet-isearch (&optional bullet)
6698 "Isearch (regexp) for topic with bullet BULLET."
6699 (interactive)
6700 (if (not bullet)
6701 (setq bullet (solicit-char-in-string
6702 "ISearch for topic with bullet: "
6703 (regexp-sans-escapes allout-bullets-string))))
6705 (let ((isearch-regexp t)
6706 (isearch-string (concat "^"
6707 allout-header-prefix
6708 "[ \t]*"
6709 bullet)))
6710 (isearch-repeat 'forward)
6711 (isearch-mode t)))
6713 ;;;_ #11 Unit tests -- this should be last item before "Provide"
6714 ;;;_ > allout-run-unit-tests ()
6715 (defun allout-run-unit-tests ()
6716 "Run the various allout unit tests."
6717 (message "Running allout tests...")
6718 (allout-test-resumptions)
6719 (message "Running allout tests... Done.")
6720 (sit-for .5))
6721 ;;;_ : test resumptions:
6722 ;;;_ > allout-tests-obliterate-variable (name)
6723 (defun allout-tests-obliterate-variable (name)
6724 "Completely unbind variable with NAME."
6725 (if (local-variable-p name (current-buffer)) (kill-local-variable name))
6726 (while (boundp name) (makunbound name)))
6727 ;;;_ > allout-test-resumptions ()
6728 (defvar allout-tests-globally-unbound nil
6729 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6730 (defvar allout-tests-globally-true nil
6731 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6732 (defvar allout-tests-locally-true nil
6733 "Fodder for allout resumptions tests -- defvar just for byte compiler.")
6734 (defun allout-test-resumptions ()
6735 "Exercise allout resumptions."
6736 ;; for each resumption case, we also test that the right local/global
6737 ;; scopes are affected during resumption effects:
6739 ;; ensure that previously unbound variables return to the unbound state.
6740 (with-temp-buffer
6741 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6742 (allout-add-resumptions '(allout-tests-globally-unbound t))
6743 (assert (not (default-boundp 'allout-tests-globally-unbound)))
6744 (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6745 (assert (boundp 'allout-tests-globally-unbound))
6746 (assert (equal allout-tests-globally-unbound t))
6747 (allout-do-resumptions)
6748 (assert (not (local-variable-p 'allout-tests-globally-unbound
6749 (current-buffer))))
6750 (assert (not (boundp 'allout-tests-globally-unbound))))
6752 ;; ensure that variable with prior global value is resumed
6753 (with-temp-buffer
6754 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6755 (setq allout-tests-globally-true t)
6756 (allout-add-resumptions '(allout-tests-globally-true nil))
6757 (assert (equal (default-value 'allout-tests-globally-true) t))
6758 (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6759 (assert (equal allout-tests-globally-true nil))
6760 (allout-do-resumptions)
6761 (assert (not (local-variable-p 'allout-tests-globally-true
6762 (current-buffer))))
6763 (assert (boundp 'allout-tests-globally-true))
6764 (assert (equal allout-tests-globally-true t)))
6766 ;; ensure that prior local value is resumed
6767 (with-temp-buffer
6768 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6769 (set (make-local-variable 'allout-tests-locally-true) t)
6770 (assert (not (default-boundp 'allout-tests-locally-true))
6771 nil (concat "Test setup mistake -- variable supposed to"
6772 " not have global binding, but it does."))
6773 (assert (local-variable-p 'allout-tests-locally-true (current-buffer))
6774 nil (concat "Test setup mistake -- variable supposed to have"
6775 " local binding, but it lacks one."))
6776 (allout-add-resumptions '(allout-tests-locally-true nil))
6777 (assert (not (default-boundp 'allout-tests-locally-true)))
6778 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6779 (assert (equal allout-tests-locally-true nil))
6780 (allout-do-resumptions)
6781 (assert (boundp 'allout-tests-locally-true))
6782 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6783 (assert (equal allout-tests-locally-true t))
6784 (assert (not (default-boundp 'allout-tests-locally-true))))
6786 ;; ensure that last of multiple resumptions holds, for various scopes.
6787 (with-temp-buffer
6788 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6789 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6790 (setq allout-tests-globally-true t)
6791 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6792 (set (make-local-variable 'allout-tests-locally-true) t)
6793 (allout-add-resumptions '(allout-tests-globally-unbound t)
6794 '(allout-tests-globally-true nil)
6795 '(allout-tests-locally-true nil))
6796 (allout-add-resumptions '(allout-tests-globally-unbound 2)
6797 '(allout-tests-globally-true 3)
6798 '(allout-tests-locally-true 4))
6799 ;; reestablish many of the basic conditions are maintained after re-add:
6800 (assert (not (default-boundp 'allout-tests-globally-unbound)))
6801 (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6802 (assert (equal allout-tests-globally-unbound 2))
6803 (assert (default-boundp 'allout-tests-globally-true))
6804 (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6805 (assert (equal allout-tests-globally-true 3))
6806 (assert (not (default-boundp 'allout-tests-locally-true)))
6807 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6808 (assert (equal allout-tests-locally-true 4))
6809 (allout-do-resumptions)
6810 (assert (not (local-variable-p 'allout-tests-globally-unbound
6811 (current-buffer))))
6812 (assert (not (boundp 'allout-tests-globally-unbound)))
6813 (assert (not (local-variable-p 'allout-tests-globally-true
6814 (current-buffer))))
6815 (assert (boundp 'allout-tests-globally-true))
6816 (assert (equal allout-tests-globally-true t))
6817 (assert (boundp 'allout-tests-locally-true))
6818 (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6819 (assert (equal allout-tests-locally-true t))
6820 (assert (not (default-boundp 'allout-tests-locally-true))))
6822 ;; ensure that deliberately unbinding registered variables doesn't foul things
6823 (with-temp-buffer
6824 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6825 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6826 (setq allout-tests-globally-true t)
6827 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6828 (set (make-local-variable 'allout-tests-locally-true) t)
6829 (allout-add-resumptions '(allout-tests-globally-unbound t)
6830 '(allout-tests-globally-true nil)
6831 '(allout-tests-locally-true nil))
6832 (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
6833 (allout-tests-obliterate-variable 'allout-tests-globally-true)
6834 (allout-tests-obliterate-variable 'allout-tests-locally-true)
6835 (allout-do-resumptions))
6837 ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
6838 (when allout-run-unit-tests-on-load
6839 (allout-run-unit-tests))
6841 ;;;_ #12 Provide
6842 (provide 'allout)
6844 ;;;_* Local emacs vars.
6845 ;; The following `allout-layout' local variable setting:
6846 ;; - closes all topics from the first topic to just before the third-to-last,
6847 ;; - shows the children of the third to last (config vars)
6848 ;; - and the second to last (code section),
6849 ;; - and closes the last topic (this local-variables section).
6850 ;;Local variables:
6851 ;;allout-layout: (0 : -1 -1 0)
6852 ;;End:
6854 ;;; allout.el ends here