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