Commit | Line | Data |
---|---|---|
6a05d05f | 1 | ;;; allout.el --- extensive outline mode for use alone and with other modes |
19b84ba3 | 2 | |
73b0cd50 | 3 | ;; Copyright (C) 1992-1994, 2001-2011 Free Software Foundation, Inc. |
1977b8f6 | 4 | |
d82979ea EZ |
5 | ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com> |
6 | ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com> | |
60c7bbd2 | 7 | ;; Created: Dec 1991 -- first release to usenet |
0af8c88b | 8 | ;; Version: 2.3 |
96497653 | 9 | ;; Keywords: outlines, wp, languages, PGP, GnuPG |
01fc9422 | 10 | ;; Website: http://myriadicity.net/Sundry/EmacsAllout |
1977b8f6 RS |
11 | |
12 | ;; This file is part of GNU Emacs. | |
13 | ||
eb3fa2cf | 14 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
59243403 | 15 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
16 | ;; the Free Software Foundation, either version 3 of the License, or |
17 | ;; (at your option) any later version. | |
59243403 | 18 | |
1977b8f6 | 19 | ;; GNU Emacs is distributed in the hope that it will be useful, |
59243403 RS |
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ;; GNU General Public License for more details. | |
23 | ||
24 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 25 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
1977b8f6 | 26 | |
6a05d05f | 27 | ;;; Commentary: |
19b84ba3 | 28 | |
96b83743 EZ |
29 | ;; Allout outline minor mode provides extensive outline formatting and |
30 | ;; and manipulation beyond standard emacs outline mode. Some features: | |
71296446 | 31 | ;; |
96b83743 EZ |
32 | ;; - Classic outline-mode topic-oriented navigation and exposure adjustment |
33 | ;; - Topic-oriented editing including coherent topic and subtopic | |
34 | ;; creation, promotion, demotion, cut/paste across depths, etc. | |
35 | ;; - Incremental search with dynamic exposure and reconcealment of text | |
60c7bbd2 | 36 | ;; - Customizable bullet format -- enables programming-language specific |
96b83743 | 37 | ;; outlining, for code-folding editing. (Allout code itself is to try it; |
60c7bbd2 | 38 | ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but |
96b83743 | 39 | ;; emacs local file variables need to be enabled when the |
60c7bbd2 | 40 | ;; file was visited -- see `enable-local-variables'.) |
96b83743 | 41 | ;; - Configurable per-file initial exposure settings |
3a00a363 KM |
42 | ;; - Symmetric-key and key-pair topic encryption. Encryption is via the |
43 | ;; Emacs 'epg' library. See allout-toggle-current-subtree-encryption | |
44 | ;; docstring. | |
96b83743 EZ |
45 | ;; - Automatic topic-number maintenance |
46 | ;; - "Hot-spot" operation, for single-keystroke maneuvering and | |
d82979ea | 47 | ;; exposure control (see the allout-mode docstring) |
96b83743 | 48 | ;; - Easy rendering of exposed portions into numbered, latex, indented, etc |
d82979ea | 49 | ;; outline styles |
60c7bbd2 | 50 | ;; - Careful attention to whitespace -- enabling blank lines between items |
96b83743 EZ |
51 | ;; and maintenance of hanging indentation (in paragraph auto-fill and |
52 | ;; across topic promotion and demotion) of topic bodies consistent with | |
53 | ;; indentation of their topic header. | |
71296446 | 54 | ;; |
d82979ea | 55 | ;; and more. |
71296446 | 56 | ;; |
96b83743 | 57 | ;; See the `allout-mode' function's docstring for an introduction to the |
01fc9422 EZ |
58 | ;; mode. |
59 | ;; | |
96497653 KM |
60 | ;; Directions to the latest development version and helpful notes are |
61 | ;; available at http://myriadicity.net/Sundry/EmacsAllout . | |
96b83743 | 62 | ;; |
11c46e15 KM |
63 | ;; The outline menubar additions provide quick reference to many of the |
64 | ;; features. See the docstring of the variables `allout-layout' and | |
fd5359c6 | 65 | ;; `allout-auto-activation' for details on automatic activation of |
11c46e15 KM |
66 | ;; `allout-mode' as a minor mode. (`allout-init' is deprecated in favor of |
67 | ;; a purely customization-based method.) | |
c567ac01 | 68 | ;; |
60c7bbd2 | 69 | ;; Note -- the lines beginning with `;;;_' are outline topic headers. |
11c46e15 KM |
70 | ;; Customize `allout-auto-activation' to enable, then revisit this |
71 | ;; buffer to give it a whirl. | |
19b84ba3 | 72 | |
d82979ea | 73 | ;; ken manheimer (ken dot manheimer at gmail dot com) |
c567ac01 | 74 | |
6a05d05f PJ |
75 | ;;; Code: |
76 | ||
96497653 | 77 | ;;;_* Dependency loads |
96b83743 | 78 | (require 'overlay) |
01fc9422 | 79 | (eval-when-compile |
ff3e8c8e KM |
80 | ;; Most of the requires here are for stuff covered by autoloads, which |
81 | ;; byte-compiling doesn't trigger. | |
29fac3fe | 82 | (require 'epg) |
ff3e8c8e | 83 | (require 'epa) |
08cf18e4 GM |
84 | (require 'overlay) |
85 | ;; `cl' is required for `assert'. `assert' is not covered by a standard | |
86 | ;; autoload, but it is a macro, so that eval-when-compile is sufficient | |
87 | ;; to byte-compile it in, or to do the require when the buffer evalled. | |
88 | (require 'cl) | |
89 | ) | |
d82979ea | 90 | |
19b84ba3 | 91 | ;;;_* USER CUSTOMIZATION VARIABLES: |
96b83743 | 92 | |
1c9b9df0 | 93 | ;;;_ > defgroup allout, allout-keybindings |
4bef9110 | 94 | (defgroup allout nil |
96497653 KM |
95 | "Extensive outline minor-mode, for use stand-alone and with other modes. |
96 | ||
97 | See Allout Auto Activation for automatic activation." | |
fd5359c6 | 98 | :prefix "allout-" |
d82979ea | 99 | :group 'outlines) |
1c9b9df0 KM |
100 | (defgroup allout-keybindings nil |
101 | "Allout outline mode keyboard bindings configuration." | |
102 | :group 'allout) | |
19b84ba3 RS |
103 | |
104 | ;;;_ + Layout, Mode, and Topic Header Configuration | |
105 | ||
08b5f072 | 106 | (defvar allout-command-prefix) ; defined below |
08b5f072 | 107 | |
1c9b9df0 | 108 | ;;;_ > allout-keybindings incidentals: |
d3e51865 KM |
109 | ;;;_ : internal key binding stuff - in this section for load-order. |
110 | ;;;_ = allout-mode-map | |
111 | (defvar allout-mode-map 'allout-mode-map | |
112 | "Keybindings place-holder for (allout) outline minor mode. | |
113 | ||
114 | Do NOT set the value of this variable. Instead, customize | |
115 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
116 | `allout-unprefixed-keybindings'.") | |
117 | ;;;_ = allout-mode-map-value | |
118 | (defvar allout-mode-map-value nil | |
119 | "Keymap for allout outline minor mode. | |
120 | ||
121 | Do NOT set the value of this variable. Instead, customize | |
122 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
123 | `allout-unprefixed-keybindings'.") | |
124 | ;;;_ = make allout-mode-map-value an alias for allout-mode-map: | |
125 | ;; this needs to be revised when the value is changed, sigh. | |
126 | (defalias 'allout-mode-map allout-mode-map-value) | |
127 | ;;;_ > allout-compose-and-institute-keymap (&optional varname value) | |
128 | (defun allout-compose-and-institute-keymap (&optional varname value) | |
129 | "Create the allout keymap according to the keybinding specs, and set it. | |
130 | ||
131 | Useful standalone or to effect customizations of the | |
1c9b9df0 KM |
132 | respective allout-mode keybinding variables, `allout-command-prefix', |
133 | `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'" | |
134 | ;; Set the customization variable, if any: | |
135 | (when varname | |
136 | (set-default varname value)) | |
d3e51865 | 137 | (let ((map (make-sparse-keymap))) |
1c9b9df0 | 138 | (when (boundp 'allout-prefixed-keybindings) |
d3e51865 | 139 | ;; tolerate first definitions of the variables: |
1c9b9df0 KM |
140 | (dolist (entry allout-prefixed-keybindings) |
141 | (define-key map | |
142 | ;; XXX vector vs non-vector key descriptions? | |
143 | (vconcat allout-command-prefix | |
144 | (car (read-from-string (car entry)))) | |
145 | (cadr entry)))) | |
146 | (when (boundp 'allout-unprefixed-keybindings) | |
147 | (dolist (entry allout-unprefixed-keybindings) | |
148 | (define-key map (car (read-from-string (car entry))) (cadr entry)))) | |
d3e51865 KM |
149 | (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line |
150 | map global-map) | |
151 | (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line | |
152 | map global-map) | |
153 | (substitute-key-definition 'end-of-line 'allout-end-of-line | |
154 | map global-map) | |
155 | (substitute-key-definition 'move-end-of-line 'allout-end-of-line | |
156 | map global-map) | |
157 | (allout-institute-keymap map))) | |
158 | ;;;_ > allout-institute-keymap (map) | |
159 | (defun allout-institute-keymap (map) | |
160 | "Associate allout-mode bindings with allout as a minor mode." | |
161 | ;; Architecture: | |
162 | ;; allout-mode-map var is a keymap by virtue of being a defalias for | |
163 | ;; allout-mode-map-value, which has the actual keymap value. | |
164 | ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be | |
165 | ;; used in minor-mode-map-alist to indirect to the actual | |
166 | ;; allout-mode-map-var value, which can be adjusted and reassigned. | |
167 | ||
642f3c5c | 168 | ;; allout-mode-map-value for keymap reference in various places: |
d3e51865 | 169 | (setq allout-mode-map-value map) |
642f3c5c KM |
170 | ;; the function value keymap of allout-mode-map is used in |
171 | ;; minor-mode-map-alist - update it: | |
172 | (fset allout-mode-map allout-mode-map-value)) | |
d3e51865 KM |
173 | ;;;_ * intialize the mode map: |
174 | ;; ensure that allout-mode-map has some setting even if allout-mode hasn't | |
175 | ;; been invoked: | |
176 | (allout-compose-and-institute-keymap) | |
1c9b9df0 | 177 | ;;;_ = allout-command-prefix |
2a1408fd | 178 | (defcustom allout-command-prefix "\C-c " |
9201cc28 | 179 | "Key sequence to be used as prefix for outline mode command key bindings. |
2a1408fd DN |
180 | |
181 | Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're | |
182 | willing to let allout use a bunch of \C-c keybindings." | |
183 | :type 'string | |
1c9b9df0 | 184 | :group 'allout-keybindings |
d3e51865 | 185 | :set 'allout-compose-and-institute-keymap) |
1c9b9df0 KM |
186 | ;;;_ = allout-keybindings-binding |
187 | (define-widget 'allout-keybindings-binding 'lazy | |
188 | "Structure of allout keybindings customization items." | |
189 | :type '(repeat | |
190 | (list (string :tag "Key" :value "[(meta control shift ?f)]") | |
191 | (function :tag "Function name" | |
192 | :value allout-forward-current-level)))) | |
193 | ;;;_ = allout-prefixed-keybindings | |
194 | (defcustom allout-prefixed-keybindings | |
195 | '(("[(control ?n)]" allout-next-visible-heading) | |
196 | ("[(control ?p)]" allout-previous-visible-heading) | |
d3e51865 | 197 | ("[(control ?u)]" allout-up-current-level) |
1c9b9df0 KM |
198 | ("[(control ?f)]" allout-forward-current-level) |
199 | ("[(control ?b)]" allout-backward-current-level) | |
200 | ("[(control ?a)]" allout-beginning-of-current-entry) | |
201 | ("[(control ?e)]" allout-end-of-entry) | |
202 | ("[(control ?i)]" allout-show-children) | |
1c9b9df0 KM |
203 | ("[(control ?s)]" allout-show-current-subtree) |
204 | ("[(control ?t)]" allout-toggle-current-subtree-exposure) | |
d3e51865 KM |
205 | ;; Let user customize if they want to preempt describe-prefix-bindings ^h use. |
206 | ;; ("[(control ?h)]" allout-hide-current-subtree) | |
1c9b9df0 KM |
207 | ("[?h]" allout-hide-current-subtree) |
208 | ("[(control ?o)]" allout-show-current-entry) | |
209 | ("[?!]" allout-show-all) | |
210 | ("[?x]" allout-toggle-current-subtree-encryption) | |
211 | ("[? ]" allout-open-sibtopic) | |
212 | ("[?.]" allout-open-subtopic) | |
213 | ("[?,]" allout-open-supertopic) | |
214 | ("[?']" allout-shift-in) | |
215 | ("[?>]" allout-shift-in) | |
216 | ("[?<]" allout-shift-out) | |
217 | ("[(control ?m)]" allout-rebullet-topic) | |
218 | ("[?*]" allout-rebullet-current-heading) | |
4936e3ba | 219 | ("[?#]" allout-number-siblings) |
1c9b9df0 | 220 | ("[(control ?k)]" allout-kill-topic) |
d3e51865 | 221 | ("[(meta ?k)]" allout-copy-topic-as-kill) |
1c9b9df0 KM |
222 | ("[?@]" allout-resolve-xref) |
223 | ("[?=?c]" allout-copy-exposed-to-buffer) | |
224 | ("[?=?i]" allout-indented-exposed-to-buffer) | |
225 | ("[?=?t]" allout-latexify-exposed) | |
226 | ("[?=?p]" allout-flatten-exposed-to-buffer) | |
227 | ) | |
228 | "Allout-mode key bindings that are prefixed with `allout-command-prefix'. | |
229 | ||
230 | See `allout-unprefixed-keybindings' for the list of keybindings | |
231 | that are not prefixed. | |
232 | ||
233 | Use vector format for the keys: | |
234 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
235 | - enclose control, shift, or meta-modified keys as sequences within | |
236 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 237 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 KM |
238 | See the existing keys for examples. |
239 | ||
240 | Functions can be bound to multiple keys, but binding keys to | |
241 | multiple functions will not work - the last binding for a key | |
242 | prevails." | |
243 | :type 'allout-keybindings-binding | |
244 | :group 'allout-keybindings | |
d3e51865 | 245 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
246 | ) |
247 | ;;;_ = allout-unprefixed-keybindings | |
248 | (defcustom allout-unprefixed-keybindings | |
249 | '(("[(control ?k)]" allout-kill-line) | |
d3e51865 | 250 | ("[(meta ?k)]" allout-copy-line-as-kill) |
1c9b9df0 | 251 | ("[(control ?y)]" allout-yank) |
d3e51865 | 252 | ("[(meta ?y)]" allout-yank-pop) |
1c9b9df0 KM |
253 | ) |
254 | "Allout-mode functions bound to keys without any added prefix. | |
255 | ||
256 | This is in contrast to the majority of allout-mode bindings on | |
257 | `allout-prefixed-bindings', whose bindings are created with a | |
0d327994 | 258 | preceding command key. |
1c9b9df0 KM |
259 | |
260 | Use vector format for the keys: | |
261 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
262 | - enclose control, shift, or meta-modified keys as sequences within | |
263 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 264 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 KM |
265 | See the existing keys for examples." |
266 | :type 'allout-keybindings-binding | |
267 | :group 'allout-keybindings | |
d3e51865 | 268 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
269 | ) |
270 | ||
11c46e15 KM |
271 | ;;;_ > allout-auto-activation-helper (var value) |
272 | ;;;###autoload | |
273 | (defun allout-auto-activation-helper (var value) | |
274 | "Institute `allout-auto-activation'. | |
275 | ||
276 | Intended to be used as the `allout-auto-activation' :set function." | |
277 | (set-default var value) | |
278 | (allout-setup)) | |
279 | ;;;_ > allout-setup () | |
280 | ;;;###autoload | |
281 | (defun allout-setup () | |
282 | "Do fundamental emacs session for allout auto-activation. | |
283 | ||
284 | Establishes allout processing as part of visiting a file if | |
285 | `allout-auto-activation' is non-nil, or removes it otherwise. | |
286 | ||
287 | The proper way to use this is through customizing the setting of | |
288 | `allout-auto-activation'." | |
289 | (if (not allout-auto-activation) | |
290 | (remove-hook 'find-file-hook 'allout-find-file-hook) | |
291 | (add-hook 'find-file-hook 'allout-find-file-hook))) | |
fd5359c6 | 292 | ;;;_ = allout-auto-activation |
11c46e15 | 293 | ;;;###autoload |
fd5359c6 | 294 | (defcustom allout-auto-activation nil |
11c46e15 | 295 | "Configure allout outline mode auto-activation. |
19b84ba3 | 296 | |
11c46e15 KM |
297 | Control whether and how allout outline mode is automatically |
298 | activated when files are visited with non-nil buffer-specific | |
299 | file variable `allout-layout'. | |
19b84ba3 | 300 | |
11c46e15 KM |
301 | When allout-auto-activation is \"On\" \(t), allout mode is |
302 | activated in buffers with non-nil `allout-layout', and the | |
303 | specified layout is applied. | |
19b84ba3 | 304 | |
11c46e15 | 305 | With value \"ask\", auto-mode-activation is enabled, and endorsement for |
19b84ba3 RS |
306 | performing auto-layout is asked of the user each time. |
307 | ||
11c46e15 KM |
308 | With value \"activate\", only auto-mode-activation is enabled. |
309 | Auto-layout is not. | |
19b84ba3 | 310 | |
96497653 | 311 | With value nil, inhibit any automatic allout-mode activation." |
11c46e15 | 312 | :set 'allout-auto-activation-helper |
c6eee9aa | 313 | ;; FIXME: Using strings here is unusual and less efficient than symbols. |
9179616f DL |
314 | :type '(choice (const :tag "On" t) |
315 | (const :tag "Ask about layout" "ask") | |
316 | (const :tag "Mode only" "activate") | |
317 | (const :tag "Off" nil)) | |
318 | :group 'allout) | |
11c46e15 | 319 | (allout-setup) |
4034b0e2 LT |
320 | ;;;_ = allout-default-layout |
321 | (defcustom allout-default-layout '(-2 : 0) | |
9201cc28 | 322 | "Default allout outline layout specification. |
4034b0e2 LT |
323 | |
324 | This setting specifies the outline exposure to use when | |
325 | `allout-layout' has the local value `t'. This docstring describes the | |
326 | layout specifications. | |
327 | ||
328 | A list value specifies a default layout for the current buffer, | |
329 | to be applied upon activation of `allout-mode'. Any non-nil | |
330 | value will automatically trigger `allout-mode', provided | |
11c46e15 | 331 | `allout-auto-activation' has been customized to enable it. |
4034b0e2 LT |
332 | |
333 | The types of elements in the layout specification are: | |
334 | ||
60c7bbd2 RS |
335 | INTEGER -- dictate the relative depth to open the corresponding topic(s), |
336 | where: | |
337 | -- negative numbers force the topic to be closed before opening | |
338 | to the absolute value of the number, so all siblings are open | |
339 | only to that level. | |
340 | -- positive numbers open to the relative depth indicated by the | |
341 | number, but do not force already opened subtopics to be closed. | |
342 | -- 0 means to close topic -- hide all subitems. | |
97610156 | 343 | : -- repeat spec -- apply the preceding element to all siblings at |
60c7bbd2 RS |
344 | current level, *up to* those siblings that would be covered by specs |
345 | following the `:' on the list. Ie, apply to all topics at level but | |
346 | trailing ones accounted for by trailing specs. (Only the first of | |
347 | multiple colons at the same level is honored -- later ones are ignored.) | |
348 | * -- completely exposes the topic, including bodies | |
349 | + -- exposes all subtopics, but not the bodies | |
350 | - -- exposes the body of the corresponding topic, but not subtopics | |
351 | LIST -- a nested layout spec, to be applied intricately to its | |
4034b0e2 | 352 | corresponding item(s) |
1977b8f6 | 353 | |
4034b0e2 | 354 | Examples: |
60c7bbd2 | 355 | (-2 : 0) |
4034b0e2 LT |
356 | Collapse the top-level topics to show their children and |
357 | grandchildren, but completely collapse the final top-level topic. | |
60c7bbd2 | 358 | (-1 () : 1 0) |
4034b0e2 LT |
359 | Close the first topic so only the immediate subtopics are shown, |
360 | leave the subsequent topics exposed as they are until the second | |
361 | second to last topic, which is exposed at least one level, and | |
362 | completely close the last topic. | |
60c7bbd2 | 363 | (-2 : -1 *) |
4034b0e2 LT |
364 | Expose children and grandchildren of all topics at current |
365 | level except the last two; expose children of the second to | |
366 | last and completely expose the last one, including its subtopics. | |
19b84ba3 | 367 | |
4034b0e2 | 368 | See `allout-expose-topic' for more about the exposure process. |
19b84ba3 | 369 | |
353e2ef2 KH |
370 | Also, allout's mode-specific provisions will make topic prefixes default |
371 | to the comment-start string, if any, of the language of the file. This | |
4034b0e2 LT |
372 | is modulo the setting of `allout-use-mode-specific-leader', which see." |
373 | :type 'allout-layout-type | |
374 | :group 'allout) | |
375 | ;;;_ : allout-layout-type | |
376 | (define-widget 'allout-layout-type 'lazy | |
377 | "Allout layout format customization basic building blocks." | |
378 | :type '(repeat | |
379 | (choice (integer :tag "integer (<= zero is strict)") | |
380 | (const :tag ": (repeat prior)" :) | |
381 | (const :tag "* (completely expose)" *) | |
382 | (const :tag "+ (expose all offspring, headlines only)" +) | |
383 | (const :tag "- (expose topic body but not offspring)" -) | |
384 | (allout-layout-type :tag "<Nested layout>")))) | |
385 | ||
2a1408fd DN |
386 | ;;;_ = allout-inhibit-auto-fill |
387 | (defcustom allout-inhibit-auto-fill nil | |
9201cc28 | 388 | "If non-nil, auto-fill will be inhibited in the allout buffers. |
2a1408fd DN |
389 | |
390 | You can customize this setting to set it for all allout buffers, or set it | |
391 | in individual buffers if you want to inhibit auto-fill only in particular | |
392 | buffers. (You could use a function on `allout-mode-hook' to inhibit | |
393 | auto-fill according, eg, to the major mode.) | |
394 | ||
395 | If you don't set this and auto-fill-mode is enabled, allout will use the | |
396 | value that `normal-auto-fill-function', if any, when allout mode starts, or | |
397 | else allout's special hanging-indent maintaining auto-fill function, | |
398 | `allout-auto-fill'." | |
399 | :type 'boolean | |
400 | :group 'allout) | |
401 | (make-variable-buffer-local 'allout-inhibit-auto-fill) | |
381987c3 KM |
402 | ;;;_ = allout-inhibit-auto-fill-on-headline |
403 | (defcustom allout-inhibit-auto-fill-on-headline nil | |
404 | "If non-nil, auto-fill will be inhibited while on topic's header line." | |
405 | :type 'boolean | |
406 | :group 'allout) | |
407 | (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline) | |
2a1408fd DN |
408 | ;;;_ = allout-use-hanging-indents |
409 | (defcustom allout-use-hanging-indents t | |
9201cc28 | 410 | "If non-nil, topic body text auto-indent defaults to indent of the header. |
2a1408fd | 411 | Ie, it is indented to be just past the header prefix. This is |
8dd59f01 | 412 | relevant mostly for use with `indented-text-mode', or other situations |
2a1408fd DN |
413 | where auto-fill occurs." |
414 | :type 'boolean | |
415 | :group 'allout) | |
416 | (make-variable-buffer-local 'allout-use-hanging-indents) | |
417 | ;;;###autoload | |
418 | (put 'allout-use-hanging-indents 'safe-local-variable | |
4f91a816 | 419 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
2a1408fd DN |
420 | ;;;_ = allout-reindent-bodies |
421 | (defcustom allout-reindent-bodies (if allout-use-hanging-indents | |
422 | 'text) | |
9201cc28 | 423 | "Non-nil enables auto-adjust of topic body hanging indent with depth shifts. |
2a1408fd DN |
424 | |
425 | When active, topic body lines that are indented even with or beyond | |
426 | their topic header are reindented to correspond with depth shifts of | |
427 | the header. | |
428 | ||
429 | A value of t enables reindent in non-programming-code buffers, ie | |
430 | those that do not have the variable `comment-start' set. A value of | |
431 | `force' enables reindent whether or not `comment-start' is set." | |
432 | :type '(choice (const nil) (const t) (const text) (const force)) | |
433 | :group 'allout) | |
434 | ||
435 | (make-variable-buffer-local 'allout-reindent-bodies) | |
436 | ;;;###autoload | |
437 | (put 'allout-reindent-bodies 'safe-local-variable | |
4f91a816 | 438 | (lambda (x) (memq x '(nil t text force)))) |
2a1408fd | 439 | |
fd5359c6 MR |
440 | ;;;_ = allout-show-bodies |
441 | (defcustom allout-show-bodies nil | |
9201cc28 | 442 | "If non-nil, show entire body when exposing a topic, rather than |
9179616f DL |
443 | just the header." |
444 | :type 'boolean | |
445 | :group 'allout) | |
fd5359c6 | 446 | (make-variable-buffer-local 'allout-show-bodies) |
8570ce80 SM |
447 | ;;;###autoload |
448 | (put 'allout-show-bodies 'safe-local-variable | |
4f91a816 | 449 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 450 | |
48bd8440 EZ |
451 | ;;;_ = allout-beginning-of-line-cycles |
452 | (defcustom allout-beginning-of-line-cycles t | |
9201cc28 | 453 | "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
454 | |
455 | Cycling only happens on when the command is repeated, not when it | |
456 | follows a different command. | |
457 | ||
458 | Smart-placement means that repeated calls to this function will | |
459 | advance as follows: | |
460 | ||
461 | - if the cursor is on a non-headline body line and not on the first column: | |
462 | then it goes to the first column | |
463 | - if the cursor is on the first column of a non-headline body line: | |
464 | then it goes to the start of the headline within the item body | |
465 | - if the cursor is on the headline and not the start of the headline: | |
466 | then it goes to the start of the headline | |
467 | - if the cursor is on the start of the headline: | |
c07583cd | 468 | then it goes to the bullet character (for hotspot navigation) |
48bd8440 | 469 | - if the cursor is on the bullet character: |
c07583cd | 470 | then it goes to the first column of that line (the headline) |
48bd8440 EZ |
471 | - if the cursor is on the first column of the headline: |
472 | then it goes to the start of the headline within the item body. | |
473 | ||
474 | In this fashion, you can use the beginning-of-line command to do | |
475 | its normal job and then, when repeated, advance through the | |
476 | entry, cycling back to start. | |
477 | ||
478 | If this configuration variable is nil, then the cursor is just | |
479 | advanced to the beginning of the line and remains there on | |
480 | repeated calls." | |
481 | :type 'boolean :group 'allout) | |
482 | ;;;_ = allout-end-of-line-cycles | |
483 | (defcustom allout-end-of-line-cycles t | |
9201cc28 | 484 | "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
485 | |
486 | Cycling only happens on when the command is repeated, not when it | |
487 | follows a different command. | |
488 | ||
60c7bbd2 | 489 | Smart placement means that repeated calls to this function will |
48bd8440 EZ |
490 | advance as follows: |
491 | ||
492 | - if the cursor is not on the end-of-line, | |
493 | then it goes to the end-of-line | |
494 | - if the cursor is on the end-of-line but not the end-of-entry, | |
495 | then it goes to the end-of-entry, exposing it if necessary | |
496 | - if the cursor is on the end-of-entry, | |
497 | then it goes to the end of the head line | |
498 | ||
499 | In this fashion, you can use the end-of-line command to do its | |
500 | normal job and then, when repeated, advance through the entry, | |
501 | cycling back to start. | |
502 | ||
503 | If this configuration variable is nil, then the cursor is just | |
504 | advanced to the end of the line and remains there on repeated | |
505 | calls." | |
506 | :type 'boolean :group 'allout) | |
507 | ||
fd5359c6 MR |
508 | ;;;_ = allout-header-prefix |
509 | (defcustom allout-header-prefix "." | |
48bd8440 EZ |
510 | ;; this string is treated as literal match. it will be `regexp-quote'd, so |
511 | ;; one cannot use regular expressions to match varying header prefixes. | |
9201cc28 | 512 | "Leading string which helps distinguish topic headers. |
19b84ba3 RS |
513 | |
514 | Outline topic header lines are identified by a leading topic | |
c567ac01 | 515 | header prefix, which mostly have the value of this var at their front. |
48bd8440 EZ |
516 | Level 1 topics are exceptions. They consist of only a single |
517 | character, which is typically set to the `allout-primary-bullet'." | |
4bef9110 SE |
518 | :type 'string |
519 | :group 'allout) | |
fd5359c6 | 520 | (make-variable-buffer-local 'allout-header-prefix) |
8570ce80 SM |
521 | ;;;###autoload |
522 | (put 'allout-header-prefix 'safe-local-variable 'stringp) | |
fd5359c6 MR |
523 | ;;;_ = allout-primary-bullet |
524 | (defcustom allout-primary-bullet "*" | |
19b84ba3 RS |
525 | "Bullet used for top-level outline topics. |
526 | ||
527 | Outline topic header lines are identified by a leading topic header | |
c567ac01 | 528 | prefix, which is concluded by bullets that includes the value of this |
fd5359c6 | 529 | var and the respective allout-*-bullets-string vars. |
c567ac01 | 530 | |
353e2ef2 | 531 | The value of an asterisk (`*') provides for backwards compatibility |
e126900f | 532 | with the original Emacs outline mode. See `allout-plain-bullets-string' |
2265e017 | 533 | and `allout-distinctive-bullets-string' for the range of available |
4bef9110 SE |
534 | bullets." |
535 | :type 'string | |
536 | :group 'allout) | |
fd5359c6 | 537 | (make-variable-buffer-local 'allout-primary-bullet) |
8570ce80 SM |
538 | ;;;###autoload |
539 | (put 'allout-primary-bullet 'safe-local-variable 'stringp) | |
fd5359c6 | 540 | ;;;_ = allout-plain-bullets-string |
d82979ea | 541 | (defcustom allout-plain-bullets-string ".," |
9201cc28 | 542 | "The bullets normally used in outline topic prefixes. |
19b84ba3 | 543 | |
fd5359c6 | 544 | See `allout-distinctive-bullets-string' for the other kind of |
c567ac01 | 545 | bullets. |
1977b8f6 | 546 | |
353e2ef2 | 547 | DO NOT include the close-square-bracket, `]', as a bullet. |
1977b8f6 | 548 | |
c567ac01 | 549 | Outline mode has to be reactivated in order for changes to the value |
4bef9110 SE |
550 | of this var to take effect." |
551 | :type 'string | |
552 | :group 'allout) | |
fd5359c6 | 553 | (make-variable-buffer-local 'allout-plain-bullets-string) |
8570ce80 SM |
554 | ;;;###autoload |
555 | (put 'allout-plain-bullets-string 'safe-local-variable 'stringp) | |
fd5359c6 | 556 | ;;;_ = allout-distinctive-bullets-string |
d82979ea | 557 | (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^" |
9201cc28 | 558 | "Persistent outline header bullets used to distinguish special topics. |
1977b8f6 | 559 | |
38b2ca53 NR |
560 | These bullets are distinguish topics with particular character. |
561 | They are not used by default in the topic creation routines, but | |
562 | are offered as options when you modify topic creation with a | |
563 | universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]). | |
564 | ||
565 | Distinctive bullets are not cycled when topics are shifted or | |
566 | otherwise automatically rebulleted, so their marking is | |
567 | persistent until deliberately changed. Their significance is | |
568 | purely by convention, however. Some conventions suggest | |
569 | themselves: | |
570 | ||
60c7bbd2 RS |
571 | `(' - open paren -- an aside or incidental point |
572 | `?' - question mark -- uncertain or outright question | |
573 | `!' - exclamation point/bang -- emphatic | |
574 | `[' - open square bracket -- meta-note, about item instead of item's subject | |
575 | `\"' - double quote -- a quotation or other citation | |
0af8c88b | 576 | `=' - equal sign -- an assignment, some kind of definition |
60c7bbd2 | 577 | `^' - carat -- relates to something above |
38b2ca53 NR |
578 | |
579 | Some are more elusive, but their rationale may be recognizable: | |
580 | ||
60c7bbd2 RS |
581 | `+' - plus -- pending consideration, completion |
582 | `_' - underscore -- done, completed | |
583 | `&' - ampersand -- addendum, furthermore | |
38b2ca53 NR |
584 | |
585 | \(Some other non-plain bullets have special meaning to the | |
586 | software. By default: | |
587 | ||
60c7bbd2 RS |
588 | `~' marks encryptable topics -- see `allout-topic-encryption-bullet' |
589 | `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.) | |
38b2ca53 NR |
590 | |
591 | See `allout-plain-bullets-string' for the standard, alternating | |
592 | bullets. | |
1977b8f6 | 593 | |
fd5359c6 | 594 | You must run `set-allout-regexp' in order for outline mode to |
38b2ca53 | 595 | adopt changes of this value. |
19b84ba3 | 596 | |
353e2ef2 | 597 | DO NOT include the close-square-bracket, `]', on either of the bullet |
4bef9110 SE |
598 | strings." |
599 | :type 'string | |
600 | :group 'allout) | |
fd5359c6 | 601 | (make-variable-buffer-local 'allout-distinctive-bullets-string) |
8570ce80 SM |
602 | ;;;###autoload |
603 | (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp) | |
1977b8f6 | 604 | |
fd5359c6 MR |
605 | ;;;_ = allout-use-mode-specific-leader |
606 | (defcustom allout-use-mode-specific-leader t | |
9201cc28 | 607 | "When non-nil, use mode-specific topic-header prefixes. |
19b84ba3 | 608 | |
48bd8440 EZ |
609 | Allout outline mode will use the mode-specific `allout-mode-leaders' or |
610 | comment-start string, if any, to lead the topic prefix string, so topic | |
611 | headers look like comments in the programming language. It will also use | |
612 | the comment-start string, with an '_' appended, for `allout-primary-bullet'. | |
19b84ba3 | 613 | |
48bd8440 EZ |
614 | String values are used as literals, not regular expressions, so |
615 | do not escape any regulare-expression characters. | |
19b84ba3 | 616 | |
24190da5 | 617 | Value t means to first check for assoc value in `allout-mode-leaders' |
c07583cd | 618 | alist, then use comment-start string, if any, then use default (`.'). |
9179616f | 619 | \(See note about use of comment-start strings, below.) |
19b84ba3 | 620 | |
fd5359c6 | 621 | Set to the symbol for either of `allout-mode-leaders' or |
19b84ba3 RS |
622 | `comment-start' to use only one of them, respectively. |
623 | ||
c07583cd | 624 | Value nil means to always use the default (`.') and leave |
48bd8440 EZ |
625 | `allout-primary-bullet' unaltered. |
626 | ||
627 | comment-start strings that do not end in spaces are tripled in | |
628 | the header-prefix, and an `_' underscore is tacked on the end, to | |
629 | distinguish them from regular comment strings. comment-start | |
630 | strings that do end in spaces are not tripled, but an underscore | |
75bcb912 | 631 | is substituted for the space. [This presumes that the space is |
48bd8440 EZ |
632 | for appearance, not comment syntax. You can use |
633 | `allout-mode-leaders' to override this behavior, when | |
634 | undesired.]" | |
71296446 | 635 | :type '(choice (const t) (const nil) string |
fd5359c6 | 636 | (const allout-mode-leaders) |
4bef9110 SE |
637 | (const comment-start)) |
638 | :group 'allout) | |
8570ce80 SM |
639 | ;;;###autoload |
640 | (put 'allout-use-mode-specific-leader 'safe-local-variable | |
4f91a816 | 641 | (lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start)) |
da506f05 | 642 | (stringp x)))) |
fd5359c6 MR |
643 | ;;;_ = allout-mode-leaders |
644 | (defvar allout-mode-leaders '() | |
645 | "Specific allout-prefix leading strings per major modes. | |
19b84ba3 | 646 | |
48bd8440 EZ |
647 | Use this if the mode's comment-start string isn't what you |
648 | prefer, or if the mode lacks a comment-start string. See | |
649 | `allout-use-mode-specific-leader' for more details. | |
19b84ba3 RS |
650 | |
651 | If you're constructing a string that will comment-out outline | |
652 | structuring so it can be included in program code, append an extra | |
653 | character, like an \"_\" underscore, to distinguish the lead string | |
48bd8440 | 654 | from regular comments that start at the beginning-of-line.") |
19b84ba3 | 655 | |
fd5359c6 MR |
656 | ;;;_ = allout-old-style-prefixes |
657 | (defcustom allout-old-style-prefixes nil | |
9201cc28 | 658 | "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. |
19b84ba3 RS |
659 | |
660 | Non-nil restricts the topic creation and modification | |
c567ac01 | 661 | functions to asterix-padded prefixes, so they look exactly |
e126900f | 662 | like the original Emacs-outline style prefixes. |
1977b8f6 | 663 | |
c567ac01 | 664 | Whatever the setting of this variable, both old and new style prefixes |
4bef9110 SE |
665 | are always respected by the topic maneuvering functions." |
666 | :type 'boolean | |
667 | :group 'allout) | |
fd5359c6 | 668 | (make-variable-buffer-local 'allout-old-style-prefixes) |
8570ce80 SM |
669 | ;;;###autoload |
670 | (put 'allout-old-style-prefixes 'safe-local-variable | |
4f91a816 | 671 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
60c7bbd2 | 672 | ;;;_ = allout-stylish-prefixes -- alternating bullets |
fd5359c6 | 673 | (defcustom allout-stylish-prefixes t |
9201cc28 | 674 | "Do fancy stuff with topic prefix bullets according to level, etc. |
c567ac01 | 675 | |
19b84ba3 RS |
676 | Non-nil enables topic creation, modification, and repositioning |
677 | functions to vary the topic bullet char (the char that marks the topic | |
678 | depth) just preceding the start of the topic text) according to level. | |
353e2ef2 | 679 | Otherwise, only asterisks (`*') and distinctive bullets are used. |
19b84ba3 RS |
680 | |
681 | This is how an outline can look (but sans indentation) with stylish | |
682 | prefixes: | |
c567ac01 RS |
683 | |
684 | * Top level | |
685 | .* A topic | |
686 | . + One level 3 subtopic | |
687 | . . One level 4 subtopic | |
19b84ba3 | 688 | . . A second 4 subtopic |
c567ac01 | 689 | . + Another level 3 subtopic |
19b84ba3 RS |
690 | . #1 A numbered level 4 subtopic |
691 | . #2 Another | |
692 | . ! Another level 4 subtopic with a different distinctive bullet | |
693 | . #4 And another numbered level 4 subtopic | |
c567ac01 | 694 | |
19b84ba3 RS |
695 | This would be an outline with stylish prefixes inhibited (but the |
696 | numbered and other distinctive bullets retained): | |
c567ac01 RS |
697 | |
698 | * Top level | |
699 | .* A topic | |
19b84ba3 RS |
700 | . * One level 3 subtopic |
701 | . * One level 4 subtopic | |
702 | . * A second 4 subtopic | |
703 | . * Another level 3 subtopic | |
704 | . #1 A numbered level 4 subtopic | |
705 | . #2 Another | |
706 | . ! Another level 4 subtopic with a different distinctive bullet | |
707 | . #4 And another numbered level 4 subtopic | |
c567ac01 RS |
708 | |
709 | Stylish and constant prefixes (as well as old-style prefixes) are | |
710 | always respected by the topic maneuvering functions, regardless of | |
711 | this variable setting. | |
712 | ||
2265e017 | 713 | The setting of this var is not relevant when `allout-old-style-prefixes' |
4bef9110 SE |
714 | is non-nil." |
715 | :type 'boolean | |
716 | :group 'allout) | |
fd5359c6 | 717 | (make-variable-buffer-local 'allout-stylish-prefixes) |
8570ce80 SM |
718 | ;;;###autoload |
719 | (put 'allout-stylish-prefixes 'safe-local-variable | |
4f91a816 | 720 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 721 | |
fd5359c6 MR |
722 | ;;;_ = allout-numbered-bullet |
723 | (defcustom allout-numbered-bullet "#" | |
9201cc28 | 724 | "String designating bullet of topics that have auto-numbering; nil for none. |
19b84ba3 | 725 | |
a0776d6b | 726 | Topics having this bullet have automatic maintenance of a sibling |
19b84ba3 | 727 | sequence-number tacked on, just after the bullet. Conventionally set |
c567ac01 | 728 | to \"#\", you can set it to a bullet of your choice. A nil value |
4bef9110 SE |
729 | disables numbering maintenance." |
730 | :type '(choice (const nil) string) | |
731 | :group 'allout) | |
fd5359c6 | 732 | (make-variable-buffer-local 'allout-numbered-bullet) |
8570ce80 | 733 | ;;;###autoload |
64686e6d RS |
734 | (put 'allout-numbered-bullet 'safe-local-variable |
735 | (if (fboundp 'string-or-null-p) | |
736 | 'string-or-null-p | |
4f91a816 | 737 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
738 | ;;;_ = allout-file-xref-bullet |
739 | (defcustom allout-file-xref-bullet "@" | |
9201cc28 | 740 | "Bullet signifying file cross-references, for `allout-resolve-xref'. |
19b84ba3 | 741 | |
9179616f | 742 | Set this var to the bullet you want to use for file cross-references." |
4bef9110 SE |
743 | :type '(choice (const nil) string) |
744 | :group 'allout) | |
8570ce80 | 745 | ;;;###autoload |
64686e6d RS |
746 | (put 'allout-file-xref-bullet 'safe-local-variable |
747 | (if (fboundp 'string-or-null-p) | |
748 | 'string-or-null-p | |
4f91a816 | 749 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
750 | ;;;_ = allout-presentation-padding |
751 | (defcustom allout-presentation-padding 2 | |
9201cc28 | 752 | "Presentation-format white-space padding factor, for greater indent." |
9179616f DL |
753 | :type 'integer |
754 | :group 'allout) | |
755 | ||
fd5359c6 | 756 | (make-variable-buffer-local 'allout-presentation-padding) |
8570ce80 SM |
757 | ;;;###autoload |
758 | (put 'allout-presentation-padding 'safe-local-variable 'integerp) | |
9179616f | 759 | |
96497653 KM |
760 | ;;;_ = allout-flattened-numbering-abbreviation |
761 | (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering | |
c6eee9aa | 762 | 'allout-flattened-numbering-abbreviation "24.1") |
96497653 | 763 | (defcustom allout-flattened-numbering-abbreviation nil |
9201cc28 | 764 | "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic |
9179616f DL |
765 | numbers to minimal amount with some context. Otherwise, entire |
766 | numbers are always used." | |
767 | :type 'boolean | |
768 | :group 'allout) | |
769 | ||
c567ac01 | 770 | ;;;_ + LaTeX formatting |
fd5359c6 MR |
771 | ;;;_ - allout-number-pages |
772 | (defcustom allout-number-pages nil | |
9201cc28 | 773 | "Non-nil turns on page numbering for LaTeX formatting of an outline." |
4bef9110 SE |
774 | :type 'boolean |
775 | :group 'allout) | |
fd5359c6 MR |
776 | ;;;_ - allout-label-style |
777 | (defcustom allout-label-style "\\large\\bf" | |
9201cc28 | 778 | "Font and size of labels for LaTeX formatting of an outline." |
4bef9110 SE |
779 | :type 'string |
780 | :group 'allout) | |
fd5359c6 MR |
781 | ;;;_ - allout-head-line-style |
782 | (defcustom allout-head-line-style "\\large\\sl " | |
9201cc28 | 783 | "Font and size of entries for LaTeX formatting of an outline." |
4bef9110 SE |
784 | :type 'string |
785 | :group 'allout) | |
fd5359c6 MR |
786 | ;;;_ - allout-body-line-style |
787 | (defcustom allout-body-line-style " " | |
9201cc28 | 788 | "Font and size of entries for LaTeX formatting of an outline." |
4bef9110 SE |
789 | :type 'string |
790 | :group 'allout) | |
fd5359c6 MR |
791 | ;;;_ - allout-title-style |
792 | (defcustom allout-title-style "\\Large\\bf" | |
9201cc28 | 793 | "Font and size of titles for LaTeX formatting of an outline." |
4bef9110 SE |
794 | :type 'string |
795 | :group 'allout) | |
fd5359c6 | 796 | ;;;_ - allout-title |
d82979ea | 797 | (defcustom allout-title '(or buffer-file-name (buffer-name)) |
9201cc28 | 798 | "Expression to be evaluated to determine the title for LaTeX |
4bef9110 SE |
799 | formatted copy." |
800 | :type 'sexp | |
801 | :group 'allout) | |
fd5359c6 MR |
802 | ;;;_ - allout-line-skip |
803 | (defcustom allout-line-skip ".05cm" | |
9201cc28 | 804 | "Space between lines for LaTeX formatting of an outline." |
4bef9110 SE |
805 | :type 'string |
806 | :group 'allout) | |
fd5359c6 MR |
807 | ;;;_ - allout-indent |
808 | (defcustom allout-indent ".3cm" | |
9201cc28 | 809 | "LaTeX formatted depth-indent spacing." |
4bef9110 SE |
810 | :type 'string |
811 | :group 'allout) | |
c567ac01 | 812 | |
d82979ea | 813 | ;;;_ + Topic encryption |
8570ce80 SM |
814 | ;;;_ = allout-encryption group |
815 | (defgroup allout-encryption nil | |
816 | "Settings for topic encryption features of allout outliner." | |
817 | :group 'allout) | |
d82979ea EZ |
818 | ;;;_ = allout-topic-encryption-bullet |
819 | (defcustom allout-topic-encryption-bullet "~" | |
9201cc28 | 820 | "Bullet signifying encryption of the entry's body." |
d82979ea | 821 | :type '(choice (const nil) string) |
21e8bc99 | 822 | :version "22.1" |
8570ce80 | 823 | :group 'allout-encryption) |
d82979ea | 824 | ;;;_ = allout-encrypt-unencrypted-on-saves |
96b83743 | 825 | (defcustom allout-encrypt-unencrypted-on-saves t |
9201cc28 | 826 | "When saving, should topics pending encryption be encrypted? |
d82979ea EZ |
827 | |
828 | The idea is to prevent file-system exposure of any un-encrypted stuff, and | |
829 | mostly covers both deliberate file writes and auto-saves. | |
830 | ||
831 | - Yes: encrypt all topics pending encryption, even if it's the one | |
c07583cd | 832 | currently being edited. (In that case, the currently edited topic |
d82979ea EZ |
833 | will be automatically decrypted before any user interaction, so they |
834 | can continue editing but the copy on the file system will be | |
835 | encrypted.) | |
836 | Auto-saves will use the \"All except current topic\" mode if this | |
60c7bbd2 | 837 | one is selected, to avoid practical difficulties -- see below. |
d82979ea EZ |
838 | - All except current topic: skip the topic currently being edited, even if |
839 | it's pending encryption. This may expose the current topic on the | |
840 | file sytem, but avoids the nuisance of prompts for the encryption | |
0949617b | 841 | passphrase in the middle of editing for, eg, autosaves. |
d82979ea EZ |
842 | This mode is used for auto-saves for both this option and \"Yes\". |
843 | - No: leave it to the user to encrypt any unencrypted topics. | |
844 | ||
845 | For practical reasons, auto-saves always use the 'except-current policy | |
c07583cd | 846 | when auto-encryption is enabled. (Otherwise, spurious passphrase prompts |
0949617b EZ |
847 | and unavoidable timing collisions are too disruptive.) If security for a |
848 | file requires that even the current topic is never auto-saved in the clear, | |
d82979ea EZ |
849 | disable auto-saves for that file." |
850 | ||
851 | :type '(choice (const :tag "Yes" t) | |
852 | (const :tag "All except current topic" except-current) | |
853 | (const :tag "No" nil)) | |
21e8bc99 | 854 | :version "22.1" |
8570ce80 | 855 | :group 'allout-encryption) |
d82979ea EZ |
856 | (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) |
857 | ||
01fc9422 EZ |
858 | ;;;_ + Developer |
859 | ;;;_ = allout-developer group | |
860 | (defgroup allout-developer nil | |
1c9b9df0 | 861 | "Allout settings developers care about, including topic encryption and more." |
01fc9422 EZ |
862 | :group 'allout) |
863 | ;;;_ = allout-run-unit-tests-on-load | |
864 | (defcustom allout-run-unit-tests-on-load nil | |
9201cc28 | 865 | "When non-nil, unit tests will be run at end of loading the allout module. |
01fc9422 EZ |
866 | |
867 | Generally, allout code developers are the only ones who'll want to set this. | |
868 | ||
869 | \(If set, this makes it an even better practice to exercise changes by | |
5204800f NR |
870 | doing byte-compilation with a repeat count, so the file is loaded after |
871 | compilation.) | |
01fc9422 EZ |
872 | |
873 | See `allout-run-unit-tests' to see what's run." | |
874 | :type 'boolean | |
875 | :group 'allout-developer) | |
876 | ||
c567ac01 RS |
877 | ;;;_ + Miscellaneous customization |
878 | ||
d82979ea EZ |
879 | ;;;_ = allout-enable-file-variable-adjustment |
880 | (defcustom allout-enable-file-variable-adjustment t | |
9201cc28 | 881 | "If non-nil, some allout outline actions edit Emacs local file var text. |
d82979ea EZ |
882 | |
883 | This can range from changes to existing entries, addition of new ones, | |
884 | and creation of a new local variables section when necessary. | |
19b84ba3 | 885 | |
d82979ea EZ |
886 | Emacs file variables adjustments are also inhibited if `enable-local-variables' |
887 | is nil. | |
c567ac01 | 888 | |
d82979ea | 889 | Operations potentially causing edits include allout encryption routines. |
69027dea | 890 | For details, see `allout-toggle-current-subtree-encryption's docstring." |
4bef9110 SE |
891 | :type 'boolean |
892 | :group 'allout) | |
d82979ea | 893 | (make-variable-buffer-local 'allout-enable-file-variable-adjustment) |
c567ac01 | 894 | |
60c7bbd2 | 895 | ;;;_* CODE -- no user customizations below. |
c567ac01 | 896 | |
9179616f DL |
897 | ;;;_ #1 Internal Outline Formatting and Configuration |
898 | ;;;_ : Version | |
fd5359c6 | 899 | ;;;_ = allout-version |
0af8c88b | 900 | (defvar allout-version "2.3" |
c07583cd | 901 | "Version of currently loaded outline package. (allout.el)") |
fd5359c6 MR |
902 | ;;;_ > allout-version |
903 | (defun allout-version (&optional here) | |
19b84ba3 RS |
904 | "Return string describing the loaded outline version." |
905 | (interactive "P") | |
fd5359c6 | 906 | (let ((msg (concat "Allout Outline Mode v " allout-version))) |
eac9cf5f | 907 | (if here (insert msg)) |
19b84ba3 RS |
908 | (message "%s" msg) |
909 | msg)) | |
69027dea EZ |
910 | ;;;_ : Mode activation (defined here because it's referenced early) |
911 | ;;;_ = allout-mode | |
912 | (defvar allout-mode nil "Allout outline mode minor-mode flag.") | |
913 | (make-variable-buffer-local 'allout-mode) | |
4034b0e2 | 914 | ;;;_ = allout-layout nil |
60c7bbd2 | 915 | (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring. |
4034b0e2 LT |
916 | "Buffer-specific setting for allout layout. |
917 | ||
11c46e15 KM |
918 | In buffers where this is non-nil \(and if `allout-auto-activation' |
919 | has been customized to enable this behavior), `allout-mode' will be | |
920 | automatically activated. The layout dictated by the value will be used to | |
921 | set the initial exposure when `allout-mode' is activated. | |
4034b0e2 LT |
922 | |
923 | \*You should not setq-default this variable non-nil unless you want every | |
924 | visited file to be treated as an allout file.* | |
925 | ||
926 | The value would typically be set by a file local variable. For | |
927 | example, the following lines at the bottom of an Emacs Lisp file: | |
928 | ||
929 | ;;;Local variables: | |
c07583cd | 930 | ;;;allout-layout: (0 : -1 -1 0) |
4034b0e2 LT |
931 | ;;;End: |
932 | ||
933 | dictate activation of `allout-mode' mode when the file is visited | |
11c46e15 KM |
934 | \(presuming proper `allout-auto-activation' customization), |
935 | followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'. | |
936 | \(This is the layout used for the allout.el source file.) | |
4034b0e2 LT |
937 | |
938 | `allout-default-layout' describes the specification format. | |
939 | `allout-layout' can additionally have the value `t', in which | |
940 | case the value of `allout-default-layout' is used.") | |
941 | (make-variable-buffer-local 'allout-layout) | |
b1a569b5 | 942 | ;;;###autoload |
8570ce80 | 943 | (put 'allout-layout 'safe-local-variable |
4f91a816 | 944 | (lambda (x) (or (numberp x) (listp x) (memq x '(: * + -))))) |
4034b0e2 | 945 | |
9179616f | 946 | ;;;_ : Topic header format |
fd5359c6 MR |
947 | ;;;_ = allout-regexp |
948 | (defvar allout-regexp "" | |
c567ac01 | 949 | "*Regular expression to match the beginning of a heading line. |
19b84ba3 | 950 | |
c567ac01 RS |
951 | Any line whose beginning matches this regexp is considered a |
952 | heading. This var is set according to the user configuration vars | |
2265e017 | 953 | by `set-allout-regexp'.") |
fd5359c6 MR |
954 | (make-variable-buffer-local 'allout-regexp) |
955 | ;;;_ = allout-bullets-string | |
956 | (defvar allout-bullets-string "" | |
19b84ba3 RS |
957 | "A string dictating the valid set of outline topic bullets. |
958 | ||
60c7bbd2 | 959 | This var should *not* be set by the user -- it is set by `set-allout-regexp', |
fd5359c6 MR |
960 | and is produced from the elements of `allout-plain-bullets-string' |
961 | and `allout-distinctive-bullets-string'.") | |
962 | (make-variable-buffer-local 'allout-bullets-string) | |
963 | ;;;_ = allout-bullets-string-len | |
964 | (defvar allout-bullets-string-len 0 | |
2265e017 | 965 | "Length of current buffers' `allout-plain-bullets-string'.") |
fd5359c6 | 966 | (make-variable-buffer-local 'allout-bullets-string-len) |
d8350998 CY |
967 | ;;;_ = allout-depth-specific-regexp |
968 | (defvar allout-depth-specific-regexp "" | |
969 | "*Regular expression to match a heading line prefix for a particular depth. | |
970 | ||
971 | This expression is used to search for depth-specific topic | |
972 | headers at depth 2 and greater. Use `allout-depth-one-regexp' | |
973 | for to seek topics at depth one. | |
974 | ||
975 | This var is set according to the user configuration vars by | |
976 | `set-allout-regexp'. It is prepared with format strings for two | |
977 | decimal numbers, which should each be one less than the depth of the | |
978 | topic prefix to be matched.") | |
979 | (make-variable-buffer-local 'allout-depth-specific-regexp) | |
980 | ;;;_ = allout-depth-one-regexp | |
981 | (defvar allout-depth-one-regexp "" | |
982 | "*Regular expression to match a heading line prefix for depth one. | |
983 | ||
984 | This var is set according to the user configuration vars by | |
985 | `set-allout-regexp'. It is prepared with format strings for two | |
986 | decimal numbers, which should each be one less than the depth of the | |
987 | topic prefix to be matched.") | |
988 | (make-variable-buffer-local 'allout-depth-one-regexp) | |
fd5359c6 MR |
989 | ;;;_ = allout-line-boundary-regexp |
990 | (defvar allout-line-boundary-regexp () | |
42c3e51c | 991 | "`allout-regexp' prepended with a newline for the search target. |
19b84ba3 | 992 | |
d8350998 | 993 | This is properly set by `set-allout-regexp'.") |
fd5359c6 MR |
994 | (make-variable-buffer-local 'allout-line-boundary-regexp) |
995 | ;;;_ = allout-bob-regexp | |
996 | (defvar allout-bob-regexp () | |
d8350998 | 997 | "Like `allout-line-boundary-regexp', for headers at beginning of buffer.") |
fd5359c6 MR |
998 | (make-variable-buffer-local 'allout-bob-regexp) |
999 | ;;;_ = allout-header-subtraction | |
1000 | (defvar allout-header-subtraction (1- (length allout-header-prefix)) | |
1001 | "Allout-header prefix length to subtract when computing topic depth.") | |
1002 | (make-variable-buffer-local 'allout-header-subtraction) | |
1003 | ;;;_ = allout-plain-bullets-string-len | |
1004 | (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) | |
2265e017 | 1005 | "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") |
fd5359c6 MR |
1006 | (make-variable-buffer-local 'allout-plain-bullets-string-len) |
1007 | ||
d8350998 | 1008 | ;;;_ = allout-doublecheck-at-and-shallower |
2a1408fd | 1009 | (defconst allout-doublecheck-at-and-shallower 3 |
ede4ac6a | 1010 | "Validate apparent topics of this depth and shallower as being non-aberrant. |
fd5359c6 | 1011 | |
2a1408fd DN |
1012 | Verified with `allout-aberrant-container-p'. The usefulness of |
1013 | this check is limited to shallow depths, because the | |
1014 | determination of aberrance is according to the mistaken item | |
1015 | being followed by a legitimate item of excessively greater depth. | |
1016 | ||
1017 | The classic example of a mistaken item, for a standard allout | |
1018 | outline configuration, is a body line that begins with an '...' | |
1019 | ellipsis. This happens to contain a legitimate depth-2 header | |
1020 | prefix, constituted by two '..' dots at the beginning of the | |
1021 | line. The only thing that can distinguish it *in principle* from | |
1022 | a legitimate one is if the following real header is at a depth | |
1023 | that is discontinuous from the depth of 2 implied by the | |
1024 | ellipsis, ie depth 4 or more. As the depth being tested gets | |
1025 | greater, the likelihood of this kind of disqualification is | |
1026 | lower, and the usefulness of this test is lower. | |
1027 | ||
1028 | Extending the depth of the doublecheck increases the amount it is | |
1029 | applied, increasing the cost of the test - on casual estimation, | |
1030 | for outlines with many deep topics, geometrically (O(n)?). | |
1031 | Taken together with decreasing likelihood that the test will be | |
1032 | useful at greater depths, more modest doublecheck limits are more | |
1033 | suitably economical.") | |
fd5359c6 MR |
1034 | ;;;_ X allout-reset-header-lead (header-lead) |
1035 | (defun allout-reset-header-lead (header-lead) | |
9201cc28 | 1036 | "Reset the leading string used to identify topic headers." |
1977b8f6 | 1037 | (interactive "sNew lead string: ") |
fd5359c6 MR |
1038 | (setq allout-header-prefix header-lead) |
1039 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
1040 | (set-allout-regexp)) | |
1041 | ;;;_ X allout-lead-with-comment-string (header-lead) | |
1042 | (defun allout-lead-with-comment-string (&optional header-lead) | |
9201cc28 | 1043 | "Set the topic-header leading string to specified string. |
19b84ba3 RS |
1044 | |
1045 | Useful when for encapsulating outline structure in programming | |
1046 | language comments. Returns the leading string." | |
1977b8f6 RS |
1047 | |
1048 | (interactive "P") | |
1049 | (if (not (stringp header-lead)) | |
1050 | (setq header-lead (read-string | |
1051 | "String prefix for topic headers: "))) | |
fd5359c6 MR |
1052 | (setq allout-reindent-bodies nil) |
1053 | (allout-reset-header-lead header-lead) | |
1977b8f6 | 1054 | header-lead) |
48bd8440 EZ |
1055 | ;;;_ > allout-infer-header-lead-and-primary-bullet () |
1056 | (defun allout-infer-header-lead-and-primary-bullet () | |
1057 | "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'. | |
19b84ba3 RS |
1058 | |
1059 | Works according to settings of: | |
1060 | ||
8d118843 | 1061 | `comment-start' |
fd5359c6 MR |
1062 | `allout-header-prefix' (default) |
1063 | `allout-use-mode-specific-leader' | |
1064 | and `allout-mode-leaders'. | |
19b84ba3 | 1065 | |
c07583cd | 1066 | Apply this via (re)activation of `allout-mode', rather than |
8d118843 | 1067 | invoking it directly." |
fd5359c6 MR |
1068 | (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) |
1069 | (if (or (stringp allout-use-mode-specific-leader) | |
1070 | (memq allout-use-mode-specific-leader | |
1071 | '(allout-mode-leaders | |
19b84ba3 RS |
1072 | comment-start |
1073 | t))) | |
fd5359c6 | 1074 | allout-use-mode-specific-leader |
60c7bbd2 | 1075 | ;; Oops -- garbled value, equate with effect of t: |
19b84ba3 RS |
1076 | t))) |
1077 | (leader | |
1078 | (cond | |
1079 | ((not use-leader) nil) | |
1080 | ;; Use the explicitly designated leader: | |
1081 | ((stringp use-leader) use-leader) | |
fd5359c6 | 1082 | (t (or (and (memq use-leader '(t allout-mode-leaders)) |
19b84ba3 | 1083 | ;; Get it from outline mode leaders? |
fd5359c6 MR |
1084 | (cdr (assq major-mode allout-mode-leaders))) |
1085 | ;; ... didn't get from allout-mode-leaders... | |
19b84ba3 RS |
1086 | (and (memq use-leader '(t comment-start)) |
1087 | comment-start | |
1088 | ;; Use comment-start, maybe tripled, and with | |
353e2ef2 | 1089 | ;; underscore: |
19b84ba3 RS |
1090 | (concat |
1091 | (if (string= " " | |
1092 | (substring comment-start | |
1093 | (1- (length comment-start)))) | |
1094 | ;; Use comment-start, sans trailing space: | |
1095 | (substring comment-start 0 -1) | |
1096 | (concat comment-start comment-start comment-start)) | |
1097 | ;; ... and append underscore, whichever: | |
1098 | "_"))))))) | |
1099 | (if (not leader) | |
1100 | nil | |
48bd8440 EZ |
1101 | (setq allout-header-prefix leader) |
1102 | (if (not allout-old-style-prefixes) | |
ea18b2b1 | 1103 | ;; setting allout-primary-bullet makes the top level topics use -- |
60c7bbd2 | 1104 | ;; actually, be -- the special prefix: |
48bd8440 EZ |
1105 | (setq allout-primary-bullet leader)) |
1106 | allout-header-prefix))) | |
1107 | (defalias 'allout-infer-header-lead | |
1108 | 'allout-infer-header-lead-and-primary-bullet) | |
fd5359c6 MR |
1109 | ;;;_ > allout-infer-body-reindent () |
1110 | (defun allout-infer-body-reindent () | |
1111 | "Determine proper setting for `allout-reindent-bodies'. | |
8d118843 | 1112 | |
c07583cd | 1113 | Depends on default setting of `allout-reindent-bodies' (which see) |
8d118843 RS |
1114 | and presence of setting for `comment-start', to tell whether the |
1115 | file is programming code." | |
fd5359c6 | 1116 | (if (and allout-reindent-bodies |
8d118843 | 1117 | comment-start |
fd5359c6 MR |
1118 | (not (eq 'force allout-reindent-bodies))) |
1119 | (setq allout-reindent-bodies nil))) | |
1120 | ;;;_ > set-allout-regexp () | |
1121 | (defun set-allout-regexp () | |
19b84ba3 RS |
1122 | "Generate proper topic-header regexp form for outline functions. |
1123 | ||
fd5359c6 | 1124 | Works with respect to `allout-plain-bullets-string' and |
d8350998 CY |
1125 | `allout-distinctive-bullets-string'. |
1126 | ||
1127 | Also refresh various data structures that hinge on the regexp." | |
1977b8f6 RS |
1128 | |
1129 | (interactive) | |
fd5359c6 MR |
1130 | ;; Derive allout-bullets-string from user configured components: |
1131 | (setq allout-bullets-string "") | |
1132 | (let ((strings (list 'allout-plain-bullets-string | |
1133 | 'allout-distinctive-bullets-string | |
1134 | 'allout-primary-bullet)) | |
1977b8f6 RS |
1135 | cur-string |
1136 | cur-len | |
c567ac01 | 1137 | cur-char |
96b83743 | 1138 | index) |
1977b8f6 | 1139 | (while strings |
96b83743 | 1140 | (setq index 0) |
1977b8f6 RS |
1141 | (setq cur-len (length (setq cur-string (symbol-value (car strings))))) |
1142 | (while (< index cur-len) | |
1143 | (setq cur-char (aref cur-string index)) | |
fd5359c6 MR |
1144 | (setq allout-bullets-string |
1145 | (concat allout-bullets-string | |
1977b8f6 RS |
1146 | (cond |
1147 | ; Single dash would denote a | |
1148 | ; sequence, repeated denotes | |
1149 | ; a dash: | |
1150 | ((eq cur-char ?-) "--") | |
1151 | ; literal close-square-bracket | |
1152 | ; doesn't work right in the | |
1153 | ; expr, exclude it: | |
1154 | ((eq cur-char ?\]) "") | |
1155 | (t (regexp-quote (char-to-string cur-char)))))) | |
1156 | (setq index (1+ index))) | |
1157 | (setq strings (cdr strings))) | |
1158 | ) | |
fd5359c6 MR |
1159 | ;; Derive next for repeated use in allout-pending-bullet: |
1160 | (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) | |
1161 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
d8350998 | 1162 | |
42c3e51c | 1163 | (let (new-part old-part formfeed-part) |
d8350998 CY |
1164 | (setq new-part (concat "\\(" |
1165 | (regexp-quote allout-header-prefix) | |
1166 | "[ \t]*" | |
1167 | ;; already regexp-quoted in a custom way: | |
1168 | "[" allout-bullets-string "]" | |
1169 | "\\)") | |
1170 | old-part (concat "\\(" | |
1171 | (regexp-quote allout-primary-bullet) | |
1172 | "\\|" | |
1173 | (regexp-quote allout-header-prefix) | |
1174 | "\\)" | |
1175 | "+" | |
1176 | " ?[^" allout-primary-bullet "]") | |
42c3e51c KM |
1177 | formfeed-part "\\(\^L\\)" |
1178 | ||
d8350998 CY |
1179 | allout-regexp (concat new-part |
1180 | "\\|" | |
1181 | old-part | |
42c3e51c KM |
1182 | "\\|" |
1183 | formfeed-part) | |
d8350998 CY |
1184 | |
1185 | allout-line-boundary-regexp (concat "\n" new-part | |
1186 | "\\|" | |
42c3e51c KM |
1187 | "\n" old-part |
1188 | "\\|" | |
1189 | "\n" formfeed-part) | |
d8350998 CY |
1190 | |
1191 | allout-bob-regexp (concat "\\`" new-part | |
1192 | "\\|" | |
42c3e51c KM |
1193 | "\\`" old-part |
1194 | "\\|" | |
1195 | "\\`" formfeed-part | |
1196 | )) | |
d8350998 CY |
1197 | |
1198 | (setq allout-depth-specific-regexp | |
1199 | (concat "\\(^\\|\\`\\)" | |
1200 | "\\(" | |
1201 | ||
1202 | ;; new-style spacers-then-bullet string: | |
1203 | "\\(" | |
1204 | (allout-format-quote (regexp-quote allout-header-prefix)) | |
1205 | " \\{%s\\}" | |
1206 | "[" (allout-format-quote allout-bullets-string) "]" | |
1207 | "\\)" | |
1208 | ||
1209 | ;; old-style all-bullets string, if primary not multi-char: | |
1210 | (if (< 0 allout-header-subtraction) | |
1211 | "" | |
1212 | (concat "\\|\\(" | |
1213 | (allout-format-quote | |
1214 | (regexp-quote allout-primary-bullet)) | |
1215 | (allout-format-quote | |
1216 | (regexp-quote allout-primary-bullet)) | |
1217 | (allout-format-quote | |
1218 | (regexp-quote allout-primary-bullet)) | |
1219 | "\\{%s\\}" | |
1220 | ;; disqualify greater depths: | |
1221 | "[^" | |
1222 | (allout-format-quote allout-primary-bullet) | |
1223 | "]\\)" | |
1224 | )) | |
1225 | "\\)" | |
1226 | )) | |
1227 | (setq allout-depth-one-regexp | |
1228 | (concat "\\(^\\|\\`\\)" | |
1229 | "\\(" | |
1230 | ||
1231 | "\\(" | |
1232 | (regexp-quote allout-header-prefix) | |
1233 | ;; disqualify any bullet char following any amount of | |
1234 | ;; intervening whitespace: | |
1235 | " *" | |
1236 | (concat "[^ " allout-bullets-string "]") | |
1237 | "\\)" | |
1238 | (if (< 0 allout-header-subtraction) | |
1239 | ;; Need not support anything like the old | |
1240 | ;; bullet style if the prefix is multi-char. | |
1241 | "" | |
1242 | (concat "\\|" | |
1243 | (regexp-quote allout-primary-bullet) | |
1244 | ;; disqualify deeper primary-bullet sequences: | |
1245 | "[^" allout-primary-bullet "]")) | |
1246 | "\\)" | |
1247 | )))) | |
9179616f | 1248 | ;;;_ : Menu bar |
95c12694 RS |
1249 | (defvar allout-mode-exposure-menu) |
1250 | (defvar allout-mode-editing-menu) | |
1251 | (defvar allout-mode-navigation-menu) | |
1252 | (defvar allout-mode-misc-menu) | |
fd5359c6 | 1253 | (defun produce-allout-mode-menubar-entries () |
9179616f | 1254 | (require 'easymenu) |
fd5359c6 | 1255 | (easy-menu-define allout-mode-exposure-menu |
d3e51865 | 1256 | allout-mode-map-value |
9179616f DL |
1257 | "Allout outline exposure menu." |
1258 | '("Exposure" | |
fd5359c6 MR |
1259 | ["Show Entry" allout-show-current-entry t] |
1260 | ["Show Children" allout-show-children t] | |
1261 | ["Show Subtree" allout-show-current-subtree t] | |
1262 | ["Hide Subtree" allout-hide-current-subtree t] | |
1263 | ["Hide Leaves" allout-hide-current-leaves t] | |
9179616f | 1264 | "----" |
fd5359c6 MR |
1265 | ["Show All" allout-show-all t])) |
1266 | (easy-menu-define allout-mode-editing-menu | |
d3e51865 | 1267 | allout-mode-map-value |
9179616f DL |
1268 | "Allout outline editing menu." |
1269 | '("Headings" | |
fd5359c6 MR |
1270 | ["Open Sibling" allout-open-sibtopic t] |
1271 | ["Open Subtopic" allout-open-subtopic t] | |
1272 | ["Open Supertopic" allout-open-supertopic t] | |
9179616f | 1273 | "----" |
fd5359c6 MR |
1274 | ["Shift Topic In" allout-shift-in t] |
1275 | ["Shift Topic Out" allout-shift-out t] | |
1276 | ["Rebullet Topic" allout-rebullet-topic t] | |
1277 | ["Rebullet Heading" allout-rebullet-current-heading t] | |
d82979ea EZ |
1278 | ["Number Siblings" allout-number-siblings t] |
1279 | "----" | |
1280 | ["Toggle Topic Encryption" | |
1281 | allout-toggle-current-subtree-encryption | |
1282 | (> (allout-current-depth) 1)])) | |
fd5359c6 | 1283 | (easy-menu-define allout-mode-navigation-menu |
d3e51865 | 1284 | allout-mode-map-value |
9179616f DL |
1285 | "Allout outline navigation menu." |
1286 | '("Navigation" | |
fd5359c6 | 1287 | ["Next Visible Heading" allout-next-visible-heading t] |
9179616f | 1288 | ["Previous Visible Heading" |
fd5359c6 | 1289 | allout-previous-visible-heading t] |
9179616f | 1290 | "----" |
fd5359c6 MR |
1291 | ["Up Level" allout-up-current-level t] |
1292 | ["Forward Current Level" allout-forward-current-level t] | |
9179616f | 1293 | ["Backward Current Level" |
fd5359c6 | 1294 | allout-backward-current-level t] |
9179616f DL |
1295 | "----" |
1296 | ["Beginning of Entry" | |
fd5359c6 | 1297 | allout-beginning-of-current-entry t] |
d82979ea | 1298 | ["End of Entry" allout-end-of-entry t] |
fd5359c6 MR |
1299 | ["End of Subtree" allout-end-of-current-subtree t])) |
1300 | (easy-menu-define allout-mode-misc-menu | |
d3e51865 | 1301 | allout-mode-map-value |
9179616f DL |
1302 | "Allout outlines miscellaneous bindings." |
1303 | '("Misc" | |
fd5359c6 | 1304 | ["Version" allout-version t] |
9179616f | 1305 | "----" |
fd5359c6 | 1306 | ["Duplicate Exposed" allout-copy-exposed-to-buffer t] |
9179616f | 1307 | ["Duplicate Exposed, numbered" |
71296446 | 1308 | allout-flatten-exposed-to-buffer t] |
9179616f | 1309 | ["Duplicate Exposed, indented" |
71296446 | 1310 | allout-indented-exposed-to-buffer t] |
9179616f | 1311 | "----" |
fd5359c6 MR |
1312 | ["Set Header Lead" allout-reset-header-lead t] |
1313 | ["Set New Exposure" allout-expose-topic t]))) | |
01fc9422 | 1314 | ;;;_ : Allout Modal-Variables Utilities |
fd5359c6 MR |
1315 | ;;;_ = allout-mode-prior-settings |
1316 | (defvar allout-mode-prior-settings nil | |
01fc9422 | 1317 | "Internal `allout-mode' use; settings to be resumed on mode deactivation. |
1977b8f6 | 1318 | |
01fc9422 EZ |
1319 | See `allout-add-resumptions' and `allout-do-resumptions'.") |
1320 | (make-variable-buffer-local 'allout-mode-prior-settings) | |
1321 | ;;;_ > allout-add-resumptions (&rest pairs) | |
1322 | (defun allout-add-resumptions (&rest pairs) | |
48bd8440 | 1323 | "Set name/value PAIRS. |
01fc9422 EZ |
1324 | |
1325 | Old settings are preserved for later resumption using `allout-do-resumptions'. | |
1326 | ||
48bd8440 EZ |
1327 | The new values are set as a buffer local. On resumption, the prior buffer |
1328 | scope of the variable is restored along with its value. If it was a void | |
1329 | buffer-local value, then it is left as nil on resumption. | |
1330 | ||
01fc9422 | 1331 | The pairs are lists whose car is the name of the variable and car of the |
48bd8440 EZ |
1332 | cdr is the new value: '(some-var some-value)'. The pairs can actually be |
1333 | triples, where the third element qualifies the disposition of the setting, | |
1334 | as described further below. | |
01fc9422 | 1335 | |
48bd8440 EZ |
1336 | If the optional third element is the symbol 'extend, then the new value |
1337 | created by `cons'ing the second element of the pair onto the front of the | |
1338 | existing value. | |
01fc9422 | 1339 | |
48bd8440 EZ |
1340 | If the optional third element is the symbol 'append, then the new value is |
1341 | extended from the existing one by `append'ing a list containing the second | |
1342 | element of the pair onto the end of the existing value. | |
01fc9422 | 1343 | |
48bd8440 | 1344 | Extension, and resumptions in general, should not be used for hook |
60c7bbd2 | 1345 | functions -- use the 'local mode of `add-hook' for that, instead. |
01fc9422 EZ |
1346 | |
1347 | The settings are stored on `allout-mode-prior-settings'." | |
1348 | (while pairs | |
1349 | (let* ((pair (pop pairs)) | |
1350 | (name (car pair)) | |
48bd8440 EZ |
1351 | (value (cadr pair)) |
1352 | (qualifier (if (> (length pair) 2) | |
1353 | (caddr pair))) | |
1354 | prior-value) | |
01fc9422 EZ |
1355 | (if (not (symbolp name)) |
1356 | (error "Pair's name, %S, must be a symbol, not %s" | |
1357 | name (type-of name))) | |
d8350998 | 1358 | (setq prior-value (condition-case nil |
48bd8440 EZ |
1359 | (symbol-value name) |
1360 | (void-variable nil))) | |
01fc9422 EZ |
1361 | (when (not (assoc name allout-mode-prior-settings)) |
1362 | ;; Not already added as a resumption, create the prior setting entry. | |
1c9b9df0 | 1363 | (if (local-variable-p name (current-buffer)) |
60c7bbd2 | 1364 | ;; is already local variable -- preserve the prior value: |
48bd8440 | 1365 | (push (list name prior-value) allout-mode-prior-settings) |
01fc9422 EZ |
1366 | ;; wasn't local variable, indicate so for resumption by killing |
1367 | ;; local value, and make it local: | |
1368 | (push (list name) allout-mode-prior-settings) | |
1369 | (make-local-variable name))) | |
48bd8440 EZ |
1370 | (if qualifier |
1371 | (cond ((eq qualifier 'extend) | |
1372 | (if (not (listp prior-value)) | |
1373 | (error "extension of non-list prior value attempted") | |
1374 | (set name (cons value prior-value)))) | |
1375 | ((eq qualifier 'append) | |
1376 | (if (not (listp prior-value)) | |
1377 | (error "appending of non-list prior value attempted") | |
1378 | (set name (append prior-value (list value))))) | |
1379 | (t (error "unrecognized setting qualifier `%s' encountered" | |
1380 | qualifier))) | |
1381 | (set name value))))) | |
01fc9422 EZ |
1382 | ;;;_ > allout-do-resumptions () |
1383 | (defun allout-do-resumptions () | |
1384 | "Resume all name/value settings registered by `allout-add-resumptions'. | |
1385 | ||
1386 | This is used when concluding allout-mode, to resume selected variables to | |
1387 | their settings before allout-mode was started." | |
1388 | ||
1389 | (while allout-mode-prior-settings | |
1390 | (let* ((pair (pop allout-mode-prior-settings)) | |
1391 | (name (car pair)) | |
1392 | (value-cell (cdr pair))) | |
1393 | (if (not value-cell) | |
1394 | ;; Prior value was global: | |
1395 | (kill-local-variable name) | |
1396 | ;; Prior value was explicit: | |
1397 | (set name (car value-cell)))))) | |
9179616f | 1398 | ;;;_ : Mode-specific incidentals |
fd5359c6 | 1399 | ;;;_ > allout-unprotected (expr) |
d82979ea | 1400 | (defmacro allout-unprotected (expr) |
96b83743 | 1401 | "Enable internal outline operations to alter invisible text." |
1b4d97b2 | 1402 | `(let ((inhibit-read-only (if (not buffer-read-only) t)) |
0458fa80 | 1403 | (inhibit-field-text-motion t)) |
96b83743 EZ |
1404 | ,expr)) |
1405 | ;;;_ = allout-mode-hook | |
1406 | (defvar allout-mode-hook nil | |
1407 | "*Hook that's run when allout mode starts.") | |
01fc9422 EZ |
1408 | ;;;_ = allout-mode-deactivate-hook |
1409 | (defvar allout-mode-deactivate-hook nil | |
1410 | "*Hook that's run when allout mode ends.") | |
7927f48d | 1411 | (define-obsolete-variable-alias 'allout-mode-deactivate-hook |
c6eee9aa | 1412 | 'allout-mode-off-hook "24.1") |
01fc9422 EZ |
1413 | ;;;_ = allout-exposure-category |
1414 | (defvar allout-exposure-category nil | |
1415 | "Symbol for use as allout invisible-text overlay category.") | |
da506f05 RS |
1416 | ;;;_ = allout-exposure-change-hook |
1417 | (defvar allout-exposure-change-hook nil | |
48bd8440 EZ |
1418 | "*Hook that's run after allout outline subtree exposure changes. |
1419 | ||
1420 | It is run at the conclusion of `allout-flag-region'. | |
1421 | ||
1422 | Functions on the hook must take three arguments: | |
1423 | ||
60c7bbd2 RS |
1424 | - FROM -- integer indicating the point at the start of the change. |
1425 | - TO -- integer indicating the point of the end of the change. | |
1426 | - FLAG -- change mode: nil for exposure, otherwise concealment. | |
48bd8440 | 1427 | |
1e004a83 | 1428 | This hook might be invoked multiple times by a single command.") |
48bd8440 EZ |
1429 | ;;;_ = allout-structure-added-hook |
1430 | (defvar allout-structure-added-hook nil | |
1431 | "*Hook that's run after addition of items to the outline. | |
1432 | ||
1433 | Functions on the hook should take two arguments: | |
1434 | ||
60c7bbd2 RS |
1435 | - NEW-START -- integer indicating position of start of the first new item. |
1436 | - NEW-END -- integer indicating position of end of the last new item. | |
48bd8440 | 1437 | |
48bd8440 EZ |
1438 | This hook might be invoked multiple times by a single command.") |
1439 | ;;;_ = allout-structure-deleted-hook | |
1440 | (defvar allout-structure-deleted-hook nil | |
1441 | "*Hook that's run after disciplined deletion of subtrees from the outline. | |
1442 | ||
1443 | Functions on the hook must take two arguments: | |
1444 | ||
60c7bbd2 RS |
1445 | - DEPTH -- integer indicating the depth of the subtree that was deleted. |
1446 | - REMOVED-FROM -- integer indicating the point where the subtree was removed. | |
da506f05 | 1447 | |
60c7bbd2 | 1448 | Some edits that remove or invalidate items may missed by this hook: |
48bd8440 | 1449 | specifically edits that native allout routines do not control. |
96b83743 | 1450 | |
48bd8440 EZ |
1451 | This hook might be invoked multiple times by a single command.") |
1452 | ;;;_ = allout-structure-shifted-hook | |
1453 | (defvar allout-structure-shifted-hook nil | |
1454 | "*Hook that's run after shifting of items in the outline. | |
1455 | ||
1456 | Functions on the hook should take two arguments: | |
1457 | ||
60c7bbd2 RS |
1458 | - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease |
1459 | - START -- integer indicating the start point of the shifted parent item. | |
48bd8440 | 1460 | |
60c7bbd2 | 1461 | Some edits that shift items can be missed by this hook: specifically edits |
48bd8440 EZ |
1462 | that native allout routines do not control. |
1463 | ||
1464 | This hook might be invoked multiple times by a single command.") | |
4ec28e14 KM |
1465 | ;;;_ = allout-after-copy-or-kill-hook |
1466 | (defvar allout-after-copy-or-kill-hook nil | |
1467 | "*Hook that's run after copying outline text. | |
1468 | ||
11c46e15 | 1469 | Functions on the hook should not take any arguments.") |
96b83743 EZ |
1470 | ;;;_ = allout-outside-normal-auto-fill-function |
1471 | (defvar allout-outside-normal-auto-fill-function nil | |
1472 | "Value of normal-auto-fill-function outside of allout mode. | |
1473 | ||
1474 | Used by allout-auto-fill to do the mandated normal-auto-fill-function | |
1475 | wrapped within allout's automatic fill-prefix setting.") | |
1476 | (make-variable-buffer-local 'allout-outside-normal-auto-fill-function) | |
2576c28f KM |
1477 | ;;;_ = prevent redundant activation by desktop mode: |
1478 | (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil)) | |
0949617b EZ |
1479 | ;;;_ = allout-passphrase-verifier-string |
1480 | (defvar allout-passphrase-verifier-string nil | |
1481 | "Setting used to test solicited encryption passphrases against the one | |
1482 | already associated with a file. | |
1483 | ||
1484 | It consists of an encrypted random string useful only to verify that a | |
1485 | passphrase entered by the user is effective for decryption. The passphrase | |
1486 | itself is \*not* recorded in the file anywhere, and the encrypted contents | |
1487 | are random binary characters to avoid exposing greater susceptibility to | |
1488 | search attacks. | |
d82979ea EZ |
1489 | |
1490 | The verifier string is retained as an Emacs file variable, as well as in | |
a0a022d5 | 1491 | the Emacs buffer state, if file variable adjustments are enabled. See |
d82979ea | 1492 | `allout-enable-file-variable-adjustment' for details about that.") |
0949617b | 1493 | (make-variable-buffer-local 'allout-passphrase-verifier-string) |
29fac3fe KM |
1494 | (make-obsolete 'allout-passphrase-verifier-string |
1495 | 'allout-passphrase-verifier-string "23.3") | |
8570ce80 | 1496 | ;;;###autoload |
7e5d77dc | 1497 | (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp) |
0949617b EZ |
1498 | ;;;_ = allout-passphrase-hint-string |
1499 | (defvar allout-passphrase-hint-string "" | |
1500 | "Variable used to retain reminder string for file's encryption passphrase. | |
d82979ea | 1501 | |
0949617b | 1502 | See the description of `allout-passphrase-hint-handling' for details about how |
d82979ea EZ |
1503 | the reminder is deployed. |
1504 | ||
a0a022d5 | 1505 | The hint is retained as an Emacs file variable, as well as in the Emacs buffer |
d82979ea EZ |
1506 | state, if file variable adjustments are enabled. See |
1507 | `allout-enable-file-variable-adjustment' for details about that.") | |
0949617b EZ |
1508 | (make-variable-buffer-local 'allout-passphrase-hint-string) |
1509 | (setq-default allout-passphrase-hint-string "") | |
29fac3fe KM |
1510 | (make-obsolete 'allout-passphrase-hint-string |
1511 | 'allout-passphrase-hint-string "23.3") | |
8570ce80 SM |
1512 | ;;;###autoload |
1513 | (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp) | |
d82979ea EZ |
1514 | ;;;_ = allout-after-save-decrypt |
1515 | (defvar allout-after-save-decrypt nil | |
1516 | "Internal variable, is nil or has the value of two points: | |
1517 | ||
1518 | - the location of a topic to be decrypted after saving is done | |
1519 | - where to situate the cursor after the decryption is performed | |
1520 | ||
1521 | This is used to decrypt the topic that was currently being edited, if it | |
1522 | was encrypted automatically as part of a file write or autosave.") | |
1523 | (make-variable-buffer-local 'allout-after-save-decrypt) | |
48bd8440 EZ |
1524 | ;;;_ = allout-encryption-plaintext-sanitization-regexps |
1525 | (defvar allout-encryption-plaintext-sanitization-regexps nil | |
1526 | "List of regexps whose matches are removed from plaintext before encryption. | |
1527 | ||
1528 | This is for the sake of removing artifacts, like escapes, that are added on | |
1529 | and not actually part of the original plaintext. The removal is done just | |
1530 | prior to encryption. | |
1531 | ||
1532 | Entries must be symbols that are bound to the desired values. | |
1533 | ||
1534 | Each value can be a regexp or a list with a regexp followed by a | |
1535 | substitution string. If it's just a regexp, all its matches are removed | |
1536 | before the text is encrypted. If it's a regexp and a substitution, the | |
1537 | substition is used against the regexp matches, a la `replace-match'.") | |
1538 | (make-variable-buffer-local 'allout-encryption-text-removal-regexps) | |
1539 | ;;;_ = allout-encryption-ciphertext-rejection-regexps | |
1540 | (defvar allout-encryption-ciphertext-rejection-regexps nil | |
1541 | "Variable for regexps matching plaintext to remove before encryption. | |
1542 | ||
ff3e8c8e KM |
1543 | This is used to detect strings in encryption results that would |
1544 | register as allout mode structural elements, for exmple, as a | |
1545 | topic prefix. | |
48bd8440 EZ |
1546 | |
1547 | Entries must be symbols that are bound to the desired regexp values. | |
1548 | ||
ff3e8c8e KM |
1549 | Encryptions that result in matches will be retried, up to |
1550 | `allout-encryption-ciphertext-rejection-limit' times, after which | |
1551 | an error is raised.") | |
48bd8440 EZ |
1552 | |
1553 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps) | |
1554 | ;;;_ = allout-encryption-ciphertext-rejection-ceiling | |
1555 | (defvar allout-encryption-ciphertext-rejection-ceiling 5 | |
1556 | "Limit on number of times encryption ciphertext is rejected. | |
1557 | ||
1558 | See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.") | |
1559 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling) | |
69027dea EZ |
1560 | ;;;_ > allout-mode-p () |
1561 | ;; Must define this macro above any uses, or byte compilation will lack | |
60c7bbd2 | 1562 | ;; proper def, if file isn't loaded -- eg, during emacs build! |
96497653 | 1563 | ;;;###autoload |
69027dea EZ |
1564 | (defmacro allout-mode-p () |
1565 | "Return t if `allout-mode' is active in current buffer." | |
1566 | 'allout-mode) | |
d82979ea EZ |
1567 | ;;;_ > allout-write-file-hook-handler () |
1568 | (defun allout-write-file-hook-handler () | |
1569 | "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes." | |
1570 | ||
0949617b EZ |
1571 | (if (or (not (allout-mode-p)) |
1572 | (not (boundp 'allout-encrypt-unencrypted-on-saves)) | |
d82979ea EZ |
1573 | (not allout-encrypt-unencrypted-on-saves)) |
1574 | nil | |
1575 | (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves | |
1576 | 'except-current) | |
1577 | (point-marker)))) | |
1578 | (if (save-excursion (goto-char (point-min)) | |
1579 | (allout-next-topic-pending-encryption except-mark)) | |
1580 | (progn | |
1581 | (message "auto-encrypting pending topics") | |
96b83743 | 1582 | (sit-for 0) |
d82979ea EZ |
1583 | (condition-case failure |
1584 | (setq allout-after-save-decrypt | |
1585 | (allout-encrypt-decrypted except-mark)) | |
42c3e51c KM |
1586 | (error (message |
1587 | "allout-write-file-hook-handler suppressing error %s" | |
1588 | failure) | |
1589 | (sit-for 2))))) | |
d82979ea | 1590 | )) |
42c3e51c | 1591 | nil) |
d82979ea EZ |
1592 | ;;;_ > allout-auto-save-hook-handler () |
1593 | (defun allout-auto-save-hook-handler () | |
69027dea | 1594 | "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save." |
d82979ea | 1595 | |
0949617b | 1596 | (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves) |
d82979ea EZ |
1597 | ;; Always implement 'except-current policy when enabled. |
1598 | (let ((allout-encrypt-unencrypted-on-saves 'except-current)) | |
1599 | (allout-write-file-hook-handler)))) | |
1600 | ;;;_ > allout-after-saves-handler () | |
1601 | (defun allout-after-saves-handler () | |
1602 | "Decrypt topic encrypted for save, if it's currently being edited. | |
1603 | ||
1604 | Ie, if it was pending encryption and contained the point in its body before | |
1605 | the save. | |
1606 | ||
1607 | We use values stored in `allout-after-save-decrypt' to locate the topic | |
1608 | and the place for the cursor after the decryption is done." | |
1609 | (if (not (and (allout-mode-p) | |
1610 | (boundp 'allout-after-save-decrypt) | |
1611 | allout-after-save-decrypt)) | |
1612 | t | |
1613 | (goto-char (car allout-after-save-decrypt)) | |
1614 | (let ((was-modified (buffer-modified-p))) | |
69027dea | 1615 | (allout-toggle-subtree-encryption) |
d82979ea EZ |
1616 | (if (not was-modified) |
1617 | (set-buffer-modified-p nil))) | |
1618 | (goto-char (cadr allout-after-save-decrypt)) | |
1619 | (setq allout-after-save-decrypt nil)) | |
1620 | ) | |
1c9b9df0 KM |
1621 | ;;;_ > allout-called-interactively-p () |
1622 | (defmacro allout-called-interactively-p () | |
1623 | "A version of called-interactively-p independent of emacs version." | |
1624 | ;; ... to ease maintenance of allout without betraying deprecation. | |
1625 | (if (equal (subr-arity (symbol-function 'called-interactively-p)) | |
1626 | '(0 . 0)) | |
1627 | '(called-interactively-p) | |
1628 | '(called-interactively-p 'interactive))) | |
498a6493 CY |
1629 | ;;;_ = allout-inhibit-aberrance-doublecheck nil |
1630 | ;; In some exceptional moments, disparate topic depths need to be allowed | |
1631 | ;; momentarily, eg when one topic is being yanked into another and they're | |
1632 | ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck | |
1633 | ;; prevents the aberrance doublecheck to allow, eg, the reconciliation | |
1634 | ;; processing to happen in the presence of such discrepancies. It should | |
1635 | ;; almost never be needed, however. | |
1636 | (defvar allout-inhibit-aberrance-doublecheck nil | |
1637 | "Internal state, for momentarily inhibits aberrance doublecheck. | |
1638 | ||
1639 | This should only be momentarily let-bound non-nil, not set | |
1640 | non-nil in a lasting way.") | |
19b84ba3 | 1641 | |
1c9b9df0 | 1642 | ;;;_ #2 Mode environment and activation |
fd5359c6 MR |
1643 | ;;;_ = allout-explicitly-deactivated |
1644 | (defvar allout-explicitly-deactivated nil | |
d82979ea | 1645 | "If t, `allout-mode's last deactivation was deliberate. |
2265e017 | 1646 | So `allout-post-command-business' should not reactivate it...") |
fd5359c6 | 1647 | (make-variable-buffer-local 'allout-explicitly-deactivated) |
11c46e15 KM |
1648 | ;;;_ > allout-init (mode) |
1649 | (defun allout-init (mode) | |
1650 | "DEPRECATED - configure allout activation by customizing | |
1651 | `allout-auto-activation'. This function remains around, limited | |
01c35094 | 1652 | from what it did before, for backwards compatibility. |
11c46e15 KM |
1653 | |
1654 | MODE is the activation mode - see `allout-auto-activation' for | |
1655 | valid values." | |
1656 | ||
1657 | (custom-set-variables (list 'allout-auto-activation (format "%s" mode))) | |
1658 | (format "%s" mode)) | |
1659 | (make-obsolete 'allout-init | |
1660 | "customize 'allout-auto-activation' instead." "23.3") | |
fd5359c6 MR |
1661 | ;;;_ > allout-setup-menubar () |
1662 | (defun allout-setup-menubar () | |
aad94676 | 1663 | "Populate the current buffer's menubar with `allout-mode' stuff." |
fd5359c6 MR |
1664 | (let ((menus (list allout-mode-exposure-menu |
1665 | allout-mode-editing-menu | |
1666 | allout-mode-navigation-menu | |
1667 | allout-mode-misc-menu)) | |
9179616f DL |
1668 | cur) |
1669 | (while menus | |
1670 | (setq cur (car menus) | |
1671 | menus (cdr menus)) | |
1672 | (easy-menu-add cur)))) | |
01fc9422 EZ |
1673 | ;;;_ > allout-overlay-preparations |
1674 | (defun allout-overlay-preparations () | |
1675 | "Set the properties of the allout invisible-text overlay and others." | |
1676 | (setplist 'allout-exposure-category nil) | |
1677 | (put 'allout-exposure-category 'invisible 'allout) | |
1678 | (put 'allout-exposure-category 'evaporate t) | |
1c9b9df0 | 1679 | ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The |
ea18b2b1 | 1680 | ;; latter would be sufficient, but it seems that a separate behavior -- |
60c7bbd2 RS |
1681 | ;; the _transient_ opening of invisible text during isearch -- is keyed to |
1682 | ;; presence of the isearch-open-invisible property -- even though this | |
96b83743 | 1683 | ;; property controls the isearch _arrival_ behavior. This is the case at |
21e8bc99 | 1684 | ;; least in emacs 21, 22.1, and xemacs 21.4. |
01fc9422 | 1685 | (put 'allout-exposure-category 'isearch-open-invisible |
96b83743 EZ |
1686 | 'allout-isearch-end-handler) |
1687 | (if (featurep 'xemacs) | |
01fc9422 EZ |
1688 | (put 'allout-exposure-category 'start-open t) |
1689 | (put 'allout-exposure-category 'insert-in-front-hooks | |
96b83743 | 1690 | '(allout-overlay-insert-in-front-handler))) |
01fc9422 EZ |
1691 | (put 'allout-exposure-category 'modification-hooks |
1692 | '(allout-overlay-interior-modification-handler))) | |
d3e51865 | 1693 | ;;;_ > define-minor-mode allout-mode |
19b84ba3 | 1694 | ;;;_ : Defun: |
0949617b | 1695 | ;;;###autoload |
d3e51865 | 1696 | (define-minor-mode allout-mode |
c567ac01 | 1697 | ;;;_ . Doc string: |
19b84ba3 | 1698 | "Toggle minor mode for controlling exposure and editing of text outlines. |
d3e51865 | 1699 | \\<allout-mode-map-value> |
19b84ba3 | 1700 | |
2576c28f | 1701 | Allout outline mode always runs as a minor mode. |
19b84ba3 | 1702 | |
2576c28f KM |
1703 | Allout outline mode provides extensive outline oriented |
1704 | formatting and manipulation. It enables structural editing of | |
1705 | outlines, as well as navigation and exposure. It also is | |
1706 | specifically aimed at accommodating syntax-sensitive text like | |
1707 | programming languages. \(For example, see the allout code itself, | |
1708 | which is organized as an allout outline.) | |
19b84ba3 | 1709 | |
c07583cd | 1710 | In addition to typical outline navigation and exposure, allout includes: |
19b84ba3 | 1711 | |
c07583cd KS |
1712 | - topic-oriented authoring, including keystroke-based topic creation, |
1713 | repositioning, promotion/demotion, cut, and paste | |
9179616f | 1714 | - incremental search with dynamic exposure and reconcealment of hidden text |
c07583cd | 1715 | - adjustable format, so programming code can be developed in outline-structure |
2576c28f | 1716 | - easy topic encryption and decryption, symmetric or key-pair |
c07583cd KS |
1717 | - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control |
1718 | - integral outline layout, for automatic initial exposure when visiting a file | |
1719 | - independent extensibility, using comprehensive exposure and authoring hooks | |
9179616f DL |
1720 | |
1721 | and many other features. | |
19b84ba3 | 1722 | |
2576c28f KM |
1723 | Below is a description of the key bindings, and then description |
1724 | of special `allout-mode' features and terminology. See also the | |
1725 | outline menubar additions for quick reference to many of the | |
11c46e15 KM |
1726 | features. Customize `allout-auto-activation' to prepare your |
1727 | emacs session for automatic activation of `allout-mode'. | |
9179616f | 1728 | |
d3e51865 KM |
1729 | The bindings are those listed in `allout-prefixed-keybindings' |
1730 | and `allout-unprefixed-keybindings'. We recommend customizing | |
1731 | `allout-command-prefix' to use just `\\C-c' as the command | |
1732 | prefix, if the allout bindings don't conflict with any personal | |
1733 | bindings you have on \\C-c. In any case, outline structure | |
1734 | navigation and authoring is simplified by positioning the cursor | |
1735 | on an item's bullet character, the \"hot-spot\" -- then you can | |
1736 | invoke allout commands with just the un-prefixed, | |
1737 | un-control-shifted command letters. This is described further in | |
1738 | the HOT-SPOT Operation section. | |
c07583cd KS |
1739 | |
1740 | Exposure Control: | |
1741 | ---------------- | |
1742 | \\[allout-hide-current-subtree] `allout-hide-current-subtree' | |
1743 | \\[allout-show-children] `allout-show-children' | |
1744 | \\[allout-show-current-subtree] `allout-show-current-subtree' | |
1745 | \\[allout-show-current-entry] `allout-show-current-entry' | |
1746 | \\[allout-show-all] `allout-show-all' | |
1747 | ||
1748 | Navigation: | |
1749 | ---------- | |
1750 | \\[allout-next-visible-heading] `allout-next-visible-heading' | |
1751 | \\[allout-previous-visible-heading] `allout-previous-visible-heading' | |
1752 | \\[allout-up-current-level] `allout-up-current-level' | |
1753 | \\[allout-forward-current-level] `allout-forward-current-level' | |
1754 | \\[allout-backward-current-level] `allout-backward-current-level' | |
1755 | \\[allout-end-of-entry] `allout-end-of-entry' | |
1756 | \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot) | |
60c7bbd2 | 1757 | \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but |
c07583cd KS |
1758 | if immediately repeated cycles to the beginning of the current item |
1759 | and then to the hot-spot (if `allout-beginning-of-line-cycles' is set). | |
1760 | ||
1761 | ||
1762 | Topic Header Production: | |
1763 | ----------------------- | |
1764 | \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic. | |
1765 | \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic. | |
1766 | \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent. | |
1767 | ||
1768 | Topic Level and Prefix Adjustment: | |
1769 | --------------------------------- | |
1770 | \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper | |
1771 | \\[allout-shift-out] `allout-shift-out' ... less deep | |
1772 | \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for | |
1773 | current topic | |
1774 | \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and | |
60c7bbd2 | 1775 | its' offspring -- distinctive bullets are not changed, others |
c07583cd | 1776 | are alternated according to nesting depth. |
ea18b2b1 | 1777 | \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -- |
c07583cd KS |
1778 | the offspring are not affected. |
1779 | With repeat count, revoke numbering. | |
1780 | ||
1781 | Topic-oriented Killing and Yanking: | |
1782 | ---------------------------------- | |
1783 | \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring. | |
1784 | \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring. | |
1785 | \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure. | |
1786 | \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it. | |
1787 | \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to | |
1788 | depth of heading if yanking into bare topic | |
1789 | heading (ie, prefix sans text). | |
1790 | \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank | |
1791 | ||
1792 | Topic-oriented Encryption: | |
1793 | ------------------------- | |
1794 | \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption' | |
1795 | Encrypt/Decrypt topic content | |
1796 | ||
1797 | Misc commands: | |
1798 | ------------- | |
1799 | M-x outlineify-sticky Activate outline mode for current buffer, | |
1800 | and establish a default file-var setting | |
1801 | for `allout-layout'. | |
1802 | \\[allout-mark-topic] `allout-mark-topic' | |
1803 | \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer' | |
1804 | Duplicate outline, sans concealed text, to | |
1805 | buffer with name derived from derived from that | |
60c7bbd2 | 1806 | of current buffer -- \"*BUFFERNAME exposed*\". |
c07583cd KS |
1807 | \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer' |
1808 | Like above 'copy-exposed', but convert topic | |
1809 | prefixes to section.subsection... numeric | |
1810 | format. | |
11c46e15 KM |
1811 | \\[customize-variable] allout-auto-activation |
1812 | Prepare Emacs session for allout outline mode | |
c07583cd | 1813 | auto-activation. |
1977b8f6 | 1814 | |
96b83743 | 1815 | Topic Encryption |
d82979ea | 1816 | |
96b83743 | 1817 | Outline mode supports gpg encryption of topics, with support for |
29fac3fe KM |
1818 | symmetric and key-pair modes, and auto-encryption of topics |
1819 | pending encryption on save. | |
d82979ea | 1820 | |
c07583cd | 1821 | Topics pending encryption are, by default, automatically |
29fac3fe KM |
1822 | encrypted during file saves, including checkpoint saves, to avoid |
1823 | exposing the plain text of encrypted topics in the file system. | |
1824 | If the content of the topic containing the cursor was encrypted | |
1825 | for a save, it is automatically decrypted for continued editing. | |
c07583cd | 1826 | |
2576c28f KM |
1827 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
1828 | symmetric decryption keys, preventing entry of the correct key on | |
1829 | subsequent decryption attempts until the cache times-out. That | |
1830 | can take several minutes. \(Decryption of other entries is not | |
1831 | affected.) Upgrade your EasyPG version, if you can, and you can | |
1832 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
1833 | signal. | |
c07583cd KS |
1834 | |
1835 | See `allout-toggle-current-subtree-encryption' function docstring | |
1836 | and `allout-encrypt-unencrypted-on-saves' customization variable | |
1837 | for details. | |
d82979ea | 1838 | |
c07583cd | 1839 | HOT-SPOT Operation |
c567ac01 | 1840 | |
19b84ba3 RS |
1841 | Hot-spot operation provides a means for easy, single-keystroke outline |
1842 | navigation and exposure control. | |
c567ac01 | 1843 | |
19b84ba3 RS |
1844 | When the text cursor is positioned directly on the bullet character of |
1845 | a topic, regular characters (a to z) invoke the commands of the | |
fd5359c6 | 1846 | corresponding allout-mode keymap control chars. For example, \"f\" |
96b83743 | 1847 | would invoke the command typically bound to \"C-c<space>C-f\" |
fd5359c6 | 1848 | \(\\[allout-forward-current-level] `allout-forward-current-level'). |
19b84ba3 | 1849 | |
96b83743 EZ |
1850 | Thus, by positioning the cursor on a topic bullet, you can |
1851 | execute the outline navigation and manipulation commands with a | |
c07583cd | 1852 | single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get |
96b83743 | 1853 | this special translation, so you can use them to get out of the |
c07583cd KS |
1854 | hot-spot and back to normal editing operation. |
1855 | ||
d41b91e6 | 1856 | In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is |
c07583cd KS |
1857 | replaced with one that makes it easy to get to the hot-spot. If you |
1858 | repeat it immediately it cycles (if `allout-beginning-of-line-cycles' | |
1859 | is set) to the beginning of the item and then, if you hit it again | |
1860 | immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry' | |
1861 | \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located | |
1862 | at the beginning of the current entry. | |
1863 | ||
1864 | Extending Allout | |
c567ac01 | 1865 | |
c07583cd KS |
1866 | Allout exposure and authoring activites all have associated |
1867 | hooks, by which independent code can cooperate with allout | |
1868 | without changes to the allout core. Here are key ones: | |
1977b8f6 | 1869 | |
c07583cd | 1870 | `allout-mode-hook' |
2576c28f KM |
1871 | `allout-mode-deactivate-hook' \(deprecated) |
1872 | `allout-mode-off-hook' | |
c07583cd KS |
1873 | `allout-exposure-change-hook' |
1874 | `allout-structure-added-hook' | |
1875 | `allout-structure-deleted-hook' | |
1876 | `allout-structure-shifted-hook' | |
4ec28e14 | 1877 | `allout-after-copy-or-kill-hook' |
c07583cd KS |
1878 | |
1879 | Terminology | |
1977b8f6 | 1880 | |
60c7bbd2 | 1881 | Topic hierarchy constituents -- TOPICS and SUBTOPICS: |
c567ac01 | 1882 | |
c07583cd KS |
1883 | ITEM: A unitary outline element, including the HEADER and ENTRY text. |
1884 | TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH | |
1885 | and with no intervening items of lower DEPTH than the container. | |
1886 | CURRENT ITEM: | |
1887 | The visible ITEM most immediately containing the cursor. | |
1888 | DEPTH: The degree of nesting of an ITEM; it increases with containment. | |
1889 | The DEPTH is determined by the HEADER PREFIX. The DEPTH is also | |
1890 | called the: | |
1891 | LEVEL: The same as DEPTH. | |
c567ac01 RS |
1892 | |
1893 | ANCESTORS: | |
c07583cd KS |
1894 | Those ITEMs whose TOPICs contain an ITEM. |
1895 | PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that | |
1896 | of the ITEM. | |
c567ac01 | 1897 | OFFSPRING: |
c07583cd | 1898 | The ITEMs contained within an ITEM's TOPIC. |
19b84ba3 | 1899 | SUBTOPIC: |
c07583cd KS |
1900 | An OFFSPRING of its ANCESTOR TOPICs. |
1901 | CHILD: | |
1902 | An immediate SUBTOPIC of its PARENT. | |
c567ac01 | 1903 | SIBLINGS: |
c07583cd | 1904 | TOPICs having the same PARENT and DEPTH. |
353e2ef2 | 1905 | |
c567ac01 RS |
1906 | Topic text constituents: |
1907 | ||
c07583cd KS |
1908 | HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER |
1909 | text. | |
1910 | ENTRY: The text content of an ITEM, before any OFFSPRING, but including | |
1911 | the HEADER text and distinct from the ITEM PREFIX. | |
1912 | BODY: Same as ENTRY. | |
1913 | PREFIX: The leading text of an ITEM which distinguishes it from normal | |
1914 | ENTRY text. Allout recognizes the outline structure according | |
1915 | to the strict PREFIX format. It consists of a PREFIX-LEAD string, | |
1916 | PREFIX-PADDING, and a BULLET. The BULLET might be followed by a | |
d82979ea | 1917 | number, indicating the ordinal number of the topic among its |
c07583cd KS |
1918 | siblings, or an asterisk indicating encryption, plus an optional |
1919 | space. After that is the ITEM HEADER text, which is not part of | |
1920 | the PREFIX. | |
c567ac01 | 1921 | |
c07583cd KS |
1922 | The relative length of the PREFIX determines the nesting DEPTH |
1923 | of the ITEM. | |
c567ac01 | 1924 | PREFIX-LEAD: |
c07583cd KS |
1925 | The string at the beginning of a HEADER PREFIX, by default a `.'. |
1926 | It can be customized by changing the setting of | |
1927 | `allout-header-prefix' and then reinitializing `allout-mode'. | |
1928 | ||
1929 | When the PREFIX-LEAD is set to the comment-string of a | |
1930 | programming language, outline structuring can be embedded in | |
1931 | program code without interfering with processing of the text | |
1932 | (by emacs or the language processor) as program code. This | |
1933 | setting happens automatically when allout mode is used in | |
1934 | programming-mode buffers. See `allout-use-mode-specific-leader' | |
1935 | docstring for more detail. | |
c567ac01 | 1936 | PREFIX-PADDING: |
c07583cd KS |
1937 | Spaces or asterisks which separate the PREFIX-LEAD and the |
1938 | bullet, determining the ITEM's DEPTH. | |
1939 | BULLET: A character at the end of the ITEM PREFIX, it must be one of | |
1940 | the characters listed on `allout-plain-bullets-string' or | |
38b2ca53 NR |
1941 | `allout-distinctive-bullets-string'. When creating a TOPIC, |
1942 | plain BULLETs are by default used, according to the DEPTH of the | |
1943 | TOPIC. Choice among the distinctive BULLETs is offered when you | |
1944 | provide a universal argugment \(\\[universal-argument]) to the | |
1945 | TOPIC creation command, or when explictly rebulleting a TOPIC. The | |
1946 | significance of the various distinctive bullets is purely by | |
1947 | convention. See the documentation for the above bullet strings for | |
1948 | more details. | |
c567ac01 | 1949 | EXPOSURE: |
c07583cd KS |
1950 | The state of a TOPIC which determines the on-screen visibility |
1951 | of its OFFSPRING and contained ENTRY text. | |
c567ac01 | 1952 | CONCEALED: |
c07583cd KS |
1953 | TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed |
1954 | text is represented by \"...\" ellipses. | |
c567ac01 | 1955 | |
c07583cd KS |
1956 | CONCEALED TOPICs are effectively collapsed within an ANCESTOR. |
1957 | CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED. | |
1958 | OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be." | |
c567ac01 | 1959 | ;;;_ . Code |
d3e51865 KM |
1960 | :lighter " Allout" |
1961 | :keymap 'allout-mode-map | |
1977b8f6 | 1962 | |
2576c28f KM |
1963 | (let ((write-file-hook-var-name (cond ((boundp 'write-file-functions) |
1964 | 'write-file-functions) | |
1965 | ((boundp 'write-file-hooks) | |
1966 | 'write-file-hooks) | |
1967 | (t 'local-write-file-hooks))) | |
1968 | (use-layout (if (listp allout-layout) | |
1969 | allout-layout | |
1970 | allout-default-layout))) | |
1977b8f6 | 1971 | |
d3e51865 | 1972 | (if (not (allout-mode-p)) |
2576c28f KM |
1973 | (progn |
1974 | ;; Deactivation: | |
1975 | ||
1976 | ; Activation not explicitly | |
1977 | ; requested, and either in | |
1978 | ; active state or *de*activation | |
1979 | ; specifically requested: | |
1980 | (allout-do-resumptions) | |
1981 | ||
1982 | (remove-from-invisibility-spec '(allout . t)) | |
1983 | (remove-hook 'pre-command-hook 'allout-pre-command-business t) | |
1984 | (remove-hook 'post-command-hook 'allout-post-command-business t) | |
1985 | (remove-hook 'before-change-functions 'allout-before-change-handler t) | |
1986 | (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) | |
d3e51865 KM |
1987 | (remove-hook write-file-hook-var-name |
1988 | 'allout-write-file-hook-handler t) | |
2576c28f KM |
1989 | (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t) |
1990 | ||
1991 | (remove-overlays (point-min) (point-max) | |
d3e51865 | 1992 | 'category 'allout-exposure-category)) |
2576c28f | 1993 | |
d3e51865 | 1994 | ;; Activating: |
fd5359c6 | 1995 | (if allout-old-style-prefixes |
01fc9422 | 1996 | ;; Inhibit all the fancy formatting: |
48bd8440 | 1997 | (allout-add-resumptions '(allout-primary-bullet "*"))) |
19b84ba3 | 1998 | |
01fc9422 | 1999 | (allout-overlay-preparations) ; Doesn't hurt to redo this. |
96b83743 | 2000 | |
d8350998 | 2001 | (allout-infer-header-lead-and-primary-bullet) |
fd5359c6 | 2002 | (allout-infer-body-reindent) |
19b84ba3 | 2003 | |
fd5359c6 | 2004 | (set-allout-regexp) |
2576c28f KM |
2005 | (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps |
2006 | allout-line-boundary-regexp | |
2007 | extend) | |
2008 | '(allout-encryption-ciphertext-rejection-regexps | |
2009 | allout-bob-regexp | |
2010 | extend)) | |
19b84ba3 | 2011 | |
d3e51865 | 2012 | (allout-compose-and-institute-keymap) |
01fc9422 | 2013 | (produce-allout-mode-menubar-entries) |
01fc9422 | 2014 | |
96b83743 | 2015 | (add-to-invisibility-spec '(allout . t)) |
38b2ca53 | 2016 | |
01fc9422 EZ |
2017 | (allout-add-resumptions '(line-move-ignore-invisible t)) |
2018 | (add-hook 'pre-command-hook 'allout-pre-command-business nil t) | |
2019 | (add-hook 'post-command-hook 'allout-post-command-business nil t) | |
2576c28f | 2020 | (add-hook 'before-change-functions 'allout-before-change-handler nil t) |
01fc9422 EZ |
2021 | (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) |
2022 | (add-hook write-file-hook-var-name 'allout-write-file-hook-handler | |
2023 | nil t) | |
2576c28f | 2024 | (add-hook 'auto-save-hook 'allout-auto-save-hook-handler nil t) |
01fc9422 EZ |
2025 | |
2026 | ;; Stash auto-fill settings and adjust so custom allout auto-fill | |
2027 | ;; func will be used if auto-fill is active or activated. (The | |
2028 | ;; custom func respects topic headline, maintains hanging-indents, | |
2029 | ;; etc.) | |
01fc9422 EZ |
2030 | (allout-add-resumptions (list 'allout-former-auto-filler |
2031 | auto-fill-function) | |
2032 | ;; Register allout-auto-fill to be used if | |
2033 | ;; filling is active: | |
2034 | (list 'allout-outside-normal-auto-fill-function | |
2035 | normal-auto-fill-function) | |
2036 | '(normal-auto-fill-function allout-auto-fill) | |
2037 | ;; Paragraphs are broken by topic headlines. | |
2038 | (list 'paragraph-start | |
2039 | (concat paragraph-start "\\|^\\(" | |
2040 | allout-regexp "\\)")) | |
2041 | (list 'paragraph-separate | |
2042 | (concat paragraph-separate "\\|^\\(" | |
2043 | allout-regexp "\\)"))) | |
2576c28f KM |
2044 | (if (and auto-fill-function (not allout-inhibit-auto-fill)) |
2045 | ;; allout-auto-fill will use the stashed values and so forth. | |
2046 | (allout-add-resumptions '(auto-fill-function allout-auto-fill))) | |
2047 | ||
fd5359c6 | 2048 | (allout-setup-menubar) |
2576c28f KM |
2049 | |
2050 | ;; Do auto layout if warranted: | |
2051 | (when (and allout-layout | |
2052 | allout-auto-activation | |
2053 | use-layout | |
11c46e15 KM |
2054 | (and (not (string= allout-auto-activation "activate")) |
2055 | (if (string= allout-auto-activation "ask") | |
2576c28f KM |
2056 | (if (y-or-n-p (format "Expose %s with layout '%s'? " |
2057 | (buffer-name) | |
2058 | use-layout)) | |
2059 | t | |
2060 | (message "Skipped %s layout." (buffer-name)) | |
2061 | nil) | |
2062 | t))) | |
2063 | (save-excursion | |
2064 | (message "Adjusting '%s' exposure..." (buffer-name)) | |
2065 | (goto-char 0) | |
2066 | (allout-this-or-next-heading) | |
2067 | (condition-case err | |
2068 | (progn | |
2069 | (apply 'allout-expose-topic (list use-layout)) | |
2070 | (message "Adjusting '%s' exposure... done." | |
2071 | (buffer-name))) | |
2072 | ;; Problem applying exposure -- notify user, but don't | |
2073 | ;; interrupt, eg, file visit: | |
2074 | (error (message "%s" (car (cdr err))) | |
2075 | (sit-for 1)))) | |
2076 | ) ; when allout-layout | |
2077 | ) ; if (allout-mode-p) | |
2078 | ) ; let (()) | |
2079 | ) ; define-minor-mode | |
2080 | ;;;_ > allout-minor-mode alias | |
2081 | (defalias 'allout-minor-mode 'allout-mode) | |
41ff6d0a JB |
2082 | ;;;_ > allout-unload-function |
2083 | (defun allout-unload-function () | |
2084 | "Unload the allout outline library." | |
2085 | (save-current-buffer | |
2086 | (dolist (buffer (buffer-list)) | |
2087 | (set-buffer buffer) | |
74f53697 | 2088 | (when (allout-mode-p) (allout-mode -1)))) |
41ff6d0a JB |
2089 | ;; continue standard unloading |
2090 | nil) | |
2091 | ||
773e7e48 EZ |
2092 | ;;;_ - Position Assessment |
2093 | ;;;_ > allout-hidden-p (&optional pos) | |
2094 | (defsubst allout-hidden-p (&optional pos) | |
1c9b9df0 | 2095 | "Non-nil if the character after point was made invisible by allout." |
da506f05 | 2096 | (eq (get-char-property (or pos (point)) 'invisible) 'allout)) |
773e7e48 | 2097 | |
96b83743 EZ |
2098 | ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end |
2099 | ;;; &optional prelen) | |
2100 | (defun allout-overlay-insert-in-front-handler (ol after beg end | |
2101 | &optional prelen) | |
2a1408fd | 2102 | "Shift the overlay so stuff inserted in front of it is excluded." |
96b83743 | 2103 | (if after |
1c9b9df0 KM |
2104 | ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay |
2105 | ;; front-advance on the overlay worked as expected? | |
96b83743 EZ |
2106 | (move-overlay ol (1+ beg) (overlay-end ol)))) |
2107 | ;;;_ > allout-overlay-interior-modification-handler (ol after beg end | |
2108 | ;;; &optional prelen) | |
2109 | (defun allout-overlay-interior-modification-handler (ol after beg end | |
2110 | &optional prelen) | |
2111 | "Get confirmation before making arbitrary changes to invisible text. | |
2112 | ||
2113 | We expose the invisible text and ask for confirmation. Refusal or | |
75bcb912 | 2114 | `keyboard-quit' abandons the changes, with keyboard-quit additionally |
96b83743 EZ |
2115 | reclosing the opened text. |
2116 | ||
60c7bbd2 | 2117 | No confirmation is necessary when `inhibit-read-only' is set -- eg, allout |
96b83743 EZ |
2118 | internal functions use this feature cohesively bunch changes." |
2119 | ||
2120 | (when (and (not inhibit-read-only) (not after)) | |
2121 | (let ((start (point)) | |
2122 | (ol-start (overlay-start ol)) | |
2123 | (ol-end (overlay-end ol)) | |
96b83743 EZ |
2124 | first) |
2125 | (goto-char beg) | |
2126 | (while (< (point) end) | |
2127 | (when (allout-hidden-p) | |
2128 | (allout-show-to-offshoot) | |
2129 | (if (allout-hidden-p) | |
2130 | (save-excursion (forward-char 1) | |
2131 | (allout-show-to-offshoot))) | |
2132 | (when (not first) | |
96b83743 EZ |
2133 | (setq first (point)))) |
2134 | (goto-char (if (featurep 'xemacs) | |
2135 | (next-property-change (1+ (point)) nil end) | |
2136 | (next-char-property-change (1+ (point)) end)))) | |
2137 | (when first | |
2138 | (goto-char first) | |
2139 | (condition-case nil | |
2140 | (if (not | |
2141 | (yes-or-no-p | |
2142 | (substitute-command-keys | |
4034b0e2 | 2143 | (concat "Modify concealed text? (\"no\" just aborts," |
96b83743 EZ |
2144 | " \\[keyboard-quit] also reconceals) ")))) |
2145 | (progn (goto-char start) | |
5a0c3f56 | 2146 | (error "Concealed-text change refused"))) |
96b83743 EZ |
2147 | (quit (allout-flag-region ol-start ol-end nil) |
2148 | (allout-flag-region ol-start ol-end t) | |
5a0c3f56 | 2149 | (error "Concealed-text change abandoned, text reconcealed")))) |
96b83743 EZ |
2150 | (goto-char start)))) |
2151 | ;;;_ > allout-before-change-handler (beg end) | |
2152 | (defun allout-before-change-handler (beg end) | |
2153 | "Protect against changes to invisible text. | |
2154 | ||
60c7bbd2 | 2155 | See `allout-overlay-interior-modification-handler' for details." |
d8350998 | 2156 | |
4936e3ba KM |
2157 | (when (and (allout-mode-p) undo-in-progress (allout-hidden-p)) |
2158 | (allout-show-children)) | |
d8350998 | 2159 | |
01fc9422 EZ |
2160 | ;; allout-overlay-interior-modification-handler on an overlay handles |
2161 | ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. | |
2162 | (when (and (featurep 'xemacs) (allout-mode-p)) | |
2163 | ;; process all of the pending overlays: | |
d8350998 | 2164 | (save-excursion |
f520c6f2 | 2165 | (goto-char beg) |
d8350998 | 2166 | (let ((overlay (allout-get-invisibility-overlay))) |
1c9b9df0 KM |
2167 | (if overlay |
2168 | (allout-overlay-interior-modification-handler | |
2169 | overlay nil beg end nil)))))) | |
96b83743 EZ |
2170 | ;;;_ > allout-isearch-end-handler (&optional overlay) |
2171 | (defun allout-isearch-end-handler (&optional overlay) | |
2172 | "Reconcile allout outline exposure on arriving in hidden text after isearch. | |
2173 | ||
2174 | Optional OVERLAY parameter is for when this function is used by | |
2175 | `isearch-open-invisible' overlay property. It is otherwise unused, so this | |
2176 | function can also be used as an `isearch-mode-end-hook'." | |
2177 | ||
2178 | (if (and (allout-mode-p) (allout-hidden-p)) | |
2179 | (allout-show-to-offshoot))) | |
2180 | ||
60c7bbd2 | 2181 | ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs |
a5a1e2ef SM |
2182 | ;; All the basic outline functions that directly do string matches to |
2183 | ;; evaluate heading prefix location set the variables | |
2184 | ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' | |
2185 | ;; when successful. Functions starting with `allout-recent-' all | |
2186 | ;; use this state, providing the means to avoid redundant searches | |
2187 | ;; for just-established data. This optimization can provide | |
2188 | ;; significant speed improvement, but it must be employed carefully. | |
fd5359c6 MR |
2189 | ;;;_ = allout-recent-prefix-beginning |
2190 | (defvar allout-recent-prefix-beginning 0 | |
c567ac01 | 2191 | "Buffer point of the start of the last topic prefix encountered.") |
fd5359c6 MR |
2192 | (make-variable-buffer-local 'allout-recent-prefix-beginning) |
2193 | ;;;_ = allout-recent-prefix-end | |
2194 | (defvar allout-recent-prefix-end 0 | |
c567ac01 | 2195 | "Buffer point of the end of the last topic prefix encountered.") |
fd5359c6 | 2196 | (make-variable-buffer-local 'allout-recent-prefix-end) |
d8350998 CY |
2197 | ;;;_ = allout-recent-depth |
2198 | (defvar allout-recent-depth 0 | |
2199 | "Depth of the last topic prefix encountered.") | |
2200 | (make-variable-buffer-local 'allout-recent-depth) | |
fd5359c6 MR |
2201 | ;;;_ = allout-recent-end-of-subtree |
2202 | (defvar allout-recent-end-of-subtree 0 | |
2265e017 | 2203 | "Buffer point last returned by `allout-end-of-current-subtree'.") |
fd5359c6 | 2204 | (make-variable-buffer-local 'allout-recent-end-of-subtree) |
d8350998 CY |
2205 | ;;;_ > allout-prefix-data () |
2206 | (defsubst allout-prefix-data () | |
2207 | "Register allout-prefix state data. | |
fd5359c6 | 2208 | |
75bcb912 JB |
2209 | For reference by `allout-recent' funcs. Return |
2210 | the new value of `allout-recent-prefix-beginning'." | |
42c3e51c | 2211 | (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3)) |
d8350998 | 2212 | allout-recent-prefix-beginning (or (match-beginning 1) |
42c3e51c KM |
2213 | (match-beginning 2) |
2214 | (match-beginning 3)) | |
d8350998 CY |
2215 | allout-recent-depth (max 1 (- allout-recent-prefix-end |
2216 | allout-recent-prefix-beginning | |
2217 | allout-header-subtraction))) | |
2218 | allout-recent-prefix-beginning) | |
2219 | ;;;_ > nullify-allout-prefix-data () | |
2220 | (defsubst nullify-allout-prefix-data () | |
2221 | "Mark allout prefix data as being uninformative." | |
2222 | (setq allout-recent-prefix-end (point) | |
2223 | allout-recent-prefix-beginning (point) | |
2224 | allout-recent-depth 0) | |
2225 | allout-recent-prefix-beginning) | |
fd5359c6 | 2226 | ;;;_ > allout-recent-depth () |
d8350998 | 2227 | (defsubst allout-recent-depth () |
19b84ba3 | 2228 | "Return depth of last heading encountered by an outline maneuvering function. |
c567ac01 RS |
2229 | |
2230 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2231 | headings set the variables `allout-recent-prefix-beginning' and |
2232 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 RS |
2233 | to return the current depth." |
2234 | ||
d8350998 | 2235 | allout-recent-depth) |
fd5359c6 | 2236 | ;;;_ > allout-recent-prefix () |
d8350998 | 2237 | (defsubst allout-recent-prefix () |
2265e017 | 2238 | "Like `allout-recent-depth', but returns text of last encountered prefix. |
c567ac01 RS |
2239 | |
2240 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2241 | headings set the variables `allout-recent-prefix-beginning' and |
2242 | `allout-recent-prefix-end' if successful. This function uses those settings | |
d8350998 CY |
2243 | to return the current prefix." |
2244 | (buffer-substring-no-properties allout-recent-prefix-beginning | |
2245 | allout-recent-prefix-end)) | |
fd5359c6 MR |
2246 | ;;;_ > allout-recent-bullet () |
2247 | (defmacro allout-recent-bullet () | |
2248 | "Like allout-recent-prefix, but returns bullet of last encountered prefix. | |
c567ac01 RS |
2249 | |
2250 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2251 | headings set the variables `allout-recent-prefix-beginning' and |
2252 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 2253 | to return the current depth of the most recently matched topic." |
d8350998 CY |
2254 | '(buffer-substring-no-properties (1- allout-recent-prefix-end) |
2255 | allout-recent-prefix-end)) | |
c567ac01 | 2256 | |
19b84ba3 | 2257 | ;;;_ #4 Navigation |
c567ac01 | 2258 | |
46771bb3 | 2259 | ;;;_ - Position Assessment |
c567ac01 | 2260 | ;;;_ : Location Predicates |
ede4ac6a KS |
2261 | ;;;_ > allout-do-doublecheck () |
2262 | (defsubst allout-do-doublecheck () | |
2263 | "True if current item conditions qualify for checking on topic aberrance." | |
2264 | (and | |
60c7bbd2 | 2265 | ;; presume integrity of outline and yanked content during yank -- necessary |
ede4ac6a | 2266 | ;; to allow for level disparity of yank location and yanked text: |
498a6493 | 2267 | (not allout-inhibit-aberrance-doublecheck) |
ede4ac6a KS |
2268 | ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck: |
2269 | (<= allout-recent-depth allout-doublecheck-at-and-shallower))) | |
2270 | ;;;_ > allout-aberrant-container-p () | |
d8350998 CY |
2271 | (defun allout-aberrant-container-p () |
2272 | "True if topic, or next sibling with children, contains them discontinuously. | |
2273 | ||
2274 | Discontinuous means an immediate offspring that is nested more | |
2275 | than one level deeper than the topic. | |
2276 | ||
2277 | If topic has no offspring, then the next sibling with offspring will | |
2278 | determine whether or not this one is determined to be aberrant. | |
2279 | ||
2280 | If true, then the allout-recent-* settings are calibrated on the | |
2281 | offspring that qaulifies it as aberrant, ie with depth that | |
2282 | exceeds the topic by more than one." | |
2283 | ||
2284 | ;; This is most clearly understood when considering standard-prefix-leader | |
2285 | ;; low-level topics, which can all too easily match text not intended as | |
2286 | ;; headers. For example, any line with a leading '.' or '*' and lacking a | |
2287 | ;; following bullet qualifies without this protection. (A sequence of | |
2288 | ;; them can occur naturally, eg a typical textual bullet list.) We | |
2289 | ;; disqualify such low-level sequences when they are followed by a | |
2290 | ;; discontinuously contained child, inferring that the sequences are not | |
2291 | ;; actually connected with their prospective context. | |
2292 | ||
2293 | (let ((depth (allout-depth)) | |
2294 | (start-point (point)) | |
2295 | done aberrant) | |
2a1408fd DN |
2296 | (save-match-data |
2297 | (save-excursion | |
2298 | (while (and (not done) | |
2299 | (re-search-forward allout-line-boundary-regexp nil 0)) | |
2300 | (allout-prefix-data) | |
2301 | (goto-char allout-recent-prefix-beginning) | |
2302 | (cond | |
8dd59f01 | 2303 | ;; sibling -- continue: |
2a1408fd | 2304 | ((eq allout-recent-depth depth)) |
8dd59f01 | 2305 | ;; first offspring is excessive -- aberrant: |
2a1408fd DN |
2306 | ((> allout-recent-depth (1+ depth)) |
2307 | (setq done t aberrant t)) | |
8dd59f01 | 2308 | ;; next non-sibling is lower-depth -- not aberrant: |
2a1408fd | 2309 | (t (setq done t)))))) |
d8350998 CY |
2310 | (if aberrant |
2311 | aberrant | |
2312 | (goto-char start-point) | |
2313 | ;; recalibrate allout-recent-* | |
2314 | (allout-depth) | |
2315 | nil))) | |
ede4ac6a KS |
2316 | ;;;_ > allout-on-current-heading-p () |
2317 | (defun allout-on-current-heading-p () | |
2318 | "Return non-nil if point is on current visible topics' header line. | |
2319 | ||
2320 | Actually, returns prefix beginning point." | |
2321 | (save-excursion | |
2322 | (allout-beginning-of-current-line) | |
2a1408fd DN |
2323 | (save-match-data |
2324 | (and (looking-at allout-regexp) | |
2325 | (allout-prefix-data) | |
2326 | (or (not (allout-do-doublecheck)) | |
2327 | (not (allout-aberrant-container-p))))))) | |
ede4ac6a KS |
2328 | ;;;_ > allout-on-heading-p () |
2329 | (defalias 'allout-on-heading-p 'allout-on-current-heading-p) | |
2330 | ;;;_ > allout-e-o-prefix-p () | |
2331 | (defun allout-e-o-prefix-p () | |
2332 | "True if point is located where current topic prefix ends, heading begins." | |
2a1408fd DN |
2333 | (and (save-match-data |
2334 | (save-excursion (let ((inhibit-field-text-motion t)) | |
2335 | (beginning-of-line)) | |
2336 | (looking-at allout-regexp)) | |
2337 | (= (point) (save-excursion (allout-end-of-prefix)(point)))))) | |
c567ac01 | 2338 | ;;;_ : Location attributes |
fd5359c6 | 2339 | ;;;_ > allout-depth () |
96b83743 EZ |
2340 | (defun allout-depth () |
2341 | "Return depth of topic most immediately containing point. | |
2342 | ||
42c3e51c KM |
2343 | Does not do doublecheck for aberrant topic header. |
2344 | ||
96b83743 EZ |
2345 | Return zero if point is not within any topic. |
2346 | ||
2347 | Like `allout-current-depth', but respects hidden as well as visible topics." | |
9179616f | 2348 | (save-excursion |
96b83743 EZ |
2349 | (let ((start-point (point))) |
2350 | (if (and (allout-goto-prefix) | |
2351 | (not (< start-point (point)))) | |
d8350998 | 2352 | allout-recent-depth |
96b83743 | 2353 | (progn |
d8350998 CY |
2354 | ;; Oops, no prefix, nullify it: |
2355 | (nullify-allout-prefix-data) | |
96b83743 EZ |
2356 | ;; ... and return 0: |
2357 | 0))))) | |
fd5359c6 | 2358 | ;;;_ > allout-current-depth () |
96b83743 EZ |
2359 | (defun allout-current-depth () |
2360 | "Return depth of visible topic most immediately containing point. | |
2361 | ||
2362 | Return zero if point is not within any topic." | |
2363 | (save-excursion | |
2364 | (if (allout-back-to-current-heading) | |
2365 | (max 1 | |
2366 | (- allout-recent-prefix-end | |
2367 | allout-recent-prefix-beginning | |
2368 | allout-header-subtraction)) | |
2369 | 0))) | |
fd5359c6 MR |
2370 | ;;;_ > allout-get-current-prefix () |
2371 | (defun allout-get-current-prefix () | |
c567ac01 | 2372 | "Topic prefix of the current topic." |
1977b8f6 | 2373 | (save-excursion |
fd5359c6 MR |
2374 | (if (allout-goto-prefix) |
2375 | (allout-recent-prefix)))) | |
2376 | ;;;_ > allout-get-bullet () | |
2377 | (defun allout-get-bullet () | |
c567ac01 | 2378 | "Return bullet of containing topic (visible or not)." |
1977b8f6 | 2379 | (save-excursion |
fd5359c6 MR |
2380 | (and (allout-goto-prefix) |
2381 | (allout-recent-bullet)))) | |
2382 | ;;;_ > allout-current-bullet () | |
2383 | (defun allout-current-bullet () | |
c567ac01 | 2384 | "Return bullet of current (visible) topic heading, or none if none found." |
96b83743 | 2385 | (condition-case nil |
1977b8f6 | 2386 | (save-excursion |
fd5359c6 | 2387 | (allout-back-to-current-heading) |
d8350998 CY |
2388 | (buffer-substring-no-properties (- allout-recent-prefix-end 1) |
2389 | allout-recent-prefix-end)) | |
1977b8f6 | 2390 | ;; Quick and dirty provision, ostensibly for missing bullet: |
d8350998 | 2391 | (args-out-of-range nil)) |
1977b8f6 | 2392 | ) |
fd5359c6 MR |
2393 | ;;;_ > allout-get-prefix-bullet (prefix) |
2394 | (defun allout-get-prefix-bullet (prefix) | |
c567ac01 | 2395 | "Return the bullet of the header prefix string PREFIX." |
1977b8f6 RS |
2396 | ;; Doesn't make sense if we're old-style prefixes, but this just |
2397 | ;; oughtn't be called then, so forget about it... | |
fd5359c6 | 2398 | (if (string-match allout-regexp prefix) |
d8350998 | 2399 | (substring prefix (1- (match-end 2)) (match-end 2)))) |
fd5359c6 MR |
2400 | ;;;_ > allout-sibling-index (&optional depth) |
2401 | (defun allout-sibling-index (&optional depth) | |
9179616f DL |
2402 | "Item number of this prospective topic among its siblings. |
2403 | ||
e126900f | 2404 | If optional arg DEPTH is greater than current depth, then we're |
9179616f DL |
2405 | opening a new level, and return 0. |
2406 | ||
2407 | If less than this depth, ascend to that depth and count..." | |
2408 | ||
2409 | (save-excursion | |
2410 | (cond ((and depth (<= depth 0) 0)) | |
65e7eb3d | 2411 | ((or (null depth) (= depth (allout-depth))) |
9179616f | 2412 | (let ((index 1)) |
d8350998 | 2413 | (while (allout-previous-sibling allout-recent-depth nil) |
9179616f DL |
2414 | (setq index (1+ index))) |
2415 | index)) | |
d8350998 | 2416 | ((< depth allout-recent-depth) |
fd5359c6 MR |
2417 | (allout-ascend-to-depth depth) |
2418 | (allout-sibling-index)) | |
9179616f | 2419 | (0)))) |
fd5359c6 MR |
2420 | ;;;_ > allout-topic-flat-index () |
2421 | (defun allout-topic-flat-index () | |
9179616f DL |
2422 | "Return a list indicating point's numeric section.subsect.subsubsect... |
2423 | Outermost is first." | |
fd5359c6 MR |
2424 | (let* ((depth (allout-depth)) |
2425 | (next-index (allout-sibling-index depth)) | |
9179616f DL |
2426 | (rev-sibls nil)) |
2427 | (while (> next-index 0) | |
2428 | (setq rev-sibls (cons next-index rev-sibls)) | |
2429 | (setq depth (1- depth)) | |
fd5359c6 | 2430 | (setq next-index (allout-sibling-index depth))) |
9179616f DL |
2431 | rev-sibls) |
2432 | ) | |
1977b8f6 | 2433 | |
96b83743 EZ |
2434 | ;;;_ - Navigation routines |
2435 | ;;;_ > allout-beginning-of-current-line () | |
2436 | (defun allout-beginning-of-current-line () | |
2437 | "Like beginning of line, but to visible text." | |
2438 | ||
5204800f NR |
2439 | ;; This combination of move-beginning-of-line and beginning-of-line is |
2440 | ;; deliberate, but the (beginning-of-line) may now be superfluous. | |
0458fa80 EZ |
2441 | (let ((inhibit-field-text-motion t)) |
2442 | (move-beginning-of-line 1) | |
96b83743 | 2443 | (beginning-of-line) |
0458fa80 EZ |
2444 | (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p))) |
2445 | (beginning-of-line) | |
2446 | (if (or (allout-hidden-p) (not (bolp))) | |
2447 | (forward-char -1))))) | |
96b83743 EZ |
2448 | ;;;_ > allout-end-of-current-line () |
2449 | (defun allout-end-of-current-line () | |
2450 | "Move to the end of line, past concealed text if any." | |
1c9b9df0 | 2451 | ;; This is for symmetry with `allout-beginning-of-current-line' -- |
96b83743 EZ |
2452 | ;; `move-end-of-line' doesn't suffer the same problem as |
2453 | ;; `move-beginning-of-line'. | |
0458fa80 | 2454 | (let ((inhibit-field-text-motion t)) |
96b83743 | 2455 | (end-of-line) |
0458fa80 EZ |
2456 | (while (allout-hidden-p) |
2457 | (end-of-line) | |
2458 | (if (allout-hidden-p) (forward-char 1))))) | |
48bd8440 EZ |
2459 | ;;;_ > allout-beginning-of-line () |
2460 | (defun allout-beginning-of-line () | |
2461 | "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set." | |
2462 | ||
2463 | (interactive) | |
2464 | ||
2465 | (if (or (not allout-beginning-of-line-cycles) | |
2466 | (not (equal last-command this-command))) | |
2a1408fd DN |
2467 | (progn |
2468 | (if (and (not (bolp)) | |
2469 | (allout-hidden-p (1- (point)))) | |
1c9b9df0 | 2470 | (goto-char (allout-previous-single-char-property-change |
2a1408fd DN |
2471 | (1- (point)) 'invisible))) |
2472 | (move-beginning-of-line 1)) | |
d8350998 CY |
2473 | (allout-depth) |
2474 | (let ((beginning-of-body | |
2475 | (save-excursion | |
ede4ac6a | 2476 | (while (and (allout-do-doublecheck) |
d8350998 CY |
2477 | (allout-aberrant-container-p) |
2478 | (allout-previous-visible-heading 1))) | |
2479 | (allout-beginning-of-current-entry) | |
2480 | (point)))) | |
48bd8440 | 2481 | (cond ((= (current-column) 0) |
d8350998 | 2482 | (goto-char beginning-of-body)) |
48bd8440 EZ |
2483 | ((< (point) beginning-of-body) |
2484 | (allout-beginning-of-current-line)) | |
2485 | ((= (point) beginning-of-body) | |
2486 | (goto-char (allout-current-bullet-pos))) | |
2487 | (t (allout-beginning-of-current-line) | |
2488 | (if (< (point) beginning-of-body) | |
2489 | ;; we were on the headline after its start: | |
d8350998 | 2490 | (goto-char beginning-of-body))))))) |
48bd8440 EZ |
2491 | ;;;_ > allout-end-of-line () |
2492 | (defun allout-end-of-line () | |
2493 | "End-of-line with `allout-end-of-line-cycles' behavior, if set." | |
2494 | ||
2495 | (interactive) | |
2496 | ||
2497 | (if (or (not allout-end-of-line-cycles) | |
2498 | (not (equal last-command this-command))) | |
2499 | (allout-end-of-current-line) | |
2500 | (let ((end-of-entry (save-excursion | |
2501 | (allout-end-of-entry) | |
2502 | (point)))) | |
2503 | (cond ((not (eolp)) | |
2504 | (allout-end-of-current-line)) | |
2505 | ((or (allout-hidden-p) (save-excursion | |
2506 | (forward-char -1) | |
2507 | (allout-hidden-p))) | |
2508 | (allout-back-to-current-heading) | |
2509 | (allout-show-current-entry) | |
d8350998 | 2510 | (allout-show-children) |
48bd8440 EZ |
2511 | (allout-end-of-entry)) |
2512 | ((>= (point) end-of-entry) | |
2513 | (allout-back-to-current-heading) | |
2514 | (allout-end-of-current-line)) | |
2a1408fd | 2515 | (t |
1c9b9df0 | 2516 | (if (not (allout-mark-active-p)) |
2a1408fd DN |
2517 | (push-mark)) |
2518 | (allout-end-of-entry)))))) | |
1c9b9df0 KM |
2519 | ;;;_ > allout-mark-active-p () |
2520 | (defun allout-mark-active-p () | |
2521 | "True if the mark is currently or always active." | |
2522 | ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler | |
2523 | ;; provisions, at least in fsf emacs to prevent warnings about lack of, | |
2524 | ;; eg, region-active-p. | |
2525 | (cond ((boundp 'mark-active) | |
2526 | mark-active) | |
2527 | ((fboundp 'region-active-p) | |
2528 | (region-active-p)) | |
2529 | (t))) | |
fd5359c6 MR |
2530 | ;;;_ > allout-next-heading () |
2531 | (defsubst allout-next-heading () | |
c07583cd | 2532 | "Move to the heading for the topic (possibly invisible) after this one. |
c567ac01 | 2533 | |
d8350998 | 2534 | Returns the location of the heading, or nil if none found. |
c567ac01 | 2535 | |
75bcb912 | 2536 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
2a1408fd DN |
2537 | (save-match-data |
2538 | ||
2539 | (if (looking-at allout-regexp) | |
2540 | (forward-char 1)) | |
2541 | ||
2542 | (when (re-search-forward allout-line-boundary-regexp nil 0) | |
2543 | (allout-prefix-data) | |
42c3e51c KM |
2544 | (goto-char allout-recent-prefix-beginning) |
2545 | (while (not (bolp)) | |
2546 | (forward-char -1)) | |
2a1408fd DN |
2547 | (and (allout-do-doublecheck) |
2548 | ;; this will set allout-recent-* on the first non-aberrant topic, | |
2549 | ;; whether it's the current one or one that disqualifies it: | |
2550 | (allout-aberrant-container-p)) | |
42c3e51c | 2551 | ;; this may or may not be the same as above depending on doublecheck: |
2a1408fd | 2552 | (goto-char allout-recent-prefix-beginning)))) |
96b83743 | 2553 | ;;;_ > allout-this-or-next-heading |
fd5359c6 | 2554 | (defun allout-this-or-next-heading () |
8d118843 | 2555 | "Position cursor on current or next heading." |
fd5359c6 MR |
2556 | ;; A throwaway non-macro that is defined after allout-next-heading |
2557 | ;; and usable by allout-mode. | |
d8350998 | 2558 | (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading))) |
fd5359c6 | 2559 | ;;;_ > allout-previous-heading () |
8a559d4e | 2560 | (defun allout-previous-heading () |
c07583cd | 2561 | "Move to the prior (possibly invisible) heading line. |
c567ac01 | 2562 | |
d8350998 CY |
2563 | Return the location of the beginning of the heading, or nil if not found. |
2564 | ||
75bcb912 | 2565 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
d8350998 CY |
2566 | |
2567 | (if (bobp) | |
2568 | nil | |
d8350998 | 2569 | (let ((start-point (point))) |
ede4ac6a | 2570 | ;; allout-goto-prefix-doublechecked calls us, so we can't use it here. |
d8350998 | 2571 | (allout-goto-prefix) |
2a1408fd DN |
2572 | (save-match-data |
2573 | (when (or (re-search-backward allout-line-boundary-regexp nil 0) | |
2574 | (looking-at allout-bob-regexp)) | |
2575 | (goto-char (allout-prefix-data)) | |
2576 | (if (and (allout-do-doublecheck) | |
2577 | (allout-aberrant-container-p)) | |
2578 | (or (allout-previous-heading) | |
2579 | (and (goto-char start-point) | |
2580 | ;; recalibrate allout-recent-*: | |
2581 | (allout-depth) | |
2582 | nil)) | |
2583 | (point))))))) | |
96b83743 EZ |
2584 | ;;;_ > allout-get-invisibility-overlay () |
2585 | (defun allout-get-invisibility-overlay () | |
2586 | "Return the overlay at point that dictates allout invisibility." | |
2587 | (let ((overlays (overlays-at (point))) | |
2588 | got) | |
2589 | (while (and overlays (not got)) | |
2590 | (if (equal (overlay-get (car overlays) 'invisible) 'allout) | |
d8350998 CY |
2591 | (setq got (car overlays)) |
2592 | (pop overlays))) | |
96b83743 EZ |
2593 | got)) |
2594 | ;;;_ > allout-back-to-visible-text () | |
2595 | (defun allout-back-to-visible-text () | |
2596 | "Move to most recent prior character that is visible, and return point." | |
2597 | (if (allout-hidden-p) | |
2598 | (goto-char (overlay-start (allout-get-invisibility-overlay)))) | |
2599 | (point)) | |
c567ac01 RS |
2600 | |
2601 | ;;;_ - Subtree Charting | |
2602 | ;;;_ " These routines either produce or assess charts, which are | |
2603 | ;;; nested lists of the locations of topics within a subtree. | |
2604 | ;;; | |
d8350998 CY |
2605 | ;;; Charts enable efficient subtree navigation by providing a reusable basis |
2606 | ;;; for elaborate, compound assessment and adjustment of a subtree. | |
c567ac01 | 2607 | |
48bd8440 EZ |
2608 | ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth) |
2609 | (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth) | |
19b84ba3 RS |
2610 | "Produce a location \"chart\" of subtopics of the containing topic. |
2611 | ||
c07583cd | 2612 | Optional argument LEVELS specifies a depth limit (relative to start |
65e7eb3d | 2613 | depth) for the chart. Null LEVELS means no limit. |
48bd8440 EZ |
2614 | |
2615 | When optional argument VISIBLE is non-nil, the chart includes | |
2616 | only the visible subelements of the charted subjects. | |
2617 | ||
65e7eb3d | 2618 | The remaining optional args are for internal use by the function. |
d82979ea EZ |
2619 | |
2620 | Point is left at the end of the subtree. | |
19b84ba3 | 2621 | |
d82979ea | 2622 | Charts are used to capture outline structure, so that outline-altering |
19b84ba3 RS |
2623 | routines need assess the structure only once, and then use the chart |
2624 | for their elaborate manipulations. | |
2625 | ||
d8350998 CY |
2626 | The chart entries for the topics are in reverse order, so the |
2627 | last topic is listed first. The entry for each topic consists of | |
2628 | an integer indicating the point at the beginning of the topic | |
2629 | prefix. Charts for offspring consists of a list containing, | |
2630 | recursively, the charts for the respective subtopics. The chart | |
2631 | for a topics' offspring precedes the entry for the topic itself. | |
19b84ba3 | 2632 | |
d82979ea EZ |
2633 | The other function parameters are for internal recursion, and should |
2634 | not be specified by external callers. ORIG-DEPTH is depth of topic at | |
2635 | starting point, and PREV-DEPTH is depth of prior topic." | |
19b84ba3 | 2636 | |
353e2ef2 | 2637 | (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. |
19b84ba3 RS |
2638 | chart curr-depth) |
2639 | ||
2640 | (if original ; Just starting? | |
2641 | ; Register initial settings and | |
2642 | ; position to first offspring: | |
fd5359c6 | 2643 | (progn (setq orig-depth (allout-depth)) |
19b84ba3 | 2644 | (or prev-depth (setq prev-depth (1+ orig-depth))) |
48bd8440 EZ |
2645 | (if visible |
2646 | (allout-next-visible-heading 1) | |
2647 | (allout-next-heading)))) | |
c567ac01 | 2648 | |
19b84ba3 RS |
2649 | ;; Loop over the current levels' siblings. Besides being more |
2650 | ;; efficient than tail-recursing over a level, it avoids exceeding | |
e126900f | 2651 | ;; the typically quite constrained Emacs max-lisp-eval-depth. |
9179616f | 2652 | ;; |
19b84ba3 RS |
2653 | ;; Probably would speed things up to implement loop-based stack |
2654 | ;; operation rather than recursing for lower levels. Bah. | |
9179616f | 2655 | |
c567ac01 | 2656 | (while (and (not (eobp)) |
19b84ba3 | 2657 | ; Still within original topic? |
d8350998 | 2658 | (< orig-depth (setq curr-depth allout-recent-depth)) |
19b84ba3 RS |
2659 | (cond ((= prev-depth curr-depth) |
2660 | ;; Register this one and move on: | |
d8350998 | 2661 | (setq chart (cons allout-recent-prefix-beginning chart)) |
19b84ba3 | 2662 | (if (and levels (<= levels 1)) |
60c7bbd2 | 2663 | ;; At depth limit -- skip sublevels: |
fd5359c6 | 2664 | (or (allout-next-sibling curr-depth) |
60c7bbd2 | 2665 | ;; or no more siblings -- proceed to |
19b84ba3 | 2666 | ;; next heading at lesser depth: |
e6a9aec7 | 2667 | (while (and (<= curr-depth |
d8350998 | 2668 | allout-recent-depth) |
48bd8440 EZ |
2669 | (if visible |
2670 | (allout-next-visible-heading 1) | |
2671 | (allout-next-heading))))) | |
2672 | (if visible | |
2673 | (allout-next-visible-heading 1) | |
2674 | (allout-next-heading)))) | |
19b84ba3 RS |
2675 | |
2676 | ((and (< prev-depth curr-depth) | |
2677 | (or (not levels) | |
2678 | (> levels 0))) | |
2679 | ;; Recurse on deeper level of curr topic: | |
2680 | (setq chart | |
fd5359c6 | 2681 | (cons (allout-chart-subtree (and levels |
19b84ba3 | 2682 | (1- levels)) |
48bd8440 EZ |
2683 | visible |
2684 | orig-depth | |
2685 | curr-depth) | |
19b84ba3 RS |
2686 | chart)) |
2687 | ;; ... then continue with this one. | |
2688 | ) | |
2689 | ||
2690 | ;; ... else nil if we've ascended back to prev-depth. | |
2691 | ||
2692 | ))) | |
2693 | ||
2694 | (if original ; We're at the last sibling on | |
2695 | ; the original level. Position | |
2696 | ; to the end of it: | |
c567ac01 | 2697 | (progn (and (not (eobp)) (forward-char -1)) |
96b83743 EZ |
2698 | (and (= (preceding-char) ?\n) |
2699 | (= (aref (buffer-substring (max 1 (- (point) 3)) | |
2700 | (point)) | |
2701 | 1) | |
2702 | ?\n) | |
19b84ba3 | 2703 | (forward-char -1)) |
fd5359c6 | 2704 | (setq allout-recent-end-of-subtree (point)))) |
353e2ef2 | 2705 | |
c567ac01 RS |
2706 | chart ; (nreverse chart) not necessary, |
2707 | ; and maybe not preferable. | |
2708 | )) | |
fd5359c6 MR |
2709 | ;;;_ > allout-chart-siblings (&optional start end) |
2710 | (defun allout-chart-siblings (&optional start end) | |
c567ac01 | 2711 | "Produce a list of locations of this and succeeding sibling topics. |
fd5359c6 | 2712 | Effectively a top-level chart of siblings. See `allout-chart-subtree' |
c567ac01 RS |
2713 | for an explanation of charts." |
2714 | (save-excursion | |
d8350998 CY |
2715 | (when (allout-goto-prefix-doublechecked) |
2716 | (let ((chart (list (point)))) | |
2717 | (while (allout-next-sibling) | |
2718 | (setq chart (cons (point) chart))) | |
2719 | (if chart (setq chart (nreverse chart))))))) | |
fd5359c6 MR |
2720 | ;;;_ > allout-chart-to-reveal (chart depth) |
2721 | (defun allout-chart-to-reveal (chart depth) | |
c567ac01 | 2722 | |
19b84ba3 | 2723 | "Return a flat list of hidden points in subtree CHART, up to DEPTH. |
c567ac01 | 2724 | |
65e7eb3d EZ |
2725 | If DEPTH is nil, include hidden points at any depth. |
2726 | ||
19b84ba3 | 2727 | Note that point can be left at any of the points on chart, or at the |
c567ac01 RS |
2728 | start point." |
2729 | ||
2730 | (let (result here) | |
65e7eb3d | 2731 | (while (and (or (null depth) (> depth 0)) |
c567ac01 RS |
2732 | chart) |
2733 | (setq here (car chart)) | |
2734 | (if (listp here) | |
65e7eb3d EZ |
2735 | (let ((further (allout-chart-to-reveal here (if (null depth) |
2736 | depth | |
2737 | (1- depth))))) | |
60c7bbd2 | 2738 | ;; We're on the start of a subtree -- recurse with it, if there's |
c567ac01 RS |
2739 | ;; more depth to go: |
2740 | (if further (setq result (append further result))) | |
2741 | (setq chart (cdr chart))) | |
2742 | (goto-char here) | |
96b83743 | 2743 | (if (allout-hidden-p) |
c567ac01 RS |
2744 | (setq result (cons here result))) |
2745 | (setq chart (cdr chart)))) | |
2746 | result)) | |
fd5359c6 | 2747 | ;;;_ X allout-chart-spec (chart spec &optional exposing) |
e126900f | 2748 | ;; (defun allout-chart-spec (chart spec &optional exposing) |
c07583cd | 2749 | ;; "Not yet (if ever) implemented. |
e126900f JB |
2750 | |
2751 | ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC. | |
2752 | ||
2753 | ;; Exposure spec indicates the locations to be exposed and the prescribed | |
2754 | ;; exposure status. Optional arg EXPOSING is an integer, with 0 | |
2755 | ;; indicating pending concealment, anything higher indicating depth to | |
2756 | ;; which subtopic headers should be exposed, and negative numbers | |
2757 | ;; indicating (negative of) the depth to which subtopic headers and | |
2758 | ;; bodies should be exposed. | |
2759 | ||
2760 | ;; The produced list can have two types of entries. Bare numbers | |
2761 | ;; indicate points in the buffer where topic headers that should be | |
2762 | ;; exposed reside. | |
2763 | ||
2764 | ;; - bare negative numbers indicates that the topic starting at the | |
2765 | ;; point which is the negative of the number should be opened, | |
2766 | ;; including their entries. | |
2767 | ;; - bare positive values indicate that this topic header should be | |
2768 | ;; opened. | |
2769 | ;; - Lists signify the beginning and end points of regions that should | |
c07583cd | 2770 | ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and |
e126900f JB |
2771 | ;; exposure:" |
2772 | ;; (while spec | |
2773 | ;; (cond ((listp spec) | |
2774 | ;; ) | |
2775 | ;; ) | |
2776 | ;; (setq spec (cdr spec))) | |
2777 | ;; ) | |
c567ac01 RS |
2778 | |
2779 | ;;;_ - Within Topic | |
fd5359c6 MR |
2780 | ;;;_ > allout-goto-prefix () |
2781 | (defun allout-goto-prefix () | |
9179616f | 2782 | "Put point at beginning of immediately containing outline topic. |
19b84ba3 | 2783 | |
9179616f | 2784 | Goes to most immediate subsequent topic if none immediately containing. |
19b84ba3 RS |
2785 | |
2786 | Not sensitive to topic visibility. | |
c567ac01 | 2787 | |
d27081f5 | 2788 | Returns the point at the beginning of the prefix, or nil if none." |
c567ac01 | 2789 | |
2a1408fd DN |
2790 | (save-match-data |
2791 | (let (done) | |
2792 | (while (and (not done) | |
2793 | (search-backward "\n" nil 1)) | |
2794 | (forward-char 1) | |
2795 | (if (looking-at allout-regexp) | |
2796 | (setq done (allout-prefix-data)) | |
2797 | (forward-char -1))) | |
2798 | (if (bobp) | |
2799 | (cond ((looking-at allout-regexp) | |
2800 | (allout-prefix-data)) | |
2801 | ((allout-next-heading)) | |
2802 | (done)) | |
2803 | done)))) | |
d8350998 CY |
2804 | ;;;_ > allout-goto-prefix-doublechecked () |
2805 | (defun allout-goto-prefix-doublechecked () | |
2806 | "Put point at beginning of immediately containing outline topic. | |
2807 | ||
c07583cd | 2808 | Like `allout-goto-prefix', but shallow topics (according to |
65e7eb3d EZ |
2809 | `allout-doublecheck-at-and-shallower') are checked and |
2810 | disqualified for child containment discontinuity, according to | |
2811 | `allout-aberrant-container-p'." | |
ede4ac6a KS |
2812 | (if (allout-goto-prefix) |
2813 | (if (and (allout-do-doublecheck) | |
2814 | (allout-aberrant-container-p)) | |
2815 | (allout-previous-heading) | |
2816 | (point)))) | |
d8350998 | 2817 | |
fd5359c6 MR |
2818 | ;;;_ > allout-end-of-prefix () |
2819 | (defun allout-end-of-prefix (&optional ignore-decorations) | |
19b84ba3 RS |
2820 | "Position cursor at beginning of header text. |
2821 | ||
2822 | If optional IGNORE-DECORATIONS is non-nil, put just after bullet, | |
2823 | otherwise skip white space between bullet and ensuing text." | |
c567ac01 | 2824 | |
d8350998 | 2825 | (if (not (allout-goto-prefix-doublechecked)) |
1977b8f6 | 2826 | nil |
d8350998 | 2827 | (goto-char allout-recent-prefix-end) |
2a1408fd DN |
2828 | (save-match-data |
2829 | (if ignore-decorations | |
2830 | t | |
2831 | (while (looking-at "[0-9]") (forward-char 1)) | |
2832 | (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))) | |
1977b8f6 | 2833 | ;; Reestablish where we are: |
fd5359c6 MR |
2834 | (allout-current-depth))) |
2835 | ;;;_ > allout-current-bullet-pos () | |
2836 | (defun allout-current-bullet-pos () | |
c07583cd | 2837 | "Return position of current (visible) topic's bullet." |
c567ac01 | 2838 | |
8a559d4e | 2839 | (if (not (allout-current-depth)) |
c567ac01 | 2840 | nil |
8a559d4e | 2841 | (1- allout-recent-prefix-end))) |
1c9b9df0 KM |
2842 | ;;;_ > allout-back-to-current-heading (&optional interactive) |
2843 | (defun allout-back-to-current-heading (&optional interactive) | |
80f66ef4 | 2844 | "Move to heading line of current topic, or beginning if not in a topic. |
96b83743 | 2845 | |
80f66ef4 CY |
2846 | If interactive, we position at the end of the prefix. |
2847 | ||
2848 | Return value of resulting point, unless we started outside | |
2849 | of (before any) topics, in which case we return nil." | |
96b83743 | 2850 | |
1c9b9df0 KM |
2851 | (interactive "p") |
2852 | ||
96b83743 | 2853 | (allout-beginning-of-current-line) |
80f66ef4 | 2854 | (let ((bol-point (point))) |
1e004a83 KM |
2855 | (when (allout-goto-prefix-doublechecked) |
2856 | (if (<= (point) bol-point) | |
2857 | (progn | |
2858 | (setq bol-point (point)) | |
2859 | (allout-beginning-of-current-line) | |
2860 | (if (not (= bol-point (point))) | |
2861 | (if (looking-at allout-regexp) | |
2862 | (allout-prefix-data))) | |
1c9b9df0 | 2863 | (if interactive |
ede4ac6a | 2864 | (allout-end-of-prefix) |
1e004a83 KM |
2865 | (point))) |
2866 | (goto-char (point-min)) | |
2867 | nil)))) | |
fd5359c6 MR |
2868 | ;;;_ > allout-back-to-heading () |
2869 | (defalias 'allout-back-to-heading 'allout-back-to-current-heading) | |
96b83743 EZ |
2870 | ;;;_ > allout-pre-next-prefix () |
2871 | (defun allout-pre-next-prefix () | |
1977b8f6 RS |
2872 | "Skip forward to just before the next heading line. |
2873 | ||
c567ac01 | 2874 | Returns that character position." |
1977b8f6 | 2875 | |
8a559d4e EZ |
2876 | (if (allout-next-heading) |
2877 | (goto-char (1- allout-recent-prefix-beginning)))) | |
96b83743 EZ |
2878 | ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank) |
2879 | (defun allout-end-of-subtree (&optional current include-trailing-blank) | |
d82979ea EZ |
2880 | "Put point at the end of the last leaf in the containing topic. |
2881 | ||
96b83743 EZ |
2882 | Optional CURRENT means put point at the end of the containing |
2883 | visible topic. | |
2884 | ||
2885 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if | |
2886 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2887 | excluded as delimiting whitespace between topics. | |
d82979ea EZ |
2888 | |
2889 | Returns the value of point." | |
2890 | (interactive "P") | |
2891 | (if current | |
2892 | (allout-back-to-current-heading) | |
d8350998 CY |
2893 | (allout-goto-prefix-doublechecked)) |
2894 | (let ((level allout-recent-depth)) | |
fd5359c6 | 2895 | (allout-next-heading) |
1977b8f6 | 2896 | (while (and (not (eobp)) |
d8350998 | 2897 | (> allout-recent-depth level)) |
fd5359c6 | 2898 | (allout-next-heading)) |
48bd8440 EZ |
2899 | (if (eobp) |
2900 | (allout-end-of-entry) | |
2901 | (forward-char -1)) | |
96b83743 | 2902 | (if (and (not include-trailing-blank) (= ?\n (preceding-char))) |
c567ac01 | 2903 | (forward-char -1)) |
fd5359c6 | 2904 | (setq allout-recent-end-of-subtree (point)))) |
96b83743 EZ |
2905 | ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank) |
2906 | (defun allout-end-of-current-subtree (&optional include-trailing-blank) | |
2907 | ||
d82979ea EZ |
2908 | "Put point at end of last leaf in currently visible containing topic. |
2909 | ||
96b83743 EZ |
2910 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if |
2911 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2912 | excluded as delimiting whitespace between topics. | |
2913 | ||
d82979ea EZ |
2914 | Returns the value of point." |
2915 | (interactive) | |
96b83743 | 2916 | (allout-end-of-subtree t include-trailing-blank)) |
1c9b9df0 KM |
2917 | ;;;_ > allout-beginning-of-current-entry (&optional interactive) |
2918 | (defun allout-beginning-of-current-entry (&optional interactive) | |
d82979ea | 2919 | "When not already there, position point at beginning of current topic header. |
c567ac01 RS |
2920 | |
2921 | If already there, move cursor to bullet for hot-spot operation. | |
46771bb3 | 2922 | \(See `allout-mode' doc string for details of hot-spot operation.)" |
1c9b9df0 | 2923 | (interactive "p") |
c567ac01 | 2924 | (let ((start-point (point))) |
46771bb3 | 2925 | (move-beginning-of-line 1) |
d8350998 CY |
2926 | (if (< 0 (allout-current-depth)) |
2927 | (goto-char allout-recent-prefix-end) | |
2928 | (goto-char (point-min))) | |
fd5359c6 | 2929 | (allout-end-of-prefix) |
1c9b9df0 | 2930 | (if (and interactive |
c567ac01 | 2931 | (= (point) start-point)) |
fd5359c6 | 2932 | (goto-char (allout-current-bullet-pos))))) |
96b83743 EZ |
2933 | ;;;_ > allout-end-of-entry (&optional inclusive) |
2934 | (defun allout-end-of-entry (&optional inclusive) | |
2935 | "Position the point at the end of the current topics' entry. | |
2936 | ||
2937 | Optional INCLUSIVE means also include trailing empty line, if any. When | |
2938 | unset, whitespace between items separates them even when the items are | |
2939 | collapsed." | |
1977b8f6 | 2940 | (interactive) |
96b83743 EZ |
2941 | (allout-pre-next-prefix) |
2942 | (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char))) | |
2943 | (forward-char -1)) | |
2944 | (point)) | |
fd5359c6 MR |
2945 | ;;;_ > allout-end-of-current-heading () |
2946 | (defun allout-end-of-current-heading () | |
9179616f | 2947 | (interactive) |
fd5359c6 | 2948 | (allout-beginning-of-current-entry) |
96b83743 | 2949 | (search-forward "\n" nil t) |
d82979ea | 2950 | (forward-char -1)) |
fd5359c6 | 2951 | (defalias 'allout-end-of-heading 'allout-end-of-current-heading) |
d82979ea EZ |
2952 | ;;;_ > allout-get-body-text () |
2953 | (defun allout-get-body-text () | |
2954 | "Return the unmangled body text of the topic immediately containing point." | |
2955 | (save-excursion | |
2956 | (allout-end-of-prefix) | |
96b83743 | 2957 | (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
2958 | nil |
2959 | (backward-char 1) | |
2960 | (let ((pre-body (point))) | |
2961 | (if (not pre-body) | |
2962 | nil | |
96b83743 | 2963 | (allout-end-of-entry t) |
d82979ea EZ |
2964 | (if (not (= pre-body (point))) |
2965 | (buffer-substring-no-properties (1+ pre-body) (point)))) | |
2966 | ) | |
2967 | ) | |
2968 | ) | |
2969 | ) | |
1977b8f6 | 2970 | |
c567ac01 | 2971 | ;;;_ - Depth-wise |
fd5359c6 MR |
2972 | ;;;_ > allout-ascend-to-depth (depth) |
2973 | (defun allout-ascend-to-depth (depth) | |
c567ac01 | 2974 | "Ascend to depth DEPTH, returning depth if successful, nil if not." |
fd5359c6 | 2975 | (if (and (> depth 0)(<= depth (allout-depth))) |
d8350998 CY |
2976 | (let (last-ascended) |
2977 | (while (and (< depth allout-recent-depth) | |
2978 | (setq last-ascended (allout-ascend)))) | |
2979 | (goto-char allout-recent-prefix-beginning) | |
1c9b9df0 | 2980 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
d8350998 | 2981 | (and last-ascended allout-recent-depth)))) |
1c9b9df0 | 2982 | ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful) |
c07583cd KS |
2983 | (defun allout-ascend (&optional dont-move-if-unsuccessful) |
2984 | "Ascend one level, returning resulting depth if successful, nil if not. | |
2985 | ||
2986 | Point is left at the beginning of the level whether or not | |
2987 | successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in | |
2988 | which case point is returned to its original starting location." | |
2989 | (if dont-move-if-unsuccessful | |
2990 | (setq dont-move-if-unsuccessful (point))) | |
d82979ea EZ |
2991 | (prog1 |
2992 | (if (allout-beginning-of-level) | |
498a6493 CY |
2993 | (let ((bolevel (point)) |
2994 | (bolevel-depth allout-recent-depth)) | |
2995 | (allout-previous-heading) | |
c07583cd KS |
2996 | (cond ((< allout-recent-depth bolevel-depth) |
2997 | allout-recent-depth) | |
2998 | ((= allout-recent-depth bolevel-depth) | |
2999 | (if dont-move-if-unsuccessful | |
3000 | (goto-char dont-move-if-unsuccessful)) | |
3001 | (allout-depth) | |
3002 | nil) | |
3003 | (t | |
3004 | ;; some topic after very first is lower depth than first: | |
3005 | (goto-char bolevel) | |
3006 | (allout-depth) | |
3007 | nil)))) | |
1c9b9df0 | 3008 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 MR |
3009 | ;;;_ > allout-descend-to-depth (depth) |
3010 | (defun allout-descend-to-depth (depth) | |
19b84ba3 RS |
3011 | "Descend to depth DEPTH within current topic. |
3012 | ||
3013 | Returning depth if successful, nil if not." | |
1977b8f6 | 3014 | (let ((start-point (point)) |
fd5359c6 | 3015 | (start-depth (allout-depth))) |
1977b8f6 | 3016 | (while |
fd5359c6 | 3017 | (and (> (allout-depth) 0) |
d8350998 | 3018 | (not (= depth allout-recent-depth)) ; ... not there yet |
fd5359c6 | 3019 | (allout-next-heading) ; ... go further |
d8350998 | 3020 | (< start-depth allout-recent-depth))) ; ... still in topic |
fd5359c6 | 3021 | (if (and (> (allout-depth) 0) |
d8350998 | 3022 | (= allout-recent-depth depth)) |
1977b8f6 RS |
3023 | depth |
3024 | (goto-char start-point) | |
3025 | nil)) | |
3026 | ) | |
d8350998 CY |
3027 | ;;;_ > allout-up-current-level (arg) |
3028 | (defun allout-up-current-level (arg) | |
3029 | "Move out ARG levels from current visible topic." | |
d82979ea | 3030 | (interactive "p") |
8a559d4e EZ |
3031 | (let ((start-point (point))) |
3032 | (allout-back-to-current-heading) | |
3033 | (if (not (allout-ascend)) | |
3034 | (progn (goto-char start-point) | |
3035 | (error "Can't ascend past outermost level")) | |
1c9b9df0 | 3036 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
8a559d4e | 3037 | allout-recent-prefix-beginning))) |
1977b8f6 | 3038 | |
c567ac01 | 3039 | ;;;_ - Linear |
fd5359c6 MR |
3040 | ;;;_ > allout-next-sibling (&optional depth backward) |
3041 | (defun allout-next-sibling (&optional depth backward) | |
2265e017 | 3042 | "Like `allout-forward-current-level', but respects invisible topics. |
1977b8f6 | 3043 | |
c567ac01 | 3044 | Traverse at optional DEPTH, or current depth if none specified. |
1977b8f6 | 3045 | |
c567ac01 | 3046 | Go backward if optional arg BACKWARD is non-nil. |
1977b8f6 | 3047 | |
d8350998 | 3048 | Return the start point of the new topic if successful, nil otherwise." |
1977b8f6 | 3049 | |
d8350998 | 3050 | (if (if backward (bobp) (eobp)) |
1977b8f6 | 3051 | nil |
d8350998 | 3052 | (let ((target-depth (or depth (allout-depth))) |
1977b8f6 | 3053 | (start-point (point)) |
ede4ac6a | 3054 | (start-prefix-beginning allout-recent-prefix-beginning) |
d8350998 CY |
3055 | (count 0) |
3056 | leaping | |
c567ac01 | 3057 | last-depth) |
d8350998 CY |
3058 | (while (and |
3059 | ;; done too few single steps to resort to the leap routine: | |
3060 | (not leaping) | |
3061 | ;; not at limit: | |
3062 | (not (if backward (bobp) (eobp))) | |
3063 | ;; still traversable: | |
3064 | (if backward (allout-previous-heading) (allout-next-heading)) | |
3065 | ;; we're below the target depth | |
3066 | (> (setq last-depth allout-recent-depth) target-depth)) | |
3067 | (setq count (1+ count)) | |
3068 | (if (> count 7) ; lists are commonly 7 +- 2, right?-) | |
3069 | (setq leaping t))) | |
3070 | (cond (leaping | |
3071 | (or (allout-next-sibling-leap target-depth backward) | |
3072 | (progn | |
3073 | (goto-char start-point) | |
3074 | (if depth (allout-depth) target-depth) | |
3075 | nil))) | |
3076 | ((and (not (eobp)) | |
3077 | (and (> (or last-depth (allout-depth)) 0) | |
ede4ac6a KS |
3078 | (= allout-recent-depth target-depth)) |
3079 | (not (= start-prefix-beginning | |
3080 | allout-recent-prefix-beginning))) | |
d8350998 CY |
3081 | allout-recent-prefix-beginning) |
3082 | (t | |
3083 | (goto-char start-point) | |
3084 | (if depth (allout-depth) target-depth) | |
3085 | nil))))) | |
3086 | ;;;_ > allout-next-sibling-leap (&optional depth backward) | |
3087 | (defun allout-next-sibling-leap (&optional depth backward) | |
3088 | "Like `allout-next-sibling', but by direct search for topic at depth. | |
3089 | ||
3090 | Traverse at optional DEPTH, or current depth if none specified. | |
3091 | ||
3092 | Go backward if optional arg BACKWARD is non-nil. | |
3093 | ||
3094 | Return the start point of the new topic if successful, nil otherwise. | |
3095 | ||
3096 | Costs more than regular `allout-next-sibling' for short traversals: | |
3097 | ||
c07583cd | 3098 | - we have to check the prior (next, if travelling backwards) |
d8350998 CY |
3099 | item to confirm connectivity with the prior topic, and |
3100 | - if confirmed, we have to reestablish the allout-recent-* settings with | |
3101 | some extra navigation | |
3102 | - if confirmation fails, we have to do more work to recover | |
3103 | ||
3104 | It is an increasingly big win when there are many intervening | |
3105 | offspring before the next sibling, however, so | |
3106 | `allout-next-sibling' resorts to this if it finds itself in that | |
3107 | situation." | |
3108 | ||
3109 | (if (if backward (bobp) (eobp)) | |
3110 | nil | |
3111 | (let* ((start-point (point)) | |
3112 | (target-depth (or depth (allout-depth))) | |
3113 | (search-whitespace-regexp nil) | |
3114 | (depth-biased (- target-depth 2)) | |
3115 | (expression (if (<= target-depth 1) | |
3116 | allout-depth-one-regexp | |
3117 | (format allout-depth-specific-regexp | |
3118 | depth-biased depth-biased))) | |
3119 | found | |
3120 | done) | |
3121 | (while (not done) | |
2a1408fd DN |
3122 | (setq found (save-match-data |
3123 | (if backward | |
3124 | (re-search-backward expression nil 'to-limit) | |
3125 | (forward-char 1) | |
3126 | (re-search-forward expression nil 'to-limit)))) | |
d8350998 CY |
3127 | (if (and found (allout-aberrant-container-p)) |
3128 | (setq found nil)) | |
3129 | (setq done (or found (if backward (bobp) (eobp))))) | |
3130 | (if (not found) | |
3131 | (progn (goto-char start-point) | |
3132 | nil) | |
3133 | ;; rationale: if any intervening items were at a lower depth, we | |
60c7bbd2 | 3134 | ;; would now be on the first offspring at the target depth -- ie, |
97610156 | 3135 | ;; the preceding item (per the search direction) must be at a |
d8350998 CY |
3136 | ;; lesser depth. that's all we need to check. |
3137 | (if backward (allout-next-heading) (allout-previous-heading)) | |
3138 | (if (< allout-recent-depth target-depth) | |
3139 | ;; return to start and reestablish allout-recent-*: | |
3140 | (progn | |
3141 | (goto-char start-point) | |
3142 | (allout-depth) | |
3143 | nil) | |
3144 | (goto-char found) | |
3145 | ;; locate cursor and set allout-recent-*: | |
3146 | (allout-goto-prefix)))))) | |
fd5359c6 MR |
3147 | ;;;_ > allout-previous-sibling (&optional depth backward) |
3148 | (defun allout-previous-sibling (&optional depth backward) | |
d82979ea | 3149 | "Like `allout-forward-current-level' backwards, respecting invisible topics. |
1977b8f6 | 3150 | |
c567ac01 | 3151 | Optional DEPTH specifies depth to traverse, default current depth. |
1977b8f6 | 3152 | |
c567ac01 | 3153 | Optional BACKWARD reverses direction. |
1977b8f6 | 3154 | |
c567ac01 | 3155 | Return depth if successful, nil otherwise." |
fd5359c6 | 3156 | (allout-next-sibling depth (not backward)) |
1977b8f6 | 3157 | ) |
fd5359c6 MR |
3158 | ;;;_ > allout-snug-back () |
3159 | (defun allout-snug-back () | |
539d7736 | 3160 | "Position cursor at end of previous topic. |
19b84ba3 RS |
3161 | |
3162 | Presumes point is at the start of a topic prefix." | |
c567ac01 RS |
3163 | (if (or (bobp) (eobp)) |
3164 | nil | |
3165 | (forward-char -1)) | |
96b83743 | 3166 | (if (or (bobp) (not (= ?\n (preceding-char)))) |
c567ac01 | 3167 | nil |
96b83743 | 3168 | (forward-char -1)) |
c567ac01 | 3169 | (point)) |
fd5359c6 MR |
3170 | ;;;_ > allout-beginning-of-level () |
3171 | (defun allout-beginning-of-level () | |
c567ac01 | 3172 | "Go back to the first sibling at this level, visible or not." |
fd5359c6 MR |
3173 | (allout-end-of-level 'backward)) |
3174 | ;;;_ > allout-end-of-level (&optional backward) | |
3175 | (defun allout-end-of-level (&optional backward) | |
c567ac01 | 3176 | "Go to the last sibling at this level, visible or not." |
1977b8f6 | 3177 | |
fd5359c6 MR |
3178 | (let ((depth (allout-depth))) |
3179 | (while (allout-previous-sibling depth nil)) | |
d8350998 | 3180 | (prog1 allout-recent-depth |
1c9b9df0 | 3181 | (if (allout-called-interactively-p) (allout-end-of-prefix))))) |
fd5359c6 MR |
3182 | ;;;_ > allout-next-visible-heading (arg) |
3183 | (defun allout-next-visible-heading (arg) | |
19b84ba3 | 3184 | "Move to the next ARG'th visible heading line, backward if arg is negative. |
c567ac01 | 3185 | |
96b83743 | 3186 | Move to buffer limit in indicated direction if headings are exhausted." |
1977b8f6 | 3187 | |
1977b8f6 | 3188 | (interactive "p") |
0458fa80 EZ |
3189 | (let* ((inhibit-field-text-motion t) |
3190 | (backward (if (< arg 0) (setq arg (* -1 arg)))) | |
c567ac01 | 3191 | (step (if backward -1 1)) |
82b392a4 | 3192 | (progress (allout-current-bullet-pos)) |
c567ac01 RS |
3193 | prev got) |
3194 | ||
d8350998 CY |
3195 | (while (> arg 0) |
3196 | (while (and | |
3197 | ;; Boundary condition: | |
3198 | (not (if backward (bobp)(eobp))) | |
3199 | ;; Move, skipping over all concealed lines in one fell swoop: | |
3200 | (prog1 (condition-case nil (or (line-move step) t) | |
3201 | (error nil)) | |
82b392a4 KM |
3202 | (allout-beginning-of-current-line) |
3203 | ;; line-move can wind up on the same line if long. | |
3204 | ;; when moving forward, that would yield no-progress | |
3205 | (when (and (not backward) | |
3206 | (<= (point) progress)) | |
3207 | ;; ensure progress by doing line-move from end-of-line: | |
3208 | (end-of-line) | |
3209 | (condition-case nil (or (line-move step) t) | |
3210 | (error nil)) | |
3211 | (allout-beginning-of-current-line) | |
3212 | (setq progress (point)))) | |
d8350998 | 3213 | ;; Deal with apparent header line: |
2a1408fd DN |
3214 | (save-match-data |
3215 | (if (not (looking-at allout-regexp)) | |
3216 | ;; not a header line, keep looking: | |
d8350998 | 3217 | t |
2a1408fd DN |
3218 | (allout-prefix-data) |
3219 | (if (and (allout-do-doublecheck) | |
3220 | (allout-aberrant-container-p)) | |
3221 | ;; skip this aberrant prospective header line: | |
3222 | t | |
8dd59f01 | 3223 | ;; this prospective headerline qualifies -- register: |
2a1408fd DN |
3224 | (setq got allout-recent-prefix-beginning) |
3225 | ;; and break the loop: | |
3226 | nil))))) | |
c567ac01 RS |
3227 | ;; Register this got, it may be the last: |
3228 | (if got (setq prev got)) | |
3229 | (setq arg (1- arg))) | |
3230 | (cond (got ; Last move was to a prefix: | |
d8350998 | 3231 | (allout-end-of-prefix)) |
c567ac01 | 3232 | (prev ; Last move wasn't, but prev was: |
d8350998 CY |
3233 | (goto-char prev) |
3234 | (allout-end-of-prefix)) | |
c567ac01 | 3235 | ((not backward) (end-of-line) nil)))) |
fd5359c6 MR |
3236 | ;;;_ > allout-previous-visible-heading (arg) |
3237 | (defun allout-previous-visible-heading (arg) | |
c567ac01 | 3238 | "Move to the previous heading line. |
1977b8f6 | 3239 | |
c567ac01 | 3240 | With argument, repeats or can move forward if negative. |
2265e017 | 3241 | A heading line is one that starts with a `*' (or that `allout-regexp' |
c567ac01 | 3242 | matches)." |
1977b8f6 | 3243 | (interactive "p") |
d8350998 | 3244 | (prog1 (allout-next-visible-heading (- arg)) |
1c9b9df0 | 3245 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 | 3246 | ;;;_ > allout-forward-current-level (arg) |
d82979ea | 3247 | (defun allout-forward-current-level (arg) |
19b84ba3 | 3248 | "Position point at the next heading of the same level. |
1977b8f6 | 3249 | |
19b84ba3 | 3250 | Takes optional repeat-count, goes backward if count is negative. |
1977b8f6 | 3251 | |
19b84ba3 | 3252 | Returns resulting position, else nil if none found." |
d82979ea | 3253 | (interactive "p") |
fd5359c6 | 3254 | (let ((start-depth (allout-current-depth)) |
19b84ba3 | 3255 | (start-arg arg) |
d8350998 | 3256 | (backward (> 0 arg))) |
19b84ba3 RS |
3257 | (if (= 0 start-depth) |
3258 | (error "No siblings, not in a topic...")) | |
3259 | (if backward (setq arg (* -1 arg))) | |
d8350998 CY |
3260 | (allout-back-to-current-heading) |
3261 | (while (and (not (zerop arg)) | |
3262 | (if backward | |
3263 | (allout-previous-sibling) | |
3264 | (allout-next-sibling))) | |
3265 | (setq arg (1- arg))) | |
1c9b9df0 | 3266 | (if (not (allout-called-interactively-p)) |
d8350998 CY |
3267 | nil |
3268 | (allout-end-of-prefix) | |
3269 | (if (not (zerop arg)) | |
3270 | (error "Hit %s level %d topic, traversed %d of %d requested" | |
3271 | (if backward "first" "last") | |
3272 | allout-recent-depth | |
3273 | (- (abs start-arg) arg) | |
3274 | (abs start-arg)))))) | |
fd5359c6 | 3275 | ;;;_ > allout-backward-current-level (arg) |
d82979ea | 3276 | (defun allout-backward-current-level (arg) |
fd5359c6 | 3277 | "Inverse of `allout-forward-current-level'." |
d82979ea | 3278 | (interactive "p") |
1c9b9df0 | 3279 | (if (allout-called-interactively-p) |
19b84ba3 | 3280 | (let ((current-prefix-arg (* -1 arg))) |
fd5359c6 MR |
3281 | (call-interactively 'allout-forward-current-level)) |
3282 | (allout-forward-current-level (* -1 arg)))) | |
c567ac01 | 3283 | |
19b84ba3 | 3284 | ;;;_ #5 Alteration |
c567ac01 RS |
3285 | |
3286 | ;;;_ - Fundamental | |
fd5359c6 MR |
3287 | ;;;_ = allout-post-goto-bullet |
3288 | (defvar allout-post-goto-bullet nil | |
3289 | "Outline internal var, for `allout-pre-command-business' hot-spot operation. | |
19b84ba3 RS |
3290 | |
3291 | When set, tells post-processing to reposition on topic bullet, and | |
2265e017 | 3292 | then unset it. Set by `allout-pre-command-business' when implementing |
19b84ba3 RS |
3293 | hot-spot operation, where literal characters typed over a topic bullet |
3294 | are mapped to the command of the corresponding control-key on the | |
d3e51865 | 3295 | `allout-mode-map-value'.") |
fd5359c6 | 3296 | (make-variable-buffer-local 'allout-post-goto-bullet) |
48bd8440 EZ |
3297 | ;;;_ = allout-command-counter |
3298 | (defvar allout-command-counter 0 | |
3299 | "Counter that monotonically increases in allout-mode buffers. | |
3300 | ||
3301 | Set by `allout-pre-command-business', to support allout addons in | |
3302 | coordinating with allout activity.") | |
3303 | (make-variable-buffer-local 'allout-command-counter) | |
fd5359c6 MR |
3304 | ;;;_ > allout-post-command-business () |
3305 | (defun allout-post-command-business () | |
2265e017 | 3306 | "Outline `post-command-hook' function. |
c567ac01 | 3307 | |
2265e017 | 3308 | - Implement (and clear) `allout-post-goto-bullet', for hot-spot |
c567ac01 RS |
3309 | outline commands. |
3310 | ||
96b83743 | 3311 | - Decrypt topic currently being edited if it was encrypted for a save." |
c567ac01 RS |
3312 | |
3313 | ; Apply any external change func: | |
fd5359c6 | 3314 | (if (not (allout-mode-p)) ; In allout-mode. |
19b84ba3 | 3315 | nil |
d82979ea EZ |
3316 | |
3317 | (if (and (boundp 'allout-after-save-decrypt) | |
3318 | allout-after-save-decrypt) | |
3319 | (allout-after-saves-handler)) | |
3320 | ||
48bd8440 | 3321 | ;; Implement allout-post-goto-bullet, if set: |
fd5359c6 MR |
3322 | (if (and allout-post-goto-bullet |
3323 | (allout-current-bullet-pos)) | |
3324 | (progn (goto-char (allout-current-bullet-pos)) | |
3325 | (setq allout-post-goto-bullet nil))) | |
19b84ba3 | 3326 | )) |
fd5359c6 MR |
3327 | ;;;_ > allout-pre-command-business () |
3328 | (defun allout-pre-command-business () | |
2265e017 | 3329 | "Outline `pre-command-hook' function for outline buffers. |
48bd8440 EZ |
3330 | |
3331 | Among other things, implements special behavior when the cursor is on the | |
3332 | topic bullet character. | |
c567ac01 | 3333 | |
d3e51865 KM |
3334 | When the cursor is on the bullet character, self-insert |
3335 | characters are reinterpreted as the corresponding | |
3336 | control-character in the `allout-mode-map-value'. The | |
3337 | `allout-mode' `post-command-hook' insures that the cursor which | |
3338 | has moved as a result of such reinterpretation is positioned on | |
3339 | the bullet character of the destination topic. | |
c567ac01 | 3340 | |
c07583cd | 3341 | The upshot is that you can get easy, single (ie, unmodified) key |
9179616f | 3342 | outline maneuvering operations by positioning the cursor on the bullet |
58edceeb JB |
3343 | char. When in this mode you can use regular cursor-positioning |
3344 | command/keystrokes to relocate the cursor off of a bullet character to | |
3345 | return to regular interpretation of self-insert characters." | |
d82979ea | 3346 | |
fd5359c6 | 3347 | (if (not (allout-mode-p)) |
9179616f | 3348 | nil |
48bd8440 EZ |
3349 | ;; Increment allout-command-counter |
3350 | (setq allout-command-counter (1+ allout-command-counter)) | |
3351 | ;; Do hot-spot navigation. | |
9179616f | 3352 | (if (and (eq this-command 'self-insert-command) |
fd5359c6 | 3353 | (eq (point)(allout-current-bullet-pos))) |
01fc9422 EZ |
3354 | (allout-hotspot-key-handler)))) |
3355 | ;;;_ > allout-hotspot-key-handler () | |
3356 | (defun allout-hotspot-key-handler () | |
3357 | "Catchall handling of key bindings in hot-spots. | |
3358 | ||
3359 | Translates unmodified keystrokes to corresponding allout commands, when | |
3360 | they would qualify if prefixed with the allout-command-prefix, and sets | |
3361 | this-command accordingly. | |
3362 | ||
3363 | Returns the qualifying command, if any, else nil." | |
3364 | (interactive) | |
1c9b9df0 | 3365 | (let* ((modified (event-modifiers last-command-event)) |
8989a920 | 3366 | (key-num (cond ((numberp last-command-event) last-command-event) |
01fc9422 EZ |
3367 | ;; for XEmacs character type: |
3368 | ((and (fboundp 'characterp) | |
8989a920 GM |
3369 | (apply 'characterp (list last-command-event))) |
3370 | (apply 'char-to-int (list last-command-event))) | |
01fc9422 | 3371 | (t 0))) |
d8350998 | 3372 | mapped-binding) |
01fc9422 EZ |
3373 | |
3374 | (if (zerop key-num) | |
3375 | nil | |
3376 | ||
d8350998 CY |
3377 | (if (and |
3378 | ;; exclude control chars and escape: | |
1c9b9df0 | 3379 | (not modified) |
d8350998 CY |
3380 | (<= 33 key-num) |
3381 | (setq mapped-binding | |
642f3c5c KM |
3382 | (or |
3383 | ;; try control-modified versions of keys: | |
3384 | (key-binding (vconcat allout-command-prefix | |
3385 | (vector | |
3386 | (if (and (<= 97 key-num) ; "a" | |
3387 | (>= 122 key-num)) ; "z" | |
3388 | (- key-num 96) key-num))) | |
3389 | t) | |
3390 | ;; try non-modified versions of keys: | |
3391 | (key-binding (vconcat allout-command-prefix | |
3392 | (vector key-num)) | |
3393 | t)))) | |
60c7bbd2 | 3394 | ;; Qualified as an allout command -- do hot-spot operation. |
01fc9422 | 3395 | (setq allout-post-goto-bullet t) |
1c9b9df0 KM |
3396 | ;; accept-defaults nil, or else we get allout-item-icon-key-handler. |
3397 | (setq mapped-binding (key-binding (vector key-num)))) | |
01fc9422 EZ |
3398 | |
3399 | (while (keymapp mapped-binding) | |
3400 | (setq mapped-binding | |
d8350998 | 3401 | (lookup-key mapped-binding (vector (read-char))))) |
01fc9422 | 3402 | |
1c9b9df0 KM |
3403 | (when mapped-binding |
3404 | (setq this-command mapped-binding))))) | |
01fc9422 | 3405 | |
fd5359c6 MR |
3406 | ;;;_ > allout-find-file-hook () |
3407 | (defun allout-find-file-hook () | |
4034b0e2 | 3408 | "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'. |
fd5359c6 | 3409 | |
11c46e15 | 3410 | See `allout-auto-activation' for setup instructions." |
fd5359c6 MR |
3411 | (if (and allout-auto-activation |
3412 | (not (allout-mode-p)) | |
3413 | allout-layout) | |
2576c28f | 3414 | (allout-mode))) |
c567ac01 RS |
3415 | |
3416 | ;;;_ - Topic Format Assessment | |
fd5359c6 MR |
3417 | ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet) |
3418 | (defun allout-solicit-alternate-bullet (depth &optional current-bullet) | |
1977b8f6 | 3419 | |
19b84ba3 RS |
3420 | "Prompt for and return a bullet char as an alternative to the current one. |
3421 | ||
3422 | Offer one suitable for current depth DEPTH as default." | |
1977b8f6 | 3423 | |
9179616f | 3424 | (let* ((default-bullet (or (and (stringp current-bullet) current-bullet) |
fd5359c6 MR |
3425 | (allout-bullet-for-depth depth))) |
3426 | (sans-escapes (regexp-sans-escapes allout-bullets-string)) | |
9179616f DL |
3427 | choice) |
3428 | (save-excursion | |
fd5359c6 | 3429 | (goto-char (allout-current-bullet-pos)) |
9179616f DL |
3430 | (setq choice (solicit-char-in-string |
3431 | (format "Select bullet: %s ('%s' default): " | |
3432 | sans-escapes | |
1c9b9df0 | 3433 | (allout-substring-no-properties default-bullet)) |
9179616f DL |
3434 | sans-escapes |
3435 | t))) | |
3436 | (message "") | |
1977b8f6 RS |
3437 | (if (string= choice "") default-bullet choice)) |
3438 | ) | |
fd5359c6 MR |
3439 | ;;;_ > allout-distinctive-bullet (bullet) |
3440 | (defun allout-distinctive-bullet (bullet) | |
e126900f | 3441 | "True if BULLET is one of those on `allout-distinctive-bullets-string'." |
fd5359c6 MR |
3442 | (string-match (regexp-quote bullet) allout-distinctive-bullets-string)) |
3443 | ;;;_ > allout-numbered-type-prefix (&optional prefix) | |
3444 | (defun allout-numbered-type-prefix (&optional prefix) | |
c567ac01 | 3445 | "True if current header prefix bullet is numbered bullet." |
fd5359c6 MR |
3446 | (and allout-numbered-bullet |
3447 | (string= allout-numbered-bullet | |
1977b8f6 | 3448 | (if prefix |
fd5359c6 MR |
3449 | (allout-get-prefix-bullet prefix) |
3450 | (allout-get-bullet))))) | |
d82979ea EZ |
3451 | ;;;_ > allout-encrypted-type-prefix (&optional prefix) |
3452 | (defun allout-encrypted-type-prefix (&optional prefix) | |
c07583cd | 3453 | "True if current header prefix bullet is for an encrypted entry (body)." |
d82979ea EZ |
3454 | (and allout-topic-encryption-bullet |
3455 | (string= allout-topic-encryption-bullet | |
3456 | (if prefix | |
3457 | (allout-get-prefix-bullet prefix) | |
3458 | (allout-get-bullet))))) | |
fd5359c6 MR |
3459 | ;;;_ > allout-bullet-for-depth (&optional depth) |
3460 | (defun allout-bullet-for-depth (&optional depth) | |
19b84ba3 | 3461 | "Return outline topic bullet suited to optional DEPTH, or current depth." |
1977b8f6 | 3462 | ;; Find bullet in plain-bullets-string modulo DEPTH. |
fd5359c6 MR |
3463 | (if allout-stylish-prefixes |
3464 | (char-to-string (aref allout-plain-bullets-string | |
1977b8f6 | 3465 | (% (max 0 (- depth 2)) |
fd5359c6 MR |
3466 | allout-plain-bullets-string-len))) |
3467 | allout-primary-bullet) | |
1977b8f6 RS |
3468 | ) |
3469 | ||
c567ac01 | 3470 | ;;;_ - Topic Production |
fd5359c6 MR |
3471 | ;;;_ > allout-make-topic-prefix (&optional prior-bullet |
3472 | (defun allout-make-topic-prefix (&optional prior-bullet | |
1977b8f6 RS |
3473 | new |
3474 | depth | |
b6a5875b | 3475 | instead |
1977b8f6 RS |
3476 | number-control |
3477 | index) | |
3478 | ;; Depth null means use current depth, non-null means we're either | |
3479 | ;; opening a new topic after current topic, lower or higher, or we're | |
3480 | ;; changing level of current topic. | |
b6a5875b | 3481 | ;; Instead dominates specified bullet-char. |
c567ac01 | 3482 | ;;;_ . Doc string: |
19b84ba3 | 3483 | "Generate a topic prefix suitable for optional arg DEPTH, or current depth. |
c567ac01 RS |
3484 | |
3485 | All the arguments are optional. | |
3486 | ||
3487 | PRIOR-BULLET indicates the bullet of the prefix being changed, or | |
3488 | nil if none. This bullet may be preserved (other options | |
2265e017 | 3489 | notwithstanding) if it is on the `allout-distinctive-bullets-string', |
c567ac01 RS |
3490 | for instance. |
3491 | ||
3492 | Second arg NEW indicates that a new topic is being opened after the | |
3493 | topic at point, if non-nil. Default bullet for new topics, eg, may | |
3494 | be set (contingent to other args) to numbered bullets if previous | |
3495 | sibling is one. The implication otherwise is that the current topic | |
60c7bbd2 | 3496 | is being adjusted -- shifted or rebulleted -- and we don't consider |
c567ac01 RS |
3497 | bullet or previous sibling. |
3498 | ||
3499 | Third arg DEPTH forces the topic prefix to that depth, regardless of | |
3500 | the current topics' depth. | |
3501 | ||
b6a5875b KM |
3502 | If INSTEAD is: |
3503 | ||
3504 | - nil, then the bullet char for the context is used, per distinction or depth | |
2dab465b KM |
3505 | - a \(numeric) character, then character's string representation is used |
3506 | - a string, then the user is asked for bullet with the first char as default | |
b6a5875b KM |
3507 | - anything else, the user is solicited with bullet char per context as default |
3508 | ||
3509 | \(INSTEAD overrides other options, including, eg, a distinctive | |
3510 | PRIOR-BULLET.) | |
c567ac01 | 3511 | |
fd5359c6 | 3512 | Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet' |
b6a5875b | 3513 | is non-nil *and* no specific INSTEAD was specified. Then |
c567ac01 RS |
3514 | NUMBER-CONTROL non-nil forces prefix to either numbered or |
3515 | denumbered format, depending on the value of the sixth arg, INDEX. | |
3516 | ||
3517 | \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...) | |
3518 | ||
3519 | If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then | |
3520 | the prefix of the topic is forced to be numbered. Non-nil | |
3521 | NUMBER-CONTROL and nil INDEX forces non-numbered format on the | |
3522 | bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means | |
3523 | that the index for the numbered prefix will be derived, by counting | |
3524 | siblings back to start of level. If INDEX is a number, then that | |
3525 | number is used as the index for the numbered prefix (allowing, eg, | |
a0776d6b | 3526 | sequential renumbering to not require this function counting back the |
c567ac01 RS |
3527 | index for each successive sibling)." |
3528 | ;;;_ . Code: | |
1977b8f6 RS |
3529 | ;; The options are ordered in likely frequence of use, most common |
3530 | ;; highest, least lowest. Ie, more likely to be doing prefix | |
3531 | ;; adjustments than soliciting, and yet more than numbering. | |
3532 | ;; Current prefix is least dominant, but most likely to be commonly | |
3533 | ;; specified... | |
3534 | ||
3535 | (let* (body | |
3536 | numbering | |
3537 | denumbering | |
fd5359c6 MR |
3538 | (depth (or depth (allout-depth))) |
3539 | (header-lead allout-header-prefix) | |
1977b8f6 RS |
3540 | (bullet-char |
3541 | ||
3542 | ;; Getting value for bullet char is practically the whole job: | |
3543 | ||
3544 | (cond | |
60c7bbd2 | 3545 | ; Simplest situation -- level 1: |
fd5359c6 | 3546 | ((<= depth 1) (setq header-lead "") allout-primary-bullet) |
1977b8f6 | 3547 | ; Simple, too: all asterisks: |
fd5359c6 | 3548 | (allout-old-style-prefixes |
60c7bbd2 | 3549 | ;; Cheat -- make body the whole thing, null out header-lead and |
1977b8f6 RS |
3550 | ;; bullet-char: |
3551 | (setq body (make-string depth | |
fd5359c6 | 3552 | (string-to-char allout-primary-bullet))) |
1977b8f6 RS |
3553 | (setq header-lead "") |
3554 | "") | |
3555 | ||
3556 | ;; (Neither level 1 nor old-style, so we're space padding. | |
3557 | ;; Sneak it in the condition of the next case, whatever it is.) | |
3558 | ||
3559 | ;; Solicitation overrides numbering and other cases: | |
3560 | ((progn (setq body (make-string (- depth 2) ?\ )) | |
3561 | ;; The actual condition: | |
b6a5875b | 3562 | instead) |
2dab465b KM |
3563 | (let ((got (cond ((stringp instead) |
3564 | (if (> (length instead) 0) | |
3565 | (allout-solicit-alternate-bullet | |
3566 | depth (substring instead 0 1)))) | |
3567 | ((characterp instead) (char-to-string instead)) | |
3568 | (t (allout-solicit-alternate-bullet depth))))) | |
1977b8f6 | 3569 | ;; Gotta check whether we're numbering and got a numbered bullet: |
fd5359c6 | 3570 | (setq numbering (and allout-numbered-bullet |
1977b8f6 | 3571 | (not (and number-control (not index))) |
fd5359c6 | 3572 | (string= got allout-numbered-bullet))) |
1977b8f6 RS |
3573 | ;; Now return what we got, regardless: |
3574 | got)) | |
3575 | ||
3576 | ;; Numbering invoked through args: | |
fd5359c6 | 3577 | ((and allout-numbered-bullet number-control) |
1977b8f6 | 3578 | (if (setq numbering (not (setq denumbering (not index)))) |
fd5359c6 | 3579 | allout-numbered-bullet |
19b84ba3 | 3580 | (if (and prior-bullet |
fd5359c6 | 3581 | (not (string= allout-numbered-bullet |
19b84ba3 RS |
3582 | prior-bullet))) |
3583 | prior-bullet | |
fd5359c6 | 3584 | (allout-bullet-for-depth depth)))) |
1977b8f6 RS |
3585 | |
3586 | ;;; Neither soliciting nor controlled numbering ;;; | |
3587 | ;;; (may be controlled denumbering, tho) ;;; | |
3588 | ||
3589 | ;; Check wrt previous sibling: | |
3590 | ((and new ; only check for new prefixes | |
fd5359c6 MR |
3591 | (<= depth (allout-depth)) |
3592 | allout-numbered-bullet ; ... & numbering enabled | |
1977b8f6 RS |
3593 | (not denumbering) |
3594 | (let ((sibling-bullet | |
3595 | (save-excursion | |
3596 | ;; Locate correct sibling: | |
fd5359c6 MR |
3597 | (or (>= depth (allout-depth)) |
3598 | (allout-ascend-to-depth depth)) | |
3599 | (allout-get-bullet)))) | |
1977b8f6 | 3600 | (if (and sibling-bullet |
fd5359c6 | 3601 | (string= allout-numbered-bullet sibling-bullet)) |
1977b8f6 RS |
3602 | (setq numbering sibling-bullet))))) |
3603 | ||
3604 | ;; Distinctive prior bullet? | |
3605 | ((and prior-bullet | |
fd5359c6 | 3606 | (allout-distinctive-bullet prior-bullet) |
1977b8f6 | 3607 | ;; Either non-numbered: |
fd5359c6 MR |
3608 | (or (not (and allout-numbered-bullet |
3609 | (string= prior-bullet allout-numbered-bullet))) | |
1977b8f6 RS |
3610 | ;; or numbered, and not denumbering: |
3611 | (setq numbering (not denumbering))) | |
3612 | ;; Here 'tis: | |
3613 | prior-bullet)) | |
3614 | ||
3615 | ;; Else, standard bullet per depth: | |
fd5359c6 | 3616 | ((allout-bullet-for-depth depth))))) |
1977b8f6 RS |
3617 | |
3618 | (concat header-lead | |
3619 | body | |
3620 | bullet-char | |
3621 | (if numbering | |
3622 | (format "%d" (cond ((and index (numberp index)) index) | |
fd5359c6 MR |
3623 | (new (1+ (allout-sibling-index depth))) |
3624 | ((allout-sibling-index)))))) | |
1977b8f6 RS |
3625 | ) |
3626 | ) | |
96b83743 EZ |
3627 | ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet) |
3628 | (defun allout-open-topic (relative-depth &optional before offer-recent-bullet) | |
d82979ea | 3629 | "Open a new topic at depth DEPTH. |
19b84ba3 RS |
3630 | |
3631 | New topic is situated after current one, unless optional flag BEFORE | |
60c7bbd2 RS |
3632 | is non-nil, or unless current line is completely empty -- lacking even |
3633 | whitespace -- in which case open is done on the current line. | |
96b83743 EZ |
3634 | |
3635 | When adding an offspring, it will be added immediately after the parent if | |
3636 | the other offspring are exposed, or after the last child if the offspring | |
c07583cd | 3637 | are hidden. (The intervening offspring will be exposed in the latter |
96b83743 | 3638 | case.) |
c567ac01 | 3639 | |
96b83743 | 3640 | If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling. |
9179616f | 3641 | |
c567ac01 RS |
3642 | Nuances: |
3643 | ||
3644 | - Creation of new topics is with respect to the visible topic | |
3645 | containing the cursor, regardless of intervening concealed ones. | |
3646 | ||
3647 | - New headers are generally created after/before the body of a | |
3648 | topic. However, they are created right at cursor location if the | |
3649 | cursor is on a blank line, even if that breaks the current topic | |
3650 | body. This is intentional, to provide a simple means for | |
3651 | deliberately dividing topic bodies. | |
3652 | ||
3653 | - Double spacing of topic lists is preserved. Also, the first | |
3654 | level two topic is created double-spaced (and so would be | |
3655 | subsequent siblings, if that's left intact). Otherwise, | |
3656 | single-spacing is used. | |
3657 | ||
3658 | - Creation of sibling or nested topics is with respect to the topic | |
3659 | you're starting from, even when creating backwards. This way you | |
3660 | can easily create a sibling in front of the current topic without | |
a0776d6b | 3661 | having to go to its preceding sibling, and then open forward |
c567ac01 | 3662 | from there." |
1977b8f6 | 3663 | |
96b83743 | 3664 | (allout-beginning-of-current-line) |
2a1408fd DN |
3665 | (save-match-data |
3666 | (let* ((inhibit-field-text-motion t) | |
3667 | (depth (+ (allout-current-depth) relative-depth)) | |
3668 | (opening-on-blank (if (looking-at "^\$") | |
3669 | (not (setq before nil)))) | |
3670 | ;; bunch o vars set while computing ref-topic | |
3671 | opening-numbered | |
3672 | ref-depth | |
3673 | ref-bullet | |
3674 | (ref-topic (save-excursion | |
3675 | (cond ((< relative-depth 0) | |
3676 | (allout-ascend-to-depth depth)) | |
3677 | ((>= relative-depth 1) nil) | |
3678 | (t (allout-back-to-current-heading))) | |
3679 | (setq ref-depth allout-recent-depth) | |
3680 | (setq ref-bullet | |
3681 | (if (> allout-recent-prefix-end 1) | |
3682 | (allout-recent-bullet) | |
3683 | "")) | |
3684 | (setq opening-numbered | |
3685 | (save-excursion | |
3686 | (and allout-numbered-bullet | |
3687 | (or (<= relative-depth 0) | |
3688 | (allout-descend-to-depth depth)) | |
3689 | (if (allout-numbered-type-prefix) | |
3690 | allout-numbered-bullet)))) | |
3691 | (point))) | |
3692 | dbl-space | |
3693 | doing-beginning | |
3694 | start end) | |
3695 | ||
3696 | (if (not opening-on-blank) | |
1977b8f6 | 3697 | ; Positioning and vertical |
60c7bbd2 | 3698 | ; padding -- only if not |
1977b8f6 | 3699 | ; opening-on-blank: |
2a1408fd DN |
3700 | (progn |
3701 | (goto-char ref-topic) | |
3702 | (setq dbl-space ; Determine double space action: | |
3703 | (or (and (<= relative-depth 0) ; not descending; | |
3704 | (save-excursion | |
3705 | ;; at b-o-b or preceded by a blank line? | |
3706 | (or (> 0 (forward-line -1)) | |
3707 | (looking-at "^\\s-*$") | |
3708 | (bobp))) | |
3709 | (save-excursion | |
3710 | ;; succeeded by a blank line? | |
3711 | (allout-end-of-current-subtree) | |
3712 | (looking-at "\n\n"))) | |
3713 | (and (= ref-depth 1) | |
3714 | (or before | |
3715 | (= depth 1) | |
3716 | (save-excursion | |
3717 | ;; Don't already have following | |
3718 | ;; vertical padding: | |
3719 | (not (allout-pre-next-prefix))))))) | |
3720 | ||
3721 | ;; Position to prior heading, if inserting backwards, and not | |
3722 | ;; going outwards: | |
3723 | (if (and before (>= relative-depth 0)) | |
3724 | (progn (allout-back-to-current-heading) | |
3725 | (setq doing-beginning (bobp)) | |
3726 | (if (not (bobp)) | |
3727 | (allout-previous-heading))) | |
3728 | (if (and before (bobp)) | |
3729 | (open-line 1))) | |
3730 | ||
3731 | (if (<= relative-depth 0) | |
3732 | ;; Not going inwards, don't snug up: | |
3733 | (if doing-beginning | |
3734 | (if (not dbl-space) | |
3735 | (open-line 1) | |
3736 | (open-line 2)) | |
3737 | (if before | |
3738 | (progn (end-of-line) | |
3739 | (allout-pre-next-prefix) | |
3740 | (while (and (= ?\n (following-char)) | |
3741 | (save-excursion | |
3742 | (forward-char 1) | |
3743 | (allout-hidden-p))) | |
3744 | (forward-char 1)) | |
3745 | (if (not (looking-at "^$")) | |
3746 | (open-line 1))) | |
3747 | (allout-end-of-current-subtree) | |
3748 | (if (looking-at "\n\n") (forward-char 1)))) | |
8dd59f01 | 3749 | ;; Going inwards -- double-space if first offspring is |
2a1408fd DN |
3750 | ;; double-spaced, otherwise snug up. |
3751 | (allout-end-of-entry) | |
3752 | (if (eobp) | |
3753 | (newline 1) | |
3754 | (line-move 1)) | |
3755 | (allout-beginning-of-current-line) | |
3756 | (backward-char 1) | |
3757 | (if (bolp) | |
3758 | ;; Blank lines between current header body and next | |
8dd59f01 | 3759 | ;; header -- get to last substantive (non-white-space) |
2a1408fd DN |
3760 | ;; line in body: |
3761 | (progn (setq dbl-space t) | |
3762 | (re-search-backward "[^ \t\n]" nil t))) | |
3763 | (if (looking-at "\n\n") | |
3764 | (setq dbl-space t)) | |
3765 | (if (save-excursion | |
3766 | (allout-next-heading) | |
3767 | (when (> allout-recent-depth ref-depth) | |
3768 | ;; This is an offspring. | |
3769 | (forward-line -1) | |
3770 | (looking-at "^\\s-*$"))) | |
3771 | (progn (forward-line 1) | |
96b83743 | 3772 | (open-line 1) |
2a1408fd DN |
3773 | (forward-line 1))) |
3774 | (allout-end-of-current-line)) | |
3775 | ||
3776 | ;;(if doing-beginning (goto-char doing-beginning)) | |
3777 | (if (not (bobp)) | |
3778 | ;; We insert a newline char rather than using open-line to | |
3779 | ;; avoid rear-stickiness inheritence of read-only property. | |
3780 | (progn (if (and (not (> depth ref-depth)) | |
3781 | (not before)) | |
3782 | (open-line 1) | |
3783 | (if (and (not dbl-space) (> depth ref-depth)) | |
3784 | (newline 1) | |
3785 | (if dbl-space | |
3786 | (open-line 1) | |
3787 | (if (not before) | |
3788 | (newline 1))))) | |
3789 | (if (and dbl-space (not (> relative-depth 0))) | |
3790 | (newline 1)) | |
3791 | (if (and (not (eobp)) | |
3792 | (or (not (bolp)) | |
3793 | (and (not (bobp)) | |
3794 | ;; bolp doesnt detect concealed | |
3795 | ;; trailing newlines, compensate: | |
3796 | (save-excursion | |
3797 | (forward-char -1) | |
3798 | (allout-hidden-p))))) | |
3799 | (forward-char 1)))) | |
3800 | )) | |
3801 | (setq start (point)) | |
3802 | (insert (concat (allout-make-topic-prefix opening-numbered t depth) | |
3803 | " ")) | |
3804 | (setq end (1+ (point))) | |
3805 | ||
3806 | (allout-rebullet-heading (and offer-recent-bullet ref-bullet) | |
3807 | depth nil nil t) | |
3808 | (if (> relative-depth 0) | |
3809 | (save-excursion (goto-char ref-topic) | |
3810 | (allout-show-children))) | |
3811 | (end-of-line) | |
48bd8440 | 3812 | |
2a1408fd DN |
3813 | (run-hook-with-args 'allout-structure-added-hook start end) |
3814 | ) | |
1977b8f6 RS |
3815 | ) |
3816 | ) | |
fd5359c6 MR |
3817 | ;;;_ > allout-open-subtopic (arg) |
3818 | (defun allout-open-subtopic (arg) | |
c567ac01 RS |
3819 | "Open new topic header at deeper level than the current one. |
3820 | ||
3821 | Negative universal arg means to open deeper, but place the new topic | |
3822 | prior to the current one." | |
1977b8f6 | 3823 | (interactive "p") |
d82979ea | 3824 | (allout-open-topic 1 (> 0 arg) (< 1 arg))) |
fd5359c6 MR |
3825 | ;;;_ > allout-open-sibtopic (arg) |
3826 | (defun allout-open-sibtopic (arg) | |
19b84ba3 RS |
3827 | "Open new topic header at same level as the current one. |
3828 | ||
9179616f DL |
3829 | Positive universal arg means to use the bullet of the prior sibling. |
3830 | ||
19b84ba3 | 3831 | Negative universal arg means to place the new topic prior to the current |
c567ac01 | 3832 | one." |
1977b8f6 | 3833 | (interactive "p") |
d82979ea | 3834 | (allout-open-topic 0 (> 0 arg) (not (= 1 arg)))) |
fd5359c6 MR |
3835 | ;;;_ > allout-open-supertopic (arg) |
3836 | (defun allout-open-supertopic (arg) | |
c567ac01 | 3837 | "Open new topic header at shallower level than the current one. |
19b84ba3 | 3838 | |
c567ac01 RS |
3839 | Negative universal arg means to open shallower, but place the new |
3840 | topic prior to the current one." | |
1977b8f6 RS |
3841 | |
3842 | (interactive "p") | |
d82979ea | 3843 | (allout-open-topic -1 (> 0 arg) (< 1 arg))) |
c567ac01 RS |
3844 | |
3845 | ;;;_ - Outline Alteration | |
3846 | ;;;_ : Topic Modification | |
fd5359c6 MR |
3847 | ;;;_ = allout-former-auto-filler |
3848 | (defvar allout-former-auto-filler nil | |
2265e017 | 3849 | "Name of modal fill function being wrapped by `allout-auto-fill'.") |
fd5359c6 MR |
3850 | ;;;_ > allout-auto-fill () |
3851 | (defun allout-auto-fill () | |
aad94676 | 3852 | "`allout-mode' autofill function. |
19b84ba3 RS |
3853 | |
3854 | Maintains outline hanging topic indentation if | |
fd5359c6 | 3855 | `allout-use-hanging-indents' is set." |
01fc9422 | 3856 | |
381987c3 KM |
3857 | (when (and (not allout-inhibit-auto-fill) |
3858 | (or (not allout-inhibit-auto-fill-on-headline) | |
3859 | (not (allout-on-current-heading-p)))) | |
01fc9422 EZ |
3860 | (let ((fill-prefix (if allout-use-hanging-indents |
3861 | ;; Check for topic header indentation: | |
2a1408fd DN |
3862 | (save-match-data |
3863 | (save-excursion | |
3864 | (beginning-of-line) | |
3865 | (if (looking-at allout-regexp) | |
3866 | ;; ... construct indentation to account for | |
3867 | ;; length of topic prefix: | |
3868 | (make-string (progn (allout-end-of-prefix) | |
3869 | (current-column)) | |
3870 | ?\ )))))) | |
7927f48d KM |
3871 | (use-auto-fill-function |
3872 | (if (and (eq allout-outside-normal-auto-fill-function | |
3873 | 'allout-auto-fill) | |
3874 | (eq auto-fill-function 'allout-auto-fill)) | |
3875 | 'do-auto-fill | |
3876 | (or allout-outside-normal-auto-fill-function | |
3877 | auto-fill-function)))) | |
01fc9422 EZ |
3878 | (if (or allout-former-auto-filler allout-use-hanging-indents) |
3879 | (funcall use-auto-fill-function))))) | |
fd5359c6 MR |
3880 | ;;;_ > allout-reindent-body (old-depth new-depth &optional number) |
3881 | (defun allout-reindent-body (old-depth new-depth &optional number) | |
e126900f | 3882 | "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH. |
c567ac01 RS |
3883 | |
3884 | Optional arg NUMBER indicates numbering is being added, and it must | |
a0776d6b | 3885 | be accommodated. |
c567ac01 RS |
3886 | |
3887 | Note that refill of indented paragraphs is not done." | |
1977b8f6 RS |
3888 | |
3889 | (save-excursion | |
fd5359c6 | 3890 | (allout-end-of-prefix) |
c567ac01 RS |
3891 | (let* ((new-margin (current-column)) |
3892 | excess old-indent-begin old-indent-end | |
c567ac01 RS |
3893 | ;; We want the column where the header-prefix text started |
3894 | ;; *before* the prefix was changed, so we infer it relative | |
3895 | ;; to the new margin and the shift in depth: | |
3896 | (old-margin (+ old-depth (- new-margin new-depth)))) | |
353e2ef2 | 3897 | |
c567ac01 | 3898 | ;; Process lines up to (but excluding) next topic header: |
fd5359c6 | 3899 | (allout-unprotected |
c567ac01 RS |
3900 | (save-match-data |
3901 | (while | |
96b83743 | 3902 | (and (re-search-forward "\n\\(\\s-*\\)" |
c567ac01 RS |
3903 | nil |
3904 | t) | |
3905 | ;; Register the indent data, before we reset the | |
353e2ef2 | 3906 | ;; match data with a subsequent `looking-at': |
c567ac01 RS |
3907 | (setq old-indent-begin (match-beginning 1) |
3908 | old-indent-end (match-end 1)) | |
fd5359c6 | 3909 | (not (looking-at allout-regexp))) |
d82979ea EZ |
3910 | (if (> 0 (setq excess (- (- old-indent-end old-indent-begin) |
3911 | old-margin))) | |
60c7bbd2 | 3912 | ;; Text starts left of old margin -- don't adjust: |
c567ac01 | 3913 | nil |
ea18b2b1 | 3914 | ;; Text was hanging at or right of old left margin -- |
c567ac01 RS |
3915 | ;; reindent it, preserving its existing indentation |
3916 | ;; beyond the old margin: | |
3917 | (delete-region old-indent-begin old-indent-end) | |
d82979ea | 3918 | (indent-to (+ new-margin excess (current-column)))))))))) |
fd5359c6 MR |
3919 | ;;;_ > allout-rebullet-current-heading (arg) |
3920 | (defun allout-rebullet-current-heading (arg) | |
9179616f DL |
3921 | "Solicit new bullet for current visible heading." |
3922 | (interactive "p") | |
3923 | (let ((initial-col (current-column)) | |
fd5359c6 | 3924 | (on-bullet (eq (point)(allout-current-bullet-pos))) |
d8350998 | 3925 | from to |
9179616f DL |
3926 | (backwards (if (< arg 0) |
3927 | (setq arg (* arg -1))))) | |
3928 | (while (> arg 0) | |
fd5359c6 MR |
3929 | (save-excursion (allout-back-to-current-heading) |
3930 | (allout-end-of-prefix) | |
d8350998 CY |
3931 | (setq from allout-recent-prefix-beginning |
3932 | to allout-recent-prefix-end) | |
b6a5875b | 3933 | (allout-rebullet-heading t ;;; instead |
9179616f DL |
3934 | nil ;;; depth |
3935 | nil ;;; number-control | |
3936 | nil ;;; index | |
d8350998 CY |
3937 | t) ;;; do-successors |
3938 | (run-hook-with-args 'allout-exposure-change-hook | |
3939 | from to t)) | |
9179616f DL |
3940 | (setq arg (1- arg)) |
3941 | (if (<= arg 0) | |
3942 | nil | |
3943 | (setq initial-col nil) ; Override positioning back to init col | |
3944 | (if (not backwards) | |
fd5359c6 | 3945 | (allout-next-visible-heading 1) |
d8350998 | 3946 | (allout-goto-prefix-doublechecked) |
fd5359c6 | 3947 | (allout-next-visible-heading -1)))) |
9179616f | 3948 | (message "Done.") |
fd5359c6 | 3949 | (cond (on-bullet (goto-char (allout-current-bullet-pos))) |
9179616f | 3950 | (initial-col (move-to-column initial-col))))) |
b6a5875b KM |
3951 | ;;;_ > allout-rebullet-heading (&optional instead ...) |
3952 | (defun allout-rebullet-heading (&optional instead | |
1977b8f6 RS |
3953 | new-depth |
3954 | number-control | |
3955 | index | |
3956 | do-successors) | |
3957 | ||
c567ac01 | 3958 | "Adjust bullet of current topic prefix. |
1977b8f6 | 3959 | |
d82979ea EZ |
3960 | All args are optional. |
3961 | ||
b6a5875b KM |
3962 | If INSTEAD is: |
3963 | - nil, then the bullet char for the context is used, per distinction or depth | |
2dab465b KM |
3964 | - a \(numeric) character, then character's string representation is used |
3965 | - a string, then the user is asked for bullet with the first char as default | |
b6a5875b | 3966 | - anything else, the user is solicited with bullet char per context as default |
1977b8f6 | 3967 | |
d82979ea | 3968 | Second arg DEPTH forces the topic prefix to that depth, regardless |
9179616f | 3969 | of the topic's current depth. |
1977b8f6 | 3970 | |
c567ac01 | 3971 | Third arg NUMBER-CONTROL can force the prefix to or away from |
fd5359c6 | 3972 | numbered form. It has effect only if `allout-numbered-bullet' is |
c567ac01 RS |
3973 | non-nil and soliciting was not explicitly invoked (via first arg). |
3974 | Its effect, numbering or denumbering, then depends on the setting | |
75bcb912 | 3975 | of the fourth arg, INDEX. |
1977b8f6 | 3976 | |
75bcb912 | 3977 | If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the |
c567ac01 RS |
3978 | prefix of the topic is forced to be non-numbered. Null index and |
3979 | non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and | |
3980 | non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil | |
3981 | INDEX is a number, then that number is used for the numbered | |
3982 | prefix. Non-nil and non-number means that the index for the | |
d82979ea | 3983 | numbered prefix will be derived by allout-make-topic-prefix. |
1977b8f6 | 3984 | |
c567ac01 RS |
3985 | Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding |
3986 | siblings. | |
1977b8f6 | 3987 | |
fd5359c6 MR |
3988 | Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes', |
3989 | and `allout-numbered-bullet', which all affect the behavior of | |
c567ac01 | 3990 | this function." |
1977b8f6 | 3991 | |
fd5359c6 | 3992 | (let* ((current-depth (allout-depth)) |
1977b8f6 | 3993 | (new-depth (or new-depth current-depth)) |
fd5359c6 MR |
3994 | (mb allout-recent-prefix-beginning) |
3995 | (me allout-recent-prefix-end) | |
d8350998 | 3996 | (current-bullet (buffer-substring-no-properties (- me 1) me)) |
ede4ac6a | 3997 | (has-annotation (get-text-property mb 'allout-was-hidden)) |
fd5359c6 | 3998 | (new-prefix (allout-make-topic-prefix current-bullet |
1977b8f6 RS |
3999 | nil |
4000 | new-depth | |
b6a5875b | 4001 | instead |
1977b8f6 RS |
4002 | number-control |
4003 | index))) | |
4004 | ||
c567ac01 | 4005 | ;; Is new one is identical to old? |
1977b8f6 RS |
4006 | (if (and (= current-depth new-depth) |
4007 | (string= current-bullet | |
4008 | (substring new-prefix (1- (length new-prefix))))) | |
c567ac01 | 4009 | ;; Nothing to do: |
1977b8f6 RS |
4010 | t |
4011 | ||
4012 | ;; New prefix probably different from old: | |
c567ac01 | 4013 | ; get rid of old one: |
fd5359c6 | 4014 | (allout-unprotected (delete-region mb me)) |
1977b8f6 | 4015 | (goto-char mb) |
c567ac01 RS |
4016 | ; Dispense with number if |
4017 | ; numbered-bullet prefix: | |
2a1408fd DN |
4018 | (save-match-data |
4019 | (if (and allout-numbered-bullet | |
4020 | (string= allout-numbered-bullet current-bullet) | |
4021 | (looking-at "[0-9]+")) | |
4022 | (allout-unprotected | |
4023 | (delete-region (match-beginning 0)(match-end 0))))) | |
1977b8f6 | 4024 | |
ede4ac6a KS |
4025 | ;; convey 'allout-was-hidden annotation, if original had it: |
4026 | (if has-annotation | |
4027 | (put-text-property 0 (length new-prefix) 'allout-was-hidden t | |
4028 | new-prefix)) | |
4029 | ||
c567ac01 | 4030 | ; Put in new prefix: |
fd5359c6 | 4031 | (allout-unprotected (insert new-prefix)) |
1977b8f6 | 4032 | |
d82979ea | 4033 | ;; Reindent the body if elected, margin changed, and not encrypted body: |
fd5359c6 | 4034 | (if (and allout-reindent-bodies |
d82979ea EZ |
4035 | (not (= new-depth current-depth)) |
4036 | (not (allout-encrypted-topic-p))) | |
fd5359c6 | 4037 | (allout-reindent-body current-depth new-depth)) |
1977b8f6 | 4038 | |
e47ca23b KM |
4039 | (run-hook-with-args 'allout-exposure-change-hook mb me nil) |
4040 | ||
c567ac01 RS |
4041 | ;; Recursively rectify successive siblings of orig topic if |
4042 | ;; caller elected for it: | |
4043 | (if do-successors | |
4044 | (save-excursion | |
fd5359c6 | 4045 | (while (allout-next-sibling new-depth nil) |
c567ac01 RS |
4046 | (setq index |
4047 | (cond ((numberp index) (1+ index)) | |
fd5359c6 MR |
4048 | ((not number-control) (allout-sibling-index)))) |
4049 | (if (allout-numbered-type-prefix) | |
b6a5875b | 4050 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4051 | new-depth ;;; new-depth |
4052 | number-control;;; number-control | |
4053 | index ;;; index | |
4054 | nil))))) ;;;(dont!)do-successors | |
4055 | ) ; (if (and (= current-depth new-depth)...)) | |
fd5359c6 | 4056 | ) ; let* ((current-depth (allout-depth))...) |
c567ac01 | 4057 | ) ; defun |
fd5359c6 | 4058 | ;;;_ > allout-rebullet-topic (arg) |
d8350998 | 4059 | (defun allout-rebullet-topic (arg &optional sans-offspring) |
d82979ea | 4060 | "Rebullet the visible topic containing point and all contained subtopics. |
19b84ba3 | 4061 | |
c567ac01 | 4062 | Descends into invisible as well as visible topics, however. |
1977b8f6 | 4063 | |
75bcb912 | 4064 | When optional SANS-OFFSPRING is non-nil, subtopics are not |
c07583cd | 4065 | shifted. (Shifting a topic outwards without shifting its |
d8350998 CY |
4066 | offspring is disallowed, since this would create a \"containment |
4067 | discontinuity\", where the depth difference between a topic and | |
4068 | its immediate offspring is greater than one.) | |
4069 | ||
c567ac01 | 4070 | With repeat count, shift topic depth by that amount." |
1977b8f6 | 4071 | (interactive "P") |
96b83743 | 4072 | (let ((start-col (current-column))) |
1977b8f6 RS |
4073 | (save-excursion |
4074 | ;; Normalize arg: | |
4075 | (cond ((null arg) (setq arg 0)) | |
4076 | ((listp arg) (setq arg (car arg)))) | |
4077 | ;; Fill the user in, in case we're shifting a big topic: | |
4078 | (if (not (zerop arg)) (message "Shifting...")) | |
fd5359c6 | 4079 | (allout-back-to-current-heading) |
d8350998 | 4080 | (if (<= (+ allout-recent-depth arg) 0) |
1977b8f6 | 4081 | (error "Attempt to shift topic below level 1")) |
d8350998 | 4082 | (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring) |
1977b8f6 | 4083 | (if (not (zerop arg)) (message "Shifting... done."))) |
c567ac01 | 4084 | (move-to-column (max 0 (+ start-col arg))))) |
d8350998 | 4085 | ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...) |
fd5359c6 | 4086 | (defun allout-rebullet-topic-grunt (&optional relative-depth |
1977b8f6 RS |
4087 | starting-depth |
4088 | starting-point | |
4089 | index | |
d8350998 CY |
4090 | do-successors |
4091 | sans-offspring) | |
d82979ea EZ |
4092 | "Like `allout-rebullet-topic', but on nearest containing topic |
4093 | \(visible or not). | |
1977b8f6 | 4094 | |
d82979ea | 4095 | See `allout-rebullet-heading' for rebulleting behavior. |
1977b8f6 | 4096 | |
d82979ea | 4097 | All arguments are optional. |
1977b8f6 | 4098 | |
d82979ea EZ |
4099 | First arg RELATIVE-DEPTH means to shift the depth of the entire |
4100 | topic that amount. | |
e126900f | 4101 | |
d8350998 CY |
4102 | Several subsequent args are for internal recursive use by the function |
4103 | itself: STARTING-DEPTH, STARTING-POINT, and INDEX. | |
4104 | ||
4105 | Finally, if optional SANS-OFFSPRING is non-nil then the offspring | |
c07583cd | 4106 | are not shifted. (Shifting a topic outwards without shifting |
d8350998 CY |
4107 | its offspring is disallowed, since this would create a |
4108 | \"containment discontinuity\", where the depth difference between | |
75bcb912 | 4109 | a topic and its immediate offspring is greater than one.)" |
d8350998 CY |
4110 | |
4111 | ;; XXX the recursion here is peculiar, and in general the routine may | |
4112 | ;; need simplification with refactoring. | |
4113 | ||
4114 | (if (and sans-offspring | |
4115 | relative-depth | |
4116 | (< relative-depth 0)) | |
4117 | (error (concat "Attempt to shift topic outwards without offspring," | |
4118 | " would cause containment discontinuity."))) | |
1977b8f6 RS |
4119 | |
4120 | (let* ((relative-depth (or relative-depth 0)) | |
fd5359c6 | 4121 | (new-depth (allout-depth)) |
1977b8f6 RS |
4122 | (starting-depth (or starting-depth new-depth)) |
4123 | (on-starting-call (null starting-point)) | |
4124 | (index (or index | |
4125 | ;; Leave index null on starting call, so rebullet-heading | |
4126 | ;; calculates it at what might be new depth: | |
4127 | (and (or (zerop relative-depth) | |
4128 | (not on-starting-call)) | |
fd5359c6 | 4129 | (allout-sibling-index)))) |
d8350998 | 4130 | (starting-index index) |
1977b8f6 | 4131 | (moving-outwards (< 0 relative-depth)) |
d8350998 CY |
4132 | (starting-point (or starting-point (point))) |
4133 | (local-point (point))) | |
1977b8f6 RS |
4134 | |
4135 | ;; Sanity check for excessive promotion done only on starting call: | |
4136 | (and on-starting-call | |
4137 | moving-outwards | |
4138 | (> 0 (+ starting-depth relative-depth)) | |
d8350998 | 4139 | (error "Attempt to shift topic out beyond level 1")) |
1977b8f6 RS |
4140 | |
4141 | (cond ((= starting-depth new-depth) | |
d8350998 CY |
4142 | ;; We're at depth to work on this one. |
4143 | ||
4144 | ;; When shifting out we work on the children before working on | |
4145 | ;; the parent to avoid interim `allout-aberrant-container-p' | |
4146 | ;; aberrancy, and vice-versa when shifting in: | |
4147 | (if (>= relative-depth 0) | |
4148 | (allout-rebullet-heading nil | |
4149 | (+ starting-depth relative-depth) | |
4150 | nil ;;; number | |
4151 | index | |
4152 | nil)) ;;; do-successors | |
4153 | (when (not sans-offspring) | |
4154 | ;; ... and work on subsequent ones which are at greater depth: | |
4155 | (setq index 0) | |
4156 | (allout-next-heading) | |
4157 | (while (and (not (eobp)) | |
4158 | (< starting-depth (allout-depth))) | |
4159 | (setq index (1+ index)) | |
4160 | (allout-rebullet-topic-grunt relative-depth | |
4161 | (1+ starting-depth) | |
4162 | starting-point | |
4163 | index))) | |
4164 | (when (< relative-depth 0) | |
4165 | (save-excursion | |
4166 | (goto-char local-point) | |
b6a5875b | 4167 | (allout-rebullet-heading nil ;;; instead |
d8350998 CY |
4168 | (+ starting-depth relative-depth) |
4169 | nil ;;; number | |
4170 | starting-index | |
4171 | nil)))) ;;; do-successors | |
1977b8f6 RS |
4172 | |
4173 | ((< starting-depth new-depth) | |
60c7bbd2 | 4174 | ;; Rare case -- subtopic more than one level deeper than parent. |
1977b8f6 | 4175 | ;; Treat this one at an even deeper level: |
d8350998 CY |
4176 | (allout-rebullet-topic-grunt relative-depth |
4177 | new-depth | |
4178 | starting-point | |
4179 | index | |
4180 | sans-offspring))) | |
1977b8f6 RS |
4181 | |
4182 | (if on-starting-call | |
4183 | (progn | |
4184 | ;; Rectify numbering of former siblings of the adjusted topic, | |
4185 | ;; if topic has changed depth | |
4186 | (if (or do-successors | |
4187 | (and (not (zerop relative-depth)) | |
d8350998 CY |
4188 | (or (= allout-recent-depth starting-depth) |
4189 | (= allout-recent-depth (+ starting-depth | |
1977b8f6 | 4190 | relative-depth))))) |
fd5359c6 | 4191 | (allout-rebullet-heading nil nil nil nil t)) |
1977b8f6 RS |
4192 | ;; Now rectify numbering of new siblings of the adjusted topic, |
4193 | ;; if depth has been changed: | |
4194 | (progn (goto-char starting-point) | |
4195 | (if (not (zerop relative-depth)) | |
fd5359c6 | 4196 | (allout-rebullet-heading nil nil nil nil t))))) |
1977b8f6 RS |
4197 | ) |
4198 | ) | |
fd5359c6 MR |
4199 | ;;;_ > allout-renumber-to-depth (&optional depth) |
4200 | (defun allout-renumber-to-depth (&optional depth) | |
19b84ba3 RS |
4201 | "Renumber siblings at current depth. |
4202 | ||
4203 | Affects superior topics if optional arg DEPTH is less than current depth. | |
c567ac01 RS |
4204 | |
4205 | Returns final depth." | |
4206 | ||
4207 | ;; Proceed by level, processing subsequent siblings on each, | |
4208 | ;; ascending until we get shallower than the start depth: | |
4209 | ||
fd5359c6 | 4210 | (let ((ascender (allout-depth)) |
9179616f | 4211 | was-eobp) |
c567ac01 | 4212 | (while (and (not (eobp)) |
fd5359c6 | 4213 | (allout-depth) |
d8350998 | 4214 | (>= allout-recent-depth depth) |
c567ac01 RS |
4215 | (>= ascender depth)) |
4216 | ; Skip over all topics at | |
4217 | ; lesser depths, which can not | |
4218 | ; have been disturbed: | |
9179616f | 4219 | (while (and (not (setq was-eobp (eobp))) |
d8350998 | 4220 | (> allout-recent-depth ascender)) |
fd5359c6 | 4221 | (allout-next-heading)) |
c567ac01 | 4222 | ; Prime ascender for ascension: |
d8350998 CY |
4223 | (setq ascender (1- allout-recent-depth)) |
4224 | (if (>= allout-recent-depth depth) | |
b6a5875b | 4225 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4226 | nil ;;; depth |
4227 | nil ;;; number-control | |
4228 | nil ;;; index | |
9179616f DL |
4229 | t)) ;;; do-successors |
4230 | (if was-eobp (goto-char (point-max))))) | |
d8350998 | 4231 | allout-recent-depth) |
fd5359c6 MR |
4232 | ;;;_ > allout-number-siblings (&optional denumber) |
4233 | (defun allout-number-siblings (&optional denumber) | |
c567ac01 | 4234 | "Assign numbered topic prefix to this topic and its siblings. |
1977b8f6 | 4235 | |
60c7bbd2 | 4236 | With universal argument, denumber -- assign default bullet to this |
c567ac01 | 4237 | topic and its siblings. |
1977b8f6 | 4238 | |
c567ac01 RS |
4239 | With repeated universal argument (`^U^U'), solicit bullet for each |
4240 | rebulleting each topic at this level." | |
1977b8f6 RS |
4241 | |
4242 | (interactive "P") | |
4243 | ||
4244 | (save-excursion | |
fd5359c6 MR |
4245 | (allout-back-to-current-heading) |
4246 | (allout-beginning-of-level) | |
d8350998 | 4247 | (let ((depth allout-recent-depth) |
c567ac01 | 4248 | (index (if (not denumber) 1)) |
1977b8f6 RS |
4249 | (use-bullet (equal '(16) denumber)) |
4250 | (more t)) | |
4251 | (while more | |
b6a5875b | 4252 | (allout-rebullet-heading use-bullet ;;; instead |
c567ac01 | 4253 | depth ;;; depth |
1977b8f6 RS |
4254 | t ;;; number-control |
4255 | index ;;; index | |
4256 | nil) ;;; do-successors | |
4257 | (if index (setq index (1+ index))) | |
fd5359c6 MR |
4258 | (setq more (allout-next-sibling depth nil)))))) |
4259 | ;;;_ > allout-shift-in (arg) | |
4260 | (defun allout-shift-in (arg) | |
d8350998 CY |
4261 | "Increase depth of current heading and any items collapsed within it. |
4262 | ||
4263 | With a negative argument, the item is shifted out using | |
4264 | `allout-shift-out', instead. | |
4265 | ||
4266 | With an argument greater than one, shift-in the item but not its | |
4267 | offspring, making the item into a sibling of its former children, | |
97610156 | 4268 | and a child of sibling that formerly preceded it. |
d8350998 CY |
4269 | |
4270 | You are not allowed to shift the first offspring of a topic | |
4271 | inwards, because that would yield a \"containment | |
4272 | discontinuity\", where the depth difference between a topic and | |
4273 | its immediate offspring is greater than one. The first topic in | |
4274 | the file can be adjusted to any positive depth, however." | |
d82979ea | 4275 | |
1977b8f6 | 4276 | (interactive "p") |
d8350998 CY |
4277 | (if (< arg 0) |
4278 | (allout-shift-out (* arg -1)) | |
4279 | ;; refuse to create a containment discontinuity: | |
4280 | (save-excursion | |
4281 | (allout-back-to-current-heading) | |
4282 | (if (not (bobp)) | |
4283 | (let* ((current-depth allout-recent-depth) | |
4284 | (start-point (point)) | |
4285 | (predecessor-depth (progn | |
4286 | (forward-char -1) | |
4287 | (allout-goto-prefix-doublechecked) | |
4288 | (if (< (point) start-point) | |
4289 | allout-recent-depth | |
4290 | 0)))) | |
4291 | (if (and (> predecessor-depth 0) | |
4292 | (> (1+ current-depth) | |
4293 | (1+ predecessor-depth))) | |
4294 | (error (concat "Disallowed shift deeper than" | |
498a6493 CY |
4295 | " containing topic's children.")) |
4296 | (allout-back-to-current-heading) | |
4297 | (if (< allout-recent-depth (1+ current-depth)) | |
4298 | (allout-show-children)))))) | |
d8350998 CY |
4299 | (let ((where (point))) |
4300 | (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring)) | |
4301 | (run-hook-with-args 'allout-structure-shifted-hook arg where)))) | |
fd5359c6 MR |
4302 | ;;;_ > allout-shift-out (arg) |
4303 | (defun allout-shift-out (arg) | |
d82979ea | 4304 | "Decrease depth of current heading and any topics collapsed within it. |
d8350998 CY |
4305 | This will make the item a sibling of its former container. |
4306 | ||
4307 | With a negative argument, the item is shifted in using | |
4308 | `allout-shift-in', instead. | |
4309 | ||
4310 | With an argument greater than one, shift-out the item's offspring | |
4311 | but not the item itself, making the former children siblings of | |
4312 | the item. | |
d82979ea | 4313 | |
d8350998 CY |
4314 | With an argument greater than 1, the item's offspring are shifted |
4315 | out without shifting the item. This will make the immediate | |
4316 | subtopics into siblings of the item." | |
1977b8f6 | 4317 | (interactive "p") |
d8350998 CY |
4318 | (if (< arg 0) |
4319 | (allout-shift-in (* arg -1)) | |
4320 | ;; Get proper exposure in this area: | |
4321 | (save-excursion (if (allout-ascend) | |
4322 | (allout-show-children))) | |
4323 | ;; Show collapsed children if there's a successor which will become | |
4324 | ;; their sibling: | |
4325 | (if (and (allout-current-topic-collapsed-p) | |
4326 | (save-excursion (allout-next-sibling))) | |
4327 | (allout-show-children)) | |
4328 | (let ((where (and (allout-depth) allout-recent-prefix-beginning))) | |
4329 | (save-excursion | |
4330 | (if (> arg 1) | |
4331 | ;; Shift the offspring but not the topic: | |
4332 | (let ((children-chart (allout-chart-subtree 1))) | |
4333 | (if (listp (car children-chart)) | |
4334 | ;; whoops: | |
4335 | (setq children-chart (allout-flatten children-chart))) | |
4336 | (save-excursion | |
4337 | (dolist (child-point children-chart) | |
4338 | (goto-char child-point) | |
4339 | (allout-shift-out 1)))) | |
4340 | (allout-rebullet-topic (* arg -1)))) | |
4341 | (run-hook-with-args 'allout-structure-shifted-hook (* arg -1) where)))) | |
c567ac01 | 4342 | ;;;_ : Surgery (kill-ring) functions with special provisions for outlines: |
fd5359c6 MR |
4343 | ;;;_ > allout-kill-line (&optional arg) |
4344 | (defun allout-kill-line (&optional arg) | |
c567ac01 | 4345 | "Kill line, adjusting subsequent lines suitably for outline mode." |
1977b8f6 RS |
4346 | |
4347 | (interactive "*P") | |
d82979ea | 4348 | |
96b83743 EZ |
4349 | (if (or (not (allout-mode-p)) |
4350 | (not (bolp)) | |
2a1408fd | 4351 | (not (save-match-data (looking-at allout-regexp)))) |
4034b0e2 | 4352 | ;; Just do a regular kill: |
96b83743 EZ |
4353 | (kill-line arg) |
4354 | ;; Ah, have to watch out for adjustments: | |
4355 | (let* ((beg (point)) | |
d8350998 | 4356 | end |
96b83743 EZ |
4357 | (beg-hidden (allout-hidden-p)) |
4358 | (end-hidden (save-excursion (allout-end-of-current-line) | |
d8350998 | 4359 | (setq end (point)) |
96b83743 | 4360 | (allout-hidden-p))) |
d8350998 | 4361 | (depth (allout-depth))) |
96b83743 | 4362 | |
d8350998 | 4363 | (allout-annotate-hidden beg end) |
4ec28e14 KM |
4364 | (unwind-protect |
4365 | (if (and (not beg-hidden) (not end-hidden)) | |
4366 | (allout-unprotected (kill-line arg)) | |
4367 | (kill-line arg)) | |
11c46e15 | 4368 | (run-hooks 'allout-after-copy-or-kill-hook) |
4ec28e14 KM |
4369 | (allout-deannotate-hidden beg end) |
4370 | ||
4371 | (if allout-numbered-bullet | |
4372 | (save-excursion ; Renumber subsequent topics if needed: | |
4373 | (if (not (save-match-data (looking-at allout-regexp))) | |
4374 | (allout-next-heading)) | |
4375 | (allout-renumber-to-depth depth))) | |
4376 | (run-hook-with-args 'allout-structure-deleted-hook depth (point)))))) | |
1b4d97b2 CY |
4377 | ;;;_ > allout-copy-line-as-kill () |
4378 | (defun allout-copy-line-as-kill () | |
4379 | "Like allout-kill-topic, but save to kill ring instead of deleting." | |
4380 | (interactive) | |
4381 | (let ((buffer-read-only t)) | |
4382 | (condition-case nil | |
4383 | (allout-kill-line) | |
4384 | (buffer-read-only nil)))) | |
fd5359c6 MR |
4385 | ;;;_ > allout-kill-topic () |
4386 | (defun allout-kill-topic () | |
c567ac01 RS |
4387 | "Kill topic together with subtopics. |
4388 | ||
96b83743 EZ |
4389 | Trailing whitespace is killed with a topic if that whitespace: |
4390 | ||
4391 | - would separate the topic from a subsequent sibling | |
4392 | - would separate the topic from the end of buffer | |
4393 | - would not be added to whitespace already separating the topic from the | |
4394 | previous one. | |
4395 | ||
d8350998 | 4396 | Topic exposure is marked with text-properties, to be used by |
75bcb912 | 4397 | `allout-yank-processing' for exposure recovery." |
1977b8f6 RS |
4398 | |
4399 | (interactive) | |
0458fa80 | 4400 | (let* ((inhibit-field-text-motion t) |
96b83743 | 4401 | (beg (prog1 (allout-back-to-current-heading) (beginning-of-line))) |
ede4ac6a | 4402 | end |
d8350998 | 4403 | (depth allout-recent-depth)) |
fd5359c6 | 4404 | (allout-end-of-current-subtree) |
96b83743 EZ |
4405 | (if (and (/= (current-column) 0) (not (eobp))) |
4406 | (forward-char 1)) | |
1977b8f6 | 4407 | (if (not (eobp)) |
2a1408fd | 4408 | (if (and (save-match-data (looking-at "\n")) |
96b83743 EZ |
4409 | (or (save-excursion |
4410 | (or (not (allout-next-heading)) | |
d8350998 | 4411 | (= depth allout-recent-depth))) |
96b83743 EZ |
4412 | (and (> (- beg (point-min)) 3) |
4413 | (string= (buffer-substring (- beg 2) beg) "\n\n")))) | |
c567ac01 | 4414 | (forward-char 1))) |
353e2ef2 | 4415 | |
ede4ac6a | 4416 | (allout-annotate-hidden beg (setq end (point))) |
4ec28e14 | 4417 | (unwind-protect ; for possible barf-if-buffer-read-only. |
ede4ac6a | 4418 | (allout-unprotected (kill-region beg end)) |
4ec28e14 | 4419 | (allout-deannotate-hidden beg end) |
11c46e15 | 4420 | (run-hooks 'allout-after-copy-or-kill-hook) |
d8350998 | 4421 | |
4ec28e14 KM |
4422 | (save-excursion |
4423 | (allout-renumber-to-depth depth)) | |
4424 | (run-hook-with-args 'allout-structure-deleted-hook depth (point))))) | |
1b4d97b2 CY |
4425 | ;;;_ > allout-copy-topic-as-kill () |
4426 | (defun allout-copy-topic-as-kill () | |
75bcb912 | 4427 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4428 | (interactive) |
4429 | (let ((buffer-read-only t)) | |
4430 | (condition-case nil | |
4431 | (allout-kill-topic) | |
4432 | (buffer-read-only (message "Topic copied..."))))) | |
d8350998 CY |
4433 | ;;;_ > allout-annotate-hidden (begin end) |
4434 | (defun allout-annotate-hidden (begin end) | |
4435 | "Qualify text with properties to indicate exposure status." | |
4436 | ||
1b4d97b2 CY |
4437 | (let ((was-modified (buffer-modified-p)) |
4438 | (buffer-read-only nil)) | |
ede4ac6a | 4439 | (allout-deannotate-hidden begin end) |
d8350998 CY |
4440 | (save-excursion |
4441 | (goto-char begin) | |
4442 | (let (done next prev overlay) | |
4443 | (while (not done) | |
4444 | ;; at or advance to start of next hidden region: | |
4445 | (if (not (allout-hidden-p)) | |
4446 | (setq next | |
1b4d97b2 | 4447 | (max (1+ (point)) |
1c9b9df0 KM |
4448 | (allout-next-single-char-property-change (point) |
4449 | 'invisible | |
4450 | nil end)))) | |
d8350998 | 4451 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4452 | ;; still not at start of hidden area -- must not be any left. |
d8350998 CY |
4453 | (setq done t) |
4454 | (goto-char next) | |
4455 | (setq prev next) | |
4456 | (if (not (allout-hidden-p)) | |
4457 | ;; still not at start of hidden area. | |
4458 | (setq done t) | |
4459 | (setq overlay (allout-get-invisibility-overlay)) | |
4460 | (setq next (overlay-end overlay) | |
4461 | prev next) | |
4462 | ;; advance to end of this hidden area: | |
4463 | (when next | |
4464 | (goto-char next) | |
4465 | (allout-unprotected | |
ede4ac6a KS |
4466 | (let ((buffer-undo-list t)) |
4467 | (put-text-property (overlay-start overlay) next | |
4468 | 'allout-was-hidden t))))))))) | |
d8350998 | 4469 | (set-buffer-modified-p was-modified))) |
ede4ac6a KS |
4470 | ;;;_ > allout-deannotate-hidden (begin end) |
4471 | (defun allout-deannotate-hidden (begin end) | |
4472 | "Remove allout hidden-text annotation between BEGIN and END." | |
4473 | ||
4474 | (allout-unprotected | |
4475 | (let ((inhibit-read-only t) | |
4476 | (buffer-undo-list t)) | |
11c46e15 KM |
4477 | (remove-text-properties begin (min end (point-max)) |
4478 | '(allout-was-hidden t))))) | |
d8350998 CY |
4479 | ;;;_ > allout-hide-by-annotation (begin end) |
4480 | (defun allout-hide-by-annotation (begin end) | |
4481 | "Translate text properties indicating exposure status into actual exposure." | |
4482 | (save-excursion | |
4483 | (goto-char begin) | |
4484 | (let ((was-modified (buffer-modified-p)) | |
4485 | done next prev) | |
4486 | (while (not done) | |
4487 | ;; at or advance to start of next annotation: | |
4488 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
1c9b9df0 KM |
4489 | (setq next (allout-next-single-char-property-change |
4490 | (point) 'allout-was-hidden nil end))) | |
d8350998 | 4491 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4492 | ;; no more or not advancing -- must not be any left. |
d8350998 CY |
4493 | (setq done t) |
4494 | (goto-char next) | |
4495 | (setq prev next) | |
4496 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
4497 | ;; still not at start of annotation. | |
4498 | (setq done t) | |
4499 | ;; advance to just after end of this annotation: | |
1c9b9df0 KM |
4500 | (setq next (allout-next-single-char-property-change |
4501 | (point) 'allout-was-hidden nil end)) | |
d806ab68 KM |
4502 | (let ((o (make-overlay prev next nil 'front-advance))) |
4503 | (overlay-put o 'category 'allout-exposure-category) | |
4504 | (overlay-put o 'evaporate t)) | |
ede4ac6a | 4505 | (allout-deannotate-hidden prev next) |
d8350998 CY |
4506 | (setq prev next) |
4507 | (if next (goto-char next))))) | |
4508 | (set-buffer-modified-p was-modified)))) | |
fd5359c6 MR |
4509 | ;;;_ > allout-yank-processing () |
4510 | (defun allout-yank-processing (&optional arg) | |
c567ac01 | 4511 | |
96b83743 | 4512 | "Incidental allout-specific business to be done just after text yanks. |
19b84ba3 | 4513 | |
c567ac01 | 4514 | Does depth adjustment of yanked topics, when: |
1977b8f6 | 4515 | |
c567ac01 RS |
4516 | 1 the stuff being yanked starts with a valid outline header prefix, and |
4517 | 2 it is being yanked at the end of a line which consists of only a valid | |
1977b8f6 RS |
4518 | topic prefix. |
4519 | ||
a0776d6b | 4520 | Also, adjusts numbering of subsequent siblings when appropriate. |
1977b8f6 | 4521 | |
c567ac01 RS |
4522 | Depth adjustment alters the depth of all the topics being yanked |
4523 | the amount it takes to make the first topic have the depth of the | |
4524 | header into which it's being yanked. | |
1977b8f6 | 4525 | |
c567ac01 RS |
4526 | The point is left in front of yanked, adjusted topics, rather than |
4527 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
d82979ea | 4528 | however, are left exactly like normal, non-allout-specific yanks." |
c567ac01 RS |
4529 | |
4530 | (interactive "*P") | |
4531 | ; Get to beginning, leaving | |
4532 | ; region around subject: | |
96b83743 | 4533 | (if (< (allout-mark-marker t) (point)) |
c567ac01 | 4534 | (exchange-point-and-mark)) |
2a1408fd DN |
4535 | (save-match-data |
4536 | (let* ((subj-beg (point)) | |
4537 | (into-bol (bolp)) | |
4538 | (subj-end (allout-mark-marker t)) | |
4539 | ;; 'resituate' if yanking an entire topic into topic header: | |
4540 | (resituate (and (let ((allout-inhibit-aberrance-doublecheck t)) | |
4541 | (allout-e-o-prefix-p)) | |
4542 | (looking-at allout-regexp) | |
4543 | (allout-prefix-data))) | |
4544 | ;; `rectify-numbering' if resituating (where several topics may | |
4545 | ;; be resituating) or yanking a topic into a topic slot (bol): | |
4546 | (rectify-numbering (or resituate | |
8dd59f01 | 4547 | (and into-bol (looking-at allout-regexp))))) |
2a1408fd | 4548 | (if resituate |
8dd59f01 | 4549 | ;; Yanking a topic into the start of a topic -- reconcile to fit: |
2a1408fd DN |
4550 | (let* ((inhibit-field-text-motion t) |
4551 | (prefix-len (if (not (match-end 1)) | |
4552 | 1 | |
4553 | (- (match-end 1) subj-beg))) | |
4554 | (subj-depth allout-recent-depth) | |
4555 | (prefix-bullet (allout-recent-bullet)) | |
4556 | (adjust-to-depth | |
4557 | ;; Nil if adjustment unnecessary, otherwise depth to which | |
4558 | ;; adjustment should be made: | |
4559 | (save-excursion | |
4560 | (and (goto-char subj-end) | |
4561 | (eolp) | |
4562 | (goto-char subj-beg) | |
4563 | (and (looking-at allout-regexp) | |
4564 | (progn | |
4565 | (beginning-of-line) | |
4566 | (not (= (point) subj-beg))) | |
4567 | (looking-at allout-regexp) | |
4568 | (allout-prefix-data)) | |
4569 | allout-recent-depth))) | |
4570 | (more t)) | |
4571 | (setq rectify-numbering allout-numbered-bullet) | |
4572 | (if adjust-to-depth | |
c567ac01 | 4573 | ; Do the adjustment: |
2a1408fd DN |
4574 | (progn |
4575 | (save-restriction | |
4576 | (narrow-to-region subj-beg subj-end) | |
c567ac01 RS |
4577 | ; Trim off excessive blank |
4578 | ; line at end, if any: | |
2a1408fd DN |
4579 | (goto-char (point-max)) |
4580 | (if (looking-at "^$") | |
4581 | (allout-unprotected (delete-char -1))) | |
c567ac01 RS |
4582 | ; Work backwards, with each |
4583 | ; shallowest level, | |
4584 | ; successively excluding the | |
4585 | ; last processed topic from | |
4586 | ; the narrow region: | |
2a1408fd DN |
4587 | (while more |
4588 | (allout-back-to-current-heading) | |
c567ac01 | 4589 | ; go as high as we can in each bunch: |
2a1408fd DN |
4590 | (while (allout-ascend t)) |
4591 | (save-excursion | |
4592 | (allout-unprotected | |
4593 | (allout-rebullet-topic-grunt (- adjust-to-depth | |
4594 | subj-depth))) | |
4595 | (allout-depth)) | |
4596 | (if (setq more (not (bobp))) | |
4597 | (progn (widen) | |
4598 | (forward-char -1) | |
4599 | (narrow-to-region subj-beg (point)))))) | |
b6a5875b KM |
4600 | ;; Remove new heading prefix: |
4601 | (allout-unprotected | |
4602 | (progn | |
4603 | (delete-region (point) (+ (point) | |
4604 | prefix-len | |
4605 | (- adjust-to-depth | |
4606 | subj-depth))) | |
c567ac01 RS |
4607 | ; and delete residual subj |
4608 | ; prefix digits and space: | |
b6a5875b | 4609 | (while (looking-at "[0-9]") (delete-char 1)) |
e47ca23b KM |
4610 | (delete-char -1) |
4611 | (if (not (eolp)) | |
4612 | (forward-char)))) | |
b6a5875b | 4613 | ;; Assert new topic's bullet - minimal effort if unchanged: |
b0911414 | 4614 | (allout-rebullet-heading (string-to-char prefix-bullet))) |
2a1408fd DN |
4615 | (exchange-point-and-mark)))) |
4616 | (if rectify-numbering | |
4617 | (progn | |
4618 | (save-excursion | |
c567ac01 | 4619 | ; Give some preliminary feedback: |
2a1408fd | 4620 | (message "... reconciling numbers") |
c567ac01 | 4621 | ; ... and renumber, in case necessary: |
2a1408fd DN |
4622 | (goto-char subj-beg) |
4623 | (if (allout-goto-prefix-doublechecked) | |
4624 | (allout-unprotected | |
b6a5875b | 4625 | (allout-rebullet-heading nil ;;; instead |
2a1408fd DN |
4626 | (allout-depth) ;;; depth |
4627 | nil ;;; number-control | |
4628 | nil ;;; index | |
4629 | t))) | |
4630 | (message "")))) | |
4631 | (if (or into-bol resituate) | |
4632 | (allout-hide-by-annotation (point) (allout-mark-marker t)) | |
4633 | (allout-deannotate-hidden (allout-mark-marker t) (point))) | |
4634 | (if (not resituate) | |
4635 | (exchange-point-and-mark)) | |
4636 | (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end)))) | |
fd5359c6 MR |
4637 | ;;;_ > allout-yank (&optional arg) |
4638 | (defun allout-yank (&optional arg) | |
aad94676 | 4639 | "`allout-mode' yank, with depth and numbering adjustment of yanked topics. |
19b84ba3 | 4640 | |
a0776d6b | 4641 | Non-topic yanks work no differently than normal yanks. |
c567ac01 RS |
4642 | |
4643 | If a topic is being yanked into a bare topic prefix, the depth of the | |
4644 | yanked topic is adjusted to the depth of the topic prefix. | |
4645 | ||
2265e017 | 4646 | 1 we're yanking in an `allout-mode' buffer |
c567ac01 RS |
4647 | 2 the stuff being yanked starts with a valid outline header prefix, and |
4648 | 3 it is being yanked at the end of a line which consists of only a valid | |
4649 | topic prefix. | |
4650 | ||
4651 | If these conditions hold then the depth of the yanked topics are all | |
4652 | adjusted the amount it takes to make the first one at the depth of the | |
4653 | header into which it's being yanked. | |
4654 | ||
4655 | The point is left in front of yanked, adjusted topics, rather than | |
4656 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
4657 | however, (ones that don't qualify for adjustment) are handled | |
4658 | exactly like normal yanks. | |
4659 | ||
a0776d6b | 4660 | Numbering of yanked topics, and the successive siblings at the depth |
c567ac01 RS |
4661 | into which they're being yanked, is adjusted. |
4662 | ||
539d7736 JB |
4663 | `allout-yank-pop' works with `allout-yank' just like normal `yank-pop' |
4664 | works with normal `yank' in non-outline buffers." | |
1977b8f6 RS |
4665 | |
4666 | (interactive "*P") | |
4667 | (setq this-command 'yank) | |
48bd8440 EZ |
4668 | (allout-unprotected |
4669 | (yank arg)) | |
fd5359c6 | 4670 | (if (allout-mode-p) |
48bd8440 | 4671 | (allout-yank-processing))) |
fd5359c6 MR |
4672 | ;;;_ > allout-yank-pop (&optional arg) |
4673 | (defun allout-yank-pop (&optional arg) | |
2265e017 | 4674 | "Yank-pop like `allout-yank' when popping to bare outline prefixes. |
19b84ba3 RS |
4675 | |
4676 | Adapts level of popped topics to level of fresh prefix. | |
c567ac01 | 4677 | |
60c7bbd2 | 4678 | Note -- prefix changes to distinctive bullets will stick, if followed |
c567ac01 | 4679 | by pops to non-distinctive yanks. Bug..." |
1977b8f6 RS |
4680 | |
4681 | (interactive "*p") | |
1977b8f6 | 4682 | (setq this-command 'yank) |
c567ac01 | 4683 | (yank-pop arg) |
fd5359c6 MR |
4684 | (if (allout-mode-p) |
4685 | (allout-yank-processing))) | |
1977b8f6 | 4686 | |
c567ac01 RS |
4687 | ;;;_ - Specialty bullet functions |
4688 | ;;;_ : File Cross references | |
fd5359c6 MR |
4689 | ;;;_ > allout-resolve-xref () |
4690 | (defun allout-resolve-xref () | |
19b84ba3 RS |
4691 | "Pop to file associated with current heading, if it has an xref bullet. |
4692 | ||
fd5359c6 | 4693 | \(Works according to setting of `allout-file-xref-bullet')." |
1977b8f6 | 4694 | (interactive) |
fd5359c6 | 4695 | (if (not allout-file-xref-bullet) |
1977b8f6 | 4696 | (error |
60c7bbd2 | 4697 | "Outline cross references disabled -- no `allout-file-xref-bullet'") |
fd5359c6 | 4698 | (if (not (string= (allout-current-bullet) allout-file-xref-bullet)) |
635ca796 | 4699 | (error "Current heading lacks cross-reference bullet `%s'" |
fd5359c6 | 4700 | allout-file-xref-bullet) |
0458fa80 EZ |
4701 | (let ((inhibit-field-text-motion t) |
4702 | file-name) | |
2a1408fd DN |
4703 | (save-match-data |
4704 | (save-excursion | |
4705 | (let* ((text-start allout-recent-prefix-end) | |
9b026d9f | 4706 | (heading-end (point-at-eol))) |
2a1408fd DN |
4707 | (goto-char text-start) |
4708 | (setq file-name | |
4709 | (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t) | |
4710 | (buffer-substring (match-beginning 1) | |
4711 | (match-end 1))))))) | |
69027dea | 4712 | (setq file-name (expand-file-name file-name)) |
1977b8f6 RS |
4713 | (if (or (file-exists-p file-name) |
4714 | (if (file-writable-p file-name) | |
4715 | (y-or-n-p (format "%s not there, create one? " | |
4716 | file-name)) | |
4717 | (error "%s not found and can't be created" file-name))) | |
4718 | (condition-case failure | |
4719 | (find-file-other-window file-name) | |
d8350998 | 4720 | (error failure)) |
1977b8f6 RS |
4721 | (error "%s not found" file-name)) |
4722 | ) | |
4723 | ) | |
4724 | ) | |
4725 | ) | |
19b84ba3 | 4726 | |
9179616f | 4727 | ;;;_ #6 Exposure Control |
c567ac01 RS |
4728 | |
4729 | ;;;_ - Fundamental | |
d82979ea EZ |
4730 | ;;;_ > allout-flag-region (from to flag) |
4731 | (defun allout-flag-region (from to flag) | |
48bd8440 EZ |
4732 | "Conceal text between FROM and TO if FLAG is non-nil, else reveal it. |
4733 | ||
4734 | Exposure-change hook `allout-exposure-change-hook' is run with the same | |
1e004a83 | 4735 | arguments as this function, after the exposure changes are made." |
96b83743 | 4736 | |
96b83743 | 4737 | ;; We use outline invisibility spec. |
01fc9422 | 4738 | (remove-overlays from to 'category 'allout-exposure-category) |
96b83743 | 4739 | (when flag |
2a1408fd | 4740 | (let ((o (make-overlay from to nil 'front-advance))) |
01fc9422 | 4741 | (overlay-put o 'category 'allout-exposure-category) |
68ba37fb | 4742 | (overlay-put o 'evaporate t) |
96b83743 | 4743 | (when (featurep 'xemacs) |
01fc9422 | 4744 | (let ((props (symbol-plist 'allout-exposure-category))) |
96b83743 | 4745 | (while props |
1c9b9df0 KM |
4746 | (condition-case nil |
4747 | ;; as of 2008-02-27, xemacs lacks modification-hooks | |
4748 | (overlay-put o (pop props) (pop props)) | |
4749 | (error nil))))))) | |
48bd8440 | 4750 | (run-hook-with-args 'allout-exposure-change-hook from to flag)) |
fd5359c6 MR |
4751 | ;;;_ > allout-flag-current-subtree (flag) |
4752 | (defun allout-flag-current-subtree (flag) | |
96b83743 | 4753 | "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it." |
19b84ba3 | 4754 | |
c567ac01 | 4755 | (save-excursion |
fd5359c6 | 4756 | (allout-back-to-current-heading) |
0458fa80 EZ |
4757 | (let ((inhibit-field-text-motion t)) |
4758 | (end-of-line)) | |
96b83743 EZ |
4759 | (allout-flag-region (point) |
4760 | ;; Exposing must not leave trailing blanks hidden, | |
4761 | ;; but can leave them exposed when hiding, so we | |
4762 | ;; can use flag's inverse as the | |
4763 | ;; include-trailing-blank cue: | |
4764 | (allout-end-of-current-subtree (not flag)) | |
4765 | flag))) | |
c567ac01 | 4766 | |
c567ac01 | 4767 | ;;;_ - Topic-specific |
01fc9422 EZ |
4768 | ;;;_ > allout-show-entry () |
4769 | (defun allout-show-entry () | |
4770 | "Like `allout-show-current-entry', but reveals entries in hidden topics. | |
c567ac01 RS |
4771 | |
4772 | This is a way to give restricted peek at a concealed locality without the | |
4773 | expense of exposing its context, but can leave the outline with aberrant | |
96b83743 EZ |
4774 | exposure. `allout-show-offshoot' should be used after the peek to rectify |
4775 | the exposure." | |
c567ac01 RS |
4776 | |
4777 | (interactive) | |
4778 | (save-excursion | |
96b83743 | 4779 | (let (beg end) |
d8350998 | 4780 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4781 | (setq beg (if (allout-hidden-p) (1- (point)) (point))) |
4782 | (setq end (allout-pre-next-prefix)) | |
4783 | (allout-flag-region beg end nil) | |
9179616f | 4784 | (list beg end)))) |
fd5359c6 MR |
4785 | ;;;_ > allout-show-children (&optional level strict) |
4786 | (defun allout-show-children (&optional level strict) | |
c567ac01 RS |
4787 | |
4788 | "If point is visible, show all direct subheadings of this heading. | |
19b84ba3 | 4789 | |
2265e017 | 4790 | Otherwise, do `allout-show-to-offshoot', and then show subheadings. |
c567ac01 RS |
4791 | |
4792 | Optional LEVEL specifies how many levels below the current level | |
4793 | should be shown, or all levels if t. Default is 1. | |
4794 | ||
4795 | Optional STRICT means don't resort to -show-to-offshoot, no matter | |
4796 | what. This is basically so -show-to-offshoot, which is called by | |
4797 | this function, can employ the pure offspring-revealing capabilities of | |
19b84ba3 RS |
4798 | it. |
4799 | ||
4800 | Returns point at end of subtree that was opened, if any. (May get a | |
4801 | point of non-opened subtree?)" | |
c567ac01 RS |
4802 | |
4803 | (interactive "p") | |
96b83743 | 4804 | (let ((start-point (point))) |
19b84ba3 | 4805 | (if (and (not strict) |
96b83743 | 4806 | (allout-hidden-p)) |
c567ac01 | 4807 | |
96b83743 EZ |
4808 | (progn (allout-show-to-offshoot) ; Point's concealed, open to |
4809 | ; expose it. | |
4810 | ;; Then recurse, but with "strict" set so we don't | |
4811 | ;; infinite regress: | |
4812 | (allout-show-children level t)) | |
c567ac01 | 4813 | |
19b84ba3 | 4814 | (save-excursion |
96b83743 EZ |
4815 | (allout-beginning-of-current-line) |
4816 | (save-restriction | |
d8350998 | 4817 | (let* (depth |
65e7eb3d EZ |
4818 | ;; translate the level spec for this routine to the ones |
4819 | ;; used by -chart-subtree and -chart-to-reveal: | |
4820 | (chart-level (cond ((not level) 1) | |
4821 | ((eq level t) nil) | |
4822 | (t level))) | |
4823 | (chart (allout-chart-subtree chart-level)) | |
4824 | (to-reveal (or (allout-chart-to-reveal chart chart-level) | |
d8350998 CY |
4825 | ;; interactive, show discontinuous children: |
4826 | (and chart | |
1c9b9df0 | 4827 | (allout-called-interactively-p) |
d8350998 CY |
4828 | (save-excursion |
4829 | (allout-back-to-current-heading) | |
4830 | (setq depth (allout-current-depth)) | |
4831 | (and (allout-next-heading) | |
4832 | (> allout-recent-depth | |
4833 | (1+ depth)))) | |
4834 | (message | |
4835 | "Discontinuous offspring; use `%s %s'%s." | |
4836 | (substitute-command-keys | |
4837 | "\\[universal-argument]") | |
4838 | (substitute-command-keys | |
4839 | "\\[allout-shift-out]") | |
4840 | " to elevate them.") | |
4841 | (allout-chart-to-reveal | |
4842 | chart (- allout-recent-depth depth)))))) | |
96b83743 EZ |
4843 | (goto-char start-point) |
4844 | (when (and strict (allout-hidden-p)) | |
4845 | ;; Concealed root would already have been taken care of, | |
4846 | ;; unless strict was set. | |
4847 | (allout-flag-region (point) (allout-snug-back) nil) | |
4848 | (when allout-show-bodies | |
4849 | (goto-char (car to-reveal)) | |
4850 | (allout-show-current-entry))) | |
4851 | (while to-reveal | |
4852 | (goto-char (car to-reveal)) | |
4853 | (allout-flag-region (save-excursion (allout-snug-back) (point)) | |
4854 | (progn (search-forward "\n" nil t) | |
4855 | (1- (point))) | |
4856 | nil) | |
4857 | (when allout-show-bodies | |
4858 | (goto-char (car to-reveal)) | |
4859 | (allout-show-current-entry)) | |
4860 | (setq to-reveal (cdr to-reveal))))))) | |
4861 | ;; Compensate for `save-excursion's maintenance of point | |
4862 | ;; within invisible text: | |
4863 | (goto-char start-point))) | |
fd5359c6 MR |
4864 | ;;;_ > allout-show-to-offshoot () |
4865 | (defun allout-show-to-offshoot () | |
2265e017 | 4866 | "Like `allout-show-entry', but reveals all concealed ancestors, as well. |
c567ac01 | 4867 | |
96b83743 | 4868 | Useful for coherently exposing to a random point in a hidden region." |
c567ac01 RS |
4869 | (interactive) |
4870 | (save-excursion | |
0458fa80 EZ |
4871 | (let ((inhibit-field-text-motion t) |
4872 | (orig-pt (point)) | |
d8350998 | 4873 | (orig-pref (allout-goto-prefix-doublechecked)) |
c567ac01 | 4874 | (last-at (point)) |
65e7eb3d EZ |
4875 | (bag-it 0)) |
4876 | (while (or (> bag-it 1) (allout-hidden-p)) | |
96b83743 | 4877 | (while (allout-hidden-p) |
d8350998 | 4878 | (move-beginning-of-line 1) |
96b83743 | 4879 | (if (allout-hidden-p) (forward-char -1))) |
c567ac01 | 4880 | (if (= last-at (setq last-at (point))) |
65e7eb3d EZ |
4881 | ;; Oops, we're not making any progress! Show the current topic |
4882 | ;; completely, and try one more time here, if we haven't already. | |
c567ac01 | 4883 | (progn (beginning-of-line) |
fd5359c6 | 4884 | (allout-show-current-subtree) |
c567ac01 | 4885 | (goto-char orig-pt) |
65e7eb3d EZ |
4886 | (setq bag-it (1+ bag-it)) |
4887 | (if (> bag-it 1) | |
4888 | (error "allout-show-to-offshoot: %s" | |
4889 | "Stumped by aberrant nesting."))) | |
4890 | (if (> bag-it 0) (setq bag-it 0)) | |
d8350998 CY |
4891 | (allout-show-children) |
4892 | (goto-char orig-pref))) | |
19b84ba3 | 4893 | (goto-char orig-pt))) |
fd5359c6 MR |
4894 | (if (allout-hidden-p) |
4895 | (allout-show-entry))) | |
4896 | ;;;_ > allout-hide-current-entry () | |
4897 | (defun allout-hide-current-entry () | |
c567ac01 RS |
4898 | "Hide the body directly following this heading." |
4899 | (interactive) | |
fd5359c6 | 4900 | (allout-back-to-current-heading) |
c567ac01 | 4901 | (save-excursion |
0458fa80 EZ |
4902 | (let ((inhibit-field-text-motion t)) |
4903 | (end-of-line)) | |
96b83743 | 4904 | (allout-flag-region (point) |
d82979ea | 4905 | (progn (allout-end-of-entry) (point)) |
96b83743 | 4906 | t))) |
fd5359c6 MR |
4907 | ;;;_ > allout-show-current-entry (&optional arg) |
4908 | (defun allout-show-current-entry (&optional arg) | |
96b83743 | 4909 | "Show body following current heading, or hide entry with universal argument." |
c567ac01 RS |
4910 | |
4911 | (interactive "P") | |
4912 | (if arg | |
fd5359c6 | 4913 | (allout-hide-current-entry) |
96b83743 | 4914 | (save-excursion (allout-show-to-offshoot)) |
c567ac01 | 4915 | (save-excursion |
fd5359c6 | 4916 | (allout-flag-region (point) |
96b83743 EZ |
4917 | (progn (allout-end-of-entry t) (point)) |
4918 | nil) | |
d82979ea | 4919 | ))) |
fd5359c6 MR |
4920 | ;;;_ > allout-show-current-subtree (&optional arg) |
4921 | (defun allout-show-current-subtree (&optional arg) | |
75bcb912 JB |
4922 | "Show everything within the current topic. |
4923 | With a repeat-count, expose this topic and its siblings." | |
19b84ba3 RS |
4924 | (interactive "P") |
4925 | (save-excursion | |
fd5359c6 | 4926 | (if (<= (allout-current-depth) 0) |
60c7bbd2 | 4927 | ;; Outside any topics -- try to get to the first: |
fd5359c6 | 4928 | (if (not (allout-next-heading)) |
6a05d05f | 4929 | (error "No topics") |
60c7bbd2 RS |
4930 | ;; got to first, outermost topic -- set to expose it and siblings: |
4931 | (message "Above outermost topic -- exposing all.") | |
96b83743 EZ |
4932 | (allout-flag-region (point-min)(point-max) nil)) |
4933 | (allout-beginning-of-current-line) | |
19b84ba3 | 4934 | (if (not arg) |
96b83743 | 4935 | (allout-flag-current-subtree nil) |
fd5359c6 MR |
4936 | (allout-beginning-of-level) |
4937 | (allout-expose-topic '(* :)))))) | |
96b83743 EZ |
4938 | ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners) |
4939 | (defun allout-current-topic-collapsed-p (&optional include-single-liners) | |
4940 | "True if the currently visible containing topic is already collapsed. | |
4941 | ||
64686e6d RS |
4942 | Single line topics intrinsically can be considered as being both |
4943 | collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is | |
4944 | true, then single-line topics are considered to be collapsed. By | |
4945 | default, they are treated as being uncollapsed." | |
2a1408fd DN |
4946 | (save-match-data |
4947 | (save-excursion | |
4948 | (and | |
4949 | ;; Is the topic all on one line (allowing for trailing blank line)? | |
4950 | (>= (progn (allout-back-to-current-heading) | |
82b392a4 KM |
4951 | (let ((inhibit-field-text-motion t)) |
4952 | (move-end-of-line 1)) | |
2a1408fd DN |
4953 | (point)) |
4954 | (allout-end-of-current-subtree (not (looking-at "\n\n")))) | |
4955 | ||
4956 | (or include-single-liners | |
4957 | (progn (backward-char 1) (allout-hidden-p))))))) | |
fd5359c6 MR |
4958 | ;;;_ > allout-hide-current-subtree (&optional just-close) |
4959 | (defun allout-hide-current-subtree (&optional just-close) | |
19b84ba3 | 4960 | "Close the current topic, or containing topic if this one is already closed. |
c567ac01 | 4961 | |
19b84ba3 | 4962 | If this topic is closed and it's a top level topic, close this topic |
353e2ef2 | 4963 | and its siblings. |
19b84ba3 | 4964 | |
96b83743 | 4965 | If optional arg JUST-CLOSE is non-nil, do not close the parent or |
19b84ba3 | 4966 | siblings, even if the target topic is already closed." |
c567ac01 RS |
4967 | |
4968 | (interactive) | |
96b83743 | 4969 | (let* ((from (point)) |
60c7bbd2 | 4970 | (sibs-msg "Top-level topic already closed -- closing siblings...") |
96b83743 EZ |
4971 | (current-exposed (not (allout-current-topic-collapsed-p t)))) |
4972 | (cond (current-exposed (allout-flag-current-subtree t)) | |
4973 | (just-close nil) | |
d8350998 | 4974 | ((allout-ascend) (allout-hide-current-subtree)) |
96b83743 EZ |
4975 | (t (goto-char 0) |
4976 | (message sibs-msg) | |
d8350998 | 4977 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4978 | (allout-expose-topic '(0 :)) |
4979 | (message (concat sibs-msg " Done.")))) | |
4980 | (goto-char from))) | |
2a1408fd DN |
4981 | ;;;_ > allout-toggle-current-subtree-exposure |
4982 | (defun allout-toggle-current-subtree-exposure () | |
4983 | "Show or hide the current subtree depending on its current state." | |
4984 | ;; thanks to tassilo for suggesting this. | |
4985 | (interactive) | |
4986 | (save-excursion | |
4987 | (allout-back-to-heading) | |
4988 | (if (allout-hidden-p (point-at-eol)) | |
4989 | (allout-show-current-subtree) | |
4990 | (allout-hide-current-subtree)))) | |
fd5359c6 MR |
4991 | ;;;_ > allout-show-current-branches () |
4992 | (defun allout-show-current-branches () | |
c567ac01 RS |
4993 | "Show all subheadings of this heading, but not their bodies." |
4994 | (interactive) | |
0458fa80 EZ |
4995 | (let ((inhibit-field-text-motion t)) |
4996 | (beginning-of-line)) | |
fd5359c6 MR |
4997 | (allout-show-children t)) |
4998 | ;;;_ > allout-hide-current-leaves () | |
4999 | (defun allout-hide-current-leaves () | |
353e2ef2 | 5000 | "Hide the bodies of the current topic and all its offspring." |
c567ac01 | 5001 | (interactive) |
fd5359c6 MR |
5002 | (allout-back-to-current-heading) |
5003 | (allout-hide-region-body (point) (progn (allout-end-of-current-subtree) | |
c567ac01 RS |
5004 | (point)))) |
5005 | ||
5006 | ;;;_ - Region and beyond | |
fd5359c6 MR |
5007 | ;;;_ > allout-show-all () |
5008 | (defun allout-show-all () | |
c567ac01 RS |
5009 | "Show all of the text in the buffer." |
5010 | (interactive) | |
19b84ba3 | 5011 | (message "Exposing entire buffer...") |
96b83743 | 5012 | (allout-flag-region (point-min) (point-max) nil) |
19b84ba3 | 5013 | (message "Exposing entire buffer... Done.")) |
fd5359c6 MR |
5014 | ;;;_ > allout-hide-bodies () |
5015 | (defun allout-hide-bodies () | |
c567ac01 RS |
5016 | "Hide all of buffer except headings." |
5017 | (interactive) | |
fd5359c6 MR |
5018 | (allout-hide-region-body (point-min) (point-max))) |
5019 | ;;;_ > allout-hide-region-body (start end) | |
5020 | (defun allout-hide-region-body (start end) | |
c567ac01 | 5021 | "Hide all body lines in the region, but not headings." |
2a1408fd DN |
5022 | (save-match-data |
5023 | (save-excursion | |
5024 | (save-restriction | |
5025 | (narrow-to-region start end) | |
5026 | (goto-char (point-min)) | |
5027 | (let ((inhibit-field-text-motion t)) | |
5028 | (while (not (eobp)) | |
5029 | (end-of-line) | |
5030 | (allout-flag-region (point) (allout-end-of-entry) t) | |
5031 | (if (not (eobp)) | |
5032 | (forward-char | |
5033 | (if (looking-at "\n\n") | |
5034 | 2 1))))))))) | |
c567ac01 | 5035 | |
fd5359c6 MR |
5036 | ;;;_ > allout-expose-topic (spec) |
5037 | (defun allout-expose-topic (spec) | |
19b84ba3 | 5038 | "Apply exposure specs to successive outline topic items. |
c567ac01 | 5039 | |
fd5359c6 MR |
5040 | Use the more convenient frontend, `allout-new-exposure', if you don't |
5041 | need evaluation of the arguments, or even better, the `allout-layout' | |
19b84ba3 RS |
5042 | variable-keyed mode-activation/auto-exposure feature of allout outline |
5043 | mode. See the respective documentation strings for more details. | |
c567ac01 RS |
5044 | |
5045 | Cursor is left at start position. | |
5046 | ||
19b84ba3 RS |
5047 | SPEC is either a number or a list. |
5048 | ||
5049 | Successive specs on a list are applied to successive sibling topics. | |
c567ac01 | 5050 | |
c07583cd | 5051 | A simple spec (either a number, one of a few symbols, or the null |
19b84ba3 RS |
5052 | list) dictates the exposure for the corresponding topic. |
5053 | ||
5054 | Non-null lists recursively designate exposure specs for respective | |
5055 | subtopics of the current topic. | |
c567ac01 | 5056 | |
353e2ef2 | 5057 | The `:' repeat spec is used to specify exposure for any number of |
19b84ba3 | 5058 | successive siblings, up to the trailing ones for which there are |
353e2ef2 | 5059 | explicit specs following the `:'. |
c567ac01 RS |
5060 | |
5061 | Simple (numeric and null-list) specs are interpreted as follows: | |
5062 | ||
19b84ba3 RS |
5063 | Numbers indicate the relative depth to open the corresponding topic. |
5064 | - negative numbers force the topic to be closed before opening to the | |
5065 | absolute value of the number, so all siblings are open only to | |
5066 | that level. | |
5067 | - positive numbers open to the relative depth indicated by the | |
5068 | number, but do not force already opened subtopics to be closed. | |
60c7bbd2 | 5069 | - 0 means to close topic -- hide all offspring. |
353e2ef2 | 5070 | : - `repeat' |
c567ac01 | 5071 | apply prior element to all siblings at current level, *up to* |
353e2ef2 | 5072 | those siblings that would be covered by specs following the `:' |
c567ac01 | 5073 | on the list. Ie, apply to all topics at level but the last |
c07583cd | 5074 | ones. (Only first of multiple colons at same level is |
60c7bbd2 | 5075 | respected -- subsequent ones are discarded.) |
19b84ba3 RS |
5076 | * - completely opens the topic, including bodies. |
5077 | + - shows all the sub headers, but not the bodies | |
5078 | - - exposes the body of the corresponding topic. | |
c567ac01 RS |
5079 | |
5080 | Examples: | |
fd5359c6 | 5081 | \(allout-expose-topic '(-1 : 0)) |
c567ac01 RS |
5082 | Close this and all following topics at current level, exposing |
5083 | only their immediate children, but close down the last topic | |
5084 | at this current level completely. | |
fd5359c6 | 5085 | \(allout-expose-topic '(-1 () : 1 0)) |
c567ac01 RS |
5086 | Close current topic so only the immediate subtopics are shown; |
5087 | show the children in the second to last topic, and completely | |
5088 | close the last one. | |
fd5359c6 | 5089 | \(allout-expose-topic '(-2 : -1 *)) |
c567ac01 RS |
5090 | Expose children and grandchildren of all topics at current |
5091 | level except the last two; expose children of the second to | |
5092 | last and completely open the last one." | |
5093 | ||
5094 | (interactive "xExposure spec: ") | |
19b84ba3 RS |
5095 | (if (not (listp spec)) |
5096 | nil | |
fd5359c6 | 5097 | (let ((depth (allout-depth)) |
19b84ba3 RS |
5098 | (max-pos 0) |
5099 | prev-elem curr-elem | |
96b83743 | 5100 | stay) |
19b84ba3 RS |
5101 | (while spec |
5102 | (setq prev-elem curr-elem | |
5103 | curr-elem (car spec) | |
5104 | spec (cdr spec)) | |
5105 | (cond ; Do current element: | |
5106 | ((null curr-elem) nil) | |
5107 | ((symbolp curr-elem) | |
fd5359c6 MR |
5108 | (cond ((eq curr-elem '*) (allout-show-current-subtree) |
5109 | (if (> allout-recent-end-of-subtree max-pos) | |
5110 | (setq max-pos allout-recent-end-of-subtree))) | |
65e7eb3d EZ |
5111 | ((eq curr-elem '+) |
5112 | (if (not (allout-hidden-p)) | |
5113 | (save-excursion (allout-hide-current-subtree t))) | |
5114 | (allout-show-current-branches) | |
fd5359c6 MR |
5115 | (if (> allout-recent-end-of-subtree max-pos) |
5116 | (setq max-pos allout-recent-end-of-subtree))) | |
5117 | ((eq curr-elem '-) (allout-show-current-entry)) | |
19b84ba3 RS |
5118 | ((eq curr-elem ':) |
5119 | (setq stay t) | |
353e2ef2 | 5120 | ;; Expand the `repeat' spec to an explicit version, |
19b84ba3 RS |
5121 | ;; w.r.t. remaining siblings: |
5122 | (let ((residue ; = # of sibs not covered by remaining spec | |
60c7bbd2 | 5123 | ;; Dang, could be nice to make use of the chart, sigh: |
fd5359c6 | 5124 | (- (length (allout-chart-siblings)) |
19b84ba3 RS |
5125 | (length spec)))) |
5126 | (if (< 0 residue) | |
60c7bbd2 | 5127 | ;; Some residue -- cover it with prev-elem: |
19b84ba3 RS |
5128 | (setq spec (append (make-list residue prev-elem) |
5129 | spec))))))) | |
5130 | ((numberp curr-elem) | |
96b83743 | 5131 | (if (and (>= 0 curr-elem) (not (allout-hidden-p))) |
fd5359c6 | 5132 | (save-excursion (allout-hide-current-subtree t) |
19b84ba3 RS |
5133 | (if (> 0 curr-elem) |
5134 | nil | |
fd5359c6 | 5135 | (if (> allout-recent-end-of-subtree max-pos) |
19b84ba3 | 5136 | (setq max-pos |
fd5359c6 | 5137 | allout-recent-end-of-subtree))))) |
19b84ba3 | 5138 | (if (> (abs curr-elem) 0) |
fd5359c6 MR |
5139 | (progn (allout-show-children (abs curr-elem)) |
5140 | (if (> allout-recent-end-of-subtree max-pos) | |
5141 | (setq max-pos allout-recent-end-of-subtree))))) | |
19b84ba3 | 5142 | ((listp curr-elem) |
fd5359c6 MR |
5143 | (if (allout-descend-to-depth (1+ depth)) |
5144 | (let ((got (allout-expose-topic curr-elem))) | |
19b84ba3 RS |
5145 | (if (and got (> got max-pos)) (setq max-pos got)))))) |
5146 | (cond (stay (setq stay nil)) | |
5147 | ((listp (car spec)) nil) | |
5148 | ((> max-pos (point)) | |
5149 | ;; Capitalize on max-pos state to get us nearer next sibling: | |
5150 | (progn (goto-char (min (point-max) max-pos)) | |
fd5359c6 MR |
5151 | (allout-next-heading))) |
5152 | ((allout-next-sibling depth)))) | |
19b84ba3 | 5153 | max-pos))) |
fd5359c6 MR |
5154 | ;;;_ > allout-old-expose-topic (spec &rest followers) |
5155 | (defun allout-old-expose-topic (spec &rest followers) | |
d82979ea | 5156 | |
c07583cd | 5157 | "Deprecated. Use `allout-expose-topic' (with different schema |
d82979ea EZ |
5158 | format) instead. |
5159 | ||
5160 | Dictate wholesale exposure scheme for current topic, according to SPEC. | |
c567ac01 RS |
5161 | |
5162 | SPEC is either a number or a list. Optional successive args | |
5163 | dictate exposure for subsequent siblings of current topic. | |
5164 | ||
5165 | A simple spec (either a number, a special symbol, or the null list) | |
5166 | dictates the overall exposure for a topic. Non null lists are | |
5167 | composite specs whose first element dictates the overall exposure for | |
5168 | a topic, with the subsequent elements in the list interpreted as specs | |
5169 | that dictate the exposure for the successive offspring of the topic. | |
5170 | ||
5171 | Simple (numeric and null-list) specs are interpreted as follows: | |
5172 | ||
5173 | - Numbers indicate the relative depth to open the corresponding topic: | |
5174 | - negative numbers force the topic to be close before opening to the | |
5175 | absolute value of the number. | |
5176 | - positive numbers just open to the relative depth indicated by the number. | |
5177 | - 0 just closes | |
353e2ef2 KH |
5178 | - `*' completely opens the topic, including bodies. |
5179 | - `+' shows all the sub headers, but not the bodies | |
5180 | - `-' exposes the body and immediate offspring of the corresponding topic. | |
c567ac01 RS |
5181 | |
5182 | If the spec is a list, the first element must be a number, which | |
5183 | dictates the exposure depth of the topic as a whole. Subsequent | |
5184 | elements of the list are nested SPECs, dictating the specific exposure | |
5185 | for the corresponding offspring of the topic. | |
5186 | ||
e126900f | 5187 | Optional FOLLOWERS arguments dictate exposure for succeeding siblings." |
c567ac01 RS |
5188 | |
5189 | (interactive "xExposure spec: ") | |
0458fa80 EZ |
5190 | (let ((inhibit-field-text-motion t) |
5191 | (depth (allout-current-depth)) | |
c567ac01 RS |
5192 | max-pos) |
5193 | (cond ((null spec) nil) | |
5194 | ((symbolp spec) | |
fd5359c6 MR |
5195 | (if (eq spec '*) (allout-show-current-subtree)) |
5196 | (if (eq spec '+) (allout-show-current-branches)) | |
5197 | (if (eq spec '-) (allout-show-current-entry))) | |
c567ac01 RS |
5198 | ((numberp spec) |
5199 | (if (>= 0 spec) | |
fd5359c6 | 5200 | (save-excursion (allout-hide-current-subtree t) |
c567ac01 RS |
5201 | (end-of-line) |
5202 | (if (or (not max-pos) | |
5203 | (> (point) max-pos)) | |
5204 | (setq max-pos (point))) | |
5205 | (if (> 0 spec) | |
5206 | (setq spec (* -1 spec))))) | |
5207 | (if (> spec 0) | |
fd5359c6 | 5208 | (allout-show-children spec))) |
c567ac01 | 5209 | ((listp spec) |
fd5359c6 | 5210 | ;(let ((got (allout-old-expose-topic (car spec)))) |
c567ac01 RS |
5211 | ; (if (and got (or (not max-pos) (> got max-pos))) |
5212 | ; (setq max-pos got))) | |
fd5359c6 | 5213 | (let ((new-depth (+ (allout-current-depth) 1)) |
c567ac01 | 5214 | got) |
fd5359c6 | 5215 | (setq max-pos (allout-old-expose-topic (car spec))) |
c567ac01 RS |
5216 | (setq spec (cdr spec)) |
5217 | (if (and spec | |
fd5359c6 MR |
5218 | (allout-descend-to-depth new-depth) |
5219 | (not (allout-hidden-p))) | |
5220 | (progn (setq got (apply 'allout-old-expose-topic spec)) | |
c567ac01 RS |
5221 | (if (and got (or (not max-pos) (> got max-pos))) |
5222 | (setq max-pos got))))))) | |
5223 | (while (and followers | |
5224 | (progn (if (and max-pos (< (point) max-pos)) | |
5225 | (progn (goto-char max-pos) | |
5226 | (setq max-pos nil))) | |
5227 | (end-of-line) | |
fd5359c6 MR |
5228 | (allout-next-sibling depth))) |
5229 | (allout-old-expose-topic (car followers)) | |
c567ac01 RS |
5230 | (setq followers (cdr followers))) |
5231 | max-pos)) | |
fd5359c6 MR |
5232 | ;;;_ > allout-new-exposure '() |
5233 | (defmacro allout-new-exposure (&rest spec) | |
5234 | "Literal frontend for `allout-expose-topic', doesn't evaluate arguments. | |
2265e017 MR |
5235 | Some arguments that would need to be quoted in `allout-expose-topic' |
5236 | need not be quoted in `allout-new-exposure'. | |
c567ac01 RS |
5237 | |
5238 | Cursor is left at start position. | |
5239 | ||
d82979ea EZ |
5240 | Use this instead of obsolete `allout-exposure'. |
5241 | ||
c567ac01 | 5242 | Examples: |
bff05d9e | 5243 | \(allout-new-exposure (-1 () () () 1) 0) |
c567ac01 RS |
5244 | Close current topic at current level so only the immediate |
5245 | subtopics are shown, except also show the children of the | |
5246 | third subtopic; and close the next topic at the current level. | |
bff05d9e | 5247 | \(allout-new-exposure : -1 0) |
c567ac01 RS |
5248 | Close all topics at current level to expose only their |
5249 | immediate children, except for the last topic at the current | |
353e2ef2 | 5250 | level, in which even its immediate children are hidden. |
bff05d9e | 5251 | \(allout-new-exposure -2 : -1 *) |
c567ac01 RS |
5252 | Expose children and grandchildren of first topic at current |
5253 | level, and expose children of subsequent topics at current | |
5254 | level *except* for the last, which should be opened completely." | |
5255 | (list 'save-excursion | |
d8350998 | 5256 | '(if (not (or (allout-goto-prefix-doublechecked) |
fd5359c6 MR |
5257 | (allout-next-heading))) |
5258 | (error "allout-new-exposure: Can't find any outline topics")) | |
5259 | (list 'allout-expose-topic (list 'quote spec)))) | |
c567ac01 | 5260 | |
60c7bbd2 | 5261 | ;;;_ #7 Systematic outline presentation -- copying, printing, flattening |
19b84ba3 | 5262 | |
9179616f DL |
5263 | ;;;_ - Mapping and processing of topics |
5264 | ;;;_ ( See also Subtree Charting, in Navigation code.) | |
fd5359c6 MR |
5265 | ;;;_ > allout-stringify-flat-index (flat-index) |
5266 | (defun allout-stringify-flat-index (flat-index &optional context) | |
9179616f DL |
5267 | "Convert list representing section/subsection/... to document string. |
5268 | ||
5269 | Optional arg CONTEXT indicates interior levels to include." | |
5270 | (let ((delim ".") | |
71296446 | 5271 | result |
9179616f DL |
5272 | numstr |
5273 | (context-depth (or (and context 2) 1))) | |
5274 | ;; Take care of the explicit context: | |
5275 | (while (> context-depth 0) | |
5276 | (setq numstr (int-to-string (car flat-index)) | |
5277 | flat-index (cdr flat-index) | |
5278 | result (if flat-index | |
5279 | (cons delim (cons numstr result)) | |
5280 | (cons numstr result)) | |
5281 | context-depth (if flat-index (1- context-depth) 0))) | |
5282 | (setq delim " ") | |
5283 | ;; Take care of the indentation: | |
5284 | (if flat-index | |
5285 | (progn | |
5286 | (while flat-index | |
5287 | (setq result | |
5288 | (cons delim | |
5289 | (cons (make-string | |
5290 | (1+ (truncate (if (zerop (car flat-index)) | |
5291 | 1 | |
5292 | (log10 (car flat-index))))) | |
5293 | ? ) | |
5294 | result))) | |
5295 | (setq flat-index (cdr flat-index))) | |
5296 | ;; Dispose of single extra delim: | |
5297 | (setq result (cdr result)))) | |
5298 | (apply 'concat result))) | |
fd5359c6 MR |
5299 | ;;;_ > allout-stringify-flat-index-plain (flat-index) |
5300 | (defun allout-stringify-flat-index-plain (flat-index) | |
9179616f DL |
5301 | "Convert list representing section/subsection/... to document string." |
5302 | (let ((delim ".") | |
5303 | result) | |
5304 | (while flat-index | |
5305 | (setq result (cons (int-to-string (car flat-index)) | |
5306 | (if result | |
5307 | (cons delim result)))) | |
5308 | (setq flat-index (cdr flat-index))) | |
5309 | (apply 'concat result))) | |
fd5359c6 MR |
5310 | ;;;_ > allout-stringify-flat-index-indented (flat-index) |
5311 | (defun allout-stringify-flat-index-indented (flat-index) | |
9179616f DL |
5312 | "Convert list representing section/subsection/... to document string." |
5313 | (let ((delim ".") | |
71296446 | 5314 | result |
9179616f DL |
5315 | numstr) |
5316 | ;; Take care of the explicit context: | |
5317 | (setq numstr (int-to-string (car flat-index)) | |
5318 | flat-index (cdr flat-index) | |
5319 | result (if flat-index | |
5320 | (cons delim (cons numstr result)) | |
5321 | (cons numstr result))) | |
5322 | (setq delim " ") | |
5323 | ;; Take care of the indentation: | |
5324 | (if flat-index | |
5325 | (progn | |
5326 | (while flat-index | |
5327 | (setq result | |
5328 | (cons delim | |
5329 | (cons (make-string | |
5330 | (1+ (truncate (if (zerop (car flat-index)) | |
5331 | 1 | |
5332 | (log10 (car flat-index))))) | |
5333 | ? ) | |
5334 | result))) | |
5335 | (setq flat-index (cdr flat-index))) | |
5336 | ;; Dispose of single extra delim: | |
5337 | (setq result (cdr result)))) | |
5338 | (apply 'concat result))) | |
fd5359c6 MR |
5339 | ;;;_ > allout-listify-exposed (&optional start end format) |
5340 | (defun allout-listify-exposed (&optional start end format) | |
19b84ba3 | 5341 | |
9179616f | 5342 | "Produce a list representing exposed topics in current region. |
c567ac01 | 5343 | |
fd5359c6 | 5344 | This list can then be used by `allout-process-exposed' to manipulate |
9179616f | 5345 | the subject region. |
353e2ef2 | 5346 | |
9179616f | 5347 | Optional START and END indicate bounds of region. |
19b84ba3 | 5348 | |
75bcb912 | 5349 | Optional arg, FORMAT, designates an alternate presentation form for |
9179616f | 5350 | the prefix: |
c567ac01 | 5351 | |
60c7bbd2 | 5352 | list -- Present prefix as numeric section.subsection..., starting with |
9179616f | 5353 | section indicated by the list, innermost nesting first. |
60c7bbd2 | 5354 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5355 | except for distinctive bullets. |
c567ac01 | 5356 | |
9179616f DL |
5357 | The elements of the list produced are lists that represents a topic |
5358 | header and body. The elements of that list are: | |
c567ac01 | 5359 | |
9179616f DL |
5360 | - a number representing the depth of the topic, |
5361 | - a string representing the header-prefix, including trailing whitespace and | |
5362 | bullet. | |
5363 | - a string representing the bullet character, | |
5364 | - and a series of strings, each containing one line of the exposed | |
5365 | portion of the topic entry." | |
c567ac01 | 5366 | |
9179616f DL |
5367 | (interactive "r") |
5368 | (save-excursion | |
5369 | (let* | |
0458fa80 EZ |
5370 | ((inhibit-field-text-motion t) |
5371 | ;; state vars: | |
5372 | strings prefix result depth new-depth out gone-out bullet beg | |
9179616f | 5373 | next done) |
c567ac01 | 5374 | |
9179616f DL |
5375 | (goto-char start) |
5376 | (beginning-of-line) | |
97610156 | 5377 | ;; Goto initial topic, and register preceding stuff, if any: |
d8350998 | 5378 | (if (> (allout-goto-prefix-doublechecked) start) |
60c7bbd2 | 5379 | ;; First topic follows beginning point -- register preliminary stuff: |
3e2ee889 KM |
5380 | (setq result |
5381 | (list (list 0 "" nil | |
5382 | (buffer-substring-no-properties start | |
5383 | (1- (point))))))) | |
9179616f DL |
5384 | (while (and (not done) |
5385 | (not (eobp)) ; Loop until we've covered the region. | |
5386 | (not (> (point) end))) | |
d8350998 | 5387 | (setq depth allout-recent-depth ; Current topics depth, |
fd5359c6 MR |
5388 | bullet (allout-recent-bullet) ; ... bullet, |
5389 | prefix (allout-recent-prefix) | |
5390 | beg (progn (allout-end-of-prefix t) (point))) ; and beginning. | |
9179616f | 5391 | (setq done ; The boundary for the current topic: |
fd5359c6 | 5392 | (not (allout-next-visible-heading 1))) |
d8350998 | 5393 | (setq new-depth allout-recent-depth) |
9179616f DL |
5394 | (setq gone-out out |
5395 | out (< new-depth depth)) | |
5396 | (beginning-of-line) | |
5397 | (setq next (point)) | |
5398 | (goto-char beg) | |
5399 | (setq strings nil) | |
5400 | (while (> next (point)) ; Get all the exposed text in | |
5401 | (setq strings | |
3e2ee889 | 5402 | (cons (buffer-substring-no-properties |
9179616f DL |
5403 | beg |
5404 | ;To hidden text or end of line: | |
5405 | (progn | |
96b83743 EZ |
5406 | (end-of-line) |
5407 | (allout-back-to-visible-text))) | |
9179616f | 5408 | strings)) |
96b83743 | 5409 | (when (< (point) next) ; Resume from after hid text, if any. |
1b4d97b2 CY |
5410 | (line-move 1) |
5411 | (beginning-of-line)) | |
9179616f DL |
5412 | (setq beg (point))) |
5413 | ;; Accumulate list for this topic: | |
5414 | (setq strings (nreverse strings)) | |
5415 | (setq result | |
5416 | (cons | |
5417 | (if format | |
5418 | (let ((special (if (string-match | |
5419 | (regexp-quote bullet) | |
fd5359c6 | 5420 | allout-distinctive-bullets-string) |
9179616f DL |
5421 | bullet))) |
5422 | (cond ((listp format) | |
5423 | (list depth | |
96497653 | 5424 | (if allout-flattened-numbering-abbreviation |
fd5359c6 | 5425 | (allout-stringify-flat-index format |
9179616f | 5426 | gone-out) |
fd5359c6 | 5427 | (allout-stringify-flat-index-plain |
9179616f DL |
5428 | format)) |
5429 | strings | |
5430 | special)) | |
5431 | ((eq format 'indent) | |
5432 | (if special | |
5433 | (list depth | |
5434 | (concat (make-string (1+ depth) ? ) | |
5435 | (substring prefix -1)) | |
5436 | strings) | |
5437 | (list depth | |
5438 | (make-string depth ? ) | |
5439 | strings))) | |
fd5359c6 | 5440 | (t (error "allout-listify-exposed: %s %s" |
9179616f DL |
5441 | "invalid format" format)))) |
5442 | (list depth prefix strings)) | |
5443 | result)) | |
5444 | ;; Reasses format, if any: | |
5445 | (if (and format (listp format)) | |
5446 | (cond ((= new-depth depth) | |
5447 | (setq format (cons (1+ (car format)) | |
5448 | (cdr format)))) | |
60c7bbd2 | 5449 | ((> new-depth depth) ; descending -- assume by 1: |
9179616f DL |
5450 | (setq format (cons 1 format))) |
5451 | (t | |
5452 | ; Pop the residue: | |
5453 | (while (< new-depth depth) | |
5454 | (setq format (cdr format)) | |
5455 | (setq depth (1- depth))) | |
5456 | ; And increment the current one: | |
5457 | (setq format | |
5458 | (cons (1+ (or (car format) | |
5459 | -1)) | |
5460 | (cdr format))))))) | |
5461 | ;; Put the list with first at front, to last at back: | |
5462 | (nreverse result)))) | |
c60d543d RS |
5463 | ;;;_ > allout-region-active-p () |
5464 | (defmacro allout-region-active-p () | |
42c3e51c KM |
5465 | (cond ((fboundp 'use-region-p) '(use-region-p)) |
5466 | ((fboundp 'region-active-p) '(region-active-p)) | |
5467 | (t 'mark-active))) | |
5468 | ;;_ > allout-process-exposed (&optional func from to frombuf | |
9179616f | 5469 | ;;; tobuf format) |
fd5359c6 | 5470 | (defun allout-process-exposed (&optional func from to frombuf tobuf |
96b83743 | 5471 | format start-num) |
9179616f | 5472 | "Map function on exposed parts of current topic; results to another buffer. |
353e2ef2 | 5473 | |
d82979ea EZ |
5474 | All args are options; default values itemized below. |
5475 | ||
5476 | Apply FUNCTION to exposed portions FROM position TO position in buffer | |
9179616f DL |
5477 | FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an |
5478 | alternate presentation form: | |
c567ac01 | 5479 | |
60c7bbd2 | 5480 | `flat' -- Present prefix as numeric section.subsection..., starting with |
75bcb912 | 5481 | section indicated by the START-NUM, innermost nesting first. |
60c7bbd2 | 5482 | X`flat-indented' -- Prefix is like `flat' for first topic at each |
9179616f DL |
5483 | X level, but subsequent topics have only leaf topic |
5484 | X number, padded with blanks to line up with first. | |
60c7bbd2 | 5485 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5486 | except for distinctive bullets. |
c567ac01 | 5487 | |
9179616f | 5488 | Defaults: |
d82979ea | 5489 | FUNCTION: `allout-insert-listified' |
9179616f DL |
5490 | FROM: region start, if region active, else start of buffer |
5491 | TO: region end, if region active, else end of buffer | |
5492 | FROMBUF: current buffer | |
5493 | TOBUF: buffer name derived: \"*current-buffer-name exposed*\" | |
5494 | FORMAT: nil" | |
5495 | ||
5496 | ; Resolve arguments, | |
5497 | ; defaulting if necessary: | |
fd5359c6 | 5498 | (if (not func) (setq func 'allout-insert-listified)) |
9179616f | 5499 | (if (not (and from to)) |
c60d543d | 5500 | (if (allout-region-active-p) |
9179616f DL |
5501 | (setq from (region-beginning) to (region-end)) |
5502 | (setq from (point-min) to (point-max)))) | |
5503 | (if frombuf | |
5504 | (if (not (bufferp frombuf)) | |
60c7bbd2 | 5505 | ;; Specified but not a buffer -- get it: |
9179616f DL |
5506 | (let ((got (get-buffer frombuf))) |
5507 | (if (not got) | |
fd5359c6 | 5508 | (error (concat "allout-process-exposed: source buffer " |
9179616f DL |
5509 | frombuf |
5510 | " not found.")) | |
5511 | (setq frombuf got)))) | |
60c7bbd2 | 5512 | ;; not specified -- default it: |
9179616f DL |
5513 | (setq frombuf (current-buffer))) |
5514 | (if tobuf | |
5515 | (if (not (bufferp tobuf)) | |
5516 | (setq tobuf (get-buffer-create tobuf))) | |
60c7bbd2 | 5517 | ;; not specified -- default it: |
9179616f DL |
5518 | (setq tobuf (concat "*" (buffer-name frombuf) " exposed*"))) |
5519 | (if (listp format) | |
5520 | (nreverse format)) | |
5521 | ||
5522 | (let* ((listified | |
5523 | (progn (set-buffer frombuf) | |
fd5359c6 | 5524 | (allout-listify-exposed from to format)))) |
9179616f | 5525 | (set-buffer tobuf) |
5110e166 | 5526 | (mapc func listified) |
9179616f DL |
5527 | (pop-to-buffer tobuf))) |
5528 | ||
5529 | ;;;_ - Copy exposed | |
fd5359c6 MR |
5530 | ;;;_ > allout-insert-listified (listified) |
5531 | (defun allout-insert-listified (listified) | |
9179616f DL |
5532 | "Insert contents of listified outline portion in current buffer. |
5533 | ||
e126900f | 5534 | LISTIFIED is a list representing each topic header and body: |
9179616f DL |
5535 | |
5536 | \`(depth prefix text)' | |
5537 | ||
d82979ea | 5538 | or \`(depth prefix text bullet-plus)' |
9179616f DL |
5539 | |
5540 | If `bullet-plus' is specified, it is inserted just after the entire prefix." | |
5541 | (setq listified (cdr listified)) | |
5542 | (let ((prefix (prog1 | |
5543 | (car listified) | |
5544 | (setq listified (cdr listified)))) | |
5545 | (text (prog1 | |
5546 | (car listified) | |
5547 | (setq listified (cdr listified)))) | |
5548 | (bullet-plus (car listified))) | |
eac9cf5f PJ |
5549 | (insert prefix) |
5550 | (if bullet-plus (insert (concat " " bullet-plus))) | |
9179616f | 5551 | (while text |
eac9cf5f | 5552 | (insert (car text)) |
9179616f | 5553 | (if (setq text (cdr text)) |
0949617b | 5554 | (insert "\n"))) |
eac9cf5f | 5555 | (insert "\n"))) |
fd5359c6 MR |
5556 | ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format) |
5557 | (defun allout-copy-exposed-to-buffer (&optional arg tobuf format) | |
9179616f DL |
5558 | "Duplicate exposed portions of current outline to another buffer. |
5559 | ||
5560 | Other buffer has current buffers name with \" exposed\" appended to it. | |
5561 | ||
5562 | With repeat count, copy the exposed parts of only the current topic. | |
5563 | ||
5564 | Optional second arg TOBUF is target buffer name. | |
5565 | ||
5566 | Optional third arg FORMAT, if non-nil, symbolically designates an | |
5567 | alternate presentation format for the outline: | |
5568 | ||
5569 | `flat' - Convert topic header prefixes to numeric | |
5570 | section.subsection... identifiers. | |
5571 | `indent' - Convert header prefixes to all white space, except for | |
5572 | distinctive bullets. | |
5573 | `indent-flat' - The best of both - only the first of each level has | |
5574 | the full path, the rest have only the section number | |
5575 | of the leaf, preceded by the right amount of indentation." | |
c567ac01 RS |
5576 | |
5577 | (interactive "P") | |
5578 | (if (not tobuf) | |
5579 | (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*")))) | |
5580 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5581 | (beg (if arg (allout-back-to-current-heading) (point-min))) |
5582 | (end (if arg (allout-end-of-current-subtree) (point-max))) | |
9179616f DL |
5583 | (buf (current-buffer)) |
5584 | (start-list ())) | |
5585 | (if (eq format 'flat) | |
5586 | (setq format (if arg (save-excursion | |
5587 | (goto-char beg) | |
fd5359c6 | 5588 | (allout-topic-flat-index)) |
9179616f | 5589 | '(1)))) |
7fdbcd83 | 5590 | (with-current-buffer tobuf (erase-buffer)) |
fd5359c6 | 5591 | (allout-process-exposed 'allout-insert-listified |
c567ac01 RS |
5592 | beg |
5593 | end | |
5594 | (current-buffer) | |
9179616f DL |
5595 | tobuf |
5596 | format start-list) | |
c567ac01 RS |
5597 | (goto-char (point-min)) |
5598 | (pop-to-buffer buf) | |
5599 | (goto-char start-pt))) | |
fd5359c6 MR |
5600 | ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf) |
5601 | (defun allout-flatten-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5602 | "Present numeric outline of outline's exposed portions in another buffer. |
5603 | ||
60c7bbd2 | 5604 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5605 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5606 | |
fd5359c6 | 5607 | Use `allout-indented-exposed-to-buffer' for indented presentation. |
9179616f DL |
5608 | |
5609 | With repeat count, copy the exposed portions of only current topic. | |
5610 | ||
e126900f | 5611 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5612 | it, unless optional second arg TOBUF is specified, in which case it is |
5613 | used verbatim." | |
5614 | (interactive "P") | |
fd5359c6 MR |
5615 | (allout-copy-exposed-to-buffer arg tobuf 'flat)) |
5616 | ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf) | |
5617 | (defun allout-indented-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5618 | "Present indented outline of outline's exposed portions in another buffer. |
5619 | ||
60c7bbd2 | 5620 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5621 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5622 | |
fd5359c6 | 5623 | Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation. |
9179616f DL |
5624 | |
5625 | With repeat count, copy the exposed portions of only current topic. | |
5626 | ||
e126900f | 5627 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5628 | it, unless optional second arg TOBUF is specified, in which case it is |
5629 | used verbatim." | |
5630 | (interactive "P") | |
fd5359c6 | 5631 | (allout-copy-exposed-to-buffer arg tobuf 'indent)) |
c567ac01 RS |
5632 | |
5633 | ;;;_ - LaTeX formatting | |
e126900f JB |
5634 | ;;;_ > allout-latex-verb-quote (string &optional flow) |
5635 | (defun allout-latex-verb-quote (string &optional flow) | |
539d7736 | 5636 | "Return copy of STRING for literal reproduction across LaTeX processing. |
c07583cd | 5637 | Expresses the original characters (including carriage returns) of the |
539d7736 | 5638 | string across LaTeX processing." |
9179616f DL |
5639 | (mapconcat (function |
5640 | (lambda (char) | |
c567ac01 RS |
5641 | (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*)) |
5642 | (concat "\\char" (number-to-string char) "{}")) | |
5643 | ((= char ?\n) "\\\\") | |
9179616f | 5644 | (t (char-to-string char))))) |
e126900f | 5645 | string |
c567ac01 | 5646 | "")) |
fd5359c6 MR |
5647 | ;;;_ > allout-latex-verbatim-quote-curr-line () |
5648 | (defun allout-latex-verbatim-quote-curr-line () | |
c07583cd | 5649 | "Express line for exact (literal) representation across LaTeX processing. |
19b84ba3 | 5650 | |
c07583cd | 5651 | Adjust line contents so it is unaltered (from the original line) |
539d7736 | 5652 | across LaTeX processing, within the context of a `verbatim' |
c567ac01 | 5653 | environment. Leaves point at the end of the line." |
0458fa80 EZ |
5654 | (let ((inhibit-field-text-motion t)) |
5655 | (beginning-of-line) | |
5656 | (let ((beg (point)) | |
626b459f | 5657 | (end (point-at-eol))) |
2a1408fd DN |
5658 | (save-match-data |
5659 | (while (re-search-forward "\\\\" | |
5660 | ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#" | |
5661 | end ; bounded by end-of-line | |
5662 | 1) ; no matches, move to end & return nil | |
5663 | (goto-char (match-beginning 2)) | |
5664 | (insert "\\") | |
5665 | (setq end (1+ end)) | |
5666 | (goto-char (1+ (match-end 2)))))))) | |
e126900f JB |
5667 | ;;;_ > allout-insert-latex-header (buffer) |
5668 | (defun allout-insert-latex-header (buffer) | |
539d7736 | 5669 | "Insert initial LaTeX commands at point in BUFFER." |
c567ac01 RS |
5670 | ;; Much of this is being derived from the stuff in appendix of E in |
5671 | ;; the TeXBook, pg 421. | |
e126900f | 5672 | (set-buffer buffer) |
c567ac01 RS |
5673 | (let ((doc-style (format "\n\\documentstyle{%s}\n" |
5674 | "report")) | |
fd5359c6 | 5675 | (page-numbering (if allout-number-pages |
c567ac01 RS |
5676 | "\\pagestyle{empty}\n" |
5677 | "")) | |
c567ac01 | 5678 | (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5679 | allout-title-style)) |
c567ac01 | 5680 | (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n" |
fd5359c6 | 5681 | allout-label-style)) |
c567ac01 | 5682 | (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5683 | allout-head-line-style)) |
c567ac01 | 5684 | (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5685 | allout-body-line-style)) |
c567ac01 RS |
5686 | (setlength (format "%s%s%s%s" |
5687 | "\\newlength{\\stepsize}\n" | |
5688 | "\\setlength{\\stepsize}{" | |
fd5359c6 | 5689 | allout-indent |
c567ac01 RS |
5690 | "}\n")) |
5691 | (oneheadline (format "%s%s%s%s%s%s%s" | |
5692 | "\\newcommand{\\OneHeadLine}[3]{%\n" | |
5693 | "\\noindent%\n" | |
5694 | "\\hspace*{#2\\stepsize}%\n" | |
5695 | "\\labelcmd{#1}\\hspace*{.2cm}" | |
5696 | "\\headlinecmd{#3}\\\\[" | |
fd5359c6 | 5697 | allout-line-skip |
c567ac01 RS |
5698 | "]\n}\n")) |
5699 | (onebodyline (format "%s%s%s%s%s%s" | |
5700 | "\\newcommand{\\OneBodyLine}[2]{%\n" | |
5701 | "\\noindent%\n" | |
5702 | "\\hspace*{#1\\stepsize}%\n" | |
5703 | "\\bodylinecmd{#2}\\\\[" | |
fd5359c6 | 5704 | allout-line-skip |
c567ac01 RS |
5705 | "]\n}\n")) |
5706 | (begindoc "\\begin{document}\n\\begin{center}\n") | |
5707 | (title (format "%s%s%s%s" | |
5708 | "\\titlecmd{" | |
fd5359c6 | 5709 | (allout-latex-verb-quote (if allout-title |
96b83743 | 5710 | (condition-case nil |
fd5359c6 | 5711 | (eval allout-title) |
d8350998 | 5712 | (error "<unnamed buffer>")) |
c567ac01 RS |
5713 | "Unnamed Outline")) |
5714 | "}\n" | |
5715 | "\\end{center}\n\n")) | |
5716 | (hsize "\\hsize = 7.5 true in\n") | |
5717 | (hoffset "\\hoffset = -1.5 true in\n") | |
5718 | (vspace "\\vspace{.1cm}\n\n")) | |
5719 | (insert (concat doc-style | |
5720 | page-numbering | |
5721 | titlecmd | |
5722 | labelcmd | |
5723 | headlinecmd | |
5724 | bodylinecmd | |
5725 | setlength | |
5726 | oneheadline | |
5727 | onebodyline | |
5728 | begindoc | |
5729 | title | |
5730 | hsize | |
5731 | hoffset | |
5732 | vspace) | |
5733 | ))) | |
e126900f JB |
5734 | ;;;_ > allout-insert-latex-trailer (buffer) |
5735 | (defun allout-insert-latex-trailer (buffer) | |
539d7736 | 5736 | "Insert concluding LaTeX commands at point in BUFFER." |
e126900f | 5737 | (set-buffer buffer) |
c567ac01 | 5738 | (insert "\n\\end{document}\n")) |
fd5359c6 MR |
5739 | ;;;_ > allout-latexify-one-item (depth prefix bullet text) |
5740 | (defun allout-latexify-one-item (depth prefix bullet text) | |
19b84ba3 RS |
5741 | "Insert LaTeX commands for formatting one outline item. |
5742 | ||
9179616f | 5743 | Args are the topics numeric DEPTH, the header PREFIX lead string, the |
19b84ba3 | 5744 | BULLET string, and a list of TEXT strings for the body." |
c567ac01 RS |
5745 | (let* ((head-line (if text (car text))) |
5746 | (body-lines (cdr text)) | |
5747 | (curr-line) | |
5748 | body-content bop) | |
5749 | ; Do the head line: | |
71296446 | 5750 | (insert (concat "\\OneHeadLine{\\verb\1 " |
d82979ea EZ |
5751 | (allout-latex-verb-quote bullet) |
5752 | "\1}{" | |
5753 | depth | |
5754 | "}{\\verb\1 " | |
5755 | (if head-line | |
5756 | (allout-latex-verb-quote head-line) | |
5757 | "") | |
5758 | "\1}\n")) | |
c567ac01 RS |
5759 | (if (not body-lines) |
5760 | nil | |
eac9cf5f PJ |
5761 | ;;(insert "\\beginlines\n") |
5762 | (insert "\\begin{verbatim}\n") | |
c567ac01 RS |
5763 | (while body-lines |
5764 | (setq curr-line (car body-lines)) | |
5765 | (if (and (not body-content) | |
5766 | (not (string-match "^\\s-*$" curr-line))) | |
5767 | (setq body-content t)) | |
5768 | ; Mangle any occurrences of | |
5769 | ; "\end{verbatim}" in text, | |
5770 | ; it's special: | |
5771 | (if (and body-content | |
5772 | (setq bop (string-match "\\end{verbatim}" curr-line))) | |
5773 | (setq curr-line (concat (substring curr-line 0 bop) | |
5774 | ">" | |
5775 | (substring curr-line bop)))) | |
eac9cf5f PJ |
5776 | ;;(insert "|" (car body-lines) "|") |
5777 | (insert curr-line) | |
fd5359c6 | 5778 | (allout-latex-verbatim-quote-curr-line) |
eac9cf5f | 5779 | (insert "\n") |
c567ac01 RS |
5780 | (setq body-lines (cdr body-lines))) |
5781 | (if body-content | |
5782 | (setq body-content nil) | |
5783 | (forward-char -1) | |
eac9cf5f | 5784 | (insert "\\ ") |
c567ac01 | 5785 | (forward-char 1)) |
eac9cf5f PJ |
5786 | ;;(insert "\\endlines\n") |
5787 | (insert "\\end{verbatim}\n") | |
c567ac01 | 5788 | ))) |
fd5359c6 MR |
5789 | ;;;_ > allout-latexify-exposed (arg &optional tobuf) |
5790 | (defun allout-latexify-exposed (arg &optional tobuf) | |
539d7736 | 5791 | "Format current topics exposed portions to TOBUF for LaTeX processing. |
19b84ba3 RS |
5792 | TOBUF defaults to a buffer named the same as the current buffer, but |
5793 | with \"*\" prepended and \" latex-formed*\" appended. | |
c567ac01 RS |
5794 | |
5795 | With repeat count, copy the exposed portions of entire buffer." | |
5796 | ||
5797 | (interactive "P") | |
5798 | (if (not tobuf) | |
5799 | (setq tobuf | |
5800 | (get-buffer-create (concat "*" (buffer-name) " latexified*")))) | |
5801 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5802 | (beg (if arg (point-min) (allout-back-to-current-heading))) |
5803 | (end (if arg (point-max) (allout-end-of-current-subtree))) | |
c567ac01 RS |
5804 | (buf (current-buffer))) |
5805 | (set-buffer tobuf) | |
1977b8f6 | 5806 | (erase-buffer) |
fd5359c6 | 5807 | (allout-insert-latex-header tobuf) |
c567ac01 | 5808 | (goto-char (point-max)) |
fd5359c6 | 5809 | (allout-process-exposed 'allout-latexify-one-item |
c567ac01 RS |
5810 | beg |
5811 | end | |
5812 | buf | |
5813 | tobuf) | |
5814 | (goto-char (point-max)) | |
fd5359c6 | 5815 | (allout-insert-latex-trailer tobuf) |
1977b8f6 | 5816 | (goto-char (point-min)) |
c567ac01 RS |
5817 | (pop-to-buffer buf) |
5818 | (goto-char start-pt))) | |
5819 | ||
d82979ea | 5820 | ;;;_ #8 Encryption |
29fac3fe KM |
5821 | ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue) |
5822 | (defun allout-toggle-current-subtree-encryption (&optional keymode-cue) | |
5823 | "Encrypt clear or decrypt encoded topic text. | |
5824 | ||
5825 | Allout uses emacs 'epg' libary to perform encryption. Symmetric | |
5826 | and keypair encryption are supported. All encryption is ascii | |
5827 | armored. | |
5828 | ||
075746e2 KM |
5829 | Entry encryption defaults to symmetric key mode unless keypair |
5830 | recipients are associated with the file \(see | |
5831 | `epa-file-encrypt-to') or the function is invoked with a | |
5832 | \(KEYMODE-CUE) universal argument greater than 1. | |
5833 | ||
5834 | When encrypting, KEYMODE-CUE universal argument greater than 1 | |
5835 | causes prompting for recipients for public-key keypair | |
5836 | encryption. Selecting no recipients results in symmetric key | |
29fac3fe KM |
5837 | encryption. |
5838 | ||
075746e2 KM |
5839 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5840 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5841 | the specified recipients with the file, replacing those currently | |
5842 | associated with it. This can be used to deassociate any | |
5843 | recipients with the file, by selecting no recipients in the | |
5844 | dialog. | |
5845 | ||
29fac3fe KM |
5846 | Encrypted topic's bullets are set to a `~' to signal that the |
5847 | contents of the topic (body and subtopics, but not heading) is | |
5848 | pending encryption or encrypted. `*' asterisk immediately after | |
5849 | the bullet signals that the body is encrypted, its absence means | |
5850 | the topic is meant to be encrypted but is not currently. When a | |
5851 | file with topics pending encryption is saved, topics pending | |
5852 | encryption are encrypted. See allout-encrypt-unencrypted-on-saves | |
5853 | for auto-encryption specifics. | |
0949617b | 5854 | |
6eb0a10d | 5855 | \*NOTE WELL* that automatic encryption that happens during saves will |
60c7bbd2 | 5856 | default to symmetric encryption -- you must deliberately (re)encrypt key-pair |
0949617b | 5857 | encrypted topics if you want them to continue to use the key-pair cipher. |
d82979ea | 5858 | |
d8350998 | 5859 | Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be |
d82979ea | 5860 | encrypted. If you want to encrypt the contents of a top-level topic, use |
29fac3fe | 5861 | \\[allout-shift-in] to increase its depth." |
69027dea EZ |
5862 | (interactive "P") |
5863 | (save-excursion | |
5864 | (allout-back-to-current-heading) | |
29fac3fe KM |
5865 | (allout-toggle-subtree-encryption keymode-cue))) |
5866 | ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue) | |
5867 | (defun allout-toggle-subtree-encryption (&optional keymode-cue) | |
c07583cd | 5868 | "Encrypt clear text or decrypt encoded topic contents (body and subtopics.) |
69027dea | 5869 | |
075746e2 KM |
5870 | Entry encryption defaults to symmetric key mode unless keypair |
5871 | recipients are associated with the file \(see | |
5872 | `epa-file-encrypt-to') or the function is invoked with a | |
5873 | \(KEYMODE-CUE) universal argument greater than 1. | |
69027dea | 5874 | |
075746e2 KM |
5875 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
5876 | causes prompting for recipients for public-key keypair | |
5877 | encryption. Selecting no recipients results in symmetric key | |
5878 | encryption. | |
69027dea | 5879 | |
075746e2 KM |
5880 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5881 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5882 | the specified recipients with the file, replacing those currently | |
5883 | associated with it. This can be used to deassociate any | |
5884 | recipients with the file, by selecting no recipients in the | |
5885 | dialog. | |
5886 | ||
5887 | Encryption and decryption uses the emacs epg library. | |
69027dea | 5888 | |
29fac3fe | 5889 | Encrypted text will be ascii-armored. |
69027dea EZ |
5890 | |
5891 | See `allout-toggle-current-subtree-encryption' for more details." | |
d82979ea EZ |
5892 | |
5893 | (interactive "P") | |
5894 | (save-excursion | |
5895 | (allout-end-of-prefix t) | |
5896 | ||
d8350998 | 5897 | (if (= allout-recent-depth 1) |
d82979ea EZ |
5898 | (error (concat "Cannot encrypt or decrypt level 1 topics -" |
5899 | " shift it in to make it encryptable"))) | |
5900 | ||
d82979ea | 5901 | (let* ((allout-buffer (current-buffer)) |
498a6493 | 5902 | ;; Assess location: |
d8350998 | 5903 | (bullet-pos allout-recent-prefix-beginning) |
d82979ea EZ |
5904 | (after-bullet-pos (point)) |
5905 | (was-encrypted | |
5906 | (progn (if (= (point-max) after-bullet-pos) | |
5907 | (error "no body to encrypt")) | |
0949617b | 5908 | (allout-encrypted-topic-p))) |
96b83743 | 5909 | (was-collapsed (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
5910 | nil |
5911 | (backward-char 1) | |
96b83743 | 5912 | (allout-hidden-p))) |
d82979ea EZ |
5913 | (subtree-beg (1+ (point))) |
5914 | (subtree-end (allout-end-of-subtree)) | |
5915 | (subject-text (buffer-substring-no-properties subtree-beg | |
5916 | subtree-end)) | |
5917 | (subtree-end-char (char-after (1- subtree-end))) | |
96b83743 | 5918 | (subtree-trailing-char (char-after subtree-end)) |
60c7bbd2 | 5919 | ;; kluge -- result-text needs to be nil, but we also want to |
96b83743 EZ |
5920 | ;; check for the error condition |
5921 | (result-text (if (or (string= "" subject-text) | |
5922 | (string= "\n" subject-text)) | |
5923 | (error "No topic contents to %scrypt" | |
5924 | (if was-encrypted "de" "en")) | |
5925 | nil)) | |
d82979ea | 5926 | ;; Assess key parameters: |
498a6493 CY |
5927 | (was-coding-system buffer-file-coding-system)) |
5928 | ||
5929 | (when (not was-encrypted) | |
5930 | ;; ensure that non-ascii chars pending encryption are noticed before | |
116f996b | 5931 | ;; they're encrypted, so the coding system is set to accommodate |
498a6493 CY |
5932 | ;; them. |
5933 | (setq buffer-file-coding-system | |
1c9b9df0 | 5934 | (allout-select-safe-coding-system subtree-beg subtree-end)) |
498a6493 CY |
5935 | ;; if the coding system for the text being encrypted is different |
5936 | ;; than that prevailing, then there a real risk that the coding | |
5937 | ;; system can't be noticed by emacs when the file is visited. to | |
5938 | ;; mitigate that, offer to preserve the coding system using a file | |
5939 | ;; local variable. | |
5940 | (if (and (not (equal buffer-file-coding-system | |
5941 | was-coding-system)) | |
5942 | (yes-or-no-p | |
5943 | (format (concat "Register coding system %s as file local" | |
5944 | " var? Necessary when only encrypted text" | |
5945 | " is in that coding system. ") | |
5946 | buffer-file-coding-system))) | |
5947 | (allout-adjust-file-variable "buffer-file-coding-system" | |
5948 | buffer-file-coding-system))) | |
d82979ea EZ |
5949 | |
5950 | (setq result-text | |
5951 | (allout-encrypt-string subject-text was-encrypted | |
075746e2 | 5952 | (current-buffer) keymode-cue)) |
d82979ea EZ |
5953 | |
5954 | ;; Replace the subtree with the processed product. | |
5955 | (allout-unprotected | |
5956 | (progn | |
5957 | (set-buffer allout-buffer) | |
5958 | (delete-region subtree-beg subtree-end) | |
5959 | (insert result-text) | |
5960 | (if was-collapsed | |
96b83743 EZ |
5961 | (allout-flag-region (1- subtree-beg) (point) t)) |
5962 | ;; adjust trailing-blank-lines to preserve topic spacing: | |
d82979ea | 5963 | (if (not was-encrypted) |
96b83743 EZ |
5964 | (if (and (= subtree-end-char ?\n) |
5965 | (= subtree-trailing-char ?\n)) | |
5966 | (insert subtree-trailing-char))) | |
d82979ea EZ |
5967 | ;; Ensure that the item has an encrypted-entry bullet: |
5968 | (if (not (string= (buffer-substring-no-properties | |
5969 | (1- after-bullet-pos) after-bullet-pos) | |
5970 | allout-topic-encryption-bullet)) | |
5971 | (progn (goto-char (1- after-bullet-pos)) | |
5972 | (delete-char 1) | |
5973 | (insert allout-topic-encryption-bullet))) | |
5974 | (if was-encrypted | |
5975 | ;; Remove the is-encrypted bullet qualifier: | |
5976 | (progn (goto-char after-bullet-pos) | |
5977 | (delete-char 1)) | |
5978 | ;; Add the is-encrypted bullet qualifier: | |
5979 | (goto-char after-bullet-pos) | |
d8350998 | 5980 | (insert "*")))) |
1b4d97b2 CY |
5981 | (run-hook-with-args 'allout-structure-added-hook |
5982 | bullet-pos subtree-end)))) | |
075746e2 | 5983 | ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 5984 | ;;; &optional rejected) |
075746e2 | 5985 | (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 5986 | &optional rejected) |
0949617b | 5987 | "Encrypt or decrypt message TEXT. |
d82979ea | 5988 | |
ff3e8c8e | 5989 | Returns the resulting string, or nil if the transformation fails. |
d82979ea | 5990 | |
ff3e8c8e | 5991 | If DECRYPT is true (default false), then decrypt instead of encrypt. |
d82979ea | 5992 | |
ff3e8c8e | 5993 | ALLOUT-BUFFER identifies the buffer containing the text. |
d82979ea | 5994 | |
075746e2 KM |
5995 | Entry encryption defaults to symmetric key mode unless keypair |
5996 | recipients are associated with the file \(see | |
5997 | `epa-file-encrypt-to') or the function is invoked with a | |
5998 | \(KEYMODE-CUE) universal argument greater than 1. | |
d82979ea | 5999 | |
075746e2 KM |
6000 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
6001 | causes prompting for recipients for public-key keypair | |
6002 | encryption. Selecting no recipients results in symmetric key | |
6003 | encryption. | |
0949617b | 6004 | |
075746e2 KM |
6005 | Further, encrypting with a KEYMODE-CUE universal argument greater |
6006 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
6007 | the specified recipients with the file, replacing those currently | |
6008 | associated with it. This can be used to deassociate any | |
6009 | recipients with the file, by selecting no recipients in the | |
6010 | dialog. | |
d82979ea | 6011 | |
29fac3fe | 6012 | Optional REJECTED is for internal use, to convey the number of |
48bd8440 EZ |
6013 | rejections due to matches against |
6014 | `allout-encryption-ciphertext-rejection-regexps', as limited by | |
6015 | `allout-encryption-ciphertext-rejection-ceiling'. | |
6016 | ||
2576c28f KM |
6017 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
6018 | symmetric decryption keys, preventing entry of the correct key on | |
6019 | subsequent decryption attempts until the cache times-out. That | |
6020 | can take several minutes. \(Decryption of other entries is not | |
6021 | affected.) Upgrade your EasyPG version, if you can, and you can | |
6022 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
6023 | signal." | |
48bd8440 | 6024 | |
ff3e8c8e | 6025 | (require 'epg) |
29fac3fe | 6026 | (require 'epa) |
0949617b | 6027 | |
075746e2 KM |
6028 | (let* ((epg-context (let* ((context (epg-make-context nil t))) |
6029 | (epg-context-set-passphrase-callback | |
6030 | context #'epa-passphrase-callback-function) | |
6031 | context)) | |
498a6493 CY |
6032 | (encoding (with-current-buffer allout-buffer |
6033 | buffer-file-coding-system)) | |
6034 | (multibyte (with-current-buffer allout-buffer | |
ff3e8c8e | 6035 | enable-multibyte-characters)) |
29fac3fe KM |
6036 | ;; "sanitization" avoids encryption results that are outline structure. |
6037 | (sani-regexps 'allout-encryption-plaintext-sanitization-regexps) | |
6038 | (strip-plaintext-regexps (if (not decrypt) | |
6039 | (allout-get-configvar-values | |
6040 | sani-regexps))) | |
6041 | (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps) | |
6042 | (reject-ciphertext-regexps (if (not decrypt) | |
6043 | (allout-get-configvar-values | |
6044 | rejection-regexps))) | |
48bd8440 EZ |
6045 | (rejected (or rejected 0)) |
6046 | (rejections-left (- allout-encryption-ciphertext-rejection-ceiling | |
6047 | rejected)) | |
075746e2 KM |
6048 | (keypair-mode (cond (decrypt 'decrypting) |
6049 | ((<= (prefix-numeric-value keymode-cue) 1) | |
6050 | 'default) | |
6051 | ((<= (prefix-numeric-value keymode-cue) 4) | |
6052 | 'prompt) | |
6053 | ((> (prefix-numeric-value keymode-cue) 4) | |
6054 | 'prompt-save))) | |
6055 | (keypair-message (concat "Select encryption recipients.\n" | |
6056 | "Symmetric encryption is done if no" | |
6057 | " recipients are selected. ")) | |
6058 | (encrypt-to (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to)) | |
29fac3fe KM |
6059 | recipients |
6060 | massaged-text | |
6061 | result-text | |
38b2ca53 | 6062 | ) |
0949617b | 6063 | |
ff3e8c8e KM |
6064 | ;; Massage the subject text for encoding and filtering. |
6065 | (with-temp-buffer | |
6066 | (insert text) | |
6067 | ;; convey the text characteristics of the original buffer: | |
96497653 | 6068 | (set-buffer-multibyte multibyte) |
ff3e8c8e KM |
6069 | (when encoding |
6070 | (set-buffer-file-coding-system encoding) | |
6071 | (if (not decrypt) | |
6072 | (encode-coding-region (point-min) (point-max) encoding))) | |
6073 | ||
6074 | ;; remove sanitization regexps matches before encrypting: | |
6075 | (when (and strip-plaintext-regexps (not decrypt)) | |
6076 | (dolist (re strip-plaintext-regexps) | |
6077 | (let ((re (if (listp re) (car re) re)) | |
6078 | (replacement (if (listp re) (cadr re) ""))) | |
6079 | (goto-char (point-min)) | |
6080 | (save-match-data | |
6081 | (while (re-search-forward re nil t) | |
6082 | (replace-match replacement nil nil)))))) | |
6083 | (setq massaged-text (buffer-substring-no-properties (point-min) | |
6084 | (point-max)))) | |
075746e2 KM |
6085 | ;; determine key mode and, if keypair, recipients: |
6086 | (setq recipients | |
6087 | (case keypair-mode | |
6088 | ||
6089 | (decrypting nil) | |
6090 | ||
6091 | (default (if encrypt-to (epg-list-keys epg-context encrypt-to))) | |
6092 | ||
6093 | ((prompt prompt-save) | |
6094 | (save-window-excursion | |
6095 | (epa-select-keys epg-context keypair-message))))) | |
6096 | ||
ff3e8c8e | 6097 | (setq result-text |
ff3e8c8e | 6098 | (if decrypt |
2a095cec KM |
6099 | (condition-case err |
6100 | (epg-decrypt-string epg-context | |
6101 | (encode-coding-string massaged-text | |
6102 | (or encoding 'utf-8))) | |
6103 | (epg-error | |
6104 | (signal 'egp-error | |
6105 | (cons (concat (cadr err) " - gpg version problem?") | |
6106 | (cddr err))))) | |
0af8c88b KM |
6107 | (replace-regexp-in-string "\n$" "" |
6108 | (epg-encrypt-string epg-context | |
6109 | (encode-coding-string massaged-text | |
6110 | (or encoding 'utf-8)) | |
6111 | recipients)))) | |
ff3e8c8e KM |
6112 | |
6113 | ;; validate result -- non-empty | |
075746e2 KM |
6114 | (if (not result-text) |
6115 | (error "%scryption failed." (if decrypt "De" "En"))) | |
6116 | ||
29fac3fe | 6117 | |
075746e2 KM |
6118 | (when (eq keypair-mode 'prompt-save) |
6119 | ;; set epa-file-encrypt-to in the buffer: | |
6120 | (setq epa-file-encrypt-to (mapcar (lambda (key) | |
6121 | (epg-user-id-string | |
6122 | (car (epg-key-user-id-list key)))) | |
6123 | recipients)) | |
6124 | ;; change the file variable: | |
6125 | (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to)) | |
d82979ea | 6126 | |
075746e2 | 6127 | (cond |
29fac3fe KM |
6128 | ;; Retry (within limit) if ciphertext contains rejections: |
6129 | ((and (not decrypt) | |
6130 | ;; Check for disqualification of this ciphertext: | |
6131 | (let ((regexps reject-ciphertext-regexps) | |
6132 | reject-it) | |
6133 | (while (and regexps (not reject-it)) | |
6134 | (setq reject-it (string-match (car regexps) result-text)) | |
6135 | (pop regexps)) | |
6136 | reject-it)) | |
6137 | (setq rejections-left (1- rejections-left)) | |
6138 | (if (<= rejections-left 0) | |
6139 | (error (concat "Ciphertext rejected too many times" | |
6140 | " (%s), per `%s'") | |
6141 | allout-encryption-ciphertext-rejection-ceiling | |
6142 | 'allout-encryption-ciphertext-rejection-regexps) | |
6143 | ;; try again (gpg-agent may have the key cached): | |
6144 | (allout-encrypt-string text decrypt allout-buffer keypair-mode | |
6145 | (1+ rejected)))) | |
6146 | ||
6147 | ;; Barf if encryption yields extraordinary control chars: | |
6148 | ((and (not decrypt) | |
6149 | (string-match "[\C-a\C-k\C-o-\C-z\C-@]" | |
6150 | result-text)) | |
6151 | (error (concat "Encryption produced non-armored text, which" | |
6152 | "conflicts with allout mode -- reconfigure!"))) | |
6153 | ||
6154 | (t result-text)))) | |
d82979ea EZ |
6155 | ;;;_ > allout-encrypted-topic-p () |
6156 | (defun allout-encrypted-topic-p () | |
6157 | "True if the current topic is encryptable and encrypted." | |
6158 | (save-excursion | |
6159 | (allout-end-of-prefix t) | |
6160 | (and (string= (buffer-substring-no-properties (1- (point)) (point)) | |
6161 | allout-topic-encryption-bullet) | |
2a1408fd | 6162 | (save-match-data (looking-at "\\*"))) |
d82979ea EZ |
6163 | ) |
6164 | ) | |
d82979ea EZ |
6165 | ;;;_ > allout-next-topic-pending-encryption (&optional except-mark) |
6166 | (defun allout-next-topic-pending-encryption (&optional except-mark) | |
6167 | "Return the point of the next topic pending encryption, or nil if none. | |
6168 | ||
6169 | EXCEPT-MARK identifies a point whose containing topics should be excluded | |
6170 | from encryption. This supports 'except-current mode of | |
6171 | `allout-encrypt-unencrypted-on-saves'. | |
6172 | ||
75bcb912 | 6173 | Such a topic has the `allout-topic-encryption-bullet' without an |
d82979ea EZ |
6174 | immediately following '*' that would mark the topic as being encrypted. It |
6175 | must also have content." | |
6176 | (let (done got content-beg) | |
2a1408fd DN |
6177 | (save-match-data |
6178 | (while (not done) | |
d82979ea | 6179 | |
2a1408fd DN |
6180 | (if (not (re-search-forward |
6181 | (format "\\(\\`\\|\n\\)%s *%s[^*]" | |
6182 | (regexp-quote allout-header-prefix) | |
6183 | (regexp-quote allout-topic-encryption-bullet)) | |
6184 | nil t)) | |
6185 | (setq got nil | |
6186 | done t) | |
6187 | (goto-char (setq got (match-beginning 0))) | |
6188 | (if (save-match-data (looking-at "\n")) | |
6189 | (forward-char 1)) | |
6190 | (setq got (point))) | |
6191 | ||
6192 | (cond ((not got) | |
6193 | (setq done t)) | |
6194 | ||
6195 | ((not (search-forward "\n")) | |
6196 | (setq got nil | |
6197 | done t)) | |
6198 | ||
6199 | ((eobp) | |
6200 | (setq got nil | |
6201 | done t)) | |
6202 | ||
6203 | (t | |
6204 | (setq content-beg (point)) | |
6205 | (backward-char 1) | |
6206 | (allout-end-of-subtree) | |
6207 | (if (or (<= (point) content-beg) | |
6208 | (and except-mark | |
6209 | (<= content-beg except-mark) | |
6210 | (>= (point) except-mark))) | |
6211 | ;; Continue looking | |
6212 | (setq got nil) | |
6213 | ;; Got it! | |
6214 | (setq done t))) | |
6215 | ) | |
6216 | ) | |
6217 | (if got | |
6218 | (goto-char got)) | |
d82979ea | 6219 | ) |
d82979ea EZ |
6220 | ) |
6221 | ) | |
6222 | ;;;_ > allout-encrypt-decrypted (&optional except-mark) | |
6223 | (defun allout-encrypt-decrypted (&optional except-mark) | |
6224 | "Encrypt topics pending encryption except those containing exemption point. | |
6225 | ||
6226 | EXCEPT-MARK identifies a point whose containing topics should be excluded | |
60c7bbd2 | 6227 | from encryption. This supports the `except-current' mode of |
d82979ea EZ |
6228 | `allout-encrypt-unencrypted-on-saves'. |
6229 | ||
6230 | If a topic that is currently being edited was encrypted, we return a list | |
6231 | containing the location of the topic and the location of the cursor just | |
6232 | before the topic was encrypted. This can be used, eg, to decrypt the topic | |
6233 | and exactly resituate the cursor if this is being done as part of a file | |
6234 | save. See `allout-encrypt-unencrypted-on-saves' for more info." | |
6235 | ||
6236 | (interactive "p") | |
2a1408fd DN |
6237 | (save-match-data |
6238 | (save-excursion | |
6239 | (let* ((current-mark (point-marker)) | |
6240 | (current-mark-position (marker-position current-mark)) | |
6241 | was-modified | |
6242 | bo-subtree | |
6243 | editing-topic editing-point) | |
6244 | (goto-char (point-min)) | |
6245 | (while (allout-next-topic-pending-encryption except-mark) | |
6246 | (setq was-modified (buffer-modified-p)) | |
6247 | (when (save-excursion | |
6248 | (and (boundp 'allout-encrypt-unencrypted-on-saves) | |
6249 | allout-encrypt-unencrypted-on-saves | |
6250 | (setq bo-subtree (re-search-forward "$")) | |
6251 | (not (allout-hidden-p)) | |
6252 | (>= current-mark (point)) | |
6253 | (allout-end-of-current-subtree) | |
6254 | (<= current-mark (point)))) | |
d82979ea EZ |
6255 | (setq editing-topic (point) |
6256 | ;; we had to wait for this 'til now so prior topics are | |
6257 | ;; encrypted, any relevant text shifts are in place: | |
96b83743 EZ |
6258 | editing-point (- current-mark-position |
6259 | (count-trailing-whitespace-region | |
6260 | bo-subtree current-mark-position)))) | |
2a1408fd DN |
6261 | (allout-toggle-subtree-encryption) |
6262 | (if (not was-modified) | |
6263 | (set-buffer-modified-p nil)) | |
6264 | ) | |
d82979ea EZ |
6265 | (if (not was-modified) |
6266 | (set-buffer-modified-p nil)) | |
2a1408fd | 6267 | (if editing-topic (list editing-topic editing-point)) |
d82979ea | 6268 | ) |
d82979ea EZ |
6269 | ) |
6270 | ) | |
6271 | ) | |
6272 | ||
6273 | ;;;_ #9 miscellaneous | |
d8350998 CY |
6274 | ;;;_ : Mode: |
6275 | ;;;_ > outlineify-sticky () | |
19b84ba3 | 6276 | ;; outlinify-sticky is correct spelling; provide this alias for sticklers: |
0949617b | 6277 | ;;;###autoload |
19b84ba3 | 6278 | (defalias 'outlinify-sticky 'outlineify-sticky) |
0949617b | 6279 | ;;;###autoload |
c567ac01 | 6280 | (defun outlineify-sticky (&optional arg) |
a0776d6b | 6281 | "Activate outline mode and establish file var so it is started subsequently. |
1977b8f6 | 6282 | |
11c46e15 KM |
6283 | See `allout-layout' and customization of `allout-auto-activation' |
6284 | for details on preparing emacs for automatic allout activation." | |
19b84ba3 RS |
6285 | |
6286 | (interactive "P") | |
6287 | ||
2576c28f KM |
6288 | (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate... |
6289 | (allout-mode) | |
19b84ba3 RS |
6290 | |
6291 | (save-excursion | |
6292 | (goto-char (point-min)) | |
ede4ac6a | 6293 | (if (allout-goto-prefix) |
19b84ba3 | 6294 | t |
fd5359c6 | 6295 | (allout-open-topic 2) |
60c7bbd2 | 6296 | (insert (concat "Dummy outline topic header -- see" |
d82979ea EZ |
6297 | "`allout-mode' docstring: `^Hm'.")) |
6298 | (allout-adjust-file-variable | |
4034b0e2 | 6299 | "allout-layout" (or allout-layout '(-1 : 0)))))) |
d8350998 | 6300 | ;;;_ > allout-file-vars-section-data () |
d82979ea EZ |
6301 | (defun allout-file-vars-section-data () |
6302 | "Return data identifying the file-vars section, or nil if none. | |
6303 | ||
60c7bbd2 | 6304 | Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)." |
d82979ea EZ |
6305 | ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function. |
6306 | (let (beg prefix suffix) | |
6307 | (save-excursion | |
1977b8f6 | 6308 | (goto-char (point-max)) |
d82979ea EZ |
6309 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
6310 | (if (let ((case-fold-search t)) | |
6311 | (not (search-forward "Local Variables:" nil t))) | |
6312 | nil | |
6313 | (setq beg (- (point) 16)) | |
6314 | (setq suffix (buffer-substring-no-properties | |
6315 | (point) | |
96b83743 | 6316 | (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6317 | (forward-char -1)) |
6318 | (point)))) | |
6319 | (setq prefix (buffer-substring-no-properties | |
96b83743 | 6320 | (progn (if (search-backward "\n" nil t) |
d82979ea EZ |
6321 | (forward-char 1)) |
6322 | (point)) | |
6323 | beg)) | |
6324 | (list beg prefix suffix)) | |
6325 | ) | |
6326 | ) | |
6327 | ) | |
d8350998 | 6328 | ;;;_ > allout-adjust-file-variable (varname value) |
d82979ea | 6329 | (defun allout-adjust-file-variable (varname value) |
a0a022d5 | 6330 | "Adjust the setting of an Emacs file variable named VARNAME to VALUE. |
d82979ea EZ |
6331 | |
6332 | This activity is inhibited if either `enable-local-variables' | |
6333 | `allout-enable-file-variable-adjustment' are nil. | |
6334 | ||
6335 | When enabled, an entry for the variable is created if not already present, | |
6336 | or changed if established with a different value. The section for the file | |
6337 | variables, itself, is created if not already present. When created, the | |
c07583cd | 6338 | section lines (including the section line) exist as second-level topics in |
d82979ea EZ |
6339 | a top-level topic at the end of the file. |
6340 | ||
a0a022d5 | 6341 | `enable-local-variables' must be true for any of this to happen." |
d82979ea EZ |
6342 | (if (not (and enable-local-variables |
6343 | allout-enable-file-variable-adjustment)) | |
6344 | nil | |
6345 | (save-excursion | |
0458fa80 EZ |
6346 | (let ((inhibit-field-text-motion t) |
6347 | (section-data (allout-file-vars-section-data)) | |
d82979ea EZ |
6348 | beg prefix suffix) |
6349 | (if section-data | |
6350 | (setq beg (car section-data) | |
6351 | prefix (cadr section-data) | |
6352 | suffix (car (cddr section-data))) | |
6353 | ;; create the section | |
6354 | (goto-char (point-max)) | |
6355 | (open-line 1) | |
6356 | (allout-open-topic 0) | |
6357 | (end-of-line) | |
6358 | (insert "Local emacs vars.\n") | |
6359 | (allout-open-topic 1) | |
6360 | (setq beg (point) | |
6361 | suffix "" | |
6362 | prefix (buffer-substring-no-properties (progn | |
6363 | (beginning-of-line) | |
6364 | (point)) | |
6365 | beg)) | |
6366 | (goto-char beg) | |
6367 | (insert "Local variables:\n") | |
6368 | (allout-open-topic 0) | |
6369 | (insert "End:\n") | |
6370 | ) | |
6371 | ;; look for existing entry or create one, leaving point for insertion | |
6372 | ;; of new value: | |
6373 | (goto-char beg) | |
6374 | (allout-show-to-offshoot) | |
6375 | (if (search-forward (concat "\n" prefix varname ":") nil t) | |
6376 | (let* ((value-beg (point)) | |
96b83743 | 6377 | (line-end (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6378 | (forward-char -1)) |
6379 | (point))) | |
6380 | (value-end (- line-end (length suffix)))) | |
6381 | (if (> value-end value-beg) | |
6382 | (delete-region value-beg value-end))) | |
6383 | (end-of-line) | |
6384 | (open-line 1) | |
6385 | (forward-line 1) | |
6386 | (insert (concat prefix varname ":"))) | |
6387 | (insert (format " %S%s" value suffix)) | |
6388 | ) | |
6389 | ) | |
6390 | ) | |
6391 | ) | |
d8350998 CY |
6392 | ;;;_ > allout-get-configvar-values (varname) |
6393 | (defun allout-get-configvar-values (configvar-name) | |
6394 | "Return a list of values of the symbols in list bound to CONFIGVAR-NAME. | |
6395 | ||
6396 | The user is prompted for removal of symbols that are unbound, and they | |
6397 | otherwise are ignored. | |
6398 | ||
6399 | CONFIGVAR-NAME should be the name of the configuration variable, | |
6400 | not its value." | |
6401 | ||
6402 | (let ((configvar-value (symbol-value configvar-name)) | |
6403 | got) | |
6404 | (dolist (sym configvar-value) | |
6405 | (if (not (boundp sym)) | |
60c7bbd2 | 6406 | (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? " |
d8350998 CY |
6407 | configvar-name sym)) |
6408 | (delq sym (symbol-value configvar-name))) | |
6409 | (push (symbol-value sym) got))) | |
6410 | (reverse got))) | |
6411 | ;;;_ : Topics: | |
6412 | ;;;_ > allout-mark-topic () | |
6413 | (defun allout-mark-topic () | |
6414 | "Put the region around topic currently containing point." | |
6415 | (interactive) | |
6416 | (let ((inhibit-field-text-motion t)) | |
6417 | (beginning-of-line)) | |
6418 | (allout-goto-prefix-doublechecked) | |
6419 | (push-mark (point)) | |
6420 | (allout-end-of-current-subtree) | |
6421 | (exchange-point-and-mark)) | |
6422 | ;;;_ : UI: | |
6423 | ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting) | |
1977b8f6 | 6424 | (defun solicit-char-in-string (prompt string &optional do-defaulting) |
c567ac01 | 6425 | "Solicit (with first arg PROMPT) choice of a character from string STRING. |
1977b8f6 | 6426 | |
c567ac01 | 6427 | Optional arg DO-DEFAULTING indicates to accept empty input (CR)." |
1977b8f6 RS |
6428 | |
6429 | (let ((new-prompt prompt) | |
6430 | got) | |
6431 | ||
6432 | (while (not got) | |
6433 | (message "%s" new-prompt) | |
6434 | ||
6435 | ;; We do our own reading here, so we can circumvent, eg, special | |
9179616f | 6436 | ;; treatment for `?' character. (Oughta use minibuffer keymap instead.) |
1977b8f6 | 6437 | (setq got |
c567ac01 | 6438 | (char-to-string (let ((cursor-in-echo-area nil)) (read-char)))) |
1977b8f6 | 6439 | |
9179616f DL |
6440 | (setq got |
6441 | (cond ((string-match (regexp-quote got) string) got) | |
6442 | ((and do-defaulting (string= got "\r")) | |
6443 | ;; Return empty string to default: | |
6444 | "") | |
6445 | ((string= got "\C-g") (signal 'quit nil)) | |
6446 | (t | |
6447 | (setq new-prompt (concat prompt | |
6448 | got | |
6449 | " ...pick from: " | |
6450 | string | |
6451 | "")) | |
6452 | nil)))) | |
60c7bbd2 | 6453 | ;; got something out of loop -- return it: |
9179616f | 6454 | got) |
1977b8f6 | 6455 | ) |
d8350998 CY |
6456 | ;;;_ : Strings: |
6457 | ;;;_ > regexp-sans-escapes (string) | |
c567ac01 RS |
6458 | (defun regexp-sans-escapes (regexp &optional successive-backslashes) |
6459 | "Return a copy of REGEXP with all character escapes stripped out. | |
19b84ba3 | 6460 | |
60c7bbd2 | 6461 | Representations of actual backslashes -- '\\\\\\\\' -- are left as a |
c567ac01 RS |
6462 | single backslash. |
6463 | ||
d82979ea | 6464 | Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion." |
c567ac01 RS |
6465 | |
6466 | (if (string= regexp "") | |
6467 | "" | |
6468 | ;; Set successive-backslashes to number if current char is | |
6469 | ;; backslash, or else to nil: | |
6470 | (setq successive-backslashes | |
6471 | (if (= (aref regexp 0) ?\\) | |
6472 | (if successive-backslashes (1+ successive-backslashes) 1) | |
6473 | nil)) | |
6474 | (if (or (not successive-backslashes) (= 2 successive-backslashes)) | |
6475 | ;; Include first char: | |
6476 | (concat (substring regexp 0 1) | |
6477 | (regexp-sans-escapes (substring regexp 1))) | |
6478 | ;; Exclude first char, but maintain count: | |
6479 | (regexp-sans-escapes (substring regexp 1) successive-backslashes)))) | |
d8350998 | 6480 | ;;;_ > count-trailing-whitespace-region (beg end) |
96b83743 EZ |
6481 | (defun count-trailing-whitespace-region (beg end) |
6482 | "Return number of trailing whitespace chars between BEG and END. | |
6483 | ||
6484 | If BEG is bigger than END we return 0." | |
6485 | (if (> beg end) | |
6486 | 0 | |
2a1408fd DN |
6487 | (save-match-data |
6488 | (save-excursion | |
6489 | (goto-char beg) | |
6490 | (let ((count 0)) | |
6491 | (while (re-search-forward "[ ][ ]*$" end t) | |
6492 | (goto-char (1+ (match-beginning 2))) | |
6493 | (setq count (1+ count))) | |
6494 | count))))) | |
d8350998 CY |
6495 | ;;;_ > allout-format-quote (string) |
6496 | (defun allout-format-quote (string) | |
6497 | "Return a copy of string with all \"%\" characters doubled." | |
6498 | (apply 'concat | |
6499 | (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char))) | |
6500 | string))) | |
6501 | ;;;_ : lists | |
6502 | ;;;_ > allout-flatten (list) | |
6503 | (defun allout-flatten (list) | |
6504 | "Return a list of all atoms in list." | |
6505 | ;; classic. | |
6506 | (cond ((null list) nil) | |
8a559d4e EZ |
6507 | ((atom (car list)) (cons (car list) (allout-flatten (cdr list)))) |
6508 | (t (append (allout-flatten (car list)) (allout-flatten (cdr list)))))) | |
75bcb912 | 6509 | ;;;_ : Compatibility: |
1c9b9df0 KM |
6510 | ;;;_ : xemacs undo-in-progress provision: |
6511 | (unless (boundp 'undo-in-progress) | |
6512 | (defvar undo-in-progress nil | |
6513 | "Placeholder defvar for XEmacs compatibility from allout.el.") | |
6514 | (defadvice undo-more (around allout activate) | |
6515 | ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs. | |
6516 | (let ((undo-in-progress t)) ad-do-it))) | |
6517 | ||
d8350998 | 6518 | ;;;_ > allout-mark-marker to accommodate divergent emacsen: |
96b83743 EZ |
6519 | (defun allout-mark-marker (&optional force buffer) |
6520 | "Accommodate the different signature for `mark-marker' across Emacsen. | |
6521 | ||
3bda1277 | 6522 | XEmacs takes two optional args, while Emacs does not, |
96b83743 EZ |
6523 | so pass them along when appropriate." |
6524 | (if (featurep 'xemacs) | |
6525 | (apply 'mark-marker force buffer) | |
6526 | (mark-marker))) | |
d8350998 | 6527 | ;;;_ > subst-char-in-string if necessary |
d82979ea EZ |
6528 | (if (not (fboundp 'subst-char-in-string)) |
6529 | (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
6530 | "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
6531 | Unless optional argument INPLACE is non-nil, return a new string." | |
6532 | (let ((i (length string)) | |
6533 | (newstr (if inplace string (copy-sequence string)))) | |
6534 | (while (> i 0) | |
6535 | (setq i (1- i)) | |
6536 | (if (eq (aref newstr i) fromchar) | |
6537 | (aset newstr i tochar))) | |
6538 | newstr))) | |
d8350998 | 6539 | ;;;_ > wholenump if necessary |
96b83743 EZ |
6540 | (if (not (fboundp 'wholenump)) |
6541 | (defalias 'wholenump 'natnump)) | |
d8350998 | 6542 | ;;;_ > remove-overlays if necessary |
96b83743 EZ |
6543 | (if (not (fboundp 'remove-overlays)) |
6544 | (defun remove-overlays (&optional beg end name val) | |
6545 | "Clear BEG and END of overlays whose property NAME has value VAL. | |
6546 | Overlays might be moved and/or split. | |
6547 | BEG and END default respectively to the beginning and end of buffer." | |
6548 | (unless beg (setq beg (point-min))) | |
6549 | (unless end (setq end (point-max))) | |
6550 | (if (< end beg) | |
6551 | (setq beg (prog1 end (setq end beg)))) | |
6552 | (save-excursion | |
6553 | (dolist (o (overlays-in beg end)) | |
6554 | (when (eq (overlay-get o name) val) | |
6555 | ;; Either push this overlay outside beg...end | |
6556 | ;; or split it to exclude beg...end | |
6557 | ;; or delete it entirely (if it is contained in beg...end). | |
6558 | (if (< (overlay-start o) beg) | |
6559 | (if (> (overlay-end o) end) | |
6560 | (progn | |
6561 | (move-overlay (copy-overlay o) | |
6562 | (overlay-start o) beg) | |
6563 | (move-overlay o end (overlay-end o))) | |
6564 | (move-overlay o (overlay-start o) beg)) | |
6565 | (if (> (overlay-end o) end) | |
6566 | (move-overlay o end (overlay-end o)) | |
6567 | (delete-overlay o))))))) | |
6568 | ) | |
60c7bbd2 | 6569 | ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6570 | (if (not (fboundp 'copy-overlay)) |
6571 | (defun copy-overlay (o) | |
6572 | "Return a copy of overlay O." | |
6573 | (let ((o1 (make-overlay (overlay-start o) (overlay-end o) | |
6574 | ;; FIXME: there's no easy way to find the | |
6575 | ;; insertion-type of the two markers. | |
6576 | (overlay-buffer o))) | |
6577 | (props (overlay-properties o))) | |
6578 | (while props | |
6579 | (overlay-put o1 (pop props) (pop props))) | |
6580 | o1))) | |
60c7bbd2 | 6581 | ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6582 | (if (not (fboundp 'add-to-invisibility-spec)) |
6583 | (defun add-to-invisibility-spec (element) | |
6584 | "Add ELEMENT to `buffer-invisibility-spec'. | |
6585 | See documentation for `buffer-invisibility-spec' for the kind of elements | |
6586 | that can be added." | |
6587 | (if (eq buffer-invisibility-spec t) | |
6588 | (setq buffer-invisibility-spec (list t))) | |
6589 | (setq buffer-invisibility-spec | |
6590 | (cons element buffer-invisibility-spec)))) | |
60c7bbd2 | 6591 | ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6592 | (if (not (fboundp 'remove-from-invisibility-spec)) |
6593 | (defun remove-from-invisibility-spec (element) | |
6594 | "Remove ELEMENT from `buffer-invisibility-spec'." | |
6595 | (if (consp buffer-invisibility-spec) | |
6596 | (setq buffer-invisibility-spec (delete element | |
6597 | buffer-invisibility-spec))))) | |
60c7bbd2 | 6598 | ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs |
96b83743 EZ |
6599 | (if (not (fboundp 'move-beginning-of-line)) |
6600 | (defun move-beginning-of-line (arg) | |
6601 | "Move point to beginning of current line as displayed. | |
6602 | \(This disregards invisible newlines such as those | |
6603 | which are part of the text that an image rests on.) | |
6604 | ||
6605 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6606 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6607 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6608 | (interactive "p") |
6609 | (or arg (setq arg 1)) | |
6610 | (if (/= arg 1) | |
6611 | (condition-case nil (line-move (1- arg)) (error nil))) | |
6612 | ||
8570ce80 SM |
6613 | ;; Move to beginning-of-line, ignoring fields and invisibles. |
6614 | (skip-chars-backward "^\n") | |
2a1408fd DN |
6615 | (while (and (not (bobp)) |
6616 | (let ((prop | |
6617 | (get-char-property (1- (point)) 'invisible))) | |
6618 | (if (eq buffer-invisibility-spec t) | |
6619 | prop | |
6620 | (or (memq prop buffer-invisibility-spec) | |
6621 | (assq prop buffer-invisibility-spec))))) | |
8570ce80 SM |
6622 | (goto-char (if (featurep 'xemacs) |
6623 | (previous-property-change (point)) | |
6624 | (previous-char-property-change (point)))) | |
6625 | (skip-chars-backward "^\n")) | |
6626 | (vertical-motion 0)) | |
96b83743 | 6627 | ) |
9b026d9f | 6628 | ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs |
96b83743 EZ |
6629 | (if (not (fboundp 'move-end-of-line)) |
6630 | (defun move-end-of-line (arg) | |
6631 | "Move point to end of current line as displayed. | |
6632 | \(This disregards invisible newlines such as those | |
6633 | which are part of the text that an image rests on.) | |
6634 | ||
6635 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6636 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6637 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6638 | (interactive "p") |
6639 | (or arg (setq arg 1)) | |
8570ce80 | 6640 | (let (done) |
96b83743 EZ |
6641 | (while (not done) |
6642 | (let ((newpos | |
6643 | (save-excursion | |
6644 | (let ((goal-column 0)) | |
6645 | (and (condition-case nil | |
6646 | (or (line-move arg) t) | |
6647 | (error nil)) | |
6648 | (not (bobp)) | |
6649 | (progn | |
2a1408fd DN |
6650 | (while |
6651 | (and | |
6652 | (not (bobp)) | |
6653 | (let ((prop | |
6654 | (get-char-property (1- (point)) | |
6655 | 'invisible))) | |
6656 | (if (eq buffer-invisibility-spec t) | |
6657 | prop | |
6658 | (or (memq prop | |
6659 | buffer-invisibility-spec) | |
6660 | (assq prop | |
6661 | buffer-invisibility-spec))))) | |
8570ce80 SM |
6662 | (goto-char |
6663 | (previous-char-property-change (point)))) | |
96b83743 EZ |
6664 | (backward-char 1))) |
6665 | (point))))) | |
6666 | (goto-char newpos) | |
6667 | (if (and (> (point) newpos) | |
6668 | (eq (preceding-char) ?\n)) | |
6669 | (backward-char 1) | |
6670 | (if (and (> (point) newpos) (not (eobp)) | |
6671 | (not (eq (following-char) ?\n))) | |
6672 | ;; If we skipped something intangible | |
6673 | ;; and now we're not really at eol, | |
6674 | ;; keep going. | |
6675 | (setq arg 1) | |
8570ce80 | 6676 | (setq done t))))))) |
96b83743 | 6677 | ) |
1c9b9df0 KM |
6678 | ;;;_ > allout-next-single-char-property-change -- alias unless lacking |
6679 | (defalias 'allout-next-single-char-property-change | |
6680 | (if (fboundp 'next-single-char-property-change) | |
6681 | 'next-single-char-property-change | |
6682 | 'next-single-property-change) | |
6683 | ;; No docstring because xemacs defalias doesn't support it. | |
6684 | ) | |
6685 | ;;;_ > allout-previous-single-char-property-change -- alias unless lacking | |
6686 | (defalias 'allout-previous-single-char-property-change | |
6687 | (if (fboundp 'previous-single-char-property-change) | |
6688 | 'previous-single-char-property-change | |
6689 | 'previous-single-property-change) | |
6690 | ;; No docstring because xemacs defalias doesn't support it. | |
6691 | ) | |
1c9b9df0 KM |
6692 | ;;;_ > allout-select-safe-coding-system |
6693 | (defalias 'allout-select-safe-coding-system | |
6694 | (if (fboundp 'select-safe-coding-system) | |
6695 | 'select-safe-coding-system | |
6696 | 'detect-coding-region) | |
6697 | ) | |
6698 | ;;;_ > allout-substring-no-properties | |
6699 | ;; define as alias first, so byte compiler is happy. | |
6700 | (defalias 'allout-substring-no-properties 'substring-no-properties) | |
6701 | ;; then supplant with definition if underlying alias absent. | |
6702 | (if (not (fboundp 'substring-no-properties)) | |
6703 | (defun allout-substring-no-properties (string &optional start end) | |
6704 | (substring string (or start 0) end)) | |
6705 | ) | |
96b83743 | 6706 | |
96b83743 | 6707 | ;;;_ #10 Unfinished |
fd5359c6 MR |
6708 | ;;;_ > allout-bullet-isearch (&optional bullet) |
6709 | (defun allout-bullet-isearch (&optional bullet) | |
c07583cd | 6710 | "Isearch (regexp) for topic with bullet BULLET." |
c567ac01 RS |
6711 | (interactive) |
6712 | (if (not bullet) | |
6713 | (setq bullet (solicit-char-in-string | |
6714 | "ISearch for topic with bullet: " | |
fd5359c6 | 6715 | (regexp-sans-escapes allout-bullets-string)))) |
353e2ef2 | 6716 | |
c567ac01 RS |
6717 | (let ((isearch-regexp t) |
6718 | (isearch-string (concat "^" | |
fd5359c6 | 6719 | allout-header-prefix |
c567ac01 RS |
6720 | "[ \t]*" |
6721 | bullet))) | |
6722 | (isearch-repeat 'forward) | |
6723 | (isearch-mode t))) | |
96b83743 | 6724 | |
60c7bbd2 | 6725 | ;;;_ #11 Unit tests -- this should be last item before "Provide" |
01fc9422 EZ |
6726 | ;;;_ > allout-run-unit-tests () |
6727 | (defun allout-run-unit-tests () | |
6728 | "Run the various allout unit tests." | |
6729 | (message "Running allout tests...") | |
6730 | (allout-test-resumptions) | |
6731 | (message "Running allout tests... Done.") | |
6732 | (sit-for .5)) | |
6733 | ;;;_ : test resumptions: | |
6734 | ;;;_ > allout-tests-obliterate-variable (name) | |
6735 | (defun allout-tests-obliterate-variable (name) | |
6736 | "Completely unbind variable with NAME." | |
1c9b9df0 | 6737 | (if (local-variable-p name (current-buffer)) (kill-local-variable name)) |
01fc9422 EZ |
6738 | (while (boundp name) (makunbound name))) |
6739 | ;;;_ > allout-test-resumptions () | |
6740 | (defvar allout-tests-globally-unbound nil | |
60c7bbd2 | 6741 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6742 | (defvar allout-tests-globally-true nil |
60c7bbd2 | 6743 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6744 | (defvar allout-tests-locally-true nil |
60c7bbd2 | 6745 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 EZ |
6746 | (defun allout-test-resumptions () |
6747 | "Exercise allout resumptions." | |
6748 | ;; for each resumption case, we also test that the right local/global | |
6749 | ;; scopes are affected during resumption effects: | |
6750 | ||
6751 | ;; ensure that previously unbound variables return to the unbound state. | |
6752 | (with-temp-buffer | |
6753 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6754 | (allout-add-resumptions '(allout-tests-globally-unbound t)) | |
6755 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6756 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6757 | (assert (boundp 'allout-tests-globally-unbound)) |
6758 | (assert (equal allout-tests-globally-unbound t)) | |
6759 | (allout-do-resumptions) | |
1c9b9df0 KM |
6760 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6761 | (current-buffer)))) | |
01fc9422 EZ |
6762 | (assert (not (boundp 'allout-tests-globally-unbound)))) |
6763 | ||
6764 | ;; ensure that variable with prior global value is resumed | |
6765 | (with-temp-buffer | |
6766 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6767 | (setq allout-tests-globally-true t) | |
6768 | (allout-add-resumptions '(allout-tests-globally-true nil)) | |
6769 | (assert (equal (default-value 'allout-tests-globally-true) t)) | |
1c9b9df0 | 6770 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6771 | (assert (equal allout-tests-globally-true nil)) |
6772 | (allout-do-resumptions) | |
1c9b9df0 KM |
6773 | (assert (not (local-variable-p 'allout-tests-globally-true |
6774 | (current-buffer)))) | |
01fc9422 EZ |
6775 | (assert (boundp 'allout-tests-globally-true)) |
6776 | (assert (equal allout-tests-globally-true t))) | |
6777 | ||
6778 | ;; ensure that prior local value is resumed | |
6779 | (with-temp-buffer | |
6780 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6781 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6782 | (assert (not (default-boundp 'allout-tests-locally-true)) | |
60c7bbd2 | 6783 | nil (concat "Test setup mistake -- variable supposed to" |
01fc9422 | 6784 | " not have global binding, but it does.")) |
1c9b9df0 | 6785 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer)) |
60c7bbd2 | 6786 | nil (concat "Test setup mistake -- variable supposed to have" |
01fc9422 EZ |
6787 | " local binding, but it lacks one.")) |
6788 | (allout-add-resumptions '(allout-tests-locally-true nil)) | |
6789 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6790 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6791 | (assert (equal allout-tests-locally-true nil)) |
6792 | (allout-do-resumptions) | |
6793 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6794 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6795 | (assert (equal allout-tests-locally-true t)) |
6796 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6797 | ||
6798 | ;; ensure that last of multiple resumptions holds, for various scopes. | |
6799 | (with-temp-buffer | |
6800 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6801 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6802 | (setq allout-tests-globally-true t) | |
6803 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6804 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6805 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6806 | '(allout-tests-globally-true nil) | |
6807 | '(allout-tests-locally-true nil)) | |
6808 | (allout-add-resumptions '(allout-tests-globally-unbound 2) | |
6809 | '(allout-tests-globally-true 3) | |
6810 | '(allout-tests-locally-true 4)) | |
6811 | ;; reestablish many of the basic conditions are maintained after re-add: | |
6812 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6813 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6814 | (assert (equal allout-tests-globally-unbound 2)) |
6815 | (assert (default-boundp 'allout-tests-globally-true)) | |
1c9b9df0 | 6816 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6817 | (assert (equal allout-tests-globally-true 3)) |
6818 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6819 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6820 | (assert (equal allout-tests-locally-true 4)) |
6821 | (allout-do-resumptions) | |
1c9b9df0 KM |
6822 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6823 | (current-buffer)))) | |
01fc9422 | 6824 | (assert (not (boundp 'allout-tests-globally-unbound))) |
1c9b9df0 KM |
6825 | (assert (not (local-variable-p 'allout-tests-globally-true |
6826 | (current-buffer)))) | |
01fc9422 EZ |
6827 | (assert (boundp 'allout-tests-globally-true)) |
6828 | (assert (equal allout-tests-globally-true t)) | |
6829 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6830 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6831 | (assert (equal allout-tests-locally-true t)) |
6832 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6833 | ||
6834 | ;; ensure that deliberately unbinding registered variables doesn't foul things | |
6835 | (with-temp-buffer | |
6836 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6837 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6838 | (setq allout-tests-globally-true t) | |
6839 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6840 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6841 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6842 | '(allout-tests-globally-true nil) | |
6843 | '(allout-tests-locally-true nil)) | |
6844 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6845 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6846 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6847 | (allout-do-resumptions)) | |
6848 | ) | |
6849 | ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true: | |
6850 | (when allout-run-unit-tests-on-load | |
6851 | (allout-run-unit-tests)) | |
6852 | ||
6853 | ;;;_ #12 Provide | |
96b83743 | 6854 | (provide 'allout) |
1977b8f6 RS |
6855 | |
6856 | ;;;_* Local emacs vars. | |
31468dcb SM |
6857 | ;; The following `allout-layout' local variable setting: |
6858 | ;; - closes all topics from the first topic to just before the third-to-last, | |
6859 | ;; - shows the children of the third to last (config vars) | |
6860 | ;; - and the second to last (code section), | |
6861 | ;; - and closes the last topic (this local-variables section). | |
6862 | ;;Local variables: | |
6863 | ;;allout-layout: (0 : -1 -1 0) | |
6864 | ;;End: | |
6865 | ||
6a05d05f | 6866 | ;;; allout.el ends here |