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