Commit | Line | Data |
---|---|---|
6a05d05f | 1 | ;;; allout.el --- extensive outline mode for use alone and with other modes |
19b84ba3 | 2 | |
ab422c4d | 3 | ;; Copyright (C) 1992-1994, 2001-2013 Free Software Foundation, Inc. |
1977b8f6 | 4 | |
8642c216 KM |
5 | ;; Author: Ken Manheimer <ken dot manheimer at gmail...> |
6 | ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...> | |
60c7bbd2 | 7 | ;; Created: Dec 1991 -- first release to usenet |
0af8c88b | 8 | ;; Version: 2.3 |
96497653 | 9 | ;; Keywords: outlines, wp, languages, PGP, GnuPG |
8642c216 | 10 | ;; Website: http://myriadicity.net/software-and-systems/craft/emacs-allout |
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 |
08cf18e4 GM |
80 | ;; `cl' is required for `assert'. `assert' is not covered by a standard |
81 | ;; autoload, but it is a macro, so that eval-when-compile is sufficient | |
82 | ;; to byte-compile it in, or to do the require when the buffer evalled. | |
83 | (require 'cl) | |
84 | ) | |
d82979ea | 85 | |
19b84ba3 | 86 | ;;;_* USER CUSTOMIZATION VARIABLES: |
96b83743 | 87 | |
1c9b9df0 | 88 | ;;;_ > defgroup allout, allout-keybindings |
4bef9110 | 89 | (defgroup allout nil |
96497653 KM |
90 | "Extensive outline minor-mode, for use stand-alone and with other modes. |
91 | ||
92 | See Allout Auto Activation for automatic activation." | |
fd5359c6 | 93 | :prefix "allout-" |
d82979ea | 94 | :group 'outlines) |
1c9b9df0 KM |
95 | (defgroup allout-keybindings nil |
96 | "Allout outline mode keyboard bindings configuration." | |
97 | :group 'allout) | |
19b84ba3 RS |
98 | |
99 | ;;;_ + Layout, Mode, and Topic Header Configuration | |
100 | ||
08b5f072 | 101 | (defvar allout-command-prefix) ; defined below |
08b5f072 | 102 | |
1c9b9df0 | 103 | ;;;_ > allout-keybindings incidentals: |
d3e51865 KM |
104 | ;;;_ : internal key binding stuff - in this section for load-order. |
105 | ;;;_ = allout-mode-map | |
106 | (defvar allout-mode-map 'allout-mode-map | |
107 | "Keybindings place-holder for (allout) outline minor mode. | |
108 | ||
109 | Do NOT set the value of this variable. Instead, customize | |
110 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
111 | `allout-unprefixed-keybindings'.") | |
112 | ;;;_ = allout-mode-map-value | |
113 | (defvar allout-mode-map-value nil | |
114 | "Keymap for allout outline minor mode. | |
115 | ||
116 | Do NOT set the value of this variable. Instead, customize | |
117 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
118 | `allout-unprefixed-keybindings'.") | |
119 | ;;;_ = make allout-mode-map-value an alias for allout-mode-map: | |
120 | ;; this needs to be revised when the value is changed, sigh. | |
121 | (defalias 'allout-mode-map allout-mode-map-value) | |
122 | ;;;_ > allout-compose-and-institute-keymap (&optional varname value) | |
123 | (defun allout-compose-and-institute-keymap (&optional varname value) | |
124 | "Create the allout keymap according to the keybinding specs, and set it. | |
125 | ||
126 | Useful standalone or to effect customizations of the | |
1c9b9df0 KM |
127 | respective allout-mode keybinding variables, `allout-command-prefix', |
128 | `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'" | |
129 | ;; Set the customization variable, if any: | |
130 | (when varname | |
131 | (set-default varname value)) | |
d3e51865 | 132 | (let ((map (make-sparse-keymap))) |
1c9b9df0 | 133 | (when (boundp 'allout-prefixed-keybindings) |
d3e51865 | 134 | ;; tolerate first definitions of the variables: |
1c9b9df0 KM |
135 | (dolist (entry allout-prefixed-keybindings) |
136 | (define-key map | |
137 | ;; XXX vector vs non-vector key descriptions? | |
138 | (vconcat allout-command-prefix | |
139 | (car (read-from-string (car entry)))) | |
140 | (cadr entry)))) | |
141 | (when (boundp 'allout-unprefixed-keybindings) | |
142 | (dolist (entry allout-unprefixed-keybindings) | |
143 | (define-key map (car (read-from-string (car entry))) (cadr entry)))) | |
d3e51865 KM |
144 | (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line |
145 | map global-map) | |
146 | (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line | |
147 | map global-map) | |
148 | (substitute-key-definition 'end-of-line 'allout-end-of-line | |
149 | map global-map) | |
150 | (substitute-key-definition 'move-end-of-line 'allout-end-of-line | |
151 | map global-map) | |
152 | (allout-institute-keymap map))) | |
153 | ;;;_ > allout-institute-keymap (map) | |
154 | (defun allout-institute-keymap (map) | |
155 | "Associate allout-mode bindings with allout as a minor mode." | |
156 | ;; Architecture: | |
157 | ;; allout-mode-map var is a keymap by virtue of being a defalias for | |
158 | ;; allout-mode-map-value, which has the actual keymap value. | |
159 | ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be | |
160 | ;; used in minor-mode-map-alist to indirect to the actual | |
161 | ;; allout-mode-map-var value, which can be adjusted and reassigned. | |
162 | ||
642f3c5c | 163 | ;; allout-mode-map-value for keymap reference in various places: |
d3e51865 | 164 | (setq allout-mode-map-value map) |
642f3c5c KM |
165 | ;; the function value keymap of allout-mode-map is used in |
166 | ;; minor-mode-map-alist - update it: | |
167 | (fset allout-mode-map allout-mode-map-value)) | |
cd1181db | 168 | ;;;_ * initialize the mode map: |
d3e51865 KM |
169 | ;; ensure that allout-mode-map has some setting even if allout-mode hasn't |
170 | ;; been invoked: | |
171 | (allout-compose-and-institute-keymap) | |
1c9b9df0 | 172 | ;;;_ = allout-command-prefix |
2a1408fd | 173 | (defcustom allout-command-prefix "\C-c " |
9201cc28 | 174 | "Key sequence to be used as prefix for outline mode command key bindings. |
2a1408fd DN |
175 | |
176 | Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're | |
177 | willing to let allout use a bunch of \C-c keybindings." | |
178 | :type 'string | |
1c9b9df0 | 179 | :group 'allout-keybindings |
d3e51865 | 180 | :set 'allout-compose-and-institute-keymap) |
1c9b9df0 KM |
181 | ;;;_ = allout-keybindings-binding |
182 | (define-widget 'allout-keybindings-binding 'lazy | |
183 | "Structure of allout keybindings customization items." | |
184 | :type '(repeat | |
185 | (list (string :tag "Key" :value "[(meta control shift ?f)]") | |
186 | (function :tag "Function name" | |
187 | :value allout-forward-current-level)))) | |
188 | ;;;_ = allout-prefixed-keybindings | |
189 | (defcustom allout-prefixed-keybindings | |
190 | '(("[(control ?n)]" allout-next-visible-heading) | |
191 | ("[(control ?p)]" allout-previous-visible-heading) | |
d3e51865 | 192 | ("[(control ?u)]" allout-up-current-level) |
1c9b9df0 KM |
193 | ("[(control ?f)]" allout-forward-current-level) |
194 | ("[(control ?b)]" allout-backward-current-level) | |
195 | ("[(control ?a)]" allout-beginning-of-current-entry) | |
196 | ("[(control ?e)]" allout-end-of-entry) | |
197 | ("[(control ?i)]" allout-show-children) | |
1c9b9df0 KM |
198 | ("[(control ?s)]" allout-show-current-subtree) |
199 | ("[(control ?t)]" allout-toggle-current-subtree-exposure) | |
d3e51865 KM |
200 | ;; Let user customize if they want to preempt describe-prefix-bindings ^h use. |
201 | ;; ("[(control ?h)]" allout-hide-current-subtree) | |
1c9b9df0 KM |
202 | ("[?h]" allout-hide-current-subtree) |
203 | ("[(control ?o)]" allout-show-current-entry) | |
204 | ("[?!]" allout-show-all) | |
205 | ("[?x]" allout-toggle-current-subtree-encryption) | |
206 | ("[? ]" allout-open-sibtopic) | |
207 | ("[?.]" allout-open-subtopic) | |
208 | ("[?,]" allout-open-supertopic) | |
209 | ("[?']" allout-shift-in) | |
210 | ("[?>]" allout-shift-in) | |
211 | ("[?<]" allout-shift-out) | |
212 | ("[(control ?m)]" allout-rebullet-topic) | |
213 | ("[?*]" allout-rebullet-current-heading) | |
4936e3ba | 214 | ("[?#]" allout-number-siblings) |
1c9b9df0 | 215 | ("[(control ?k)]" allout-kill-topic) |
d3e51865 | 216 | ("[(meta ?k)]" allout-copy-topic-as-kill) |
1c9b9df0 KM |
217 | ("[?@]" allout-resolve-xref) |
218 | ("[?=?c]" allout-copy-exposed-to-buffer) | |
219 | ("[?=?i]" allout-indented-exposed-to-buffer) | |
220 | ("[?=?t]" allout-latexify-exposed) | |
221 | ("[?=?p]" allout-flatten-exposed-to-buffer) | |
222 | ) | |
223 | "Allout-mode key bindings that are prefixed with `allout-command-prefix'. | |
224 | ||
225 | See `allout-unprefixed-keybindings' for the list of keybindings | |
226 | that are not prefixed. | |
227 | ||
228 | Use vector format for the keys: | |
229 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
230 | - enclose control, shift, or meta-modified keys as sequences within | |
231 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 232 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 KM |
233 | See the existing keys for examples. |
234 | ||
235 | Functions can be bound to multiple keys, but binding keys to | |
236 | multiple functions will not work - the last binding for a key | |
237 | prevails." | |
2bed3f04 | 238 | :version "24.1" |
1c9b9df0 KM |
239 | :type 'allout-keybindings-binding |
240 | :group 'allout-keybindings | |
d3e51865 | 241 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
242 | ) |
243 | ;;;_ = allout-unprefixed-keybindings | |
244 | (defcustom allout-unprefixed-keybindings | |
245 | '(("[(control ?k)]" allout-kill-line) | |
d3e51865 | 246 | ("[(meta ?k)]" allout-copy-line-as-kill) |
1c9b9df0 | 247 | ("[(control ?y)]" allout-yank) |
d3e51865 | 248 | ("[(meta ?y)]" allout-yank-pop) |
1c9b9df0 KM |
249 | ) |
250 | "Allout-mode functions bound to keys without any added prefix. | |
251 | ||
252 | This is in contrast to the majority of allout-mode bindings on | |
253 | `allout-prefixed-bindings', whose bindings are created with a | |
0d327994 | 254 | preceding command key. |
1c9b9df0 KM |
255 | |
256 | Use vector format for the keys: | |
257 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
258 | - enclose control, shift, or meta-modified keys as sequences within | |
259 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 260 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 | 261 | See the existing keys for examples." |
2bed3f04 | 262 | :version "24.1" |
1c9b9df0 KM |
263 | :type 'allout-keybindings-binding |
264 | :group 'allout-keybindings | |
d3e51865 | 265 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
266 | ) |
267 | ||
11c46e15 KM |
268 | ;;;_ > allout-auto-activation-helper (var value) |
269 | ;;;###autoload | |
270 | (defun allout-auto-activation-helper (var value) | |
271 | "Institute `allout-auto-activation'. | |
272 | ||
273 | Intended to be used as the `allout-auto-activation' :set function." | |
274 | (set-default var value) | |
275 | (allout-setup)) | |
276 | ;;;_ > allout-setup () | |
277 | ;;;###autoload | |
278 | (defun allout-setup () | |
20db1522 | 279 | "Do fundamental Emacs session for allout auto-activation. |
11c46e15 KM |
280 | |
281 | Establishes allout processing as part of visiting a file if | |
282 | `allout-auto-activation' is non-nil, or removes it otherwise. | |
283 | ||
284 | The proper way to use this is through customizing the setting of | |
285 | `allout-auto-activation'." | |
286 | (if (not allout-auto-activation) | |
287 | (remove-hook 'find-file-hook 'allout-find-file-hook) | |
288 | (add-hook 'find-file-hook 'allout-find-file-hook))) | |
fd5359c6 | 289 | ;;;_ = allout-auto-activation |
11c46e15 | 290 | ;;;###autoload |
fd5359c6 | 291 | (defcustom allout-auto-activation nil |
11c46e15 | 292 | "Configure allout outline mode auto-activation. |
19b84ba3 | 293 | |
11c46e15 KM |
294 | Control whether and how allout outline mode is automatically |
295 | activated when files are visited with non-nil buffer-specific | |
296 | file variable `allout-layout'. | |
19b84ba3 | 297 | |
20db1522 | 298 | When allout-auto-activation is \"On\" (t), allout mode is |
11c46e15 KM |
299 | activated in buffers with non-nil `allout-layout', and the |
300 | specified layout is applied. | |
19b84ba3 | 301 | |
11c46e15 | 302 | With value \"ask\", auto-mode-activation is enabled, and endorsement for |
19b84ba3 RS |
303 | performing auto-layout is asked of the user each time. |
304 | ||
11c46e15 KM |
305 | With value \"activate\", only auto-mode-activation is enabled. |
306 | Auto-layout is not. | |
19b84ba3 | 307 | |
96497653 | 308 | With value nil, inhibit any automatic allout-mode activation." |
11c46e15 | 309 | :set 'allout-auto-activation-helper |
c6eee9aa | 310 | ;; FIXME: Using strings here is unusual and less efficient than symbols. |
9179616f DL |
311 | :type '(choice (const :tag "On" t) |
312 | (const :tag "Ask about layout" "ask") | |
313 | (const :tag "Mode only" "activate") | |
314 | (const :tag "Off" nil)) | |
315 | :group 'allout) | |
11c46e15 | 316 | (allout-setup) |
4034b0e2 LT |
317 | ;;;_ = allout-default-layout |
318 | (defcustom allout-default-layout '(-2 : 0) | |
9201cc28 | 319 | "Default allout outline layout specification. |
4034b0e2 LT |
320 | |
321 | This setting specifies the outline exposure to use when | |
322 | `allout-layout' has the local value `t'. This docstring describes the | |
323 | layout specifications. | |
324 | ||
325 | A list value specifies a default layout for the current buffer, | |
326 | to be applied upon activation of `allout-mode'. Any non-nil | |
327 | value will automatically trigger `allout-mode', provided | |
11c46e15 | 328 | `allout-auto-activation' has been customized to enable it. |
4034b0e2 LT |
329 | |
330 | The types of elements in the layout specification are: | |
331 | ||
60c7bbd2 RS |
332 | INTEGER -- dictate the relative depth to open the corresponding topic(s), |
333 | where: | |
334 | -- negative numbers force the topic to be closed before opening | |
335 | to the absolute value of the number, so all siblings are open | |
336 | only to that level. | |
337 | -- positive numbers open to the relative depth indicated by the | |
338 | number, but do not force already opened subtopics to be closed. | |
339 | -- 0 means to close topic -- hide all subitems. | |
97610156 | 340 | : -- repeat spec -- apply the preceding element to all siblings at |
60c7bbd2 RS |
341 | current level, *up to* those siblings that would be covered by specs |
342 | following the `:' on the list. Ie, apply to all topics at level but | |
343 | trailing ones accounted for by trailing specs. (Only the first of | |
344 | multiple colons at the same level is honored -- later ones are ignored.) | |
345 | * -- completely exposes the topic, including bodies | |
346 | + -- exposes all subtopics, but not the bodies | |
347 | - -- exposes the body of the corresponding topic, but not subtopics | |
348 | LIST -- a nested layout spec, to be applied intricately to its | |
4034b0e2 | 349 | corresponding item(s) |
1977b8f6 | 350 | |
4034b0e2 | 351 | Examples: |
60c7bbd2 | 352 | (-2 : 0) |
4034b0e2 LT |
353 | Collapse the top-level topics to show their children and |
354 | grandchildren, but completely collapse the final top-level topic. | |
60c7bbd2 | 355 | (-1 () : 1 0) |
4034b0e2 LT |
356 | Close the first topic so only the immediate subtopics are shown, |
357 | leave the subsequent topics exposed as they are until the second | |
358 | second to last topic, which is exposed at least one level, and | |
359 | completely close the last topic. | |
60c7bbd2 | 360 | (-2 : -1 *) |
4034b0e2 LT |
361 | Expose children and grandchildren of all topics at current |
362 | level except the last two; expose children of the second to | |
363 | last and completely expose the last one, including its subtopics. | |
19b84ba3 | 364 | |
4034b0e2 | 365 | See `allout-expose-topic' for more about the exposure process. |
19b84ba3 | 366 | |
353e2ef2 KH |
367 | Also, allout's mode-specific provisions will make topic prefixes default |
368 | to the comment-start string, if any, of the language of the file. This | |
4034b0e2 LT |
369 | is modulo the setting of `allout-use-mode-specific-leader', which see." |
370 | :type 'allout-layout-type | |
371 | :group 'allout) | |
372 | ;;;_ : allout-layout-type | |
373 | (define-widget 'allout-layout-type 'lazy | |
374 | "Allout layout format customization basic building blocks." | |
375 | :type '(repeat | |
376 | (choice (integer :tag "integer (<= zero is strict)") | |
377 | (const :tag ": (repeat prior)" :) | |
378 | (const :tag "* (completely expose)" *) | |
379 | (const :tag "+ (expose all offspring, headlines only)" +) | |
380 | (const :tag "- (expose topic body but not offspring)" -) | |
381 | (allout-layout-type :tag "<Nested layout>")))) | |
382 | ||
2a1408fd DN |
383 | ;;;_ = allout-inhibit-auto-fill |
384 | (defcustom allout-inhibit-auto-fill nil | |
9201cc28 | 385 | "If non-nil, auto-fill will be inhibited in the allout buffers. |
2a1408fd DN |
386 | |
387 | You can customize this setting to set it for all allout buffers, or set it | |
388 | in individual buffers if you want to inhibit auto-fill only in particular | |
389 | buffers. (You could use a function on `allout-mode-hook' to inhibit | |
390 | auto-fill according, eg, to the major mode.) | |
391 | ||
392 | If you don't set this and auto-fill-mode is enabled, allout will use the | |
393 | value that `normal-auto-fill-function', if any, when allout mode starts, or | |
394 | else allout's special hanging-indent maintaining auto-fill function, | |
395 | `allout-auto-fill'." | |
396 | :type 'boolean | |
397 | :group 'allout) | |
398 | (make-variable-buffer-local 'allout-inhibit-auto-fill) | |
381987c3 KM |
399 | ;;;_ = allout-inhibit-auto-fill-on-headline |
400 | (defcustom allout-inhibit-auto-fill-on-headline nil | |
401 | "If non-nil, auto-fill will be inhibited while on topic's header line." | |
2bed3f04 | 402 | :version "24.1" |
381987c3 KM |
403 | :type 'boolean |
404 | :group 'allout) | |
405 | (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline) | |
2a1408fd DN |
406 | ;;;_ = allout-use-hanging-indents |
407 | (defcustom allout-use-hanging-indents t | |
9201cc28 | 408 | "If non-nil, topic body text auto-indent defaults to indent of the header. |
2a1408fd | 409 | Ie, it is indented to be just past the header prefix. This is |
8dd59f01 | 410 | relevant mostly for use with `indented-text-mode', or other situations |
2a1408fd DN |
411 | where auto-fill occurs." |
412 | :type 'boolean | |
413 | :group 'allout) | |
414 | (make-variable-buffer-local 'allout-use-hanging-indents) | |
415 | ;;;###autoload | |
416 | (put 'allout-use-hanging-indents 'safe-local-variable | |
4f91a816 | 417 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
2a1408fd DN |
418 | ;;;_ = allout-reindent-bodies |
419 | (defcustom allout-reindent-bodies (if allout-use-hanging-indents | |
420 | 'text) | |
9201cc28 | 421 | "Non-nil enables auto-adjust of topic body hanging indent with depth shifts. |
2a1408fd DN |
422 | |
423 | When active, topic body lines that are indented even with or beyond | |
424 | their topic header are reindented to correspond with depth shifts of | |
425 | the header. | |
426 | ||
427 | A value of t enables reindent in non-programming-code buffers, ie | |
428 | those that do not have the variable `comment-start' set. A value of | |
429 | `force' enables reindent whether or not `comment-start' is set." | |
430 | :type '(choice (const nil) (const t) (const text) (const force)) | |
431 | :group 'allout) | |
432 | ||
433 | (make-variable-buffer-local 'allout-reindent-bodies) | |
434 | ;;;###autoload | |
435 | (put 'allout-reindent-bodies 'safe-local-variable | |
4f91a816 | 436 | (lambda (x) (memq x '(nil t text force)))) |
2a1408fd | 437 | |
fd5359c6 MR |
438 | ;;;_ = allout-show-bodies |
439 | (defcustom allout-show-bodies nil | |
9201cc28 | 440 | "If non-nil, show entire body when exposing a topic, rather than |
9179616f DL |
441 | just the header." |
442 | :type 'boolean | |
443 | :group 'allout) | |
fd5359c6 | 444 | (make-variable-buffer-local 'allout-show-bodies) |
8570ce80 SM |
445 | ;;;###autoload |
446 | (put 'allout-show-bodies 'safe-local-variable | |
4f91a816 | 447 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 448 | |
48bd8440 EZ |
449 | ;;;_ = allout-beginning-of-line-cycles |
450 | (defcustom allout-beginning-of-line-cycles t | |
9201cc28 | 451 | "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
452 | |
453 | Cycling only happens on when the command is repeated, not when it | |
454 | follows a different command. | |
455 | ||
456 | Smart-placement means that repeated calls to this function will | |
457 | advance as follows: | |
458 | ||
459 | - if the cursor is on a non-headline body line and not on the first column: | |
460 | then it goes to the first column | |
461 | - if the cursor is on the first column of a non-headline body line: | |
462 | then it goes to the start of the headline within the item body | |
463 | - if the cursor is on the headline and not the start of the headline: | |
464 | then it goes to the start of the headline | |
465 | - if the cursor is on the start of the headline: | |
c07583cd | 466 | then it goes to the bullet character (for hotspot navigation) |
48bd8440 | 467 | - if the cursor is on the bullet character: |
c07583cd | 468 | then it goes to the first column of that line (the headline) |
48bd8440 EZ |
469 | - if the cursor is on the first column of the headline: |
470 | then it goes to the start of the headline within the item body. | |
471 | ||
472 | In this fashion, you can use the beginning-of-line command to do | |
473 | its normal job and then, when repeated, advance through the | |
474 | entry, cycling back to start. | |
475 | ||
476 | If this configuration variable is nil, then the cursor is just | |
477 | advanced to the beginning of the line and remains there on | |
478 | repeated calls." | |
479 | :type 'boolean :group 'allout) | |
480 | ;;;_ = allout-end-of-line-cycles | |
481 | (defcustom allout-end-of-line-cycles t | |
9201cc28 | 482 | "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
483 | |
484 | Cycling only happens on when the command is repeated, not when it | |
485 | follows a different command. | |
486 | ||
60c7bbd2 | 487 | Smart placement means that repeated calls to this function will |
48bd8440 EZ |
488 | advance as follows: |
489 | ||
490 | - if the cursor is not on the end-of-line, | |
491 | then it goes to the end-of-line | |
492 | - if the cursor is on the end-of-line but not the end-of-entry, | |
493 | then it goes to the end-of-entry, exposing it if necessary | |
494 | - if the cursor is on the end-of-entry, | |
495 | then it goes to the end of the head line | |
496 | ||
497 | In this fashion, you can use the end-of-line command to do its | |
498 | normal job and then, when repeated, advance through the entry, | |
499 | cycling back to start. | |
500 | ||
501 | If this configuration variable is nil, then the cursor is just | |
502 | advanced to the end of the line and remains there on repeated | |
503 | calls." | |
504 | :type 'boolean :group 'allout) | |
505 | ||
fd5359c6 MR |
506 | ;;;_ = allout-header-prefix |
507 | (defcustom allout-header-prefix "." | |
48bd8440 EZ |
508 | ;; this string is treated as literal match. it will be `regexp-quote'd, so |
509 | ;; one cannot use regular expressions to match varying header prefixes. | |
9201cc28 | 510 | "Leading string which helps distinguish topic headers. |
19b84ba3 RS |
511 | |
512 | Outline topic header lines are identified by a leading topic | |
c567ac01 | 513 | header prefix, which mostly have the value of this var at their front. |
48bd8440 EZ |
514 | Level 1 topics are exceptions. They consist of only a single |
515 | character, which is typically set to the `allout-primary-bullet'." | |
4bef9110 SE |
516 | :type 'string |
517 | :group 'allout) | |
fd5359c6 | 518 | (make-variable-buffer-local 'allout-header-prefix) |
8570ce80 SM |
519 | ;;;###autoload |
520 | (put 'allout-header-prefix 'safe-local-variable 'stringp) | |
fd5359c6 MR |
521 | ;;;_ = allout-primary-bullet |
522 | (defcustom allout-primary-bullet "*" | |
19b84ba3 RS |
523 | "Bullet used for top-level outline topics. |
524 | ||
525 | Outline topic header lines are identified by a leading topic header | |
c567ac01 | 526 | prefix, which is concluded by bullets that includes the value of this |
fd5359c6 | 527 | var and the respective allout-*-bullets-string vars. |
c567ac01 | 528 | |
353e2ef2 | 529 | The value of an asterisk (`*') provides for backwards compatibility |
e126900f | 530 | with the original Emacs outline mode. See `allout-plain-bullets-string' |
2265e017 | 531 | and `allout-distinctive-bullets-string' for the range of available |
4bef9110 SE |
532 | bullets." |
533 | :type 'string | |
534 | :group 'allout) | |
fd5359c6 | 535 | (make-variable-buffer-local 'allout-primary-bullet) |
8570ce80 SM |
536 | ;;;###autoload |
537 | (put 'allout-primary-bullet 'safe-local-variable 'stringp) | |
fd5359c6 | 538 | ;;;_ = allout-plain-bullets-string |
d82979ea | 539 | (defcustom allout-plain-bullets-string ".," |
9201cc28 | 540 | "The bullets normally used in outline topic prefixes. |
19b84ba3 | 541 | |
fd5359c6 | 542 | See `allout-distinctive-bullets-string' for the other kind of |
c567ac01 | 543 | bullets. |
1977b8f6 | 544 | |
353e2ef2 | 545 | DO NOT include the close-square-bracket, `]', as a bullet. |
1977b8f6 | 546 | |
c567ac01 | 547 | Outline mode has to be reactivated in order for changes to the value |
4bef9110 SE |
548 | of this var to take effect." |
549 | :type 'string | |
550 | :group 'allout) | |
fd5359c6 | 551 | (make-variable-buffer-local 'allout-plain-bullets-string) |
8570ce80 SM |
552 | ;;;###autoload |
553 | (put 'allout-plain-bullets-string 'safe-local-variable 'stringp) | |
fd5359c6 | 554 | ;;;_ = allout-distinctive-bullets-string |
d82979ea | 555 | (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^" |
9201cc28 | 556 | "Persistent outline header bullets used to distinguish special topics. |
1977b8f6 | 557 | |
38b2ca53 NR |
558 | These bullets are distinguish topics with particular character. |
559 | They are not used by default in the topic creation routines, but | |
560 | are offered as options when you modify topic creation with a | |
20db1522 | 561 | universal argument (\\[universal-argument]), or during rebulleting (\\[allout-rebullet-current-heading]). |
38b2ca53 NR |
562 | |
563 | Distinctive bullets are not cycled when topics are shifted or | |
564 | otherwise automatically rebulleted, so their marking is | |
565 | persistent until deliberately changed. Their significance is | |
566 | purely by convention, however. Some conventions suggest | |
567 | themselves: | |
568 | ||
60c7bbd2 RS |
569 | `(' - open paren -- an aside or incidental point |
570 | `?' - question mark -- uncertain or outright question | |
571 | `!' - exclamation point/bang -- emphatic | |
572 | `[' - open square bracket -- meta-note, about item instead of item's subject | |
573 | `\"' - double quote -- a quotation or other citation | |
0af8c88b | 574 | `=' - equal sign -- an assignment, some kind of definition |
60c7bbd2 | 575 | `^' - carat -- relates to something above |
38b2ca53 NR |
576 | |
577 | Some are more elusive, but their rationale may be recognizable: | |
578 | ||
60c7bbd2 RS |
579 | `+' - plus -- pending consideration, completion |
580 | `_' - underscore -- done, completed | |
581 | `&' - ampersand -- addendum, furthermore | |
38b2ca53 NR |
582 | |
583 | \(Some other non-plain bullets have special meaning to the | |
584 | software. By default: | |
585 | ||
60c7bbd2 RS |
586 | `~' marks encryptable topics -- see `allout-topic-encryption-bullet' |
587 | `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.) | |
38b2ca53 NR |
588 | |
589 | See `allout-plain-bullets-string' for the standard, alternating | |
590 | bullets. | |
1977b8f6 | 591 | |
fd5359c6 | 592 | You must run `set-allout-regexp' in order for outline mode to |
38b2ca53 | 593 | adopt changes of this value. |
19b84ba3 | 594 | |
353e2ef2 | 595 | DO NOT include the close-square-bracket, `]', on either of the bullet |
4bef9110 SE |
596 | strings." |
597 | :type 'string | |
598 | :group 'allout) | |
fd5359c6 | 599 | (make-variable-buffer-local 'allout-distinctive-bullets-string) |
8570ce80 SM |
600 | ;;;###autoload |
601 | (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp) | |
1977b8f6 | 602 | |
fd5359c6 MR |
603 | ;;;_ = allout-use-mode-specific-leader |
604 | (defcustom allout-use-mode-specific-leader t | |
9201cc28 | 605 | "When non-nil, use mode-specific topic-header prefixes. |
19b84ba3 | 606 | |
48bd8440 EZ |
607 | Allout outline mode will use the mode-specific `allout-mode-leaders' or |
608 | comment-start string, if any, to lead the topic prefix string, so topic | |
609 | headers look like comments in the programming language. It will also use | |
610 | the comment-start string, with an '_' appended, for `allout-primary-bullet'. | |
19b84ba3 | 611 | |
48bd8440 | 612 | String values are used as literals, not regular expressions, so |
40ba43b4 | 613 | do not escape any regular-expression characters. |
19b84ba3 | 614 | |
24190da5 | 615 | Value t means to first check for assoc value in `allout-mode-leaders' |
c07583cd | 616 | alist, then use comment-start string, if any, then use default (`.'). |
9179616f | 617 | \(See note about use of comment-start strings, below.) |
19b84ba3 | 618 | |
fd5359c6 | 619 | Set to the symbol for either of `allout-mode-leaders' or |
19b84ba3 RS |
620 | `comment-start' to use only one of them, respectively. |
621 | ||
c07583cd | 622 | Value nil means to always use the default (`.') and leave |
48bd8440 EZ |
623 | `allout-primary-bullet' unaltered. |
624 | ||
625 | comment-start strings that do not end in spaces are tripled in | |
626 | the header-prefix, and an `_' underscore is tacked on the end, to | |
627 | distinguish them from regular comment strings. comment-start | |
628 | strings that do end in spaces are not tripled, but an underscore | |
75bcb912 | 629 | is substituted for the space. [This presumes that the space is |
48bd8440 EZ |
630 | for appearance, not comment syntax. You can use |
631 | `allout-mode-leaders' to override this behavior, when | |
632 | undesired.]" | |
71296446 | 633 | :type '(choice (const t) (const nil) string |
fd5359c6 | 634 | (const allout-mode-leaders) |
4bef9110 SE |
635 | (const comment-start)) |
636 | :group 'allout) | |
8570ce80 SM |
637 | ;;;###autoload |
638 | (put 'allout-use-mode-specific-leader 'safe-local-variable | |
4f91a816 | 639 | (lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start)) |
da506f05 | 640 | (stringp x)))) |
fd5359c6 MR |
641 | ;;;_ = allout-mode-leaders |
642 | (defvar allout-mode-leaders '() | |
643 | "Specific allout-prefix leading strings per major modes. | |
19b84ba3 | 644 | |
48bd8440 EZ |
645 | Use this if the mode's comment-start string isn't what you |
646 | prefer, or if the mode lacks a comment-start string. See | |
647 | `allout-use-mode-specific-leader' for more details. | |
19b84ba3 RS |
648 | |
649 | If you're constructing a string that will comment-out outline | |
650 | structuring so it can be included in program code, append an extra | |
651 | character, like an \"_\" underscore, to distinguish the lead string | |
48bd8440 | 652 | from regular comments that start at the beginning-of-line.") |
19b84ba3 | 653 | |
fd5359c6 MR |
654 | ;;;_ = allout-old-style-prefixes |
655 | (defcustom allout-old-style-prefixes nil | |
9201cc28 | 656 | "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. |
19b84ba3 RS |
657 | |
658 | Non-nil restricts the topic creation and modification | |
c567ac01 | 659 | functions to asterix-padded prefixes, so they look exactly |
e126900f | 660 | like the original Emacs-outline style prefixes. |
1977b8f6 | 661 | |
c567ac01 | 662 | Whatever the setting of this variable, both old and new style prefixes |
4bef9110 SE |
663 | are always respected by the topic maneuvering functions." |
664 | :type 'boolean | |
665 | :group 'allout) | |
fd5359c6 | 666 | (make-variable-buffer-local 'allout-old-style-prefixes) |
8570ce80 SM |
667 | ;;;###autoload |
668 | (put 'allout-old-style-prefixes 'safe-local-variable | |
4f91a816 | 669 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
60c7bbd2 | 670 | ;;;_ = allout-stylish-prefixes -- alternating bullets |
fd5359c6 | 671 | (defcustom allout-stylish-prefixes t |
9201cc28 | 672 | "Do fancy stuff with topic prefix bullets according to level, etc. |
c567ac01 | 673 | |
19b84ba3 RS |
674 | Non-nil enables topic creation, modification, and repositioning |
675 | functions to vary the topic bullet char (the char that marks the topic | |
676 | depth) just preceding the start of the topic text) according to level. | |
353e2ef2 | 677 | Otherwise, only asterisks (`*') and distinctive bullets are used. |
19b84ba3 RS |
678 | |
679 | This is how an outline can look (but sans indentation) with stylish | |
680 | prefixes: | |
c567ac01 RS |
681 | |
682 | * Top level | |
683 | .* A topic | |
684 | . + One level 3 subtopic | |
685 | . . One level 4 subtopic | |
19b84ba3 | 686 | . . A second 4 subtopic |
c567ac01 | 687 | . + Another level 3 subtopic |
19b84ba3 RS |
688 | . #1 A numbered level 4 subtopic |
689 | . #2 Another | |
690 | . ! Another level 4 subtopic with a different distinctive bullet | |
691 | . #4 And another numbered level 4 subtopic | |
c567ac01 | 692 | |
19b84ba3 RS |
693 | This would be an outline with stylish prefixes inhibited (but the |
694 | numbered and other distinctive bullets retained): | |
c567ac01 RS |
695 | |
696 | * Top level | |
697 | .* A topic | |
19b84ba3 RS |
698 | . * One level 3 subtopic |
699 | . * One level 4 subtopic | |
700 | . * A second 4 subtopic | |
701 | . * Another level 3 subtopic | |
702 | . #1 A numbered level 4 subtopic | |
703 | . #2 Another | |
704 | . ! Another level 4 subtopic with a different distinctive bullet | |
705 | . #4 And another numbered level 4 subtopic | |
c567ac01 RS |
706 | |
707 | Stylish and constant prefixes (as well as old-style prefixes) are | |
708 | always respected by the topic maneuvering functions, regardless of | |
709 | this variable setting. | |
710 | ||
2265e017 | 711 | The setting of this var is not relevant when `allout-old-style-prefixes' |
4bef9110 SE |
712 | is non-nil." |
713 | :type 'boolean | |
714 | :group 'allout) | |
fd5359c6 | 715 | (make-variable-buffer-local 'allout-stylish-prefixes) |
8570ce80 SM |
716 | ;;;###autoload |
717 | (put 'allout-stylish-prefixes 'safe-local-variable | |
4f91a816 | 718 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 719 | |
fd5359c6 MR |
720 | ;;;_ = allout-numbered-bullet |
721 | (defcustom allout-numbered-bullet "#" | |
9201cc28 | 722 | "String designating bullet of topics that have auto-numbering; nil for none. |
19b84ba3 | 723 | |
a0776d6b | 724 | Topics having this bullet have automatic maintenance of a sibling |
19b84ba3 | 725 | sequence-number tacked on, just after the bullet. Conventionally set |
c567ac01 | 726 | to \"#\", you can set it to a bullet of your choice. A nil value |
4bef9110 SE |
727 | disables numbering maintenance." |
728 | :type '(choice (const nil) string) | |
729 | :group 'allout) | |
fd5359c6 | 730 | (make-variable-buffer-local 'allout-numbered-bullet) |
8570ce80 | 731 | ;;;###autoload |
64686e6d RS |
732 | (put 'allout-numbered-bullet 'safe-local-variable |
733 | (if (fboundp 'string-or-null-p) | |
734 | 'string-or-null-p | |
4f91a816 | 735 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
736 | ;;;_ = allout-file-xref-bullet |
737 | (defcustom allout-file-xref-bullet "@" | |
9201cc28 | 738 | "Bullet signifying file cross-references, for `allout-resolve-xref'. |
19b84ba3 | 739 | |
9179616f | 740 | Set this var to the bullet you want to use for file cross-references." |
4bef9110 SE |
741 | :type '(choice (const nil) string) |
742 | :group 'allout) | |
8570ce80 | 743 | ;;;###autoload |
64686e6d RS |
744 | (put 'allout-file-xref-bullet 'safe-local-variable |
745 | (if (fboundp 'string-or-null-p) | |
746 | 'string-or-null-p | |
4f91a816 | 747 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
748 | ;;;_ = allout-presentation-padding |
749 | (defcustom allout-presentation-padding 2 | |
9201cc28 | 750 | "Presentation-format white-space padding factor, for greater indent." |
9179616f DL |
751 | :type 'integer |
752 | :group 'allout) | |
753 | ||
fd5359c6 | 754 | (make-variable-buffer-local 'allout-presentation-padding) |
8570ce80 SM |
755 | ;;;###autoload |
756 | (put 'allout-presentation-padding 'safe-local-variable 'integerp) | |
9179616f | 757 | |
96497653 KM |
758 | ;;;_ = allout-flattened-numbering-abbreviation |
759 | (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering | |
c6eee9aa | 760 | 'allout-flattened-numbering-abbreviation "24.1") |
96497653 | 761 | (defcustom allout-flattened-numbering-abbreviation nil |
9201cc28 | 762 | "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic |
9179616f DL |
763 | numbers to minimal amount with some context. Otherwise, entire |
764 | numbers are always used." | |
2bed3f04 | 765 | :version "24.1" |
9179616f DL |
766 | :type 'boolean |
767 | :group 'allout) | |
768 | ||
c567ac01 | 769 | ;;;_ + LaTeX formatting |
fd5359c6 MR |
770 | ;;;_ - allout-number-pages |
771 | (defcustom allout-number-pages nil | |
9201cc28 | 772 | "Non-nil turns on page numbering for LaTeX formatting of an outline." |
4bef9110 SE |
773 | :type 'boolean |
774 | :group 'allout) | |
fd5359c6 MR |
775 | ;;;_ - allout-label-style |
776 | (defcustom allout-label-style "\\large\\bf" | |
9201cc28 | 777 | "Font and size of labels for LaTeX formatting of an outline." |
4bef9110 SE |
778 | :type 'string |
779 | :group 'allout) | |
fd5359c6 MR |
780 | ;;;_ - allout-head-line-style |
781 | (defcustom allout-head-line-style "\\large\\sl " | |
9201cc28 | 782 | "Font and size of entries for LaTeX formatting of an outline." |
4bef9110 SE |
783 | :type 'string |
784 | :group 'allout) | |
fd5359c6 MR |
785 | ;;;_ - allout-body-line-style |
786 | (defcustom allout-body-line-style " " | |
9201cc28 | 787 | "Font and size of entries for LaTeX formatting of an outline." |
4bef9110 SE |
788 | :type 'string |
789 | :group 'allout) | |
fd5359c6 MR |
790 | ;;;_ - allout-title-style |
791 | (defcustom allout-title-style "\\Large\\bf" | |
9201cc28 | 792 | "Font and size of titles for LaTeX formatting of an outline." |
4bef9110 SE |
793 | :type 'string |
794 | :group 'allout) | |
fd5359c6 | 795 | ;;;_ - allout-title |
d82979ea | 796 | (defcustom allout-title '(or buffer-file-name (buffer-name)) |
9201cc28 | 797 | "Expression to be evaluated to determine the title for LaTeX |
4bef9110 SE |
798 | formatted copy." |
799 | :type 'sexp | |
800 | :group 'allout) | |
fd5359c6 MR |
801 | ;;;_ - allout-line-skip |
802 | (defcustom allout-line-skip ".05cm" | |
9201cc28 | 803 | "Space between lines for LaTeX formatting of an outline." |
4bef9110 SE |
804 | :type 'string |
805 | :group 'allout) | |
fd5359c6 MR |
806 | ;;;_ - allout-indent |
807 | (defcustom allout-indent ".3cm" | |
9201cc28 | 808 | "LaTeX formatted depth-indent spacing." |
4bef9110 SE |
809 | :type 'string |
810 | :group 'allout) | |
c567ac01 | 811 | |
d82979ea | 812 | ;;;_ + Topic encryption |
8570ce80 SM |
813 | ;;;_ = allout-encryption group |
814 | (defgroup allout-encryption nil | |
815 | "Settings for topic encryption features of allout outliner." | |
816 | :group 'allout) | |
d82979ea EZ |
817 | ;;;_ = allout-topic-encryption-bullet |
818 | (defcustom allout-topic-encryption-bullet "~" | |
9201cc28 | 819 | "Bullet signifying encryption of the entry's body." |
d82979ea | 820 | :type '(choice (const nil) string) |
21e8bc99 | 821 | :version "22.1" |
8570ce80 | 822 | :group 'allout-encryption) |
d82979ea | 823 | ;;;_ = allout-encrypt-unencrypted-on-saves |
96b83743 | 824 | (defcustom allout-encrypt-unencrypted-on-saves t |
13aa217b KM |
825 | "If non-nil, topics pending encryption are encrypted during buffer saves. |
826 | ||
e1dbe924 | 827 | This prevents file-system exposure of un-encrypted contents of |
13aa217b KM |
828 | items marked for encryption. |
829 | ||
830 | When non-nil, if the topic currently being edited is decrypted, | |
831 | it will be encrypted for saving but automatically decrypted | |
832 | before any subsequent user interaction, so it is once again clear | |
833 | text for editing though the file system copy is encrypted. | |
834 | ||
835 | \(Auto-saves are handled differently. Buffers with plain-text | |
836 | exposed encrypted topics are exempted from auto saves until all | |
837 | such topics are encrypted.)" | |
838 | ||
839 | :type 'boolean | |
840 | :version "23.1" | |
8570ce80 | 841 | :group 'allout-encryption) |
d82979ea | 842 | (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) |
13aa217b KM |
843 | (defvar allout-auto-save-temporarily-disabled nil |
844 | "True while topic encryption is pending and auto-saving was active. | |
845 | ||
20db1522 | 846 | The value of `buffer-saved-size' at the time of decryption is used, |
13aa217b KM |
847 | for restoring when all encryptions are established.") |
848 | (defvar allout-just-did-undo nil | |
849 | "True just after undo commands, until allout-post-command-business.") | |
850 | (make-variable-buffer-local 'allout-just-did-undo) | |
d82979ea | 851 | |
01fc9422 EZ |
852 | ;;;_ + Developer |
853 | ;;;_ = allout-developer group | |
854 | (defgroup allout-developer nil | |
1c9b9df0 | 855 | "Allout settings developers care about, including topic encryption and more." |
01fc9422 EZ |
856 | :group 'allout) |
857 | ;;;_ = allout-run-unit-tests-on-load | |
858 | (defcustom allout-run-unit-tests-on-load nil | |
9201cc28 | 859 | "When non-nil, unit tests will be run at end of loading the allout module. |
01fc9422 EZ |
860 | |
861 | Generally, allout code developers are the only ones who'll want to set this. | |
862 | ||
863 | \(If set, this makes it an even better practice to exercise changes by | |
5204800f NR |
864 | doing byte-compilation with a repeat count, so the file is loaded after |
865 | compilation.) | |
01fc9422 EZ |
866 | |
867 | See `allout-run-unit-tests' to see what's run." | |
868 | :type 'boolean | |
869 | :group 'allout-developer) | |
870 | ||
c567ac01 RS |
871 | ;;;_ + Miscellaneous customization |
872 | ||
d82979ea EZ |
873 | ;;;_ = allout-enable-file-variable-adjustment |
874 | (defcustom allout-enable-file-variable-adjustment t | |
9201cc28 | 875 | "If non-nil, some allout outline actions edit Emacs local file var text. |
d82979ea EZ |
876 | |
877 | This can range from changes to existing entries, addition of new ones, | |
878 | and creation of a new local variables section when necessary. | |
19b84ba3 | 879 | |
d82979ea EZ |
880 | Emacs file variables adjustments are also inhibited if `enable-local-variables' |
881 | is nil. | |
c567ac01 | 882 | |
d82979ea | 883 | Operations potentially causing edits include allout encryption routines. |
69027dea | 884 | For details, see `allout-toggle-current-subtree-encryption's docstring." |
4bef9110 SE |
885 | :type 'boolean |
886 | :group 'allout) | |
d82979ea | 887 | (make-variable-buffer-local 'allout-enable-file-variable-adjustment) |
c567ac01 | 888 | |
60c7bbd2 | 889 | ;;;_* CODE -- no user customizations below. |
c567ac01 | 890 | |
9179616f DL |
891 | ;;;_ #1 Internal Outline Formatting and Configuration |
892 | ;;;_ : Version | |
fd5359c6 | 893 | ;;;_ = allout-version |
0af8c88b | 894 | (defvar allout-version "2.3" |
c07583cd | 895 | "Version of currently loaded outline package. (allout.el)") |
fd5359c6 MR |
896 | ;;;_ > allout-version |
897 | (defun allout-version (&optional here) | |
19b84ba3 RS |
898 | "Return string describing the loaded outline version." |
899 | (interactive "P") | |
fd5359c6 | 900 | (let ((msg (concat "Allout Outline Mode v " allout-version))) |
eac9cf5f | 901 | (if here (insert msg)) |
19b84ba3 RS |
902 | (message "%s" msg) |
903 | msg)) | |
69027dea EZ |
904 | ;;;_ : Mode activation (defined here because it's referenced early) |
905 | ;;;_ = allout-mode | |
906 | (defvar allout-mode nil "Allout outline mode minor-mode flag.") | |
907 | (make-variable-buffer-local 'allout-mode) | |
4034b0e2 | 908 | ;;;_ = allout-layout nil |
60c7bbd2 | 909 | (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring. |
4034b0e2 LT |
910 | "Buffer-specific setting for allout layout. |
911 | ||
20db1522 | 912 | In buffers where this is non-nil (and if `allout-auto-activation' |
11c46e15 KM |
913 | has been customized to enable this behavior), `allout-mode' will be |
914 | automatically activated. The layout dictated by the value will be used to | |
915 | set the initial exposure when `allout-mode' is activated. | |
4034b0e2 LT |
916 | |
917 | \*You should not setq-default this variable non-nil unless you want every | |
918 | visited file to be treated as an allout file.* | |
919 | ||
920 | The value would typically be set by a file local variable. For | |
921 | example, the following lines at the bottom of an Emacs Lisp file: | |
922 | ||
923 | ;;;Local variables: | |
c07583cd | 924 | ;;;allout-layout: (0 : -1 -1 0) |
4034b0e2 LT |
925 | ;;;End: |
926 | ||
927 | dictate activation of `allout-mode' mode when the file is visited | |
11c46e15 KM |
928 | \(presuming proper `allout-auto-activation' customization), |
929 | followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'. | |
930 | \(This is the layout used for the allout.el source file.) | |
4034b0e2 LT |
931 | |
932 | `allout-default-layout' describes the specification format. | |
933 | `allout-layout' can additionally have the value `t', in which | |
934 | case the value of `allout-default-layout' is used.") | |
935 | (make-variable-buffer-local 'allout-layout) | |
b1a569b5 | 936 | ;;;###autoload |
8570ce80 | 937 | (put 'allout-layout 'safe-local-variable |
4f91a816 | 938 | (lambda (x) (or (numberp x) (listp x) (memq x '(: * + -))))) |
4034b0e2 | 939 | |
9179616f | 940 | ;;;_ : Topic header format |
fd5359c6 MR |
941 | ;;;_ = allout-regexp |
942 | (defvar allout-regexp "" | |
fb7ada5f | 943 | "Regular expression to match the beginning of a heading line. |
19b84ba3 | 944 | |
c567ac01 RS |
945 | Any line whose beginning matches this regexp is considered a |
946 | heading. This var is set according to the user configuration vars | |
2265e017 | 947 | by `set-allout-regexp'.") |
fd5359c6 MR |
948 | (make-variable-buffer-local 'allout-regexp) |
949 | ;;;_ = allout-bullets-string | |
950 | (defvar allout-bullets-string "" | |
19b84ba3 RS |
951 | "A string dictating the valid set of outline topic bullets. |
952 | ||
60c7bbd2 | 953 | This var should *not* be set by the user -- it is set by `set-allout-regexp', |
fd5359c6 MR |
954 | and is produced from the elements of `allout-plain-bullets-string' |
955 | and `allout-distinctive-bullets-string'.") | |
956 | (make-variable-buffer-local 'allout-bullets-string) | |
957 | ;;;_ = allout-bullets-string-len | |
958 | (defvar allout-bullets-string-len 0 | |
2265e017 | 959 | "Length of current buffers' `allout-plain-bullets-string'.") |
fd5359c6 | 960 | (make-variable-buffer-local 'allout-bullets-string-len) |
d8350998 CY |
961 | ;;;_ = allout-depth-specific-regexp |
962 | (defvar allout-depth-specific-regexp "" | |
fb7ada5f | 963 | "Regular expression to match a heading line prefix for a particular depth. |
d8350998 CY |
964 | |
965 | This expression is used to search for depth-specific topic | |
966 | headers at depth 2 and greater. Use `allout-depth-one-regexp' | |
967 | for to seek topics at depth one. | |
968 | ||
969 | This var is set according to the user configuration vars by | |
970 | `set-allout-regexp'. It is prepared with format strings for two | |
971 | decimal numbers, which should each be one less than the depth of the | |
972 | topic prefix to be matched.") | |
973 | (make-variable-buffer-local 'allout-depth-specific-regexp) | |
974 | ;;;_ = allout-depth-one-regexp | |
975 | (defvar allout-depth-one-regexp "" | |
fb7ada5f | 976 | "Regular expression to match a heading line prefix for depth one. |
d8350998 CY |
977 | |
978 | This var is set according to the user configuration vars by | |
979 | `set-allout-regexp'. It is prepared with format strings for two | |
980 | decimal numbers, which should each be one less than the depth of the | |
981 | topic prefix to be matched.") | |
982 | (make-variable-buffer-local 'allout-depth-one-regexp) | |
fd5359c6 MR |
983 | ;;;_ = allout-line-boundary-regexp |
984 | (defvar allout-line-boundary-regexp () | |
42c3e51c | 985 | "`allout-regexp' prepended with a newline for the search target. |
19b84ba3 | 986 | |
d8350998 | 987 | This is properly set by `set-allout-regexp'.") |
fd5359c6 MR |
988 | (make-variable-buffer-local 'allout-line-boundary-regexp) |
989 | ;;;_ = allout-bob-regexp | |
990 | (defvar allout-bob-regexp () | |
d8350998 | 991 | "Like `allout-line-boundary-regexp', for headers at beginning of buffer.") |
fd5359c6 MR |
992 | (make-variable-buffer-local 'allout-bob-regexp) |
993 | ;;;_ = allout-header-subtraction | |
994 | (defvar allout-header-subtraction (1- (length allout-header-prefix)) | |
995 | "Allout-header prefix length to subtract when computing topic depth.") | |
996 | (make-variable-buffer-local 'allout-header-subtraction) | |
997 | ;;;_ = allout-plain-bullets-string-len | |
998 | (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) | |
2265e017 | 999 | "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") |
fd5359c6 MR |
1000 | (make-variable-buffer-local 'allout-plain-bullets-string-len) |
1001 | ||
d8350998 | 1002 | ;;;_ = allout-doublecheck-at-and-shallower |
2a1408fd | 1003 | (defconst allout-doublecheck-at-and-shallower 3 |
ede4ac6a | 1004 | "Validate apparent topics of this depth and shallower as being non-aberrant. |
fd5359c6 | 1005 | |
2a1408fd DN |
1006 | Verified with `allout-aberrant-container-p'. The usefulness of |
1007 | this check is limited to shallow depths, because the | |
1008 | determination of aberrance is according to the mistaken item | |
1009 | being followed by a legitimate item of excessively greater depth. | |
1010 | ||
1011 | The classic example of a mistaken item, for a standard allout | |
1012 | outline configuration, is a body line that begins with an '...' | |
1013 | ellipsis. This happens to contain a legitimate depth-2 header | |
1014 | prefix, constituted by two '..' dots at the beginning of the | |
1015 | line. The only thing that can distinguish it *in principle* from | |
1016 | a legitimate one is if the following real header is at a depth | |
1017 | that is discontinuous from the depth of 2 implied by the | |
1018 | ellipsis, ie depth 4 or more. As the depth being tested gets | |
1019 | greater, the likelihood of this kind of disqualification is | |
1020 | lower, and the usefulness of this test is lower. | |
1021 | ||
1022 | Extending the depth of the doublecheck increases the amount it is | |
1023 | applied, increasing the cost of the test - on casual estimation, | |
1024 | for outlines with many deep topics, geometrically (O(n)?). | |
1025 | Taken together with decreasing likelihood that the test will be | |
1026 | useful at greater depths, more modest doublecheck limits are more | |
1027 | suitably economical.") | |
fd5359c6 MR |
1028 | ;;;_ X allout-reset-header-lead (header-lead) |
1029 | (defun allout-reset-header-lead (header-lead) | |
9201cc28 | 1030 | "Reset the leading string used to identify topic headers." |
1977b8f6 | 1031 | (interactive "sNew lead string: ") |
fd5359c6 MR |
1032 | (setq allout-header-prefix header-lead) |
1033 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
1034 | (set-allout-regexp)) | |
1035 | ;;;_ X allout-lead-with-comment-string (header-lead) | |
1036 | (defun allout-lead-with-comment-string (&optional header-lead) | |
9201cc28 | 1037 | "Set the topic-header leading string to specified string. |
19b84ba3 | 1038 | |
20db1522 | 1039 | Useful for encapsulating outline structure in programming |
19b84ba3 | 1040 | language comments. Returns the leading string." |
1977b8f6 RS |
1041 | |
1042 | (interactive "P") | |
1043 | (if (not (stringp header-lead)) | |
1044 | (setq header-lead (read-string | |
1045 | "String prefix for topic headers: "))) | |
fd5359c6 MR |
1046 | (setq allout-reindent-bodies nil) |
1047 | (allout-reset-header-lead header-lead) | |
1977b8f6 | 1048 | header-lead) |
48bd8440 EZ |
1049 | ;;;_ > allout-infer-header-lead-and-primary-bullet () |
1050 | (defun allout-infer-header-lead-and-primary-bullet () | |
1051 | "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'. | |
19b84ba3 RS |
1052 | |
1053 | Works according to settings of: | |
1054 | ||
8d118843 | 1055 | `comment-start' |
fd5359c6 MR |
1056 | `allout-header-prefix' (default) |
1057 | `allout-use-mode-specific-leader' | |
1058 | and `allout-mode-leaders'. | |
19b84ba3 | 1059 | |
c07583cd | 1060 | Apply this via (re)activation of `allout-mode', rather than |
8d118843 | 1061 | invoking it directly." |
fd5359c6 MR |
1062 | (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) |
1063 | (if (or (stringp allout-use-mode-specific-leader) | |
1064 | (memq allout-use-mode-specific-leader | |
1065 | '(allout-mode-leaders | |
19b84ba3 RS |
1066 | comment-start |
1067 | t))) | |
fd5359c6 | 1068 | allout-use-mode-specific-leader |
60c7bbd2 | 1069 | ;; Oops -- garbled value, equate with effect of t: |
19b84ba3 RS |
1070 | t))) |
1071 | (leader | |
1072 | (cond | |
1073 | ((not use-leader) nil) | |
1074 | ;; Use the explicitly designated leader: | |
1075 | ((stringp use-leader) use-leader) | |
fd5359c6 | 1076 | (t (or (and (memq use-leader '(t allout-mode-leaders)) |
19b84ba3 | 1077 | ;; Get it from outline mode leaders? |
fd5359c6 MR |
1078 | (cdr (assq major-mode allout-mode-leaders))) |
1079 | ;; ... didn't get from allout-mode-leaders... | |
19b84ba3 RS |
1080 | (and (memq use-leader '(t comment-start)) |
1081 | comment-start | |
1082 | ;; Use comment-start, maybe tripled, and with | |
353e2ef2 | 1083 | ;; underscore: |
19b84ba3 RS |
1084 | (concat |
1085 | (if (string= " " | |
1086 | (substring comment-start | |
1087 | (1- (length comment-start)))) | |
1088 | ;; Use comment-start, sans trailing space: | |
1089 | (substring comment-start 0 -1) | |
1090 | (concat comment-start comment-start comment-start)) | |
1091 | ;; ... and append underscore, whichever: | |
1092 | "_"))))))) | |
1093 | (if (not leader) | |
1094 | nil | |
48bd8440 EZ |
1095 | (setq allout-header-prefix leader) |
1096 | (if (not allout-old-style-prefixes) | |
ea18b2b1 | 1097 | ;; setting allout-primary-bullet makes the top level topics use -- |
60c7bbd2 | 1098 | ;; actually, be -- the special prefix: |
48bd8440 EZ |
1099 | (setq allout-primary-bullet leader)) |
1100 | allout-header-prefix))) | |
1101 | (defalias 'allout-infer-header-lead | |
1102 | 'allout-infer-header-lead-and-primary-bullet) | |
fd5359c6 MR |
1103 | ;;;_ > allout-infer-body-reindent () |
1104 | (defun allout-infer-body-reindent () | |
1105 | "Determine proper setting for `allout-reindent-bodies'. | |
8d118843 | 1106 | |
c07583cd | 1107 | Depends on default setting of `allout-reindent-bodies' (which see) |
8d118843 RS |
1108 | and presence of setting for `comment-start', to tell whether the |
1109 | file is programming code." | |
fd5359c6 | 1110 | (if (and allout-reindent-bodies |
8d118843 | 1111 | comment-start |
fd5359c6 MR |
1112 | (not (eq 'force allout-reindent-bodies))) |
1113 | (setq allout-reindent-bodies nil))) | |
1114 | ;;;_ > set-allout-regexp () | |
1115 | (defun set-allout-regexp () | |
19b84ba3 RS |
1116 | "Generate proper topic-header regexp form for outline functions. |
1117 | ||
fd5359c6 | 1118 | Works with respect to `allout-plain-bullets-string' and |
d8350998 CY |
1119 | `allout-distinctive-bullets-string'. |
1120 | ||
1121 | Also refresh various data structures that hinge on the regexp." | |
1977b8f6 RS |
1122 | |
1123 | (interactive) | |
fd5359c6 MR |
1124 | ;; Derive allout-bullets-string from user configured components: |
1125 | (setq allout-bullets-string "") | |
1126 | (let ((strings (list 'allout-plain-bullets-string | |
1127 | 'allout-distinctive-bullets-string | |
1128 | 'allout-primary-bullet)) | |
1977b8f6 RS |
1129 | cur-string |
1130 | cur-len | |
c567ac01 | 1131 | cur-char |
96b83743 | 1132 | index) |
1977b8f6 | 1133 | (while strings |
96b83743 | 1134 | (setq index 0) |
1977b8f6 RS |
1135 | (setq cur-len (length (setq cur-string (symbol-value (car strings))))) |
1136 | (while (< index cur-len) | |
1137 | (setq cur-char (aref cur-string index)) | |
fd5359c6 MR |
1138 | (setq allout-bullets-string |
1139 | (concat allout-bullets-string | |
1977b8f6 RS |
1140 | (cond |
1141 | ; Single dash would denote a | |
1142 | ; sequence, repeated denotes | |
1143 | ; a dash: | |
1144 | ((eq cur-char ?-) "--") | |
1145 | ; literal close-square-bracket | |
1146 | ; doesn't work right in the | |
1147 | ; expr, exclude it: | |
1148 | ((eq cur-char ?\]) "") | |
1149 | (t (regexp-quote (char-to-string cur-char)))))) | |
1150 | (setq index (1+ index))) | |
1151 | (setq strings (cdr strings))) | |
1152 | ) | |
fd5359c6 MR |
1153 | ;; Derive next for repeated use in allout-pending-bullet: |
1154 | (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) | |
1155 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
d8350998 | 1156 | |
42c3e51c | 1157 | (let (new-part old-part formfeed-part) |
d8350998 CY |
1158 | (setq new-part (concat "\\(" |
1159 | (regexp-quote allout-header-prefix) | |
1160 | "[ \t]*" | |
1161 | ;; already regexp-quoted in a custom way: | |
1162 | "[" allout-bullets-string "]" | |
1163 | "\\)") | |
1164 | old-part (concat "\\(" | |
1165 | (regexp-quote allout-primary-bullet) | |
1166 | "\\|" | |
1167 | (regexp-quote allout-header-prefix) | |
1168 | "\\)" | |
1169 | "+" | |
1170 | " ?[^" allout-primary-bullet "]") | |
42c3e51c KM |
1171 | formfeed-part "\\(\^L\\)" |
1172 | ||
d8350998 CY |
1173 | allout-regexp (concat new-part |
1174 | "\\|" | |
1175 | old-part | |
42c3e51c KM |
1176 | "\\|" |
1177 | formfeed-part) | |
d8350998 CY |
1178 | |
1179 | allout-line-boundary-regexp (concat "\n" new-part | |
1180 | "\\|" | |
42c3e51c KM |
1181 | "\n" old-part |
1182 | "\\|" | |
1183 | "\n" formfeed-part) | |
d8350998 CY |
1184 | |
1185 | allout-bob-regexp (concat "\\`" new-part | |
1186 | "\\|" | |
42c3e51c KM |
1187 | "\\`" old-part |
1188 | "\\|" | |
1189 | "\\`" formfeed-part | |
1190 | )) | |
d8350998 CY |
1191 | |
1192 | (setq allout-depth-specific-regexp | |
1193 | (concat "\\(^\\|\\`\\)" | |
1194 | "\\(" | |
1195 | ||
1196 | ;; new-style spacers-then-bullet string: | |
1197 | "\\(" | |
1198 | (allout-format-quote (regexp-quote allout-header-prefix)) | |
1199 | " \\{%s\\}" | |
1200 | "[" (allout-format-quote allout-bullets-string) "]" | |
1201 | "\\)" | |
1202 | ||
1203 | ;; old-style all-bullets string, if primary not multi-char: | |
1204 | (if (< 0 allout-header-subtraction) | |
1205 | "" | |
1206 | (concat "\\|\\(" | |
1207 | (allout-format-quote | |
1208 | (regexp-quote allout-primary-bullet)) | |
1209 | (allout-format-quote | |
1210 | (regexp-quote allout-primary-bullet)) | |
1211 | (allout-format-quote | |
1212 | (regexp-quote allout-primary-bullet)) | |
1213 | "\\{%s\\}" | |
1214 | ;; disqualify greater depths: | |
1215 | "[^" | |
1216 | (allout-format-quote allout-primary-bullet) | |
1217 | "]\\)" | |
1218 | )) | |
1219 | "\\)" | |
1220 | )) | |
1221 | (setq allout-depth-one-regexp | |
1222 | (concat "\\(^\\|\\`\\)" | |
1223 | "\\(" | |
1224 | ||
1225 | "\\(" | |
1226 | (regexp-quote allout-header-prefix) | |
1227 | ;; disqualify any bullet char following any amount of | |
1228 | ;; intervening whitespace: | |
1229 | " *" | |
1230 | (concat "[^ " allout-bullets-string "]") | |
1231 | "\\)" | |
1232 | (if (< 0 allout-header-subtraction) | |
1233 | ;; Need not support anything like the old | |
1234 | ;; bullet style if the prefix is multi-char. | |
1235 | "" | |
1236 | (concat "\\|" | |
1237 | (regexp-quote allout-primary-bullet) | |
1238 | ;; disqualify deeper primary-bullet sequences: | |
1239 | "[^" allout-primary-bullet "]")) | |
1240 | "\\)" | |
1241 | )))) | |
9179616f | 1242 | ;;;_ : Menu bar |
95c12694 RS |
1243 | (defvar allout-mode-exposure-menu) |
1244 | (defvar allout-mode-editing-menu) | |
1245 | (defvar allout-mode-navigation-menu) | |
1246 | (defvar allout-mode-misc-menu) | |
fd5359c6 | 1247 | (defun produce-allout-mode-menubar-entries () |
9179616f | 1248 | (require 'easymenu) |
fd5359c6 | 1249 | (easy-menu-define allout-mode-exposure-menu |
d3e51865 | 1250 | allout-mode-map-value |
9179616f DL |
1251 | "Allout outline exposure menu." |
1252 | '("Exposure" | |
fd5359c6 MR |
1253 | ["Show Entry" allout-show-current-entry t] |
1254 | ["Show Children" allout-show-children t] | |
1255 | ["Show Subtree" allout-show-current-subtree t] | |
1256 | ["Hide Subtree" allout-hide-current-subtree t] | |
1257 | ["Hide Leaves" allout-hide-current-leaves t] | |
9179616f | 1258 | "----" |
fd5359c6 MR |
1259 | ["Show All" allout-show-all t])) |
1260 | (easy-menu-define allout-mode-editing-menu | |
d3e51865 | 1261 | allout-mode-map-value |
9179616f DL |
1262 | "Allout outline editing menu." |
1263 | '("Headings" | |
fd5359c6 MR |
1264 | ["Open Sibling" allout-open-sibtopic t] |
1265 | ["Open Subtopic" allout-open-subtopic t] | |
1266 | ["Open Supertopic" allout-open-supertopic t] | |
9179616f | 1267 | "----" |
fd5359c6 MR |
1268 | ["Shift Topic In" allout-shift-in t] |
1269 | ["Shift Topic Out" allout-shift-out t] | |
1270 | ["Rebullet Topic" allout-rebullet-topic t] | |
1271 | ["Rebullet Heading" allout-rebullet-current-heading t] | |
d82979ea EZ |
1272 | ["Number Siblings" allout-number-siblings t] |
1273 | "----" | |
1274 | ["Toggle Topic Encryption" | |
1275 | allout-toggle-current-subtree-encryption | |
1276 | (> (allout-current-depth) 1)])) | |
fd5359c6 | 1277 | (easy-menu-define allout-mode-navigation-menu |
d3e51865 | 1278 | allout-mode-map-value |
9179616f DL |
1279 | "Allout outline navigation menu." |
1280 | '("Navigation" | |
fd5359c6 | 1281 | ["Next Visible Heading" allout-next-visible-heading t] |
9179616f | 1282 | ["Previous Visible Heading" |
fd5359c6 | 1283 | allout-previous-visible-heading t] |
9179616f | 1284 | "----" |
fd5359c6 MR |
1285 | ["Up Level" allout-up-current-level t] |
1286 | ["Forward Current Level" allout-forward-current-level t] | |
9179616f | 1287 | ["Backward Current Level" |
fd5359c6 | 1288 | allout-backward-current-level t] |
9179616f DL |
1289 | "----" |
1290 | ["Beginning of Entry" | |
fd5359c6 | 1291 | allout-beginning-of-current-entry t] |
d82979ea | 1292 | ["End of Entry" allout-end-of-entry t] |
fd5359c6 MR |
1293 | ["End of Subtree" allout-end-of-current-subtree t])) |
1294 | (easy-menu-define allout-mode-misc-menu | |
d3e51865 | 1295 | allout-mode-map-value |
9179616f DL |
1296 | "Allout outlines miscellaneous bindings." |
1297 | '("Misc" | |
fd5359c6 | 1298 | ["Version" allout-version t] |
9179616f | 1299 | "----" |
fd5359c6 | 1300 | ["Duplicate Exposed" allout-copy-exposed-to-buffer t] |
9179616f | 1301 | ["Duplicate Exposed, numbered" |
71296446 | 1302 | allout-flatten-exposed-to-buffer t] |
9179616f | 1303 | ["Duplicate Exposed, indented" |
71296446 | 1304 | allout-indented-exposed-to-buffer t] |
9179616f | 1305 | "----" |
fd5359c6 MR |
1306 | ["Set Header Lead" allout-reset-header-lead t] |
1307 | ["Set New Exposure" allout-expose-topic t]))) | |
01fc9422 | 1308 | ;;;_ : Allout Modal-Variables Utilities |
fd5359c6 MR |
1309 | ;;;_ = allout-mode-prior-settings |
1310 | (defvar allout-mode-prior-settings nil | |
01fc9422 | 1311 | "Internal `allout-mode' use; settings to be resumed on mode deactivation. |
1977b8f6 | 1312 | |
01fc9422 EZ |
1313 | See `allout-add-resumptions' and `allout-do-resumptions'.") |
1314 | (make-variable-buffer-local 'allout-mode-prior-settings) | |
1315 | ;;;_ > allout-add-resumptions (&rest pairs) | |
1316 | (defun allout-add-resumptions (&rest pairs) | |
48bd8440 | 1317 | "Set name/value PAIRS. |
01fc9422 EZ |
1318 | |
1319 | Old settings are preserved for later resumption using `allout-do-resumptions'. | |
1320 | ||
48bd8440 EZ |
1321 | The new values are set as a buffer local. On resumption, the prior buffer |
1322 | scope of the variable is restored along with its value. If it was a void | |
1323 | buffer-local value, then it is left as nil on resumption. | |
1324 | ||
01fc9422 | 1325 | The pairs are lists whose car is the name of the variable and car of the |
48bd8440 EZ |
1326 | cdr is the new value: '(some-var some-value)'. The pairs can actually be |
1327 | triples, where the third element qualifies the disposition of the setting, | |
1328 | as described further below. | |
01fc9422 | 1329 | |
48bd8440 EZ |
1330 | If the optional third element is the symbol 'extend, then the new value |
1331 | created by `cons'ing the second element of the pair onto the front of the | |
1332 | existing value. | |
01fc9422 | 1333 | |
48bd8440 EZ |
1334 | If the optional third element is the symbol 'append, then the new value is |
1335 | extended from the existing one by `append'ing a list containing the second | |
1336 | element of the pair onto the end of the existing value. | |
01fc9422 | 1337 | |
48bd8440 | 1338 | Extension, and resumptions in general, should not be used for hook |
60c7bbd2 | 1339 | functions -- use the 'local mode of `add-hook' for that, instead. |
01fc9422 EZ |
1340 | |
1341 | The settings are stored on `allout-mode-prior-settings'." | |
1342 | (while pairs | |
1343 | (let* ((pair (pop pairs)) | |
1344 | (name (car pair)) | |
48bd8440 EZ |
1345 | (value (cadr pair)) |
1346 | (qualifier (if (> (length pair) 2) | |
1347 | (caddr pair))) | |
1348 | prior-value) | |
01fc9422 EZ |
1349 | (if (not (symbolp name)) |
1350 | (error "Pair's name, %S, must be a symbol, not %s" | |
1351 | name (type-of name))) | |
d8350998 | 1352 | (setq prior-value (condition-case nil |
48bd8440 EZ |
1353 | (symbol-value name) |
1354 | (void-variable nil))) | |
01fc9422 EZ |
1355 | (when (not (assoc name allout-mode-prior-settings)) |
1356 | ;; Not already added as a resumption, create the prior setting entry. | |
1c9b9df0 | 1357 | (if (local-variable-p name (current-buffer)) |
60c7bbd2 | 1358 | ;; is already local variable -- preserve the prior value: |
48bd8440 | 1359 | (push (list name prior-value) allout-mode-prior-settings) |
01fc9422 EZ |
1360 | ;; wasn't local variable, indicate so for resumption by killing |
1361 | ;; local value, and make it local: | |
1362 | (push (list name) allout-mode-prior-settings) | |
1363 | (make-local-variable name))) | |
48bd8440 EZ |
1364 | (if qualifier |
1365 | (cond ((eq qualifier 'extend) | |
1366 | (if (not (listp prior-value)) | |
1367 | (error "extension of non-list prior value attempted") | |
1368 | (set name (cons value prior-value)))) | |
1369 | ((eq qualifier 'append) | |
1370 | (if (not (listp prior-value)) | |
1371 | (error "appending of non-list prior value attempted") | |
1372 | (set name (append prior-value (list value))))) | |
1373 | (t (error "unrecognized setting qualifier `%s' encountered" | |
1374 | qualifier))) | |
1375 | (set name value))))) | |
01fc9422 EZ |
1376 | ;;;_ > allout-do-resumptions () |
1377 | (defun allout-do-resumptions () | |
1378 | "Resume all name/value settings registered by `allout-add-resumptions'. | |
1379 | ||
1380 | This is used when concluding allout-mode, to resume selected variables to | |
1381 | their settings before allout-mode was started." | |
1382 | ||
1383 | (while allout-mode-prior-settings | |
1384 | (let* ((pair (pop allout-mode-prior-settings)) | |
1385 | (name (car pair)) | |
1386 | (value-cell (cdr pair))) | |
1387 | (if (not value-cell) | |
1388 | ;; Prior value was global: | |
1389 | (kill-local-variable name) | |
1390 | ;; Prior value was explicit: | |
1391 | (set name (car value-cell)))))) | |
9179616f | 1392 | ;;;_ : Mode-specific incidentals |
fd5359c6 | 1393 | ;;;_ > allout-unprotected (expr) |
d82979ea | 1394 | (defmacro allout-unprotected (expr) |
96b83743 | 1395 | "Enable internal outline operations to alter invisible text." |
1b4d97b2 | 1396 | `(let ((inhibit-read-only (if (not buffer-read-only) t)) |
0458fa80 | 1397 | (inhibit-field-text-motion t)) |
96b83743 EZ |
1398 | ,expr)) |
1399 | ;;;_ = allout-mode-hook | |
1400 | (defvar allout-mode-hook nil | |
7b97c764 | 1401 | "Hook run when allout mode starts.") |
01fc9422 | 1402 | ;;;_ = allout-mode-deactivate-hook |
7927f48d | 1403 | (define-obsolete-variable-alias 'allout-mode-deactivate-hook |
c6eee9aa | 1404 | 'allout-mode-off-hook "24.1") |
e5bd0a28 SM |
1405 | (defvar allout-mode-deactivate-hook nil |
1406 | "Hook run when allout mode ends.") | |
01fc9422 EZ |
1407 | ;;;_ = allout-exposure-category |
1408 | (defvar allout-exposure-category nil | |
1409 | "Symbol for use as allout invisible-text overlay category.") | |
48bd8440 | 1410 | |
7b97c764 | 1411 | ;;;_ = allout-exposure-change-functions |
e5bd0a28 | 1412 | (define-obsolete-variable-alias 'allout-exposure-change-hook |
2a1e2476 | 1413 | 'allout-exposure-change-functions "24.3") |
7b97c764 CY |
1414 | (defcustom allout-exposure-change-functions nil |
1415 | "Abnormal hook run after allout outline subtree exposure changes. | |
48bd8440 EZ |
1416 | It is run at the conclusion of `allout-flag-region'. |
1417 | ||
1418 | Functions on the hook must take three arguments: | |
1419 | ||
60c7bbd2 RS |
1420 | - FROM -- integer indicating the point at the start of the change. |
1421 | - TO -- integer indicating the point of the end of the change. | |
1422 | - FLAG -- change mode: nil for exposure, otherwise concealment. | |
48bd8440 | 1423 | |
7b97c764 CY |
1424 | This hook might be invoked multiple times by a single command." |
1425 | :type 'hook | |
1426 | :group 'allout | |
2a1e2476 | 1427 | :version "24.3") |
48bd8440 | 1428 | |
7b97c764 | 1429 | ;;;_ = allout-structure-added-functions |
e5bd0a28 | 1430 | (define-obsolete-variable-alias 'allout-structure-added-hook |
2a1e2476 | 1431 | 'allout-structure-added-functions "24.3") |
7b97c764 CY |
1432 | (defcustom allout-structure-added-functions nil |
1433 | "Abnormal hook run after adding items to an Allout outline. | |
48bd8440 EZ |
1434 | Functions on the hook should take two arguments: |
1435 | ||
60c7bbd2 RS |
1436 | - NEW-START -- integer indicating position of start of the first new item. |
1437 | - NEW-END -- integer indicating position of end of the last new item. | |
48bd8440 | 1438 | |
7b97c764 CY |
1439 | This hook might be invoked multiple times by a single command." |
1440 | :type 'hook | |
1441 | :group 'allout | |
2a1e2476 | 1442 | :version "24.3") |
7b97c764 | 1443 | |
7b97c764 | 1444 | ;;;_ = allout-structure-deleted-functions |
e5bd0a28 | 1445 | (define-obsolete-variable-alias 'allout-structure-deleted-hook |
2a1e2476 | 1446 | 'allout-structure-deleted-functions "24.3") |
7b97c764 CY |
1447 | (defcustom allout-structure-deleted-functions nil |
1448 | "Abnormal hook run after deleting subtrees from an Allout outline. | |
48bd8440 EZ |
1449 | Functions on the hook must take two arguments: |
1450 | ||
60c7bbd2 RS |
1451 | - DEPTH -- integer indicating the depth of the subtree that was deleted. |
1452 | - REMOVED-FROM -- integer indicating the point where the subtree was removed. | |
da506f05 | 1453 | |
20db1522 | 1454 | Some edits that remove or invalidate items may be missed by this hook: |
48bd8440 | 1455 | specifically edits that native allout routines do not control. |
96b83743 | 1456 | |
7b97c764 CY |
1457 | This hook might be invoked multiple times by a single command." |
1458 | :type 'hook | |
1459 | :group 'allout | |
2a1e2476 | 1460 | :version "24.3") |
48bd8440 | 1461 | |
7b97c764 | 1462 | ;;;_ = allout-structure-shifted-functions |
e5bd0a28 | 1463 | (define-obsolete-variable-alias 'allout-structure-shifted-hook |
2a1e2476 | 1464 | 'allout-structure-shifted-functions "24.3") |
7b97c764 CY |
1465 | (defcustom allout-structure-shifted-functions nil |
1466 | "Abnormal hook run after shifting items in an Allout outline. | |
48bd8440 EZ |
1467 | Functions on the hook should take two arguments: |
1468 | ||
60c7bbd2 RS |
1469 | - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease |
1470 | - START -- integer indicating the start point of the shifted parent item. | |
48bd8440 | 1471 | |
60c7bbd2 | 1472 | Some edits that shift items can be missed by this hook: specifically edits |
48bd8440 EZ |
1473 | that native allout routines do not control. |
1474 | ||
7b97c764 CY |
1475 | This hook might be invoked multiple times by a single command." |
1476 | :type 'hook | |
1477 | :group 'allout | |
2a1e2476 | 1478 | :version "24.3") |
7b97c764 | 1479 | |
4ec28e14 | 1480 | ;;;_ = allout-after-copy-or-kill-hook |
7b97c764 CY |
1481 | (defcustom allout-after-copy-or-kill-hook nil |
1482 | "Normal hook run after copying outline text.." | |
1483 | :type 'hook | |
1484 | :group 'allout | |
2a1e2476 | 1485 | :version "24.3") |
4ec28e14 | 1486 | |
919d884a | 1487 | ;;;_ = allout-post-undo-hook |
7b97c764 CY |
1488 | (defcustom allout-post-undo-hook nil |
1489 | "Normal hook run after undo activity. | |
919d884a | 1490 | The item that's current when the hook is run *may* be the one |
7b97c764 CY |
1491 | that was affected by the undo.." |
1492 | :type 'hook | |
1493 | :group 'allout | |
2a1e2476 | 1494 | :version "24.3") |
919d884a | 1495 | |
96b83743 EZ |
1496 | ;;;_ = allout-outside-normal-auto-fill-function |
1497 | (defvar allout-outside-normal-auto-fill-function nil | |
20db1522 | 1498 | "Value of `normal-auto-fill-function' outside of allout mode. |
96b83743 | 1499 | |
20db1522 JB |
1500 | Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function' |
1501 | wrapped within allout's automatic `fill-prefix' setting.") | |
96b83743 | 1502 | (make-variable-buffer-local 'allout-outside-normal-auto-fill-function) |
2576c28f KM |
1503 | ;;;_ = prevent redundant activation by desktop mode: |
1504 | (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil)) | |
0949617b EZ |
1505 | ;;;_ = allout-passphrase-verifier-string |
1506 | (defvar allout-passphrase-verifier-string nil | |
1507 | "Setting used to test solicited encryption passphrases against the one | |
1508 | already associated with a file. | |
1509 | ||
1510 | It consists of an encrypted random string useful only to verify that a | |
1511 | passphrase entered by the user is effective for decryption. The passphrase | |
1512 | itself is \*not* recorded in the file anywhere, and the encrypted contents | |
1513 | are random binary characters to avoid exposing greater susceptibility to | |
1514 | search attacks. | |
d82979ea EZ |
1515 | |
1516 | The verifier string is retained as an Emacs file variable, as well as in | |
a0a022d5 | 1517 | the Emacs buffer state, if file variable adjustments are enabled. See |
d82979ea | 1518 | `allout-enable-file-variable-adjustment' for details about that.") |
0949617b | 1519 | (make-variable-buffer-local 'allout-passphrase-verifier-string) |
59f7af81 CY |
1520 | (make-obsolete-variable 'allout-passphrase-verifier-string |
1521 | 'allout-passphrase-verifier-string "23.3") | |
8570ce80 | 1522 | ;;;###autoload |
7e5d77dc | 1523 | (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp) |
0949617b EZ |
1524 | ;;;_ = allout-passphrase-hint-string |
1525 | (defvar allout-passphrase-hint-string "" | |
1526 | "Variable used to retain reminder string for file's encryption passphrase. | |
d82979ea | 1527 | |
0949617b | 1528 | See the description of `allout-passphrase-hint-handling' for details about how |
d82979ea EZ |
1529 | the reminder is deployed. |
1530 | ||
a0a022d5 | 1531 | The hint is retained as an Emacs file variable, as well as in the Emacs buffer |
d82979ea EZ |
1532 | state, if file variable adjustments are enabled. See |
1533 | `allout-enable-file-variable-adjustment' for details about that.") | |
0949617b EZ |
1534 | (make-variable-buffer-local 'allout-passphrase-hint-string) |
1535 | (setq-default allout-passphrase-hint-string "") | |
59f7af81 CY |
1536 | (make-obsolete-variable 'allout-passphrase-hint-string |
1537 | 'allout-passphrase-hint-string "23.3") | |
8570ce80 SM |
1538 | ;;;###autoload |
1539 | (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp) | |
d82979ea EZ |
1540 | ;;;_ = allout-after-save-decrypt |
1541 | (defvar allout-after-save-decrypt nil | |
1542 | "Internal variable, is nil or has the value of two points: | |
1543 | ||
1544 | - the location of a topic to be decrypted after saving is done | |
1545 | - where to situate the cursor after the decryption is performed | |
1546 | ||
1547 | This is used to decrypt the topic that was currently being edited, if it | |
1548 | was encrypted automatically as part of a file write or autosave.") | |
1549 | (make-variable-buffer-local 'allout-after-save-decrypt) | |
48bd8440 EZ |
1550 | ;;;_ = allout-encryption-plaintext-sanitization-regexps |
1551 | (defvar allout-encryption-plaintext-sanitization-regexps nil | |
1552 | "List of regexps whose matches are removed from plaintext before encryption. | |
1553 | ||
1554 | This is for the sake of removing artifacts, like escapes, that are added on | |
1555 | and not actually part of the original plaintext. The removal is done just | |
1556 | prior to encryption. | |
1557 | ||
1558 | Entries must be symbols that are bound to the desired values. | |
1559 | ||
1560 | Each value can be a regexp or a list with a regexp followed by a | |
1561 | substitution string. If it's just a regexp, all its matches are removed | |
1562 | before the text is encrypted. If it's a regexp and a substitution, the | |
c7015153 | 1563 | substitution is used against the regexp matches, a la `replace-match'.") |
30ae0b2c | 1564 | (make-variable-buffer-local 'allout-encryption-plaintext-sanitization-regexps) |
48bd8440 EZ |
1565 | ;;;_ = allout-encryption-ciphertext-rejection-regexps |
1566 | (defvar allout-encryption-ciphertext-rejection-regexps nil | |
1567 | "Variable for regexps matching plaintext to remove before encryption. | |
1568 | ||
ff3e8c8e | 1569 | This is used to detect strings in encryption results that would |
4c36be58 | 1570 | register as allout mode structural elements, for example, as a |
ff3e8c8e | 1571 | topic prefix. |
48bd8440 EZ |
1572 | |
1573 | Entries must be symbols that are bound to the desired regexp values. | |
1574 | ||
ff3e8c8e KM |
1575 | Encryptions that result in matches will be retried, up to |
1576 | `allout-encryption-ciphertext-rejection-limit' times, after which | |
1577 | an error is raised.") | |
48bd8440 EZ |
1578 | |
1579 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps) | |
1580 | ;;;_ = allout-encryption-ciphertext-rejection-ceiling | |
1581 | (defvar allout-encryption-ciphertext-rejection-ceiling 5 | |
1582 | "Limit on number of times encryption ciphertext is rejected. | |
1583 | ||
1584 | See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.") | |
1585 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling) | |
69027dea EZ |
1586 | ;;;_ > allout-mode-p () |
1587 | ;; Must define this macro above any uses, or byte compilation will lack | |
60c7bbd2 | 1588 | ;; proper def, if file isn't loaded -- eg, during emacs build! |
96497653 | 1589 | ;;;###autoload |
69027dea EZ |
1590 | (defmacro allout-mode-p () |
1591 | "Return t if `allout-mode' is active in current buffer." | |
1592 | 'allout-mode) | |
13aa217b KM |
1593 | ;;;_ > allout-write-contents-hook-handler () |
1594 | (defun allout-write-contents-hook-handler () | |
1595 | "Implement `allout-encrypt-unencrypted-on-saves' for file writes | |
1596 | ||
1597 | Return nil if all goes smoothly, or else return an informative | |
1598 | message if an error is encountered. The message will serve as a | |
1599 | non-nil return on `write-contents-functions' to prevent saving of | |
1600 | the buffer while it has decrypted content. | |
1601 | ||
20db1522 | 1602 | This behavior depends on Emacs versions that implement the |
13aa217b | 1603 | `write-contents-functions' hook." |
d82979ea | 1604 | |
0949617b EZ |
1605 | (if (or (not (allout-mode-p)) |
1606 | (not (boundp 'allout-encrypt-unencrypted-on-saves)) | |
d82979ea EZ |
1607 | (not allout-encrypt-unencrypted-on-saves)) |
1608 | nil | |
13aa217b KM |
1609 | (if (save-excursion (goto-char (point-min)) |
1610 | (allout-next-topic-pending-encryption)) | |
1611 | (progn | |
1612 | (message "auto-encrypting pending topics") | |
1613 | (sit-for 0) | |
1614 | (condition-case failure | |
1615 | (progn | |
d82979ea | 1616 | (setq allout-after-save-decrypt |
13aa217b KM |
1617 | (allout-encrypt-decrypted)) |
1618 | ;; aok - return nil: | |
1619 | nil) | |
1620 | (error | |
1621 | ;; whoops - probably some still-decrypted items, return non-nil: | |
1622 | (let ((text (format (concat "%s contents write inhibited due to" | |
1623 | " encrypted topic encryption error:" | |
1624 | " %s") | |
1625 | (buffer-name (current-buffer)) | |
1626 | failure))) | |
1627 | (message text)(sit-for 2) | |
1628 | text))))) | |
1629 | )) | |
d82979ea EZ |
1630 | ;;;_ > allout-after-saves-handler () |
1631 | (defun allout-after-saves-handler () | |
1632 | "Decrypt topic encrypted for save, if it's currently being edited. | |
1633 | ||
1634 | Ie, if it was pending encryption and contained the point in its body before | |
1635 | the save. | |
1636 | ||
1637 | We use values stored in `allout-after-save-decrypt' to locate the topic | |
1638 | and the place for the cursor after the decryption is done." | |
1639 | (if (not (and (allout-mode-p) | |
1640 | (boundp 'allout-after-save-decrypt) | |
1641 | allout-after-save-decrypt)) | |
1642 | t | |
1643 | (goto-char (car allout-after-save-decrypt)) | |
1644 | (let ((was-modified (buffer-modified-p))) | |
69027dea | 1645 | (allout-toggle-subtree-encryption) |
d82979ea EZ |
1646 | (if (not was-modified) |
1647 | (set-buffer-modified-p nil))) | |
1648 | (goto-char (cadr allout-after-save-decrypt)) | |
1649 | (setq allout-after-save-decrypt nil)) | |
1650 | ) | |
1c9b9df0 KM |
1651 | ;;;_ > allout-called-interactively-p () |
1652 | (defmacro allout-called-interactively-p () | |
20db1522 | 1653 | "A version of `called-interactively-p' independent of Emacs version." |
1c9b9df0 | 1654 | ;; ... to ease maintenance of allout without betraying deprecation. |
23ba2705 SM |
1655 | (if (ignore-errors (called-interactively-p 'interactive) t) |
1656 | '(called-interactively-p 'interactive) | |
1657 | '(called-interactively-p))) | |
498a6493 CY |
1658 | ;;;_ = allout-inhibit-aberrance-doublecheck nil |
1659 | ;; In some exceptional moments, disparate topic depths need to be allowed | |
1660 | ;; momentarily, eg when one topic is being yanked into another and they're | |
1661 | ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck | |
1662 | ;; prevents the aberrance doublecheck to allow, eg, the reconciliation | |
1663 | ;; processing to happen in the presence of such discrepancies. It should | |
1664 | ;; almost never be needed, however. | |
1665 | (defvar allout-inhibit-aberrance-doublecheck nil | |
1666 | "Internal state, for momentarily inhibits aberrance doublecheck. | |
1667 | ||
1668 | This should only be momentarily let-bound non-nil, not set | |
1669 | non-nil in a lasting way.") | |
19b84ba3 | 1670 | |
1c9b9df0 | 1671 | ;;;_ #2 Mode environment and activation |
fd5359c6 MR |
1672 | ;;;_ = allout-explicitly-deactivated |
1673 | (defvar allout-explicitly-deactivated nil | |
d82979ea | 1674 | "If t, `allout-mode's last deactivation was deliberate. |
2265e017 | 1675 | So `allout-post-command-business' should not reactivate it...") |
fd5359c6 | 1676 | (make-variable-buffer-local 'allout-explicitly-deactivated) |
11c46e15 KM |
1677 | ;;;_ > allout-init (mode) |
1678 | (defun allout-init (mode) | |
1679 | "DEPRECATED - configure allout activation by customizing | |
1680 | `allout-auto-activation'. This function remains around, limited | |
01c35094 | 1681 | from what it did before, for backwards compatibility. |
11c46e15 KM |
1682 | |
1683 | MODE is the activation mode - see `allout-auto-activation' for | |
1684 | valid values." | |
59f7af81 | 1685 | (declare (obsolete allout-auto-activation "23.3")) |
11c46e15 KM |
1686 | (custom-set-variables (list 'allout-auto-activation (format "%s" mode))) |
1687 | (format "%s" mode)) | |
59f7af81 | 1688 | |
fd5359c6 MR |
1689 | ;;;_ > allout-setup-menubar () |
1690 | (defun allout-setup-menubar () | |
aad94676 | 1691 | "Populate the current buffer's menubar with `allout-mode' stuff." |
fd5359c6 MR |
1692 | (let ((menus (list allout-mode-exposure-menu |
1693 | allout-mode-editing-menu | |
1694 | allout-mode-navigation-menu | |
1695 | allout-mode-misc-menu)) | |
9179616f DL |
1696 | cur) |
1697 | (while menus | |
1698 | (setq cur (car menus) | |
1699 | menus (cdr menus)) | |
1700 | (easy-menu-add cur)))) | |
01fc9422 EZ |
1701 | ;;;_ > allout-overlay-preparations |
1702 | (defun allout-overlay-preparations () | |
1703 | "Set the properties of the allout invisible-text overlay and others." | |
1704 | (setplist 'allout-exposure-category nil) | |
1705 | (put 'allout-exposure-category 'invisible 'allout) | |
1706 | (put 'allout-exposure-category 'evaporate t) | |
1c9b9df0 | 1707 | ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The |
ea18b2b1 | 1708 | ;; latter would be sufficient, but it seems that a separate behavior -- |
60c7bbd2 RS |
1709 | ;; the _transient_ opening of invisible text during isearch -- is keyed to |
1710 | ;; presence of the isearch-open-invisible property -- even though this | |
96b83743 | 1711 | ;; property controls the isearch _arrival_ behavior. This is the case at |
21e8bc99 | 1712 | ;; least in emacs 21, 22.1, and xemacs 21.4. |
01fc9422 | 1713 | (put 'allout-exposure-category 'isearch-open-invisible |
96b83743 EZ |
1714 | 'allout-isearch-end-handler) |
1715 | (if (featurep 'xemacs) | |
01fc9422 EZ |
1716 | (put 'allout-exposure-category 'start-open t) |
1717 | (put 'allout-exposure-category 'insert-in-front-hooks | |
96b83743 | 1718 | '(allout-overlay-insert-in-front-handler))) |
01fc9422 EZ |
1719 | (put 'allout-exposure-category 'modification-hooks |
1720 | '(allout-overlay-interior-modification-handler))) | |
d3e51865 | 1721 | ;;;_ > define-minor-mode allout-mode |
19b84ba3 | 1722 | ;;;_ : Defun: |
0949617b | 1723 | ;;;###autoload |
d3e51865 | 1724 | (define-minor-mode allout-mode |
c567ac01 | 1725 | ;;;_ . Doc string: |
06e21633 CY |
1726 | "Toggle Allout outline mode. |
1727 | With a prefix argument ARG, enable Allout outline mode if ARG is | |
1728 | positive, and disable it otherwise. If called from Lisp, enable | |
1729 | the mode if ARG is omitted or nil. | |
19b84ba3 | 1730 | |
06e21633 CY |
1731 | \\<allout-mode-map-value> |
1732 | Allout outline mode is a minor mode that provides extensive | |
1733 | outline oriented formatting and manipulation. It enables | |
1734 | structural editing of outlines, as well as navigation and | |
1735 | exposure. It also is specifically aimed at accommodating | |
20db1522 | 1736 | syntax-sensitive text like programming languages. (For example, |
06e21633 CY |
1737 | see the allout code itself, which is organized as an allout |
1738 | outline.) | |
19b84ba3 | 1739 | |
c07583cd | 1740 | In addition to typical outline navigation and exposure, allout includes: |
19b84ba3 | 1741 | |
c07583cd KS |
1742 | - topic-oriented authoring, including keystroke-based topic creation, |
1743 | repositioning, promotion/demotion, cut, and paste | |
9179616f | 1744 | - incremental search with dynamic exposure and reconcealment of hidden text |
c07583cd | 1745 | - adjustable format, so programming code can be developed in outline-structure |
2576c28f | 1746 | - easy topic encryption and decryption, symmetric or key-pair |
c07583cd KS |
1747 | - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control |
1748 | - integral outline layout, for automatic initial exposure when visiting a file | |
1749 | - independent extensibility, using comprehensive exposure and authoring hooks | |
9179616f DL |
1750 | |
1751 | and many other features. | |
19b84ba3 | 1752 | |
2576c28f KM |
1753 | Below is a description of the key bindings, and then description |
1754 | of special `allout-mode' features and terminology. See also the | |
1755 | outline menubar additions for quick reference to many of the | |
11c46e15 | 1756 | features. Customize `allout-auto-activation' to prepare your |
20db1522 | 1757 | Emacs session for automatic activation of `allout-mode'. |
9179616f | 1758 | |
d3e51865 KM |
1759 | The bindings are those listed in `allout-prefixed-keybindings' |
1760 | and `allout-unprefixed-keybindings'. We recommend customizing | |
1761 | `allout-command-prefix' to use just `\\C-c' as the command | |
1762 | prefix, if the allout bindings don't conflict with any personal | |
1763 | bindings you have on \\C-c. In any case, outline structure | |
1764 | navigation and authoring is simplified by positioning the cursor | |
1765 | on an item's bullet character, the \"hot-spot\" -- then you can | |
1766 | invoke allout commands with just the un-prefixed, | |
1767 | un-control-shifted command letters. This is described further in | |
1768 | the HOT-SPOT Operation section. | |
c07583cd KS |
1769 | |
1770 | Exposure Control: | |
1771 | ---------------- | |
1772 | \\[allout-hide-current-subtree] `allout-hide-current-subtree' | |
1773 | \\[allout-show-children] `allout-show-children' | |
1774 | \\[allout-show-current-subtree] `allout-show-current-subtree' | |
1775 | \\[allout-show-current-entry] `allout-show-current-entry' | |
1776 | \\[allout-show-all] `allout-show-all' | |
1777 | ||
1778 | Navigation: | |
1779 | ---------- | |
1780 | \\[allout-next-visible-heading] `allout-next-visible-heading' | |
1781 | \\[allout-previous-visible-heading] `allout-previous-visible-heading' | |
1782 | \\[allout-up-current-level] `allout-up-current-level' | |
1783 | \\[allout-forward-current-level] `allout-forward-current-level' | |
1784 | \\[allout-backward-current-level] `allout-backward-current-level' | |
1785 | \\[allout-end-of-entry] `allout-end-of-entry' | |
1786 | \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot) | |
60c7bbd2 | 1787 | \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but |
c07583cd KS |
1788 | if immediately repeated cycles to the beginning of the current item |
1789 | and then to the hot-spot (if `allout-beginning-of-line-cycles' is set). | |
1790 | ||
1791 | ||
1792 | Topic Header Production: | |
1793 | ----------------------- | |
1794 | \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic. | |
1795 | \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic. | |
1796 | \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent. | |
1797 | ||
1798 | Topic Level and Prefix Adjustment: | |
1799 | --------------------------------- | |
1800 | \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper | |
1801 | \\[allout-shift-out] `allout-shift-out' ... less deep | |
1802 | \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for | |
1803 | current topic | |
1804 | \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and | |
20db1522 | 1805 | its offspring -- distinctive bullets are not changed, others |
c07583cd | 1806 | are alternated according to nesting depth. |
ea18b2b1 | 1807 | \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -- |
c07583cd KS |
1808 | the offspring are not affected. |
1809 | With repeat count, revoke numbering. | |
1810 | ||
1811 | Topic-oriented Killing and Yanking: | |
1812 | ---------------------------------- | |
1813 | \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring. | |
1814 | \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring. | |
20db1522 | 1815 | \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure. |
c07583cd KS |
1816 | \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it. |
1817 | \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to | |
1818 | depth of heading if yanking into bare topic | |
1819 | heading (ie, prefix sans text). | |
20db1522 | 1820 | \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'. |
c07583cd KS |
1821 | |
1822 | Topic-oriented Encryption: | |
1823 | ------------------------- | |
1824 | \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption' | |
1825 | Encrypt/Decrypt topic content | |
1826 | ||
1827 | Misc commands: | |
1828 | ------------- | |
1829 | M-x outlineify-sticky Activate outline mode for current buffer, | |
1830 | and establish a default file-var setting | |
1831 | for `allout-layout'. | |
1832 | \\[allout-mark-topic] `allout-mark-topic' | |
1833 | \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer' | |
1834 | Duplicate outline, sans concealed text, to | |
1835 | buffer with name derived from derived from that | |
60c7bbd2 | 1836 | of current buffer -- \"*BUFFERNAME exposed*\". |
c07583cd KS |
1837 | \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer' |
1838 | Like above 'copy-exposed', but convert topic | |
1839 | prefixes to section.subsection... numeric | |
1840 | format. | |
11c46e15 KM |
1841 | \\[customize-variable] allout-auto-activation |
1842 | Prepare Emacs session for allout outline mode | |
c07583cd | 1843 | auto-activation. |
1977b8f6 | 1844 | |
96b83743 | 1845 | Topic Encryption |
d82979ea | 1846 | |
96b83743 | 1847 | Outline mode supports gpg encryption of topics, with support for |
29fac3fe KM |
1848 | symmetric and key-pair modes, and auto-encryption of topics |
1849 | pending encryption on save. | |
d82979ea | 1850 | |
c07583cd | 1851 | Topics pending encryption are, by default, automatically |
29fac3fe KM |
1852 | encrypted during file saves, including checkpoint saves, to avoid |
1853 | exposing the plain text of encrypted topics in the file system. | |
1854 | If the content of the topic containing the cursor was encrypted | |
1855 | for a save, it is automatically decrypted for continued editing. | |
c07583cd | 1856 | |
2576c28f KM |
1857 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
1858 | symmetric decryption keys, preventing entry of the correct key on | |
1859 | subsequent decryption attempts until the cache times-out. That | |
20db1522 | 1860 | can take several minutes. (Decryption of other entries is not |
2576c28f KM |
1861 | affected.) Upgrade your EasyPG version, if you can, and you can |
1862 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
1863 | signal. | |
c07583cd KS |
1864 | |
1865 | See `allout-toggle-current-subtree-encryption' function docstring | |
1866 | and `allout-encrypt-unencrypted-on-saves' customization variable | |
1867 | for details. | |
d82979ea | 1868 | |
c07583cd | 1869 | HOT-SPOT Operation |
c567ac01 | 1870 | |
19b84ba3 RS |
1871 | Hot-spot operation provides a means for easy, single-keystroke outline |
1872 | navigation and exposure control. | |
c567ac01 | 1873 | |
19b84ba3 RS |
1874 | When the text cursor is positioned directly on the bullet character of |
1875 | a topic, regular characters (a to z) invoke the commands of the | |
fd5359c6 | 1876 | corresponding allout-mode keymap control chars. For example, \"f\" |
96b83743 | 1877 | would invoke the command typically bound to \"C-c<space>C-f\" |
fd5359c6 | 1878 | \(\\[allout-forward-current-level] `allout-forward-current-level'). |
19b84ba3 | 1879 | |
96b83743 EZ |
1880 | Thus, by positioning the cursor on a topic bullet, you can |
1881 | execute the outline navigation and manipulation commands with a | |
c07583cd | 1882 | single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get |
96b83743 | 1883 | this special translation, so you can use them to get out of the |
c07583cd KS |
1884 | hot-spot and back to normal editing operation. |
1885 | ||
d41b91e6 | 1886 | In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is |
c07583cd KS |
1887 | replaced with one that makes it easy to get to the hot-spot. If you |
1888 | repeat it immediately it cycles (if `allout-beginning-of-line-cycles' | |
1889 | is set) to the beginning of the item and then, if you hit it again | |
1890 | immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry' | |
1891 | \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located | |
1892 | at the beginning of the current entry. | |
1893 | ||
1894 | Extending Allout | |
c567ac01 | 1895 | |
fa463103 | 1896 | Allout exposure and authoring activities all have associated |
c07583cd KS |
1897 | hooks, by which independent code can cooperate with allout |
1898 | without changes to the allout core. Here are key ones: | |
1977b8f6 | 1899 | |
c07583cd | 1900 | `allout-mode-hook' |
20db1522 | 1901 | `allout-mode-deactivate-hook' (deprecated) |
2576c28f | 1902 | `allout-mode-off-hook' |
7b97c764 CY |
1903 | `allout-exposure-change-functions' |
1904 | `allout-structure-added-functions' | |
1905 | `allout-structure-deleted-functions' | |
1906 | `allout-structure-shifted-functions' | |
4ec28e14 | 1907 | `allout-after-copy-or-kill-hook' |
919d884a | 1908 | `allout-post-undo-hook' |
c07583cd KS |
1909 | |
1910 | Terminology | |
1977b8f6 | 1911 | |
60c7bbd2 | 1912 | Topic hierarchy constituents -- TOPICS and SUBTOPICS: |
c567ac01 | 1913 | |
c07583cd KS |
1914 | ITEM: A unitary outline element, including the HEADER and ENTRY text. |
1915 | TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH | |
1916 | and with no intervening items of lower DEPTH than the container. | |
1917 | CURRENT ITEM: | |
1918 | The visible ITEM most immediately containing the cursor. | |
1919 | DEPTH: The degree of nesting of an ITEM; it increases with containment. | |
1920 | The DEPTH is determined by the HEADER PREFIX. The DEPTH is also | |
1921 | called the: | |
1922 | LEVEL: The same as DEPTH. | |
c567ac01 RS |
1923 | |
1924 | ANCESTORS: | |
c07583cd KS |
1925 | Those ITEMs whose TOPICs contain an ITEM. |
1926 | PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that | |
1927 | of the ITEM. | |
c567ac01 | 1928 | OFFSPRING: |
c07583cd | 1929 | The ITEMs contained within an ITEM's TOPIC. |
19b84ba3 | 1930 | SUBTOPIC: |
c07583cd KS |
1931 | An OFFSPRING of its ANCESTOR TOPICs. |
1932 | CHILD: | |
1933 | An immediate SUBTOPIC of its PARENT. | |
c567ac01 | 1934 | SIBLINGS: |
c07583cd | 1935 | TOPICs having the same PARENT and DEPTH. |
353e2ef2 | 1936 | |
c567ac01 RS |
1937 | Topic text constituents: |
1938 | ||
c07583cd KS |
1939 | HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER |
1940 | text. | |
1941 | ENTRY: The text content of an ITEM, before any OFFSPRING, but including | |
1942 | the HEADER text and distinct from the ITEM PREFIX. | |
1943 | BODY: Same as ENTRY. | |
1944 | PREFIX: The leading text of an ITEM which distinguishes it from normal | |
1945 | ENTRY text. Allout recognizes the outline structure according | |
1946 | to the strict PREFIX format. It consists of a PREFIX-LEAD string, | |
1947 | PREFIX-PADDING, and a BULLET. The BULLET might be followed by a | |
d82979ea | 1948 | number, indicating the ordinal number of the topic among its |
c07583cd KS |
1949 | siblings, or an asterisk indicating encryption, plus an optional |
1950 | space. After that is the ITEM HEADER text, which is not part of | |
1951 | the PREFIX. | |
c567ac01 | 1952 | |
c07583cd KS |
1953 | The relative length of the PREFIX determines the nesting DEPTH |
1954 | of the ITEM. | |
c567ac01 | 1955 | PREFIX-LEAD: |
c07583cd KS |
1956 | The string at the beginning of a HEADER PREFIX, by default a `.'. |
1957 | It can be customized by changing the setting of | |
1958 | `allout-header-prefix' and then reinitializing `allout-mode'. | |
1959 | ||
1960 | When the PREFIX-LEAD is set to the comment-string of a | |
1961 | programming language, outline structuring can be embedded in | |
1962 | program code without interfering with processing of the text | |
20db1522 | 1963 | (by Emacs or the language processor) as program code. This |
c07583cd KS |
1964 | setting happens automatically when allout mode is used in |
1965 | programming-mode buffers. See `allout-use-mode-specific-leader' | |
1966 | docstring for more detail. | |
c567ac01 | 1967 | PREFIX-PADDING: |
c07583cd KS |
1968 | Spaces or asterisks which separate the PREFIX-LEAD and the |
1969 | bullet, determining the ITEM's DEPTH. | |
1970 | BULLET: A character at the end of the ITEM PREFIX, it must be one of | |
1971 | the characters listed on `allout-plain-bullets-string' or | |
38b2ca53 NR |
1972 | `allout-distinctive-bullets-string'. When creating a TOPIC, |
1973 | plain BULLETs are by default used, according to the DEPTH of the | |
1974 | TOPIC. Choice among the distinctive BULLETs is offered when you | |
20db1522 | 1975 | provide a universal argument (\\[universal-argument]) to the |
e4769531 | 1976 | TOPIC creation command, or when explicitly rebulleting a TOPIC. The |
38b2ca53 NR |
1977 | significance of the various distinctive bullets is purely by |
1978 | convention. See the documentation for the above bullet strings for | |
1979 | more details. | |
c567ac01 | 1980 | EXPOSURE: |
c07583cd KS |
1981 | The state of a TOPIC which determines the on-screen visibility |
1982 | of its OFFSPRING and contained ENTRY text. | |
c567ac01 | 1983 | CONCEALED: |
c07583cd KS |
1984 | TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed |
1985 | text is represented by \"...\" ellipses. | |
c567ac01 | 1986 | |
c07583cd KS |
1987 | CONCEALED TOPICs are effectively collapsed within an ANCESTOR. |
1988 | CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED. | |
1989 | OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be." | |
c567ac01 | 1990 | ;;;_ . Code |
d3e51865 KM |
1991 | :lighter " Allout" |
1992 | :keymap 'allout-mode-map | |
1977b8f6 | 1993 | |
13aa217b | 1994 | (let ((use-layout (if (listp allout-layout) |
2576c28f KM |
1995 | allout-layout |
1996 | allout-default-layout))) | |
1977b8f6 | 1997 | |
d3e51865 | 1998 | (if (not (allout-mode-p)) |
2576c28f KM |
1999 | (progn |
2000 | ;; Deactivation: | |
2001 | ||
2002 | ; Activation not explicitly | |
2003 | ; requested, and either in | |
2004 | ; active state or *de*activation | |
2005 | ; specifically requested: | |
2006 | (allout-do-resumptions) | |
2007 | ||
2008 | (remove-from-invisibility-spec '(allout . t)) | |
2009 | (remove-hook 'pre-command-hook 'allout-pre-command-business t) | |
2010 | (remove-hook 'post-command-hook 'allout-post-command-business t) | |
2011 | (remove-hook 'before-change-functions 'allout-before-change-handler t) | |
2012 | (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) | |
13aa217b KM |
2013 | (remove-hook 'write-contents-functions |
2014 | 'allout-write-contents-hook-handler t) | |
2576c28f KM |
2015 | |
2016 | (remove-overlays (point-min) (point-max) | |
d3e51865 | 2017 | 'category 'allout-exposure-category)) |
2576c28f | 2018 | |
d3e51865 | 2019 | ;; Activating: |
fd5359c6 | 2020 | (if allout-old-style-prefixes |
01fc9422 | 2021 | ;; Inhibit all the fancy formatting: |
48bd8440 | 2022 | (allout-add-resumptions '(allout-primary-bullet "*"))) |
19b84ba3 | 2023 | |
01fc9422 | 2024 | (allout-overlay-preparations) ; Doesn't hurt to redo this. |
96b83743 | 2025 | |
d8350998 | 2026 | (allout-infer-header-lead-and-primary-bullet) |
fd5359c6 | 2027 | (allout-infer-body-reindent) |
19b84ba3 | 2028 | |
fd5359c6 | 2029 | (set-allout-regexp) |
2576c28f KM |
2030 | (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps |
2031 | allout-line-boundary-regexp | |
2032 | extend) | |
2033 | '(allout-encryption-ciphertext-rejection-regexps | |
2034 | allout-bob-regexp | |
2035 | extend)) | |
19b84ba3 | 2036 | |
d3e51865 | 2037 | (allout-compose-and-institute-keymap) |
01fc9422 | 2038 | (produce-allout-mode-menubar-entries) |
01fc9422 | 2039 | |
96b83743 | 2040 | (add-to-invisibility-spec '(allout . t)) |
38b2ca53 | 2041 | |
01fc9422 EZ |
2042 | (allout-add-resumptions '(line-move-ignore-invisible t)) |
2043 | (add-hook 'pre-command-hook 'allout-pre-command-business nil t) | |
2044 | (add-hook 'post-command-hook 'allout-post-command-business nil t) | |
2576c28f | 2045 | (add-hook 'before-change-functions 'allout-before-change-handler nil t) |
01fc9422 | 2046 | (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) |
13aa217b | 2047 | (add-hook 'write-contents-functions 'allout-write-contents-hook-handler |
01fc9422 | 2048 | nil t) |
01fc9422 EZ |
2049 | |
2050 | ;; Stash auto-fill settings and adjust so custom allout auto-fill | |
2051 | ;; func will be used if auto-fill is active or activated. (The | |
2052 | ;; custom func respects topic headline, maintains hanging-indents, | |
2053 | ;; etc.) | |
01fc9422 EZ |
2054 | (allout-add-resumptions (list 'allout-former-auto-filler |
2055 | auto-fill-function) | |
2056 | ;; Register allout-auto-fill to be used if | |
2057 | ;; filling is active: | |
2058 | (list 'allout-outside-normal-auto-fill-function | |
2059 | normal-auto-fill-function) | |
2060 | '(normal-auto-fill-function allout-auto-fill) | |
2061 | ;; Paragraphs are broken by topic headlines. | |
2062 | (list 'paragraph-start | |
2063 | (concat paragraph-start "\\|^\\(" | |
2064 | allout-regexp "\\)")) | |
2065 | (list 'paragraph-separate | |
2066 | (concat paragraph-separate "\\|^\\(" | |
2067 | allout-regexp "\\)"))) | |
2576c28f KM |
2068 | (if (and auto-fill-function (not allout-inhibit-auto-fill)) |
2069 | ;; allout-auto-fill will use the stashed values and so forth. | |
2070 | (allout-add-resumptions '(auto-fill-function allout-auto-fill))) | |
2071 | ||
fd5359c6 | 2072 | (allout-setup-menubar) |
2576c28f KM |
2073 | |
2074 | ;; Do auto layout if warranted: | |
2075 | (when (and allout-layout | |
2076 | allout-auto-activation | |
2077 | use-layout | |
11c46e15 KM |
2078 | (and (not (string= allout-auto-activation "activate")) |
2079 | (if (string= allout-auto-activation "ask") | |
2576c28f KM |
2080 | (if (y-or-n-p (format "Expose %s with layout '%s'? " |
2081 | (buffer-name) | |
2082 | use-layout)) | |
2083 | t | |
2084 | (message "Skipped %s layout." (buffer-name)) | |
2085 | nil) | |
2086 | t))) | |
2087 | (save-excursion | |
2088 | (message "Adjusting '%s' exposure..." (buffer-name)) | |
2089 | (goto-char 0) | |
2090 | (allout-this-or-next-heading) | |
2091 | (condition-case err | |
2092 | (progn | |
2093 | (apply 'allout-expose-topic (list use-layout)) | |
2094 | (message "Adjusting '%s' exposure... done." | |
2095 | (buffer-name))) | |
2096 | ;; Problem applying exposure -- notify user, but don't | |
2097 | ;; interrupt, eg, file visit: | |
2098 | (error (message "%s" (car (cdr err))) | |
2099 | (sit-for 1)))) | |
2100 | ) ; when allout-layout | |
2101 | ) ; if (allout-mode-p) | |
2102 | ) ; let (()) | |
2103 | ) ; define-minor-mode | |
2104 | ;;;_ > allout-minor-mode alias | |
2105 | (defalias 'allout-minor-mode 'allout-mode) | |
41ff6d0a JB |
2106 | ;;;_ > allout-unload-function |
2107 | (defun allout-unload-function () | |
2108 | "Unload the allout outline library." | |
2109 | (save-current-buffer | |
2110 | (dolist (buffer (buffer-list)) | |
2111 | (set-buffer buffer) | |
74f53697 | 2112 | (when (allout-mode-p) (allout-mode -1)))) |
41ff6d0a JB |
2113 | ;; continue standard unloading |
2114 | nil) | |
2115 | ||
773e7e48 EZ |
2116 | ;;;_ - Position Assessment |
2117 | ;;;_ > allout-hidden-p (&optional pos) | |
2118 | (defsubst allout-hidden-p (&optional pos) | |
1c9b9df0 | 2119 | "Non-nil if the character after point was made invisible by allout." |
da506f05 | 2120 | (eq (get-char-property (or pos (point)) 'invisible) 'allout)) |
773e7e48 | 2121 | |
96b83743 EZ |
2122 | ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end |
2123 | ;;; &optional prelen) | |
2124 | (defun allout-overlay-insert-in-front-handler (ol after beg end | |
2125 | &optional prelen) | |
2a1408fd | 2126 | "Shift the overlay so stuff inserted in front of it is excluded." |
96b83743 | 2127 | (if after |
1c9b9df0 KM |
2128 | ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay |
2129 | ;; front-advance on the overlay worked as expected? | |
96b83743 EZ |
2130 | (move-overlay ol (1+ beg) (overlay-end ol)))) |
2131 | ;;;_ > allout-overlay-interior-modification-handler (ol after beg end | |
2132 | ;;; &optional prelen) | |
2133 | (defun allout-overlay-interior-modification-handler (ol after beg end | |
2134 | &optional prelen) | |
2135 | "Get confirmation before making arbitrary changes to invisible text. | |
2136 | ||
2137 | We expose the invisible text and ask for confirmation. Refusal or | |
75bcb912 | 2138 | `keyboard-quit' abandons the changes, with keyboard-quit additionally |
96b83743 EZ |
2139 | reclosing the opened text. |
2140 | ||
60c7bbd2 | 2141 | No confirmation is necessary when `inhibit-read-only' is set -- eg, allout |
96b83743 EZ |
2142 | internal functions use this feature cohesively bunch changes." |
2143 | ||
2144 | (when (and (not inhibit-read-only) (not after)) | |
2145 | (let ((start (point)) | |
2146 | (ol-start (overlay-start ol)) | |
2147 | (ol-end (overlay-end ol)) | |
96b83743 EZ |
2148 | first) |
2149 | (goto-char beg) | |
2150 | (while (< (point) end) | |
2151 | (when (allout-hidden-p) | |
2152 | (allout-show-to-offshoot) | |
2153 | (if (allout-hidden-p) | |
2154 | (save-excursion (forward-char 1) | |
2155 | (allout-show-to-offshoot))) | |
2156 | (when (not first) | |
96b83743 EZ |
2157 | (setq first (point)))) |
2158 | (goto-char (if (featurep 'xemacs) | |
2159 | (next-property-change (1+ (point)) nil end) | |
2160 | (next-char-property-change (1+ (point)) end)))) | |
2161 | (when first | |
2162 | (goto-char first) | |
2163 | (condition-case nil | |
2164 | (if (not | |
2165 | (yes-or-no-p | |
2166 | (substitute-command-keys | |
4034b0e2 | 2167 | (concat "Modify concealed text? (\"no\" just aborts," |
96b83743 EZ |
2168 | " \\[keyboard-quit] also reconceals) ")))) |
2169 | (progn (goto-char start) | |
5a0c3f56 | 2170 | (error "Concealed-text change refused"))) |
96b83743 EZ |
2171 | (quit (allout-flag-region ol-start ol-end nil) |
2172 | (allout-flag-region ol-start ol-end t) | |
5a0c3f56 | 2173 | (error "Concealed-text change abandoned, text reconcealed")))) |
96b83743 EZ |
2174 | (goto-char start)))) |
2175 | ;;;_ > allout-before-change-handler (beg end) | |
2176 | (defun allout-before-change-handler (beg end) | |
2177 | "Protect against changes to invisible text. | |
2178 | ||
60c7bbd2 | 2179 | See `allout-overlay-interior-modification-handler' for details." |
d8350998 | 2180 | |
13aa217b KM |
2181 | (when (and (allout-mode-p) undo-in-progress) |
2182 | (setq allout-just-did-undo t) | |
2183 | (if (allout-hidden-p) | |
2184 | (allout-show-children))) | |
d8350998 | 2185 | |
01fc9422 EZ |
2186 | ;; allout-overlay-interior-modification-handler on an overlay handles |
2187 | ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. | |
2188 | (when (and (featurep 'xemacs) (allout-mode-p)) | |
2189 | ;; process all of the pending overlays: | |
d8350998 | 2190 | (save-excursion |
f520c6f2 | 2191 | (goto-char beg) |
d8350998 | 2192 | (let ((overlay (allout-get-invisibility-overlay))) |
1c9b9df0 KM |
2193 | (if overlay |
2194 | (allout-overlay-interior-modification-handler | |
2195 | overlay nil beg end nil)))))) | |
96b83743 EZ |
2196 | ;;;_ > allout-isearch-end-handler (&optional overlay) |
2197 | (defun allout-isearch-end-handler (&optional overlay) | |
2198 | "Reconcile allout outline exposure on arriving in hidden text after isearch. | |
2199 | ||
2200 | Optional OVERLAY parameter is for when this function is used by | |
2201 | `isearch-open-invisible' overlay property. It is otherwise unused, so this | |
2202 | function can also be used as an `isearch-mode-end-hook'." | |
2203 | ||
2204 | (if (and (allout-mode-p) (allout-hidden-p)) | |
2205 | (allout-show-to-offshoot))) | |
2206 | ||
60c7bbd2 | 2207 | ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs |
a5a1e2ef SM |
2208 | ;; All the basic outline functions that directly do string matches to |
2209 | ;; evaluate heading prefix location set the variables | |
2210 | ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' | |
2211 | ;; when successful. Functions starting with `allout-recent-' all | |
2212 | ;; use this state, providing the means to avoid redundant searches | |
2213 | ;; for just-established data. This optimization can provide | |
2214 | ;; significant speed improvement, but it must be employed carefully. | |
fd5359c6 MR |
2215 | ;;;_ = allout-recent-prefix-beginning |
2216 | (defvar allout-recent-prefix-beginning 0 | |
c567ac01 | 2217 | "Buffer point of the start of the last topic prefix encountered.") |
fd5359c6 MR |
2218 | (make-variable-buffer-local 'allout-recent-prefix-beginning) |
2219 | ;;;_ = allout-recent-prefix-end | |
2220 | (defvar allout-recent-prefix-end 0 | |
c567ac01 | 2221 | "Buffer point of the end of the last topic prefix encountered.") |
fd5359c6 | 2222 | (make-variable-buffer-local 'allout-recent-prefix-end) |
d8350998 CY |
2223 | ;;;_ = allout-recent-depth |
2224 | (defvar allout-recent-depth 0 | |
2225 | "Depth of the last topic prefix encountered.") | |
2226 | (make-variable-buffer-local 'allout-recent-depth) | |
fd5359c6 MR |
2227 | ;;;_ = allout-recent-end-of-subtree |
2228 | (defvar allout-recent-end-of-subtree 0 | |
2265e017 | 2229 | "Buffer point last returned by `allout-end-of-current-subtree'.") |
fd5359c6 | 2230 | (make-variable-buffer-local 'allout-recent-end-of-subtree) |
d8350998 CY |
2231 | ;;;_ > allout-prefix-data () |
2232 | (defsubst allout-prefix-data () | |
2233 | "Register allout-prefix state data. | |
fd5359c6 | 2234 | |
75bcb912 JB |
2235 | For reference by `allout-recent' funcs. Return |
2236 | the new value of `allout-recent-prefix-beginning'." | |
42c3e51c | 2237 | (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3)) |
d8350998 | 2238 | allout-recent-prefix-beginning (or (match-beginning 1) |
42c3e51c KM |
2239 | (match-beginning 2) |
2240 | (match-beginning 3)) | |
d8350998 CY |
2241 | allout-recent-depth (max 1 (- allout-recent-prefix-end |
2242 | allout-recent-prefix-beginning | |
2243 | allout-header-subtraction))) | |
2244 | allout-recent-prefix-beginning) | |
2245 | ;;;_ > nullify-allout-prefix-data () | |
2246 | (defsubst nullify-allout-prefix-data () | |
2247 | "Mark allout prefix data as being uninformative." | |
2248 | (setq allout-recent-prefix-end (point) | |
2249 | allout-recent-prefix-beginning (point) | |
2250 | allout-recent-depth 0) | |
2251 | allout-recent-prefix-beginning) | |
fd5359c6 | 2252 | ;;;_ > allout-recent-depth () |
d8350998 | 2253 | (defsubst allout-recent-depth () |
19b84ba3 | 2254 | "Return depth of last heading encountered by an outline maneuvering function. |
c567ac01 RS |
2255 | |
2256 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2257 | headings set the variables `allout-recent-prefix-beginning' and |
2258 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 RS |
2259 | to return the current depth." |
2260 | ||
d8350998 | 2261 | allout-recent-depth) |
fd5359c6 | 2262 | ;;;_ > allout-recent-prefix () |
d8350998 | 2263 | (defsubst allout-recent-prefix () |
2265e017 | 2264 | "Like `allout-recent-depth', but returns text of last encountered prefix. |
c567ac01 RS |
2265 | |
2266 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2267 | headings set the variables `allout-recent-prefix-beginning' and |
2268 | `allout-recent-prefix-end' if successful. This function uses those settings | |
d8350998 CY |
2269 | to return the current prefix." |
2270 | (buffer-substring-no-properties allout-recent-prefix-beginning | |
2271 | allout-recent-prefix-end)) | |
fd5359c6 MR |
2272 | ;;;_ > allout-recent-bullet () |
2273 | (defmacro allout-recent-bullet () | |
20db1522 | 2274 | "Like `allout-recent-prefix', but returns bullet of last encountered prefix. |
c567ac01 RS |
2275 | |
2276 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2277 | headings set the variables `allout-recent-prefix-beginning' and |
2278 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 2279 | to return the current depth of the most recently matched topic." |
d8350998 CY |
2280 | '(buffer-substring-no-properties (1- allout-recent-prefix-end) |
2281 | allout-recent-prefix-end)) | |
c567ac01 | 2282 | |
19b84ba3 | 2283 | ;;;_ #4 Navigation |
c567ac01 | 2284 | |
46771bb3 | 2285 | ;;;_ - Position Assessment |
c567ac01 | 2286 | ;;;_ : Location Predicates |
ede4ac6a KS |
2287 | ;;;_ > allout-do-doublecheck () |
2288 | (defsubst allout-do-doublecheck () | |
2289 | "True if current item conditions qualify for checking on topic aberrance." | |
2290 | (and | |
60c7bbd2 | 2291 | ;; presume integrity of outline and yanked content during yank -- necessary |
ede4ac6a | 2292 | ;; to allow for level disparity of yank location and yanked text: |
498a6493 | 2293 | (not allout-inhibit-aberrance-doublecheck) |
ede4ac6a KS |
2294 | ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck: |
2295 | (<= allout-recent-depth allout-doublecheck-at-and-shallower))) | |
2296 | ;;;_ > allout-aberrant-container-p () | |
d8350998 CY |
2297 | (defun allout-aberrant-container-p () |
2298 | "True if topic, or next sibling with children, contains them discontinuously. | |
2299 | ||
2300 | Discontinuous means an immediate offspring that is nested more | |
2301 | than one level deeper than the topic. | |
2302 | ||
2303 | If topic has no offspring, then the next sibling with offspring will | |
2304 | determine whether or not this one is determined to be aberrant. | |
2305 | ||
2306 | If true, then the allout-recent-* settings are calibrated on the | |
e1dbe924 | 2307 | offspring that qualifies it as aberrant, ie with depth that |
d8350998 CY |
2308 | exceeds the topic by more than one." |
2309 | ||
2310 | ;; This is most clearly understood when considering standard-prefix-leader | |
2311 | ;; low-level topics, which can all too easily match text not intended as | |
2312 | ;; headers. For example, any line with a leading '.' or '*' and lacking a | |
2313 | ;; following bullet qualifies without this protection. (A sequence of | |
2314 | ;; them can occur naturally, eg a typical textual bullet list.) We | |
2315 | ;; disqualify such low-level sequences when they are followed by a | |
2316 | ;; discontinuously contained child, inferring that the sequences are not | |
2317 | ;; actually connected with their prospective context. | |
2318 | ||
2319 | (let ((depth (allout-depth)) | |
2320 | (start-point (point)) | |
2321 | done aberrant) | |
2a1408fd DN |
2322 | (save-match-data |
2323 | (save-excursion | |
2324 | (while (and (not done) | |
2325 | (re-search-forward allout-line-boundary-regexp nil 0)) | |
2326 | (allout-prefix-data) | |
2327 | (goto-char allout-recent-prefix-beginning) | |
2328 | (cond | |
8dd59f01 | 2329 | ;; sibling -- continue: |
2a1408fd | 2330 | ((eq allout-recent-depth depth)) |
8dd59f01 | 2331 | ;; first offspring is excessive -- aberrant: |
2a1408fd DN |
2332 | ((> allout-recent-depth (1+ depth)) |
2333 | (setq done t aberrant t)) | |
8dd59f01 | 2334 | ;; next non-sibling is lower-depth -- not aberrant: |
2a1408fd | 2335 | (t (setq done t)))))) |
d8350998 CY |
2336 | (if aberrant |
2337 | aberrant | |
2338 | (goto-char start-point) | |
2339 | ;; recalibrate allout-recent-* | |
2340 | (allout-depth) | |
2341 | nil))) | |
ede4ac6a KS |
2342 | ;;;_ > allout-on-current-heading-p () |
2343 | (defun allout-on-current-heading-p () | |
2344 | "Return non-nil if point is on current visible topics' header line. | |
2345 | ||
2346 | Actually, returns prefix beginning point." | |
2347 | (save-excursion | |
2348 | (allout-beginning-of-current-line) | |
2a1408fd DN |
2349 | (save-match-data |
2350 | (and (looking-at allout-regexp) | |
2351 | (allout-prefix-data) | |
2352 | (or (not (allout-do-doublecheck)) | |
2353 | (not (allout-aberrant-container-p))))))) | |
ede4ac6a KS |
2354 | ;;;_ > allout-on-heading-p () |
2355 | (defalias 'allout-on-heading-p 'allout-on-current-heading-p) | |
2356 | ;;;_ > allout-e-o-prefix-p () | |
2357 | (defun allout-e-o-prefix-p () | |
2358 | "True if point is located where current topic prefix ends, heading begins." | |
2a1408fd DN |
2359 | (and (save-match-data |
2360 | (save-excursion (let ((inhibit-field-text-motion t)) | |
2361 | (beginning-of-line)) | |
2362 | (looking-at allout-regexp)) | |
2363 | (= (point) (save-excursion (allout-end-of-prefix)(point)))))) | |
c567ac01 | 2364 | ;;;_ : Location attributes |
fd5359c6 | 2365 | ;;;_ > allout-depth () |
96b83743 EZ |
2366 | (defun allout-depth () |
2367 | "Return depth of topic most immediately containing point. | |
2368 | ||
42c3e51c KM |
2369 | Does not do doublecheck for aberrant topic header. |
2370 | ||
96b83743 EZ |
2371 | Return zero if point is not within any topic. |
2372 | ||
2373 | Like `allout-current-depth', but respects hidden as well as visible topics." | |
9179616f | 2374 | (save-excursion |
96b83743 EZ |
2375 | (let ((start-point (point))) |
2376 | (if (and (allout-goto-prefix) | |
2377 | (not (< start-point (point)))) | |
d8350998 | 2378 | allout-recent-depth |
96b83743 | 2379 | (progn |
d8350998 CY |
2380 | ;; Oops, no prefix, nullify it: |
2381 | (nullify-allout-prefix-data) | |
96b83743 EZ |
2382 | ;; ... and return 0: |
2383 | 0))))) | |
fd5359c6 | 2384 | ;;;_ > allout-current-depth () |
96b83743 EZ |
2385 | (defun allout-current-depth () |
2386 | "Return depth of visible topic most immediately containing point. | |
2387 | ||
2388 | Return zero if point is not within any topic." | |
2389 | (save-excursion | |
2390 | (if (allout-back-to-current-heading) | |
2391 | (max 1 | |
2392 | (- allout-recent-prefix-end | |
2393 | allout-recent-prefix-beginning | |
2394 | allout-header-subtraction)) | |
2395 | 0))) | |
fd5359c6 MR |
2396 | ;;;_ > allout-get-current-prefix () |
2397 | (defun allout-get-current-prefix () | |
c567ac01 | 2398 | "Topic prefix of the current topic." |
1977b8f6 | 2399 | (save-excursion |
fd5359c6 MR |
2400 | (if (allout-goto-prefix) |
2401 | (allout-recent-prefix)))) | |
2402 | ;;;_ > allout-get-bullet () | |
2403 | (defun allout-get-bullet () | |
c567ac01 | 2404 | "Return bullet of containing topic (visible or not)." |
1977b8f6 | 2405 | (save-excursion |
fd5359c6 MR |
2406 | (and (allout-goto-prefix) |
2407 | (allout-recent-bullet)))) | |
2408 | ;;;_ > allout-current-bullet () | |
2409 | (defun allout-current-bullet () | |
c567ac01 | 2410 | "Return bullet of current (visible) topic heading, or none if none found." |
96b83743 | 2411 | (condition-case nil |
1977b8f6 | 2412 | (save-excursion |
fd5359c6 | 2413 | (allout-back-to-current-heading) |
d8350998 CY |
2414 | (buffer-substring-no-properties (- allout-recent-prefix-end 1) |
2415 | allout-recent-prefix-end)) | |
1977b8f6 | 2416 | ;; Quick and dirty provision, ostensibly for missing bullet: |
d8350998 | 2417 | (args-out-of-range nil)) |
1977b8f6 | 2418 | ) |
fd5359c6 MR |
2419 | ;;;_ > allout-get-prefix-bullet (prefix) |
2420 | (defun allout-get-prefix-bullet (prefix) | |
c567ac01 | 2421 | "Return the bullet of the header prefix string PREFIX." |
1977b8f6 RS |
2422 | ;; Doesn't make sense if we're old-style prefixes, but this just |
2423 | ;; oughtn't be called then, so forget about it... | |
fd5359c6 | 2424 | (if (string-match allout-regexp prefix) |
d8350998 | 2425 | (substring prefix (1- (match-end 2)) (match-end 2)))) |
fd5359c6 MR |
2426 | ;;;_ > allout-sibling-index (&optional depth) |
2427 | (defun allout-sibling-index (&optional depth) | |
9179616f DL |
2428 | "Item number of this prospective topic among its siblings. |
2429 | ||
e126900f | 2430 | If optional arg DEPTH is greater than current depth, then we're |
9179616f DL |
2431 | opening a new level, and return 0. |
2432 | ||
2433 | If less than this depth, ascend to that depth and count..." | |
2434 | ||
2435 | (save-excursion | |
2436 | (cond ((and depth (<= depth 0) 0)) | |
65e7eb3d | 2437 | ((or (null depth) (= depth (allout-depth))) |
9179616f | 2438 | (let ((index 1)) |
d8350998 | 2439 | (while (allout-previous-sibling allout-recent-depth nil) |
9179616f DL |
2440 | (setq index (1+ index))) |
2441 | index)) | |
d8350998 | 2442 | ((< depth allout-recent-depth) |
fd5359c6 MR |
2443 | (allout-ascend-to-depth depth) |
2444 | (allout-sibling-index)) | |
9179616f | 2445 | (0)))) |
fd5359c6 MR |
2446 | ;;;_ > allout-topic-flat-index () |
2447 | (defun allout-topic-flat-index () | |
9179616f DL |
2448 | "Return a list indicating point's numeric section.subsect.subsubsect... |
2449 | Outermost is first." | |
fd5359c6 MR |
2450 | (let* ((depth (allout-depth)) |
2451 | (next-index (allout-sibling-index depth)) | |
9179616f DL |
2452 | (rev-sibls nil)) |
2453 | (while (> next-index 0) | |
2454 | (setq rev-sibls (cons next-index rev-sibls)) | |
2455 | (setq depth (1- depth)) | |
fd5359c6 | 2456 | (setq next-index (allout-sibling-index depth))) |
9179616f DL |
2457 | rev-sibls) |
2458 | ) | |
1977b8f6 | 2459 | |
96b83743 EZ |
2460 | ;;;_ - Navigation routines |
2461 | ;;;_ > allout-beginning-of-current-line () | |
2462 | (defun allout-beginning-of-current-line () | |
2463 | "Like beginning of line, but to visible text." | |
2464 | ||
5204800f NR |
2465 | ;; This combination of move-beginning-of-line and beginning-of-line is |
2466 | ;; deliberate, but the (beginning-of-line) may now be superfluous. | |
0458fa80 EZ |
2467 | (let ((inhibit-field-text-motion t)) |
2468 | (move-beginning-of-line 1) | |
96b83743 | 2469 | (beginning-of-line) |
0458fa80 EZ |
2470 | (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p))) |
2471 | (beginning-of-line) | |
2472 | (if (or (allout-hidden-p) (not (bolp))) | |
2473 | (forward-char -1))))) | |
96b83743 EZ |
2474 | ;;;_ > allout-end-of-current-line () |
2475 | (defun allout-end-of-current-line () | |
2476 | "Move to the end of line, past concealed text if any." | |
1c9b9df0 | 2477 | ;; This is for symmetry with `allout-beginning-of-current-line' -- |
96b83743 EZ |
2478 | ;; `move-end-of-line' doesn't suffer the same problem as |
2479 | ;; `move-beginning-of-line'. | |
0458fa80 | 2480 | (let ((inhibit-field-text-motion t)) |
96b83743 | 2481 | (end-of-line) |
0458fa80 EZ |
2482 | (while (allout-hidden-p) |
2483 | (end-of-line) | |
2484 | (if (allout-hidden-p) (forward-char 1))))) | |
48bd8440 EZ |
2485 | ;;;_ > allout-beginning-of-line () |
2486 | (defun allout-beginning-of-line () | |
2487 | "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set." | |
2488 | ||
2489 | (interactive) | |
2490 | ||
2491 | (if (or (not allout-beginning-of-line-cycles) | |
2492 | (not (equal last-command this-command))) | |
2a1408fd DN |
2493 | (progn |
2494 | (if (and (not (bolp)) | |
2495 | (allout-hidden-p (1- (point)))) | |
1c9b9df0 | 2496 | (goto-char (allout-previous-single-char-property-change |
2a1408fd DN |
2497 | (1- (point)) 'invisible))) |
2498 | (move-beginning-of-line 1)) | |
d8350998 CY |
2499 | (allout-depth) |
2500 | (let ((beginning-of-body | |
2501 | (save-excursion | |
ede4ac6a | 2502 | (while (and (allout-do-doublecheck) |
d8350998 CY |
2503 | (allout-aberrant-container-p) |
2504 | (allout-previous-visible-heading 1))) | |
2505 | (allout-beginning-of-current-entry) | |
2506 | (point)))) | |
48bd8440 | 2507 | (cond ((= (current-column) 0) |
d8350998 | 2508 | (goto-char beginning-of-body)) |
48bd8440 EZ |
2509 | ((< (point) beginning-of-body) |
2510 | (allout-beginning-of-current-line)) | |
2511 | ((= (point) beginning-of-body) | |
2512 | (goto-char (allout-current-bullet-pos))) | |
2513 | (t (allout-beginning-of-current-line) | |
2514 | (if (< (point) beginning-of-body) | |
2515 | ;; we were on the headline after its start: | |
d8350998 | 2516 | (goto-char beginning-of-body))))))) |
48bd8440 EZ |
2517 | ;;;_ > allout-end-of-line () |
2518 | (defun allout-end-of-line () | |
2519 | "End-of-line with `allout-end-of-line-cycles' behavior, if set." | |
2520 | ||
2521 | (interactive) | |
2522 | ||
2523 | (if (or (not allout-end-of-line-cycles) | |
2524 | (not (equal last-command this-command))) | |
2525 | (allout-end-of-current-line) | |
2526 | (let ((end-of-entry (save-excursion | |
2527 | (allout-end-of-entry) | |
2528 | (point)))) | |
2529 | (cond ((not (eolp)) | |
2530 | (allout-end-of-current-line)) | |
2531 | ((or (allout-hidden-p) (save-excursion | |
2532 | (forward-char -1) | |
2533 | (allout-hidden-p))) | |
2534 | (allout-back-to-current-heading) | |
2535 | (allout-show-current-entry) | |
d8350998 | 2536 | (allout-show-children) |
48bd8440 EZ |
2537 | (allout-end-of-entry)) |
2538 | ((>= (point) end-of-entry) | |
2539 | (allout-back-to-current-heading) | |
2540 | (allout-end-of-current-line)) | |
2a1408fd | 2541 | (t |
1c9b9df0 | 2542 | (if (not (allout-mark-active-p)) |
2a1408fd DN |
2543 | (push-mark)) |
2544 | (allout-end-of-entry)))))) | |
1c9b9df0 KM |
2545 | ;;;_ > allout-mark-active-p () |
2546 | (defun allout-mark-active-p () | |
2547 | "True if the mark is currently or always active." | |
2548 | ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler | |
0d26e0b6 | 2549 | ;; provisions, at least in GNU Emacs to prevent warnings about lack of, |
1c9b9df0 KM |
2550 | ;; eg, region-active-p. |
2551 | (cond ((boundp 'mark-active) | |
2552 | mark-active) | |
2553 | ((fboundp 'region-active-p) | |
2554 | (region-active-p)) | |
2555 | (t))) | |
fd5359c6 MR |
2556 | ;;;_ > allout-next-heading () |
2557 | (defsubst allout-next-heading () | |
c07583cd | 2558 | "Move to the heading for the topic (possibly invisible) after this one. |
c567ac01 | 2559 | |
d8350998 | 2560 | Returns the location of the heading, or nil if none found. |
c567ac01 | 2561 | |
75bcb912 | 2562 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
2a1408fd DN |
2563 | (save-match-data |
2564 | ||
2565 | (if (looking-at allout-regexp) | |
2566 | (forward-char 1)) | |
2567 | ||
2568 | (when (re-search-forward allout-line-boundary-regexp nil 0) | |
2569 | (allout-prefix-data) | |
42c3e51c KM |
2570 | (goto-char allout-recent-prefix-beginning) |
2571 | (while (not (bolp)) | |
2572 | (forward-char -1)) | |
2a1408fd DN |
2573 | (and (allout-do-doublecheck) |
2574 | ;; this will set allout-recent-* on the first non-aberrant topic, | |
2575 | ;; whether it's the current one or one that disqualifies it: | |
2576 | (allout-aberrant-container-p)) | |
42c3e51c | 2577 | ;; this may or may not be the same as above depending on doublecheck: |
2a1408fd | 2578 | (goto-char allout-recent-prefix-beginning)))) |
96b83743 | 2579 | ;;;_ > allout-this-or-next-heading |
fd5359c6 | 2580 | (defun allout-this-or-next-heading () |
8d118843 | 2581 | "Position cursor on current or next heading." |
fd5359c6 MR |
2582 | ;; A throwaway non-macro that is defined after allout-next-heading |
2583 | ;; and usable by allout-mode. | |
d8350998 | 2584 | (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading))) |
fd5359c6 | 2585 | ;;;_ > allout-previous-heading () |
8a559d4e | 2586 | (defun allout-previous-heading () |
c07583cd | 2587 | "Move to the prior (possibly invisible) heading line. |
c567ac01 | 2588 | |
d8350998 CY |
2589 | Return the location of the beginning of the heading, or nil if not found. |
2590 | ||
75bcb912 | 2591 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
d8350998 CY |
2592 | |
2593 | (if (bobp) | |
2594 | nil | |
d8350998 | 2595 | (let ((start-point (point))) |
ede4ac6a | 2596 | ;; allout-goto-prefix-doublechecked calls us, so we can't use it here. |
d8350998 | 2597 | (allout-goto-prefix) |
2a1408fd DN |
2598 | (save-match-data |
2599 | (when (or (re-search-backward allout-line-boundary-regexp nil 0) | |
2600 | (looking-at allout-bob-regexp)) | |
2601 | (goto-char (allout-prefix-data)) | |
2602 | (if (and (allout-do-doublecheck) | |
2603 | (allout-aberrant-container-p)) | |
2604 | (or (allout-previous-heading) | |
2605 | (and (goto-char start-point) | |
2606 | ;; recalibrate allout-recent-*: | |
2607 | (allout-depth) | |
2608 | nil)) | |
2609 | (point))))))) | |
96b83743 EZ |
2610 | ;;;_ > allout-get-invisibility-overlay () |
2611 | (defun allout-get-invisibility-overlay () | |
2612 | "Return the overlay at point that dictates allout invisibility." | |
2613 | (let ((overlays (overlays-at (point))) | |
2614 | got) | |
2615 | (while (and overlays (not got)) | |
2616 | (if (equal (overlay-get (car overlays) 'invisible) 'allout) | |
d8350998 CY |
2617 | (setq got (car overlays)) |
2618 | (pop overlays))) | |
96b83743 EZ |
2619 | got)) |
2620 | ;;;_ > allout-back-to-visible-text () | |
2621 | (defun allout-back-to-visible-text () | |
2622 | "Move to most recent prior character that is visible, and return point." | |
2623 | (if (allout-hidden-p) | |
2624 | (goto-char (overlay-start (allout-get-invisibility-overlay)))) | |
2625 | (point)) | |
c567ac01 RS |
2626 | |
2627 | ;;;_ - Subtree Charting | |
2628 | ;;;_ " These routines either produce or assess charts, which are | |
2629 | ;;; nested lists of the locations of topics within a subtree. | |
2630 | ;;; | |
d8350998 CY |
2631 | ;;; Charts enable efficient subtree navigation by providing a reusable basis |
2632 | ;;; for elaborate, compound assessment and adjustment of a subtree. | |
c567ac01 | 2633 | |
48bd8440 EZ |
2634 | ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth) |
2635 | (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth) | |
19b84ba3 RS |
2636 | "Produce a location \"chart\" of subtopics of the containing topic. |
2637 | ||
c07583cd | 2638 | Optional argument LEVELS specifies a depth limit (relative to start |
65e7eb3d | 2639 | depth) for the chart. Null LEVELS means no limit. |
48bd8440 EZ |
2640 | |
2641 | When optional argument VISIBLE is non-nil, the chart includes | |
2642 | only the visible subelements of the charted subjects. | |
2643 | ||
65e7eb3d | 2644 | The remaining optional args are for internal use by the function. |
d82979ea EZ |
2645 | |
2646 | Point is left at the end of the subtree. | |
19b84ba3 | 2647 | |
d82979ea | 2648 | Charts are used to capture outline structure, so that outline-altering |
20db1522 | 2649 | routines need to assess the structure only once, and then use the chart |
19b84ba3 RS |
2650 | for their elaborate manipulations. |
2651 | ||
d8350998 CY |
2652 | The chart entries for the topics are in reverse order, so the |
2653 | last topic is listed first. The entry for each topic consists of | |
2654 | an integer indicating the point at the beginning of the topic | |
20db1522 | 2655 | prefix. Charts for offspring consist of a list containing, |
d8350998 CY |
2656 | recursively, the charts for the respective subtopics. The chart |
2657 | for a topics' offspring precedes the entry for the topic itself. | |
19b84ba3 | 2658 | |
d82979ea EZ |
2659 | The other function parameters are for internal recursion, and should |
2660 | not be specified by external callers. ORIG-DEPTH is depth of topic at | |
2661 | starting point, and PREV-DEPTH is depth of prior topic." | |
19b84ba3 | 2662 | |
353e2ef2 | 2663 | (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. |
19b84ba3 RS |
2664 | chart curr-depth) |
2665 | ||
2666 | (if original ; Just starting? | |
2667 | ; Register initial settings and | |
2668 | ; position to first offspring: | |
fd5359c6 | 2669 | (progn (setq orig-depth (allout-depth)) |
19b84ba3 | 2670 | (or prev-depth (setq prev-depth (1+ orig-depth))) |
48bd8440 EZ |
2671 | (if visible |
2672 | (allout-next-visible-heading 1) | |
2673 | (allout-next-heading)))) | |
c567ac01 | 2674 | |
19b84ba3 RS |
2675 | ;; Loop over the current levels' siblings. Besides being more |
2676 | ;; efficient than tail-recursing over a level, it avoids exceeding | |
e126900f | 2677 | ;; the typically quite constrained Emacs max-lisp-eval-depth. |
9179616f | 2678 | ;; |
19b84ba3 RS |
2679 | ;; Probably would speed things up to implement loop-based stack |
2680 | ;; operation rather than recursing for lower levels. Bah. | |
9179616f | 2681 | |
c567ac01 | 2682 | (while (and (not (eobp)) |
19b84ba3 | 2683 | ; Still within original topic? |
d8350998 | 2684 | (< orig-depth (setq curr-depth allout-recent-depth)) |
19b84ba3 RS |
2685 | (cond ((= prev-depth curr-depth) |
2686 | ;; Register this one and move on: | |
d8350998 | 2687 | (setq chart (cons allout-recent-prefix-beginning chart)) |
19b84ba3 | 2688 | (if (and levels (<= levels 1)) |
60c7bbd2 | 2689 | ;; At depth limit -- skip sublevels: |
fd5359c6 | 2690 | (or (allout-next-sibling curr-depth) |
60c7bbd2 | 2691 | ;; or no more siblings -- proceed to |
19b84ba3 | 2692 | ;; next heading at lesser depth: |
e6a9aec7 | 2693 | (while (and (<= curr-depth |
d8350998 | 2694 | allout-recent-depth) |
48bd8440 EZ |
2695 | (if visible |
2696 | (allout-next-visible-heading 1) | |
2697 | (allout-next-heading))))) | |
2698 | (if visible | |
2699 | (allout-next-visible-heading 1) | |
2700 | (allout-next-heading)))) | |
19b84ba3 RS |
2701 | |
2702 | ((and (< prev-depth curr-depth) | |
2703 | (or (not levels) | |
2704 | (> levels 0))) | |
2705 | ;; Recurse on deeper level of curr topic: | |
2706 | (setq chart | |
fd5359c6 | 2707 | (cons (allout-chart-subtree (and levels |
19b84ba3 | 2708 | (1- levels)) |
48bd8440 EZ |
2709 | visible |
2710 | orig-depth | |
2711 | curr-depth) | |
19b84ba3 RS |
2712 | chart)) |
2713 | ;; ... then continue with this one. | |
2714 | ) | |
2715 | ||
2716 | ;; ... else nil if we've ascended back to prev-depth. | |
2717 | ||
2718 | ))) | |
2719 | ||
2720 | (if original ; We're at the last sibling on | |
2721 | ; the original level. Position | |
2722 | ; to the end of it: | |
c567ac01 | 2723 | (progn (and (not (eobp)) (forward-char -1)) |
96b83743 EZ |
2724 | (and (= (preceding-char) ?\n) |
2725 | (= (aref (buffer-substring (max 1 (- (point) 3)) | |
2726 | (point)) | |
2727 | 1) | |
2728 | ?\n) | |
19b84ba3 | 2729 | (forward-char -1)) |
fd5359c6 | 2730 | (setq allout-recent-end-of-subtree (point)))) |
353e2ef2 | 2731 | |
c567ac01 RS |
2732 | chart ; (nreverse chart) not necessary, |
2733 | ; and maybe not preferable. | |
2734 | )) | |
fd5359c6 MR |
2735 | ;;;_ > allout-chart-siblings (&optional start end) |
2736 | (defun allout-chart-siblings (&optional start end) | |
c567ac01 | 2737 | "Produce a list of locations of this and succeeding sibling topics. |
fd5359c6 | 2738 | Effectively a top-level chart of siblings. See `allout-chart-subtree' |
c567ac01 RS |
2739 | for an explanation of charts." |
2740 | (save-excursion | |
d8350998 CY |
2741 | (when (allout-goto-prefix-doublechecked) |
2742 | (let ((chart (list (point)))) | |
2743 | (while (allout-next-sibling) | |
2744 | (setq chart (cons (point) chart))) | |
2745 | (if chart (setq chart (nreverse chart))))))) | |
fd5359c6 MR |
2746 | ;;;_ > allout-chart-to-reveal (chart depth) |
2747 | (defun allout-chart-to-reveal (chart depth) | |
c567ac01 | 2748 | |
19b84ba3 | 2749 | "Return a flat list of hidden points in subtree CHART, up to DEPTH. |
c567ac01 | 2750 | |
65e7eb3d EZ |
2751 | If DEPTH is nil, include hidden points at any depth. |
2752 | ||
19b84ba3 | 2753 | Note that point can be left at any of the points on chart, or at the |
c567ac01 RS |
2754 | start point." |
2755 | ||
2756 | (let (result here) | |
65e7eb3d | 2757 | (while (and (or (null depth) (> depth 0)) |
c567ac01 RS |
2758 | chart) |
2759 | (setq here (car chart)) | |
2760 | (if (listp here) | |
65e7eb3d EZ |
2761 | (let ((further (allout-chart-to-reveal here (if (null depth) |
2762 | depth | |
2763 | (1- depth))))) | |
60c7bbd2 | 2764 | ;; We're on the start of a subtree -- recurse with it, if there's |
c567ac01 RS |
2765 | ;; more depth to go: |
2766 | (if further (setq result (append further result))) | |
2767 | (setq chart (cdr chart))) | |
2768 | (goto-char here) | |
96b83743 | 2769 | (if (allout-hidden-p) |
c567ac01 RS |
2770 | (setq result (cons here result))) |
2771 | (setq chart (cdr chart)))) | |
2772 | result)) | |
fd5359c6 | 2773 | ;;;_ X allout-chart-spec (chart spec &optional exposing) |
e126900f | 2774 | ;; (defun allout-chart-spec (chart spec &optional exposing) |
c07583cd | 2775 | ;; "Not yet (if ever) implemented. |
e126900f JB |
2776 | |
2777 | ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC. | |
2778 | ||
2779 | ;; Exposure spec indicates the locations to be exposed and the prescribed | |
2780 | ;; exposure status. Optional arg EXPOSING is an integer, with 0 | |
2781 | ;; indicating pending concealment, anything higher indicating depth to | |
2782 | ;; which subtopic headers should be exposed, and negative numbers | |
2783 | ;; indicating (negative of) the depth to which subtopic headers and | |
2784 | ;; bodies should be exposed. | |
2785 | ||
2786 | ;; The produced list can have two types of entries. Bare numbers | |
2787 | ;; indicate points in the buffer where topic headers that should be | |
2788 | ;; exposed reside. | |
2789 | ||
2790 | ;; - bare negative numbers indicates that the topic starting at the | |
2791 | ;; point which is the negative of the number should be opened, | |
2792 | ;; including their entries. | |
2793 | ;; - bare positive values indicate that this topic header should be | |
2794 | ;; opened. | |
2795 | ;; - Lists signify the beginning and end points of regions that should | |
c07583cd | 2796 | ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and |
e126900f JB |
2797 | ;; exposure:" |
2798 | ;; (while spec | |
2799 | ;; (cond ((listp spec) | |
2800 | ;; ) | |
2801 | ;; ) | |
2802 | ;; (setq spec (cdr spec))) | |
2803 | ;; ) | |
c567ac01 RS |
2804 | |
2805 | ;;;_ - Within Topic | |
fd5359c6 MR |
2806 | ;;;_ > allout-goto-prefix () |
2807 | (defun allout-goto-prefix () | |
9179616f | 2808 | "Put point at beginning of immediately containing outline topic. |
19b84ba3 | 2809 | |
9179616f | 2810 | Goes to most immediate subsequent topic if none immediately containing. |
19b84ba3 RS |
2811 | |
2812 | Not sensitive to topic visibility. | |
c567ac01 | 2813 | |
d27081f5 | 2814 | Returns the point at the beginning of the prefix, or nil if none." |
c567ac01 | 2815 | |
2a1408fd DN |
2816 | (save-match-data |
2817 | (let (done) | |
2818 | (while (and (not done) | |
2819 | (search-backward "\n" nil 1)) | |
2820 | (forward-char 1) | |
2821 | (if (looking-at allout-regexp) | |
2822 | (setq done (allout-prefix-data)) | |
2823 | (forward-char -1))) | |
2824 | (if (bobp) | |
2825 | (cond ((looking-at allout-regexp) | |
2826 | (allout-prefix-data)) | |
2827 | ((allout-next-heading)) | |
2828 | (done)) | |
2829 | done)))) | |
d8350998 CY |
2830 | ;;;_ > allout-goto-prefix-doublechecked () |
2831 | (defun allout-goto-prefix-doublechecked () | |
2832 | "Put point at beginning of immediately containing outline topic. | |
2833 | ||
c07583cd | 2834 | Like `allout-goto-prefix', but shallow topics (according to |
65e7eb3d EZ |
2835 | `allout-doublecheck-at-and-shallower') are checked and |
2836 | disqualified for child containment discontinuity, according to | |
2837 | `allout-aberrant-container-p'." | |
ede4ac6a KS |
2838 | (if (allout-goto-prefix) |
2839 | (if (and (allout-do-doublecheck) | |
2840 | (allout-aberrant-container-p)) | |
2841 | (allout-previous-heading) | |
2842 | (point)))) | |
d8350998 | 2843 | |
fd5359c6 MR |
2844 | ;;;_ > allout-end-of-prefix () |
2845 | (defun allout-end-of-prefix (&optional ignore-decorations) | |
19b84ba3 RS |
2846 | "Position cursor at beginning of header text. |
2847 | ||
2848 | If optional IGNORE-DECORATIONS is non-nil, put just after bullet, | |
2849 | otherwise skip white space between bullet and ensuing text." | |
c567ac01 | 2850 | |
d8350998 | 2851 | (if (not (allout-goto-prefix-doublechecked)) |
1977b8f6 | 2852 | nil |
d8350998 | 2853 | (goto-char allout-recent-prefix-end) |
2a1408fd DN |
2854 | (save-match-data |
2855 | (if ignore-decorations | |
2856 | t | |
2857 | (while (looking-at "[0-9]") (forward-char 1)) | |
2858 | (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))) | |
1977b8f6 | 2859 | ;; Reestablish where we are: |
fd5359c6 MR |
2860 | (allout-current-depth))) |
2861 | ;;;_ > allout-current-bullet-pos () | |
2862 | (defun allout-current-bullet-pos () | |
c07583cd | 2863 | "Return position of current (visible) topic's bullet." |
c567ac01 | 2864 | |
8a559d4e | 2865 | (if (not (allout-current-depth)) |
c567ac01 | 2866 | nil |
8a559d4e | 2867 | (1- allout-recent-prefix-end))) |
1c9b9df0 KM |
2868 | ;;;_ > allout-back-to-current-heading (&optional interactive) |
2869 | (defun allout-back-to-current-heading (&optional interactive) | |
80f66ef4 | 2870 | "Move to heading line of current topic, or beginning if not in a topic. |
96b83743 | 2871 | |
80f66ef4 CY |
2872 | If interactive, we position at the end of the prefix. |
2873 | ||
2874 | Return value of resulting point, unless we started outside | |
2875 | of (before any) topics, in which case we return nil." | |
96b83743 | 2876 | |
1c9b9df0 KM |
2877 | (interactive "p") |
2878 | ||
96b83743 | 2879 | (allout-beginning-of-current-line) |
80f66ef4 | 2880 | (let ((bol-point (point))) |
1e004a83 KM |
2881 | (when (allout-goto-prefix-doublechecked) |
2882 | (if (<= (point) bol-point) | |
2883 | (progn | |
2884 | (setq bol-point (point)) | |
2885 | (allout-beginning-of-current-line) | |
2886 | (if (not (= bol-point (point))) | |
2887 | (if (looking-at allout-regexp) | |
2888 | (allout-prefix-data))) | |
1c9b9df0 | 2889 | (if interactive |
ede4ac6a | 2890 | (allout-end-of-prefix) |
1e004a83 KM |
2891 | (point))) |
2892 | (goto-char (point-min)) | |
2893 | nil)))) | |
fd5359c6 MR |
2894 | ;;;_ > allout-back-to-heading () |
2895 | (defalias 'allout-back-to-heading 'allout-back-to-current-heading) | |
96b83743 EZ |
2896 | ;;;_ > allout-pre-next-prefix () |
2897 | (defun allout-pre-next-prefix () | |
1977b8f6 RS |
2898 | "Skip forward to just before the next heading line. |
2899 | ||
c567ac01 | 2900 | Returns that character position." |
1977b8f6 | 2901 | |
8a559d4e EZ |
2902 | (if (allout-next-heading) |
2903 | (goto-char (1- allout-recent-prefix-beginning)))) | |
96b83743 EZ |
2904 | ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank) |
2905 | (defun allout-end-of-subtree (&optional current include-trailing-blank) | |
d82979ea EZ |
2906 | "Put point at the end of the last leaf in the containing topic. |
2907 | ||
96b83743 EZ |
2908 | Optional CURRENT means put point at the end of the containing |
2909 | visible topic. | |
2910 | ||
2911 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if | |
2912 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2913 | excluded as delimiting whitespace between topics. | |
d82979ea EZ |
2914 | |
2915 | Returns the value of point." | |
2916 | (interactive "P") | |
2917 | (if current | |
2918 | (allout-back-to-current-heading) | |
d8350998 CY |
2919 | (allout-goto-prefix-doublechecked)) |
2920 | (let ((level allout-recent-depth)) | |
fd5359c6 | 2921 | (allout-next-heading) |
1977b8f6 | 2922 | (while (and (not (eobp)) |
d8350998 | 2923 | (> allout-recent-depth level)) |
fd5359c6 | 2924 | (allout-next-heading)) |
48bd8440 EZ |
2925 | (if (eobp) |
2926 | (allout-end-of-entry) | |
2927 | (forward-char -1)) | |
96b83743 | 2928 | (if (and (not include-trailing-blank) (= ?\n (preceding-char))) |
c567ac01 | 2929 | (forward-char -1)) |
fd5359c6 | 2930 | (setq allout-recent-end-of-subtree (point)))) |
96b83743 EZ |
2931 | ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank) |
2932 | (defun allout-end-of-current-subtree (&optional include-trailing-blank) | |
2933 | ||
d82979ea EZ |
2934 | "Put point at end of last leaf in currently visible containing topic. |
2935 | ||
96b83743 EZ |
2936 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if |
2937 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2938 | excluded as delimiting whitespace between topics. | |
2939 | ||
d82979ea EZ |
2940 | Returns the value of point." |
2941 | (interactive) | |
96b83743 | 2942 | (allout-end-of-subtree t include-trailing-blank)) |
1c9b9df0 KM |
2943 | ;;;_ > allout-beginning-of-current-entry (&optional interactive) |
2944 | (defun allout-beginning-of-current-entry (&optional interactive) | |
d82979ea | 2945 | "When not already there, position point at beginning of current topic header. |
c567ac01 RS |
2946 | |
2947 | If already there, move cursor to bullet for hot-spot operation. | |
46771bb3 | 2948 | \(See `allout-mode' doc string for details of hot-spot operation.)" |
1c9b9df0 | 2949 | (interactive "p") |
c567ac01 | 2950 | (let ((start-point (point))) |
46771bb3 | 2951 | (move-beginning-of-line 1) |
d8350998 CY |
2952 | (if (< 0 (allout-current-depth)) |
2953 | (goto-char allout-recent-prefix-end) | |
2954 | (goto-char (point-min))) | |
fd5359c6 | 2955 | (allout-end-of-prefix) |
1c9b9df0 | 2956 | (if (and interactive |
c567ac01 | 2957 | (= (point) start-point)) |
fd5359c6 | 2958 | (goto-char (allout-current-bullet-pos))))) |
96b83743 EZ |
2959 | ;;;_ > allout-end-of-entry (&optional inclusive) |
2960 | (defun allout-end-of-entry (&optional inclusive) | |
2961 | "Position the point at the end of the current topics' entry. | |
2962 | ||
2963 | Optional INCLUSIVE means also include trailing empty line, if any. When | |
2964 | unset, whitespace between items separates them even when the items are | |
2965 | collapsed." | |
1977b8f6 | 2966 | (interactive) |
96b83743 EZ |
2967 | (allout-pre-next-prefix) |
2968 | (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char))) | |
2969 | (forward-char -1)) | |
2970 | (point)) | |
fd5359c6 MR |
2971 | ;;;_ > allout-end-of-current-heading () |
2972 | (defun allout-end-of-current-heading () | |
9179616f | 2973 | (interactive) |
fd5359c6 | 2974 | (allout-beginning-of-current-entry) |
96b83743 | 2975 | (search-forward "\n" nil t) |
d82979ea | 2976 | (forward-char -1)) |
fd5359c6 | 2977 | (defalias 'allout-end-of-heading 'allout-end-of-current-heading) |
d82979ea EZ |
2978 | ;;;_ > allout-get-body-text () |
2979 | (defun allout-get-body-text () | |
2980 | "Return the unmangled body text of the topic immediately containing point." | |
2981 | (save-excursion | |
2982 | (allout-end-of-prefix) | |
96b83743 | 2983 | (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
2984 | nil |
2985 | (backward-char 1) | |
2986 | (let ((pre-body (point))) | |
2987 | (if (not pre-body) | |
2988 | nil | |
96b83743 | 2989 | (allout-end-of-entry t) |
d82979ea EZ |
2990 | (if (not (= pre-body (point))) |
2991 | (buffer-substring-no-properties (1+ pre-body) (point)))) | |
2992 | ) | |
2993 | ) | |
2994 | ) | |
2995 | ) | |
1977b8f6 | 2996 | |
c567ac01 | 2997 | ;;;_ - Depth-wise |
fd5359c6 MR |
2998 | ;;;_ > allout-ascend-to-depth (depth) |
2999 | (defun allout-ascend-to-depth (depth) | |
c567ac01 | 3000 | "Ascend to depth DEPTH, returning depth if successful, nil if not." |
fd5359c6 | 3001 | (if (and (> depth 0)(<= depth (allout-depth))) |
d8350998 CY |
3002 | (let (last-ascended) |
3003 | (while (and (< depth allout-recent-depth) | |
3004 | (setq last-ascended (allout-ascend)))) | |
3005 | (goto-char allout-recent-prefix-beginning) | |
1c9b9df0 | 3006 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
d8350998 | 3007 | (and last-ascended allout-recent-depth)))) |
1c9b9df0 | 3008 | ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful) |
c07583cd KS |
3009 | (defun allout-ascend (&optional dont-move-if-unsuccessful) |
3010 | "Ascend one level, returning resulting depth if successful, nil if not. | |
3011 | ||
3012 | Point is left at the beginning of the level whether or not | |
3013 | successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in | |
3014 | which case point is returned to its original starting location." | |
3015 | (if dont-move-if-unsuccessful | |
3016 | (setq dont-move-if-unsuccessful (point))) | |
d82979ea EZ |
3017 | (prog1 |
3018 | (if (allout-beginning-of-level) | |
498a6493 CY |
3019 | (let ((bolevel (point)) |
3020 | (bolevel-depth allout-recent-depth)) | |
3021 | (allout-previous-heading) | |
c07583cd KS |
3022 | (cond ((< allout-recent-depth bolevel-depth) |
3023 | allout-recent-depth) | |
3024 | ((= allout-recent-depth bolevel-depth) | |
3025 | (if dont-move-if-unsuccessful | |
3026 | (goto-char dont-move-if-unsuccessful)) | |
3027 | (allout-depth) | |
3028 | nil) | |
3029 | (t | |
3030 | ;; some topic after very first is lower depth than first: | |
3031 | (goto-char bolevel) | |
3032 | (allout-depth) | |
3033 | nil)))) | |
1c9b9df0 | 3034 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 MR |
3035 | ;;;_ > allout-descend-to-depth (depth) |
3036 | (defun allout-descend-to-depth (depth) | |
19b84ba3 RS |
3037 | "Descend to depth DEPTH within current topic. |
3038 | ||
3039 | Returning depth if successful, nil if not." | |
1977b8f6 | 3040 | (let ((start-point (point)) |
fd5359c6 | 3041 | (start-depth (allout-depth))) |
1977b8f6 | 3042 | (while |
fd5359c6 | 3043 | (and (> (allout-depth) 0) |
d8350998 | 3044 | (not (= depth allout-recent-depth)) ; ... not there yet |
fd5359c6 | 3045 | (allout-next-heading) ; ... go further |
d8350998 | 3046 | (< start-depth allout-recent-depth))) ; ... still in topic |
fd5359c6 | 3047 | (if (and (> (allout-depth) 0) |
d8350998 | 3048 | (= allout-recent-depth depth)) |
1977b8f6 RS |
3049 | depth |
3050 | (goto-char start-point) | |
3051 | nil)) | |
3052 | ) | |
d8350998 CY |
3053 | ;;;_ > allout-up-current-level (arg) |
3054 | (defun allout-up-current-level (arg) | |
3055 | "Move out ARG levels from current visible topic." | |
d82979ea | 3056 | (interactive "p") |
8a559d4e EZ |
3057 | (let ((start-point (point))) |
3058 | (allout-back-to-current-heading) | |
3059 | (if (not (allout-ascend)) | |
3060 | (progn (goto-char start-point) | |
3061 | (error "Can't ascend past outermost level")) | |
1c9b9df0 | 3062 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
8a559d4e | 3063 | allout-recent-prefix-beginning))) |
1977b8f6 | 3064 | |
c567ac01 | 3065 | ;;;_ - Linear |
fd5359c6 MR |
3066 | ;;;_ > allout-next-sibling (&optional depth backward) |
3067 | (defun allout-next-sibling (&optional depth backward) | |
2265e017 | 3068 | "Like `allout-forward-current-level', but respects invisible topics. |
1977b8f6 | 3069 | |
c567ac01 | 3070 | Traverse at optional DEPTH, or current depth if none specified. |
1977b8f6 | 3071 | |
c567ac01 | 3072 | Go backward if optional arg BACKWARD is non-nil. |
1977b8f6 | 3073 | |
d8350998 | 3074 | Return the start point of the new topic if successful, nil otherwise." |
1977b8f6 | 3075 | |
d8350998 | 3076 | (if (if backward (bobp) (eobp)) |
1977b8f6 | 3077 | nil |
d8350998 | 3078 | (let ((target-depth (or depth (allout-depth))) |
1977b8f6 | 3079 | (start-point (point)) |
ede4ac6a | 3080 | (start-prefix-beginning allout-recent-prefix-beginning) |
d8350998 CY |
3081 | (count 0) |
3082 | leaping | |
c567ac01 | 3083 | last-depth) |
d8350998 CY |
3084 | (while (and |
3085 | ;; done too few single steps to resort to the leap routine: | |
3086 | (not leaping) | |
3087 | ;; not at limit: | |
3088 | (not (if backward (bobp) (eobp))) | |
3089 | ;; still traversable: | |
3090 | (if backward (allout-previous-heading) (allout-next-heading)) | |
3091 | ;; we're below the target depth | |
3092 | (> (setq last-depth allout-recent-depth) target-depth)) | |
3093 | (setq count (1+ count)) | |
3094 | (if (> count 7) ; lists are commonly 7 +- 2, right?-) | |
3095 | (setq leaping t))) | |
3096 | (cond (leaping | |
3097 | (or (allout-next-sibling-leap target-depth backward) | |
3098 | (progn | |
3099 | (goto-char start-point) | |
3100 | (if depth (allout-depth) target-depth) | |
3101 | nil))) | |
3102 | ((and (not (eobp)) | |
3103 | (and (> (or last-depth (allout-depth)) 0) | |
ede4ac6a KS |
3104 | (= allout-recent-depth target-depth)) |
3105 | (not (= start-prefix-beginning | |
3106 | allout-recent-prefix-beginning))) | |
d8350998 CY |
3107 | allout-recent-prefix-beginning) |
3108 | (t | |
3109 | (goto-char start-point) | |
3110 | (if depth (allout-depth) target-depth) | |
3111 | nil))))) | |
3112 | ;;;_ > allout-next-sibling-leap (&optional depth backward) | |
3113 | (defun allout-next-sibling-leap (&optional depth backward) | |
3114 | "Like `allout-next-sibling', but by direct search for topic at depth. | |
3115 | ||
3116 | Traverse at optional DEPTH, or current depth if none specified. | |
3117 | ||
3118 | Go backward if optional arg BACKWARD is non-nil. | |
3119 | ||
3120 | Return the start point of the new topic if successful, nil otherwise. | |
3121 | ||
3122 | Costs more than regular `allout-next-sibling' for short traversals: | |
3123 | ||
ee7683eb | 3124 | - we have to check the prior (next, if traveling backwards) |
d8350998 CY |
3125 | item to confirm connectivity with the prior topic, and |
3126 | - if confirmed, we have to reestablish the allout-recent-* settings with | |
3127 | some extra navigation | |
3128 | - if confirmation fails, we have to do more work to recover | |
3129 | ||
3130 | It is an increasingly big win when there are many intervening | |
3131 | offspring before the next sibling, however, so | |
3132 | `allout-next-sibling' resorts to this if it finds itself in that | |
3133 | situation." | |
3134 | ||
3135 | (if (if backward (bobp) (eobp)) | |
3136 | nil | |
3137 | (let* ((start-point (point)) | |
3138 | (target-depth (or depth (allout-depth))) | |
3139 | (search-whitespace-regexp nil) | |
3140 | (depth-biased (- target-depth 2)) | |
3141 | (expression (if (<= target-depth 1) | |
3142 | allout-depth-one-regexp | |
3143 | (format allout-depth-specific-regexp | |
3144 | depth-biased depth-biased))) | |
3145 | found | |
3146 | done) | |
3147 | (while (not done) | |
2a1408fd DN |
3148 | (setq found (save-match-data |
3149 | (if backward | |
3150 | (re-search-backward expression nil 'to-limit) | |
3151 | (forward-char 1) | |
3152 | (re-search-forward expression nil 'to-limit)))) | |
d8350998 CY |
3153 | (if (and found (allout-aberrant-container-p)) |
3154 | (setq found nil)) | |
3155 | (setq done (or found (if backward (bobp) (eobp))))) | |
3156 | (if (not found) | |
3157 | (progn (goto-char start-point) | |
3158 | nil) | |
3159 | ;; rationale: if any intervening items were at a lower depth, we | |
60c7bbd2 | 3160 | ;; would now be on the first offspring at the target depth -- ie, |
97610156 | 3161 | ;; the preceding item (per the search direction) must be at a |
d8350998 CY |
3162 | ;; lesser depth. that's all we need to check. |
3163 | (if backward (allout-next-heading) (allout-previous-heading)) | |
3164 | (if (< allout-recent-depth target-depth) | |
3165 | ;; return to start and reestablish allout-recent-*: | |
3166 | (progn | |
3167 | (goto-char start-point) | |
3168 | (allout-depth) | |
3169 | nil) | |
3170 | (goto-char found) | |
3171 | ;; locate cursor and set allout-recent-*: | |
3172 | (allout-goto-prefix)))))) | |
fd5359c6 MR |
3173 | ;;;_ > allout-previous-sibling (&optional depth backward) |
3174 | (defun allout-previous-sibling (&optional depth backward) | |
d82979ea | 3175 | "Like `allout-forward-current-level' backwards, respecting invisible topics. |
1977b8f6 | 3176 | |
c567ac01 | 3177 | Optional DEPTH specifies depth to traverse, default current depth. |
1977b8f6 | 3178 | |
c567ac01 | 3179 | Optional BACKWARD reverses direction. |
1977b8f6 | 3180 | |
c567ac01 | 3181 | Return depth if successful, nil otherwise." |
fd5359c6 | 3182 | (allout-next-sibling depth (not backward)) |
1977b8f6 | 3183 | ) |
fd5359c6 MR |
3184 | ;;;_ > allout-snug-back () |
3185 | (defun allout-snug-back () | |
539d7736 | 3186 | "Position cursor at end of previous topic. |
19b84ba3 RS |
3187 | |
3188 | Presumes point is at the start of a topic prefix." | |
c567ac01 RS |
3189 | (if (or (bobp) (eobp)) |
3190 | nil | |
3191 | (forward-char -1)) | |
96b83743 | 3192 | (if (or (bobp) (not (= ?\n (preceding-char)))) |
c567ac01 | 3193 | nil |
96b83743 | 3194 | (forward-char -1)) |
c567ac01 | 3195 | (point)) |
fd5359c6 MR |
3196 | ;;;_ > allout-beginning-of-level () |
3197 | (defun allout-beginning-of-level () | |
c567ac01 | 3198 | "Go back to the first sibling at this level, visible or not." |
fd5359c6 MR |
3199 | (allout-end-of-level 'backward)) |
3200 | ;;;_ > allout-end-of-level (&optional backward) | |
3201 | (defun allout-end-of-level (&optional backward) | |
c567ac01 | 3202 | "Go to the last sibling at this level, visible or not." |
1977b8f6 | 3203 | |
fd5359c6 MR |
3204 | (let ((depth (allout-depth))) |
3205 | (while (allout-previous-sibling depth nil)) | |
d8350998 | 3206 | (prog1 allout-recent-depth |
1c9b9df0 | 3207 | (if (allout-called-interactively-p) (allout-end-of-prefix))))) |
fd5359c6 MR |
3208 | ;;;_ > allout-next-visible-heading (arg) |
3209 | (defun allout-next-visible-heading (arg) | |
20db1522 | 3210 | "Move to the next ARGth visible heading line, backward if ARG is negative. |
c567ac01 | 3211 | |
96b83743 | 3212 | Move to buffer limit in indicated direction if headings are exhausted." |
1977b8f6 | 3213 | |
1977b8f6 | 3214 | (interactive "p") |
0458fa80 EZ |
3215 | (let* ((inhibit-field-text-motion t) |
3216 | (backward (if (< arg 0) (setq arg (* -1 arg)))) | |
c567ac01 | 3217 | (step (if backward -1 1)) |
82b392a4 | 3218 | (progress (allout-current-bullet-pos)) |
c567ac01 RS |
3219 | prev got) |
3220 | ||
d8350998 CY |
3221 | (while (> arg 0) |
3222 | (while (and | |
3223 | ;; Boundary condition: | |
3224 | (not (if backward (bobp)(eobp))) | |
3225 | ;; Move, skipping over all concealed lines in one fell swoop: | |
3226 | (prog1 (condition-case nil (or (line-move step) t) | |
3227 | (error nil)) | |
82b392a4 KM |
3228 | (allout-beginning-of-current-line) |
3229 | ;; line-move can wind up on the same line if long. | |
3230 | ;; when moving forward, that would yield no-progress | |
3231 | (when (and (not backward) | |
3232 | (<= (point) progress)) | |
3233 | ;; ensure progress by doing line-move from end-of-line: | |
3234 | (end-of-line) | |
3235 | (condition-case nil (or (line-move step) t) | |
3236 | (error nil)) | |
3237 | (allout-beginning-of-current-line) | |
3238 | (setq progress (point)))) | |
d8350998 | 3239 | ;; Deal with apparent header line: |
2a1408fd DN |
3240 | (save-match-data |
3241 | (if (not (looking-at allout-regexp)) | |
3242 | ;; not a header line, keep looking: | |
d8350998 | 3243 | t |
2a1408fd DN |
3244 | (allout-prefix-data) |
3245 | (if (and (allout-do-doublecheck) | |
3246 | (allout-aberrant-container-p)) | |
3247 | ;; skip this aberrant prospective header line: | |
3248 | t | |
8dd59f01 | 3249 | ;; this prospective headerline qualifies -- register: |
2a1408fd DN |
3250 | (setq got allout-recent-prefix-beginning) |
3251 | ;; and break the loop: | |
3252 | nil))))) | |
c567ac01 RS |
3253 | ;; Register this got, it may be the last: |
3254 | (if got (setq prev got)) | |
3255 | (setq arg (1- arg))) | |
3256 | (cond (got ; Last move was to a prefix: | |
d8350998 | 3257 | (allout-end-of-prefix)) |
c567ac01 | 3258 | (prev ; Last move wasn't, but prev was: |
d8350998 CY |
3259 | (goto-char prev) |
3260 | (allout-end-of-prefix)) | |
c567ac01 | 3261 | ((not backward) (end-of-line) nil)))) |
fd5359c6 MR |
3262 | ;;;_ > allout-previous-visible-heading (arg) |
3263 | (defun allout-previous-visible-heading (arg) | |
c567ac01 | 3264 | "Move to the previous heading line. |
1977b8f6 | 3265 | |
c567ac01 | 3266 | With argument, repeats or can move forward if negative. |
2265e017 | 3267 | A heading line is one that starts with a `*' (or that `allout-regexp' |
c567ac01 | 3268 | matches)." |
1977b8f6 | 3269 | (interactive "p") |
d8350998 | 3270 | (prog1 (allout-next-visible-heading (- arg)) |
1c9b9df0 | 3271 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 | 3272 | ;;;_ > allout-forward-current-level (arg) |
d82979ea | 3273 | (defun allout-forward-current-level (arg) |
19b84ba3 | 3274 | "Position point at the next heading of the same level. |
1977b8f6 | 3275 | |
19b84ba3 | 3276 | Takes optional repeat-count, goes backward if count is negative. |
1977b8f6 | 3277 | |
19b84ba3 | 3278 | Returns resulting position, else nil if none found." |
d82979ea | 3279 | (interactive "p") |
fd5359c6 | 3280 | (let ((start-depth (allout-current-depth)) |
19b84ba3 | 3281 | (start-arg arg) |
d8350998 | 3282 | (backward (> 0 arg))) |
19b84ba3 RS |
3283 | (if (= 0 start-depth) |
3284 | (error "No siblings, not in a topic...")) | |
3285 | (if backward (setq arg (* -1 arg))) | |
d8350998 CY |
3286 | (allout-back-to-current-heading) |
3287 | (while (and (not (zerop arg)) | |
3288 | (if backward | |
3289 | (allout-previous-sibling) | |
3290 | (allout-next-sibling))) | |
3291 | (setq arg (1- arg))) | |
1c9b9df0 | 3292 | (if (not (allout-called-interactively-p)) |
d8350998 CY |
3293 | nil |
3294 | (allout-end-of-prefix) | |
3295 | (if (not (zerop arg)) | |
3296 | (error "Hit %s level %d topic, traversed %d of %d requested" | |
3297 | (if backward "first" "last") | |
3298 | allout-recent-depth | |
3299 | (- (abs start-arg) arg) | |
3300 | (abs start-arg)))))) | |
fd5359c6 | 3301 | ;;;_ > allout-backward-current-level (arg) |
d82979ea | 3302 | (defun allout-backward-current-level (arg) |
fd5359c6 | 3303 | "Inverse of `allout-forward-current-level'." |
d82979ea | 3304 | (interactive "p") |
1c9b9df0 | 3305 | (if (allout-called-interactively-p) |
19b84ba3 | 3306 | (let ((current-prefix-arg (* -1 arg))) |
fd5359c6 MR |
3307 | (call-interactively 'allout-forward-current-level)) |
3308 | (allout-forward-current-level (* -1 arg)))) | |
c567ac01 | 3309 | |
19b84ba3 | 3310 | ;;;_ #5 Alteration |
c567ac01 RS |
3311 | |
3312 | ;;;_ - Fundamental | |
fd5359c6 MR |
3313 | ;;;_ = allout-post-goto-bullet |
3314 | (defvar allout-post-goto-bullet nil | |
3315 | "Outline internal var, for `allout-pre-command-business' hot-spot operation. | |
19b84ba3 RS |
3316 | |
3317 | When set, tells post-processing to reposition on topic bullet, and | |
2265e017 | 3318 | then unset it. Set by `allout-pre-command-business' when implementing |
19b84ba3 RS |
3319 | hot-spot operation, where literal characters typed over a topic bullet |
3320 | are mapped to the command of the corresponding control-key on the | |
d3e51865 | 3321 | `allout-mode-map-value'.") |
fd5359c6 | 3322 | (make-variable-buffer-local 'allout-post-goto-bullet) |
48bd8440 EZ |
3323 | ;;;_ = allout-command-counter |
3324 | (defvar allout-command-counter 0 | |
3325 | "Counter that monotonically increases in allout-mode buffers. | |
3326 | ||
3327 | Set by `allout-pre-command-business', to support allout addons in | |
3328 | coordinating with allout activity.") | |
3329 | (make-variable-buffer-local 'allout-command-counter) | |
3f2b07f8 KM |
3330 | ;;;_ = allout-this-command-hid-text |
3331 | (defvar allout-this-command-hid-text nil | |
3332 | "True if the most recent allout-mode command hid any text.") | |
3333 | (make-variable-buffer-local 'allout-this-command-hid-text) | |
fd5359c6 MR |
3334 | ;;;_ > allout-post-command-business () |
3335 | (defun allout-post-command-business () | |
2265e017 | 3336 | "Outline `post-command-hook' function. |
c567ac01 | 3337 | |
2265e017 | 3338 | - Implement (and clear) `allout-post-goto-bullet', for hot-spot |
c567ac01 RS |
3339 | outline commands. |
3340 | ||
3f2b07f8 KM |
3341 | - Move the cursor to the beginning of the entry if it is hidden |
3342 | and collapsing activity just happened. | |
3343 | ||
13aa217b KM |
3344 | - If the command we're following was an undo, check for change in |
3345 | the status of encrypted items and adjust auto-save inhibitions | |
3346 | accordingly. | |
3347 | ||
96b83743 | 3348 | - Decrypt topic currently being edited if it was encrypted for a save." |
c567ac01 | 3349 | |
fd5359c6 | 3350 | (if (not (allout-mode-p)) ; In allout-mode. |
19b84ba3 | 3351 | nil |
d82979ea | 3352 | |
13aa217b KM |
3353 | (when allout-just-did-undo |
3354 | (setq allout-just-did-undo nil) | |
919d884a | 3355 | (run-hooks 'allout-post-undo-hook) |
13aa217b KM |
3356 | (cond ((and (= buffer-saved-size -1) |
3357 | allout-auto-save-temporarily-disabled) | |
99d99081 | 3358 | ;; user possibly undid a decryption, disinhibit auto-save: |
13aa217b KM |
3359 | (allout-maybe-resume-auto-save-info-after-encryption)) |
3360 | ((save-excursion | |
3361 | (save-restriction | |
3362 | (widen) | |
3363 | (goto-char (point-min)) | |
3364 | (not (allout-next-topic-pending-encryption)))) | |
3365 | ;; plain-text encrypted items are present, inhibit auto-save: | |
3366 | (allout-inhibit-auto-save-info-for-decryption (buffer-size))))) | |
3367 | ||
d82979ea EZ |
3368 | (if (and (boundp 'allout-after-save-decrypt) |
3369 | allout-after-save-decrypt) | |
3370 | (allout-after-saves-handler)) | |
3371 | ||
48bd8440 | 3372 | ;; Implement allout-post-goto-bullet, if set: |
fd5359c6 MR |
3373 | (if (and allout-post-goto-bullet |
3374 | (allout-current-bullet-pos)) | |
3375 | (progn (goto-char (allout-current-bullet-pos)) | |
3f2b07f8 KM |
3376 | (setq allout-post-goto-bullet nil)) |
3377 | (when (and (allout-hidden-p) allout-this-command-hid-text) | |
3378 | (allout-beginning-of-current-entry))))) | |
fd5359c6 MR |
3379 | ;;;_ > allout-pre-command-business () |
3380 | (defun allout-pre-command-business () | |
2265e017 | 3381 | "Outline `pre-command-hook' function for outline buffers. |
48bd8440 EZ |
3382 | |
3383 | Among other things, implements special behavior when the cursor is on the | |
3384 | topic bullet character. | |
c567ac01 | 3385 | |
d3e51865 KM |
3386 | When the cursor is on the bullet character, self-insert |
3387 | characters are reinterpreted as the corresponding | |
3388 | control-character in the `allout-mode-map-value'. The | |
3389 | `allout-mode' `post-command-hook' insures that the cursor which | |
3390 | has moved as a result of such reinterpretation is positioned on | |
3391 | the bullet character of the destination topic. | |
c567ac01 | 3392 | |
c07583cd | 3393 | The upshot is that you can get easy, single (ie, unmodified) key |
9179616f | 3394 | outline maneuvering operations by positioning the cursor on the bullet |
58edceeb JB |
3395 | char. When in this mode you can use regular cursor-positioning |
3396 | command/keystrokes to relocate the cursor off of a bullet character to | |
3397 | return to regular interpretation of self-insert characters." | |
d82979ea | 3398 | |
fd5359c6 | 3399 | (if (not (allout-mode-p)) |
9179616f | 3400 | nil |
48bd8440 | 3401 | (setq allout-command-counter (1+ allout-command-counter)) |
3f2b07f8 | 3402 | (setq allout-this-command-hid-text nil) |
48bd8440 | 3403 | ;; Do hot-spot navigation. |
9179616f | 3404 | (if (and (eq this-command 'self-insert-command) |
fd5359c6 | 3405 | (eq (point)(allout-current-bullet-pos))) |
01fc9422 EZ |
3406 | (allout-hotspot-key-handler)))) |
3407 | ;;;_ > allout-hotspot-key-handler () | |
3408 | (defun allout-hotspot-key-handler () | |
3409 | "Catchall handling of key bindings in hot-spots. | |
3410 | ||
3411 | Translates unmodified keystrokes to corresponding allout commands, when | |
20db1522 JB |
3412 | they would qualify if prefixed with the `allout-command-prefix', and sets |
3413 | `this-command' accordingly. | |
01fc9422 EZ |
3414 | |
3415 | Returns the qualifying command, if any, else nil." | |
3416 | (interactive) | |
1c9b9df0 | 3417 | (let* ((modified (event-modifiers last-command-event)) |
8989a920 | 3418 | (key-num (cond ((numberp last-command-event) last-command-event) |
01fc9422 EZ |
3419 | ;; for XEmacs character type: |
3420 | ((and (fboundp 'characterp) | |
8989a920 GM |
3421 | (apply 'characterp (list last-command-event))) |
3422 | (apply 'char-to-int (list last-command-event))) | |
01fc9422 | 3423 | (t 0))) |
d8350998 | 3424 | mapped-binding) |
01fc9422 EZ |
3425 | |
3426 | (if (zerop key-num) | |
3427 | nil | |
3428 | ||
d8350998 CY |
3429 | (if (and |
3430 | ;; exclude control chars and escape: | |
1c9b9df0 | 3431 | (not modified) |
d8350998 CY |
3432 | (<= 33 key-num) |
3433 | (setq mapped-binding | |
642f3c5c KM |
3434 | (or |
3435 | ;; try control-modified versions of keys: | |
3436 | (key-binding (vconcat allout-command-prefix | |
3437 | (vector | |
3438 | (if (and (<= 97 key-num) ; "a" | |
3439 | (>= 122 key-num)) ; "z" | |
3440 | (- key-num 96) key-num))) | |
3441 | t) | |
3442 | ;; try non-modified versions of keys: | |
3443 | (key-binding (vconcat allout-command-prefix | |
3444 | (vector key-num)) | |
3445 | t)))) | |
60c7bbd2 | 3446 | ;; Qualified as an allout command -- do hot-spot operation. |
01fc9422 | 3447 | (setq allout-post-goto-bullet t) |
1c9b9df0 KM |
3448 | ;; accept-defaults nil, or else we get allout-item-icon-key-handler. |
3449 | (setq mapped-binding (key-binding (vector key-num)))) | |
01fc9422 EZ |
3450 | |
3451 | (while (keymapp mapped-binding) | |
3452 | (setq mapped-binding | |
d8350998 | 3453 | (lookup-key mapped-binding (vector (read-char))))) |
01fc9422 | 3454 | |
1c9b9df0 KM |
3455 | (when mapped-binding |
3456 | (setq this-command mapped-binding))))) | |
01fc9422 | 3457 | |
fd5359c6 MR |
3458 | ;;;_ > allout-find-file-hook () |
3459 | (defun allout-find-file-hook () | |
4034b0e2 | 3460 | "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'. |
fd5359c6 | 3461 | |
11c46e15 | 3462 | See `allout-auto-activation' for setup instructions." |
fd5359c6 MR |
3463 | (if (and allout-auto-activation |
3464 | (not (allout-mode-p)) | |
3465 | allout-layout) | |
2576c28f | 3466 | (allout-mode))) |
c567ac01 RS |
3467 | |
3468 | ;;;_ - Topic Format Assessment | |
fd5359c6 MR |
3469 | ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet) |
3470 | (defun allout-solicit-alternate-bullet (depth &optional current-bullet) | |
1977b8f6 | 3471 | |
19b84ba3 RS |
3472 | "Prompt for and return a bullet char as an alternative to the current one. |
3473 | ||
3474 | Offer one suitable for current depth DEPTH as default." | |
1977b8f6 | 3475 | |
9179616f | 3476 | (let* ((default-bullet (or (and (stringp current-bullet) current-bullet) |
fd5359c6 MR |
3477 | (allout-bullet-for-depth depth))) |
3478 | (sans-escapes (regexp-sans-escapes allout-bullets-string)) | |
9179616f DL |
3479 | choice) |
3480 | (save-excursion | |
fd5359c6 | 3481 | (goto-char (allout-current-bullet-pos)) |
9179616f DL |
3482 | (setq choice (solicit-char-in-string |
3483 | (format "Select bullet: %s ('%s' default): " | |
3484 | sans-escapes | |
1c9b9df0 | 3485 | (allout-substring-no-properties default-bullet)) |
9179616f DL |
3486 | sans-escapes |
3487 | t))) | |
3488 | (message "") | |
1977b8f6 RS |
3489 | (if (string= choice "") default-bullet choice)) |
3490 | ) | |
fd5359c6 MR |
3491 | ;;;_ > allout-distinctive-bullet (bullet) |
3492 | (defun allout-distinctive-bullet (bullet) | |
e126900f | 3493 | "True if BULLET is one of those on `allout-distinctive-bullets-string'." |
fd5359c6 MR |
3494 | (string-match (regexp-quote bullet) allout-distinctive-bullets-string)) |
3495 | ;;;_ > allout-numbered-type-prefix (&optional prefix) | |
3496 | (defun allout-numbered-type-prefix (&optional prefix) | |
c567ac01 | 3497 | "True if current header prefix bullet is numbered bullet." |
fd5359c6 MR |
3498 | (and allout-numbered-bullet |
3499 | (string= allout-numbered-bullet | |
1977b8f6 | 3500 | (if prefix |
fd5359c6 MR |
3501 | (allout-get-prefix-bullet prefix) |
3502 | (allout-get-bullet))))) | |
d82979ea EZ |
3503 | ;;;_ > allout-encrypted-type-prefix (&optional prefix) |
3504 | (defun allout-encrypted-type-prefix (&optional prefix) | |
c07583cd | 3505 | "True if current header prefix bullet is for an encrypted entry (body)." |
d82979ea EZ |
3506 | (and allout-topic-encryption-bullet |
3507 | (string= allout-topic-encryption-bullet | |
3508 | (if prefix | |
3509 | (allout-get-prefix-bullet prefix) | |
3510 | (allout-get-bullet))))) | |
fd5359c6 MR |
3511 | ;;;_ > allout-bullet-for-depth (&optional depth) |
3512 | (defun allout-bullet-for-depth (&optional depth) | |
19b84ba3 | 3513 | "Return outline topic bullet suited to optional DEPTH, or current depth." |
1977b8f6 | 3514 | ;; Find bullet in plain-bullets-string modulo DEPTH. |
fd5359c6 MR |
3515 | (if allout-stylish-prefixes |
3516 | (char-to-string (aref allout-plain-bullets-string | |
1977b8f6 | 3517 | (% (max 0 (- depth 2)) |
fd5359c6 MR |
3518 | allout-plain-bullets-string-len))) |
3519 | allout-primary-bullet) | |
1977b8f6 RS |
3520 | ) |
3521 | ||
c567ac01 | 3522 | ;;;_ - Topic Production |
fd5359c6 MR |
3523 | ;;;_ > allout-make-topic-prefix (&optional prior-bullet |
3524 | (defun allout-make-topic-prefix (&optional prior-bullet | |
1977b8f6 RS |
3525 | new |
3526 | depth | |
b6a5875b | 3527 | instead |
1977b8f6 RS |
3528 | number-control |
3529 | index) | |
3530 | ;; Depth null means use current depth, non-null means we're either | |
3531 | ;; opening a new topic after current topic, lower or higher, or we're | |
3532 | ;; changing level of current topic. | |
b6a5875b | 3533 | ;; Instead dominates specified bullet-char. |
c567ac01 | 3534 | ;;;_ . Doc string: |
19b84ba3 | 3535 | "Generate a topic prefix suitable for optional arg DEPTH, or current depth. |
c567ac01 RS |
3536 | |
3537 | All the arguments are optional. | |
3538 | ||
3539 | PRIOR-BULLET indicates the bullet of the prefix being changed, or | |
3540 | nil if none. This bullet may be preserved (other options | |
2265e017 | 3541 | notwithstanding) if it is on the `allout-distinctive-bullets-string', |
c567ac01 RS |
3542 | for instance. |
3543 | ||
3544 | Second arg NEW indicates that a new topic is being opened after the | |
3545 | topic at point, if non-nil. Default bullet for new topics, eg, may | |
3546 | be set (contingent to other args) to numbered bullets if previous | |
3547 | sibling is one. The implication otherwise is that the current topic | |
60c7bbd2 | 3548 | is being adjusted -- shifted or rebulleted -- and we don't consider |
c567ac01 RS |
3549 | bullet or previous sibling. |
3550 | ||
3551 | Third arg DEPTH forces the topic prefix to that depth, regardless of | |
3552 | the current topics' depth. | |
3553 | ||
b6a5875b KM |
3554 | If INSTEAD is: |
3555 | ||
3556 | - nil, then the bullet char for the context is used, per distinction or depth | |
20db1522 | 3557 | - a (numeric) character, then character's string representation is used |
2dab465b | 3558 | - a string, then the user is asked for bullet with the first char as default |
b6a5875b KM |
3559 | - anything else, the user is solicited with bullet char per context as default |
3560 | ||
3561 | \(INSTEAD overrides other options, including, eg, a distinctive | |
3562 | PRIOR-BULLET.) | |
c567ac01 | 3563 | |
fd5359c6 | 3564 | Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet' |
b6a5875b | 3565 | is non-nil *and* no specific INSTEAD was specified. Then |
c567ac01 | 3566 | NUMBER-CONTROL non-nil forces prefix to either numbered or |
4c36be58 | 3567 | unnumbered format, depending on the value of the sixth arg, INDEX. |
c567ac01 RS |
3568 | |
3569 | \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...) | |
3570 | ||
3571 | If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then | |
3572 | the prefix of the topic is forced to be numbered. Non-nil | |
3573 | NUMBER-CONTROL and nil INDEX forces non-numbered format on the | |
3574 | bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means | |
3575 | that the index for the numbered prefix will be derived, by counting | |
3576 | siblings back to start of level. If INDEX is a number, then that | |
3577 | number is used as the index for the numbered prefix (allowing, eg, | |
a0776d6b | 3578 | sequential renumbering to not require this function counting back the |
c567ac01 RS |
3579 | index for each successive sibling)." |
3580 | ;;;_ . Code: | |
c5e87d10 | 3581 | ;; The options are ordered in likely frequency of use, most common |
1977b8f6 RS |
3582 | ;; highest, least lowest. Ie, more likely to be doing prefix |
3583 | ;; adjustments than soliciting, and yet more than numbering. | |
3584 | ;; Current prefix is least dominant, but most likely to be commonly | |
3585 | ;; specified... | |
3586 | ||
3587 | (let* (body | |
3588 | numbering | |
3589 | denumbering | |
fd5359c6 MR |
3590 | (depth (or depth (allout-depth))) |
3591 | (header-lead allout-header-prefix) | |
1977b8f6 RS |
3592 | (bullet-char |
3593 | ||
3594 | ;; Getting value for bullet char is practically the whole job: | |
3595 | ||
3596 | (cond | |
60c7bbd2 | 3597 | ; Simplest situation -- level 1: |
fd5359c6 | 3598 | ((<= depth 1) (setq header-lead "") allout-primary-bullet) |
1977b8f6 | 3599 | ; Simple, too: all asterisks: |
fd5359c6 | 3600 | (allout-old-style-prefixes |
60c7bbd2 | 3601 | ;; Cheat -- make body the whole thing, null out header-lead and |
1977b8f6 RS |
3602 | ;; bullet-char: |
3603 | (setq body (make-string depth | |
fd5359c6 | 3604 | (string-to-char allout-primary-bullet))) |
1977b8f6 RS |
3605 | (setq header-lead "") |
3606 | "") | |
3607 | ||
3608 | ;; (Neither level 1 nor old-style, so we're space padding. | |
3609 | ;; Sneak it in the condition of the next case, whatever it is.) | |
3610 | ||
3611 | ;; Solicitation overrides numbering and other cases: | |
3612 | ((progn (setq body (make-string (- depth 2) ?\ )) | |
3613 | ;; The actual condition: | |
b6a5875b | 3614 | instead) |
2dab465b KM |
3615 | (let ((got (cond ((stringp instead) |
3616 | (if (> (length instead) 0) | |
3617 | (allout-solicit-alternate-bullet | |
3618 | depth (substring instead 0 1)))) | |
3619 | ((characterp instead) (char-to-string instead)) | |
3620 | (t (allout-solicit-alternate-bullet depth))))) | |
1977b8f6 | 3621 | ;; Gotta check whether we're numbering and got a numbered bullet: |
fd5359c6 | 3622 | (setq numbering (and allout-numbered-bullet |
1977b8f6 | 3623 | (not (and number-control (not index))) |
fd5359c6 | 3624 | (string= got allout-numbered-bullet))) |
1977b8f6 RS |
3625 | ;; Now return what we got, regardless: |
3626 | got)) | |
3627 | ||
3628 | ;; Numbering invoked through args: | |
fd5359c6 | 3629 | ((and allout-numbered-bullet number-control) |
1977b8f6 | 3630 | (if (setq numbering (not (setq denumbering (not index)))) |
fd5359c6 | 3631 | allout-numbered-bullet |
19b84ba3 | 3632 | (if (and prior-bullet |
fd5359c6 | 3633 | (not (string= allout-numbered-bullet |
19b84ba3 RS |
3634 | prior-bullet))) |
3635 | prior-bullet | |
fd5359c6 | 3636 | (allout-bullet-for-depth depth)))) |
1977b8f6 RS |
3637 | |
3638 | ;;; Neither soliciting nor controlled numbering ;;; | |
3639 | ;;; (may be controlled denumbering, tho) ;;; | |
3640 | ||
3641 | ;; Check wrt previous sibling: | |
3642 | ((and new ; only check for new prefixes | |
fd5359c6 MR |
3643 | (<= depth (allout-depth)) |
3644 | allout-numbered-bullet ; ... & numbering enabled | |
1977b8f6 RS |
3645 | (not denumbering) |
3646 | (let ((sibling-bullet | |
3647 | (save-excursion | |
3648 | ;; Locate correct sibling: | |
fd5359c6 MR |
3649 | (or (>= depth (allout-depth)) |
3650 | (allout-ascend-to-depth depth)) | |
3651 | (allout-get-bullet)))) | |
1977b8f6 | 3652 | (if (and sibling-bullet |
fd5359c6 | 3653 | (string= allout-numbered-bullet sibling-bullet)) |
1977b8f6 RS |
3654 | (setq numbering sibling-bullet))))) |
3655 | ||
3656 | ;; Distinctive prior bullet? | |
3657 | ((and prior-bullet | |
fd5359c6 | 3658 | (allout-distinctive-bullet prior-bullet) |
1977b8f6 | 3659 | ;; Either non-numbered: |
fd5359c6 MR |
3660 | (or (not (and allout-numbered-bullet |
3661 | (string= prior-bullet allout-numbered-bullet))) | |
1977b8f6 RS |
3662 | ;; or numbered, and not denumbering: |
3663 | (setq numbering (not denumbering))) | |
3664 | ;; Here 'tis: | |
3665 | prior-bullet)) | |
3666 | ||
3667 | ;; Else, standard bullet per depth: | |
fd5359c6 | 3668 | ((allout-bullet-for-depth depth))))) |
1977b8f6 RS |
3669 | |
3670 | (concat header-lead | |
3671 | body | |
3672 | bullet-char | |
3673 | (if numbering | |
3674 | (format "%d" (cond ((and index (numberp index)) index) | |
fd5359c6 MR |
3675 | (new (1+ (allout-sibling-index depth))) |
3676 | ((allout-sibling-index)))))) | |
1977b8f6 RS |
3677 | ) |
3678 | ) | |
96b83743 EZ |
3679 | ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet) |
3680 | (defun allout-open-topic (relative-depth &optional before offer-recent-bullet) | |
d82979ea | 3681 | "Open a new topic at depth DEPTH. |
19b84ba3 RS |
3682 | |
3683 | New topic is situated after current one, unless optional flag BEFORE | |
60c7bbd2 RS |
3684 | is non-nil, or unless current line is completely empty -- lacking even |
3685 | whitespace -- in which case open is done on the current line. | |
96b83743 EZ |
3686 | |
3687 | When adding an offspring, it will be added immediately after the parent if | |
3688 | the other offspring are exposed, or after the last child if the offspring | |
c07583cd | 3689 | are hidden. (The intervening offspring will be exposed in the latter |
96b83743 | 3690 | case.) |
c567ac01 | 3691 | |
96b83743 | 3692 | If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling. |
9179616f | 3693 | |
c567ac01 RS |
3694 | Nuances: |
3695 | ||
3696 | - Creation of new topics is with respect to the visible topic | |
3697 | containing the cursor, regardless of intervening concealed ones. | |
3698 | ||
3699 | - New headers are generally created after/before the body of a | |
3700 | topic. However, they are created right at cursor location if the | |
3701 | cursor is on a blank line, even if that breaks the current topic | |
3702 | body. This is intentional, to provide a simple means for | |
3703 | deliberately dividing topic bodies. | |
3704 | ||
3705 | - Double spacing of topic lists is preserved. Also, the first | |
3706 | level two topic is created double-spaced (and so would be | |
3707 | subsequent siblings, if that's left intact). Otherwise, | |
3708 | single-spacing is used. | |
3709 | ||
3710 | - Creation of sibling or nested topics is with respect to the topic | |
3711 | you're starting from, even when creating backwards. This way you | |
3712 | can easily create a sibling in front of the current topic without | |
a0776d6b | 3713 | having to go to its preceding sibling, and then open forward |
c567ac01 | 3714 | from there." |
1977b8f6 | 3715 | |
96b83743 | 3716 | (allout-beginning-of-current-line) |
2a1408fd DN |
3717 | (save-match-data |
3718 | (let* ((inhibit-field-text-motion t) | |
3719 | (depth (+ (allout-current-depth) relative-depth)) | |
3720 | (opening-on-blank (if (looking-at "^\$") | |
3721 | (not (setq before nil)))) | |
3722 | ;; bunch o vars set while computing ref-topic | |
3723 | opening-numbered | |
3724 | ref-depth | |
3725 | ref-bullet | |
3726 | (ref-topic (save-excursion | |
3727 | (cond ((< relative-depth 0) | |
3728 | (allout-ascend-to-depth depth)) | |
3729 | ((>= relative-depth 1) nil) | |
3730 | (t (allout-back-to-current-heading))) | |
3731 | (setq ref-depth allout-recent-depth) | |
3732 | (setq ref-bullet | |
3733 | (if (> allout-recent-prefix-end 1) | |
3734 | (allout-recent-bullet) | |
3735 | "")) | |
3736 | (setq opening-numbered | |
3737 | (save-excursion | |
3738 | (and allout-numbered-bullet | |
3739 | (or (<= relative-depth 0) | |
3740 | (allout-descend-to-depth depth)) | |
3741 | (if (allout-numbered-type-prefix) | |
3742 | allout-numbered-bullet)))) | |
3743 | (point))) | |
3744 | dbl-space | |
3745 | doing-beginning | |
3746 | start end) | |
3747 | ||
3748 | (if (not opening-on-blank) | |
1977b8f6 | 3749 | ; Positioning and vertical |
60c7bbd2 | 3750 | ; padding -- only if not |
1977b8f6 | 3751 | ; opening-on-blank: |
2a1408fd DN |
3752 | (progn |
3753 | (goto-char ref-topic) | |
3754 | (setq dbl-space ; Determine double space action: | |
3755 | (or (and (<= relative-depth 0) ; not descending; | |
3756 | (save-excursion | |
3757 | ;; at b-o-b or preceded by a blank line? | |
3758 | (or (> 0 (forward-line -1)) | |
3759 | (looking-at "^\\s-*$") | |
3760 | (bobp))) | |
3761 | (save-excursion | |
3762 | ;; succeeded by a blank line? | |
3763 | (allout-end-of-current-subtree) | |
3764 | (looking-at "\n\n"))) | |
3765 | (and (= ref-depth 1) | |
3766 | (or before | |
3767 | (= depth 1) | |
3768 | (save-excursion | |
3769 | ;; Don't already have following | |
3770 | ;; vertical padding: | |
3771 | (not (allout-pre-next-prefix))))))) | |
3772 | ||
3773 | ;; Position to prior heading, if inserting backwards, and not | |
3774 | ;; going outwards: | |
3775 | (if (and before (>= relative-depth 0)) | |
3776 | (progn (allout-back-to-current-heading) | |
3777 | (setq doing-beginning (bobp)) | |
3778 | (if (not (bobp)) | |
3779 | (allout-previous-heading))) | |
3780 | (if (and before (bobp)) | |
3781 | (open-line 1))) | |
3782 | ||
3783 | (if (<= relative-depth 0) | |
3784 | ;; Not going inwards, don't snug up: | |
3785 | (if doing-beginning | |
3786 | (if (not dbl-space) | |
3787 | (open-line 1) | |
3788 | (open-line 2)) | |
3789 | (if before | |
3790 | (progn (end-of-line) | |
3791 | (allout-pre-next-prefix) | |
3792 | (while (and (= ?\n (following-char)) | |
3793 | (save-excursion | |
3794 | (forward-char 1) | |
3795 | (allout-hidden-p))) | |
3796 | (forward-char 1)) | |
3797 | (if (not (looking-at "^$")) | |
3798 | (open-line 1))) | |
3799 | (allout-end-of-current-subtree) | |
3800 | (if (looking-at "\n\n") (forward-char 1)))) | |
8dd59f01 | 3801 | ;; Going inwards -- double-space if first offspring is |
2a1408fd DN |
3802 | ;; double-spaced, otherwise snug up. |
3803 | (allout-end-of-entry) | |
3804 | (if (eobp) | |
3805 | (newline 1) | |
3806 | (line-move 1)) | |
3807 | (allout-beginning-of-current-line) | |
3808 | (backward-char 1) | |
3809 | (if (bolp) | |
3810 | ;; Blank lines between current header body and next | |
8dd59f01 | 3811 | ;; header -- get to last substantive (non-white-space) |
2a1408fd DN |
3812 | ;; line in body: |
3813 | (progn (setq dbl-space t) | |
3814 | (re-search-backward "[^ \t\n]" nil t))) | |
3815 | (if (looking-at "\n\n") | |
3816 | (setq dbl-space t)) | |
3817 | (if (save-excursion | |
3818 | (allout-next-heading) | |
3819 | (when (> allout-recent-depth ref-depth) | |
3820 | ;; This is an offspring. | |
3821 | (forward-line -1) | |
3822 | (looking-at "^\\s-*$"))) | |
3823 | (progn (forward-line 1) | |
96b83743 | 3824 | (open-line 1) |
2a1408fd DN |
3825 | (forward-line 1))) |
3826 | (allout-end-of-current-line)) | |
3827 | ||
3828 | ;;(if doing-beginning (goto-char doing-beginning)) | |
3829 | (if (not (bobp)) | |
3830 | ;; We insert a newline char rather than using open-line to | |
0b381c7e | 3831 | ;; avoid rear-stickiness inheritance of read-only property. |
2a1408fd DN |
3832 | (progn (if (and (not (> depth ref-depth)) |
3833 | (not before)) | |
3834 | (open-line 1) | |
3835 | (if (and (not dbl-space) (> depth ref-depth)) | |
3836 | (newline 1) | |
3837 | (if dbl-space | |
3838 | (open-line 1) | |
3839 | (if (not before) | |
3840 | (newline 1))))) | |
3841 | (if (and dbl-space (not (> relative-depth 0))) | |
3842 | (newline 1)) | |
3843 | (if (and (not (eobp)) | |
3844 | (or (not (bolp)) | |
3845 | (and (not (bobp)) | |
c7015153 | 3846 | ;; bolp doesn't detect concealed |
2a1408fd DN |
3847 | ;; trailing newlines, compensate: |
3848 | (save-excursion | |
3849 | (forward-char -1) | |
3850 | (allout-hidden-p))))) | |
3851 | (forward-char 1)))) | |
3852 | )) | |
3853 | (setq start (point)) | |
3854 | (insert (concat (allout-make-topic-prefix opening-numbered t depth) | |
3855 | " ")) | |
3856 | (setq end (1+ (point))) | |
3857 | ||
3858 | (allout-rebullet-heading (and offer-recent-bullet ref-bullet) | |
3859 | depth nil nil t) | |
3860 | (if (> relative-depth 0) | |
3861 | (save-excursion (goto-char ref-topic) | |
3862 | (allout-show-children))) | |
3863 | (end-of-line) | |
48bd8440 | 3864 | |
7b97c764 | 3865 | (run-hook-with-args 'allout-structure-added-functions start end) |
2a1408fd | 3866 | ) |
1977b8f6 RS |
3867 | ) |
3868 | ) | |
fd5359c6 MR |
3869 | ;;;_ > allout-open-subtopic (arg) |
3870 | (defun allout-open-subtopic (arg) | |
c567ac01 RS |
3871 | "Open new topic header at deeper level than the current one. |
3872 | ||
20db1522 | 3873 | Negative universal ARG means to open deeper, but place the new topic |
c567ac01 | 3874 | prior to the current one." |
1977b8f6 | 3875 | (interactive "p") |
d82979ea | 3876 | (allout-open-topic 1 (> 0 arg) (< 1 arg))) |
fd5359c6 MR |
3877 | ;;;_ > allout-open-sibtopic (arg) |
3878 | (defun allout-open-sibtopic (arg) | |
19b84ba3 RS |
3879 | "Open new topic header at same level as the current one. |
3880 | ||
20db1522 | 3881 | Positive universal ARG means to use the bullet of the prior sibling. |
9179616f | 3882 | |
20db1522 | 3883 | Negative universal ARG means to place the new topic prior to the current |
c567ac01 | 3884 | one." |
1977b8f6 | 3885 | (interactive "p") |
d82979ea | 3886 | (allout-open-topic 0 (> 0 arg) (not (= 1 arg)))) |
fd5359c6 MR |
3887 | ;;;_ > allout-open-supertopic (arg) |
3888 | (defun allout-open-supertopic (arg) | |
c567ac01 | 3889 | "Open new topic header at shallower level than the current one. |
19b84ba3 | 3890 | |
20db1522 | 3891 | Negative universal ARG means to open shallower, but place the new |
c567ac01 | 3892 | topic prior to the current one." |
1977b8f6 RS |
3893 | |
3894 | (interactive "p") | |
d82979ea | 3895 | (allout-open-topic -1 (> 0 arg) (< 1 arg))) |
c567ac01 RS |
3896 | |
3897 | ;;;_ - Outline Alteration | |
3898 | ;;;_ : Topic Modification | |
fd5359c6 MR |
3899 | ;;;_ = allout-former-auto-filler |
3900 | (defvar allout-former-auto-filler nil | |
2265e017 | 3901 | "Name of modal fill function being wrapped by `allout-auto-fill'.") |
fd5359c6 MR |
3902 | ;;;_ > allout-auto-fill () |
3903 | (defun allout-auto-fill () | |
aad94676 | 3904 | "`allout-mode' autofill function. |
19b84ba3 RS |
3905 | |
3906 | Maintains outline hanging topic indentation if | |
fd5359c6 | 3907 | `allout-use-hanging-indents' is set." |
01fc9422 | 3908 | |
381987c3 KM |
3909 | (when (and (not allout-inhibit-auto-fill) |
3910 | (or (not allout-inhibit-auto-fill-on-headline) | |
3911 | (not (allout-on-current-heading-p)))) | |
01fc9422 EZ |
3912 | (let ((fill-prefix (if allout-use-hanging-indents |
3913 | ;; Check for topic header indentation: | |
2a1408fd DN |
3914 | (save-match-data |
3915 | (save-excursion | |
3916 | (beginning-of-line) | |
3917 | (if (looking-at allout-regexp) | |
3918 | ;; ... construct indentation to account for | |
3919 | ;; length of topic prefix: | |
3920 | (make-string (progn (allout-end-of-prefix) | |
3921 | (current-column)) | |
3922 | ?\ )))))) | |
7927f48d KM |
3923 | (use-auto-fill-function |
3924 | (if (and (eq allout-outside-normal-auto-fill-function | |
3925 | 'allout-auto-fill) | |
3926 | (eq auto-fill-function 'allout-auto-fill)) | |
3927 | 'do-auto-fill | |
3928 | (or allout-outside-normal-auto-fill-function | |
3929 | auto-fill-function)))) | |
01fc9422 EZ |
3930 | (if (or allout-former-auto-filler allout-use-hanging-indents) |
3931 | (funcall use-auto-fill-function))))) | |
fd5359c6 MR |
3932 | ;;;_ > allout-reindent-body (old-depth new-depth &optional number) |
3933 | (defun allout-reindent-body (old-depth new-depth &optional number) | |
e126900f | 3934 | "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH. |
c567ac01 RS |
3935 | |
3936 | Optional arg NUMBER indicates numbering is being added, and it must | |
a0776d6b | 3937 | be accommodated. |
c567ac01 RS |
3938 | |
3939 | Note that refill of indented paragraphs is not done." | |
1977b8f6 RS |
3940 | |
3941 | (save-excursion | |
fd5359c6 | 3942 | (allout-end-of-prefix) |
c567ac01 RS |
3943 | (let* ((new-margin (current-column)) |
3944 | excess old-indent-begin old-indent-end | |
c567ac01 RS |
3945 | ;; We want the column where the header-prefix text started |
3946 | ;; *before* the prefix was changed, so we infer it relative | |
3947 | ;; to the new margin and the shift in depth: | |
3948 | (old-margin (+ old-depth (- new-margin new-depth)))) | |
353e2ef2 | 3949 | |
c567ac01 | 3950 | ;; Process lines up to (but excluding) next topic header: |
fd5359c6 | 3951 | (allout-unprotected |
c567ac01 RS |
3952 | (save-match-data |
3953 | (while | |
96b83743 | 3954 | (and (re-search-forward "\n\\(\\s-*\\)" |
c567ac01 RS |
3955 | nil |
3956 | t) | |
3957 | ;; Register the indent data, before we reset the | |
353e2ef2 | 3958 | ;; match data with a subsequent `looking-at': |
c567ac01 RS |
3959 | (setq old-indent-begin (match-beginning 1) |
3960 | old-indent-end (match-end 1)) | |
fd5359c6 | 3961 | (not (looking-at allout-regexp))) |
d82979ea EZ |
3962 | (if (> 0 (setq excess (- (- old-indent-end old-indent-begin) |
3963 | old-margin))) | |
60c7bbd2 | 3964 | ;; Text starts left of old margin -- don't adjust: |
c567ac01 | 3965 | nil |
ea18b2b1 | 3966 | ;; Text was hanging at or right of old left margin -- |
c567ac01 RS |
3967 | ;; reindent it, preserving its existing indentation |
3968 | ;; beyond the old margin: | |
3969 | (delete-region old-indent-begin old-indent-end) | |
d82979ea | 3970 | (indent-to (+ new-margin excess (current-column)))))))))) |
fd5359c6 MR |
3971 | ;;;_ > allout-rebullet-current-heading (arg) |
3972 | (defun allout-rebullet-current-heading (arg) | |
9179616f DL |
3973 | "Solicit new bullet for current visible heading." |
3974 | (interactive "p") | |
3975 | (let ((initial-col (current-column)) | |
fd5359c6 | 3976 | (on-bullet (eq (point)(allout-current-bullet-pos))) |
d8350998 | 3977 | from to |
9179616f DL |
3978 | (backwards (if (< arg 0) |
3979 | (setq arg (* arg -1))))) | |
3980 | (while (> arg 0) | |
fd5359c6 MR |
3981 | (save-excursion (allout-back-to-current-heading) |
3982 | (allout-end-of-prefix) | |
d8350998 CY |
3983 | (setq from allout-recent-prefix-beginning |
3984 | to allout-recent-prefix-end) | |
b6a5875b | 3985 | (allout-rebullet-heading t ;;; instead |
9179616f DL |
3986 | nil ;;; depth |
3987 | nil ;;; number-control | |
3988 | nil ;;; index | |
d8350998 | 3989 | t) ;;; do-successors |
7b97c764 | 3990 | (run-hook-with-args 'allout-exposure-change-functions |
d8350998 | 3991 | from to t)) |
9179616f DL |
3992 | (setq arg (1- arg)) |
3993 | (if (<= arg 0) | |
3994 | nil | |
3995 | (setq initial-col nil) ; Override positioning back to init col | |
3996 | (if (not backwards) | |
fd5359c6 | 3997 | (allout-next-visible-heading 1) |
d8350998 | 3998 | (allout-goto-prefix-doublechecked) |
fd5359c6 | 3999 | (allout-next-visible-heading -1)))) |
9179616f | 4000 | (message "Done.") |
fd5359c6 | 4001 | (cond (on-bullet (goto-char (allout-current-bullet-pos))) |
9179616f | 4002 | (initial-col (move-to-column initial-col))))) |
b6a5875b KM |
4003 | ;;;_ > allout-rebullet-heading (&optional instead ...) |
4004 | (defun allout-rebullet-heading (&optional instead | |
1977b8f6 RS |
4005 | new-depth |
4006 | number-control | |
4007 | index | |
4008 | do-successors) | |
4009 | ||
c567ac01 | 4010 | "Adjust bullet of current topic prefix. |
1977b8f6 | 4011 | |
d82979ea EZ |
4012 | All args are optional. |
4013 | ||
b6a5875b KM |
4014 | If INSTEAD is: |
4015 | - nil, then the bullet char for the context is used, per distinction or depth | |
20db1522 | 4016 | - a (numeric) character, then character's string representation is used |
2dab465b | 4017 | - a string, then the user is asked for bullet with the first char as default |
b6a5875b | 4018 | - anything else, the user is solicited with bullet char per context as default |
1977b8f6 | 4019 | |
d82979ea | 4020 | Second arg DEPTH forces the topic prefix to that depth, regardless |
9179616f | 4021 | of the topic's current depth. |
1977b8f6 | 4022 | |
c567ac01 | 4023 | Third arg NUMBER-CONTROL can force the prefix to or away from |
fd5359c6 | 4024 | numbered form. It has effect only if `allout-numbered-bullet' is |
c567ac01 RS |
4025 | non-nil and soliciting was not explicitly invoked (via first arg). |
4026 | Its effect, numbering or denumbering, then depends on the setting | |
75bcb912 | 4027 | of the fourth arg, INDEX. |
1977b8f6 | 4028 | |
75bcb912 | 4029 | If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the |
c567ac01 RS |
4030 | prefix of the topic is forced to be non-numbered. Null index and |
4031 | non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and | |
4032 | non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil | |
4033 | INDEX is a number, then that number is used for the numbered | |
4034 | prefix. Non-nil and non-number means that the index for the | |
d82979ea | 4035 | numbered prefix will be derived by allout-make-topic-prefix. |
1977b8f6 | 4036 | |
c567ac01 RS |
4037 | Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding |
4038 | siblings. | |
1977b8f6 | 4039 | |
fd5359c6 MR |
4040 | Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes', |
4041 | and `allout-numbered-bullet', which all affect the behavior of | |
c567ac01 | 4042 | this function." |
1977b8f6 | 4043 | |
fd5359c6 | 4044 | (let* ((current-depth (allout-depth)) |
1977b8f6 | 4045 | (new-depth (or new-depth current-depth)) |
fd5359c6 MR |
4046 | (mb allout-recent-prefix-beginning) |
4047 | (me allout-recent-prefix-end) | |
d8350998 | 4048 | (current-bullet (buffer-substring-no-properties (- me 1) me)) |
ede4ac6a | 4049 | (has-annotation (get-text-property mb 'allout-was-hidden)) |
fd5359c6 | 4050 | (new-prefix (allout-make-topic-prefix current-bullet |
1977b8f6 RS |
4051 | nil |
4052 | new-depth | |
b6a5875b | 4053 | instead |
1977b8f6 RS |
4054 | number-control |
4055 | index))) | |
4056 | ||
20db1522 | 4057 | ;; Is new one identical to old? |
1977b8f6 RS |
4058 | (if (and (= current-depth new-depth) |
4059 | (string= current-bullet | |
4060 | (substring new-prefix (1- (length new-prefix))))) | |
c567ac01 | 4061 | ;; Nothing to do: |
1977b8f6 RS |
4062 | t |
4063 | ||
4064 | ;; New prefix probably different from old: | |
c567ac01 | 4065 | ; get rid of old one: |
fd5359c6 | 4066 | (allout-unprotected (delete-region mb me)) |
1977b8f6 | 4067 | (goto-char mb) |
c567ac01 RS |
4068 | ; Dispense with number if |
4069 | ; numbered-bullet prefix: | |
2a1408fd DN |
4070 | (save-match-data |
4071 | (if (and allout-numbered-bullet | |
4072 | (string= allout-numbered-bullet current-bullet) | |
4073 | (looking-at "[0-9]+")) | |
4074 | (allout-unprotected | |
4075 | (delete-region (match-beginning 0)(match-end 0))))) | |
1977b8f6 | 4076 | |
ede4ac6a KS |
4077 | ;; convey 'allout-was-hidden annotation, if original had it: |
4078 | (if has-annotation | |
4079 | (put-text-property 0 (length new-prefix) 'allout-was-hidden t | |
4080 | new-prefix)) | |
4081 | ||
c567ac01 | 4082 | ; Put in new prefix: |
fd5359c6 | 4083 | (allout-unprotected (insert new-prefix)) |
1977b8f6 | 4084 | |
d82979ea | 4085 | ;; Reindent the body if elected, margin changed, and not encrypted body: |
fd5359c6 | 4086 | (if (and allout-reindent-bodies |
d82979ea EZ |
4087 | (not (= new-depth current-depth)) |
4088 | (not (allout-encrypted-topic-p))) | |
fd5359c6 | 4089 | (allout-reindent-body current-depth new-depth)) |
1977b8f6 | 4090 | |
7b97c764 | 4091 | (run-hook-with-args 'allout-exposure-change-functions mb me nil) |
e47ca23b | 4092 | |
c567ac01 RS |
4093 | ;; Recursively rectify successive siblings of orig topic if |
4094 | ;; caller elected for it: | |
4095 | (if do-successors | |
4096 | (save-excursion | |
fd5359c6 | 4097 | (while (allout-next-sibling new-depth nil) |
c567ac01 RS |
4098 | (setq index |
4099 | (cond ((numberp index) (1+ index)) | |
fd5359c6 MR |
4100 | ((not number-control) (allout-sibling-index)))) |
4101 | (if (allout-numbered-type-prefix) | |
b6a5875b | 4102 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4103 | new-depth ;;; new-depth |
4104 | number-control;;; number-control | |
4105 | index ;;; index | |
4106 | nil))))) ;;;(dont!)do-successors | |
4107 | ) ; (if (and (= current-depth new-depth)...)) | |
fd5359c6 | 4108 | ) ; let* ((current-depth (allout-depth))...) |
c567ac01 | 4109 | ) ; defun |
fd5359c6 | 4110 | ;;;_ > allout-rebullet-topic (arg) |
d8350998 | 4111 | (defun allout-rebullet-topic (arg &optional sans-offspring) |
d82979ea | 4112 | "Rebullet the visible topic containing point and all contained subtopics. |
19b84ba3 | 4113 | |
c567ac01 | 4114 | Descends into invisible as well as visible topics, however. |
1977b8f6 | 4115 | |
75bcb912 | 4116 | When optional SANS-OFFSPRING is non-nil, subtopics are not |
c07583cd | 4117 | shifted. (Shifting a topic outwards without shifting its |
d8350998 CY |
4118 | offspring is disallowed, since this would create a \"containment |
4119 | discontinuity\", where the depth difference between a topic and | |
4120 | its immediate offspring is greater than one.) | |
4121 | ||
c567ac01 | 4122 | With repeat count, shift topic depth by that amount." |
1977b8f6 | 4123 | (interactive "P") |
96b83743 | 4124 | (let ((start-col (current-column))) |
1977b8f6 RS |
4125 | (save-excursion |
4126 | ;; Normalize arg: | |
4127 | (cond ((null arg) (setq arg 0)) | |
4128 | ((listp arg) (setq arg (car arg)))) | |
4129 | ;; Fill the user in, in case we're shifting a big topic: | |
4130 | (if (not (zerop arg)) (message "Shifting...")) | |
fd5359c6 | 4131 | (allout-back-to-current-heading) |
d8350998 | 4132 | (if (<= (+ allout-recent-depth arg) 0) |
1977b8f6 | 4133 | (error "Attempt to shift topic below level 1")) |
d8350998 | 4134 | (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring) |
1977b8f6 | 4135 | (if (not (zerop arg)) (message "Shifting... done."))) |
c567ac01 | 4136 | (move-to-column (max 0 (+ start-col arg))))) |
d8350998 | 4137 | ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...) |
fd5359c6 | 4138 | (defun allout-rebullet-topic-grunt (&optional relative-depth |
1977b8f6 RS |
4139 | starting-depth |
4140 | starting-point | |
4141 | index | |
d8350998 CY |
4142 | do-successors |
4143 | sans-offspring) | |
d82979ea EZ |
4144 | "Like `allout-rebullet-topic', but on nearest containing topic |
4145 | \(visible or not). | |
1977b8f6 | 4146 | |
d82979ea | 4147 | See `allout-rebullet-heading' for rebulleting behavior. |
1977b8f6 | 4148 | |
d82979ea | 4149 | All arguments are optional. |
1977b8f6 | 4150 | |
d82979ea EZ |
4151 | First arg RELATIVE-DEPTH means to shift the depth of the entire |
4152 | topic that amount. | |
e126900f | 4153 | |
d8350998 CY |
4154 | Several subsequent args are for internal recursive use by the function |
4155 | itself: STARTING-DEPTH, STARTING-POINT, and INDEX. | |
4156 | ||
4157 | Finally, if optional SANS-OFFSPRING is non-nil then the offspring | |
c07583cd | 4158 | are not shifted. (Shifting a topic outwards without shifting |
d8350998 CY |
4159 | its offspring is disallowed, since this would create a |
4160 | \"containment discontinuity\", where the depth difference between | |
75bcb912 | 4161 | a topic and its immediate offspring is greater than one.)" |
d8350998 CY |
4162 | |
4163 | ;; XXX the recursion here is peculiar, and in general the routine may | |
4164 | ;; need simplification with refactoring. | |
4165 | ||
4166 | (if (and sans-offspring | |
4167 | relative-depth | |
4168 | (< relative-depth 0)) | |
4169 | (error (concat "Attempt to shift topic outwards without offspring," | |
4170 | " would cause containment discontinuity."))) | |
1977b8f6 RS |
4171 | |
4172 | (let* ((relative-depth (or relative-depth 0)) | |
fd5359c6 | 4173 | (new-depth (allout-depth)) |
1977b8f6 RS |
4174 | (starting-depth (or starting-depth new-depth)) |
4175 | (on-starting-call (null starting-point)) | |
4176 | (index (or index | |
4177 | ;; Leave index null on starting call, so rebullet-heading | |
4178 | ;; calculates it at what might be new depth: | |
4179 | (and (or (zerop relative-depth) | |
4180 | (not on-starting-call)) | |
fd5359c6 | 4181 | (allout-sibling-index)))) |
d8350998 | 4182 | (starting-index index) |
1977b8f6 | 4183 | (moving-outwards (< 0 relative-depth)) |
d8350998 CY |
4184 | (starting-point (or starting-point (point))) |
4185 | (local-point (point))) | |
1977b8f6 RS |
4186 | |
4187 | ;; Sanity check for excessive promotion done only on starting call: | |
4188 | (and on-starting-call | |
4189 | moving-outwards | |
4190 | (> 0 (+ starting-depth relative-depth)) | |
d8350998 | 4191 | (error "Attempt to shift topic out beyond level 1")) |
1977b8f6 RS |
4192 | |
4193 | (cond ((= starting-depth new-depth) | |
d8350998 CY |
4194 | ;; We're at depth to work on this one. |
4195 | ||
4196 | ;; When shifting out we work on the children before working on | |
4197 | ;; the parent to avoid interim `allout-aberrant-container-p' | |
4198 | ;; aberrancy, and vice-versa when shifting in: | |
4199 | (if (>= relative-depth 0) | |
4200 | (allout-rebullet-heading nil | |
4201 | (+ starting-depth relative-depth) | |
4202 | nil ;;; number | |
4203 | index | |
4204 | nil)) ;;; do-successors | |
4205 | (when (not sans-offspring) | |
4206 | ;; ... and work on subsequent ones which are at greater depth: | |
4207 | (setq index 0) | |
4208 | (allout-next-heading) | |
4209 | (while (and (not (eobp)) | |
4210 | (< starting-depth (allout-depth))) | |
4211 | (setq index (1+ index)) | |
4212 | (allout-rebullet-topic-grunt relative-depth | |
4213 | (1+ starting-depth) | |
4214 | starting-point | |
4215 | index))) | |
4216 | (when (< relative-depth 0) | |
4217 | (save-excursion | |
4218 | (goto-char local-point) | |
b6a5875b | 4219 | (allout-rebullet-heading nil ;;; instead |
d8350998 CY |
4220 | (+ starting-depth relative-depth) |
4221 | nil ;;; number | |
4222 | starting-index | |
4223 | nil)))) ;;; do-successors | |
1977b8f6 RS |
4224 | |
4225 | ((< starting-depth new-depth) | |
60c7bbd2 | 4226 | ;; Rare case -- subtopic more than one level deeper than parent. |
1977b8f6 | 4227 | ;; Treat this one at an even deeper level: |
d8350998 CY |
4228 | (allout-rebullet-topic-grunt relative-depth |
4229 | new-depth | |
4230 | starting-point | |
4231 | index | |
4232 | sans-offspring))) | |
1977b8f6 RS |
4233 | |
4234 | (if on-starting-call | |
4235 | (progn | |
4236 | ;; Rectify numbering of former siblings of the adjusted topic, | |
4237 | ;; if topic has changed depth | |
4238 | (if (or do-successors | |
4239 | (and (not (zerop relative-depth)) | |
d8350998 CY |
4240 | (or (= allout-recent-depth starting-depth) |
4241 | (= allout-recent-depth (+ starting-depth | |
1977b8f6 | 4242 | relative-depth))))) |
fd5359c6 | 4243 | (allout-rebullet-heading nil nil nil nil t)) |
1977b8f6 RS |
4244 | ;; Now rectify numbering of new siblings of the adjusted topic, |
4245 | ;; if depth has been changed: | |
4246 | (progn (goto-char starting-point) | |
4247 | (if (not (zerop relative-depth)) | |
fd5359c6 | 4248 | (allout-rebullet-heading nil nil nil nil t))))) |
1977b8f6 RS |
4249 | ) |
4250 | ) | |
fd5359c6 MR |
4251 | ;;;_ > allout-renumber-to-depth (&optional depth) |
4252 | (defun allout-renumber-to-depth (&optional depth) | |
19b84ba3 RS |
4253 | "Renumber siblings at current depth. |
4254 | ||
4255 | Affects superior topics if optional arg DEPTH is less than current depth. | |
c567ac01 RS |
4256 | |
4257 | Returns final depth." | |
4258 | ||
4259 | ;; Proceed by level, processing subsequent siblings on each, | |
4260 | ;; ascending until we get shallower than the start depth: | |
4261 | ||
fd5359c6 | 4262 | (let ((ascender (allout-depth)) |
9179616f | 4263 | was-eobp) |
c567ac01 | 4264 | (while (and (not (eobp)) |
fd5359c6 | 4265 | (allout-depth) |
d8350998 | 4266 | (>= allout-recent-depth depth) |
c567ac01 RS |
4267 | (>= ascender depth)) |
4268 | ; Skip over all topics at | |
4269 | ; lesser depths, which can not | |
4270 | ; have been disturbed: | |
9179616f | 4271 | (while (and (not (setq was-eobp (eobp))) |
d8350998 | 4272 | (> allout-recent-depth ascender)) |
fd5359c6 | 4273 | (allout-next-heading)) |
c567ac01 | 4274 | ; Prime ascender for ascension: |
d8350998 CY |
4275 | (setq ascender (1- allout-recent-depth)) |
4276 | (if (>= allout-recent-depth depth) | |
b6a5875b | 4277 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4278 | nil ;;; depth |
4279 | nil ;;; number-control | |
4280 | nil ;;; index | |
9179616f DL |
4281 | t)) ;;; do-successors |
4282 | (if was-eobp (goto-char (point-max))))) | |
d8350998 | 4283 | allout-recent-depth) |
fd5359c6 MR |
4284 | ;;;_ > allout-number-siblings (&optional denumber) |
4285 | (defun allout-number-siblings (&optional denumber) | |
c567ac01 | 4286 | "Assign numbered topic prefix to this topic and its siblings. |
1977b8f6 | 4287 | |
60c7bbd2 | 4288 | With universal argument, denumber -- assign default bullet to this |
c567ac01 | 4289 | topic and its siblings. |
1977b8f6 | 4290 | |
c567ac01 RS |
4291 | With repeated universal argument (`^U^U'), solicit bullet for each |
4292 | rebulleting each topic at this level." | |
1977b8f6 RS |
4293 | |
4294 | (interactive "P") | |
4295 | ||
4296 | (save-excursion | |
fd5359c6 MR |
4297 | (allout-back-to-current-heading) |
4298 | (allout-beginning-of-level) | |
d8350998 | 4299 | (let ((depth allout-recent-depth) |
c567ac01 | 4300 | (index (if (not denumber) 1)) |
1977b8f6 RS |
4301 | (use-bullet (equal '(16) denumber)) |
4302 | (more t)) | |
4303 | (while more | |
b6a5875b | 4304 | (allout-rebullet-heading use-bullet ;;; instead |
c567ac01 | 4305 | depth ;;; depth |
1977b8f6 RS |
4306 | t ;;; number-control |
4307 | index ;;; index | |
4308 | nil) ;;; do-successors | |
4309 | (if index (setq index (1+ index))) | |
fd5359c6 MR |
4310 | (setq more (allout-next-sibling depth nil)))))) |
4311 | ;;;_ > allout-shift-in (arg) | |
4312 | (defun allout-shift-in (arg) | |
d8350998 CY |
4313 | "Increase depth of current heading and any items collapsed within it. |
4314 | ||
4315 | With a negative argument, the item is shifted out using | |
4316 | `allout-shift-out', instead. | |
4317 | ||
4318 | With an argument greater than one, shift-in the item but not its | |
4319 | offspring, making the item into a sibling of its former children, | |
97610156 | 4320 | and a child of sibling that formerly preceded it. |
d8350998 CY |
4321 | |
4322 | You are not allowed to shift the first offspring of a topic | |
4323 | inwards, because that would yield a \"containment | |
4324 | discontinuity\", where the depth difference between a topic and | |
4325 | its immediate offspring is greater than one. The first topic in | |
4326 | the file can be adjusted to any positive depth, however." | |
d82979ea | 4327 | |
1977b8f6 | 4328 | (interactive "p") |
d8350998 CY |
4329 | (if (< arg 0) |
4330 | (allout-shift-out (* arg -1)) | |
4331 | ;; refuse to create a containment discontinuity: | |
4332 | (save-excursion | |
4333 | (allout-back-to-current-heading) | |
4334 | (if (not (bobp)) | |
4335 | (let* ((current-depth allout-recent-depth) | |
4336 | (start-point (point)) | |
4337 | (predecessor-depth (progn | |
4338 | (forward-char -1) | |
4339 | (allout-goto-prefix-doublechecked) | |
4340 | (if (< (point) start-point) | |
4341 | allout-recent-depth | |
4342 | 0)))) | |
4343 | (if (and (> predecessor-depth 0) | |
4344 | (> (1+ current-depth) | |
4345 | (1+ predecessor-depth))) | |
4346 | (error (concat "Disallowed shift deeper than" | |
498a6493 CY |
4347 | " containing topic's children.")) |
4348 | (allout-back-to-current-heading) | |
4349 | (if (< allout-recent-depth (1+ current-depth)) | |
4350 | (allout-show-children)))))) | |
d8350998 CY |
4351 | (let ((where (point))) |
4352 | (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring)) | |
7b97c764 | 4353 | (run-hook-with-args 'allout-structure-shifted-functions arg where)))) |
fd5359c6 MR |
4354 | ;;;_ > allout-shift-out (arg) |
4355 | (defun allout-shift-out (arg) | |
d82979ea | 4356 | "Decrease depth of current heading and any topics collapsed within it. |
d8350998 CY |
4357 | This will make the item a sibling of its former container. |
4358 | ||
4359 | With a negative argument, the item is shifted in using | |
4360 | `allout-shift-in', instead. | |
4361 | ||
4362 | With an argument greater than one, shift-out the item's offspring | |
4363 | but not the item itself, making the former children siblings of | |
4364 | the item. | |
d82979ea | 4365 | |
d8350998 CY |
4366 | With an argument greater than 1, the item's offspring are shifted |
4367 | out without shifting the item. This will make the immediate | |
4368 | subtopics into siblings of the item." | |
1977b8f6 | 4369 | (interactive "p") |
d8350998 CY |
4370 | (if (< arg 0) |
4371 | (allout-shift-in (* arg -1)) | |
4372 | ;; Get proper exposure in this area: | |
4373 | (save-excursion (if (allout-ascend) | |
4374 | (allout-show-children))) | |
4375 | ;; Show collapsed children if there's a successor which will become | |
4376 | ;; their sibling: | |
4377 | (if (and (allout-current-topic-collapsed-p) | |
4378 | (save-excursion (allout-next-sibling))) | |
4379 | (allout-show-children)) | |
4380 | (let ((where (and (allout-depth) allout-recent-prefix-beginning))) | |
4381 | (save-excursion | |
4382 | (if (> arg 1) | |
4383 | ;; Shift the offspring but not the topic: | |
4384 | (let ((children-chart (allout-chart-subtree 1))) | |
4385 | (if (listp (car children-chart)) | |
4386 | ;; whoops: | |
4387 | (setq children-chart (allout-flatten children-chart))) | |
4388 | (save-excursion | |
4389 | (dolist (child-point children-chart) | |
4390 | (goto-char child-point) | |
4391 | (allout-shift-out 1)))) | |
4392 | (allout-rebullet-topic (* arg -1)))) | |
7b97c764 | 4393 | (run-hook-with-args 'allout-structure-shifted-functions (* arg -1) where)))) |
c567ac01 | 4394 | ;;;_ : Surgery (kill-ring) functions with special provisions for outlines: |
fd5359c6 MR |
4395 | ;;;_ > allout-kill-line (&optional arg) |
4396 | (defun allout-kill-line (&optional arg) | |
c567ac01 | 4397 | "Kill line, adjusting subsequent lines suitably for outline mode." |
1977b8f6 RS |
4398 | |
4399 | (interactive "*P") | |
d82979ea | 4400 | |
96b83743 EZ |
4401 | (if (or (not (allout-mode-p)) |
4402 | (not (bolp)) | |
2a1408fd | 4403 | (not (save-match-data (looking-at allout-regexp)))) |
4034b0e2 | 4404 | ;; Just do a regular kill: |
96b83743 EZ |
4405 | (kill-line arg) |
4406 | ;; Ah, have to watch out for adjustments: | |
4407 | (let* ((beg (point)) | |
d8350998 | 4408 | end |
96b83743 EZ |
4409 | (beg-hidden (allout-hidden-p)) |
4410 | (end-hidden (save-excursion (allout-end-of-current-line) | |
d8350998 | 4411 | (setq end (point)) |
96b83743 | 4412 | (allout-hidden-p))) |
d8350998 | 4413 | (depth (allout-depth))) |
96b83743 | 4414 | |
d8350998 | 4415 | (allout-annotate-hidden beg end) |
4ec28e14 KM |
4416 | (unwind-protect |
4417 | (if (and (not beg-hidden) (not end-hidden)) | |
4418 | (allout-unprotected (kill-line arg)) | |
4419 | (kill-line arg)) | |
11c46e15 | 4420 | (run-hooks 'allout-after-copy-or-kill-hook) |
4ec28e14 KM |
4421 | (allout-deannotate-hidden beg end) |
4422 | ||
4423 | (if allout-numbered-bullet | |
4424 | (save-excursion ; Renumber subsequent topics if needed: | |
4425 | (if (not (save-match-data (looking-at allout-regexp))) | |
4426 | (allout-next-heading)) | |
4427 | (allout-renumber-to-depth depth))) | |
7b97c764 | 4428 | (run-hook-with-args 'allout-structure-deleted-functions depth (point)))))) |
1b4d97b2 CY |
4429 | ;;;_ > allout-copy-line-as-kill () |
4430 | (defun allout-copy-line-as-kill () | |
20db1522 | 4431 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4432 | (interactive) |
4433 | (let ((buffer-read-only t)) | |
4434 | (condition-case nil | |
4435 | (allout-kill-line) | |
4436 | (buffer-read-only nil)))) | |
fd5359c6 MR |
4437 | ;;;_ > allout-kill-topic () |
4438 | (defun allout-kill-topic () | |
c567ac01 RS |
4439 | "Kill topic together with subtopics. |
4440 | ||
96b83743 EZ |
4441 | Trailing whitespace is killed with a topic if that whitespace: |
4442 | ||
4443 | - would separate the topic from a subsequent sibling | |
4444 | - would separate the topic from the end of buffer | |
4445 | - would not be added to whitespace already separating the topic from the | |
4446 | previous one. | |
4447 | ||
d8350998 | 4448 | Topic exposure is marked with text-properties, to be used by |
75bcb912 | 4449 | `allout-yank-processing' for exposure recovery." |
1977b8f6 RS |
4450 | |
4451 | (interactive) | |
0458fa80 | 4452 | (let* ((inhibit-field-text-motion t) |
96b83743 | 4453 | (beg (prog1 (allout-back-to-current-heading) (beginning-of-line))) |
ede4ac6a | 4454 | end |
d8350998 | 4455 | (depth allout-recent-depth)) |
fd5359c6 | 4456 | (allout-end-of-current-subtree) |
96b83743 EZ |
4457 | (if (and (/= (current-column) 0) (not (eobp))) |
4458 | (forward-char 1)) | |
1977b8f6 | 4459 | (if (not (eobp)) |
2a1408fd | 4460 | (if (and (save-match-data (looking-at "\n")) |
96b83743 EZ |
4461 | (or (save-excursion |
4462 | (or (not (allout-next-heading)) | |
d8350998 | 4463 | (= depth allout-recent-depth))) |
96b83743 EZ |
4464 | (and (> (- beg (point-min)) 3) |
4465 | (string= (buffer-substring (- beg 2) beg) "\n\n")))) | |
c567ac01 | 4466 | (forward-char 1))) |
353e2ef2 | 4467 | |
ede4ac6a | 4468 | (allout-annotate-hidden beg (setq end (point))) |
4ec28e14 | 4469 | (unwind-protect ; for possible barf-if-buffer-read-only. |
ede4ac6a | 4470 | (allout-unprotected (kill-region beg end)) |
4ec28e14 | 4471 | (allout-deannotate-hidden beg end) |
11c46e15 | 4472 | (run-hooks 'allout-after-copy-or-kill-hook) |
d8350998 | 4473 | |
4ec28e14 KM |
4474 | (save-excursion |
4475 | (allout-renumber-to-depth depth)) | |
7b97c764 | 4476 | (run-hook-with-args 'allout-structure-deleted-functions depth (point))))) |
1b4d97b2 CY |
4477 | ;;;_ > allout-copy-topic-as-kill () |
4478 | (defun allout-copy-topic-as-kill () | |
75bcb912 | 4479 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4480 | (interactive) |
4481 | (let ((buffer-read-only t)) | |
4482 | (condition-case nil | |
4483 | (allout-kill-topic) | |
4484 | (buffer-read-only (message "Topic copied..."))))) | |
d8350998 CY |
4485 | ;;;_ > allout-annotate-hidden (begin end) |
4486 | (defun allout-annotate-hidden (begin end) | |
4487 | "Qualify text with properties to indicate exposure status." | |
4488 | ||
1b4d97b2 CY |
4489 | (let ((was-modified (buffer-modified-p)) |
4490 | (buffer-read-only nil)) | |
ede4ac6a | 4491 | (allout-deannotate-hidden begin end) |
d8350998 CY |
4492 | (save-excursion |
4493 | (goto-char begin) | |
4494 | (let (done next prev overlay) | |
4495 | (while (not done) | |
4496 | ;; at or advance to start of next hidden region: | |
4497 | (if (not (allout-hidden-p)) | |
4498 | (setq next | |
1b4d97b2 | 4499 | (max (1+ (point)) |
1c9b9df0 KM |
4500 | (allout-next-single-char-property-change (point) |
4501 | 'invisible | |
4502 | nil end)))) | |
d8350998 | 4503 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4504 | ;; still not at start of hidden area -- must not be any left. |
d8350998 CY |
4505 | (setq done t) |
4506 | (goto-char next) | |
4507 | (setq prev next) | |
4508 | (if (not (allout-hidden-p)) | |
4509 | ;; still not at start of hidden area. | |
4510 | (setq done t) | |
4511 | (setq overlay (allout-get-invisibility-overlay)) | |
4512 | (setq next (overlay-end overlay) | |
4513 | prev next) | |
4514 | ;; advance to end of this hidden area: | |
4515 | (when next | |
4516 | (goto-char next) | |
4517 | (allout-unprotected | |
ede4ac6a KS |
4518 | (let ((buffer-undo-list t)) |
4519 | (put-text-property (overlay-start overlay) next | |
4520 | 'allout-was-hidden t))))))))) | |
d8350998 | 4521 | (set-buffer-modified-p was-modified))) |
ede4ac6a KS |
4522 | ;;;_ > allout-deannotate-hidden (begin end) |
4523 | (defun allout-deannotate-hidden (begin end) | |
4524 | "Remove allout hidden-text annotation between BEGIN and END." | |
4525 | ||
4526 | (allout-unprotected | |
4527 | (let ((inhibit-read-only t) | |
4528 | (buffer-undo-list t)) | |
11c46e15 KM |
4529 | (remove-text-properties begin (min end (point-max)) |
4530 | '(allout-was-hidden t))))) | |
d8350998 CY |
4531 | ;;;_ > allout-hide-by-annotation (begin end) |
4532 | (defun allout-hide-by-annotation (begin end) | |
4533 | "Translate text properties indicating exposure status into actual exposure." | |
4534 | (save-excursion | |
4535 | (goto-char begin) | |
4536 | (let ((was-modified (buffer-modified-p)) | |
4537 | done next prev) | |
4538 | (while (not done) | |
4539 | ;; at or advance to start of next annotation: | |
4540 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
1c9b9df0 KM |
4541 | (setq next (allout-next-single-char-property-change |
4542 | (point) 'allout-was-hidden nil end))) | |
d8350998 | 4543 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4544 | ;; no more or not advancing -- must not be any left. |
d8350998 CY |
4545 | (setq done t) |
4546 | (goto-char next) | |
4547 | (setq prev next) | |
4548 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
4549 | ;; still not at start of annotation. | |
4550 | (setq done t) | |
4551 | ;; advance to just after end of this annotation: | |
1c9b9df0 KM |
4552 | (setq next (allout-next-single-char-property-change |
4553 | (point) 'allout-was-hidden nil end)) | |
d806ab68 KM |
4554 | (let ((o (make-overlay prev next nil 'front-advance))) |
4555 | (overlay-put o 'category 'allout-exposure-category) | |
4556 | (overlay-put o 'evaporate t)) | |
ede4ac6a | 4557 | (allout-deannotate-hidden prev next) |
d8350998 CY |
4558 | (setq prev next) |
4559 | (if next (goto-char next))))) | |
4560 | (set-buffer-modified-p was-modified)))) | |
fd5359c6 MR |
4561 | ;;;_ > allout-yank-processing () |
4562 | (defun allout-yank-processing (&optional arg) | |
c567ac01 | 4563 | |
96b83743 | 4564 | "Incidental allout-specific business to be done just after text yanks. |
19b84ba3 | 4565 | |
c567ac01 | 4566 | Does depth adjustment of yanked topics, when: |
1977b8f6 | 4567 | |
c567ac01 RS |
4568 | 1 the stuff being yanked starts with a valid outline header prefix, and |
4569 | 2 it is being yanked at the end of a line which consists of only a valid | |
1977b8f6 RS |
4570 | topic prefix. |
4571 | ||
a0776d6b | 4572 | Also, adjusts numbering of subsequent siblings when appropriate. |
1977b8f6 | 4573 | |
c567ac01 RS |
4574 | Depth adjustment alters the depth of all the topics being yanked |
4575 | the amount it takes to make the first topic have the depth of the | |
4576 | header into which it's being yanked. | |
1977b8f6 | 4577 | |
c567ac01 RS |
4578 | The point is left in front of yanked, adjusted topics, rather than |
4579 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
d82979ea | 4580 | however, are left exactly like normal, non-allout-specific yanks." |
c567ac01 RS |
4581 | |
4582 | (interactive "*P") | |
4583 | ; Get to beginning, leaving | |
4584 | ; region around subject: | |
96b83743 | 4585 | (if (< (allout-mark-marker t) (point)) |
c567ac01 | 4586 | (exchange-point-and-mark)) |
2a1408fd DN |
4587 | (save-match-data |
4588 | (let* ((subj-beg (point)) | |
4589 | (into-bol (bolp)) | |
4590 | (subj-end (allout-mark-marker t)) | |
4591 | ;; 'resituate' if yanking an entire topic into topic header: | |
4592 | (resituate (and (let ((allout-inhibit-aberrance-doublecheck t)) | |
4593 | (allout-e-o-prefix-p)) | |
4594 | (looking-at allout-regexp) | |
4595 | (allout-prefix-data))) | |
4596 | ;; `rectify-numbering' if resituating (where several topics may | |
4597 | ;; be resituating) or yanking a topic into a topic slot (bol): | |
4598 | (rectify-numbering (or resituate | |
8dd59f01 | 4599 | (and into-bol (looking-at allout-regexp))))) |
2a1408fd | 4600 | (if resituate |
8dd59f01 | 4601 | ;; Yanking a topic into the start of a topic -- reconcile to fit: |
2a1408fd DN |
4602 | (let* ((inhibit-field-text-motion t) |
4603 | (prefix-len (if (not (match-end 1)) | |
4604 | 1 | |
4605 | (- (match-end 1) subj-beg))) | |
4606 | (subj-depth allout-recent-depth) | |
4607 | (prefix-bullet (allout-recent-bullet)) | |
4608 | (adjust-to-depth | |
4609 | ;; Nil if adjustment unnecessary, otherwise depth to which | |
4610 | ;; adjustment should be made: | |
4611 | (save-excursion | |
4612 | (and (goto-char subj-end) | |
4613 | (eolp) | |
4614 | (goto-char subj-beg) | |
4615 | (and (looking-at allout-regexp) | |
4616 | (progn | |
4617 | (beginning-of-line) | |
4618 | (not (= (point) subj-beg))) | |
4619 | (looking-at allout-regexp) | |
4620 | (allout-prefix-data)) | |
4621 | allout-recent-depth))) | |
4622 | (more t)) | |
4623 | (setq rectify-numbering allout-numbered-bullet) | |
4624 | (if adjust-to-depth | |
c567ac01 | 4625 | ; Do the adjustment: |
2a1408fd DN |
4626 | (progn |
4627 | (save-restriction | |
4628 | (narrow-to-region subj-beg subj-end) | |
c567ac01 RS |
4629 | ; Trim off excessive blank |
4630 | ; line at end, if any: | |
2a1408fd DN |
4631 | (goto-char (point-max)) |
4632 | (if (looking-at "^$") | |
4633 | (allout-unprotected (delete-char -1))) | |
c567ac01 RS |
4634 | ; Work backwards, with each |
4635 | ; shallowest level, | |
4636 | ; successively excluding the | |
4637 | ; last processed topic from | |
4638 | ; the narrow region: | |
2a1408fd DN |
4639 | (while more |
4640 | (allout-back-to-current-heading) | |
c567ac01 | 4641 | ; go as high as we can in each bunch: |
2a1408fd DN |
4642 | (while (allout-ascend t)) |
4643 | (save-excursion | |
4644 | (allout-unprotected | |
4645 | (allout-rebullet-topic-grunt (- adjust-to-depth | |
4646 | subj-depth))) | |
4647 | (allout-depth)) | |
4648 | (if (setq more (not (bobp))) | |
4649 | (progn (widen) | |
4650 | (forward-char -1) | |
4651 | (narrow-to-region subj-beg (point)))))) | |
b6a5875b KM |
4652 | ;; Remove new heading prefix: |
4653 | (allout-unprotected | |
4654 | (progn | |
4655 | (delete-region (point) (+ (point) | |
4656 | prefix-len | |
4657 | (- adjust-to-depth | |
4658 | subj-depth))) | |
c567ac01 RS |
4659 | ; and delete residual subj |
4660 | ; prefix digits and space: | |
b6a5875b | 4661 | (while (looking-at "[0-9]") (delete-char 1)) |
e47ca23b KM |
4662 | (delete-char -1) |
4663 | (if (not (eolp)) | |
4664 | (forward-char)))) | |
b6a5875b | 4665 | ;; Assert new topic's bullet - minimal effort if unchanged: |
b0911414 | 4666 | (allout-rebullet-heading (string-to-char prefix-bullet))) |
2a1408fd DN |
4667 | (exchange-point-and-mark)))) |
4668 | (if rectify-numbering | |
4669 | (progn | |
4670 | (save-excursion | |
c567ac01 | 4671 | ; Give some preliminary feedback: |
2a1408fd | 4672 | (message "... reconciling numbers") |
c567ac01 | 4673 | ; ... and renumber, in case necessary: |
2a1408fd DN |
4674 | (goto-char subj-beg) |
4675 | (if (allout-goto-prefix-doublechecked) | |
4676 | (allout-unprotected | |
b6a5875b | 4677 | (allout-rebullet-heading nil ;;; instead |
2a1408fd DN |
4678 | (allout-depth) ;;; depth |
4679 | nil ;;; number-control | |
4680 | nil ;;; index | |
4681 | t))) | |
4682 | (message "")))) | |
4683 | (if (or into-bol resituate) | |
4684 | (allout-hide-by-annotation (point) (allout-mark-marker t)) | |
4685 | (allout-deannotate-hidden (allout-mark-marker t) (point))) | |
4686 | (if (not resituate) | |
4687 | (exchange-point-and-mark)) | |
7b97c764 | 4688 | (run-hook-with-args 'allout-structure-added-functions subj-beg subj-end)))) |
fd5359c6 MR |
4689 | ;;;_ > allout-yank (&optional arg) |
4690 | (defun allout-yank (&optional arg) | |
aad94676 | 4691 | "`allout-mode' yank, with depth and numbering adjustment of yanked topics. |
19b84ba3 | 4692 | |
a0776d6b | 4693 | Non-topic yanks work no differently than normal yanks. |
c567ac01 RS |
4694 | |
4695 | If a topic is being yanked into a bare topic prefix, the depth of the | |
4696 | yanked topic is adjusted to the depth of the topic prefix. | |
4697 | ||
2265e017 | 4698 | 1 we're yanking in an `allout-mode' buffer |
c567ac01 RS |
4699 | 2 the stuff being yanked starts with a valid outline header prefix, and |
4700 | 3 it is being yanked at the end of a line which consists of only a valid | |
4701 | topic prefix. | |
4702 | ||
4703 | If these conditions hold then the depth of the yanked topics are all | |
4704 | adjusted the amount it takes to make the first one at the depth of the | |
4705 | header into which it's being yanked. | |
4706 | ||
4707 | The point is left in front of yanked, adjusted topics, rather than | |
4708 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
4709 | however, (ones that don't qualify for adjustment) are handled | |
4710 | exactly like normal yanks. | |
4711 | ||
a0776d6b | 4712 | Numbering of yanked topics, and the successive siblings at the depth |
c567ac01 RS |
4713 | into which they're being yanked, is adjusted. |
4714 | ||
539d7736 JB |
4715 | `allout-yank-pop' works with `allout-yank' just like normal `yank-pop' |
4716 | works with normal `yank' in non-outline buffers." | |
1977b8f6 RS |
4717 | |
4718 | (interactive "*P") | |
4719 | (setq this-command 'yank) | |
48bd8440 EZ |
4720 | (allout-unprotected |
4721 | (yank arg)) | |
fd5359c6 | 4722 | (if (allout-mode-p) |
48bd8440 | 4723 | (allout-yank-processing))) |
fd5359c6 MR |
4724 | ;;;_ > allout-yank-pop (&optional arg) |
4725 | (defun allout-yank-pop (&optional arg) | |
2265e017 | 4726 | "Yank-pop like `allout-yank' when popping to bare outline prefixes. |
19b84ba3 RS |
4727 | |
4728 | Adapts level of popped topics to level of fresh prefix. | |
c567ac01 | 4729 | |
60c7bbd2 | 4730 | Note -- prefix changes to distinctive bullets will stick, if followed |
c567ac01 | 4731 | by pops to non-distinctive yanks. Bug..." |
1977b8f6 RS |
4732 | |
4733 | (interactive "*p") | |
1977b8f6 | 4734 | (setq this-command 'yank) |
c567ac01 | 4735 | (yank-pop arg) |
fd5359c6 MR |
4736 | (if (allout-mode-p) |
4737 | (allout-yank-processing))) | |
1977b8f6 | 4738 | |
c567ac01 RS |
4739 | ;;;_ - Specialty bullet functions |
4740 | ;;;_ : File Cross references | |
fd5359c6 MR |
4741 | ;;;_ > allout-resolve-xref () |
4742 | (defun allout-resolve-xref () | |
19b84ba3 RS |
4743 | "Pop to file associated with current heading, if it has an xref bullet. |
4744 | ||
fd5359c6 | 4745 | \(Works according to setting of `allout-file-xref-bullet')." |
1977b8f6 | 4746 | (interactive) |
fd5359c6 | 4747 | (if (not allout-file-xref-bullet) |
1977b8f6 | 4748 | (error |
60c7bbd2 | 4749 | "Outline cross references disabled -- no `allout-file-xref-bullet'") |
fd5359c6 | 4750 | (if (not (string= (allout-current-bullet) allout-file-xref-bullet)) |
635ca796 | 4751 | (error "Current heading lacks cross-reference bullet `%s'" |
fd5359c6 | 4752 | allout-file-xref-bullet) |
0458fa80 EZ |
4753 | (let ((inhibit-field-text-motion t) |
4754 | file-name) | |
2a1408fd DN |
4755 | (save-match-data |
4756 | (save-excursion | |
4757 | (let* ((text-start allout-recent-prefix-end) | |
9b026d9f | 4758 | (heading-end (point-at-eol))) |
2a1408fd DN |
4759 | (goto-char text-start) |
4760 | (setq file-name | |
4761 | (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t) | |
4762 | (buffer-substring (match-beginning 1) | |
4763 | (match-end 1))))))) | |
69027dea | 4764 | (setq file-name (expand-file-name file-name)) |
1977b8f6 RS |
4765 | (if (or (file-exists-p file-name) |
4766 | (if (file-writable-p file-name) | |
4767 | (y-or-n-p (format "%s not there, create one? " | |
4768 | file-name)) | |
4769 | (error "%s not found and can't be created" file-name))) | |
4770 | (condition-case failure | |
4771 | (find-file-other-window file-name) | |
d8350998 | 4772 | (error failure)) |
1977b8f6 RS |
4773 | (error "%s not found" file-name)) |
4774 | ) | |
4775 | ) | |
4776 | ) | |
4777 | ) | |
19b84ba3 | 4778 | |
9179616f | 4779 | ;;;_ #6 Exposure Control |
c567ac01 RS |
4780 | |
4781 | ;;;_ - Fundamental | |
d82979ea EZ |
4782 | ;;;_ > allout-flag-region (from to flag) |
4783 | (defun allout-flag-region (from to flag) | |
48bd8440 | 4784 | "Conceal text between FROM and TO if FLAG is non-nil, else reveal it. |
7b97c764 CY |
4785 | After the exposure changes are made, run the abnormal hook |
4786 | `allout-exposure-change-functions' with the same arguments as | |
4787 | this function." | |
96b83743 | 4788 | |
96b83743 | 4789 | ;; We use outline invisibility spec. |
01fc9422 | 4790 | (remove-overlays from to 'category 'allout-exposure-category) |
96b83743 | 4791 | (when flag |
2a1408fd | 4792 | (let ((o (make-overlay from to nil 'front-advance))) |
01fc9422 | 4793 | (overlay-put o 'category 'allout-exposure-category) |
68ba37fb | 4794 | (overlay-put o 'evaporate t) |
96b83743 | 4795 | (when (featurep 'xemacs) |
01fc9422 | 4796 | (let ((props (symbol-plist 'allout-exposure-category))) |
96b83743 | 4797 | (while props |
1c9b9df0 KM |
4798 | (condition-case nil |
4799 | ;; as of 2008-02-27, xemacs lacks modification-hooks | |
4800 | (overlay-put o (pop props) (pop props)) | |
3f2b07f8 KM |
4801 | (error nil)))))) |
4802 | (setq allout-this-command-hid-text t)) | |
7b97c764 | 4803 | (run-hook-with-args 'allout-exposure-change-functions from to flag)) |
fd5359c6 MR |
4804 | ;;;_ > allout-flag-current-subtree (flag) |
4805 | (defun allout-flag-current-subtree (flag) | |
96b83743 | 4806 | "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it." |
19b84ba3 | 4807 | |
c567ac01 | 4808 | (save-excursion |
fd5359c6 | 4809 | (allout-back-to-current-heading) |
0458fa80 EZ |
4810 | (let ((inhibit-field-text-motion t)) |
4811 | (end-of-line)) | |
96b83743 EZ |
4812 | (allout-flag-region (point) |
4813 | ;; Exposing must not leave trailing blanks hidden, | |
4814 | ;; but can leave them exposed when hiding, so we | |
4815 | ;; can use flag's inverse as the | |
4816 | ;; include-trailing-blank cue: | |
4817 | (allout-end-of-current-subtree (not flag)) | |
4818 | flag))) | |
c567ac01 | 4819 | |
c567ac01 | 4820 | ;;;_ - Topic-specific |
01fc9422 EZ |
4821 | ;;;_ > allout-show-entry () |
4822 | (defun allout-show-entry () | |
4823 | "Like `allout-show-current-entry', but reveals entries in hidden topics. | |
c567ac01 RS |
4824 | |
4825 | This is a way to give restricted peek at a concealed locality without the | |
4826 | expense of exposing its context, but can leave the outline with aberrant | |
96b83743 EZ |
4827 | exposure. `allout-show-offshoot' should be used after the peek to rectify |
4828 | the exposure." | |
c567ac01 RS |
4829 | |
4830 | (interactive) | |
4831 | (save-excursion | |
96b83743 | 4832 | (let (beg end) |
d8350998 | 4833 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4834 | (setq beg (if (allout-hidden-p) (1- (point)) (point))) |
4835 | (setq end (allout-pre-next-prefix)) | |
4836 | (allout-flag-region beg end nil) | |
9179616f | 4837 | (list beg end)))) |
fd5359c6 MR |
4838 | ;;;_ > allout-show-children (&optional level strict) |
4839 | (defun allout-show-children (&optional level strict) | |
c567ac01 RS |
4840 | |
4841 | "If point is visible, show all direct subheadings of this heading. | |
19b84ba3 | 4842 | |
2265e017 | 4843 | Otherwise, do `allout-show-to-offshoot', and then show subheadings. |
c567ac01 RS |
4844 | |
4845 | Optional LEVEL specifies how many levels below the current level | |
4846 | should be shown, or all levels if t. Default is 1. | |
4847 | ||
4848 | Optional STRICT means don't resort to -show-to-offshoot, no matter | |
4849 | what. This is basically so -show-to-offshoot, which is called by | |
4850 | this function, can employ the pure offspring-revealing capabilities of | |
19b84ba3 RS |
4851 | it. |
4852 | ||
4853 | Returns point at end of subtree that was opened, if any. (May get a | |
4854 | point of non-opened subtree?)" | |
c567ac01 RS |
4855 | |
4856 | (interactive "p") | |
96b83743 | 4857 | (let ((start-point (point))) |
19b84ba3 | 4858 | (if (and (not strict) |
96b83743 | 4859 | (allout-hidden-p)) |
c567ac01 | 4860 | |
96b83743 EZ |
4861 | (progn (allout-show-to-offshoot) ; Point's concealed, open to |
4862 | ; expose it. | |
4863 | ;; Then recurse, but with "strict" set so we don't | |
4864 | ;; infinite regress: | |
4865 | (allout-show-children level t)) | |
c567ac01 | 4866 | |
19b84ba3 | 4867 | (save-excursion |
96b83743 EZ |
4868 | (allout-beginning-of-current-line) |
4869 | (save-restriction | |
d8350998 | 4870 | (let* (depth |
65e7eb3d EZ |
4871 | ;; translate the level spec for this routine to the ones |
4872 | ;; used by -chart-subtree and -chart-to-reveal: | |
4873 | (chart-level (cond ((not level) 1) | |
4874 | ((eq level t) nil) | |
4875 | (t level))) | |
4876 | (chart (allout-chart-subtree chart-level)) | |
4877 | (to-reveal (or (allout-chart-to-reveal chart chart-level) | |
d8350998 CY |
4878 | ;; interactive, show discontinuous children: |
4879 | (and chart | |
1c9b9df0 | 4880 | (allout-called-interactively-p) |
d8350998 CY |
4881 | (save-excursion |
4882 | (allout-back-to-current-heading) | |
4883 | (setq depth (allout-current-depth)) | |
4884 | (and (allout-next-heading) | |
4885 | (> allout-recent-depth | |
4886 | (1+ depth)))) | |
4887 | (message | |
4888 | "Discontinuous offspring; use `%s %s'%s." | |
4889 | (substitute-command-keys | |
4890 | "\\[universal-argument]") | |
4891 | (substitute-command-keys | |
4892 | "\\[allout-shift-out]") | |
4893 | " to elevate them.") | |
4894 | (allout-chart-to-reveal | |
4895 | chart (- allout-recent-depth depth)))))) | |
96b83743 EZ |
4896 | (goto-char start-point) |
4897 | (when (and strict (allout-hidden-p)) | |
4898 | ;; Concealed root would already have been taken care of, | |
4899 | ;; unless strict was set. | |
4900 | (allout-flag-region (point) (allout-snug-back) nil) | |
4901 | (when allout-show-bodies | |
4902 | (goto-char (car to-reveal)) | |
4903 | (allout-show-current-entry))) | |
4904 | (while to-reveal | |
4905 | (goto-char (car to-reveal)) | |
4906 | (allout-flag-region (save-excursion (allout-snug-back) (point)) | |
4907 | (progn (search-forward "\n" nil t) | |
4908 | (1- (point))) | |
4909 | nil) | |
4910 | (when allout-show-bodies | |
4911 | (goto-char (car to-reveal)) | |
4912 | (allout-show-current-entry)) | |
4913 | (setq to-reveal (cdr to-reveal))))))) | |
4914 | ;; Compensate for `save-excursion's maintenance of point | |
4915 | ;; within invisible text: | |
4916 | (goto-char start-point))) | |
fd5359c6 MR |
4917 | ;;;_ > allout-show-to-offshoot () |
4918 | (defun allout-show-to-offshoot () | |
2265e017 | 4919 | "Like `allout-show-entry', but reveals all concealed ancestors, as well. |
c567ac01 | 4920 | |
96b83743 | 4921 | Useful for coherently exposing to a random point in a hidden region." |
c567ac01 RS |
4922 | (interactive) |
4923 | (save-excursion | |
0458fa80 EZ |
4924 | (let ((inhibit-field-text-motion t) |
4925 | (orig-pt (point)) | |
d8350998 | 4926 | (orig-pref (allout-goto-prefix-doublechecked)) |
c567ac01 | 4927 | (last-at (point)) |
65e7eb3d EZ |
4928 | (bag-it 0)) |
4929 | (while (or (> bag-it 1) (allout-hidden-p)) | |
96b83743 | 4930 | (while (allout-hidden-p) |
d8350998 | 4931 | (move-beginning-of-line 1) |
96b83743 | 4932 | (if (allout-hidden-p) (forward-char -1))) |
c567ac01 | 4933 | (if (= last-at (setq last-at (point))) |
65e7eb3d EZ |
4934 | ;; Oops, we're not making any progress! Show the current topic |
4935 | ;; completely, and try one more time here, if we haven't already. | |
c567ac01 | 4936 | (progn (beginning-of-line) |
fd5359c6 | 4937 | (allout-show-current-subtree) |
c567ac01 | 4938 | (goto-char orig-pt) |
65e7eb3d EZ |
4939 | (setq bag-it (1+ bag-it)) |
4940 | (if (> bag-it 1) | |
4941 | (error "allout-show-to-offshoot: %s" | |
4942 | "Stumped by aberrant nesting."))) | |
4943 | (if (> bag-it 0) (setq bag-it 0)) | |
d8350998 CY |
4944 | (allout-show-children) |
4945 | (goto-char orig-pref))) | |
19b84ba3 | 4946 | (goto-char orig-pt))) |
fd5359c6 MR |
4947 | (if (allout-hidden-p) |
4948 | (allout-show-entry))) | |
4949 | ;;;_ > allout-hide-current-entry () | |
4950 | (defun allout-hide-current-entry () | |
c567ac01 RS |
4951 | "Hide the body directly following this heading." |
4952 | (interactive) | |
fd5359c6 | 4953 | (allout-back-to-current-heading) |
c567ac01 | 4954 | (save-excursion |
0458fa80 EZ |
4955 | (let ((inhibit-field-text-motion t)) |
4956 | (end-of-line)) | |
96b83743 | 4957 | (allout-flag-region (point) |
d82979ea | 4958 | (progn (allout-end-of-entry) (point)) |
96b83743 | 4959 | t))) |
fd5359c6 MR |
4960 | ;;;_ > allout-show-current-entry (&optional arg) |
4961 | (defun allout-show-current-entry (&optional arg) | |
96b83743 | 4962 | "Show body following current heading, or hide entry with universal argument." |
c567ac01 RS |
4963 | |
4964 | (interactive "P") | |
4965 | (if arg | |
fd5359c6 | 4966 | (allout-hide-current-entry) |
96b83743 | 4967 | (save-excursion (allout-show-to-offshoot)) |
c567ac01 | 4968 | (save-excursion |
fd5359c6 | 4969 | (allout-flag-region (point) |
96b83743 EZ |
4970 | (progn (allout-end-of-entry t) (point)) |
4971 | nil) | |
d82979ea | 4972 | ))) |
fd5359c6 MR |
4973 | ;;;_ > allout-show-current-subtree (&optional arg) |
4974 | (defun allout-show-current-subtree (&optional arg) | |
75bcb912 JB |
4975 | "Show everything within the current topic. |
4976 | With a repeat-count, expose this topic and its siblings." | |
19b84ba3 RS |
4977 | (interactive "P") |
4978 | (save-excursion | |
fd5359c6 | 4979 | (if (<= (allout-current-depth) 0) |
60c7bbd2 | 4980 | ;; Outside any topics -- try to get to the first: |
fd5359c6 | 4981 | (if (not (allout-next-heading)) |
6a05d05f | 4982 | (error "No topics") |
60c7bbd2 RS |
4983 | ;; got to first, outermost topic -- set to expose it and siblings: |
4984 | (message "Above outermost topic -- exposing all.") | |
96b83743 EZ |
4985 | (allout-flag-region (point-min)(point-max) nil)) |
4986 | (allout-beginning-of-current-line) | |
19b84ba3 | 4987 | (if (not arg) |
96b83743 | 4988 | (allout-flag-current-subtree nil) |
fd5359c6 MR |
4989 | (allout-beginning-of-level) |
4990 | (allout-expose-topic '(* :)))))) | |
96b83743 EZ |
4991 | ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners) |
4992 | (defun allout-current-topic-collapsed-p (&optional include-single-liners) | |
4993 | "True if the currently visible containing topic is already collapsed. | |
4994 | ||
64686e6d RS |
4995 | Single line topics intrinsically can be considered as being both |
4996 | collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is | |
4997 | true, then single-line topics are considered to be collapsed. By | |
4998 | default, they are treated as being uncollapsed." | |
2a1408fd DN |
4999 | (save-match-data |
5000 | (save-excursion | |
5001 | (and | |
5002 | ;; Is the topic all on one line (allowing for trailing blank line)? | |
5003 | (>= (progn (allout-back-to-current-heading) | |
82b392a4 KM |
5004 | (let ((inhibit-field-text-motion t)) |
5005 | (move-end-of-line 1)) | |
2a1408fd DN |
5006 | (point)) |
5007 | (allout-end-of-current-subtree (not (looking-at "\n\n")))) | |
5008 | ||
5009 | (or include-single-liners | |
5010 | (progn (backward-char 1) (allout-hidden-p))))))) | |
fd5359c6 MR |
5011 | ;;;_ > allout-hide-current-subtree (&optional just-close) |
5012 | (defun allout-hide-current-subtree (&optional just-close) | |
19b84ba3 | 5013 | "Close the current topic, or containing topic if this one is already closed. |
c567ac01 | 5014 | |
19b84ba3 | 5015 | If this topic is closed and it's a top level topic, close this topic |
353e2ef2 | 5016 | and its siblings. |
19b84ba3 | 5017 | |
96b83743 | 5018 | If optional arg JUST-CLOSE is non-nil, do not close the parent or |
19b84ba3 | 5019 | siblings, even if the target topic is already closed." |
c567ac01 RS |
5020 | |
5021 | (interactive) | |
96b83743 | 5022 | (let* ((from (point)) |
60c7bbd2 | 5023 | (sibs-msg "Top-level topic already closed -- closing siblings...") |
96b83743 EZ |
5024 | (current-exposed (not (allout-current-topic-collapsed-p t)))) |
5025 | (cond (current-exposed (allout-flag-current-subtree t)) | |
5026 | (just-close nil) | |
d8350998 | 5027 | ((allout-ascend) (allout-hide-current-subtree)) |
96b83743 EZ |
5028 | (t (goto-char 0) |
5029 | (message sibs-msg) | |
d8350998 | 5030 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
5031 | (allout-expose-topic '(0 :)) |
5032 | (message (concat sibs-msg " Done.")))) | |
5033 | (goto-char from))) | |
2a1408fd DN |
5034 | ;;;_ > allout-toggle-current-subtree-exposure |
5035 | (defun allout-toggle-current-subtree-exposure () | |
5036 | "Show or hide the current subtree depending on its current state." | |
5037 | ;; thanks to tassilo for suggesting this. | |
5038 | (interactive) | |
5039 | (save-excursion | |
5040 | (allout-back-to-heading) | |
5041 | (if (allout-hidden-p (point-at-eol)) | |
5042 | (allout-show-current-subtree) | |
5043 | (allout-hide-current-subtree)))) | |
fd5359c6 MR |
5044 | ;;;_ > allout-show-current-branches () |
5045 | (defun allout-show-current-branches () | |
c567ac01 RS |
5046 | "Show all subheadings of this heading, but not their bodies." |
5047 | (interactive) | |
0458fa80 EZ |
5048 | (let ((inhibit-field-text-motion t)) |
5049 | (beginning-of-line)) | |
fd5359c6 MR |
5050 | (allout-show-children t)) |
5051 | ;;;_ > allout-hide-current-leaves () | |
5052 | (defun allout-hide-current-leaves () | |
353e2ef2 | 5053 | "Hide the bodies of the current topic and all its offspring." |
c567ac01 | 5054 | (interactive) |
fd5359c6 MR |
5055 | (allout-back-to-current-heading) |
5056 | (allout-hide-region-body (point) (progn (allout-end-of-current-subtree) | |
c567ac01 RS |
5057 | (point)))) |
5058 | ||
5059 | ;;;_ - Region and beyond | |
fd5359c6 MR |
5060 | ;;;_ > allout-show-all () |
5061 | (defun allout-show-all () | |
c567ac01 RS |
5062 | "Show all of the text in the buffer." |
5063 | (interactive) | |
19b84ba3 | 5064 | (message "Exposing entire buffer...") |
96b83743 | 5065 | (allout-flag-region (point-min) (point-max) nil) |
19b84ba3 | 5066 | (message "Exposing entire buffer... Done.")) |
fd5359c6 MR |
5067 | ;;;_ > allout-hide-bodies () |
5068 | (defun allout-hide-bodies () | |
c567ac01 RS |
5069 | "Hide all of buffer except headings." |
5070 | (interactive) | |
fd5359c6 MR |
5071 | (allout-hide-region-body (point-min) (point-max))) |
5072 | ;;;_ > allout-hide-region-body (start end) | |
5073 | (defun allout-hide-region-body (start end) | |
c567ac01 | 5074 | "Hide all body lines in the region, but not headings." |
2a1408fd DN |
5075 | (save-match-data |
5076 | (save-excursion | |
5077 | (save-restriction | |
5078 | (narrow-to-region start end) | |
5079 | (goto-char (point-min)) | |
5080 | (let ((inhibit-field-text-motion t)) | |
5081 | (while (not (eobp)) | |
5082 | (end-of-line) | |
5083 | (allout-flag-region (point) (allout-end-of-entry) t) | |
5084 | (if (not (eobp)) | |
5085 | (forward-char | |
5086 | (if (looking-at "\n\n") | |
5087 | 2 1))))))))) | |
c567ac01 | 5088 | |
fd5359c6 MR |
5089 | ;;;_ > allout-expose-topic (spec) |
5090 | (defun allout-expose-topic (spec) | |
19b84ba3 | 5091 | "Apply exposure specs to successive outline topic items. |
c567ac01 | 5092 | |
fd5359c6 MR |
5093 | Use the more convenient frontend, `allout-new-exposure', if you don't |
5094 | need evaluation of the arguments, or even better, the `allout-layout' | |
19b84ba3 RS |
5095 | variable-keyed mode-activation/auto-exposure feature of allout outline |
5096 | mode. See the respective documentation strings for more details. | |
c567ac01 RS |
5097 | |
5098 | Cursor is left at start position. | |
5099 | ||
19b84ba3 RS |
5100 | SPEC is either a number or a list. |
5101 | ||
5102 | Successive specs on a list are applied to successive sibling topics. | |
c567ac01 | 5103 | |
c07583cd | 5104 | A simple spec (either a number, one of a few symbols, or the null |
19b84ba3 RS |
5105 | list) dictates the exposure for the corresponding topic. |
5106 | ||
5107 | Non-null lists recursively designate exposure specs for respective | |
5108 | subtopics of the current topic. | |
c567ac01 | 5109 | |
353e2ef2 | 5110 | The `:' repeat spec is used to specify exposure for any number of |
19b84ba3 | 5111 | successive siblings, up to the trailing ones for which there are |
353e2ef2 | 5112 | explicit specs following the `:'. |
c567ac01 RS |
5113 | |
5114 | Simple (numeric and null-list) specs are interpreted as follows: | |
5115 | ||
19b84ba3 RS |
5116 | Numbers indicate the relative depth to open the corresponding topic. |
5117 | - negative numbers force the topic to be closed before opening to the | |
5118 | absolute value of the number, so all siblings are open only to | |
5119 | that level. | |
5120 | - positive numbers open to the relative depth indicated by the | |
5121 | number, but do not force already opened subtopics to be closed. | |
60c7bbd2 | 5122 | - 0 means to close topic -- hide all offspring. |
353e2ef2 | 5123 | : - `repeat' |
c567ac01 | 5124 | apply prior element to all siblings at current level, *up to* |
353e2ef2 | 5125 | those siblings that would be covered by specs following the `:' |
c567ac01 | 5126 | on the list. Ie, apply to all topics at level but the last |
c07583cd | 5127 | ones. (Only first of multiple colons at same level is |
60c7bbd2 | 5128 | respected -- subsequent ones are discarded.) |
19b84ba3 RS |
5129 | * - completely opens the topic, including bodies. |
5130 | + - shows all the sub headers, but not the bodies | |
5131 | - - exposes the body of the corresponding topic. | |
c567ac01 RS |
5132 | |
5133 | Examples: | |
fd5359c6 | 5134 | \(allout-expose-topic '(-1 : 0)) |
c567ac01 RS |
5135 | Close this and all following topics at current level, exposing |
5136 | only their immediate children, but close down the last topic | |
5137 | at this current level completely. | |
fd5359c6 | 5138 | \(allout-expose-topic '(-1 () : 1 0)) |
c567ac01 RS |
5139 | Close current topic so only the immediate subtopics are shown; |
5140 | show the children in the second to last topic, and completely | |
5141 | close the last one. | |
fd5359c6 | 5142 | \(allout-expose-topic '(-2 : -1 *)) |
c567ac01 RS |
5143 | Expose children and grandchildren of all topics at current |
5144 | level except the last two; expose children of the second to | |
5145 | last and completely open the last one." | |
5146 | ||
5147 | (interactive "xExposure spec: ") | |
19b84ba3 RS |
5148 | (if (not (listp spec)) |
5149 | nil | |
fd5359c6 | 5150 | (let ((depth (allout-depth)) |
19b84ba3 RS |
5151 | (max-pos 0) |
5152 | prev-elem curr-elem | |
96b83743 | 5153 | stay) |
19b84ba3 RS |
5154 | (while spec |
5155 | (setq prev-elem curr-elem | |
5156 | curr-elem (car spec) | |
5157 | spec (cdr spec)) | |
5158 | (cond ; Do current element: | |
5159 | ((null curr-elem) nil) | |
5160 | ((symbolp curr-elem) | |
fd5359c6 MR |
5161 | (cond ((eq curr-elem '*) (allout-show-current-subtree) |
5162 | (if (> allout-recent-end-of-subtree max-pos) | |
5163 | (setq max-pos allout-recent-end-of-subtree))) | |
65e7eb3d EZ |
5164 | ((eq curr-elem '+) |
5165 | (if (not (allout-hidden-p)) | |
5166 | (save-excursion (allout-hide-current-subtree t))) | |
5167 | (allout-show-current-branches) | |
fd5359c6 MR |
5168 | (if (> allout-recent-end-of-subtree max-pos) |
5169 | (setq max-pos allout-recent-end-of-subtree))) | |
5170 | ((eq curr-elem '-) (allout-show-current-entry)) | |
19b84ba3 RS |
5171 | ((eq curr-elem ':) |
5172 | (setq stay t) | |
353e2ef2 | 5173 | ;; Expand the `repeat' spec to an explicit version, |
19b84ba3 RS |
5174 | ;; w.r.t. remaining siblings: |
5175 | (let ((residue ; = # of sibs not covered by remaining spec | |
60c7bbd2 | 5176 | ;; Dang, could be nice to make use of the chart, sigh: |
fd5359c6 | 5177 | (- (length (allout-chart-siblings)) |
19b84ba3 RS |
5178 | (length spec)))) |
5179 | (if (< 0 residue) | |
60c7bbd2 | 5180 | ;; Some residue -- cover it with prev-elem: |
19b84ba3 RS |
5181 | (setq spec (append (make-list residue prev-elem) |
5182 | spec))))))) | |
5183 | ((numberp curr-elem) | |
96b83743 | 5184 | (if (and (>= 0 curr-elem) (not (allout-hidden-p))) |
fd5359c6 | 5185 | (save-excursion (allout-hide-current-subtree t) |
19b84ba3 RS |
5186 | (if (> 0 curr-elem) |
5187 | nil | |
fd5359c6 | 5188 | (if (> allout-recent-end-of-subtree max-pos) |
19b84ba3 | 5189 | (setq max-pos |
fd5359c6 | 5190 | allout-recent-end-of-subtree))))) |
19b84ba3 | 5191 | (if (> (abs curr-elem) 0) |
fd5359c6 MR |
5192 | (progn (allout-show-children (abs curr-elem)) |
5193 | (if (> allout-recent-end-of-subtree max-pos) | |
5194 | (setq max-pos allout-recent-end-of-subtree))))) | |
19b84ba3 | 5195 | ((listp curr-elem) |
fd5359c6 MR |
5196 | (if (allout-descend-to-depth (1+ depth)) |
5197 | (let ((got (allout-expose-topic curr-elem))) | |
19b84ba3 RS |
5198 | (if (and got (> got max-pos)) (setq max-pos got)))))) |
5199 | (cond (stay (setq stay nil)) | |
5200 | ((listp (car spec)) nil) | |
5201 | ((> max-pos (point)) | |
5202 | ;; Capitalize on max-pos state to get us nearer next sibling: | |
5203 | (progn (goto-char (min (point-max) max-pos)) | |
fd5359c6 MR |
5204 | (allout-next-heading))) |
5205 | ((allout-next-sibling depth)))) | |
19b84ba3 | 5206 | max-pos))) |
fd5359c6 MR |
5207 | ;;;_ > allout-old-expose-topic (spec &rest followers) |
5208 | (defun allout-old-expose-topic (spec &rest followers) | |
d82979ea | 5209 | |
c07583cd | 5210 | "Deprecated. Use `allout-expose-topic' (with different schema |
d82979ea EZ |
5211 | format) instead. |
5212 | ||
5213 | Dictate wholesale exposure scheme for current topic, according to SPEC. | |
c567ac01 RS |
5214 | |
5215 | SPEC is either a number or a list. Optional successive args | |
5216 | dictate exposure for subsequent siblings of current topic. | |
5217 | ||
5218 | A simple spec (either a number, a special symbol, or the null list) | |
5219 | dictates the overall exposure for a topic. Non null lists are | |
5220 | composite specs whose first element dictates the overall exposure for | |
5221 | a topic, with the subsequent elements in the list interpreted as specs | |
5222 | that dictate the exposure for the successive offspring of the topic. | |
5223 | ||
5224 | Simple (numeric and null-list) specs are interpreted as follows: | |
5225 | ||
5226 | - Numbers indicate the relative depth to open the corresponding topic: | |
5227 | - negative numbers force the topic to be close before opening to the | |
5228 | absolute value of the number. | |
5229 | - positive numbers just open to the relative depth indicated by the number. | |
5230 | - 0 just closes | |
353e2ef2 KH |
5231 | - `*' completely opens the topic, including bodies. |
5232 | - `+' shows all the sub headers, but not the bodies | |
5233 | - `-' exposes the body and immediate offspring of the corresponding topic. | |
c567ac01 RS |
5234 | |
5235 | If the spec is a list, the first element must be a number, which | |
5236 | dictates the exposure depth of the topic as a whole. Subsequent | |
5237 | elements of the list are nested SPECs, dictating the specific exposure | |
5238 | for the corresponding offspring of the topic. | |
5239 | ||
e126900f | 5240 | Optional FOLLOWERS arguments dictate exposure for succeeding siblings." |
c567ac01 RS |
5241 | |
5242 | (interactive "xExposure spec: ") | |
0458fa80 EZ |
5243 | (let ((inhibit-field-text-motion t) |
5244 | (depth (allout-current-depth)) | |
c567ac01 RS |
5245 | max-pos) |
5246 | (cond ((null spec) nil) | |
5247 | ((symbolp spec) | |
fd5359c6 MR |
5248 | (if (eq spec '*) (allout-show-current-subtree)) |
5249 | (if (eq spec '+) (allout-show-current-branches)) | |
5250 | (if (eq spec '-) (allout-show-current-entry))) | |
c567ac01 RS |
5251 | ((numberp spec) |
5252 | (if (>= 0 spec) | |
fd5359c6 | 5253 | (save-excursion (allout-hide-current-subtree t) |
c567ac01 RS |
5254 | (end-of-line) |
5255 | (if (or (not max-pos) | |
5256 | (> (point) max-pos)) | |
5257 | (setq max-pos (point))) | |
5258 | (if (> 0 spec) | |
5259 | (setq spec (* -1 spec))))) | |
5260 | (if (> spec 0) | |
fd5359c6 | 5261 | (allout-show-children spec))) |
c567ac01 | 5262 | ((listp spec) |
fd5359c6 | 5263 | ;(let ((got (allout-old-expose-topic (car spec)))) |
c567ac01 RS |
5264 | ; (if (and got (or (not max-pos) (> got max-pos))) |
5265 | ; (setq max-pos got))) | |
fd5359c6 | 5266 | (let ((new-depth (+ (allout-current-depth) 1)) |
c567ac01 | 5267 | got) |
fd5359c6 | 5268 | (setq max-pos (allout-old-expose-topic (car spec))) |
c567ac01 RS |
5269 | (setq spec (cdr spec)) |
5270 | (if (and spec | |
fd5359c6 MR |
5271 | (allout-descend-to-depth new-depth) |
5272 | (not (allout-hidden-p))) | |
5273 | (progn (setq got (apply 'allout-old-expose-topic spec)) | |
c567ac01 RS |
5274 | (if (and got (or (not max-pos) (> got max-pos))) |
5275 | (setq max-pos got))))))) | |
5276 | (while (and followers | |
5277 | (progn (if (and max-pos (< (point) max-pos)) | |
5278 | (progn (goto-char max-pos) | |
5279 | (setq max-pos nil))) | |
5280 | (end-of-line) | |
fd5359c6 MR |
5281 | (allout-next-sibling depth))) |
5282 | (allout-old-expose-topic (car followers)) | |
c567ac01 RS |
5283 | (setq followers (cdr followers))) |
5284 | max-pos)) | |
fd5359c6 MR |
5285 | ;;;_ > allout-new-exposure '() |
5286 | (defmacro allout-new-exposure (&rest spec) | |
5287 | "Literal frontend for `allout-expose-topic', doesn't evaluate arguments. | |
2265e017 MR |
5288 | Some arguments that would need to be quoted in `allout-expose-topic' |
5289 | need not be quoted in `allout-new-exposure'. | |
c567ac01 RS |
5290 | |
5291 | Cursor is left at start position. | |
5292 | ||
d82979ea EZ |
5293 | Use this instead of obsolete `allout-exposure'. |
5294 | ||
c567ac01 | 5295 | Examples: |
bff05d9e | 5296 | \(allout-new-exposure (-1 () () () 1) 0) |
c567ac01 RS |
5297 | Close current topic at current level so only the immediate |
5298 | subtopics are shown, except also show the children of the | |
5299 | third subtopic; and close the next topic at the current level. | |
bff05d9e | 5300 | \(allout-new-exposure : -1 0) |
c567ac01 RS |
5301 | Close all topics at current level to expose only their |
5302 | immediate children, except for the last topic at the current | |
353e2ef2 | 5303 | level, in which even its immediate children are hidden. |
bff05d9e | 5304 | \(allout-new-exposure -2 : -1 *) |
c567ac01 RS |
5305 | Expose children and grandchildren of first topic at current |
5306 | level, and expose children of subsequent topics at current | |
5307 | level *except* for the last, which should be opened completely." | |
651eaf36 AS |
5308 | `(save-excursion |
5309 | (if (not (or (allout-goto-prefix-doublechecked) | |
5310 | (allout-next-heading))) | |
5311 | (error "allout-new-exposure: Can't find any outline topics")) | |
5312 | (allout-expose-topic ',spec))) | |
c567ac01 | 5313 | |
60c7bbd2 | 5314 | ;;;_ #7 Systematic outline presentation -- copying, printing, flattening |
19b84ba3 | 5315 | |
9179616f DL |
5316 | ;;;_ - Mapping and processing of topics |
5317 | ;;;_ ( See also Subtree Charting, in Navigation code.) | |
fd5359c6 MR |
5318 | ;;;_ > allout-stringify-flat-index (flat-index) |
5319 | (defun allout-stringify-flat-index (flat-index &optional context) | |
9179616f DL |
5320 | "Convert list representing section/subsection/... to document string. |
5321 | ||
5322 | Optional arg CONTEXT indicates interior levels to include." | |
5323 | (let ((delim ".") | |
71296446 | 5324 | result |
9179616f DL |
5325 | numstr |
5326 | (context-depth (or (and context 2) 1))) | |
5327 | ;; Take care of the explicit context: | |
5328 | (while (> context-depth 0) | |
5329 | (setq numstr (int-to-string (car flat-index)) | |
5330 | flat-index (cdr flat-index) | |
5331 | result (if flat-index | |
5332 | (cons delim (cons numstr result)) | |
5333 | (cons numstr result)) | |
5334 | context-depth (if flat-index (1- context-depth) 0))) | |
5335 | (setq delim " ") | |
5336 | ;; Take care of the indentation: | |
5337 | (if flat-index | |
5338 | (progn | |
5339 | (while flat-index | |
5340 | (setq result | |
5341 | (cons delim | |
5342 | (cons (make-string | |
5343 | (1+ (truncate (if (zerop (car flat-index)) | |
5344 | 1 | |
89561f72 | 5345 | (log (car flat-index) 10)))) |
9179616f DL |
5346 | ? ) |
5347 | result))) | |
5348 | (setq flat-index (cdr flat-index))) | |
5349 | ;; Dispose of single extra delim: | |
5350 | (setq result (cdr result)))) | |
5351 | (apply 'concat result))) | |
fd5359c6 MR |
5352 | ;;;_ > allout-stringify-flat-index-plain (flat-index) |
5353 | (defun allout-stringify-flat-index-plain (flat-index) | |
9179616f DL |
5354 | "Convert list representing section/subsection/... to document string." |
5355 | (let ((delim ".") | |
5356 | result) | |
5357 | (while flat-index | |
5358 | (setq result (cons (int-to-string (car flat-index)) | |
5359 | (if result | |
5360 | (cons delim result)))) | |
5361 | (setq flat-index (cdr flat-index))) | |
5362 | (apply 'concat result))) | |
fd5359c6 MR |
5363 | ;;;_ > allout-stringify-flat-index-indented (flat-index) |
5364 | (defun allout-stringify-flat-index-indented (flat-index) | |
9179616f DL |
5365 | "Convert list representing section/subsection/... to document string." |
5366 | (let ((delim ".") | |
71296446 | 5367 | result |
9179616f DL |
5368 | numstr) |
5369 | ;; Take care of the explicit context: | |
5370 | (setq numstr (int-to-string (car flat-index)) | |
5371 | flat-index (cdr flat-index) | |
5372 | result (if flat-index | |
5373 | (cons delim (cons numstr result)) | |
5374 | (cons numstr result))) | |
5375 | (setq delim " ") | |
5376 | ;; Take care of the indentation: | |
5377 | (if flat-index | |
5378 | (progn | |
5379 | (while flat-index | |
5380 | (setq result | |
5381 | (cons delim | |
5382 | (cons (make-string | |
5383 | (1+ (truncate (if (zerop (car flat-index)) | |
5384 | 1 | |
89561f72 | 5385 | (log (car flat-index) 10)))) |
9179616f DL |
5386 | ? ) |
5387 | result))) | |
5388 | (setq flat-index (cdr flat-index))) | |
5389 | ;; Dispose of single extra delim: | |
5390 | (setq result (cdr result)))) | |
5391 | (apply 'concat result))) | |
fd5359c6 MR |
5392 | ;;;_ > allout-listify-exposed (&optional start end format) |
5393 | (defun allout-listify-exposed (&optional start end format) | |
19b84ba3 | 5394 | |
9179616f | 5395 | "Produce a list representing exposed topics in current region. |
c567ac01 | 5396 | |
fd5359c6 | 5397 | This list can then be used by `allout-process-exposed' to manipulate |
9179616f | 5398 | the subject region. |
353e2ef2 | 5399 | |
9179616f | 5400 | Optional START and END indicate bounds of region. |
19b84ba3 | 5401 | |
75bcb912 | 5402 | Optional arg, FORMAT, designates an alternate presentation form for |
9179616f | 5403 | the prefix: |
c567ac01 | 5404 | |
60c7bbd2 | 5405 | list -- Present prefix as numeric section.subsection..., starting with |
9179616f | 5406 | section indicated by the list, innermost nesting first. |
60c7bbd2 | 5407 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5408 | except for distinctive bullets. |
c567ac01 | 5409 | |
9179616f DL |
5410 | The elements of the list produced are lists that represents a topic |
5411 | header and body. The elements of that list are: | |
c567ac01 | 5412 | |
9179616f DL |
5413 | - a number representing the depth of the topic, |
5414 | - a string representing the header-prefix, including trailing whitespace and | |
5415 | bullet. | |
5416 | - a string representing the bullet character, | |
5417 | - and a series of strings, each containing one line of the exposed | |
5418 | portion of the topic entry." | |
c567ac01 | 5419 | |
9179616f DL |
5420 | (interactive "r") |
5421 | (save-excursion | |
5422 | (let* | |
0458fa80 EZ |
5423 | ((inhibit-field-text-motion t) |
5424 | ;; state vars: | |
5425 | strings prefix result depth new-depth out gone-out bullet beg | |
9179616f | 5426 | next done) |
c567ac01 | 5427 | |
9179616f DL |
5428 | (goto-char start) |
5429 | (beginning-of-line) | |
97610156 | 5430 | ;; Goto initial topic, and register preceding stuff, if any: |
d8350998 | 5431 | (if (> (allout-goto-prefix-doublechecked) start) |
60c7bbd2 | 5432 | ;; First topic follows beginning point -- register preliminary stuff: |
3e2ee889 KM |
5433 | (setq result |
5434 | (list (list 0 "" nil | |
5435 | (buffer-substring-no-properties start | |
5436 | (1- (point))))))) | |
9179616f DL |
5437 | (while (and (not done) |
5438 | (not (eobp)) ; Loop until we've covered the region. | |
5439 | (not (> (point) end))) | |
d8350998 | 5440 | (setq depth allout-recent-depth ; Current topics depth, |
fd5359c6 MR |
5441 | bullet (allout-recent-bullet) ; ... bullet, |
5442 | prefix (allout-recent-prefix) | |
5443 | beg (progn (allout-end-of-prefix t) (point))) ; and beginning. | |
9179616f | 5444 | (setq done ; The boundary for the current topic: |
fd5359c6 | 5445 | (not (allout-next-visible-heading 1))) |
d8350998 | 5446 | (setq new-depth allout-recent-depth) |
9179616f DL |
5447 | (setq gone-out out |
5448 | out (< new-depth depth)) | |
5449 | (beginning-of-line) | |
5450 | (setq next (point)) | |
5451 | (goto-char beg) | |
5452 | (setq strings nil) | |
5453 | (while (> next (point)) ; Get all the exposed text in | |
5454 | (setq strings | |
3e2ee889 | 5455 | (cons (buffer-substring-no-properties |
9179616f DL |
5456 | beg |
5457 | ;To hidden text or end of line: | |
5458 | (progn | |
96b83743 EZ |
5459 | (end-of-line) |
5460 | (allout-back-to-visible-text))) | |
9179616f | 5461 | strings)) |
96b83743 | 5462 | (when (< (point) next) ; Resume from after hid text, if any. |
1b4d97b2 CY |
5463 | (line-move 1) |
5464 | (beginning-of-line)) | |
9179616f DL |
5465 | (setq beg (point))) |
5466 | ;; Accumulate list for this topic: | |
5467 | (setq strings (nreverse strings)) | |
5468 | (setq result | |
5469 | (cons | |
5470 | (if format | |
5471 | (let ((special (if (string-match | |
5472 | (regexp-quote bullet) | |
fd5359c6 | 5473 | allout-distinctive-bullets-string) |
9179616f DL |
5474 | bullet))) |
5475 | (cond ((listp format) | |
5476 | (list depth | |
96497653 | 5477 | (if allout-flattened-numbering-abbreviation |
fd5359c6 | 5478 | (allout-stringify-flat-index format |
9179616f | 5479 | gone-out) |
fd5359c6 | 5480 | (allout-stringify-flat-index-plain |
9179616f DL |
5481 | format)) |
5482 | strings | |
5483 | special)) | |
5484 | ((eq format 'indent) | |
5485 | (if special | |
5486 | (list depth | |
5487 | (concat (make-string (1+ depth) ? ) | |
5488 | (substring prefix -1)) | |
5489 | strings) | |
5490 | (list depth | |
5491 | (make-string depth ? ) | |
5492 | strings))) | |
fd5359c6 | 5493 | (t (error "allout-listify-exposed: %s %s" |
9179616f DL |
5494 | "invalid format" format)))) |
5495 | (list depth prefix strings)) | |
5496 | result)) | |
09e80d9f | 5497 | ;; Reassess format, if any: |
9179616f DL |
5498 | (if (and format (listp format)) |
5499 | (cond ((= new-depth depth) | |
5500 | (setq format (cons (1+ (car format)) | |
5501 | (cdr format)))) | |
60c7bbd2 | 5502 | ((> new-depth depth) ; descending -- assume by 1: |
9179616f DL |
5503 | (setq format (cons 1 format))) |
5504 | (t | |
5505 | ; Pop the residue: | |
5506 | (while (< new-depth depth) | |
5507 | (setq format (cdr format)) | |
5508 | (setq depth (1- depth))) | |
5509 | ; And increment the current one: | |
5510 | (setq format | |
5511 | (cons (1+ (or (car format) | |
5512 | -1)) | |
5513 | (cdr format))))))) | |
5514 | ;; Put the list with first at front, to last at back: | |
5515 | (nreverse result)))) | |
c60d543d RS |
5516 | ;;;_ > allout-region-active-p () |
5517 | (defmacro allout-region-active-p () | |
42c3e51c KM |
5518 | (cond ((fboundp 'use-region-p) '(use-region-p)) |
5519 | ((fboundp 'region-active-p) '(region-active-p)) | |
5520 | (t 'mark-active))) | |
5521 | ;;_ > allout-process-exposed (&optional func from to frombuf | |
9179616f | 5522 | ;;; tobuf format) |
fd5359c6 | 5523 | (defun allout-process-exposed (&optional func from to frombuf tobuf |
96b83743 | 5524 | format start-num) |
9179616f | 5525 | "Map function on exposed parts of current topic; results to another buffer. |
353e2ef2 | 5526 | |
d82979ea EZ |
5527 | All args are options; default values itemized below. |
5528 | ||
5529 | Apply FUNCTION to exposed portions FROM position TO position in buffer | |
9179616f DL |
5530 | FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an |
5531 | alternate presentation form: | |
c567ac01 | 5532 | |
60c7bbd2 | 5533 | `flat' -- Present prefix as numeric section.subsection..., starting with |
75bcb912 | 5534 | section indicated by the START-NUM, innermost nesting first. |
60c7bbd2 | 5535 | X`flat-indented' -- Prefix is like `flat' for first topic at each |
9179616f DL |
5536 | X level, but subsequent topics have only leaf topic |
5537 | X number, padded with blanks to line up with first. | |
60c7bbd2 | 5538 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5539 | except for distinctive bullets. |
c567ac01 | 5540 | |
9179616f | 5541 | Defaults: |
d82979ea | 5542 | FUNCTION: `allout-insert-listified' |
9179616f DL |
5543 | FROM: region start, if region active, else start of buffer |
5544 | TO: region end, if region active, else end of buffer | |
5545 | FROMBUF: current buffer | |
5546 | TOBUF: buffer name derived: \"*current-buffer-name exposed*\" | |
5547 | FORMAT: nil" | |
5548 | ||
5549 | ; Resolve arguments, | |
5550 | ; defaulting if necessary: | |
fd5359c6 | 5551 | (if (not func) (setq func 'allout-insert-listified)) |
9179616f | 5552 | (if (not (and from to)) |
c60d543d | 5553 | (if (allout-region-active-p) |
9179616f DL |
5554 | (setq from (region-beginning) to (region-end)) |
5555 | (setq from (point-min) to (point-max)))) | |
5556 | (if frombuf | |
5557 | (if (not (bufferp frombuf)) | |
60c7bbd2 | 5558 | ;; Specified but not a buffer -- get it: |
9179616f DL |
5559 | (let ((got (get-buffer frombuf))) |
5560 | (if (not got) | |
fd5359c6 | 5561 | (error (concat "allout-process-exposed: source buffer " |
9179616f DL |
5562 | frombuf |
5563 | " not found.")) | |
5564 | (setq frombuf got)))) | |
60c7bbd2 | 5565 | ;; not specified -- default it: |
9179616f DL |
5566 | (setq frombuf (current-buffer))) |
5567 | (if tobuf | |
5568 | (if (not (bufferp tobuf)) | |
5569 | (setq tobuf (get-buffer-create tobuf))) | |
60c7bbd2 | 5570 | ;; not specified -- default it: |
9179616f DL |
5571 | (setq tobuf (concat "*" (buffer-name frombuf) " exposed*"))) |
5572 | (if (listp format) | |
5573 | (nreverse format)) | |
5574 | ||
5575 | (let* ((listified | |
5576 | (progn (set-buffer frombuf) | |
fd5359c6 | 5577 | (allout-listify-exposed from to format)))) |
9179616f | 5578 | (set-buffer tobuf) |
5110e166 | 5579 | (mapc func listified) |
9179616f DL |
5580 | (pop-to-buffer tobuf))) |
5581 | ||
5582 | ;;;_ - Copy exposed | |
fd5359c6 MR |
5583 | ;;;_ > allout-insert-listified (listified) |
5584 | (defun allout-insert-listified (listified) | |
9179616f DL |
5585 | "Insert contents of listified outline portion in current buffer. |
5586 | ||
e126900f | 5587 | LISTIFIED is a list representing each topic header and body: |
9179616f DL |
5588 | |
5589 | \`(depth prefix text)' | |
5590 | ||
d82979ea | 5591 | or \`(depth prefix text bullet-plus)' |
9179616f DL |
5592 | |
5593 | If `bullet-plus' is specified, it is inserted just after the entire prefix." | |
5594 | (setq listified (cdr listified)) | |
5595 | (let ((prefix (prog1 | |
5596 | (car listified) | |
5597 | (setq listified (cdr listified)))) | |
5598 | (text (prog1 | |
5599 | (car listified) | |
5600 | (setq listified (cdr listified)))) | |
5601 | (bullet-plus (car listified))) | |
eac9cf5f PJ |
5602 | (insert prefix) |
5603 | (if bullet-plus (insert (concat " " bullet-plus))) | |
9179616f | 5604 | (while text |
eac9cf5f | 5605 | (insert (car text)) |
9179616f | 5606 | (if (setq text (cdr text)) |
0949617b | 5607 | (insert "\n"))) |
eac9cf5f | 5608 | (insert "\n"))) |
fd5359c6 MR |
5609 | ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format) |
5610 | (defun allout-copy-exposed-to-buffer (&optional arg tobuf format) | |
9179616f DL |
5611 | "Duplicate exposed portions of current outline to another buffer. |
5612 | ||
5613 | Other buffer has current buffers name with \" exposed\" appended to it. | |
5614 | ||
5615 | With repeat count, copy the exposed parts of only the current topic. | |
5616 | ||
5617 | Optional second arg TOBUF is target buffer name. | |
5618 | ||
5619 | Optional third arg FORMAT, if non-nil, symbolically designates an | |
5620 | alternate presentation format for the outline: | |
5621 | ||
5622 | `flat' - Convert topic header prefixes to numeric | |
5623 | section.subsection... identifiers. | |
5624 | `indent' - Convert header prefixes to all white space, except for | |
5625 | distinctive bullets. | |
5626 | `indent-flat' - The best of both - only the first of each level has | |
5627 | the full path, the rest have only the section number | |
5628 | of the leaf, preceded by the right amount of indentation." | |
c567ac01 RS |
5629 | |
5630 | (interactive "P") | |
5631 | (if (not tobuf) | |
5632 | (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*")))) | |
5633 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5634 | (beg (if arg (allout-back-to-current-heading) (point-min))) |
5635 | (end (if arg (allout-end-of-current-subtree) (point-max))) | |
9179616f DL |
5636 | (buf (current-buffer)) |
5637 | (start-list ())) | |
5638 | (if (eq format 'flat) | |
5639 | (setq format (if arg (save-excursion | |
5640 | (goto-char beg) | |
fd5359c6 | 5641 | (allout-topic-flat-index)) |
9179616f | 5642 | '(1)))) |
7fdbcd83 | 5643 | (with-current-buffer tobuf (erase-buffer)) |
fd5359c6 | 5644 | (allout-process-exposed 'allout-insert-listified |
c567ac01 RS |
5645 | beg |
5646 | end | |
5647 | (current-buffer) | |
9179616f DL |
5648 | tobuf |
5649 | format start-list) | |
c567ac01 RS |
5650 | (goto-char (point-min)) |
5651 | (pop-to-buffer buf) | |
5652 | (goto-char start-pt))) | |
fd5359c6 MR |
5653 | ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf) |
5654 | (defun allout-flatten-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5655 | "Present numeric outline of outline's exposed portions in another buffer. |
5656 | ||
60c7bbd2 | 5657 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5658 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5659 | |
fd5359c6 | 5660 | Use `allout-indented-exposed-to-buffer' for indented presentation. |
9179616f DL |
5661 | |
5662 | With repeat count, copy the exposed portions of only current topic. | |
5663 | ||
e126900f | 5664 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5665 | it, unless optional second arg TOBUF is specified, in which case it is |
5666 | used verbatim." | |
5667 | (interactive "P") | |
fd5359c6 MR |
5668 | (allout-copy-exposed-to-buffer arg tobuf 'flat)) |
5669 | ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf) | |
5670 | (defun allout-indented-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5671 | "Present indented outline of outline's exposed portions in another buffer. |
5672 | ||
60c7bbd2 | 5673 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5674 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5675 | |
fd5359c6 | 5676 | Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation. |
9179616f DL |
5677 | |
5678 | With repeat count, copy the exposed portions of only current topic. | |
5679 | ||
e126900f | 5680 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5681 | it, unless optional second arg TOBUF is specified, in which case it is |
5682 | used verbatim." | |
5683 | (interactive "P") | |
fd5359c6 | 5684 | (allout-copy-exposed-to-buffer arg tobuf 'indent)) |
c567ac01 RS |
5685 | |
5686 | ;;;_ - LaTeX formatting | |
e126900f JB |
5687 | ;;;_ > allout-latex-verb-quote (string &optional flow) |
5688 | (defun allout-latex-verb-quote (string &optional flow) | |
539d7736 | 5689 | "Return copy of STRING for literal reproduction across LaTeX processing. |
c07583cd | 5690 | Expresses the original characters (including carriage returns) of the |
539d7736 | 5691 | string across LaTeX processing." |
9179616f DL |
5692 | (mapconcat (function |
5693 | (lambda (char) | |
c567ac01 RS |
5694 | (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*)) |
5695 | (concat "\\char" (number-to-string char) "{}")) | |
5696 | ((= char ?\n) "\\\\") | |
9179616f | 5697 | (t (char-to-string char))))) |
e126900f | 5698 | string |
c567ac01 | 5699 | "")) |
fd5359c6 MR |
5700 | ;;;_ > allout-latex-verbatim-quote-curr-line () |
5701 | (defun allout-latex-verbatim-quote-curr-line () | |
c07583cd | 5702 | "Express line for exact (literal) representation across LaTeX processing. |
19b84ba3 | 5703 | |
c07583cd | 5704 | Adjust line contents so it is unaltered (from the original line) |
539d7736 | 5705 | across LaTeX processing, within the context of a `verbatim' |
c567ac01 | 5706 | environment. Leaves point at the end of the line." |
0458fa80 EZ |
5707 | (let ((inhibit-field-text-motion t)) |
5708 | (beginning-of-line) | |
5709 | (let ((beg (point)) | |
626b459f | 5710 | (end (point-at-eol))) |
2a1408fd DN |
5711 | (save-match-data |
5712 | (while (re-search-forward "\\\\" | |
5713 | ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#" | |
5714 | end ; bounded by end-of-line | |
5715 | 1) ; no matches, move to end & return nil | |
5716 | (goto-char (match-beginning 2)) | |
5717 | (insert "\\") | |
5718 | (setq end (1+ end)) | |
5719 | (goto-char (1+ (match-end 2)))))))) | |
e126900f JB |
5720 | ;;;_ > allout-insert-latex-header (buffer) |
5721 | (defun allout-insert-latex-header (buffer) | |
539d7736 | 5722 | "Insert initial LaTeX commands at point in BUFFER." |
c567ac01 RS |
5723 | ;; Much of this is being derived from the stuff in appendix of E in |
5724 | ;; the TeXBook, pg 421. | |
e126900f | 5725 | (set-buffer buffer) |
c567ac01 RS |
5726 | (let ((doc-style (format "\n\\documentstyle{%s}\n" |
5727 | "report")) | |
fd5359c6 | 5728 | (page-numbering (if allout-number-pages |
c567ac01 RS |
5729 | "\\pagestyle{empty}\n" |
5730 | "")) | |
c567ac01 | 5731 | (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5732 | allout-title-style)) |
c567ac01 | 5733 | (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n" |
fd5359c6 | 5734 | allout-label-style)) |
c567ac01 | 5735 | (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5736 | allout-head-line-style)) |
c567ac01 | 5737 | (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5738 | allout-body-line-style)) |
c567ac01 RS |
5739 | (setlength (format "%s%s%s%s" |
5740 | "\\newlength{\\stepsize}\n" | |
5741 | "\\setlength{\\stepsize}{" | |
fd5359c6 | 5742 | allout-indent |
c567ac01 RS |
5743 | "}\n")) |
5744 | (oneheadline (format "%s%s%s%s%s%s%s" | |
5745 | "\\newcommand{\\OneHeadLine}[3]{%\n" | |
5746 | "\\noindent%\n" | |
5747 | "\\hspace*{#2\\stepsize}%\n" | |
5748 | "\\labelcmd{#1}\\hspace*{.2cm}" | |
5749 | "\\headlinecmd{#3}\\\\[" | |
fd5359c6 | 5750 | allout-line-skip |
c567ac01 RS |
5751 | "]\n}\n")) |
5752 | (onebodyline (format "%s%s%s%s%s%s" | |
5753 | "\\newcommand{\\OneBodyLine}[2]{%\n" | |
5754 | "\\noindent%\n" | |
5755 | "\\hspace*{#1\\stepsize}%\n" | |
5756 | "\\bodylinecmd{#2}\\\\[" | |
fd5359c6 | 5757 | allout-line-skip |
c567ac01 RS |
5758 | "]\n}\n")) |
5759 | (begindoc "\\begin{document}\n\\begin{center}\n") | |
5760 | (title (format "%s%s%s%s" | |
5761 | "\\titlecmd{" | |
fd5359c6 | 5762 | (allout-latex-verb-quote (if allout-title |
96b83743 | 5763 | (condition-case nil |
fd5359c6 | 5764 | (eval allout-title) |
d8350998 | 5765 | (error "<unnamed buffer>")) |
c567ac01 RS |
5766 | "Unnamed Outline")) |
5767 | "}\n" | |
5768 | "\\end{center}\n\n")) | |
5769 | (hsize "\\hsize = 7.5 true in\n") | |
5770 | (hoffset "\\hoffset = -1.5 true in\n") | |
5771 | (vspace "\\vspace{.1cm}\n\n")) | |
5772 | (insert (concat doc-style | |
5773 | page-numbering | |
5774 | titlecmd | |
5775 | labelcmd | |
5776 | headlinecmd | |
5777 | bodylinecmd | |
5778 | setlength | |
5779 | oneheadline | |
5780 | onebodyline | |
5781 | begindoc | |
5782 | title | |
5783 | hsize | |
5784 | hoffset | |
5785 | vspace) | |
5786 | ))) | |
e126900f JB |
5787 | ;;;_ > allout-insert-latex-trailer (buffer) |
5788 | (defun allout-insert-latex-trailer (buffer) | |
539d7736 | 5789 | "Insert concluding LaTeX commands at point in BUFFER." |
e126900f | 5790 | (set-buffer buffer) |
c567ac01 | 5791 | (insert "\n\\end{document}\n")) |
fd5359c6 MR |
5792 | ;;;_ > allout-latexify-one-item (depth prefix bullet text) |
5793 | (defun allout-latexify-one-item (depth prefix bullet text) | |
19b84ba3 RS |
5794 | "Insert LaTeX commands for formatting one outline item. |
5795 | ||
9179616f | 5796 | Args are the topics numeric DEPTH, the header PREFIX lead string, the |
19b84ba3 | 5797 | BULLET string, and a list of TEXT strings for the body." |
c567ac01 RS |
5798 | (let* ((head-line (if text (car text))) |
5799 | (body-lines (cdr text)) | |
5800 | (curr-line) | |
5801 | body-content bop) | |
5802 | ; Do the head line: | |
71296446 | 5803 | (insert (concat "\\OneHeadLine{\\verb\1 " |
d82979ea EZ |
5804 | (allout-latex-verb-quote bullet) |
5805 | "\1}{" | |
5806 | depth | |
5807 | "}{\\verb\1 " | |
5808 | (if head-line | |
5809 | (allout-latex-verb-quote head-line) | |
5810 | "") | |
5811 | "\1}\n")) | |
c567ac01 RS |
5812 | (if (not body-lines) |
5813 | nil | |
eac9cf5f PJ |
5814 | ;;(insert "\\beginlines\n") |
5815 | (insert "\\begin{verbatim}\n") | |
c567ac01 RS |
5816 | (while body-lines |
5817 | (setq curr-line (car body-lines)) | |
5818 | (if (and (not body-content) | |
5819 | (not (string-match "^\\s-*$" curr-line))) | |
5820 | (setq body-content t)) | |
5821 | ; Mangle any occurrences of | |
5822 | ; "\end{verbatim}" in text, | |
5823 | ; it's special: | |
5824 | (if (and body-content | |
5825 | (setq bop (string-match "\\end{verbatim}" curr-line))) | |
5826 | (setq curr-line (concat (substring curr-line 0 bop) | |
5827 | ">" | |
5828 | (substring curr-line bop)))) | |
eac9cf5f PJ |
5829 | ;;(insert "|" (car body-lines) "|") |
5830 | (insert curr-line) | |
fd5359c6 | 5831 | (allout-latex-verbatim-quote-curr-line) |
eac9cf5f | 5832 | (insert "\n") |
c567ac01 RS |
5833 | (setq body-lines (cdr body-lines))) |
5834 | (if body-content | |
5835 | (setq body-content nil) | |
5836 | (forward-char -1) | |
eac9cf5f | 5837 | (insert "\\ ") |
c567ac01 | 5838 | (forward-char 1)) |
eac9cf5f PJ |
5839 | ;;(insert "\\endlines\n") |
5840 | (insert "\\end{verbatim}\n") | |
c567ac01 | 5841 | ))) |
fd5359c6 MR |
5842 | ;;;_ > allout-latexify-exposed (arg &optional tobuf) |
5843 | (defun allout-latexify-exposed (arg &optional tobuf) | |
539d7736 | 5844 | "Format current topics exposed portions to TOBUF for LaTeX processing. |
19b84ba3 RS |
5845 | TOBUF defaults to a buffer named the same as the current buffer, but |
5846 | with \"*\" prepended and \" latex-formed*\" appended. | |
c567ac01 RS |
5847 | |
5848 | With repeat count, copy the exposed portions of entire buffer." | |
5849 | ||
5850 | (interactive "P") | |
5851 | (if (not tobuf) | |
5852 | (setq tobuf | |
5853 | (get-buffer-create (concat "*" (buffer-name) " latexified*")))) | |
5854 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5855 | (beg (if arg (point-min) (allout-back-to-current-heading))) |
5856 | (end (if arg (point-max) (allout-end-of-current-subtree))) | |
c567ac01 RS |
5857 | (buf (current-buffer))) |
5858 | (set-buffer tobuf) | |
1977b8f6 | 5859 | (erase-buffer) |
fd5359c6 | 5860 | (allout-insert-latex-header tobuf) |
c567ac01 | 5861 | (goto-char (point-max)) |
fd5359c6 | 5862 | (allout-process-exposed 'allout-latexify-one-item |
c567ac01 RS |
5863 | beg |
5864 | end | |
5865 | buf | |
5866 | tobuf) | |
5867 | (goto-char (point-max)) | |
fd5359c6 | 5868 | (allout-insert-latex-trailer tobuf) |
1977b8f6 | 5869 | (goto-char (point-min)) |
c567ac01 RS |
5870 | (pop-to-buffer buf) |
5871 | (goto-char start-pt))) | |
5872 | ||
d82979ea | 5873 | ;;;_ #8 Encryption |
29fac3fe KM |
5874 | ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue) |
5875 | (defun allout-toggle-current-subtree-encryption (&optional keymode-cue) | |
5876 | "Encrypt clear or decrypt encoded topic text. | |
5877 | ||
20db1522 | 5878 | Allout uses Emacs 'epg' library to perform encryption. Symmetric |
29fac3fe KM |
5879 | and keypair encryption are supported. All encryption is ascii |
5880 | armored. | |
5881 | ||
075746e2 | 5882 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 5883 | recipients are associated with the file (see |
075746e2 KM |
5884 | `epa-file-encrypt-to') or the function is invoked with a |
5885 | \(KEYMODE-CUE) universal argument greater than 1. | |
5886 | ||
5887 | When encrypting, KEYMODE-CUE universal argument greater than 1 | |
5888 | causes prompting for recipients for public-key keypair | |
5889 | encryption. Selecting no recipients results in symmetric key | |
29fac3fe KM |
5890 | encryption. |
5891 | ||
075746e2 KM |
5892 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5893 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5894 | the specified recipients with the file, replacing those currently | |
99d99081 | 5895 | associated with it. This can be used to dissociate any |
075746e2 KM |
5896 | recipients with the file, by selecting no recipients in the |
5897 | dialog. | |
5898 | ||
29fac3fe KM |
5899 | Encrypted topic's bullets are set to a `~' to signal that the |
5900 | contents of the topic (body and subtopics, but not heading) is | |
5901 | pending encryption or encrypted. `*' asterisk immediately after | |
5902 | the bullet signals that the body is encrypted, its absence means | |
5903 | the topic is meant to be encrypted but is not currently. When a | |
5904 | file with topics pending encryption is saved, topics pending | |
20db1522 | 5905 | encryption are encrypted. See `allout-encrypt-unencrypted-on-saves' |
29fac3fe | 5906 | for auto-encryption specifics. |
0949617b | 5907 | |
6eb0a10d | 5908 | \*NOTE WELL* that automatic encryption that happens during saves will |
60c7bbd2 | 5909 | default to symmetric encryption -- you must deliberately (re)encrypt key-pair |
0949617b | 5910 | encrypted topics if you want them to continue to use the key-pair cipher. |
d82979ea | 5911 | |
d8350998 | 5912 | Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be |
d82979ea | 5913 | encrypted. If you want to encrypt the contents of a top-level topic, use |
29fac3fe | 5914 | \\[allout-shift-in] to increase its depth." |
69027dea EZ |
5915 | (interactive "P") |
5916 | (save-excursion | |
5917 | (allout-back-to-current-heading) | |
29fac3fe KM |
5918 | (allout-toggle-subtree-encryption keymode-cue))) |
5919 | ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue) | |
5920 | (defun allout-toggle-subtree-encryption (&optional keymode-cue) | |
c07583cd | 5921 | "Encrypt clear text or decrypt encoded topic contents (body and subtopics.) |
69027dea | 5922 | |
075746e2 | 5923 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 5924 | recipients are associated with the file (see |
075746e2 KM |
5925 | `epa-file-encrypt-to') or the function is invoked with a |
5926 | \(KEYMODE-CUE) universal argument greater than 1. | |
69027dea | 5927 | |
075746e2 KM |
5928 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
5929 | causes prompting for recipients for public-key keypair | |
5930 | encryption. Selecting no recipients results in symmetric key | |
5931 | encryption. | |
69027dea | 5932 | |
075746e2 KM |
5933 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5934 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5935 | the specified recipients with the file, replacing those currently | |
99d99081 | 5936 | associated with it. This can be used to dissociate any |
075746e2 KM |
5937 | recipients with the file, by selecting no recipients in the |
5938 | dialog. | |
5939 | ||
20db1522 | 5940 | Encryption and decryption uses the Emacs 'epg' library. |
69027dea | 5941 | |
29fac3fe | 5942 | Encrypted text will be ascii-armored. |
69027dea EZ |
5943 | |
5944 | See `allout-toggle-current-subtree-encryption' for more details." | |
d82979ea EZ |
5945 | |
5946 | (interactive "P") | |
5947 | (save-excursion | |
5948 | (allout-end-of-prefix t) | |
5949 | ||
d8350998 | 5950 | (if (= allout-recent-depth 1) |
d82979ea EZ |
5951 | (error (concat "Cannot encrypt or decrypt level 1 topics -" |
5952 | " shift it in to make it encryptable"))) | |
5953 | ||
d82979ea | 5954 | (let* ((allout-buffer (current-buffer)) |
13aa217b KM |
5955 | ;; for use with allout-auto-save-temporarily-disabled, if necessary: |
5956 | (was-buffer-saved-size buffer-saved-size) | |
498a6493 | 5957 | ;; Assess location: |
d8350998 | 5958 | (bullet-pos allout-recent-prefix-beginning) |
d82979ea EZ |
5959 | (after-bullet-pos (point)) |
5960 | (was-encrypted | |
5961 | (progn (if (= (point-max) after-bullet-pos) | |
5962 | (error "no body to encrypt")) | |
0949617b | 5963 | (allout-encrypted-topic-p))) |
96b83743 | 5964 | (was-collapsed (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
5965 | nil |
5966 | (backward-char 1) | |
96b83743 | 5967 | (allout-hidden-p))) |
d82979ea EZ |
5968 | (subtree-beg (1+ (point))) |
5969 | (subtree-end (allout-end-of-subtree)) | |
5970 | (subject-text (buffer-substring-no-properties subtree-beg | |
5971 | subtree-end)) | |
5972 | (subtree-end-char (char-after (1- subtree-end))) | |
96b83743 | 5973 | (subtree-trailing-char (char-after subtree-end)) |
60c7bbd2 | 5974 | ;; kluge -- result-text needs to be nil, but we also want to |
96b83743 EZ |
5975 | ;; check for the error condition |
5976 | (result-text (if (or (string= "" subject-text) | |
5977 | (string= "\n" subject-text)) | |
5978 | (error "No topic contents to %scrypt" | |
5979 | (if was-encrypted "de" "en")) | |
5980 | nil)) | |
d82979ea | 5981 | ;; Assess key parameters: |
498a6493 CY |
5982 | (was-coding-system buffer-file-coding-system)) |
5983 | ||
5984 | (when (not was-encrypted) | |
5985 | ;; ensure that non-ascii chars pending encryption are noticed before | |
116f996b | 5986 | ;; they're encrypted, so the coding system is set to accommodate |
498a6493 CY |
5987 | ;; them. |
5988 | (setq buffer-file-coding-system | |
1c9b9df0 | 5989 | (allout-select-safe-coding-system subtree-beg subtree-end)) |
498a6493 CY |
5990 | ;; if the coding system for the text being encrypted is different |
5991 | ;; than that prevailing, then there a real risk that the coding | |
5992 | ;; system can't be noticed by emacs when the file is visited. to | |
5993 | ;; mitigate that, offer to preserve the coding system using a file | |
5994 | ;; local variable. | |
5995 | (if (and (not (equal buffer-file-coding-system | |
5996 | was-coding-system)) | |
5997 | (yes-or-no-p | |
5998 | (format (concat "Register coding system %s as file local" | |
5999 | " var? Necessary when only encrypted text" | |
6000 | " is in that coding system. ") | |
6001 | buffer-file-coding-system))) | |
6002 | (allout-adjust-file-variable "buffer-file-coding-system" | |
6003 | buffer-file-coding-system))) | |
d82979ea EZ |
6004 | |
6005 | (setq result-text | |
6006 | (allout-encrypt-string subject-text was-encrypted | |
075746e2 | 6007 | (current-buffer) keymode-cue)) |
d82979ea EZ |
6008 | |
6009 | ;; Replace the subtree with the processed product. | |
6010 | (allout-unprotected | |
6011 | (progn | |
6012 | (set-buffer allout-buffer) | |
6013 | (delete-region subtree-beg subtree-end) | |
6014 | (insert result-text) | |
6015 | (if was-collapsed | |
96b83743 EZ |
6016 | (allout-flag-region (1- subtree-beg) (point) t)) |
6017 | ;; adjust trailing-blank-lines to preserve topic spacing: | |
d82979ea | 6018 | (if (not was-encrypted) |
96b83743 EZ |
6019 | (if (and (= subtree-end-char ?\n) |
6020 | (= subtree-trailing-char ?\n)) | |
6021 | (insert subtree-trailing-char))) | |
d82979ea EZ |
6022 | ;; Ensure that the item has an encrypted-entry bullet: |
6023 | (if (not (string= (buffer-substring-no-properties | |
6024 | (1- after-bullet-pos) after-bullet-pos) | |
6025 | allout-topic-encryption-bullet)) | |
6026 | (progn (goto-char (1- after-bullet-pos)) | |
6027 | (delete-char 1) | |
6028 | (insert allout-topic-encryption-bullet))) | |
6029 | (if was-encrypted | |
6030 | ;; Remove the is-encrypted bullet qualifier: | |
6031 | (progn (goto-char after-bullet-pos) | |
6032 | (delete-char 1)) | |
6033 | ;; Add the is-encrypted bullet qualifier: | |
6034 | (goto-char after-bullet-pos) | |
d8350998 | 6035 | (insert "*")))) |
13aa217b KM |
6036 | |
6037 | ;; adjust buffer's auto-save eligibility: | |
6038 | (if was-encrypted | |
6039 | (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size) | |
6040 | (allout-maybe-resume-auto-save-info-after-encryption)) | |
6041 | ||
7b97c764 | 6042 | (run-hook-with-args 'allout-structure-added-functions |
1b4d97b2 | 6043 | bullet-pos subtree-end)))) |
6450907e GM |
6044 | |
6045 | (declare-function epg-context-set-passphrase-callback "epg" | |
6046 | (context passphrase-callback)) | |
6047 | (declare-function epg-list-keys "epg" (context &optional name mode)) | |
6048 | (declare-function epg-decrypt-string "epg" (context cipher)) | |
6049 | (declare-function epg-encrypt-string "epg" | |
6050 | (context plain recipients &optional sign always-trust)) | |
6051 | (declare-function epg-user-id-string "epg" (user-id)) | |
6052 | (declare-function epg-key-user-id-list "epg" (key)) | |
6053 | ||
075746e2 | 6054 | ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 6055 | ;;; &optional rejected) |
075746e2 | 6056 | (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 6057 | &optional rejected) |
0949617b | 6058 | "Encrypt or decrypt message TEXT. |
d82979ea | 6059 | |
ff3e8c8e | 6060 | Returns the resulting string, or nil if the transformation fails. |
d82979ea | 6061 | |
ff3e8c8e | 6062 | If DECRYPT is true (default false), then decrypt instead of encrypt. |
d82979ea | 6063 | |
ff3e8c8e | 6064 | ALLOUT-BUFFER identifies the buffer containing the text. |
d82979ea | 6065 | |
075746e2 | 6066 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 6067 | recipients are associated with the file (see |
075746e2 KM |
6068 | `epa-file-encrypt-to') or the function is invoked with a |
6069 | \(KEYMODE-CUE) universal argument greater than 1. | |
d82979ea | 6070 | |
075746e2 KM |
6071 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
6072 | causes prompting for recipients for public-key keypair | |
6073 | encryption. Selecting no recipients results in symmetric key | |
6074 | encryption. | |
0949617b | 6075 | |
075746e2 KM |
6076 | Further, encrypting with a KEYMODE-CUE universal argument greater |
6077 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
6078 | the specified recipients with the file, replacing those currently | |
99d99081 | 6079 | associated with it. This can be used to dissociate any |
075746e2 KM |
6080 | recipients with the file, by selecting no recipients in the |
6081 | dialog. | |
d82979ea | 6082 | |
29fac3fe | 6083 | Optional REJECTED is for internal use, to convey the number of |
48bd8440 EZ |
6084 | rejections due to matches against |
6085 | `allout-encryption-ciphertext-rejection-regexps', as limited by | |
6086 | `allout-encryption-ciphertext-rejection-ceiling'. | |
6087 | ||
2576c28f KM |
6088 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
6089 | symmetric decryption keys, preventing entry of the correct key on | |
6090 | subsequent decryption attempts until the cache times-out. That | |
20db1522 | 6091 | can take several minutes. (Decryption of other entries is not |
2576c28f KM |
6092 | affected.) Upgrade your EasyPG version, if you can, and you can |
6093 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
6094 | signal." | |
48bd8440 | 6095 | |
ff3e8c8e | 6096 | (require 'epg) |
29fac3fe | 6097 | (require 'epa) |
0949617b | 6098 | |
075746e2 KM |
6099 | (let* ((epg-context (let* ((context (epg-make-context nil t))) |
6100 | (epg-context-set-passphrase-callback | |
6101 | context #'epa-passphrase-callback-function) | |
6102 | context)) | |
13aa217b | 6103 | |
498a6493 CY |
6104 | (encoding (with-current-buffer allout-buffer |
6105 | buffer-file-coding-system)) | |
6106 | (multibyte (with-current-buffer allout-buffer | |
ff3e8c8e | 6107 | enable-multibyte-characters)) |
29fac3fe KM |
6108 | ;; "sanitization" avoids encryption results that are outline structure. |
6109 | (sani-regexps 'allout-encryption-plaintext-sanitization-regexps) | |
6110 | (strip-plaintext-regexps (if (not decrypt) | |
6111 | (allout-get-configvar-values | |
6112 | sani-regexps))) | |
6113 | (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps) | |
6114 | (reject-ciphertext-regexps (if (not decrypt) | |
6115 | (allout-get-configvar-values | |
6116 | rejection-regexps))) | |
48bd8440 EZ |
6117 | (rejected (or rejected 0)) |
6118 | (rejections-left (- allout-encryption-ciphertext-rejection-ceiling | |
6119 | rejected)) | |
075746e2 KM |
6120 | (keypair-mode (cond (decrypt 'decrypting) |
6121 | ((<= (prefix-numeric-value keymode-cue) 1) | |
6122 | 'default) | |
6123 | ((<= (prefix-numeric-value keymode-cue) 4) | |
6124 | 'prompt) | |
6125 | ((> (prefix-numeric-value keymode-cue) 4) | |
6126 | 'prompt-save))) | |
6127 | (keypair-message (concat "Select encryption recipients.\n" | |
6128 | "Symmetric encryption is done if no" | |
6129 | " recipients are selected. ")) | |
6130 | (encrypt-to (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to)) | |
29fac3fe KM |
6131 | recipients |
6132 | massaged-text | |
6133 | result-text | |
38b2ca53 | 6134 | ) |
0949617b | 6135 | |
ff3e8c8e KM |
6136 | ;; Massage the subject text for encoding and filtering. |
6137 | (with-temp-buffer | |
6138 | (insert text) | |
6139 | ;; convey the text characteristics of the original buffer: | |
96497653 | 6140 | (set-buffer-multibyte multibyte) |
ff3e8c8e KM |
6141 | (when encoding |
6142 | (set-buffer-file-coding-system encoding) | |
6143 | (if (not decrypt) | |
6144 | (encode-coding-region (point-min) (point-max) encoding))) | |
6145 | ||
6146 | ;; remove sanitization regexps matches before encrypting: | |
6147 | (when (and strip-plaintext-regexps (not decrypt)) | |
6148 | (dolist (re strip-plaintext-regexps) | |
6149 | (let ((re (if (listp re) (car re) re)) | |
6150 | (replacement (if (listp re) (cadr re) ""))) | |
6151 | (goto-char (point-min)) | |
6152 | (save-match-data | |
6153 | (while (re-search-forward re nil t) | |
6154 | (replace-match replacement nil nil)))))) | |
6155 | (setq massaged-text (buffer-substring-no-properties (point-min) | |
6156 | (point-max)))) | |
075746e2 KM |
6157 | ;; determine key mode and, if keypair, recipients: |
6158 | (setq recipients | |
6159 | (case keypair-mode | |
6160 | ||
6161 | (decrypting nil) | |
6162 | ||
6163 | (default (if encrypt-to (epg-list-keys epg-context encrypt-to))) | |
6164 | ||
6165 | ((prompt prompt-save) | |
6166 | (save-window-excursion | |
6167 | (epa-select-keys epg-context keypair-message))))) | |
6168 | ||
ff3e8c8e | 6169 | (setq result-text |
ff3e8c8e | 6170 | (if decrypt |
2a095cec KM |
6171 | (condition-case err |
6172 | (epg-decrypt-string epg-context | |
6173 | (encode-coding-string massaged-text | |
6174 | (or encoding 'utf-8))) | |
6175 | (epg-error | |
6176 | (signal 'egp-error | |
6177 | (cons (concat (cadr err) " - gpg version problem?") | |
6178 | (cddr err))))) | |
0af8c88b KM |
6179 | (replace-regexp-in-string "\n$" "" |
6180 | (epg-encrypt-string epg-context | |
6181 | (encode-coding-string massaged-text | |
6182 | (or encoding 'utf-8)) | |
6183 | recipients)))) | |
ff3e8c8e KM |
6184 | |
6185 | ;; validate result -- non-empty | |
075746e2 KM |
6186 | (if (not result-text) |
6187 | (error "%scryption failed." (if decrypt "De" "En"))) | |
6188 | ||
29fac3fe | 6189 | |
075746e2 KM |
6190 | (when (eq keypair-mode 'prompt-save) |
6191 | ;; set epa-file-encrypt-to in the buffer: | |
6192 | (setq epa-file-encrypt-to (mapcar (lambda (key) | |
6193 | (epg-user-id-string | |
6194 | (car (epg-key-user-id-list key)))) | |
6195 | recipients)) | |
6196 | ;; change the file variable: | |
6197 | (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to)) | |
d82979ea | 6198 | |
075746e2 | 6199 | (cond |
29fac3fe KM |
6200 | ;; Retry (within limit) if ciphertext contains rejections: |
6201 | ((and (not decrypt) | |
6202 | ;; Check for disqualification of this ciphertext: | |
6203 | (let ((regexps reject-ciphertext-regexps) | |
6204 | reject-it) | |
6205 | (while (and regexps (not reject-it)) | |
6206 | (setq reject-it (string-match (car regexps) result-text)) | |
6207 | (pop regexps)) | |
6208 | reject-it)) | |
6209 | (setq rejections-left (1- rejections-left)) | |
6210 | (if (<= rejections-left 0) | |
6211 | (error (concat "Ciphertext rejected too many times" | |
6212 | " (%s), per `%s'") | |
6213 | allout-encryption-ciphertext-rejection-ceiling | |
6214 | 'allout-encryption-ciphertext-rejection-regexps) | |
6215 | ;; try again (gpg-agent may have the key cached): | |
6216 | (allout-encrypt-string text decrypt allout-buffer keypair-mode | |
6217 | (1+ rejected)))) | |
6218 | ||
6219 | ;; Barf if encryption yields extraordinary control chars: | |
6220 | ((and (not decrypt) | |
6221 | (string-match "[\C-a\C-k\C-o-\C-z\C-@]" | |
6222 | result-text)) | |
6223 | (error (concat "Encryption produced non-armored text, which" | |
6224 | "conflicts with allout mode -- reconfigure!"))) | |
29fac3fe | 6225 | (t result-text)))) |
13aa217b KM |
6226 | ;;;_ > allout-inhibit-auto-save-info-for-decryption |
6227 | (defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size) | |
6228 | "Temporarily prevent auto-saves in this buffer when an item is decrypted. | |
6229 | ||
20db1522 | 6230 | WAS-BUFFER-SAVED-SIZE is the value of `buffer-saved-size' *before* |
13aa217b KM |
6231 | the decryption." |
6232 | (when (not (or (= buffer-saved-size -1) (= was-buffer-saved-size -1))) | |
6233 | (setq allout-auto-save-temporarily-disabled was-buffer-saved-size | |
6234 | buffer-saved-size -1))) | |
6235 | ;;;_ > allout-maybe-resume-auto-save-info-after-encryption () | |
6236 | (defun allout-maybe-resume-auto-save-info-after-encryption () | |
6237 | "Restore auto-save info, *if* there are no topics pending encryption." | |
6238 | (when (and allout-auto-save-temporarily-disabled | |
6239 | (= buffer-saved-size -1) | |
6240 | (save-excursion | |
6241 | (save-restriction | |
6242 | (widen) | |
6243 | (goto-char (point-min)) | |
6244 | (not (allout-next-topic-pending-encryption))))) | |
6245 | (setq buffer-saved-size allout-auto-save-temporarily-disabled | |
6246 | allout-auto-save-temporarily-disabled nil))) | |
6247 | ||
d82979ea EZ |
6248 | ;;;_ > allout-encrypted-topic-p () |
6249 | (defun allout-encrypted-topic-p () | |
6250 | "True if the current topic is encryptable and encrypted." | |
6251 | (save-excursion | |
6252 | (allout-end-of-prefix t) | |
6253 | (and (string= (buffer-substring-no-properties (1- (point)) (point)) | |
6254 | allout-topic-encryption-bullet) | |
2a1408fd | 6255 | (save-match-data (looking-at "\\*"))) |
d82979ea EZ |
6256 | ) |
6257 | ) | |
13aa217b KM |
6258 | ;;;_ > allout-next-topic-pending-encryption () |
6259 | (defun allout-next-topic-pending-encryption () | |
d82979ea EZ |
6260 | "Return the point of the next topic pending encryption, or nil if none. |
6261 | ||
75bcb912 | 6262 | Such a topic has the `allout-topic-encryption-bullet' without an |
20db1522 JB |
6263 | immediately following '*' that would mark the topic as being encrypted. |
6264 | It must also have content." | |
d82979ea | 6265 | (let (done got content-beg) |
2a1408fd DN |
6266 | (save-match-data |
6267 | (while (not done) | |
d82979ea | 6268 | |
2a1408fd DN |
6269 | (if (not (re-search-forward |
6270 | (format "\\(\\`\\|\n\\)%s *%s[^*]" | |
6271 | (regexp-quote allout-header-prefix) | |
6272 | (regexp-quote allout-topic-encryption-bullet)) | |
6273 | nil t)) | |
6274 | (setq got nil | |
6275 | done t) | |
6276 | (goto-char (setq got (match-beginning 0))) | |
6277 | (if (save-match-data (looking-at "\n")) | |
6278 | (forward-char 1)) | |
6279 | (setq got (point))) | |
6280 | ||
6281 | (cond ((not got) | |
6282 | (setq done t)) | |
6283 | ||
6284 | ((not (search-forward "\n")) | |
6285 | (setq got nil | |
6286 | done t)) | |
6287 | ||
6288 | ((eobp) | |
6289 | (setq got nil | |
6290 | done t)) | |
6291 | ||
6292 | (t | |
6293 | (setq content-beg (point)) | |
6294 | (backward-char 1) | |
6295 | (allout-end-of-subtree) | |
13aa217b | 6296 | (if (<= (point) content-beg) |
2a1408fd DN |
6297 | ;; Continue looking |
6298 | (setq got nil) | |
6299 | ;; Got it! | |
6300 | (setq done t))) | |
6301 | ) | |
6302 | ) | |
6303 | (if got | |
6304 | (goto-char got)) | |
d82979ea | 6305 | ) |
d82979ea EZ |
6306 | ) |
6307 | ) | |
13aa217b KM |
6308 | ;;;_ > allout-encrypt-decrypted () |
6309 | (defun allout-encrypt-decrypted () | |
d82979ea EZ |
6310 | "Encrypt topics pending encryption except those containing exemption point. |
6311 | ||
d82979ea EZ |
6312 | If a topic that is currently being edited was encrypted, we return a list |
6313 | containing the location of the topic and the location of the cursor just | |
6314 | before the topic was encrypted. This can be used, eg, to decrypt the topic | |
6315 | and exactly resituate the cursor if this is being done as part of a file | |
6316 | save. See `allout-encrypt-unencrypted-on-saves' for more info." | |
6317 | ||
6318 | (interactive "p") | |
2a1408fd DN |
6319 | (save-match-data |
6320 | (save-excursion | |
6321 | (let* ((current-mark (point-marker)) | |
6322 | (current-mark-position (marker-position current-mark)) | |
6323 | was-modified | |
6324 | bo-subtree | |
6325 | editing-topic editing-point) | |
6326 | (goto-char (point-min)) | |
13aa217b | 6327 | (while (allout-next-topic-pending-encryption) |
2a1408fd DN |
6328 | (setq was-modified (buffer-modified-p)) |
6329 | (when (save-excursion | |
6330 | (and (boundp 'allout-encrypt-unencrypted-on-saves) | |
6331 | allout-encrypt-unencrypted-on-saves | |
6332 | (setq bo-subtree (re-search-forward "$")) | |
6333 | (not (allout-hidden-p)) | |
6334 | (>= current-mark (point)) | |
6335 | (allout-end-of-current-subtree) | |
6336 | (<= current-mark (point)))) | |
d82979ea EZ |
6337 | (setq editing-topic (point) |
6338 | ;; we had to wait for this 'til now so prior topics are | |
6339 | ;; encrypted, any relevant text shifts are in place: | |
96b83743 EZ |
6340 | editing-point (- current-mark-position |
6341 | (count-trailing-whitespace-region | |
6342 | bo-subtree current-mark-position)))) | |
2a1408fd DN |
6343 | (allout-toggle-subtree-encryption) |
6344 | (if (not was-modified) | |
6345 | (set-buffer-modified-p nil)) | |
6346 | ) | |
d82979ea EZ |
6347 | (if (not was-modified) |
6348 | (set-buffer-modified-p nil)) | |
2a1408fd | 6349 | (if editing-topic (list editing-topic editing-point)) |
d82979ea | 6350 | ) |
d82979ea EZ |
6351 | ) |
6352 | ) | |
6353 | ) | |
6354 | ||
6355 | ;;;_ #9 miscellaneous | |
d8350998 CY |
6356 | ;;;_ : Mode: |
6357 | ;;;_ > outlineify-sticky () | |
19b84ba3 | 6358 | ;; outlinify-sticky is correct spelling; provide this alias for sticklers: |
0949617b | 6359 | ;;;###autoload |
19b84ba3 | 6360 | (defalias 'outlinify-sticky 'outlineify-sticky) |
0949617b | 6361 | ;;;###autoload |
c567ac01 | 6362 | (defun outlineify-sticky (&optional arg) |
a0776d6b | 6363 | "Activate outline mode and establish file var so it is started subsequently. |
1977b8f6 | 6364 | |
11c46e15 | 6365 | See `allout-layout' and customization of `allout-auto-activation' |
20db1522 | 6366 | for details on preparing Emacs for automatic allout activation." |
19b84ba3 RS |
6367 | |
6368 | (interactive "P") | |
6369 | ||
2576c28f KM |
6370 | (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate... |
6371 | (allout-mode) | |
19b84ba3 RS |
6372 | |
6373 | (save-excursion | |
6374 | (goto-char (point-min)) | |
ede4ac6a | 6375 | (if (allout-goto-prefix) |
19b84ba3 | 6376 | t |
fd5359c6 | 6377 | (allout-open-topic 2) |
60c7bbd2 | 6378 | (insert (concat "Dummy outline topic header -- see" |
d82979ea EZ |
6379 | "`allout-mode' docstring: `^Hm'.")) |
6380 | (allout-adjust-file-variable | |
4034b0e2 | 6381 | "allout-layout" (or allout-layout '(-1 : 0)))))) |
d8350998 | 6382 | ;;;_ > allout-file-vars-section-data () |
d82979ea EZ |
6383 | (defun allout-file-vars-section-data () |
6384 | "Return data identifying the file-vars section, or nil if none. | |
6385 | ||
60c7bbd2 | 6386 | Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)." |
d82979ea EZ |
6387 | ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function. |
6388 | (let (beg prefix suffix) | |
6389 | (save-excursion | |
1977b8f6 | 6390 | (goto-char (point-max)) |
d82979ea EZ |
6391 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
6392 | (if (let ((case-fold-search t)) | |
6393 | (not (search-forward "Local Variables:" nil t))) | |
6394 | nil | |
6395 | (setq beg (- (point) 16)) | |
6396 | (setq suffix (buffer-substring-no-properties | |
6397 | (point) | |
96b83743 | 6398 | (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6399 | (forward-char -1)) |
6400 | (point)))) | |
6401 | (setq prefix (buffer-substring-no-properties | |
96b83743 | 6402 | (progn (if (search-backward "\n" nil t) |
d82979ea EZ |
6403 | (forward-char 1)) |
6404 | (point)) | |
6405 | beg)) | |
6406 | (list beg prefix suffix)) | |
6407 | ) | |
6408 | ) | |
6409 | ) | |
d8350998 | 6410 | ;;;_ > allout-adjust-file-variable (varname value) |
d82979ea | 6411 | (defun allout-adjust-file-variable (varname value) |
a0a022d5 | 6412 | "Adjust the setting of an Emacs file variable named VARNAME to VALUE. |
d82979ea | 6413 | |
20db1522 | 6414 | This activity is inhibited if either `enable-local-variables' or |
d82979ea EZ |
6415 | `allout-enable-file-variable-adjustment' are nil. |
6416 | ||
6417 | When enabled, an entry for the variable is created if not already present, | |
6418 | or changed if established with a different value. The section for the file | |
6419 | variables, itself, is created if not already present. When created, the | |
c07583cd | 6420 | section lines (including the section line) exist as second-level topics in |
d82979ea EZ |
6421 | a top-level topic at the end of the file. |
6422 | ||
a0a022d5 | 6423 | `enable-local-variables' must be true for any of this to happen." |
d82979ea EZ |
6424 | (if (not (and enable-local-variables |
6425 | allout-enable-file-variable-adjustment)) | |
6426 | nil | |
6427 | (save-excursion | |
0458fa80 EZ |
6428 | (let ((inhibit-field-text-motion t) |
6429 | (section-data (allout-file-vars-section-data)) | |
d82979ea EZ |
6430 | beg prefix suffix) |
6431 | (if section-data | |
6432 | (setq beg (car section-data) | |
6433 | prefix (cadr section-data) | |
6434 | suffix (car (cddr section-data))) | |
6435 | ;; create the section | |
6436 | (goto-char (point-max)) | |
6437 | (open-line 1) | |
6438 | (allout-open-topic 0) | |
6439 | (end-of-line) | |
6440 | (insert "Local emacs vars.\n") | |
6441 | (allout-open-topic 1) | |
6442 | (setq beg (point) | |
6443 | suffix "" | |
6444 | prefix (buffer-substring-no-properties (progn | |
6445 | (beginning-of-line) | |
6446 | (point)) | |
6447 | beg)) | |
6448 | (goto-char beg) | |
6449 | (insert "Local variables:\n") | |
6450 | (allout-open-topic 0) | |
6451 | (insert "End:\n") | |
6452 | ) | |
6453 | ;; look for existing entry or create one, leaving point for insertion | |
6454 | ;; of new value: | |
6455 | (goto-char beg) | |
6456 | (allout-show-to-offshoot) | |
6457 | (if (search-forward (concat "\n" prefix varname ":") nil t) | |
6458 | (let* ((value-beg (point)) | |
96b83743 | 6459 | (line-end (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6460 | (forward-char -1)) |
6461 | (point))) | |
6462 | (value-end (- line-end (length suffix)))) | |
6463 | (if (> value-end value-beg) | |
6464 | (delete-region value-beg value-end))) | |
6465 | (end-of-line) | |
6466 | (open-line 1) | |
6467 | (forward-line 1) | |
6468 | (insert (concat prefix varname ":"))) | |
6469 | (insert (format " %S%s" value suffix)) | |
6470 | ) | |
6471 | ) | |
6472 | ) | |
6473 | ) | |
d8350998 CY |
6474 | ;;;_ > allout-get-configvar-values (varname) |
6475 | (defun allout-get-configvar-values (configvar-name) | |
6476 | "Return a list of values of the symbols in list bound to CONFIGVAR-NAME. | |
6477 | ||
6478 | The user is prompted for removal of symbols that are unbound, and they | |
6479 | otherwise are ignored. | |
6480 | ||
6481 | CONFIGVAR-NAME should be the name of the configuration variable, | |
6482 | not its value." | |
6483 | ||
6484 | (let ((configvar-value (symbol-value configvar-name)) | |
6485 | got) | |
6486 | (dolist (sym configvar-value) | |
6487 | (if (not (boundp sym)) | |
60c7bbd2 | 6488 | (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? " |
d8350998 CY |
6489 | configvar-name sym)) |
6490 | (delq sym (symbol-value configvar-name))) | |
6491 | (push (symbol-value sym) got))) | |
6492 | (reverse got))) | |
6493 | ;;;_ : Topics: | |
6494 | ;;;_ > allout-mark-topic () | |
6495 | (defun allout-mark-topic () | |
6496 | "Put the region around topic currently containing point." | |
6497 | (interactive) | |
6498 | (let ((inhibit-field-text-motion t)) | |
6499 | (beginning-of-line)) | |
6500 | (allout-goto-prefix-doublechecked) | |
6501 | (push-mark (point)) | |
6502 | (allout-end-of-current-subtree) | |
6503 | (exchange-point-and-mark)) | |
6504 | ;;;_ : UI: | |
6505 | ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting) | |
1977b8f6 | 6506 | (defun solicit-char-in-string (prompt string &optional do-defaulting) |
c567ac01 | 6507 | "Solicit (with first arg PROMPT) choice of a character from string STRING. |
1977b8f6 | 6508 | |
c567ac01 | 6509 | Optional arg DO-DEFAULTING indicates to accept empty input (CR)." |
1977b8f6 RS |
6510 | |
6511 | (let ((new-prompt prompt) | |
6512 | got) | |
6513 | ||
6514 | (while (not got) | |
6515 | (message "%s" new-prompt) | |
6516 | ||
6517 | ;; We do our own reading here, so we can circumvent, eg, special | |
9179616f | 6518 | ;; treatment for `?' character. (Oughta use minibuffer keymap instead.) |
1977b8f6 | 6519 | (setq got |
c567ac01 | 6520 | (char-to-string (let ((cursor-in-echo-area nil)) (read-char)))) |
1977b8f6 | 6521 | |
9179616f DL |
6522 | (setq got |
6523 | (cond ((string-match (regexp-quote got) string) got) | |
6524 | ((and do-defaulting (string= got "\r")) | |
6525 | ;; Return empty string to default: | |
6526 | "") | |
6527 | ((string= got "\C-g") (signal 'quit nil)) | |
6528 | (t | |
6529 | (setq new-prompt (concat prompt | |
6530 | got | |
6531 | " ...pick from: " | |
6532 | string | |
6533 | "")) | |
6534 | nil)))) | |
60c7bbd2 | 6535 | ;; got something out of loop -- return it: |
9179616f | 6536 | got) |
1977b8f6 | 6537 | ) |
d8350998 CY |
6538 | ;;;_ : Strings: |
6539 | ;;;_ > regexp-sans-escapes (string) | |
c567ac01 RS |
6540 | (defun regexp-sans-escapes (regexp &optional successive-backslashes) |
6541 | "Return a copy of REGEXP with all character escapes stripped out. | |
19b84ba3 | 6542 | |
60c7bbd2 | 6543 | Representations of actual backslashes -- '\\\\\\\\' -- are left as a |
c567ac01 RS |
6544 | single backslash. |
6545 | ||
d82979ea | 6546 | Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion." |
c567ac01 RS |
6547 | |
6548 | (if (string= regexp "") | |
6549 | "" | |
6550 | ;; Set successive-backslashes to number if current char is | |
6551 | ;; backslash, or else to nil: | |
6552 | (setq successive-backslashes | |
6553 | (if (= (aref regexp 0) ?\\) | |
6554 | (if successive-backslashes (1+ successive-backslashes) 1) | |
6555 | nil)) | |
6556 | (if (or (not successive-backslashes) (= 2 successive-backslashes)) | |
6557 | ;; Include first char: | |
6558 | (concat (substring regexp 0 1) | |
6559 | (regexp-sans-escapes (substring regexp 1))) | |
6560 | ;; Exclude first char, but maintain count: | |
6561 | (regexp-sans-escapes (substring regexp 1) successive-backslashes)))) | |
d8350998 | 6562 | ;;;_ > count-trailing-whitespace-region (beg end) |
96b83743 EZ |
6563 | (defun count-trailing-whitespace-region (beg end) |
6564 | "Return number of trailing whitespace chars between BEG and END. | |
6565 | ||
6566 | If BEG is bigger than END we return 0." | |
6567 | (if (> beg end) | |
6568 | 0 | |
2a1408fd DN |
6569 | (save-match-data |
6570 | (save-excursion | |
6571 | (goto-char beg) | |
6572 | (let ((count 0)) | |
6573 | (while (re-search-forward "[ ][ ]*$" end t) | |
6574 | (goto-char (1+ (match-beginning 2))) | |
6575 | (setq count (1+ count))) | |
6576 | count))))) | |
d8350998 CY |
6577 | ;;;_ > allout-format-quote (string) |
6578 | (defun allout-format-quote (string) | |
6579 | "Return a copy of string with all \"%\" characters doubled." | |
6580 | (apply 'concat | |
6581 | (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char))) | |
6582 | string))) | |
6583 | ;;;_ : lists | |
6584 | ;;;_ > allout-flatten (list) | |
6585 | (defun allout-flatten (list) | |
6586 | "Return a list of all atoms in list." | |
6587 | ;; classic. | |
6588 | (cond ((null list) nil) | |
8a559d4e EZ |
6589 | ((atom (car list)) (cons (car list) (allout-flatten (cdr list)))) |
6590 | (t (append (allout-flatten (car list)) (allout-flatten (cdr list)))))) | |
75bcb912 | 6591 | ;;;_ : Compatibility: |
1c9b9df0 KM |
6592 | ;;;_ : xemacs undo-in-progress provision: |
6593 | (unless (boundp 'undo-in-progress) | |
6594 | (defvar undo-in-progress nil | |
6595 | "Placeholder defvar for XEmacs compatibility from allout.el.") | |
6596 | (defadvice undo-more (around allout activate) | |
6597 | ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs. | |
6598 | (let ((undo-in-progress t)) ad-do-it))) | |
6599 | ||
d8350998 | 6600 | ;;;_ > allout-mark-marker to accommodate divergent emacsen: |
96b83743 EZ |
6601 | (defun allout-mark-marker (&optional force buffer) |
6602 | "Accommodate the different signature for `mark-marker' across Emacsen. | |
6603 | ||
3bda1277 | 6604 | XEmacs takes two optional args, while Emacs does not, |
96b83743 EZ |
6605 | so pass them along when appropriate." |
6606 | (if (featurep 'xemacs) | |
6607 | (apply 'mark-marker force buffer) | |
6608 | (mark-marker))) | |
d8350998 | 6609 | ;;;_ > subst-char-in-string if necessary |
d82979ea EZ |
6610 | (if (not (fboundp 'subst-char-in-string)) |
6611 | (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
6612 | "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
6613 | Unless optional argument INPLACE is non-nil, return a new string." | |
6614 | (let ((i (length string)) | |
6615 | (newstr (if inplace string (copy-sequence string)))) | |
6616 | (while (> i 0) | |
6617 | (setq i (1- i)) | |
6618 | (if (eq (aref newstr i) fromchar) | |
6619 | (aset newstr i tochar))) | |
6620 | newstr))) | |
d8350998 | 6621 | ;;;_ > wholenump if necessary |
96b83743 EZ |
6622 | (if (not (fboundp 'wholenump)) |
6623 | (defalias 'wholenump 'natnump)) | |
d8350998 | 6624 | ;;;_ > remove-overlays if necessary |
96b83743 EZ |
6625 | (if (not (fboundp 'remove-overlays)) |
6626 | (defun remove-overlays (&optional beg end name val) | |
6627 | "Clear BEG and END of overlays whose property NAME has value VAL. | |
6628 | Overlays might be moved and/or split. | |
6629 | BEG and END default respectively to the beginning and end of buffer." | |
6630 | (unless beg (setq beg (point-min))) | |
6631 | (unless end (setq end (point-max))) | |
6632 | (if (< end beg) | |
6633 | (setq beg (prog1 end (setq end beg)))) | |
6634 | (save-excursion | |
6635 | (dolist (o (overlays-in beg end)) | |
6636 | (when (eq (overlay-get o name) val) | |
6637 | ;; Either push this overlay outside beg...end | |
6638 | ;; or split it to exclude beg...end | |
6639 | ;; or delete it entirely (if it is contained in beg...end). | |
6640 | (if (< (overlay-start o) beg) | |
6641 | (if (> (overlay-end o) end) | |
6642 | (progn | |
6643 | (move-overlay (copy-overlay o) | |
6644 | (overlay-start o) beg) | |
6645 | (move-overlay o end (overlay-end o))) | |
6646 | (move-overlay o (overlay-start o) beg)) | |
6647 | (if (> (overlay-end o) end) | |
6648 | (move-overlay o end (overlay-end o)) | |
6649 | (delete-overlay o))))))) | |
6650 | ) | |
60c7bbd2 | 6651 | ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6652 | (if (not (fboundp 'copy-overlay)) |
6653 | (defun copy-overlay (o) | |
6654 | "Return a copy of overlay O." | |
6655 | (let ((o1 (make-overlay (overlay-start o) (overlay-end o) | |
6656 | ;; FIXME: there's no easy way to find the | |
6657 | ;; insertion-type of the two markers. | |
6658 | (overlay-buffer o))) | |
6659 | (props (overlay-properties o))) | |
6660 | (while props | |
6661 | (overlay-put o1 (pop props) (pop props))) | |
6662 | o1))) | |
60c7bbd2 | 6663 | ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6664 | (if (not (fboundp 'add-to-invisibility-spec)) |
6665 | (defun add-to-invisibility-spec (element) | |
6666 | "Add ELEMENT to `buffer-invisibility-spec'. | |
6667 | See documentation for `buffer-invisibility-spec' for the kind of elements | |
6668 | that can be added." | |
6669 | (if (eq buffer-invisibility-spec t) | |
6670 | (setq buffer-invisibility-spec (list t))) | |
6671 | (setq buffer-invisibility-spec | |
6672 | (cons element buffer-invisibility-spec)))) | |
60c7bbd2 | 6673 | ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6674 | (if (not (fboundp 'remove-from-invisibility-spec)) |
6675 | (defun remove-from-invisibility-spec (element) | |
6676 | "Remove ELEMENT from `buffer-invisibility-spec'." | |
6677 | (if (consp buffer-invisibility-spec) | |
6678 | (setq buffer-invisibility-spec (delete element | |
6679 | buffer-invisibility-spec))))) | |
60c7bbd2 | 6680 | ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs |
96b83743 EZ |
6681 | (if (not (fboundp 'move-beginning-of-line)) |
6682 | (defun move-beginning-of-line (arg) | |
6683 | "Move point to beginning of current line as displayed. | |
6684 | \(This disregards invisible newlines such as those | |
6685 | which are part of the text that an image rests on.) | |
6686 | ||
6687 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6688 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6689 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6690 | (interactive "p") |
6691 | (or arg (setq arg 1)) | |
6692 | (if (/= arg 1) | |
6693 | (condition-case nil (line-move (1- arg)) (error nil))) | |
6694 | ||
99d99081 | 6695 | ;; Move to beginning-of-line, ignoring fields and invisible text. |
8570ce80 | 6696 | (skip-chars-backward "^\n") |
2a1408fd DN |
6697 | (while (and (not (bobp)) |
6698 | (let ((prop | |
6699 | (get-char-property (1- (point)) 'invisible))) | |
6700 | (if (eq buffer-invisibility-spec t) | |
6701 | prop | |
6702 | (or (memq prop buffer-invisibility-spec) | |
6703 | (assq prop buffer-invisibility-spec))))) | |
8570ce80 SM |
6704 | (goto-char (if (featurep 'xemacs) |
6705 | (previous-property-change (point)) | |
6706 | (previous-char-property-change (point)))) | |
6707 | (skip-chars-backward "^\n")) | |
6708 | (vertical-motion 0)) | |
96b83743 | 6709 | ) |
9b026d9f | 6710 | ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs |
96b83743 EZ |
6711 | (if (not (fboundp 'move-end-of-line)) |
6712 | (defun move-end-of-line (arg) | |
6713 | "Move point to end of current line as displayed. | |
6714 | \(This disregards invisible newlines such as those | |
6715 | which are part of the text that an image rests on.) | |
6716 | ||
6717 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6718 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6719 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6720 | (interactive "p") |
6721 | (or arg (setq arg 1)) | |
8570ce80 | 6722 | (let (done) |
96b83743 EZ |
6723 | (while (not done) |
6724 | (let ((newpos | |
6725 | (save-excursion | |
6726 | (let ((goal-column 0)) | |
6727 | (and (condition-case nil | |
6728 | (or (line-move arg) t) | |
6729 | (error nil)) | |
6730 | (not (bobp)) | |
6731 | (progn | |
2a1408fd DN |
6732 | (while |
6733 | (and | |
6734 | (not (bobp)) | |
6735 | (let ((prop | |
6736 | (get-char-property (1- (point)) | |
6737 | 'invisible))) | |
6738 | (if (eq buffer-invisibility-spec t) | |
6739 | prop | |
6740 | (or (memq prop | |
6741 | buffer-invisibility-spec) | |
6742 | (assq prop | |
6743 | buffer-invisibility-spec))))) | |
8570ce80 SM |
6744 | (goto-char |
6745 | (previous-char-property-change (point)))) | |
96b83743 EZ |
6746 | (backward-char 1))) |
6747 | (point))))) | |
6748 | (goto-char newpos) | |
6749 | (if (and (> (point) newpos) | |
6750 | (eq (preceding-char) ?\n)) | |
6751 | (backward-char 1) | |
6752 | (if (and (> (point) newpos) (not (eobp)) | |
6753 | (not (eq (following-char) ?\n))) | |
6754 | ;; If we skipped something intangible | |
6755 | ;; and now we're not really at eol, | |
6756 | ;; keep going. | |
6757 | (setq arg 1) | |
8570ce80 | 6758 | (setq done t))))))) |
96b83743 | 6759 | ) |
1c9b9df0 KM |
6760 | ;;;_ > allout-next-single-char-property-change -- alias unless lacking |
6761 | (defalias 'allout-next-single-char-property-change | |
6762 | (if (fboundp 'next-single-char-property-change) | |
6763 | 'next-single-char-property-change | |
6764 | 'next-single-property-change) | |
6765 | ;; No docstring because xemacs defalias doesn't support it. | |
6766 | ) | |
6767 | ;;;_ > allout-previous-single-char-property-change -- alias unless lacking | |
6768 | (defalias 'allout-previous-single-char-property-change | |
6769 | (if (fboundp 'previous-single-char-property-change) | |
6770 | 'previous-single-char-property-change | |
6771 | 'previous-single-property-change) | |
6772 | ;; No docstring because xemacs defalias doesn't support it. | |
6773 | ) | |
1c9b9df0 KM |
6774 | ;;;_ > allout-select-safe-coding-system |
6775 | (defalias 'allout-select-safe-coding-system | |
6776 | (if (fboundp 'select-safe-coding-system) | |
6777 | 'select-safe-coding-system | |
6778 | 'detect-coding-region) | |
6779 | ) | |
6780 | ;;;_ > allout-substring-no-properties | |
6781 | ;; define as alias first, so byte compiler is happy. | |
6782 | (defalias 'allout-substring-no-properties 'substring-no-properties) | |
6783 | ;; then supplant with definition if underlying alias absent. | |
6784 | (if (not (fboundp 'substring-no-properties)) | |
6785 | (defun allout-substring-no-properties (string &optional start end) | |
6786 | (substring string (or start 0) end)) | |
6787 | ) | |
96b83743 | 6788 | |
96b83743 | 6789 | ;;;_ #10 Unfinished |
fd5359c6 MR |
6790 | ;;;_ > allout-bullet-isearch (&optional bullet) |
6791 | (defun allout-bullet-isearch (&optional bullet) | |
c07583cd | 6792 | "Isearch (regexp) for topic with bullet BULLET." |
c567ac01 RS |
6793 | (interactive) |
6794 | (if (not bullet) | |
6795 | (setq bullet (solicit-char-in-string | |
6796 | "ISearch for topic with bullet: " | |
fd5359c6 | 6797 | (regexp-sans-escapes allout-bullets-string)))) |
353e2ef2 | 6798 | |
c567ac01 RS |
6799 | (let ((isearch-regexp t) |
6800 | (isearch-string (concat "^" | |
fd5359c6 | 6801 | allout-header-prefix |
c567ac01 RS |
6802 | "[ \t]*" |
6803 | bullet))) | |
6804 | (isearch-repeat 'forward) | |
6805 | (isearch-mode t))) | |
96b83743 | 6806 | |
60c7bbd2 | 6807 | ;;;_ #11 Unit tests -- this should be last item before "Provide" |
01fc9422 EZ |
6808 | ;;;_ > allout-run-unit-tests () |
6809 | (defun allout-run-unit-tests () | |
6810 | "Run the various allout unit tests." | |
6811 | (message "Running allout tests...") | |
6812 | (allout-test-resumptions) | |
6813 | (message "Running allout tests... Done.") | |
6814 | (sit-for .5)) | |
6815 | ;;;_ : test resumptions: | |
6816 | ;;;_ > allout-tests-obliterate-variable (name) | |
6817 | (defun allout-tests-obliterate-variable (name) | |
6818 | "Completely unbind variable with NAME." | |
1c9b9df0 | 6819 | (if (local-variable-p name (current-buffer)) (kill-local-variable name)) |
01fc9422 EZ |
6820 | (while (boundp name) (makunbound name))) |
6821 | ;;;_ > allout-test-resumptions () | |
6822 | (defvar allout-tests-globally-unbound nil | |
60c7bbd2 | 6823 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6824 | (defvar allout-tests-globally-true nil |
60c7bbd2 | 6825 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6826 | (defvar allout-tests-locally-true nil |
60c7bbd2 | 6827 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 EZ |
6828 | (defun allout-test-resumptions () |
6829 | "Exercise allout resumptions." | |
6830 | ;; for each resumption case, we also test that the right local/global | |
6831 | ;; scopes are affected during resumption effects: | |
6832 | ||
6833 | ;; ensure that previously unbound variables return to the unbound state. | |
6834 | (with-temp-buffer | |
6835 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6836 | (allout-add-resumptions '(allout-tests-globally-unbound t)) | |
6837 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6838 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6839 | (assert (boundp 'allout-tests-globally-unbound)) |
6840 | (assert (equal allout-tests-globally-unbound t)) | |
6841 | (allout-do-resumptions) | |
1c9b9df0 KM |
6842 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6843 | (current-buffer)))) | |
01fc9422 EZ |
6844 | (assert (not (boundp 'allout-tests-globally-unbound)))) |
6845 | ||
6846 | ;; ensure that variable with prior global value is resumed | |
6847 | (with-temp-buffer | |
6848 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6849 | (setq allout-tests-globally-true t) | |
6850 | (allout-add-resumptions '(allout-tests-globally-true nil)) | |
6851 | (assert (equal (default-value 'allout-tests-globally-true) t)) | |
1c9b9df0 | 6852 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6853 | (assert (equal allout-tests-globally-true nil)) |
6854 | (allout-do-resumptions) | |
1c9b9df0 KM |
6855 | (assert (not (local-variable-p 'allout-tests-globally-true |
6856 | (current-buffer)))) | |
01fc9422 EZ |
6857 | (assert (boundp 'allout-tests-globally-true)) |
6858 | (assert (equal allout-tests-globally-true t))) | |
6859 | ||
6860 | ;; ensure that prior local value is resumed | |
6861 | (with-temp-buffer | |
6862 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6863 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6864 | (assert (not (default-boundp 'allout-tests-locally-true)) | |
60c7bbd2 | 6865 | nil (concat "Test setup mistake -- variable supposed to" |
01fc9422 | 6866 | " not have global binding, but it does.")) |
1c9b9df0 | 6867 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer)) |
60c7bbd2 | 6868 | nil (concat "Test setup mistake -- variable supposed to have" |
01fc9422 EZ |
6869 | " local binding, but it lacks one.")) |
6870 | (allout-add-resumptions '(allout-tests-locally-true nil)) | |
6871 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6872 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6873 | (assert (equal allout-tests-locally-true nil)) |
6874 | (allout-do-resumptions) | |
6875 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6876 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6877 | (assert (equal allout-tests-locally-true t)) |
6878 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6879 | ||
6880 | ;; ensure that last of multiple resumptions holds, for various scopes. | |
6881 | (with-temp-buffer | |
6882 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6883 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6884 | (setq allout-tests-globally-true t) | |
6885 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6886 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6887 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6888 | '(allout-tests-globally-true nil) | |
6889 | '(allout-tests-locally-true nil)) | |
6890 | (allout-add-resumptions '(allout-tests-globally-unbound 2) | |
6891 | '(allout-tests-globally-true 3) | |
6892 | '(allout-tests-locally-true 4)) | |
6893 | ;; reestablish many of the basic conditions are maintained after re-add: | |
6894 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6895 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6896 | (assert (equal allout-tests-globally-unbound 2)) |
6897 | (assert (default-boundp 'allout-tests-globally-true)) | |
1c9b9df0 | 6898 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6899 | (assert (equal allout-tests-globally-true 3)) |
6900 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6901 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6902 | (assert (equal allout-tests-locally-true 4)) |
6903 | (allout-do-resumptions) | |
1c9b9df0 KM |
6904 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6905 | (current-buffer)))) | |
01fc9422 | 6906 | (assert (not (boundp 'allout-tests-globally-unbound))) |
1c9b9df0 KM |
6907 | (assert (not (local-variable-p 'allout-tests-globally-true |
6908 | (current-buffer)))) | |
01fc9422 EZ |
6909 | (assert (boundp 'allout-tests-globally-true)) |
6910 | (assert (equal allout-tests-globally-true t)) | |
6911 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6912 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6913 | (assert (equal allout-tests-locally-true t)) |
6914 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6915 | ||
6916 | ;; ensure that deliberately unbinding registered variables doesn't foul things | |
6917 | (with-temp-buffer | |
6918 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6919 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6920 | (setq allout-tests-globally-true t) | |
6921 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6922 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6923 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6924 | '(allout-tests-globally-true nil) | |
6925 | '(allout-tests-locally-true nil)) | |
6926 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6927 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6928 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6929 | (allout-do-resumptions)) | |
6930 | ) | |
6931 | ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true: | |
6932 | (when allout-run-unit-tests-on-load | |
6933 | (allout-run-unit-tests)) | |
6934 | ||
6935 | ;;;_ #12 Provide | |
96b83743 | 6936 | (provide 'allout) |
1977b8f6 RS |
6937 | |
6938 | ;;;_* Local emacs vars. | |
31468dcb SM |
6939 | ;; The following `allout-layout' local variable setting: |
6940 | ;; - closes all topics from the first topic to just before the third-to-last, | |
6941 | ;; - shows the children of the third to last (config vars) | |
6942 | ;; - and the second to last (code section), | |
6943 | ;; - and closes the last topic (this local-variables section). | |
6944 | ;;Local variables: | |
6945 | ;;allout-layout: (0 : -1 -1 0) | |
6946 | ;;End: | |
6947 | ||
6a05d05f | 6948 | ;;; allout.el ends here |