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