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 |
ff3e8c8e KM |
80 | ;; Most of the requires here are for stuff covered by autoloads, which |
81 | ;; byte-compiling doesn't trigger. | |
29fac3fe | 82 | (require 'epg) |
ff3e8c8e | 83 | (require 'epa) |
08cf18e4 GM |
84 | (require 'overlay) |
85 | ;; `cl' is required for `assert'. `assert' is not covered by a standard | |
86 | ;; autoload, but it is a macro, so that eval-when-compile is sufficient | |
87 | ;; to byte-compile it in, or to do the require when the buffer evalled. | |
88 | (require 'cl) | |
89 | ) | |
d82979ea | 90 | |
19b84ba3 | 91 | ;;;_* USER CUSTOMIZATION VARIABLES: |
96b83743 | 92 | |
1c9b9df0 | 93 | ;;;_ > defgroup allout, allout-keybindings |
4bef9110 | 94 | (defgroup allout nil |
96497653 KM |
95 | "Extensive outline minor-mode, for use stand-alone and with other modes. |
96 | ||
97 | See Allout Auto Activation for automatic activation." | |
fd5359c6 | 98 | :prefix "allout-" |
d82979ea | 99 | :group 'outlines) |
1c9b9df0 KM |
100 | (defgroup allout-keybindings nil |
101 | "Allout outline mode keyboard bindings configuration." | |
102 | :group 'allout) | |
19b84ba3 RS |
103 | |
104 | ;;;_ + Layout, Mode, and Topic Header Configuration | |
105 | ||
08b5f072 | 106 | (defvar allout-command-prefix) ; defined below |
08b5f072 | 107 | |
1c9b9df0 | 108 | ;;;_ > allout-keybindings incidentals: |
d3e51865 KM |
109 | ;;;_ : internal key binding stuff - in this section for load-order. |
110 | ;;;_ = allout-mode-map | |
111 | (defvar allout-mode-map 'allout-mode-map | |
112 | "Keybindings place-holder for (allout) outline minor mode. | |
113 | ||
114 | Do NOT set the value of this variable. Instead, customize | |
115 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
116 | `allout-unprefixed-keybindings'.") | |
117 | ;;;_ = allout-mode-map-value | |
118 | (defvar allout-mode-map-value nil | |
119 | "Keymap for allout outline minor mode. | |
120 | ||
121 | Do NOT set the value of this variable. Instead, customize | |
122 | `allout-command-prefix', `allout-prefixed-keybindings', and | |
123 | `allout-unprefixed-keybindings'.") | |
124 | ;;;_ = make allout-mode-map-value an alias for allout-mode-map: | |
125 | ;; this needs to be revised when the value is changed, sigh. | |
126 | (defalias 'allout-mode-map allout-mode-map-value) | |
127 | ;;;_ > allout-compose-and-institute-keymap (&optional varname value) | |
128 | (defun allout-compose-and-institute-keymap (&optional varname value) | |
129 | "Create the allout keymap according to the keybinding specs, and set it. | |
130 | ||
131 | Useful standalone or to effect customizations of the | |
1c9b9df0 KM |
132 | respective allout-mode keybinding variables, `allout-command-prefix', |
133 | `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'" | |
134 | ;; Set the customization variable, if any: | |
135 | (when varname | |
136 | (set-default varname value)) | |
d3e51865 | 137 | (let ((map (make-sparse-keymap))) |
1c9b9df0 | 138 | (when (boundp 'allout-prefixed-keybindings) |
d3e51865 | 139 | ;; tolerate first definitions of the variables: |
1c9b9df0 KM |
140 | (dolist (entry allout-prefixed-keybindings) |
141 | (define-key map | |
142 | ;; XXX vector vs non-vector key descriptions? | |
143 | (vconcat allout-command-prefix | |
144 | (car (read-from-string (car entry)))) | |
145 | (cadr entry)))) | |
146 | (when (boundp 'allout-unprefixed-keybindings) | |
147 | (dolist (entry allout-unprefixed-keybindings) | |
148 | (define-key map (car (read-from-string (car entry))) (cadr entry)))) | |
d3e51865 KM |
149 | (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line |
150 | map global-map) | |
151 | (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line | |
152 | map global-map) | |
153 | (substitute-key-definition 'end-of-line 'allout-end-of-line | |
154 | map global-map) | |
155 | (substitute-key-definition 'move-end-of-line 'allout-end-of-line | |
156 | map global-map) | |
157 | (allout-institute-keymap map))) | |
158 | ;;;_ > allout-institute-keymap (map) | |
159 | (defun allout-institute-keymap (map) | |
160 | "Associate allout-mode bindings with allout as a minor mode." | |
161 | ;; Architecture: | |
162 | ;; allout-mode-map var is a keymap by virtue of being a defalias for | |
163 | ;; allout-mode-map-value, which has the actual keymap value. | |
164 | ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be | |
165 | ;; used in minor-mode-map-alist to indirect to the actual | |
166 | ;; allout-mode-map-var value, which can be adjusted and reassigned. | |
167 | ||
642f3c5c | 168 | ;; allout-mode-map-value for keymap reference in various places: |
d3e51865 | 169 | (setq allout-mode-map-value map) |
642f3c5c KM |
170 | ;; the function value keymap of allout-mode-map is used in |
171 | ;; minor-mode-map-alist - update it: | |
172 | (fset allout-mode-map allout-mode-map-value)) | |
cd1181db | 173 | ;;;_ * initialize the mode map: |
d3e51865 KM |
174 | ;; ensure that allout-mode-map has some setting even if allout-mode hasn't |
175 | ;; been invoked: | |
176 | (allout-compose-and-institute-keymap) | |
1c9b9df0 | 177 | ;;;_ = allout-command-prefix |
2a1408fd | 178 | (defcustom allout-command-prefix "\C-c " |
9201cc28 | 179 | "Key sequence to be used as prefix for outline mode command key bindings. |
2a1408fd DN |
180 | |
181 | Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're | |
182 | willing to let allout use a bunch of \C-c keybindings." | |
183 | :type 'string | |
1c9b9df0 | 184 | :group 'allout-keybindings |
d3e51865 | 185 | :set 'allout-compose-and-institute-keymap) |
1c9b9df0 KM |
186 | ;;;_ = allout-keybindings-binding |
187 | (define-widget 'allout-keybindings-binding 'lazy | |
188 | "Structure of allout keybindings customization items." | |
189 | :type '(repeat | |
190 | (list (string :tag "Key" :value "[(meta control shift ?f)]") | |
191 | (function :tag "Function name" | |
192 | :value allout-forward-current-level)))) | |
193 | ;;;_ = allout-prefixed-keybindings | |
194 | (defcustom allout-prefixed-keybindings | |
195 | '(("[(control ?n)]" allout-next-visible-heading) | |
196 | ("[(control ?p)]" allout-previous-visible-heading) | |
d3e51865 | 197 | ("[(control ?u)]" allout-up-current-level) |
1c9b9df0 KM |
198 | ("[(control ?f)]" allout-forward-current-level) |
199 | ("[(control ?b)]" allout-backward-current-level) | |
200 | ("[(control ?a)]" allout-beginning-of-current-entry) | |
201 | ("[(control ?e)]" allout-end-of-entry) | |
202 | ("[(control ?i)]" allout-show-children) | |
1c9b9df0 KM |
203 | ("[(control ?s)]" allout-show-current-subtree) |
204 | ("[(control ?t)]" allout-toggle-current-subtree-exposure) | |
d3e51865 KM |
205 | ;; Let user customize if they want to preempt describe-prefix-bindings ^h use. |
206 | ;; ("[(control ?h)]" allout-hide-current-subtree) | |
1c9b9df0 KM |
207 | ("[?h]" allout-hide-current-subtree) |
208 | ("[(control ?o)]" allout-show-current-entry) | |
209 | ("[?!]" allout-show-all) | |
210 | ("[?x]" allout-toggle-current-subtree-encryption) | |
211 | ("[? ]" allout-open-sibtopic) | |
212 | ("[?.]" allout-open-subtopic) | |
213 | ("[?,]" allout-open-supertopic) | |
214 | ("[?']" allout-shift-in) | |
215 | ("[?>]" allout-shift-in) | |
216 | ("[?<]" allout-shift-out) | |
217 | ("[(control ?m)]" allout-rebullet-topic) | |
218 | ("[?*]" allout-rebullet-current-heading) | |
4936e3ba | 219 | ("[?#]" allout-number-siblings) |
1c9b9df0 | 220 | ("[(control ?k)]" allout-kill-topic) |
d3e51865 | 221 | ("[(meta ?k)]" allout-copy-topic-as-kill) |
1c9b9df0 KM |
222 | ("[?@]" allout-resolve-xref) |
223 | ("[?=?c]" allout-copy-exposed-to-buffer) | |
224 | ("[?=?i]" allout-indented-exposed-to-buffer) | |
225 | ("[?=?t]" allout-latexify-exposed) | |
226 | ("[?=?p]" allout-flatten-exposed-to-buffer) | |
227 | ) | |
228 | "Allout-mode key bindings that are prefixed with `allout-command-prefix'. | |
229 | ||
230 | See `allout-unprefixed-keybindings' for the list of keybindings | |
231 | that are not prefixed. | |
232 | ||
233 | Use vector format for the keys: | |
234 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
235 | - enclose control, shift, or meta-modified keys as sequences within | |
236 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 237 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 KM |
238 | See the existing keys for examples. |
239 | ||
240 | Functions can be bound to multiple keys, but binding keys to | |
241 | multiple functions will not work - the last binding for a key | |
242 | prevails." | |
2bed3f04 | 243 | :version "24.1" |
1c9b9df0 KM |
244 | :type 'allout-keybindings-binding |
245 | :group 'allout-keybindings | |
d3e51865 | 246 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
247 | ) |
248 | ;;;_ = allout-unprefixed-keybindings | |
249 | (defcustom allout-unprefixed-keybindings | |
250 | '(("[(control ?k)]" allout-kill-line) | |
d3e51865 | 251 | ("[(meta ?k)]" allout-copy-line-as-kill) |
1c9b9df0 | 252 | ("[(control ?y)]" allout-yank) |
d3e51865 | 253 | ("[(meta ?y)]" allout-yank-pop) |
1c9b9df0 KM |
254 | ) |
255 | "Allout-mode functions bound to keys without any added prefix. | |
256 | ||
257 | This is in contrast to the majority of allout-mode bindings on | |
258 | `allout-prefixed-bindings', whose bindings are created with a | |
0d327994 | 259 | preceding command key. |
1c9b9df0 KM |
260 | |
261 | Use vector format for the keys: | |
262 | - put literal keys after a '?' question mark, eg: '?a', '?.' | |
263 | - enclose control, shift, or meta-modified keys as sequences within | |
264 | parentheses, with the literal key, as above, preceded by the name(s) | |
01c35094 | 265 | of the modifiers, eg: [(control ?a)] |
1c9b9df0 | 266 | See the existing keys for examples." |
2bed3f04 | 267 | :version "24.1" |
1c9b9df0 KM |
268 | :type 'allout-keybindings-binding |
269 | :group 'allout-keybindings | |
d3e51865 | 270 | :set 'allout-compose-and-institute-keymap |
1c9b9df0 KM |
271 | ) |
272 | ||
11c46e15 KM |
273 | ;;;_ > allout-auto-activation-helper (var value) |
274 | ;;;###autoload | |
275 | (defun allout-auto-activation-helper (var value) | |
276 | "Institute `allout-auto-activation'. | |
277 | ||
278 | Intended to be used as the `allout-auto-activation' :set function." | |
279 | (set-default var value) | |
280 | (allout-setup)) | |
281 | ;;;_ > allout-setup () | |
282 | ;;;###autoload | |
283 | (defun allout-setup () | |
20db1522 | 284 | "Do fundamental Emacs session for allout auto-activation. |
11c46e15 KM |
285 | |
286 | Establishes allout processing as part of visiting a file if | |
287 | `allout-auto-activation' is non-nil, or removes it otherwise. | |
288 | ||
289 | The proper way to use this is through customizing the setting of | |
290 | `allout-auto-activation'." | |
291 | (if (not allout-auto-activation) | |
292 | (remove-hook 'find-file-hook 'allout-find-file-hook) | |
293 | (add-hook 'find-file-hook 'allout-find-file-hook))) | |
fd5359c6 | 294 | ;;;_ = allout-auto-activation |
11c46e15 | 295 | ;;;###autoload |
fd5359c6 | 296 | (defcustom allout-auto-activation nil |
11c46e15 | 297 | "Configure allout outline mode auto-activation. |
19b84ba3 | 298 | |
11c46e15 KM |
299 | Control whether and how allout outline mode is automatically |
300 | activated when files are visited with non-nil buffer-specific | |
301 | file variable `allout-layout'. | |
19b84ba3 | 302 | |
20db1522 | 303 | When allout-auto-activation is \"On\" (t), allout mode is |
11c46e15 KM |
304 | activated in buffers with non-nil `allout-layout', and the |
305 | specified layout is applied. | |
19b84ba3 | 306 | |
11c46e15 | 307 | With value \"ask\", auto-mode-activation is enabled, and endorsement for |
19b84ba3 RS |
308 | performing auto-layout is asked of the user each time. |
309 | ||
11c46e15 KM |
310 | With value \"activate\", only auto-mode-activation is enabled. |
311 | Auto-layout is not. | |
19b84ba3 | 312 | |
96497653 | 313 | With value nil, inhibit any automatic allout-mode activation." |
11c46e15 | 314 | :set 'allout-auto-activation-helper |
c6eee9aa | 315 | ;; FIXME: Using strings here is unusual and less efficient than symbols. |
9179616f DL |
316 | :type '(choice (const :tag "On" t) |
317 | (const :tag "Ask about layout" "ask") | |
318 | (const :tag "Mode only" "activate") | |
319 | (const :tag "Off" nil)) | |
320 | :group 'allout) | |
11c46e15 | 321 | (allout-setup) |
4034b0e2 LT |
322 | ;;;_ = allout-default-layout |
323 | (defcustom allout-default-layout '(-2 : 0) | |
9201cc28 | 324 | "Default allout outline layout specification. |
4034b0e2 LT |
325 | |
326 | This setting specifies the outline exposure to use when | |
327 | `allout-layout' has the local value `t'. This docstring describes the | |
328 | layout specifications. | |
329 | ||
330 | A list value specifies a default layout for the current buffer, | |
331 | to be applied upon activation of `allout-mode'. Any non-nil | |
332 | value will automatically trigger `allout-mode', provided | |
11c46e15 | 333 | `allout-auto-activation' has been customized to enable it. |
4034b0e2 LT |
334 | |
335 | The types of elements in the layout specification are: | |
336 | ||
60c7bbd2 RS |
337 | INTEGER -- dictate the relative depth to open the corresponding topic(s), |
338 | where: | |
339 | -- negative numbers force the topic to be closed before opening | |
340 | to the absolute value of the number, so all siblings are open | |
341 | only to that level. | |
342 | -- positive numbers open to the relative depth indicated by the | |
343 | number, but do not force already opened subtopics to be closed. | |
344 | -- 0 means to close topic -- hide all subitems. | |
97610156 | 345 | : -- repeat spec -- apply the preceding element to all siblings at |
60c7bbd2 RS |
346 | current level, *up to* those siblings that would be covered by specs |
347 | following the `:' on the list. Ie, apply to all topics at level but | |
348 | trailing ones accounted for by trailing specs. (Only the first of | |
349 | multiple colons at the same level is honored -- later ones are ignored.) | |
350 | * -- completely exposes the topic, including bodies | |
351 | + -- exposes all subtopics, but not the bodies | |
352 | - -- exposes the body of the corresponding topic, but not subtopics | |
353 | LIST -- a nested layout spec, to be applied intricately to its | |
4034b0e2 | 354 | corresponding item(s) |
1977b8f6 | 355 | |
4034b0e2 | 356 | Examples: |
60c7bbd2 | 357 | (-2 : 0) |
4034b0e2 LT |
358 | Collapse the top-level topics to show their children and |
359 | grandchildren, but completely collapse the final top-level topic. | |
60c7bbd2 | 360 | (-1 () : 1 0) |
4034b0e2 LT |
361 | Close the first topic so only the immediate subtopics are shown, |
362 | leave the subsequent topics exposed as they are until the second | |
363 | second to last topic, which is exposed at least one level, and | |
364 | completely close the last topic. | |
60c7bbd2 | 365 | (-2 : -1 *) |
4034b0e2 LT |
366 | Expose children and grandchildren of all topics at current |
367 | level except the last two; expose children of the second to | |
368 | last and completely expose the last one, including its subtopics. | |
19b84ba3 | 369 | |
4034b0e2 | 370 | See `allout-expose-topic' for more about the exposure process. |
19b84ba3 | 371 | |
353e2ef2 KH |
372 | Also, allout's mode-specific provisions will make topic prefixes default |
373 | to the comment-start string, if any, of the language of the file. This | |
4034b0e2 LT |
374 | is modulo the setting of `allout-use-mode-specific-leader', which see." |
375 | :type 'allout-layout-type | |
376 | :group 'allout) | |
377 | ;;;_ : allout-layout-type | |
378 | (define-widget 'allout-layout-type 'lazy | |
379 | "Allout layout format customization basic building blocks." | |
380 | :type '(repeat | |
381 | (choice (integer :tag "integer (<= zero is strict)") | |
382 | (const :tag ": (repeat prior)" :) | |
383 | (const :tag "* (completely expose)" *) | |
384 | (const :tag "+ (expose all offspring, headlines only)" +) | |
385 | (const :tag "- (expose topic body but not offspring)" -) | |
386 | (allout-layout-type :tag "<Nested layout>")))) | |
387 | ||
2a1408fd DN |
388 | ;;;_ = allout-inhibit-auto-fill |
389 | (defcustom allout-inhibit-auto-fill nil | |
9201cc28 | 390 | "If non-nil, auto-fill will be inhibited in the allout buffers. |
2a1408fd DN |
391 | |
392 | You can customize this setting to set it for all allout buffers, or set it | |
393 | in individual buffers if you want to inhibit auto-fill only in particular | |
394 | buffers. (You could use a function on `allout-mode-hook' to inhibit | |
395 | auto-fill according, eg, to the major mode.) | |
396 | ||
397 | If you don't set this and auto-fill-mode is enabled, allout will use the | |
398 | value that `normal-auto-fill-function', if any, when allout mode starts, or | |
399 | else allout's special hanging-indent maintaining auto-fill function, | |
400 | `allout-auto-fill'." | |
401 | :type 'boolean | |
402 | :group 'allout) | |
403 | (make-variable-buffer-local 'allout-inhibit-auto-fill) | |
381987c3 KM |
404 | ;;;_ = allout-inhibit-auto-fill-on-headline |
405 | (defcustom allout-inhibit-auto-fill-on-headline nil | |
406 | "If non-nil, auto-fill will be inhibited while on topic's header line." | |
2bed3f04 | 407 | :version "24.1" |
381987c3 KM |
408 | :type 'boolean |
409 | :group 'allout) | |
410 | (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline) | |
2a1408fd DN |
411 | ;;;_ = allout-use-hanging-indents |
412 | (defcustom allout-use-hanging-indents t | |
9201cc28 | 413 | "If non-nil, topic body text auto-indent defaults to indent of the header. |
2a1408fd | 414 | Ie, it is indented to be just past the header prefix. This is |
8dd59f01 | 415 | relevant mostly for use with `indented-text-mode', or other situations |
2a1408fd DN |
416 | where auto-fill occurs." |
417 | :type 'boolean | |
418 | :group 'allout) | |
419 | (make-variable-buffer-local 'allout-use-hanging-indents) | |
420 | ;;;###autoload | |
421 | (put 'allout-use-hanging-indents 'safe-local-variable | |
4f91a816 | 422 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
2a1408fd DN |
423 | ;;;_ = allout-reindent-bodies |
424 | (defcustom allout-reindent-bodies (if allout-use-hanging-indents | |
425 | 'text) | |
9201cc28 | 426 | "Non-nil enables auto-adjust of topic body hanging indent with depth shifts. |
2a1408fd DN |
427 | |
428 | When active, topic body lines that are indented even with or beyond | |
429 | their topic header are reindented to correspond with depth shifts of | |
430 | the header. | |
431 | ||
432 | A value of t enables reindent in non-programming-code buffers, ie | |
433 | those that do not have the variable `comment-start' set. A value of | |
434 | `force' enables reindent whether or not `comment-start' is set." | |
435 | :type '(choice (const nil) (const t) (const text) (const force)) | |
436 | :group 'allout) | |
437 | ||
438 | (make-variable-buffer-local 'allout-reindent-bodies) | |
439 | ;;;###autoload | |
440 | (put 'allout-reindent-bodies 'safe-local-variable | |
4f91a816 | 441 | (lambda (x) (memq x '(nil t text force)))) |
2a1408fd | 442 | |
fd5359c6 MR |
443 | ;;;_ = allout-show-bodies |
444 | (defcustom allout-show-bodies nil | |
9201cc28 | 445 | "If non-nil, show entire body when exposing a topic, rather than |
9179616f DL |
446 | just the header." |
447 | :type 'boolean | |
448 | :group 'allout) | |
fd5359c6 | 449 | (make-variable-buffer-local 'allout-show-bodies) |
8570ce80 SM |
450 | ;;;###autoload |
451 | (put 'allout-show-bodies 'safe-local-variable | |
4f91a816 | 452 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 453 | |
48bd8440 EZ |
454 | ;;;_ = allout-beginning-of-line-cycles |
455 | (defcustom allout-beginning-of-line-cycles t | |
9201cc28 | 456 | "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
457 | |
458 | Cycling only happens on when the command is repeated, not when it | |
459 | follows a different command. | |
460 | ||
461 | Smart-placement means that repeated calls to this function will | |
462 | advance as follows: | |
463 | ||
464 | - if the cursor is on a non-headline body line and not on the first column: | |
465 | then it goes to the first column | |
466 | - if the cursor is on the first column of a non-headline body line: | |
467 | then it goes to the start of the headline within the item body | |
468 | - if the cursor is on the headline and not the start of the headline: | |
469 | then it goes to the start of the headline | |
470 | - if the cursor is on the start of the headline: | |
c07583cd | 471 | then it goes to the bullet character (for hotspot navigation) |
48bd8440 | 472 | - if the cursor is on the bullet character: |
c07583cd | 473 | then it goes to the first column of that line (the headline) |
48bd8440 EZ |
474 | - if the cursor is on the first column of the headline: |
475 | then it goes to the start of the headline within the item body. | |
476 | ||
477 | In this fashion, you can use the beginning-of-line command to do | |
478 | its normal job and then, when repeated, advance through the | |
479 | entry, cycling back to start. | |
480 | ||
481 | If this configuration variable is nil, then the cursor is just | |
482 | advanced to the beginning of the line and remains there on | |
483 | repeated calls." | |
484 | :type 'boolean :group 'allout) | |
485 | ;;;_ = allout-end-of-line-cycles | |
486 | (defcustom allout-end-of-line-cycles t | |
9201cc28 | 487 | "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options. |
48bd8440 EZ |
488 | |
489 | Cycling only happens on when the command is repeated, not when it | |
490 | follows a different command. | |
491 | ||
60c7bbd2 | 492 | Smart placement means that repeated calls to this function will |
48bd8440 EZ |
493 | advance as follows: |
494 | ||
495 | - if the cursor is not on the end-of-line, | |
496 | then it goes to the end-of-line | |
497 | - if the cursor is on the end-of-line but not the end-of-entry, | |
498 | then it goes to the end-of-entry, exposing it if necessary | |
499 | - if the cursor is on the end-of-entry, | |
500 | then it goes to the end of the head line | |
501 | ||
502 | In this fashion, you can use the end-of-line command to do its | |
503 | normal job and then, when repeated, advance through the entry, | |
504 | cycling back to start. | |
505 | ||
506 | If this configuration variable is nil, then the cursor is just | |
507 | advanced to the end of the line and remains there on repeated | |
508 | calls." | |
509 | :type 'boolean :group 'allout) | |
510 | ||
fd5359c6 MR |
511 | ;;;_ = allout-header-prefix |
512 | (defcustom allout-header-prefix "." | |
48bd8440 EZ |
513 | ;; this string is treated as literal match. it will be `regexp-quote'd, so |
514 | ;; one cannot use regular expressions to match varying header prefixes. | |
9201cc28 | 515 | "Leading string which helps distinguish topic headers. |
19b84ba3 RS |
516 | |
517 | Outline topic header lines are identified by a leading topic | |
c567ac01 | 518 | header prefix, which mostly have the value of this var at their front. |
48bd8440 EZ |
519 | Level 1 topics are exceptions. They consist of only a single |
520 | character, which is typically set to the `allout-primary-bullet'." | |
4bef9110 SE |
521 | :type 'string |
522 | :group 'allout) | |
fd5359c6 | 523 | (make-variable-buffer-local 'allout-header-prefix) |
8570ce80 SM |
524 | ;;;###autoload |
525 | (put 'allout-header-prefix 'safe-local-variable 'stringp) | |
fd5359c6 MR |
526 | ;;;_ = allout-primary-bullet |
527 | (defcustom allout-primary-bullet "*" | |
19b84ba3 RS |
528 | "Bullet used for top-level outline topics. |
529 | ||
530 | Outline topic header lines are identified by a leading topic header | |
c567ac01 | 531 | prefix, which is concluded by bullets that includes the value of this |
fd5359c6 | 532 | var and the respective allout-*-bullets-string vars. |
c567ac01 | 533 | |
353e2ef2 | 534 | The value of an asterisk (`*') provides for backwards compatibility |
e126900f | 535 | with the original Emacs outline mode. See `allout-plain-bullets-string' |
2265e017 | 536 | and `allout-distinctive-bullets-string' for the range of available |
4bef9110 SE |
537 | bullets." |
538 | :type 'string | |
539 | :group 'allout) | |
fd5359c6 | 540 | (make-variable-buffer-local 'allout-primary-bullet) |
8570ce80 SM |
541 | ;;;###autoload |
542 | (put 'allout-primary-bullet 'safe-local-variable 'stringp) | |
fd5359c6 | 543 | ;;;_ = allout-plain-bullets-string |
d82979ea | 544 | (defcustom allout-plain-bullets-string ".," |
9201cc28 | 545 | "The bullets normally used in outline topic prefixes. |
19b84ba3 | 546 | |
fd5359c6 | 547 | See `allout-distinctive-bullets-string' for the other kind of |
c567ac01 | 548 | bullets. |
1977b8f6 | 549 | |
353e2ef2 | 550 | DO NOT include the close-square-bracket, `]', as a bullet. |
1977b8f6 | 551 | |
c567ac01 | 552 | Outline mode has to be reactivated in order for changes to the value |
4bef9110 SE |
553 | of this var to take effect." |
554 | :type 'string | |
555 | :group 'allout) | |
fd5359c6 | 556 | (make-variable-buffer-local 'allout-plain-bullets-string) |
8570ce80 SM |
557 | ;;;###autoload |
558 | (put 'allout-plain-bullets-string 'safe-local-variable 'stringp) | |
fd5359c6 | 559 | ;;;_ = allout-distinctive-bullets-string |
d82979ea | 560 | (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^" |
9201cc28 | 561 | "Persistent outline header bullets used to distinguish special topics. |
1977b8f6 | 562 | |
38b2ca53 NR |
563 | These bullets are distinguish topics with particular character. |
564 | They are not used by default in the topic creation routines, but | |
565 | are offered as options when you modify topic creation with a | |
20db1522 | 566 | universal argument (\\[universal-argument]), or during rebulleting (\\[allout-rebullet-current-heading]). |
38b2ca53 NR |
567 | |
568 | Distinctive bullets are not cycled when topics are shifted or | |
569 | otherwise automatically rebulleted, so their marking is | |
570 | persistent until deliberately changed. Their significance is | |
571 | purely by convention, however. Some conventions suggest | |
572 | themselves: | |
573 | ||
60c7bbd2 RS |
574 | `(' - open paren -- an aside or incidental point |
575 | `?' - question mark -- uncertain or outright question | |
576 | `!' - exclamation point/bang -- emphatic | |
577 | `[' - open square bracket -- meta-note, about item instead of item's subject | |
578 | `\"' - double quote -- a quotation or other citation | |
0af8c88b | 579 | `=' - equal sign -- an assignment, some kind of definition |
60c7bbd2 | 580 | `^' - carat -- relates to something above |
38b2ca53 NR |
581 | |
582 | Some are more elusive, but their rationale may be recognizable: | |
583 | ||
60c7bbd2 RS |
584 | `+' - plus -- pending consideration, completion |
585 | `_' - underscore -- done, completed | |
586 | `&' - ampersand -- addendum, furthermore | |
38b2ca53 NR |
587 | |
588 | \(Some other non-plain bullets have special meaning to the | |
589 | software. By default: | |
590 | ||
60c7bbd2 RS |
591 | `~' marks encryptable topics -- see `allout-topic-encryption-bullet' |
592 | `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.) | |
38b2ca53 NR |
593 | |
594 | See `allout-plain-bullets-string' for the standard, alternating | |
595 | bullets. | |
1977b8f6 | 596 | |
fd5359c6 | 597 | You must run `set-allout-regexp' in order for outline mode to |
38b2ca53 | 598 | adopt changes of this value. |
19b84ba3 | 599 | |
353e2ef2 | 600 | DO NOT include the close-square-bracket, `]', on either of the bullet |
4bef9110 SE |
601 | strings." |
602 | :type 'string | |
603 | :group 'allout) | |
fd5359c6 | 604 | (make-variable-buffer-local 'allout-distinctive-bullets-string) |
8570ce80 SM |
605 | ;;;###autoload |
606 | (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp) | |
1977b8f6 | 607 | |
fd5359c6 MR |
608 | ;;;_ = allout-use-mode-specific-leader |
609 | (defcustom allout-use-mode-specific-leader t | |
9201cc28 | 610 | "When non-nil, use mode-specific topic-header prefixes. |
19b84ba3 | 611 | |
48bd8440 EZ |
612 | Allout outline mode will use the mode-specific `allout-mode-leaders' or |
613 | comment-start string, if any, to lead the topic prefix string, so topic | |
614 | headers look like comments in the programming language. It will also use | |
615 | the comment-start string, with an '_' appended, for `allout-primary-bullet'. | |
19b84ba3 | 616 | |
48bd8440 | 617 | String values are used as literals, not regular expressions, so |
40ba43b4 | 618 | do not escape any regular-expression characters. |
19b84ba3 | 619 | |
24190da5 | 620 | Value t means to first check for assoc value in `allout-mode-leaders' |
c07583cd | 621 | alist, then use comment-start string, if any, then use default (`.'). |
9179616f | 622 | \(See note about use of comment-start strings, below.) |
19b84ba3 | 623 | |
fd5359c6 | 624 | Set to the symbol for either of `allout-mode-leaders' or |
19b84ba3 RS |
625 | `comment-start' to use only one of them, respectively. |
626 | ||
c07583cd | 627 | Value nil means to always use the default (`.') and leave |
48bd8440 EZ |
628 | `allout-primary-bullet' unaltered. |
629 | ||
630 | comment-start strings that do not end in spaces are tripled in | |
631 | the header-prefix, and an `_' underscore is tacked on the end, to | |
632 | distinguish them from regular comment strings. comment-start | |
633 | strings that do end in spaces are not tripled, but an underscore | |
75bcb912 | 634 | is substituted for the space. [This presumes that the space is |
48bd8440 EZ |
635 | for appearance, not comment syntax. You can use |
636 | `allout-mode-leaders' to override this behavior, when | |
637 | undesired.]" | |
71296446 | 638 | :type '(choice (const t) (const nil) string |
fd5359c6 | 639 | (const allout-mode-leaders) |
4bef9110 SE |
640 | (const comment-start)) |
641 | :group 'allout) | |
8570ce80 SM |
642 | ;;;###autoload |
643 | (put 'allout-use-mode-specific-leader 'safe-local-variable | |
4f91a816 | 644 | (lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start)) |
da506f05 | 645 | (stringp x)))) |
fd5359c6 MR |
646 | ;;;_ = allout-mode-leaders |
647 | (defvar allout-mode-leaders '() | |
648 | "Specific allout-prefix leading strings per major modes. | |
19b84ba3 | 649 | |
48bd8440 EZ |
650 | Use this if the mode's comment-start string isn't what you |
651 | prefer, or if the mode lacks a comment-start string. See | |
652 | `allout-use-mode-specific-leader' for more details. | |
19b84ba3 RS |
653 | |
654 | If you're constructing a string that will comment-out outline | |
655 | structuring so it can be included in program code, append an extra | |
656 | character, like an \"_\" underscore, to distinguish the lead string | |
48bd8440 | 657 | from regular comments that start at the beginning-of-line.") |
19b84ba3 | 658 | |
fd5359c6 MR |
659 | ;;;_ = allout-old-style-prefixes |
660 | (defcustom allout-old-style-prefixes nil | |
9201cc28 | 661 | "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. |
19b84ba3 RS |
662 | |
663 | Non-nil restricts the topic creation and modification | |
c567ac01 | 664 | functions to asterix-padded prefixes, so they look exactly |
e126900f | 665 | like the original Emacs-outline style prefixes. |
1977b8f6 | 666 | |
c567ac01 | 667 | Whatever the setting of this variable, both old and new style prefixes |
4bef9110 SE |
668 | are always respected by the topic maneuvering functions." |
669 | :type 'boolean | |
670 | :group 'allout) | |
fd5359c6 | 671 | (make-variable-buffer-local 'allout-old-style-prefixes) |
8570ce80 SM |
672 | ;;;###autoload |
673 | (put 'allout-old-style-prefixes 'safe-local-variable | |
4f91a816 | 674 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
60c7bbd2 | 675 | ;;;_ = allout-stylish-prefixes -- alternating bullets |
fd5359c6 | 676 | (defcustom allout-stylish-prefixes t |
9201cc28 | 677 | "Do fancy stuff with topic prefix bullets according to level, etc. |
c567ac01 | 678 | |
19b84ba3 RS |
679 | Non-nil enables topic creation, modification, and repositioning |
680 | functions to vary the topic bullet char (the char that marks the topic | |
681 | depth) just preceding the start of the topic text) according to level. | |
353e2ef2 | 682 | Otherwise, only asterisks (`*') and distinctive bullets are used. |
19b84ba3 RS |
683 | |
684 | This is how an outline can look (but sans indentation) with stylish | |
685 | prefixes: | |
c567ac01 RS |
686 | |
687 | * Top level | |
688 | .* A topic | |
689 | . + One level 3 subtopic | |
690 | . . One level 4 subtopic | |
19b84ba3 | 691 | . . A second 4 subtopic |
c567ac01 | 692 | . + Another level 3 subtopic |
19b84ba3 RS |
693 | . #1 A numbered level 4 subtopic |
694 | . #2 Another | |
695 | . ! Another level 4 subtopic with a different distinctive bullet | |
696 | . #4 And another numbered level 4 subtopic | |
c567ac01 | 697 | |
19b84ba3 RS |
698 | This would be an outline with stylish prefixes inhibited (but the |
699 | numbered and other distinctive bullets retained): | |
c567ac01 RS |
700 | |
701 | * Top level | |
702 | .* A topic | |
19b84ba3 RS |
703 | . * One level 3 subtopic |
704 | . * One level 4 subtopic | |
705 | . * A second 4 subtopic | |
706 | . * Another level 3 subtopic | |
707 | . #1 A numbered level 4 subtopic | |
708 | . #2 Another | |
709 | . ! Another level 4 subtopic with a different distinctive bullet | |
710 | . #4 And another numbered level 4 subtopic | |
c567ac01 RS |
711 | |
712 | Stylish and constant prefixes (as well as old-style prefixes) are | |
713 | always respected by the topic maneuvering functions, regardless of | |
714 | this variable setting. | |
715 | ||
2265e017 | 716 | The setting of this var is not relevant when `allout-old-style-prefixes' |
4bef9110 SE |
717 | is non-nil." |
718 | :type 'boolean | |
719 | :group 'allout) | |
fd5359c6 | 720 | (make-variable-buffer-local 'allout-stylish-prefixes) |
8570ce80 SM |
721 | ;;;###autoload |
722 | (put 'allout-stylish-prefixes 'safe-local-variable | |
4f91a816 | 723 | (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil))))) |
1977b8f6 | 724 | |
fd5359c6 MR |
725 | ;;;_ = allout-numbered-bullet |
726 | (defcustom allout-numbered-bullet "#" | |
9201cc28 | 727 | "String designating bullet of topics that have auto-numbering; nil for none. |
19b84ba3 | 728 | |
a0776d6b | 729 | Topics having this bullet have automatic maintenance of a sibling |
19b84ba3 | 730 | sequence-number tacked on, just after the bullet. Conventionally set |
c567ac01 | 731 | to \"#\", you can set it to a bullet of your choice. A nil value |
4bef9110 SE |
732 | disables numbering maintenance." |
733 | :type '(choice (const nil) string) | |
734 | :group 'allout) | |
fd5359c6 | 735 | (make-variable-buffer-local 'allout-numbered-bullet) |
8570ce80 | 736 | ;;;###autoload |
64686e6d RS |
737 | (put 'allout-numbered-bullet 'safe-local-variable |
738 | (if (fboundp 'string-or-null-p) | |
739 | 'string-or-null-p | |
4f91a816 | 740 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
741 | ;;;_ = allout-file-xref-bullet |
742 | (defcustom allout-file-xref-bullet "@" | |
9201cc28 | 743 | "Bullet signifying file cross-references, for `allout-resolve-xref'. |
19b84ba3 | 744 | |
9179616f | 745 | Set this var to the bullet you want to use for file cross-references." |
4bef9110 SE |
746 | :type '(choice (const nil) string) |
747 | :group 'allout) | |
8570ce80 | 748 | ;;;###autoload |
64686e6d RS |
749 | (put 'allout-file-xref-bullet 'safe-local-variable |
750 | (if (fboundp 'string-or-null-p) | |
751 | 'string-or-null-p | |
4f91a816 | 752 | (lambda (x) (or (stringp x) (null x))))) |
fd5359c6 MR |
753 | ;;;_ = allout-presentation-padding |
754 | (defcustom allout-presentation-padding 2 | |
9201cc28 | 755 | "Presentation-format white-space padding factor, for greater indent." |
9179616f DL |
756 | :type 'integer |
757 | :group 'allout) | |
758 | ||
fd5359c6 | 759 | (make-variable-buffer-local 'allout-presentation-padding) |
8570ce80 SM |
760 | ;;;###autoload |
761 | (put 'allout-presentation-padding 'safe-local-variable 'integerp) | |
9179616f | 762 | |
96497653 KM |
763 | ;;;_ = allout-flattened-numbering-abbreviation |
764 | (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering | |
c6eee9aa | 765 | 'allout-flattened-numbering-abbreviation "24.1") |
96497653 | 766 | (defcustom allout-flattened-numbering-abbreviation nil |
9201cc28 | 767 | "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic |
9179616f DL |
768 | numbers to minimal amount with some context. Otherwise, entire |
769 | numbers are always used." | |
2bed3f04 | 770 | :version "24.1" |
9179616f DL |
771 | :type 'boolean |
772 | :group 'allout) | |
773 | ||
c567ac01 | 774 | ;;;_ + LaTeX formatting |
fd5359c6 MR |
775 | ;;;_ - allout-number-pages |
776 | (defcustom allout-number-pages nil | |
9201cc28 | 777 | "Non-nil turns on page numbering for LaTeX formatting of an outline." |
4bef9110 SE |
778 | :type 'boolean |
779 | :group 'allout) | |
fd5359c6 MR |
780 | ;;;_ - allout-label-style |
781 | (defcustom allout-label-style "\\large\\bf" | |
9201cc28 | 782 | "Font and size of labels for LaTeX formatting of an outline." |
4bef9110 SE |
783 | :type 'string |
784 | :group 'allout) | |
fd5359c6 MR |
785 | ;;;_ - allout-head-line-style |
786 | (defcustom allout-head-line-style "\\large\\sl " | |
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-body-line-style |
791 | (defcustom allout-body-line-style " " | |
9201cc28 | 792 | "Font and size of entries for LaTeX formatting of an outline." |
4bef9110 SE |
793 | :type 'string |
794 | :group 'allout) | |
fd5359c6 MR |
795 | ;;;_ - allout-title-style |
796 | (defcustom allout-title-style "\\Large\\bf" | |
9201cc28 | 797 | "Font and size of titles for LaTeX formatting of an outline." |
4bef9110 SE |
798 | :type 'string |
799 | :group 'allout) | |
fd5359c6 | 800 | ;;;_ - allout-title |
d82979ea | 801 | (defcustom allout-title '(or buffer-file-name (buffer-name)) |
9201cc28 | 802 | "Expression to be evaluated to determine the title for LaTeX |
4bef9110 SE |
803 | formatted copy." |
804 | :type 'sexp | |
805 | :group 'allout) | |
fd5359c6 MR |
806 | ;;;_ - allout-line-skip |
807 | (defcustom allout-line-skip ".05cm" | |
9201cc28 | 808 | "Space between lines for LaTeX formatting of an outline." |
4bef9110 SE |
809 | :type 'string |
810 | :group 'allout) | |
fd5359c6 MR |
811 | ;;;_ - allout-indent |
812 | (defcustom allout-indent ".3cm" | |
9201cc28 | 813 | "LaTeX formatted depth-indent spacing." |
4bef9110 SE |
814 | :type 'string |
815 | :group 'allout) | |
c567ac01 | 816 | |
d82979ea | 817 | ;;;_ + Topic encryption |
8570ce80 SM |
818 | ;;;_ = allout-encryption group |
819 | (defgroup allout-encryption nil | |
820 | "Settings for topic encryption features of allout outliner." | |
821 | :group 'allout) | |
d82979ea EZ |
822 | ;;;_ = allout-topic-encryption-bullet |
823 | (defcustom allout-topic-encryption-bullet "~" | |
9201cc28 | 824 | "Bullet signifying encryption of the entry's body." |
d82979ea | 825 | :type '(choice (const nil) string) |
21e8bc99 | 826 | :version "22.1" |
8570ce80 | 827 | :group 'allout-encryption) |
d82979ea | 828 | ;;;_ = allout-encrypt-unencrypted-on-saves |
96b83743 | 829 | (defcustom allout-encrypt-unencrypted-on-saves t |
13aa217b KM |
830 | "If non-nil, topics pending encryption are encrypted during buffer saves. |
831 | ||
e1dbe924 | 832 | This prevents file-system exposure of un-encrypted contents of |
13aa217b KM |
833 | items marked for encryption. |
834 | ||
835 | When non-nil, if the topic currently being edited is decrypted, | |
836 | it will be encrypted for saving but automatically decrypted | |
837 | before any subsequent user interaction, so it is once again clear | |
838 | text for editing though the file system copy is encrypted. | |
839 | ||
840 | \(Auto-saves are handled differently. Buffers with plain-text | |
841 | exposed encrypted topics are exempted from auto saves until all | |
842 | such topics are encrypted.)" | |
843 | ||
844 | :type 'boolean | |
845 | :version "23.1" | |
8570ce80 | 846 | :group 'allout-encryption) |
d82979ea | 847 | (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) |
13aa217b KM |
848 | (defvar allout-auto-save-temporarily-disabled nil |
849 | "True while topic encryption is pending and auto-saving was active. | |
850 | ||
20db1522 | 851 | The value of `buffer-saved-size' at the time of decryption is used, |
13aa217b KM |
852 | for restoring when all encryptions are established.") |
853 | (defvar allout-just-did-undo nil | |
854 | "True just after undo commands, until allout-post-command-business.") | |
855 | (make-variable-buffer-local 'allout-just-did-undo) | |
d82979ea | 856 | |
01fc9422 EZ |
857 | ;;;_ + Developer |
858 | ;;;_ = allout-developer group | |
859 | (defgroup allout-developer nil | |
1c9b9df0 | 860 | "Allout settings developers care about, including topic encryption and more." |
01fc9422 EZ |
861 | :group 'allout) |
862 | ;;;_ = allout-run-unit-tests-on-load | |
863 | (defcustom allout-run-unit-tests-on-load nil | |
9201cc28 | 864 | "When non-nil, unit tests will be run at end of loading the allout module. |
01fc9422 EZ |
865 | |
866 | Generally, allout code developers are the only ones who'll want to set this. | |
867 | ||
868 | \(If set, this makes it an even better practice to exercise changes by | |
5204800f NR |
869 | doing byte-compilation with a repeat count, so the file is loaded after |
870 | compilation.) | |
01fc9422 EZ |
871 | |
872 | See `allout-run-unit-tests' to see what's run." | |
873 | :type 'boolean | |
874 | :group 'allout-developer) | |
875 | ||
c567ac01 RS |
876 | ;;;_ + Miscellaneous customization |
877 | ||
d82979ea EZ |
878 | ;;;_ = allout-enable-file-variable-adjustment |
879 | (defcustom allout-enable-file-variable-adjustment t | |
9201cc28 | 880 | "If non-nil, some allout outline actions edit Emacs local file var text. |
d82979ea EZ |
881 | |
882 | This can range from changes to existing entries, addition of new ones, | |
883 | and creation of a new local variables section when necessary. | |
19b84ba3 | 884 | |
d82979ea EZ |
885 | Emacs file variables adjustments are also inhibited if `enable-local-variables' |
886 | is nil. | |
c567ac01 | 887 | |
d82979ea | 888 | Operations potentially causing edits include allout encryption routines. |
69027dea | 889 | For details, see `allout-toggle-current-subtree-encryption's docstring." |
4bef9110 SE |
890 | :type 'boolean |
891 | :group 'allout) | |
d82979ea | 892 | (make-variable-buffer-local 'allout-enable-file-variable-adjustment) |
c567ac01 | 893 | |
60c7bbd2 | 894 | ;;;_* CODE -- no user customizations below. |
c567ac01 | 895 | |
9179616f DL |
896 | ;;;_ #1 Internal Outline Formatting and Configuration |
897 | ;;;_ : Version | |
fd5359c6 | 898 | ;;;_ = allout-version |
0af8c88b | 899 | (defvar allout-version "2.3" |
c07583cd | 900 | "Version of currently loaded outline package. (allout.el)") |
fd5359c6 MR |
901 | ;;;_ > allout-version |
902 | (defun allout-version (&optional here) | |
19b84ba3 RS |
903 | "Return string describing the loaded outline version." |
904 | (interactive "P") | |
fd5359c6 | 905 | (let ((msg (concat "Allout Outline Mode v " allout-version))) |
eac9cf5f | 906 | (if here (insert msg)) |
19b84ba3 RS |
907 | (message "%s" msg) |
908 | msg)) | |
69027dea EZ |
909 | ;;;_ : Mode activation (defined here because it's referenced early) |
910 | ;;;_ = allout-mode | |
911 | (defvar allout-mode nil "Allout outline mode minor-mode flag.") | |
912 | (make-variable-buffer-local 'allout-mode) | |
4034b0e2 | 913 | ;;;_ = allout-layout nil |
60c7bbd2 | 914 | (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring. |
4034b0e2 LT |
915 | "Buffer-specific setting for allout layout. |
916 | ||
20db1522 | 917 | In buffers where this is non-nil (and if `allout-auto-activation' |
11c46e15 KM |
918 | has been customized to enable this behavior), `allout-mode' will be |
919 | automatically activated. The layout dictated by the value will be used to | |
920 | set the initial exposure when `allout-mode' is activated. | |
4034b0e2 LT |
921 | |
922 | \*You should not setq-default this variable non-nil unless you want every | |
923 | visited file to be treated as an allout file.* | |
924 | ||
925 | The value would typically be set by a file local variable. For | |
926 | example, the following lines at the bottom of an Emacs Lisp file: | |
927 | ||
928 | ;;;Local variables: | |
c07583cd | 929 | ;;;allout-layout: (0 : -1 -1 0) |
4034b0e2 LT |
930 | ;;;End: |
931 | ||
932 | dictate activation of `allout-mode' mode when the file is visited | |
11c46e15 KM |
933 | \(presuming proper `allout-auto-activation' customization), |
934 | followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'. | |
935 | \(This is the layout used for the allout.el source file.) | |
4034b0e2 LT |
936 | |
937 | `allout-default-layout' describes the specification format. | |
938 | `allout-layout' can additionally have the value `t', in which | |
939 | case the value of `allout-default-layout' is used.") | |
940 | (make-variable-buffer-local 'allout-layout) | |
b1a569b5 | 941 | ;;;###autoload |
8570ce80 | 942 | (put 'allout-layout 'safe-local-variable |
4f91a816 | 943 | (lambda (x) (or (numberp x) (listp x) (memq x '(: * + -))))) |
4034b0e2 | 944 | |
9179616f | 945 | ;;;_ : Topic header format |
fd5359c6 MR |
946 | ;;;_ = allout-regexp |
947 | (defvar allout-regexp "" | |
fb7ada5f | 948 | "Regular expression to match the beginning of a heading line. |
19b84ba3 | 949 | |
c567ac01 RS |
950 | Any line whose beginning matches this regexp is considered a |
951 | heading. This var is set according to the user configuration vars | |
2265e017 | 952 | by `set-allout-regexp'.") |
fd5359c6 MR |
953 | (make-variable-buffer-local 'allout-regexp) |
954 | ;;;_ = allout-bullets-string | |
955 | (defvar allout-bullets-string "" | |
19b84ba3 RS |
956 | "A string dictating the valid set of outline topic bullets. |
957 | ||
60c7bbd2 | 958 | This var should *not* be set by the user -- it is set by `set-allout-regexp', |
fd5359c6 MR |
959 | and is produced from the elements of `allout-plain-bullets-string' |
960 | and `allout-distinctive-bullets-string'.") | |
961 | (make-variable-buffer-local 'allout-bullets-string) | |
962 | ;;;_ = allout-bullets-string-len | |
963 | (defvar allout-bullets-string-len 0 | |
2265e017 | 964 | "Length of current buffers' `allout-plain-bullets-string'.") |
fd5359c6 | 965 | (make-variable-buffer-local 'allout-bullets-string-len) |
d8350998 CY |
966 | ;;;_ = allout-depth-specific-regexp |
967 | (defvar allout-depth-specific-regexp "" | |
fb7ada5f | 968 | "Regular expression to match a heading line prefix for a particular depth. |
d8350998 CY |
969 | |
970 | This expression is used to search for depth-specific topic | |
971 | headers at depth 2 and greater. Use `allout-depth-one-regexp' | |
972 | for to seek topics at depth one. | |
973 | ||
974 | This var is set according to the user configuration vars by | |
975 | `set-allout-regexp'. It is prepared with format strings for two | |
976 | decimal numbers, which should each be one less than the depth of the | |
977 | topic prefix to be matched.") | |
978 | (make-variable-buffer-local 'allout-depth-specific-regexp) | |
979 | ;;;_ = allout-depth-one-regexp | |
980 | (defvar allout-depth-one-regexp "" | |
fb7ada5f | 981 | "Regular expression to match a heading line prefix for depth one. |
d8350998 CY |
982 | |
983 | This var is set according to the user configuration vars by | |
984 | `set-allout-regexp'. It is prepared with format strings for two | |
985 | decimal numbers, which should each be one less than the depth of the | |
986 | topic prefix to be matched.") | |
987 | (make-variable-buffer-local 'allout-depth-one-regexp) | |
fd5359c6 MR |
988 | ;;;_ = allout-line-boundary-regexp |
989 | (defvar allout-line-boundary-regexp () | |
42c3e51c | 990 | "`allout-regexp' prepended with a newline for the search target. |
19b84ba3 | 991 | |
d8350998 | 992 | This is properly set by `set-allout-regexp'.") |
fd5359c6 MR |
993 | (make-variable-buffer-local 'allout-line-boundary-regexp) |
994 | ;;;_ = allout-bob-regexp | |
995 | (defvar allout-bob-regexp () | |
d8350998 | 996 | "Like `allout-line-boundary-regexp', for headers at beginning of buffer.") |
fd5359c6 MR |
997 | (make-variable-buffer-local 'allout-bob-regexp) |
998 | ;;;_ = allout-header-subtraction | |
999 | (defvar allout-header-subtraction (1- (length allout-header-prefix)) | |
1000 | "Allout-header prefix length to subtract when computing topic depth.") | |
1001 | (make-variable-buffer-local 'allout-header-subtraction) | |
1002 | ;;;_ = allout-plain-bullets-string-len | |
1003 | (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) | |
2265e017 | 1004 | "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") |
fd5359c6 MR |
1005 | (make-variable-buffer-local 'allout-plain-bullets-string-len) |
1006 | ||
d8350998 | 1007 | ;;;_ = allout-doublecheck-at-and-shallower |
2a1408fd | 1008 | (defconst allout-doublecheck-at-and-shallower 3 |
ede4ac6a | 1009 | "Validate apparent topics of this depth and shallower as being non-aberrant. |
fd5359c6 | 1010 | |
2a1408fd DN |
1011 | Verified with `allout-aberrant-container-p'. The usefulness of |
1012 | this check is limited to shallow depths, because the | |
1013 | determination of aberrance is according to the mistaken item | |
1014 | being followed by a legitimate item of excessively greater depth. | |
1015 | ||
1016 | The classic example of a mistaken item, for a standard allout | |
1017 | outline configuration, is a body line that begins with an '...' | |
1018 | ellipsis. This happens to contain a legitimate depth-2 header | |
1019 | prefix, constituted by two '..' dots at the beginning of the | |
1020 | line. The only thing that can distinguish it *in principle* from | |
1021 | a legitimate one is if the following real header is at a depth | |
1022 | that is discontinuous from the depth of 2 implied by the | |
1023 | ellipsis, ie depth 4 or more. As the depth being tested gets | |
1024 | greater, the likelihood of this kind of disqualification is | |
1025 | lower, and the usefulness of this test is lower. | |
1026 | ||
1027 | Extending the depth of the doublecheck increases the amount it is | |
1028 | applied, increasing the cost of the test - on casual estimation, | |
1029 | for outlines with many deep topics, geometrically (O(n)?). | |
1030 | Taken together with decreasing likelihood that the test will be | |
1031 | useful at greater depths, more modest doublecheck limits are more | |
1032 | suitably economical.") | |
fd5359c6 MR |
1033 | ;;;_ X allout-reset-header-lead (header-lead) |
1034 | (defun allout-reset-header-lead (header-lead) | |
9201cc28 | 1035 | "Reset the leading string used to identify topic headers." |
1977b8f6 | 1036 | (interactive "sNew lead string: ") |
fd5359c6 MR |
1037 | (setq allout-header-prefix header-lead) |
1038 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
1039 | (set-allout-regexp)) | |
1040 | ;;;_ X allout-lead-with-comment-string (header-lead) | |
1041 | (defun allout-lead-with-comment-string (&optional header-lead) | |
9201cc28 | 1042 | "Set the topic-header leading string to specified string. |
19b84ba3 | 1043 | |
20db1522 | 1044 | Useful for encapsulating outline structure in programming |
19b84ba3 | 1045 | language comments. Returns the leading string." |
1977b8f6 RS |
1046 | |
1047 | (interactive "P") | |
1048 | (if (not (stringp header-lead)) | |
1049 | (setq header-lead (read-string | |
1050 | "String prefix for topic headers: "))) | |
fd5359c6 MR |
1051 | (setq allout-reindent-bodies nil) |
1052 | (allout-reset-header-lead header-lead) | |
1977b8f6 | 1053 | header-lead) |
48bd8440 EZ |
1054 | ;;;_ > allout-infer-header-lead-and-primary-bullet () |
1055 | (defun allout-infer-header-lead-and-primary-bullet () | |
1056 | "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'. | |
19b84ba3 RS |
1057 | |
1058 | Works according to settings of: | |
1059 | ||
8d118843 | 1060 | `comment-start' |
fd5359c6 MR |
1061 | `allout-header-prefix' (default) |
1062 | `allout-use-mode-specific-leader' | |
1063 | and `allout-mode-leaders'. | |
19b84ba3 | 1064 | |
c07583cd | 1065 | Apply this via (re)activation of `allout-mode', rather than |
8d118843 | 1066 | invoking it directly." |
fd5359c6 MR |
1067 | (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) |
1068 | (if (or (stringp allout-use-mode-specific-leader) | |
1069 | (memq allout-use-mode-specific-leader | |
1070 | '(allout-mode-leaders | |
19b84ba3 RS |
1071 | comment-start |
1072 | t))) | |
fd5359c6 | 1073 | allout-use-mode-specific-leader |
60c7bbd2 | 1074 | ;; Oops -- garbled value, equate with effect of t: |
19b84ba3 RS |
1075 | t))) |
1076 | (leader | |
1077 | (cond | |
1078 | ((not use-leader) nil) | |
1079 | ;; Use the explicitly designated leader: | |
1080 | ((stringp use-leader) use-leader) | |
fd5359c6 | 1081 | (t (or (and (memq use-leader '(t allout-mode-leaders)) |
19b84ba3 | 1082 | ;; Get it from outline mode leaders? |
fd5359c6 MR |
1083 | (cdr (assq major-mode allout-mode-leaders))) |
1084 | ;; ... didn't get from allout-mode-leaders... | |
19b84ba3 RS |
1085 | (and (memq use-leader '(t comment-start)) |
1086 | comment-start | |
1087 | ;; Use comment-start, maybe tripled, and with | |
353e2ef2 | 1088 | ;; underscore: |
19b84ba3 RS |
1089 | (concat |
1090 | (if (string= " " | |
1091 | (substring comment-start | |
1092 | (1- (length comment-start)))) | |
1093 | ;; Use comment-start, sans trailing space: | |
1094 | (substring comment-start 0 -1) | |
1095 | (concat comment-start comment-start comment-start)) | |
1096 | ;; ... and append underscore, whichever: | |
1097 | "_"))))))) | |
1098 | (if (not leader) | |
1099 | nil | |
48bd8440 EZ |
1100 | (setq allout-header-prefix leader) |
1101 | (if (not allout-old-style-prefixes) | |
ea18b2b1 | 1102 | ;; setting allout-primary-bullet makes the top level topics use -- |
60c7bbd2 | 1103 | ;; actually, be -- the special prefix: |
48bd8440 EZ |
1104 | (setq allout-primary-bullet leader)) |
1105 | allout-header-prefix))) | |
1106 | (defalias 'allout-infer-header-lead | |
1107 | 'allout-infer-header-lead-and-primary-bullet) | |
fd5359c6 MR |
1108 | ;;;_ > allout-infer-body-reindent () |
1109 | (defun allout-infer-body-reindent () | |
1110 | "Determine proper setting for `allout-reindent-bodies'. | |
8d118843 | 1111 | |
c07583cd | 1112 | Depends on default setting of `allout-reindent-bodies' (which see) |
8d118843 RS |
1113 | and presence of setting for `comment-start', to tell whether the |
1114 | file is programming code." | |
fd5359c6 | 1115 | (if (and allout-reindent-bodies |
8d118843 | 1116 | comment-start |
fd5359c6 MR |
1117 | (not (eq 'force allout-reindent-bodies))) |
1118 | (setq allout-reindent-bodies nil))) | |
1119 | ;;;_ > set-allout-regexp () | |
1120 | (defun set-allout-regexp () | |
19b84ba3 RS |
1121 | "Generate proper topic-header regexp form for outline functions. |
1122 | ||
fd5359c6 | 1123 | Works with respect to `allout-plain-bullets-string' and |
d8350998 CY |
1124 | `allout-distinctive-bullets-string'. |
1125 | ||
1126 | Also refresh various data structures that hinge on the regexp." | |
1977b8f6 RS |
1127 | |
1128 | (interactive) | |
fd5359c6 MR |
1129 | ;; Derive allout-bullets-string from user configured components: |
1130 | (setq allout-bullets-string "") | |
1131 | (let ((strings (list 'allout-plain-bullets-string | |
1132 | 'allout-distinctive-bullets-string | |
1133 | 'allout-primary-bullet)) | |
1977b8f6 RS |
1134 | cur-string |
1135 | cur-len | |
c567ac01 | 1136 | cur-char |
96b83743 | 1137 | index) |
1977b8f6 | 1138 | (while strings |
96b83743 | 1139 | (setq index 0) |
1977b8f6 RS |
1140 | (setq cur-len (length (setq cur-string (symbol-value (car strings))))) |
1141 | (while (< index cur-len) | |
1142 | (setq cur-char (aref cur-string index)) | |
fd5359c6 MR |
1143 | (setq allout-bullets-string |
1144 | (concat allout-bullets-string | |
1977b8f6 RS |
1145 | (cond |
1146 | ; Single dash would denote a | |
1147 | ; sequence, repeated denotes | |
1148 | ; a dash: | |
1149 | ((eq cur-char ?-) "--") | |
1150 | ; literal close-square-bracket | |
1151 | ; doesn't work right in the | |
1152 | ; expr, exclude it: | |
1153 | ((eq cur-char ?\]) "") | |
1154 | (t (regexp-quote (char-to-string cur-char)))))) | |
1155 | (setq index (1+ index))) | |
1156 | (setq strings (cdr strings))) | |
1157 | ) | |
fd5359c6 MR |
1158 | ;; Derive next for repeated use in allout-pending-bullet: |
1159 | (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) | |
1160 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
d8350998 | 1161 | |
42c3e51c | 1162 | (let (new-part old-part formfeed-part) |
d8350998 CY |
1163 | (setq new-part (concat "\\(" |
1164 | (regexp-quote allout-header-prefix) | |
1165 | "[ \t]*" | |
1166 | ;; already regexp-quoted in a custom way: | |
1167 | "[" allout-bullets-string "]" | |
1168 | "\\)") | |
1169 | old-part (concat "\\(" | |
1170 | (regexp-quote allout-primary-bullet) | |
1171 | "\\|" | |
1172 | (regexp-quote allout-header-prefix) | |
1173 | "\\)" | |
1174 | "+" | |
1175 | " ?[^" allout-primary-bullet "]") | |
42c3e51c KM |
1176 | formfeed-part "\\(\^L\\)" |
1177 | ||
d8350998 CY |
1178 | allout-regexp (concat new-part |
1179 | "\\|" | |
1180 | old-part | |
42c3e51c KM |
1181 | "\\|" |
1182 | formfeed-part) | |
d8350998 CY |
1183 | |
1184 | allout-line-boundary-regexp (concat "\n" new-part | |
1185 | "\\|" | |
42c3e51c KM |
1186 | "\n" old-part |
1187 | "\\|" | |
1188 | "\n" formfeed-part) | |
d8350998 CY |
1189 | |
1190 | allout-bob-regexp (concat "\\`" new-part | |
1191 | "\\|" | |
42c3e51c KM |
1192 | "\\`" old-part |
1193 | "\\|" | |
1194 | "\\`" formfeed-part | |
1195 | )) | |
d8350998 CY |
1196 | |
1197 | (setq allout-depth-specific-regexp | |
1198 | (concat "\\(^\\|\\`\\)" | |
1199 | "\\(" | |
1200 | ||
1201 | ;; new-style spacers-then-bullet string: | |
1202 | "\\(" | |
1203 | (allout-format-quote (regexp-quote allout-header-prefix)) | |
1204 | " \\{%s\\}" | |
1205 | "[" (allout-format-quote allout-bullets-string) "]" | |
1206 | "\\)" | |
1207 | ||
1208 | ;; old-style all-bullets string, if primary not multi-char: | |
1209 | (if (< 0 allout-header-subtraction) | |
1210 | "" | |
1211 | (concat "\\|\\(" | |
1212 | (allout-format-quote | |
1213 | (regexp-quote allout-primary-bullet)) | |
1214 | (allout-format-quote | |
1215 | (regexp-quote allout-primary-bullet)) | |
1216 | (allout-format-quote | |
1217 | (regexp-quote allout-primary-bullet)) | |
1218 | "\\{%s\\}" | |
1219 | ;; disqualify greater depths: | |
1220 | "[^" | |
1221 | (allout-format-quote allout-primary-bullet) | |
1222 | "]\\)" | |
1223 | )) | |
1224 | "\\)" | |
1225 | )) | |
1226 | (setq allout-depth-one-regexp | |
1227 | (concat "\\(^\\|\\`\\)" | |
1228 | "\\(" | |
1229 | ||
1230 | "\\(" | |
1231 | (regexp-quote allout-header-prefix) | |
1232 | ;; disqualify any bullet char following any amount of | |
1233 | ;; intervening whitespace: | |
1234 | " *" | |
1235 | (concat "[^ " allout-bullets-string "]") | |
1236 | "\\)" | |
1237 | (if (< 0 allout-header-subtraction) | |
1238 | ;; Need not support anything like the old | |
1239 | ;; bullet style if the prefix is multi-char. | |
1240 | "" | |
1241 | (concat "\\|" | |
1242 | (regexp-quote allout-primary-bullet) | |
1243 | ;; disqualify deeper primary-bullet sequences: | |
1244 | "[^" allout-primary-bullet "]")) | |
1245 | "\\)" | |
1246 | )))) | |
9179616f | 1247 | ;;;_ : Menu bar |
95c12694 RS |
1248 | (defvar allout-mode-exposure-menu) |
1249 | (defvar allout-mode-editing-menu) | |
1250 | (defvar allout-mode-navigation-menu) | |
1251 | (defvar allout-mode-misc-menu) | |
fd5359c6 | 1252 | (defun produce-allout-mode-menubar-entries () |
9179616f | 1253 | (require 'easymenu) |
fd5359c6 | 1254 | (easy-menu-define allout-mode-exposure-menu |
d3e51865 | 1255 | allout-mode-map-value |
9179616f DL |
1256 | "Allout outline exposure menu." |
1257 | '("Exposure" | |
fd5359c6 MR |
1258 | ["Show Entry" allout-show-current-entry t] |
1259 | ["Show Children" allout-show-children t] | |
1260 | ["Show Subtree" allout-show-current-subtree t] | |
1261 | ["Hide Subtree" allout-hide-current-subtree t] | |
1262 | ["Hide Leaves" allout-hide-current-leaves t] | |
9179616f | 1263 | "----" |
fd5359c6 MR |
1264 | ["Show All" allout-show-all t])) |
1265 | (easy-menu-define allout-mode-editing-menu | |
d3e51865 | 1266 | allout-mode-map-value |
9179616f DL |
1267 | "Allout outline editing menu." |
1268 | '("Headings" | |
fd5359c6 MR |
1269 | ["Open Sibling" allout-open-sibtopic t] |
1270 | ["Open Subtopic" allout-open-subtopic t] | |
1271 | ["Open Supertopic" allout-open-supertopic t] | |
9179616f | 1272 | "----" |
fd5359c6 MR |
1273 | ["Shift Topic In" allout-shift-in t] |
1274 | ["Shift Topic Out" allout-shift-out t] | |
1275 | ["Rebullet Topic" allout-rebullet-topic t] | |
1276 | ["Rebullet Heading" allout-rebullet-current-heading t] | |
d82979ea EZ |
1277 | ["Number Siblings" allout-number-siblings t] |
1278 | "----" | |
1279 | ["Toggle Topic Encryption" | |
1280 | allout-toggle-current-subtree-encryption | |
1281 | (> (allout-current-depth) 1)])) | |
fd5359c6 | 1282 | (easy-menu-define allout-mode-navigation-menu |
d3e51865 | 1283 | allout-mode-map-value |
9179616f DL |
1284 | "Allout outline navigation menu." |
1285 | '("Navigation" | |
fd5359c6 | 1286 | ["Next Visible Heading" allout-next-visible-heading t] |
9179616f | 1287 | ["Previous Visible Heading" |
fd5359c6 | 1288 | allout-previous-visible-heading t] |
9179616f | 1289 | "----" |
fd5359c6 MR |
1290 | ["Up Level" allout-up-current-level t] |
1291 | ["Forward Current Level" allout-forward-current-level t] | |
9179616f | 1292 | ["Backward Current Level" |
fd5359c6 | 1293 | allout-backward-current-level t] |
9179616f DL |
1294 | "----" |
1295 | ["Beginning of Entry" | |
fd5359c6 | 1296 | allout-beginning-of-current-entry t] |
d82979ea | 1297 | ["End of Entry" allout-end-of-entry t] |
fd5359c6 MR |
1298 | ["End of Subtree" allout-end-of-current-subtree t])) |
1299 | (easy-menu-define allout-mode-misc-menu | |
d3e51865 | 1300 | allout-mode-map-value |
9179616f DL |
1301 | "Allout outlines miscellaneous bindings." |
1302 | '("Misc" | |
fd5359c6 | 1303 | ["Version" allout-version t] |
9179616f | 1304 | "----" |
fd5359c6 | 1305 | ["Duplicate Exposed" allout-copy-exposed-to-buffer t] |
9179616f | 1306 | ["Duplicate Exposed, numbered" |
71296446 | 1307 | allout-flatten-exposed-to-buffer t] |
9179616f | 1308 | ["Duplicate Exposed, indented" |
71296446 | 1309 | allout-indented-exposed-to-buffer t] |
9179616f | 1310 | "----" |
fd5359c6 MR |
1311 | ["Set Header Lead" allout-reset-header-lead t] |
1312 | ["Set New Exposure" allout-expose-topic t]))) | |
01fc9422 | 1313 | ;;;_ : Allout Modal-Variables Utilities |
fd5359c6 MR |
1314 | ;;;_ = allout-mode-prior-settings |
1315 | (defvar allout-mode-prior-settings nil | |
01fc9422 | 1316 | "Internal `allout-mode' use; settings to be resumed on mode deactivation. |
1977b8f6 | 1317 | |
01fc9422 EZ |
1318 | See `allout-add-resumptions' and `allout-do-resumptions'.") |
1319 | (make-variable-buffer-local 'allout-mode-prior-settings) | |
1320 | ;;;_ > allout-add-resumptions (&rest pairs) | |
1321 | (defun allout-add-resumptions (&rest pairs) | |
48bd8440 | 1322 | "Set name/value PAIRS. |
01fc9422 EZ |
1323 | |
1324 | Old settings are preserved for later resumption using `allout-do-resumptions'. | |
1325 | ||
48bd8440 EZ |
1326 | The new values are set as a buffer local. On resumption, the prior buffer |
1327 | scope of the variable is restored along with its value. If it was a void | |
1328 | buffer-local value, then it is left as nil on resumption. | |
1329 | ||
01fc9422 | 1330 | The pairs are lists whose car is the name of the variable and car of the |
48bd8440 EZ |
1331 | cdr is the new value: '(some-var some-value)'. The pairs can actually be |
1332 | triples, where the third element qualifies the disposition of the setting, | |
1333 | as described further below. | |
01fc9422 | 1334 | |
48bd8440 EZ |
1335 | If the optional third element is the symbol 'extend, then the new value |
1336 | created by `cons'ing the second element of the pair onto the front of the | |
1337 | existing value. | |
01fc9422 | 1338 | |
48bd8440 EZ |
1339 | If the optional third element is the symbol 'append, then the new value is |
1340 | extended from the existing one by `append'ing a list containing the second | |
1341 | element of the pair onto the end of the existing value. | |
01fc9422 | 1342 | |
48bd8440 | 1343 | Extension, and resumptions in general, should not be used for hook |
60c7bbd2 | 1344 | functions -- use the 'local mode of `add-hook' for that, instead. |
01fc9422 EZ |
1345 | |
1346 | The settings are stored on `allout-mode-prior-settings'." | |
1347 | (while pairs | |
1348 | (let* ((pair (pop pairs)) | |
1349 | (name (car pair)) | |
48bd8440 EZ |
1350 | (value (cadr pair)) |
1351 | (qualifier (if (> (length pair) 2) | |
1352 | (caddr pair))) | |
1353 | prior-value) | |
01fc9422 EZ |
1354 | (if (not (symbolp name)) |
1355 | (error "Pair's name, %S, must be a symbol, not %s" | |
1356 | name (type-of name))) | |
d8350998 | 1357 | (setq prior-value (condition-case nil |
48bd8440 EZ |
1358 | (symbol-value name) |
1359 | (void-variable nil))) | |
01fc9422 EZ |
1360 | (when (not (assoc name allout-mode-prior-settings)) |
1361 | ;; Not already added as a resumption, create the prior setting entry. | |
1c9b9df0 | 1362 | (if (local-variable-p name (current-buffer)) |
60c7bbd2 | 1363 | ;; is already local variable -- preserve the prior value: |
48bd8440 | 1364 | (push (list name prior-value) allout-mode-prior-settings) |
01fc9422 EZ |
1365 | ;; wasn't local variable, indicate so for resumption by killing |
1366 | ;; local value, and make it local: | |
1367 | (push (list name) allout-mode-prior-settings) | |
1368 | (make-local-variable name))) | |
48bd8440 EZ |
1369 | (if qualifier |
1370 | (cond ((eq qualifier 'extend) | |
1371 | (if (not (listp prior-value)) | |
1372 | (error "extension of non-list prior value attempted") | |
1373 | (set name (cons value prior-value)))) | |
1374 | ((eq qualifier 'append) | |
1375 | (if (not (listp prior-value)) | |
1376 | (error "appending of non-list prior value attempted") | |
1377 | (set name (append prior-value (list value))))) | |
1378 | (t (error "unrecognized setting qualifier `%s' encountered" | |
1379 | qualifier))) | |
1380 | (set name value))))) | |
01fc9422 EZ |
1381 | ;;;_ > allout-do-resumptions () |
1382 | (defun allout-do-resumptions () | |
1383 | "Resume all name/value settings registered by `allout-add-resumptions'. | |
1384 | ||
1385 | This is used when concluding allout-mode, to resume selected variables to | |
1386 | their settings before allout-mode was started." | |
1387 | ||
1388 | (while allout-mode-prior-settings | |
1389 | (let* ((pair (pop allout-mode-prior-settings)) | |
1390 | (name (car pair)) | |
1391 | (value-cell (cdr pair))) | |
1392 | (if (not value-cell) | |
1393 | ;; Prior value was global: | |
1394 | (kill-local-variable name) | |
1395 | ;; Prior value was explicit: | |
1396 | (set name (car value-cell)))))) | |
9179616f | 1397 | ;;;_ : Mode-specific incidentals |
fd5359c6 | 1398 | ;;;_ > allout-unprotected (expr) |
d82979ea | 1399 | (defmacro allout-unprotected (expr) |
96b83743 | 1400 | "Enable internal outline operations to alter invisible text." |
1b4d97b2 | 1401 | `(let ((inhibit-read-only (if (not buffer-read-only) t)) |
0458fa80 | 1402 | (inhibit-field-text-motion t)) |
96b83743 EZ |
1403 | ,expr)) |
1404 | ;;;_ = allout-mode-hook | |
1405 | (defvar allout-mode-hook nil | |
7b97c764 | 1406 | "Hook run when allout mode starts.") |
01fc9422 | 1407 | ;;;_ = allout-mode-deactivate-hook |
7927f48d | 1408 | (define-obsolete-variable-alias 'allout-mode-deactivate-hook |
c6eee9aa | 1409 | 'allout-mode-off-hook "24.1") |
e5bd0a28 SM |
1410 | (defvar allout-mode-deactivate-hook nil |
1411 | "Hook run when allout mode ends.") | |
01fc9422 EZ |
1412 | ;;;_ = allout-exposure-category |
1413 | (defvar allout-exposure-category nil | |
1414 | "Symbol for use as allout invisible-text overlay category.") | |
48bd8440 | 1415 | |
7b97c764 | 1416 | ;;;_ = allout-exposure-change-functions |
e5bd0a28 | 1417 | (define-obsolete-variable-alias 'allout-exposure-change-hook |
2a1e2476 | 1418 | 'allout-exposure-change-functions "24.3") |
7b97c764 CY |
1419 | (defcustom allout-exposure-change-functions nil |
1420 | "Abnormal hook run after allout outline subtree exposure changes. | |
48bd8440 EZ |
1421 | It is run at the conclusion of `allout-flag-region'. |
1422 | ||
1423 | Functions on the hook must take three arguments: | |
1424 | ||
60c7bbd2 RS |
1425 | - FROM -- integer indicating the point at the start of the change. |
1426 | - TO -- integer indicating the point of the end of the change. | |
1427 | - FLAG -- change mode: nil for exposure, otherwise concealment. | |
48bd8440 | 1428 | |
7b97c764 CY |
1429 | This hook might be invoked multiple times by a single command." |
1430 | :type 'hook | |
1431 | :group 'allout | |
2a1e2476 | 1432 | :version "24.3") |
48bd8440 | 1433 | |
7b97c764 | 1434 | ;;;_ = allout-structure-added-functions |
e5bd0a28 | 1435 | (define-obsolete-variable-alias 'allout-structure-added-hook |
2a1e2476 | 1436 | 'allout-structure-added-functions "24.3") |
7b97c764 CY |
1437 | (defcustom allout-structure-added-functions nil |
1438 | "Abnormal hook run after adding items to an Allout outline. | |
48bd8440 EZ |
1439 | Functions on the hook should take two arguments: |
1440 | ||
60c7bbd2 RS |
1441 | - NEW-START -- integer indicating position of start of the first new item. |
1442 | - NEW-END -- integer indicating position of end of the last new item. | |
48bd8440 | 1443 | |
7b97c764 CY |
1444 | This hook might be invoked multiple times by a single command." |
1445 | :type 'hook | |
1446 | :group 'allout | |
2a1e2476 | 1447 | :version "24.3") |
7b97c764 | 1448 | |
7b97c764 | 1449 | ;;;_ = allout-structure-deleted-functions |
e5bd0a28 | 1450 | (define-obsolete-variable-alias 'allout-structure-deleted-hook |
2a1e2476 | 1451 | 'allout-structure-deleted-functions "24.3") |
7b97c764 CY |
1452 | (defcustom allout-structure-deleted-functions nil |
1453 | "Abnormal hook run after deleting subtrees from an Allout outline. | |
48bd8440 EZ |
1454 | Functions on the hook must take two arguments: |
1455 | ||
60c7bbd2 RS |
1456 | - DEPTH -- integer indicating the depth of the subtree that was deleted. |
1457 | - REMOVED-FROM -- integer indicating the point where the subtree was removed. | |
da506f05 | 1458 | |
20db1522 | 1459 | Some edits that remove or invalidate items may be missed by this hook: |
48bd8440 | 1460 | specifically edits that native allout routines do not control. |
96b83743 | 1461 | |
7b97c764 CY |
1462 | This hook might be invoked multiple times by a single command." |
1463 | :type 'hook | |
1464 | :group 'allout | |
2a1e2476 | 1465 | :version "24.3") |
48bd8440 | 1466 | |
7b97c764 | 1467 | ;;;_ = allout-structure-shifted-functions |
e5bd0a28 | 1468 | (define-obsolete-variable-alias 'allout-structure-shifted-hook |
2a1e2476 | 1469 | 'allout-structure-shifted-functions "24.3") |
7b97c764 CY |
1470 | (defcustom allout-structure-shifted-functions nil |
1471 | "Abnormal hook run after shifting items in an Allout outline. | |
48bd8440 EZ |
1472 | Functions on the hook should take two arguments: |
1473 | ||
60c7bbd2 RS |
1474 | - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease |
1475 | - START -- integer indicating the start point of the shifted parent item. | |
48bd8440 | 1476 | |
60c7bbd2 | 1477 | Some edits that shift items can be missed by this hook: specifically edits |
48bd8440 EZ |
1478 | that native allout routines do not control. |
1479 | ||
7b97c764 CY |
1480 | This hook might be invoked multiple times by a single command." |
1481 | :type 'hook | |
1482 | :group 'allout | |
2a1e2476 | 1483 | :version "24.3") |
7b97c764 | 1484 | |
4ec28e14 | 1485 | ;;;_ = allout-after-copy-or-kill-hook |
7b97c764 CY |
1486 | (defcustom allout-after-copy-or-kill-hook nil |
1487 | "Normal hook run after copying outline text.." | |
1488 | :type 'hook | |
1489 | :group 'allout | |
2a1e2476 | 1490 | :version "24.3") |
4ec28e14 | 1491 | |
919d884a | 1492 | ;;;_ = allout-post-undo-hook |
7b97c764 CY |
1493 | (defcustom allout-post-undo-hook nil |
1494 | "Normal hook run after undo activity. | |
919d884a | 1495 | The item that's current when the hook is run *may* be the one |
7b97c764 CY |
1496 | that was affected by the undo.." |
1497 | :type 'hook | |
1498 | :group 'allout | |
2a1e2476 | 1499 | :version "24.3") |
919d884a | 1500 | |
96b83743 EZ |
1501 | ;;;_ = allout-outside-normal-auto-fill-function |
1502 | (defvar allout-outside-normal-auto-fill-function nil | |
20db1522 | 1503 | "Value of `normal-auto-fill-function' outside of allout mode. |
96b83743 | 1504 | |
20db1522 JB |
1505 | Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function' |
1506 | wrapped within allout's automatic `fill-prefix' setting.") | |
96b83743 | 1507 | (make-variable-buffer-local 'allout-outside-normal-auto-fill-function) |
2576c28f KM |
1508 | ;;;_ = prevent redundant activation by desktop mode: |
1509 | (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil)) | |
0949617b EZ |
1510 | ;;;_ = allout-passphrase-verifier-string |
1511 | (defvar allout-passphrase-verifier-string nil | |
1512 | "Setting used to test solicited encryption passphrases against the one | |
1513 | already associated with a file. | |
1514 | ||
1515 | It consists of an encrypted random string useful only to verify that a | |
1516 | passphrase entered by the user is effective for decryption. The passphrase | |
1517 | itself is \*not* recorded in the file anywhere, and the encrypted contents | |
1518 | are random binary characters to avoid exposing greater susceptibility to | |
1519 | search attacks. | |
d82979ea EZ |
1520 | |
1521 | The verifier string is retained as an Emacs file variable, as well as in | |
a0a022d5 | 1522 | the Emacs buffer state, if file variable adjustments are enabled. See |
d82979ea | 1523 | `allout-enable-file-variable-adjustment' for details about that.") |
0949617b | 1524 | (make-variable-buffer-local 'allout-passphrase-verifier-string) |
59f7af81 CY |
1525 | (make-obsolete-variable 'allout-passphrase-verifier-string |
1526 | 'allout-passphrase-verifier-string "23.3") | |
8570ce80 | 1527 | ;;;###autoload |
7e5d77dc | 1528 | (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp) |
0949617b EZ |
1529 | ;;;_ = allout-passphrase-hint-string |
1530 | (defvar allout-passphrase-hint-string "" | |
1531 | "Variable used to retain reminder string for file's encryption passphrase. | |
d82979ea | 1532 | |
0949617b | 1533 | See the description of `allout-passphrase-hint-handling' for details about how |
d82979ea EZ |
1534 | the reminder is deployed. |
1535 | ||
a0a022d5 | 1536 | The hint is retained as an Emacs file variable, as well as in the Emacs buffer |
d82979ea EZ |
1537 | state, if file variable adjustments are enabled. See |
1538 | `allout-enable-file-variable-adjustment' for details about that.") | |
0949617b EZ |
1539 | (make-variable-buffer-local 'allout-passphrase-hint-string) |
1540 | (setq-default allout-passphrase-hint-string "") | |
59f7af81 CY |
1541 | (make-obsolete-variable 'allout-passphrase-hint-string |
1542 | 'allout-passphrase-hint-string "23.3") | |
8570ce80 SM |
1543 | ;;;###autoload |
1544 | (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp) | |
d82979ea EZ |
1545 | ;;;_ = allout-after-save-decrypt |
1546 | (defvar allout-after-save-decrypt nil | |
1547 | "Internal variable, is nil or has the value of two points: | |
1548 | ||
1549 | - the location of a topic to be decrypted after saving is done | |
1550 | - where to situate the cursor after the decryption is performed | |
1551 | ||
1552 | This is used to decrypt the topic that was currently being edited, if it | |
1553 | was encrypted automatically as part of a file write or autosave.") | |
1554 | (make-variable-buffer-local 'allout-after-save-decrypt) | |
48bd8440 EZ |
1555 | ;;;_ = allout-encryption-plaintext-sanitization-regexps |
1556 | (defvar allout-encryption-plaintext-sanitization-regexps nil | |
1557 | "List of regexps whose matches are removed from plaintext before encryption. | |
1558 | ||
1559 | This is for the sake of removing artifacts, like escapes, that are added on | |
1560 | and not actually part of the original plaintext. The removal is done just | |
1561 | prior to encryption. | |
1562 | ||
1563 | Entries must be symbols that are bound to the desired values. | |
1564 | ||
1565 | Each value can be a regexp or a list with a regexp followed by a | |
1566 | substitution string. If it's just a regexp, all its matches are removed | |
1567 | before the text is encrypted. If it's a regexp and a substitution, the | |
c7015153 | 1568 | substitution is used against the regexp matches, a la `replace-match'.") |
48bd8440 EZ |
1569 | (make-variable-buffer-local 'allout-encryption-text-removal-regexps) |
1570 | ;;;_ = allout-encryption-ciphertext-rejection-regexps | |
1571 | (defvar allout-encryption-ciphertext-rejection-regexps nil | |
1572 | "Variable for regexps matching plaintext to remove before encryption. | |
1573 | ||
ff3e8c8e | 1574 | This is used to detect strings in encryption results that would |
4c36be58 | 1575 | register as allout mode structural elements, for example, as a |
ff3e8c8e | 1576 | topic prefix. |
48bd8440 EZ |
1577 | |
1578 | Entries must be symbols that are bound to the desired regexp values. | |
1579 | ||
ff3e8c8e KM |
1580 | Encryptions that result in matches will be retried, up to |
1581 | `allout-encryption-ciphertext-rejection-limit' times, after which | |
1582 | an error is raised.") | |
48bd8440 EZ |
1583 | |
1584 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps) | |
1585 | ;;;_ = allout-encryption-ciphertext-rejection-ceiling | |
1586 | (defvar allout-encryption-ciphertext-rejection-ceiling 5 | |
1587 | "Limit on number of times encryption ciphertext is rejected. | |
1588 | ||
1589 | See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.") | |
1590 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling) | |
69027dea EZ |
1591 | ;;;_ > allout-mode-p () |
1592 | ;; Must define this macro above any uses, or byte compilation will lack | |
60c7bbd2 | 1593 | ;; proper def, if file isn't loaded -- eg, during emacs build! |
96497653 | 1594 | ;;;###autoload |
69027dea EZ |
1595 | (defmacro allout-mode-p () |
1596 | "Return t if `allout-mode' is active in current buffer." | |
1597 | 'allout-mode) | |
13aa217b KM |
1598 | ;;;_ > allout-write-contents-hook-handler () |
1599 | (defun allout-write-contents-hook-handler () | |
1600 | "Implement `allout-encrypt-unencrypted-on-saves' for file writes | |
1601 | ||
1602 | Return nil if all goes smoothly, or else return an informative | |
1603 | message if an error is encountered. The message will serve as a | |
1604 | non-nil return on `write-contents-functions' to prevent saving of | |
1605 | the buffer while it has decrypted content. | |
1606 | ||
20db1522 | 1607 | This behavior depends on Emacs versions that implement the |
13aa217b | 1608 | `write-contents-functions' hook." |
d82979ea | 1609 | |
0949617b EZ |
1610 | (if (or (not (allout-mode-p)) |
1611 | (not (boundp 'allout-encrypt-unencrypted-on-saves)) | |
d82979ea EZ |
1612 | (not allout-encrypt-unencrypted-on-saves)) |
1613 | nil | |
13aa217b KM |
1614 | (if (save-excursion (goto-char (point-min)) |
1615 | (allout-next-topic-pending-encryption)) | |
1616 | (progn | |
1617 | (message "auto-encrypting pending topics") | |
1618 | (sit-for 0) | |
1619 | (condition-case failure | |
1620 | (progn | |
d82979ea | 1621 | (setq allout-after-save-decrypt |
13aa217b KM |
1622 | (allout-encrypt-decrypted)) |
1623 | ;; aok - return nil: | |
1624 | nil) | |
1625 | (error | |
1626 | ;; whoops - probably some still-decrypted items, return non-nil: | |
1627 | (let ((text (format (concat "%s contents write inhibited due to" | |
1628 | " encrypted topic encryption error:" | |
1629 | " %s") | |
1630 | (buffer-name (current-buffer)) | |
1631 | failure))) | |
1632 | (message text)(sit-for 2) | |
1633 | text))))) | |
1634 | )) | |
d82979ea EZ |
1635 | ;;;_ > allout-after-saves-handler () |
1636 | (defun allout-after-saves-handler () | |
1637 | "Decrypt topic encrypted for save, if it's currently being edited. | |
1638 | ||
1639 | Ie, if it was pending encryption and contained the point in its body before | |
1640 | the save. | |
1641 | ||
1642 | We use values stored in `allout-after-save-decrypt' to locate the topic | |
1643 | and the place for the cursor after the decryption is done." | |
1644 | (if (not (and (allout-mode-p) | |
1645 | (boundp 'allout-after-save-decrypt) | |
1646 | allout-after-save-decrypt)) | |
1647 | t | |
1648 | (goto-char (car allout-after-save-decrypt)) | |
1649 | (let ((was-modified (buffer-modified-p))) | |
69027dea | 1650 | (allout-toggle-subtree-encryption) |
d82979ea EZ |
1651 | (if (not was-modified) |
1652 | (set-buffer-modified-p nil))) | |
1653 | (goto-char (cadr allout-after-save-decrypt)) | |
1654 | (setq allout-after-save-decrypt nil)) | |
1655 | ) | |
1c9b9df0 KM |
1656 | ;;;_ > allout-called-interactively-p () |
1657 | (defmacro allout-called-interactively-p () | |
20db1522 | 1658 | "A version of `called-interactively-p' independent of Emacs version." |
1c9b9df0 | 1659 | ;; ... to ease maintenance of allout without betraying deprecation. |
23ba2705 SM |
1660 | (if (ignore-errors (called-interactively-p 'interactive) t) |
1661 | '(called-interactively-p 'interactive) | |
1662 | '(called-interactively-p))) | |
498a6493 CY |
1663 | ;;;_ = allout-inhibit-aberrance-doublecheck nil |
1664 | ;; In some exceptional moments, disparate topic depths need to be allowed | |
1665 | ;; momentarily, eg when one topic is being yanked into another and they're | |
1666 | ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck | |
1667 | ;; prevents the aberrance doublecheck to allow, eg, the reconciliation | |
1668 | ;; processing to happen in the presence of such discrepancies. It should | |
1669 | ;; almost never be needed, however. | |
1670 | (defvar allout-inhibit-aberrance-doublecheck nil | |
1671 | "Internal state, for momentarily inhibits aberrance doublecheck. | |
1672 | ||
1673 | This should only be momentarily let-bound non-nil, not set | |
1674 | non-nil in a lasting way.") | |
19b84ba3 | 1675 | |
1c9b9df0 | 1676 | ;;;_ #2 Mode environment and activation |
fd5359c6 MR |
1677 | ;;;_ = allout-explicitly-deactivated |
1678 | (defvar allout-explicitly-deactivated nil | |
d82979ea | 1679 | "If t, `allout-mode's last deactivation was deliberate. |
2265e017 | 1680 | So `allout-post-command-business' should not reactivate it...") |
fd5359c6 | 1681 | (make-variable-buffer-local 'allout-explicitly-deactivated) |
11c46e15 KM |
1682 | ;;;_ > allout-init (mode) |
1683 | (defun allout-init (mode) | |
1684 | "DEPRECATED - configure allout activation by customizing | |
1685 | `allout-auto-activation'. This function remains around, limited | |
01c35094 | 1686 | from what it did before, for backwards compatibility. |
11c46e15 KM |
1687 | |
1688 | MODE is the activation mode - see `allout-auto-activation' for | |
1689 | valid values." | |
59f7af81 | 1690 | (declare (obsolete allout-auto-activation "23.3")) |
11c46e15 KM |
1691 | (custom-set-variables (list 'allout-auto-activation (format "%s" mode))) |
1692 | (format "%s" mode)) | |
59f7af81 | 1693 | |
fd5359c6 MR |
1694 | ;;;_ > allout-setup-menubar () |
1695 | (defun allout-setup-menubar () | |
aad94676 | 1696 | "Populate the current buffer's menubar with `allout-mode' stuff." |
fd5359c6 MR |
1697 | (let ((menus (list allout-mode-exposure-menu |
1698 | allout-mode-editing-menu | |
1699 | allout-mode-navigation-menu | |
1700 | allout-mode-misc-menu)) | |
9179616f DL |
1701 | cur) |
1702 | (while menus | |
1703 | (setq cur (car menus) | |
1704 | menus (cdr menus)) | |
1705 | (easy-menu-add cur)))) | |
01fc9422 EZ |
1706 | ;;;_ > allout-overlay-preparations |
1707 | (defun allout-overlay-preparations () | |
1708 | "Set the properties of the allout invisible-text overlay and others." | |
1709 | (setplist 'allout-exposure-category nil) | |
1710 | (put 'allout-exposure-category 'invisible 'allout) | |
1711 | (put 'allout-exposure-category 'evaporate t) | |
1c9b9df0 | 1712 | ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The |
ea18b2b1 | 1713 | ;; latter would be sufficient, but it seems that a separate behavior -- |
60c7bbd2 RS |
1714 | ;; the _transient_ opening of invisible text during isearch -- is keyed to |
1715 | ;; presence of the isearch-open-invisible property -- even though this | |
96b83743 | 1716 | ;; property controls the isearch _arrival_ behavior. This is the case at |
21e8bc99 | 1717 | ;; least in emacs 21, 22.1, and xemacs 21.4. |
01fc9422 | 1718 | (put 'allout-exposure-category 'isearch-open-invisible |
96b83743 EZ |
1719 | 'allout-isearch-end-handler) |
1720 | (if (featurep 'xemacs) | |
01fc9422 EZ |
1721 | (put 'allout-exposure-category 'start-open t) |
1722 | (put 'allout-exposure-category 'insert-in-front-hooks | |
96b83743 | 1723 | '(allout-overlay-insert-in-front-handler))) |
01fc9422 EZ |
1724 | (put 'allout-exposure-category 'modification-hooks |
1725 | '(allout-overlay-interior-modification-handler))) | |
d3e51865 | 1726 | ;;;_ > define-minor-mode allout-mode |
19b84ba3 | 1727 | ;;;_ : Defun: |
0949617b | 1728 | ;;;###autoload |
d3e51865 | 1729 | (define-minor-mode allout-mode |
c567ac01 | 1730 | ;;;_ . Doc string: |
06e21633 CY |
1731 | "Toggle Allout outline mode. |
1732 | With a prefix argument ARG, enable Allout outline mode if ARG is | |
1733 | positive, and disable it otherwise. If called from Lisp, enable | |
1734 | the mode if ARG is omitted or nil. | |
19b84ba3 | 1735 | |
06e21633 CY |
1736 | \\<allout-mode-map-value> |
1737 | Allout outline mode is a minor mode that provides extensive | |
1738 | outline oriented formatting and manipulation. It enables | |
1739 | structural editing of outlines, as well as navigation and | |
1740 | exposure. It also is specifically aimed at accommodating | |
20db1522 | 1741 | syntax-sensitive text like programming languages. (For example, |
06e21633 CY |
1742 | see the allout code itself, which is organized as an allout |
1743 | outline.) | |
19b84ba3 | 1744 | |
c07583cd | 1745 | In addition to typical outline navigation and exposure, allout includes: |
19b84ba3 | 1746 | |
c07583cd KS |
1747 | - topic-oriented authoring, including keystroke-based topic creation, |
1748 | repositioning, promotion/demotion, cut, and paste | |
9179616f | 1749 | - incremental search with dynamic exposure and reconcealment of hidden text |
c07583cd | 1750 | - adjustable format, so programming code can be developed in outline-structure |
2576c28f | 1751 | - easy topic encryption and decryption, symmetric or key-pair |
c07583cd KS |
1752 | - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control |
1753 | - integral outline layout, for automatic initial exposure when visiting a file | |
1754 | - independent extensibility, using comprehensive exposure and authoring hooks | |
9179616f DL |
1755 | |
1756 | and many other features. | |
19b84ba3 | 1757 | |
2576c28f KM |
1758 | Below is a description of the key bindings, and then description |
1759 | of special `allout-mode' features and terminology. See also the | |
1760 | outline menubar additions for quick reference to many of the | |
11c46e15 | 1761 | features. Customize `allout-auto-activation' to prepare your |
20db1522 | 1762 | Emacs session for automatic activation of `allout-mode'. |
9179616f | 1763 | |
d3e51865 KM |
1764 | The bindings are those listed in `allout-prefixed-keybindings' |
1765 | and `allout-unprefixed-keybindings'. We recommend customizing | |
1766 | `allout-command-prefix' to use just `\\C-c' as the command | |
1767 | prefix, if the allout bindings don't conflict with any personal | |
1768 | bindings you have on \\C-c. In any case, outline structure | |
1769 | navigation and authoring is simplified by positioning the cursor | |
1770 | on an item's bullet character, the \"hot-spot\" -- then you can | |
1771 | invoke allout commands with just the un-prefixed, | |
1772 | un-control-shifted command letters. This is described further in | |
1773 | the HOT-SPOT Operation section. | |
c07583cd KS |
1774 | |
1775 | Exposure Control: | |
1776 | ---------------- | |
1777 | \\[allout-hide-current-subtree] `allout-hide-current-subtree' | |
1778 | \\[allout-show-children] `allout-show-children' | |
1779 | \\[allout-show-current-subtree] `allout-show-current-subtree' | |
1780 | \\[allout-show-current-entry] `allout-show-current-entry' | |
1781 | \\[allout-show-all] `allout-show-all' | |
1782 | ||
1783 | Navigation: | |
1784 | ---------- | |
1785 | \\[allout-next-visible-heading] `allout-next-visible-heading' | |
1786 | \\[allout-previous-visible-heading] `allout-previous-visible-heading' | |
1787 | \\[allout-up-current-level] `allout-up-current-level' | |
1788 | \\[allout-forward-current-level] `allout-forward-current-level' | |
1789 | \\[allout-backward-current-level] `allout-backward-current-level' | |
1790 | \\[allout-end-of-entry] `allout-end-of-entry' | |
1791 | \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot) | |
60c7bbd2 | 1792 | \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but |
c07583cd KS |
1793 | if immediately repeated cycles to the beginning of the current item |
1794 | and then to the hot-spot (if `allout-beginning-of-line-cycles' is set). | |
1795 | ||
1796 | ||
1797 | Topic Header Production: | |
1798 | ----------------------- | |
1799 | \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic. | |
1800 | \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic. | |
1801 | \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent. | |
1802 | ||
1803 | Topic Level and Prefix Adjustment: | |
1804 | --------------------------------- | |
1805 | \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper | |
1806 | \\[allout-shift-out] `allout-shift-out' ... less deep | |
1807 | \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for | |
1808 | current topic | |
1809 | \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and | |
20db1522 | 1810 | its offspring -- distinctive bullets are not changed, others |
c07583cd | 1811 | are alternated according to nesting depth. |
ea18b2b1 | 1812 | \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -- |
c07583cd KS |
1813 | the offspring are not affected. |
1814 | With repeat count, revoke numbering. | |
1815 | ||
1816 | Topic-oriented Killing and Yanking: | |
1817 | ---------------------------------- | |
1818 | \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring. | |
1819 | \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring. | |
20db1522 | 1820 | \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure. |
c07583cd KS |
1821 | \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it. |
1822 | \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to | |
1823 | depth of heading if yanking into bare topic | |
1824 | heading (ie, prefix sans text). | |
20db1522 | 1825 | \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'. |
c07583cd KS |
1826 | |
1827 | Topic-oriented Encryption: | |
1828 | ------------------------- | |
1829 | \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption' | |
1830 | Encrypt/Decrypt topic content | |
1831 | ||
1832 | Misc commands: | |
1833 | ------------- | |
1834 | M-x outlineify-sticky Activate outline mode for current buffer, | |
1835 | and establish a default file-var setting | |
1836 | for `allout-layout'. | |
1837 | \\[allout-mark-topic] `allout-mark-topic' | |
1838 | \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer' | |
1839 | Duplicate outline, sans concealed text, to | |
1840 | buffer with name derived from derived from that | |
60c7bbd2 | 1841 | of current buffer -- \"*BUFFERNAME exposed*\". |
c07583cd KS |
1842 | \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer' |
1843 | Like above 'copy-exposed', but convert topic | |
1844 | prefixes to section.subsection... numeric | |
1845 | format. | |
11c46e15 KM |
1846 | \\[customize-variable] allout-auto-activation |
1847 | Prepare Emacs session for allout outline mode | |
c07583cd | 1848 | auto-activation. |
1977b8f6 | 1849 | |
96b83743 | 1850 | Topic Encryption |
d82979ea | 1851 | |
96b83743 | 1852 | Outline mode supports gpg encryption of topics, with support for |
29fac3fe KM |
1853 | symmetric and key-pair modes, and auto-encryption of topics |
1854 | pending encryption on save. | |
d82979ea | 1855 | |
c07583cd | 1856 | Topics pending encryption are, by default, automatically |
29fac3fe KM |
1857 | encrypted during file saves, including checkpoint saves, to avoid |
1858 | exposing the plain text of encrypted topics in the file system. | |
1859 | If the content of the topic containing the cursor was encrypted | |
1860 | for a save, it is automatically decrypted for continued editing. | |
c07583cd | 1861 | |
2576c28f KM |
1862 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
1863 | symmetric decryption keys, preventing entry of the correct key on | |
1864 | subsequent decryption attempts until the cache times-out. That | |
20db1522 | 1865 | can take several minutes. (Decryption of other entries is not |
2576c28f KM |
1866 | affected.) Upgrade your EasyPG version, if you can, and you can |
1867 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
1868 | signal. | |
c07583cd KS |
1869 | |
1870 | See `allout-toggle-current-subtree-encryption' function docstring | |
1871 | and `allout-encrypt-unencrypted-on-saves' customization variable | |
1872 | for details. | |
d82979ea | 1873 | |
c07583cd | 1874 | HOT-SPOT Operation |
c567ac01 | 1875 | |
19b84ba3 RS |
1876 | Hot-spot operation provides a means for easy, single-keystroke outline |
1877 | navigation and exposure control. | |
c567ac01 | 1878 | |
19b84ba3 RS |
1879 | When the text cursor is positioned directly on the bullet character of |
1880 | a topic, regular characters (a to z) invoke the commands of the | |
fd5359c6 | 1881 | corresponding allout-mode keymap control chars. For example, \"f\" |
96b83743 | 1882 | would invoke the command typically bound to \"C-c<space>C-f\" |
fd5359c6 | 1883 | \(\\[allout-forward-current-level] `allout-forward-current-level'). |
19b84ba3 | 1884 | |
96b83743 EZ |
1885 | Thus, by positioning the cursor on a topic bullet, you can |
1886 | execute the outline navigation and manipulation commands with a | |
c07583cd | 1887 | single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get |
96b83743 | 1888 | this special translation, so you can use them to get out of the |
c07583cd KS |
1889 | hot-spot and back to normal editing operation. |
1890 | ||
d41b91e6 | 1891 | In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is |
c07583cd KS |
1892 | replaced with one that makes it easy to get to the hot-spot. If you |
1893 | repeat it immediately it cycles (if `allout-beginning-of-line-cycles' | |
1894 | is set) to the beginning of the item and then, if you hit it again | |
1895 | immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry' | |
1896 | \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located | |
1897 | at the beginning of the current entry. | |
1898 | ||
1899 | Extending Allout | |
c567ac01 | 1900 | |
fa463103 | 1901 | Allout exposure and authoring activities all have associated |
c07583cd KS |
1902 | hooks, by which independent code can cooperate with allout |
1903 | without changes to the allout core. Here are key ones: | |
1977b8f6 | 1904 | |
c07583cd | 1905 | `allout-mode-hook' |
20db1522 | 1906 | `allout-mode-deactivate-hook' (deprecated) |
2576c28f | 1907 | `allout-mode-off-hook' |
7b97c764 CY |
1908 | `allout-exposure-change-functions' |
1909 | `allout-structure-added-functions' | |
1910 | `allout-structure-deleted-functions' | |
1911 | `allout-structure-shifted-functions' | |
4ec28e14 | 1912 | `allout-after-copy-or-kill-hook' |
919d884a | 1913 | `allout-post-undo-hook' |
c07583cd KS |
1914 | |
1915 | Terminology | |
1977b8f6 | 1916 | |
60c7bbd2 | 1917 | Topic hierarchy constituents -- TOPICS and SUBTOPICS: |
c567ac01 | 1918 | |
c07583cd KS |
1919 | ITEM: A unitary outline element, including the HEADER and ENTRY text. |
1920 | TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH | |
1921 | and with no intervening items of lower DEPTH than the container. | |
1922 | CURRENT ITEM: | |
1923 | The visible ITEM most immediately containing the cursor. | |
1924 | DEPTH: The degree of nesting of an ITEM; it increases with containment. | |
1925 | The DEPTH is determined by the HEADER PREFIX. The DEPTH is also | |
1926 | called the: | |
1927 | LEVEL: The same as DEPTH. | |
c567ac01 RS |
1928 | |
1929 | ANCESTORS: | |
c07583cd KS |
1930 | Those ITEMs whose TOPICs contain an ITEM. |
1931 | PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that | |
1932 | of the ITEM. | |
c567ac01 | 1933 | OFFSPRING: |
c07583cd | 1934 | The ITEMs contained within an ITEM's TOPIC. |
19b84ba3 | 1935 | SUBTOPIC: |
c07583cd KS |
1936 | An OFFSPRING of its ANCESTOR TOPICs. |
1937 | CHILD: | |
1938 | An immediate SUBTOPIC of its PARENT. | |
c567ac01 | 1939 | SIBLINGS: |
c07583cd | 1940 | TOPICs having the same PARENT and DEPTH. |
353e2ef2 | 1941 | |
c567ac01 RS |
1942 | Topic text constituents: |
1943 | ||
c07583cd KS |
1944 | HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER |
1945 | text. | |
1946 | ENTRY: The text content of an ITEM, before any OFFSPRING, but including | |
1947 | the HEADER text and distinct from the ITEM PREFIX. | |
1948 | BODY: Same as ENTRY. | |
1949 | PREFIX: The leading text of an ITEM which distinguishes it from normal | |
1950 | ENTRY text. Allout recognizes the outline structure according | |
1951 | to the strict PREFIX format. It consists of a PREFIX-LEAD string, | |
1952 | PREFIX-PADDING, and a BULLET. The BULLET might be followed by a | |
d82979ea | 1953 | number, indicating the ordinal number of the topic among its |
c07583cd KS |
1954 | siblings, or an asterisk indicating encryption, plus an optional |
1955 | space. After that is the ITEM HEADER text, which is not part of | |
1956 | the PREFIX. | |
c567ac01 | 1957 | |
c07583cd KS |
1958 | The relative length of the PREFIX determines the nesting DEPTH |
1959 | of the ITEM. | |
c567ac01 | 1960 | PREFIX-LEAD: |
c07583cd KS |
1961 | The string at the beginning of a HEADER PREFIX, by default a `.'. |
1962 | It can be customized by changing the setting of | |
1963 | `allout-header-prefix' and then reinitializing `allout-mode'. | |
1964 | ||
1965 | When the PREFIX-LEAD is set to the comment-string of a | |
1966 | programming language, outline structuring can be embedded in | |
1967 | program code without interfering with processing of the text | |
20db1522 | 1968 | (by Emacs or the language processor) as program code. This |
c07583cd KS |
1969 | setting happens automatically when allout mode is used in |
1970 | programming-mode buffers. See `allout-use-mode-specific-leader' | |
1971 | docstring for more detail. | |
c567ac01 | 1972 | PREFIX-PADDING: |
c07583cd KS |
1973 | Spaces or asterisks which separate the PREFIX-LEAD and the |
1974 | bullet, determining the ITEM's DEPTH. | |
1975 | BULLET: A character at the end of the ITEM PREFIX, it must be one of | |
1976 | the characters listed on `allout-plain-bullets-string' or | |
38b2ca53 NR |
1977 | `allout-distinctive-bullets-string'. When creating a TOPIC, |
1978 | plain BULLETs are by default used, according to the DEPTH of the | |
1979 | TOPIC. Choice among the distinctive BULLETs is offered when you | |
20db1522 | 1980 | provide a universal argument (\\[universal-argument]) to the |
e4769531 | 1981 | TOPIC creation command, or when explicitly rebulleting a TOPIC. The |
38b2ca53 NR |
1982 | significance of the various distinctive bullets is purely by |
1983 | convention. See the documentation for the above bullet strings for | |
1984 | more details. | |
c567ac01 | 1985 | EXPOSURE: |
c07583cd KS |
1986 | The state of a TOPIC which determines the on-screen visibility |
1987 | of its OFFSPRING and contained ENTRY text. | |
c567ac01 | 1988 | CONCEALED: |
c07583cd KS |
1989 | TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed |
1990 | text is represented by \"...\" ellipses. | |
c567ac01 | 1991 | |
c07583cd KS |
1992 | CONCEALED TOPICs are effectively collapsed within an ANCESTOR. |
1993 | CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED. | |
1994 | OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be." | |
c567ac01 | 1995 | ;;;_ . Code |
d3e51865 KM |
1996 | :lighter " Allout" |
1997 | :keymap 'allout-mode-map | |
1977b8f6 | 1998 | |
13aa217b | 1999 | (let ((use-layout (if (listp allout-layout) |
2576c28f KM |
2000 | allout-layout |
2001 | allout-default-layout))) | |
1977b8f6 | 2002 | |
d3e51865 | 2003 | (if (not (allout-mode-p)) |
2576c28f KM |
2004 | (progn |
2005 | ;; Deactivation: | |
2006 | ||
2007 | ; Activation not explicitly | |
2008 | ; requested, and either in | |
2009 | ; active state or *de*activation | |
2010 | ; specifically requested: | |
2011 | (allout-do-resumptions) | |
2012 | ||
2013 | (remove-from-invisibility-spec '(allout . t)) | |
2014 | (remove-hook 'pre-command-hook 'allout-pre-command-business t) | |
2015 | (remove-hook 'post-command-hook 'allout-post-command-business t) | |
2016 | (remove-hook 'before-change-functions 'allout-before-change-handler t) | |
2017 | (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) | |
13aa217b KM |
2018 | (remove-hook 'write-contents-functions |
2019 | 'allout-write-contents-hook-handler t) | |
2576c28f KM |
2020 | |
2021 | (remove-overlays (point-min) (point-max) | |
d3e51865 | 2022 | 'category 'allout-exposure-category)) |
2576c28f | 2023 | |
d3e51865 | 2024 | ;; Activating: |
fd5359c6 | 2025 | (if allout-old-style-prefixes |
01fc9422 | 2026 | ;; Inhibit all the fancy formatting: |
48bd8440 | 2027 | (allout-add-resumptions '(allout-primary-bullet "*"))) |
19b84ba3 | 2028 | |
01fc9422 | 2029 | (allout-overlay-preparations) ; Doesn't hurt to redo this. |
96b83743 | 2030 | |
d8350998 | 2031 | (allout-infer-header-lead-and-primary-bullet) |
fd5359c6 | 2032 | (allout-infer-body-reindent) |
19b84ba3 | 2033 | |
fd5359c6 | 2034 | (set-allout-regexp) |
2576c28f KM |
2035 | (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps |
2036 | allout-line-boundary-regexp | |
2037 | extend) | |
2038 | '(allout-encryption-ciphertext-rejection-regexps | |
2039 | allout-bob-regexp | |
2040 | extend)) | |
19b84ba3 | 2041 | |
d3e51865 | 2042 | (allout-compose-and-institute-keymap) |
01fc9422 | 2043 | (produce-allout-mode-menubar-entries) |
01fc9422 | 2044 | |
96b83743 | 2045 | (add-to-invisibility-spec '(allout . t)) |
38b2ca53 | 2046 | |
01fc9422 EZ |
2047 | (allout-add-resumptions '(line-move-ignore-invisible t)) |
2048 | (add-hook 'pre-command-hook 'allout-pre-command-business nil t) | |
2049 | (add-hook 'post-command-hook 'allout-post-command-business nil t) | |
2576c28f | 2050 | (add-hook 'before-change-functions 'allout-before-change-handler nil t) |
01fc9422 | 2051 | (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) |
13aa217b | 2052 | (add-hook 'write-contents-functions 'allout-write-contents-hook-handler |
01fc9422 | 2053 | nil t) |
01fc9422 EZ |
2054 | |
2055 | ;; Stash auto-fill settings and adjust so custom allout auto-fill | |
2056 | ;; func will be used if auto-fill is active or activated. (The | |
2057 | ;; custom func respects topic headline, maintains hanging-indents, | |
2058 | ;; etc.) | |
01fc9422 EZ |
2059 | (allout-add-resumptions (list 'allout-former-auto-filler |
2060 | auto-fill-function) | |
2061 | ;; Register allout-auto-fill to be used if | |
2062 | ;; filling is active: | |
2063 | (list 'allout-outside-normal-auto-fill-function | |
2064 | normal-auto-fill-function) | |
2065 | '(normal-auto-fill-function allout-auto-fill) | |
2066 | ;; Paragraphs are broken by topic headlines. | |
2067 | (list 'paragraph-start | |
2068 | (concat paragraph-start "\\|^\\(" | |
2069 | allout-regexp "\\)")) | |
2070 | (list 'paragraph-separate | |
2071 | (concat paragraph-separate "\\|^\\(" | |
2072 | allout-regexp "\\)"))) | |
2576c28f KM |
2073 | (if (and auto-fill-function (not allout-inhibit-auto-fill)) |
2074 | ;; allout-auto-fill will use the stashed values and so forth. | |
2075 | (allout-add-resumptions '(auto-fill-function allout-auto-fill))) | |
2076 | ||
fd5359c6 | 2077 | (allout-setup-menubar) |
2576c28f KM |
2078 | |
2079 | ;; Do auto layout if warranted: | |
2080 | (when (and allout-layout | |
2081 | allout-auto-activation | |
2082 | use-layout | |
11c46e15 KM |
2083 | (and (not (string= allout-auto-activation "activate")) |
2084 | (if (string= allout-auto-activation "ask") | |
2576c28f KM |
2085 | (if (y-or-n-p (format "Expose %s with layout '%s'? " |
2086 | (buffer-name) | |
2087 | use-layout)) | |
2088 | t | |
2089 | (message "Skipped %s layout." (buffer-name)) | |
2090 | nil) | |
2091 | t))) | |
2092 | (save-excursion | |
2093 | (message "Adjusting '%s' exposure..." (buffer-name)) | |
2094 | (goto-char 0) | |
2095 | (allout-this-or-next-heading) | |
2096 | (condition-case err | |
2097 | (progn | |
2098 | (apply 'allout-expose-topic (list use-layout)) | |
2099 | (message "Adjusting '%s' exposure... done." | |
2100 | (buffer-name))) | |
2101 | ;; Problem applying exposure -- notify user, but don't | |
2102 | ;; interrupt, eg, file visit: | |
2103 | (error (message "%s" (car (cdr err))) | |
2104 | (sit-for 1)))) | |
2105 | ) ; when allout-layout | |
2106 | ) ; if (allout-mode-p) | |
2107 | ) ; let (()) | |
2108 | ) ; define-minor-mode | |
2109 | ;;;_ > allout-minor-mode alias | |
2110 | (defalias 'allout-minor-mode 'allout-mode) | |
41ff6d0a JB |
2111 | ;;;_ > allout-unload-function |
2112 | (defun allout-unload-function () | |
2113 | "Unload the allout outline library." | |
2114 | (save-current-buffer | |
2115 | (dolist (buffer (buffer-list)) | |
2116 | (set-buffer buffer) | |
74f53697 | 2117 | (when (allout-mode-p) (allout-mode -1)))) |
41ff6d0a JB |
2118 | ;; continue standard unloading |
2119 | nil) | |
2120 | ||
773e7e48 EZ |
2121 | ;;;_ - Position Assessment |
2122 | ;;;_ > allout-hidden-p (&optional pos) | |
2123 | (defsubst allout-hidden-p (&optional pos) | |
1c9b9df0 | 2124 | "Non-nil if the character after point was made invisible by allout." |
da506f05 | 2125 | (eq (get-char-property (or pos (point)) 'invisible) 'allout)) |
773e7e48 | 2126 | |
96b83743 EZ |
2127 | ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end |
2128 | ;;; &optional prelen) | |
2129 | (defun allout-overlay-insert-in-front-handler (ol after beg end | |
2130 | &optional prelen) | |
2a1408fd | 2131 | "Shift the overlay so stuff inserted in front of it is excluded." |
96b83743 | 2132 | (if after |
1c9b9df0 KM |
2133 | ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay |
2134 | ;; front-advance on the overlay worked as expected? | |
96b83743 EZ |
2135 | (move-overlay ol (1+ beg) (overlay-end ol)))) |
2136 | ;;;_ > allout-overlay-interior-modification-handler (ol after beg end | |
2137 | ;;; &optional prelen) | |
2138 | (defun allout-overlay-interior-modification-handler (ol after beg end | |
2139 | &optional prelen) | |
2140 | "Get confirmation before making arbitrary changes to invisible text. | |
2141 | ||
2142 | We expose the invisible text and ask for confirmation. Refusal or | |
75bcb912 | 2143 | `keyboard-quit' abandons the changes, with keyboard-quit additionally |
96b83743 EZ |
2144 | reclosing the opened text. |
2145 | ||
60c7bbd2 | 2146 | No confirmation is necessary when `inhibit-read-only' is set -- eg, allout |
96b83743 EZ |
2147 | internal functions use this feature cohesively bunch changes." |
2148 | ||
2149 | (when (and (not inhibit-read-only) (not after)) | |
2150 | (let ((start (point)) | |
2151 | (ol-start (overlay-start ol)) | |
2152 | (ol-end (overlay-end ol)) | |
96b83743 EZ |
2153 | first) |
2154 | (goto-char beg) | |
2155 | (while (< (point) end) | |
2156 | (when (allout-hidden-p) | |
2157 | (allout-show-to-offshoot) | |
2158 | (if (allout-hidden-p) | |
2159 | (save-excursion (forward-char 1) | |
2160 | (allout-show-to-offshoot))) | |
2161 | (when (not first) | |
96b83743 EZ |
2162 | (setq first (point)))) |
2163 | (goto-char (if (featurep 'xemacs) | |
2164 | (next-property-change (1+ (point)) nil end) | |
2165 | (next-char-property-change (1+ (point)) end)))) | |
2166 | (when first | |
2167 | (goto-char first) | |
2168 | (condition-case nil | |
2169 | (if (not | |
2170 | (yes-or-no-p | |
2171 | (substitute-command-keys | |
4034b0e2 | 2172 | (concat "Modify concealed text? (\"no\" just aborts," |
96b83743 EZ |
2173 | " \\[keyboard-quit] also reconceals) ")))) |
2174 | (progn (goto-char start) | |
5a0c3f56 | 2175 | (error "Concealed-text change refused"))) |
96b83743 EZ |
2176 | (quit (allout-flag-region ol-start ol-end nil) |
2177 | (allout-flag-region ol-start ol-end t) | |
5a0c3f56 | 2178 | (error "Concealed-text change abandoned, text reconcealed")))) |
96b83743 EZ |
2179 | (goto-char start)))) |
2180 | ;;;_ > allout-before-change-handler (beg end) | |
2181 | (defun allout-before-change-handler (beg end) | |
2182 | "Protect against changes to invisible text. | |
2183 | ||
60c7bbd2 | 2184 | See `allout-overlay-interior-modification-handler' for details." |
d8350998 | 2185 | |
13aa217b KM |
2186 | (when (and (allout-mode-p) undo-in-progress) |
2187 | (setq allout-just-did-undo t) | |
2188 | (if (allout-hidden-p) | |
2189 | (allout-show-children))) | |
d8350998 | 2190 | |
01fc9422 EZ |
2191 | ;; allout-overlay-interior-modification-handler on an overlay handles |
2192 | ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. | |
2193 | (when (and (featurep 'xemacs) (allout-mode-p)) | |
2194 | ;; process all of the pending overlays: | |
d8350998 | 2195 | (save-excursion |
f520c6f2 | 2196 | (goto-char beg) |
d8350998 | 2197 | (let ((overlay (allout-get-invisibility-overlay))) |
1c9b9df0 KM |
2198 | (if overlay |
2199 | (allout-overlay-interior-modification-handler | |
2200 | overlay nil beg end nil)))))) | |
96b83743 EZ |
2201 | ;;;_ > allout-isearch-end-handler (&optional overlay) |
2202 | (defun allout-isearch-end-handler (&optional overlay) | |
2203 | "Reconcile allout outline exposure on arriving in hidden text after isearch. | |
2204 | ||
2205 | Optional OVERLAY parameter is for when this function is used by | |
2206 | `isearch-open-invisible' overlay property. It is otherwise unused, so this | |
2207 | function can also be used as an `isearch-mode-end-hook'." | |
2208 | ||
2209 | (if (and (allout-mode-p) (allout-hidden-p)) | |
2210 | (allout-show-to-offshoot))) | |
2211 | ||
60c7bbd2 | 2212 | ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs |
a5a1e2ef SM |
2213 | ;; All the basic outline functions that directly do string matches to |
2214 | ;; evaluate heading prefix location set the variables | |
2215 | ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' | |
2216 | ;; when successful. Functions starting with `allout-recent-' all | |
2217 | ;; use this state, providing the means to avoid redundant searches | |
2218 | ;; for just-established data. This optimization can provide | |
2219 | ;; significant speed improvement, but it must be employed carefully. | |
fd5359c6 MR |
2220 | ;;;_ = allout-recent-prefix-beginning |
2221 | (defvar allout-recent-prefix-beginning 0 | |
c567ac01 | 2222 | "Buffer point of the start of the last topic prefix encountered.") |
fd5359c6 MR |
2223 | (make-variable-buffer-local 'allout-recent-prefix-beginning) |
2224 | ;;;_ = allout-recent-prefix-end | |
2225 | (defvar allout-recent-prefix-end 0 | |
c567ac01 | 2226 | "Buffer point of the end of the last topic prefix encountered.") |
fd5359c6 | 2227 | (make-variable-buffer-local 'allout-recent-prefix-end) |
d8350998 CY |
2228 | ;;;_ = allout-recent-depth |
2229 | (defvar allout-recent-depth 0 | |
2230 | "Depth of the last topic prefix encountered.") | |
2231 | (make-variable-buffer-local 'allout-recent-depth) | |
fd5359c6 MR |
2232 | ;;;_ = allout-recent-end-of-subtree |
2233 | (defvar allout-recent-end-of-subtree 0 | |
2265e017 | 2234 | "Buffer point last returned by `allout-end-of-current-subtree'.") |
fd5359c6 | 2235 | (make-variable-buffer-local 'allout-recent-end-of-subtree) |
d8350998 CY |
2236 | ;;;_ > allout-prefix-data () |
2237 | (defsubst allout-prefix-data () | |
2238 | "Register allout-prefix state data. | |
fd5359c6 | 2239 | |
75bcb912 JB |
2240 | For reference by `allout-recent' funcs. Return |
2241 | the new value of `allout-recent-prefix-beginning'." | |
42c3e51c | 2242 | (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3)) |
d8350998 | 2243 | allout-recent-prefix-beginning (or (match-beginning 1) |
42c3e51c KM |
2244 | (match-beginning 2) |
2245 | (match-beginning 3)) | |
d8350998 CY |
2246 | allout-recent-depth (max 1 (- allout-recent-prefix-end |
2247 | allout-recent-prefix-beginning | |
2248 | allout-header-subtraction))) | |
2249 | allout-recent-prefix-beginning) | |
2250 | ;;;_ > nullify-allout-prefix-data () | |
2251 | (defsubst nullify-allout-prefix-data () | |
2252 | "Mark allout prefix data as being uninformative." | |
2253 | (setq allout-recent-prefix-end (point) | |
2254 | allout-recent-prefix-beginning (point) | |
2255 | allout-recent-depth 0) | |
2256 | allout-recent-prefix-beginning) | |
fd5359c6 | 2257 | ;;;_ > allout-recent-depth () |
d8350998 | 2258 | (defsubst allout-recent-depth () |
19b84ba3 | 2259 | "Return depth of last heading encountered by an outline maneuvering function. |
c567ac01 RS |
2260 | |
2261 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2262 | headings set the variables `allout-recent-prefix-beginning' and |
2263 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 RS |
2264 | to return the current depth." |
2265 | ||
d8350998 | 2266 | allout-recent-depth) |
fd5359c6 | 2267 | ;;;_ > allout-recent-prefix () |
d8350998 | 2268 | (defsubst allout-recent-prefix () |
2265e017 | 2269 | "Like `allout-recent-depth', but returns text of last encountered prefix. |
c567ac01 RS |
2270 | |
2271 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2272 | headings set the variables `allout-recent-prefix-beginning' and |
2273 | `allout-recent-prefix-end' if successful. This function uses those settings | |
d8350998 CY |
2274 | to return the current prefix." |
2275 | (buffer-substring-no-properties allout-recent-prefix-beginning | |
2276 | allout-recent-prefix-end)) | |
fd5359c6 MR |
2277 | ;;;_ > allout-recent-bullet () |
2278 | (defmacro allout-recent-bullet () | |
20db1522 | 2279 | "Like `allout-recent-prefix', but returns bullet of last encountered prefix. |
c567ac01 RS |
2280 | |
2281 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2282 | headings set the variables `allout-recent-prefix-beginning' and |
2283 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 2284 | to return the current depth of the most recently matched topic." |
d8350998 CY |
2285 | '(buffer-substring-no-properties (1- allout-recent-prefix-end) |
2286 | allout-recent-prefix-end)) | |
c567ac01 | 2287 | |
19b84ba3 | 2288 | ;;;_ #4 Navigation |
c567ac01 | 2289 | |
46771bb3 | 2290 | ;;;_ - Position Assessment |
c567ac01 | 2291 | ;;;_ : Location Predicates |
ede4ac6a KS |
2292 | ;;;_ > allout-do-doublecheck () |
2293 | (defsubst allout-do-doublecheck () | |
2294 | "True if current item conditions qualify for checking on topic aberrance." | |
2295 | (and | |
60c7bbd2 | 2296 | ;; presume integrity of outline and yanked content during yank -- necessary |
ede4ac6a | 2297 | ;; to allow for level disparity of yank location and yanked text: |
498a6493 | 2298 | (not allout-inhibit-aberrance-doublecheck) |
ede4ac6a KS |
2299 | ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck: |
2300 | (<= allout-recent-depth allout-doublecheck-at-and-shallower))) | |
2301 | ;;;_ > allout-aberrant-container-p () | |
d8350998 CY |
2302 | (defun allout-aberrant-container-p () |
2303 | "True if topic, or next sibling with children, contains them discontinuously. | |
2304 | ||
2305 | Discontinuous means an immediate offspring that is nested more | |
2306 | than one level deeper than the topic. | |
2307 | ||
2308 | If topic has no offspring, then the next sibling with offspring will | |
2309 | determine whether or not this one is determined to be aberrant. | |
2310 | ||
2311 | If true, then the allout-recent-* settings are calibrated on the | |
e1dbe924 | 2312 | offspring that qualifies it as aberrant, ie with depth that |
d8350998 CY |
2313 | exceeds the topic by more than one." |
2314 | ||
2315 | ;; This is most clearly understood when considering standard-prefix-leader | |
2316 | ;; low-level topics, which can all too easily match text not intended as | |
2317 | ;; headers. For example, any line with a leading '.' or '*' and lacking a | |
2318 | ;; following bullet qualifies without this protection. (A sequence of | |
2319 | ;; them can occur naturally, eg a typical textual bullet list.) We | |
2320 | ;; disqualify such low-level sequences when they are followed by a | |
2321 | ;; discontinuously contained child, inferring that the sequences are not | |
2322 | ;; actually connected with their prospective context. | |
2323 | ||
2324 | (let ((depth (allout-depth)) | |
2325 | (start-point (point)) | |
2326 | done aberrant) | |
2a1408fd DN |
2327 | (save-match-data |
2328 | (save-excursion | |
2329 | (while (and (not done) | |
2330 | (re-search-forward allout-line-boundary-regexp nil 0)) | |
2331 | (allout-prefix-data) | |
2332 | (goto-char allout-recent-prefix-beginning) | |
2333 | (cond | |
8dd59f01 | 2334 | ;; sibling -- continue: |
2a1408fd | 2335 | ((eq allout-recent-depth depth)) |
8dd59f01 | 2336 | ;; first offspring is excessive -- aberrant: |
2a1408fd DN |
2337 | ((> allout-recent-depth (1+ depth)) |
2338 | (setq done t aberrant t)) | |
8dd59f01 | 2339 | ;; next non-sibling is lower-depth -- not aberrant: |
2a1408fd | 2340 | (t (setq done t)))))) |
d8350998 CY |
2341 | (if aberrant |
2342 | aberrant | |
2343 | (goto-char start-point) | |
2344 | ;; recalibrate allout-recent-* | |
2345 | (allout-depth) | |
2346 | nil))) | |
ede4ac6a KS |
2347 | ;;;_ > allout-on-current-heading-p () |
2348 | (defun allout-on-current-heading-p () | |
2349 | "Return non-nil if point is on current visible topics' header line. | |
2350 | ||
2351 | Actually, returns prefix beginning point." | |
2352 | (save-excursion | |
2353 | (allout-beginning-of-current-line) | |
2a1408fd DN |
2354 | (save-match-data |
2355 | (and (looking-at allout-regexp) | |
2356 | (allout-prefix-data) | |
2357 | (or (not (allout-do-doublecheck)) | |
2358 | (not (allout-aberrant-container-p))))))) | |
ede4ac6a KS |
2359 | ;;;_ > allout-on-heading-p () |
2360 | (defalias 'allout-on-heading-p 'allout-on-current-heading-p) | |
2361 | ;;;_ > allout-e-o-prefix-p () | |
2362 | (defun allout-e-o-prefix-p () | |
2363 | "True if point is located where current topic prefix ends, heading begins." | |
2a1408fd DN |
2364 | (and (save-match-data |
2365 | (save-excursion (let ((inhibit-field-text-motion t)) | |
2366 | (beginning-of-line)) | |
2367 | (looking-at allout-regexp)) | |
2368 | (= (point) (save-excursion (allout-end-of-prefix)(point)))))) | |
c567ac01 | 2369 | ;;;_ : Location attributes |
fd5359c6 | 2370 | ;;;_ > allout-depth () |
96b83743 EZ |
2371 | (defun allout-depth () |
2372 | "Return depth of topic most immediately containing point. | |
2373 | ||
42c3e51c KM |
2374 | Does not do doublecheck for aberrant topic header. |
2375 | ||
96b83743 EZ |
2376 | Return zero if point is not within any topic. |
2377 | ||
2378 | Like `allout-current-depth', but respects hidden as well as visible topics." | |
9179616f | 2379 | (save-excursion |
96b83743 EZ |
2380 | (let ((start-point (point))) |
2381 | (if (and (allout-goto-prefix) | |
2382 | (not (< start-point (point)))) | |
d8350998 | 2383 | allout-recent-depth |
96b83743 | 2384 | (progn |
d8350998 CY |
2385 | ;; Oops, no prefix, nullify it: |
2386 | (nullify-allout-prefix-data) | |
96b83743 EZ |
2387 | ;; ... and return 0: |
2388 | 0))))) | |
fd5359c6 | 2389 | ;;;_ > allout-current-depth () |
96b83743 EZ |
2390 | (defun allout-current-depth () |
2391 | "Return depth of visible topic most immediately containing point. | |
2392 | ||
2393 | Return zero if point is not within any topic." | |
2394 | (save-excursion | |
2395 | (if (allout-back-to-current-heading) | |
2396 | (max 1 | |
2397 | (- allout-recent-prefix-end | |
2398 | allout-recent-prefix-beginning | |
2399 | allout-header-subtraction)) | |
2400 | 0))) | |
fd5359c6 MR |
2401 | ;;;_ > allout-get-current-prefix () |
2402 | (defun allout-get-current-prefix () | |
c567ac01 | 2403 | "Topic prefix of the current topic." |
1977b8f6 | 2404 | (save-excursion |
fd5359c6 MR |
2405 | (if (allout-goto-prefix) |
2406 | (allout-recent-prefix)))) | |
2407 | ;;;_ > allout-get-bullet () | |
2408 | (defun allout-get-bullet () | |
c567ac01 | 2409 | "Return bullet of containing topic (visible or not)." |
1977b8f6 | 2410 | (save-excursion |
fd5359c6 MR |
2411 | (and (allout-goto-prefix) |
2412 | (allout-recent-bullet)))) | |
2413 | ;;;_ > allout-current-bullet () | |
2414 | (defun allout-current-bullet () | |
c567ac01 | 2415 | "Return bullet of current (visible) topic heading, or none if none found." |
96b83743 | 2416 | (condition-case nil |
1977b8f6 | 2417 | (save-excursion |
fd5359c6 | 2418 | (allout-back-to-current-heading) |
d8350998 CY |
2419 | (buffer-substring-no-properties (- allout-recent-prefix-end 1) |
2420 | allout-recent-prefix-end)) | |
1977b8f6 | 2421 | ;; Quick and dirty provision, ostensibly for missing bullet: |
d8350998 | 2422 | (args-out-of-range nil)) |
1977b8f6 | 2423 | ) |
fd5359c6 MR |
2424 | ;;;_ > allout-get-prefix-bullet (prefix) |
2425 | (defun allout-get-prefix-bullet (prefix) | |
c567ac01 | 2426 | "Return the bullet of the header prefix string PREFIX." |
1977b8f6 RS |
2427 | ;; Doesn't make sense if we're old-style prefixes, but this just |
2428 | ;; oughtn't be called then, so forget about it... | |
fd5359c6 | 2429 | (if (string-match allout-regexp prefix) |
d8350998 | 2430 | (substring prefix (1- (match-end 2)) (match-end 2)))) |
fd5359c6 MR |
2431 | ;;;_ > allout-sibling-index (&optional depth) |
2432 | (defun allout-sibling-index (&optional depth) | |
9179616f DL |
2433 | "Item number of this prospective topic among its siblings. |
2434 | ||
e126900f | 2435 | If optional arg DEPTH is greater than current depth, then we're |
9179616f DL |
2436 | opening a new level, and return 0. |
2437 | ||
2438 | If less than this depth, ascend to that depth and count..." | |
2439 | ||
2440 | (save-excursion | |
2441 | (cond ((and depth (<= depth 0) 0)) | |
65e7eb3d | 2442 | ((or (null depth) (= depth (allout-depth))) |
9179616f | 2443 | (let ((index 1)) |
d8350998 | 2444 | (while (allout-previous-sibling allout-recent-depth nil) |
9179616f DL |
2445 | (setq index (1+ index))) |
2446 | index)) | |
d8350998 | 2447 | ((< depth allout-recent-depth) |
fd5359c6 MR |
2448 | (allout-ascend-to-depth depth) |
2449 | (allout-sibling-index)) | |
9179616f | 2450 | (0)))) |
fd5359c6 MR |
2451 | ;;;_ > allout-topic-flat-index () |
2452 | (defun allout-topic-flat-index () | |
9179616f DL |
2453 | "Return a list indicating point's numeric section.subsect.subsubsect... |
2454 | Outermost is first." | |
fd5359c6 MR |
2455 | (let* ((depth (allout-depth)) |
2456 | (next-index (allout-sibling-index depth)) | |
9179616f DL |
2457 | (rev-sibls nil)) |
2458 | (while (> next-index 0) | |
2459 | (setq rev-sibls (cons next-index rev-sibls)) | |
2460 | (setq depth (1- depth)) | |
fd5359c6 | 2461 | (setq next-index (allout-sibling-index depth))) |
9179616f DL |
2462 | rev-sibls) |
2463 | ) | |
1977b8f6 | 2464 | |
96b83743 EZ |
2465 | ;;;_ - Navigation routines |
2466 | ;;;_ > allout-beginning-of-current-line () | |
2467 | (defun allout-beginning-of-current-line () | |
2468 | "Like beginning of line, but to visible text." | |
2469 | ||
5204800f NR |
2470 | ;; This combination of move-beginning-of-line and beginning-of-line is |
2471 | ;; deliberate, but the (beginning-of-line) may now be superfluous. | |
0458fa80 EZ |
2472 | (let ((inhibit-field-text-motion t)) |
2473 | (move-beginning-of-line 1) | |
96b83743 | 2474 | (beginning-of-line) |
0458fa80 EZ |
2475 | (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p))) |
2476 | (beginning-of-line) | |
2477 | (if (or (allout-hidden-p) (not (bolp))) | |
2478 | (forward-char -1))))) | |
96b83743 EZ |
2479 | ;;;_ > allout-end-of-current-line () |
2480 | (defun allout-end-of-current-line () | |
2481 | "Move to the end of line, past concealed text if any." | |
1c9b9df0 | 2482 | ;; This is for symmetry with `allout-beginning-of-current-line' -- |
96b83743 EZ |
2483 | ;; `move-end-of-line' doesn't suffer the same problem as |
2484 | ;; `move-beginning-of-line'. | |
0458fa80 | 2485 | (let ((inhibit-field-text-motion t)) |
96b83743 | 2486 | (end-of-line) |
0458fa80 EZ |
2487 | (while (allout-hidden-p) |
2488 | (end-of-line) | |
2489 | (if (allout-hidden-p) (forward-char 1))))) | |
48bd8440 EZ |
2490 | ;;;_ > allout-beginning-of-line () |
2491 | (defun allout-beginning-of-line () | |
2492 | "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set." | |
2493 | ||
2494 | (interactive) | |
2495 | ||
2496 | (if (or (not allout-beginning-of-line-cycles) | |
2497 | (not (equal last-command this-command))) | |
2a1408fd DN |
2498 | (progn |
2499 | (if (and (not (bolp)) | |
2500 | (allout-hidden-p (1- (point)))) | |
1c9b9df0 | 2501 | (goto-char (allout-previous-single-char-property-change |
2a1408fd DN |
2502 | (1- (point)) 'invisible))) |
2503 | (move-beginning-of-line 1)) | |
d8350998 CY |
2504 | (allout-depth) |
2505 | (let ((beginning-of-body | |
2506 | (save-excursion | |
ede4ac6a | 2507 | (while (and (allout-do-doublecheck) |
d8350998 CY |
2508 | (allout-aberrant-container-p) |
2509 | (allout-previous-visible-heading 1))) | |
2510 | (allout-beginning-of-current-entry) | |
2511 | (point)))) | |
48bd8440 | 2512 | (cond ((= (current-column) 0) |
d8350998 | 2513 | (goto-char beginning-of-body)) |
48bd8440 EZ |
2514 | ((< (point) beginning-of-body) |
2515 | (allout-beginning-of-current-line)) | |
2516 | ((= (point) beginning-of-body) | |
2517 | (goto-char (allout-current-bullet-pos))) | |
2518 | (t (allout-beginning-of-current-line) | |
2519 | (if (< (point) beginning-of-body) | |
2520 | ;; we were on the headline after its start: | |
d8350998 | 2521 | (goto-char beginning-of-body))))))) |
48bd8440 EZ |
2522 | ;;;_ > allout-end-of-line () |
2523 | (defun allout-end-of-line () | |
2524 | "End-of-line with `allout-end-of-line-cycles' behavior, if set." | |
2525 | ||
2526 | (interactive) | |
2527 | ||
2528 | (if (or (not allout-end-of-line-cycles) | |
2529 | (not (equal last-command this-command))) | |
2530 | (allout-end-of-current-line) | |
2531 | (let ((end-of-entry (save-excursion | |
2532 | (allout-end-of-entry) | |
2533 | (point)))) | |
2534 | (cond ((not (eolp)) | |
2535 | (allout-end-of-current-line)) | |
2536 | ((or (allout-hidden-p) (save-excursion | |
2537 | (forward-char -1) | |
2538 | (allout-hidden-p))) | |
2539 | (allout-back-to-current-heading) | |
2540 | (allout-show-current-entry) | |
d8350998 | 2541 | (allout-show-children) |
48bd8440 EZ |
2542 | (allout-end-of-entry)) |
2543 | ((>= (point) end-of-entry) | |
2544 | (allout-back-to-current-heading) | |
2545 | (allout-end-of-current-line)) | |
2a1408fd | 2546 | (t |
1c9b9df0 | 2547 | (if (not (allout-mark-active-p)) |
2a1408fd DN |
2548 | (push-mark)) |
2549 | (allout-end-of-entry)))))) | |
1c9b9df0 KM |
2550 | ;;;_ > allout-mark-active-p () |
2551 | (defun allout-mark-active-p () | |
2552 | "True if the mark is currently or always active." | |
2553 | ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler | |
0d26e0b6 | 2554 | ;; provisions, at least in GNU Emacs to prevent warnings about lack of, |
1c9b9df0 KM |
2555 | ;; eg, region-active-p. |
2556 | (cond ((boundp 'mark-active) | |
2557 | mark-active) | |
2558 | ((fboundp 'region-active-p) | |
2559 | (region-active-p)) | |
2560 | (t))) | |
fd5359c6 MR |
2561 | ;;;_ > allout-next-heading () |
2562 | (defsubst allout-next-heading () | |
c07583cd | 2563 | "Move to the heading for the topic (possibly invisible) after this one. |
c567ac01 | 2564 | |
d8350998 | 2565 | Returns the location of the heading, or nil if none found. |
c567ac01 | 2566 | |
75bcb912 | 2567 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
2a1408fd DN |
2568 | (save-match-data |
2569 | ||
2570 | (if (looking-at allout-regexp) | |
2571 | (forward-char 1)) | |
2572 | ||
2573 | (when (re-search-forward allout-line-boundary-regexp nil 0) | |
2574 | (allout-prefix-data) | |
42c3e51c KM |
2575 | (goto-char allout-recent-prefix-beginning) |
2576 | (while (not (bolp)) | |
2577 | (forward-char -1)) | |
2a1408fd DN |
2578 | (and (allout-do-doublecheck) |
2579 | ;; this will set allout-recent-* on the first non-aberrant topic, | |
2580 | ;; whether it's the current one or one that disqualifies it: | |
2581 | (allout-aberrant-container-p)) | |
42c3e51c | 2582 | ;; this may or may not be the same as above depending on doublecheck: |
2a1408fd | 2583 | (goto-char allout-recent-prefix-beginning)))) |
96b83743 | 2584 | ;;;_ > allout-this-or-next-heading |
fd5359c6 | 2585 | (defun allout-this-or-next-heading () |
8d118843 | 2586 | "Position cursor on current or next heading." |
fd5359c6 MR |
2587 | ;; A throwaway non-macro that is defined after allout-next-heading |
2588 | ;; and usable by allout-mode. | |
d8350998 | 2589 | (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading))) |
fd5359c6 | 2590 | ;;;_ > allout-previous-heading () |
8a559d4e | 2591 | (defun allout-previous-heading () |
c07583cd | 2592 | "Move to the prior (possibly invisible) heading line. |
c567ac01 | 2593 | |
d8350998 CY |
2594 | Return the location of the beginning of the heading, or nil if not found. |
2595 | ||
75bcb912 | 2596 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
d8350998 CY |
2597 | |
2598 | (if (bobp) | |
2599 | nil | |
d8350998 | 2600 | (let ((start-point (point))) |
ede4ac6a | 2601 | ;; allout-goto-prefix-doublechecked calls us, so we can't use it here. |
d8350998 | 2602 | (allout-goto-prefix) |
2a1408fd DN |
2603 | (save-match-data |
2604 | (when (or (re-search-backward allout-line-boundary-regexp nil 0) | |
2605 | (looking-at allout-bob-regexp)) | |
2606 | (goto-char (allout-prefix-data)) | |
2607 | (if (and (allout-do-doublecheck) | |
2608 | (allout-aberrant-container-p)) | |
2609 | (or (allout-previous-heading) | |
2610 | (and (goto-char start-point) | |
2611 | ;; recalibrate allout-recent-*: | |
2612 | (allout-depth) | |
2613 | nil)) | |
2614 | (point))))))) | |
96b83743 EZ |
2615 | ;;;_ > allout-get-invisibility-overlay () |
2616 | (defun allout-get-invisibility-overlay () | |
2617 | "Return the overlay at point that dictates allout invisibility." | |
2618 | (let ((overlays (overlays-at (point))) | |
2619 | got) | |
2620 | (while (and overlays (not got)) | |
2621 | (if (equal (overlay-get (car overlays) 'invisible) 'allout) | |
d8350998 CY |
2622 | (setq got (car overlays)) |
2623 | (pop overlays))) | |
96b83743 EZ |
2624 | got)) |
2625 | ;;;_ > allout-back-to-visible-text () | |
2626 | (defun allout-back-to-visible-text () | |
2627 | "Move to most recent prior character that is visible, and return point." | |
2628 | (if (allout-hidden-p) | |
2629 | (goto-char (overlay-start (allout-get-invisibility-overlay)))) | |
2630 | (point)) | |
c567ac01 RS |
2631 | |
2632 | ;;;_ - Subtree Charting | |
2633 | ;;;_ " These routines either produce or assess charts, which are | |
2634 | ;;; nested lists of the locations of topics within a subtree. | |
2635 | ;;; | |
d8350998 CY |
2636 | ;;; Charts enable efficient subtree navigation by providing a reusable basis |
2637 | ;;; for elaborate, compound assessment and adjustment of a subtree. | |
c567ac01 | 2638 | |
48bd8440 EZ |
2639 | ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth) |
2640 | (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth) | |
19b84ba3 RS |
2641 | "Produce a location \"chart\" of subtopics of the containing topic. |
2642 | ||
c07583cd | 2643 | Optional argument LEVELS specifies a depth limit (relative to start |
65e7eb3d | 2644 | depth) for the chart. Null LEVELS means no limit. |
48bd8440 EZ |
2645 | |
2646 | When optional argument VISIBLE is non-nil, the chart includes | |
2647 | only the visible subelements of the charted subjects. | |
2648 | ||
65e7eb3d | 2649 | The remaining optional args are for internal use by the function. |
d82979ea EZ |
2650 | |
2651 | Point is left at the end of the subtree. | |
19b84ba3 | 2652 | |
d82979ea | 2653 | Charts are used to capture outline structure, so that outline-altering |
20db1522 | 2654 | routines need to assess the structure only once, and then use the chart |
19b84ba3 RS |
2655 | for their elaborate manipulations. |
2656 | ||
d8350998 CY |
2657 | The chart entries for the topics are in reverse order, so the |
2658 | last topic is listed first. The entry for each topic consists of | |
2659 | an integer indicating the point at the beginning of the topic | |
20db1522 | 2660 | prefix. Charts for offspring consist of a list containing, |
d8350998 CY |
2661 | recursively, the charts for the respective subtopics. The chart |
2662 | for a topics' offspring precedes the entry for the topic itself. | |
19b84ba3 | 2663 | |
d82979ea EZ |
2664 | The other function parameters are for internal recursion, and should |
2665 | not be specified by external callers. ORIG-DEPTH is depth of topic at | |
2666 | starting point, and PREV-DEPTH is depth of prior topic." | |
19b84ba3 | 2667 | |
353e2ef2 | 2668 | (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. |
19b84ba3 RS |
2669 | chart curr-depth) |
2670 | ||
2671 | (if original ; Just starting? | |
2672 | ; Register initial settings and | |
2673 | ; position to first offspring: | |
fd5359c6 | 2674 | (progn (setq orig-depth (allout-depth)) |
19b84ba3 | 2675 | (or prev-depth (setq prev-depth (1+ orig-depth))) |
48bd8440 EZ |
2676 | (if visible |
2677 | (allout-next-visible-heading 1) | |
2678 | (allout-next-heading)))) | |
c567ac01 | 2679 | |
19b84ba3 RS |
2680 | ;; Loop over the current levels' siblings. Besides being more |
2681 | ;; efficient than tail-recursing over a level, it avoids exceeding | |
e126900f | 2682 | ;; the typically quite constrained Emacs max-lisp-eval-depth. |
9179616f | 2683 | ;; |
19b84ba3 RS |
2684 | ;; Probably would speed things up to implement loop-based stack |
2685 | ;; operation rather than recursing for lower levels. Bah. | |
9179616f | 2686 | |
c567ac01 | 2687 | (while (and (not (eobp)) |
19b84ba3 | 2688 | ; Still within original topic? |
d8350998 | 2689 | (< orig-depth (setq curr-depth allout-recent-depth)) |
19b84ba3 RS |
2690 | (cond ((= prev-depth curr-depth) |
2691 | ;; Register this one and move on: | |
d8350998 | 2692 | (setq chart (cons allout-recent-prefix-beginning chart)) |
19b84ba3 | 2693 | (if (and levels (<= levels 1)) |
60c7bbd2 | 2694 | ;; At depth limit -- skip sublevels: |
fd5359c6 | 2695 | (or (allout-next-sibling curr-depth) |
60c7bbd2 | 2696 | ;; or no more siblings -- proceed to |
19b84ba3 | 2697 | ;; next heading at lesser depth: |
e6a9aec7 | 2698 | (while (and (<= curr-depth |
d8350998 | 2699 | allout-recent-depth) |
48bd8440 EZ |
2700 | (if visible |
2701 | (allout-next-visible-heading 1) | |
2702 | (allout-next-heading))))) | |
2703 | (if visible | |
2704 | (allout-next-visible-heading 1) | |
2705 | (allout-next-heading)))) | |
19b84ba3 RS |
2706 | |
2707 | ((and (< prev-depth curr-depth) | |
2708 | (or (not levels) | |
2709 | (> levels 0))) | |
2710 | ;; Recurse on deeper level of curr topic: | |
2711 | (setq chart | |
fd5359c6 | 2712 | (cons (allout-chart-subtree (and levels |
19b84ba3 | 2713 | (1- levels)) |
48bd8440 EZ |
2714 | visible |
2715 | orig-depth | |
2716 | curr-depth) | |
19b84ba3 RS |
2717 | chart)) |
2718 | ;; ... then continue with this one. | |
2719 | ) | |
2720 | ||
2721 | ;; ... else nil if we've ascended back to prev-depth. | |
2722 | ||
2723 | ))) | |
2724 | ||
2725 | (if original ; We're at the last sibling on | |
2726 | ; the original level. Position | |
2727 | ; to the end of it: | |
c567ac01 | 2728 | (progn (and (not (eobp)) (forward-char -1)) |
96b83743 EZ |
2729 | (and (= (preceding-char) ?\n) |
2730 | (= (aref (buffer-substring (max 1 (- (point) 3)) | |
2731 | (point)) | |
2732 | 1) | |
2733 | ?\n) | |
19b84ba3 | 2734 | (forward-char -1)) |
fd5359c6 | 2735 | (setq allout-recent-end-of-subtree (point)))) |
353e2ef2 | 2736 | |
c567ac01 RS |
2737 | chart ; (nreverse chart) not necessary, |
2738 | ; and maybe not preferable. | |
2739 | )) | |
fd5359c6 MR |
2740 | ;;;_ > allout-chart-siblings (&optional start end) |
2741 | (defun allout-chart-siblings (&optional start end) | |
c567ac01 | 2742 | "Produce a list of locations of this and succeeding sibling topics. |
fd5359c6 | 2743 | Effectively a top-level chart of siblings. See `allout-chart-subtree' |
c567ac01 RS |
2744 | for an explanation of charts." |
2745 | (save-excursion | |
d8350998 CY |
2746 | (when (allout-goto-prefix-doublechecked) |
2747 | (let ((chart (list (point)))) | |
2748 | (while (allout-next-sibling) | |
2749 | (setq chart (cons (point) chart))) | |
2750 | (if chart (setq chart (nreverse chart))))))) | |
fd5359c6 MR |
2751 | ;;;_ > allout-chart-to-reveal (chart depth) |
2752 | (defun allout-chart-to-reveal (chart depth) | |
c567ac01 | 2753 | |
19b84ba3 | 2754 | "Return a flat list of hidden points in subtree CHART, up to DEPTH. |
c567ac01 | 2755 | |
65e7eb3d EZ |
2756 | If DEPTH is nil, include hidden points at any depth. |
2757 | ||
19b84ba3 | 2758 | Note that point can be left at any of the points on chart, or at the |
c567ac01 RS |
2759 | start point." |
2760 | ||
2761 | (let (result here) | |
65e7eb3d | 2762 | (while (and (or (null depth) (> depth 0)) |
c567ac01 RS |
2763 | chart) |
2764 | (setq here (car chart)) | |
2765 | (if (listp here) | |
65e7eb3d EZ |
2766 | (let ((further (allout-chart-to-reveal here (if (null depth) |
2767 | depth | |
2768 | (1- depth))))) | |
60c7bbd2 | 2769 | ;; We're on the start of a subtree -- recurse with it, if there's |
c567ac01 RS |
2770 | ;; more depth to go: |
2771 | (if further (setq result (append further result))) | |
2772 | (setq chart (cdr chart))) | |
2773 | (goto-char here) | |
96b83743 | 2774 | (if (allout-hidden-p) |
c567ac01 RS |
2775 | (setq result (cons here result))) |
2776 | (setq chart (cdr chart)))) | |
2777 | result)) | |
fd5359c6 | 2778 | ;;;_ X allout-chart-spec (chart spec &optional exposing) |
e126900f | 2779 | ;; (defun allout-chart-spec (chart spec &optional exposing) |
c07583cd | 2780 | ;; "Not yet (if ever) implemented. |
e126900f JB |
2781 | |
2782 | ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC. | |
2783 | ||
2784 | ;; Exposure spec indicates the locations to be exposed and the prescribed | |
2785 | ;; exposure status. Optional arg EXPOSING is an integer, with 0 | |
2786 | ;; indicating pending concealment, anything higher indicating depth to | |
2787 | ;; which subtopic headers should be exposed, and negative numbers | |
2788 | ;; indicating (negative of) the depth to which subtopic headers and | |
2789 | ;; bodies should be exposed. | |
2790 | ||
2791 | ;; The produced list can have two types of entries. Bare numbers | |
2792 | ;; indicate points in the buffer where topic headers that should be | |
2793 | ;; exposed reside. | |
2794 | ||
2795 | ;; - bare negative numbers indicates that the topic starting at the | |
2796 | ;; point which is the negative of the number should be opened, | |
2797 | ;; including their entries. | |
2798 | ;; - bare positive values indicate that this topic header should be | |
2799 | ;; opened. | |
2800 | ;; - Lists signify the beginning and end points of regions that should | |
c07583cd | 2801 | ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and |
e126900f JB |
2802 | ;; exposure:" |
2803 | ;; (while spec | |
2804 | ;; (cond ((listp spec) | |
2805 | ;; ) | |
2806 | ;; ) | |
2807 | ;; (setq spec (cdr spec))) | |
2808 | ;; ) | |
c567ac01 RS |
2809 | |
2810 | ;;;_ - Within Topic | |
fd5359c6 MR |
2811 | ;;;_ > allout-goto-prefix () |
2812 | (defun allout-goto-prefix () | |
9179616f | 2813 | "Put point at beginning of immediately containing outline topic. |
19b84ba3 | 2814 | |
9179616f | 2815 | Goes to most immediate subsequent topic if none immediately containing. |
19b84ba3 RS |
2816 | |
2817 | Not sensitive to topic visibility. | |
c567ac01 | 2818 | |
d27081f5 | 2819 | Returns the point at the beginning of the prefix, or nil if none." |
c567ac01 | 2820 | |
2a1408fd DN |
2821 | (save-match-data |
2822 | (let (done) | |
2823 | (while (and (not done) | |
2824 | (search-backward "\n" nil 1)) | |
2825 | (forward-char 1) | |
2826 | (if (looking-at allout-regexp) | |
2827 | (setq done (allout-prefix-data)) | |
2828 | (forward-char -1))) | |
2829 | (if (bobp) | |
2830 | (cond ((looking-at allout-regexp) | |
2831 | (allout-prefix-data)) | |
2832 | ((allout-next-heading)) | |
2833 | (done)) | |
2834 | done)))) | |
d8350998 CY |
2835 | ;;;_ > allout-goto-prefix-doublechecked () |
2836 | (defun allout-goto-prefix-doublechecked () | |
2837 | "Put point at beginning of immediately containing outline topic. | |
2838 | ||
c07583cd | 2839 | Like `allout-goto-prefix', but shallow topics (according to |
65e7eb3d EZ |
2840 | `allout-doublecheck-at-and-shallower') are checked and |
2841 | disqualified for child containment discontinuity, according to | |
2842 | `allout-aberrant-container-p'." | |
ede4ac6a KS |
2843 | (if (allout-goto-prefix) |
2844 | (if (and (allout-do-doublecheck) | |
2845 | (allout-aberrant-container-p)) | |
2846 | (allout-previous-heading) | |
2847 | (point)))) | |
d8350998 | 2848 | |
fd5359c6 MR |
2849 | ;;;_ > allout-end-of-prefix () |
2850 | (defun allout-end-of-prefix (&optional ignore-decorations) | |
19b84ba3 RS |
2851 | "Position cursor at beginning of header text. |
2852 | ||
2853 | If optional IGNORE-DECORATIONS is non-nil, put just after bullet, | |
2854 | otherwise skip white space between bullet and ensuing text." | |
c567ac01 | 2855 | |
d8350998 | 2856 | (if (not (allout-goto-prefix-doublechecked)) |
1977b8f6 | 2857 | nil |
d8350998 | 2858 | (goto-char allout-recent-prefix-end) |
2a1408fd DN |
2859 | (save-match-data |
2860 | (if ignore-decorations | |
2861 | t | |
2862 | (while (looking-at "[0-9]") (forward-char 1)) | |
2863 | (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))) | |
1977b8f6 | 2864 | ;; Reestablish where we are: |
fd5359c6 MR |
2865 | (allout-current-depth))) |
2866 | ;;;_ > allout-current-bullet-pos () | |
2867 | (defun allout-current-bullet-pos () | |
c07583cd | 2868 | "Return position of current (visible) topic's bullet." |
c567ac01 | 2869 | |
8a559d4e | 2870 | (if (not (allout-current-depth)) |
c567ac01 | 2871 | nil |
8a559d4e | 2872 | (1- allout-recent-prefix-end))) |
1c9b9df0 KM |
2873 | ;;;_ > allout-back-to-current-heading (&optional interactive) |
2874 | (defun allout-back-to-current-heading (&optional interactive) | |
80f66ef4 | 2875 | "Move to heading line of current topic, or beginning if not in a topic. |
96b83743 | 2876 | |
80f66ef4 CY |
2877 | If interactive, we position at the end of the prefix. |
2878 | ||
2879 | Return value of resulting point, unless we started outside | |
2880 | of (before any) topics, in which case we return nil." | |
96b83743 | 2881 | |
1c9b9df0 KM |
2882 | (interactive "p") |
2883 | ||
96b83743 | 2884 | (allout-beginning-of-current-line) |
80f66ef4 | 2885 | (let ((bol-point (point))) |
1e004a83 KM |
2886 | (when (allout-goto-prefix-doublechecked) |
2887 | (if (<= (point) bol-point) | |
2888 | (progn | |
2889 | (setq bol-point (point)) | |
2890 | (allout-beginning-of-current-line) | |
2891 | (if (not (= bol-point (point))) | |
2892 | (if (looking-at allout-regexp) | |
2893 | (allout-prefix-data))) | |
1c9b9df0 | 2894 | (if interactive |
ede4ac6a | 2895 | (allout-end-of-prefix) |
1e004a83 KM |
2896 | (point))) |
2897 | (goto-char (point-min)) | |
2898 | nil)))) | |
fd5359c6 MR |
2899 | ;;;_ > allout-back-to-heading () |
2900 | (defalias 'allout-back-to-heading 'allout-back-to-current-heading) | |
96b83743 EZ |
2901 | ;;;_ > allout-pre-next-prefix () |
2902 | (defun allout-pre-next-prefix () | |
1977b8f6 RS |
2903 | "Skip forward to just before the next heading line. |
2904 | ||
c567ac01 | 2905 | Returns that character position." |
1977b8f6 | 2906 | |
8a559d4e EZ |
2907 | (if (allout-next-heading) |
2908 | (goto-char (1- allout-recent-prefix-beginning)))) | |
96b83743 EZ |
2909 | ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank) |
2910 | (defun allout-end-of-subtree (&optional current include-trailing-blank) | |
d82979ea EZ |
2911 | "Put point at the end of the last leaf in the containing topic. |
2912 | ||
96b83743 EZ |
2913 | Optional CURRENT means put point at the end of the containing |
2914 | visible topic. | |
2915 | ||
2916 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if | |
2917 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2918 | excluded as delimiting whitespace between topics. | |
d82979ea EZ |
2919 | |
2920 | Returns the value of point." | |
2921 | (interactive "P") | |
2922 | (if current | |
2923 | (allout-back-to-current-heading) | |
d8350998 CY |
2924 | (allout-goto-prefix-doublechecked)) |
2925 | (let ((level allout-recent-depth)) | |
fd5359c6 | 2926 | (allout-next-heading) |
1977b8f6 | 2927 | (while (and (not (eobp)) |
d8350998 | 2928 | (> allout-recent-depth level)) |
fd5359c6 | 2929 | (allout-next-heading)) |
48bd8440 EZ |
2930 | (if (eobp) |
2931 | (allout-end-of-entry) | |
2932 | (forward-char -1)) | |
96b83743 | 2933 | (if (and (not include-trailing-blank) (= ?\n (preceding-char))) |
c567ac01 | 2934 | (forward-char -1)) |
fd5359c6 | 2935 | (setq allout-recent-end-of-subtree (point)))) |
96b83743 EZ |
2936 | ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank) |
2937 | (defun allout-end-of-current-subtree (&optional include-trailing-blank) | |
2938 | ||
d82979ea EZ |
2939 | "Put point at end of last leaf in currently visible containing topic. |
2940 | ||
96b83743 EZ |
2941 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if |
2942 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2943 | excluded as delimiting whitespace between topics. | |
2944 | ||
d82979ea EZ |
2945 | Returns the value of point." |
2946 | (interactive) | |
96b83743 | 2947 | (allout-end-of-subtree t include-trailing-blank)) |
1c9b9df0 KM |
2948 | ;;;_ > allout-beginning-of-current-entry (&optional interactive) |
2949 | (defun allout-beginning-of-current-entry (&optional interactive) | |
d82979ea | 2950 | "When not already there, position point at beginning of current topic header. |
c567ac01 RS |
2951 | |
2952 | If already there, move cursor to bullet for hot-spot operation. | |
46771bb3 | 2953 | \(See `allout-mode' doc string for details of hot-spot operation.)" |
1c9b9df0 | 2954 | (interactive "p") |
c567ac01 | 2955 | (let ((start-point (point))) |
46771bb3 | 2956 | (move-beginning-of-line 1) |
d8350998 CY |
2957 | (if (< 0 (allout-current-depth)) |
2958 | (goto-char allout-recent-prefix-end) | |
2959 | (goto-char (point-min))) | |
fd5359c6 | 2960 | (allout-end-of-prefix) |
1c9b9df0 | 2961 | (if (and interactive |
c567ac01 | 2962 | (= (point) start-point)) |
fd5359c6 | 2963 | (goto-char (allout-current-bullet-pos))))) |
96b83743 EZ |
2964 | ;;;_ > allout-end-of-entry (&optional inclusive) |
2965 | (defun allout-end-of-entry (&optional inclusive) | |
2966 | "Position the point at the end of the current topics' entry. | |
2967 | ||
2968 | Optional INCLUSIVE means also include trailing empty line, if any. When | |
2969 | unset, whitespace between items separates them even when the items are | |
2970 | collapsed." | |
1977b8f6 | 2971 | (interactive) |
96b83743 EZ |
2972 | (allout-pre-next-prefix) |
2973 | (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char))) | |
2974 | (forward-char -1)) | |
2975 | (point)) | |
fd5359c6 MR |
2976 | ;;;_ > allout-end-of-current-heading () |
2977 | (defun allout-end-of-current-heading () | |
9179616f | 2978 | (interactive) |
fd5359c6 | 2979 | (allout-beginning-of-current-entry) |
96b83743 | 2980 | (search-forward "\n" nil t) |
d82979ea | 2981 | (forward-char -1)) |
fd5359c6 | 2982 | (defalias 'allout-end-of-heading 'allout-end-of-current-heading) |
d82979ea EZ |
2983 | ;;;_ > allout-get-body-text () |
2984 | (defun allout-get-body-text () | |
2985 | "Return the unmangled body text of the topic immediately containing point." | |
2986 | (save-excursion | |
2987 | (allout-end-of-prefix) | |
96b83743 | 2988 | (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
2989 | nil |
2990 | (backward-char 1) | |
2991 | (let ((pre-body (point))) | |
2992 | (if (not pre-body) | |
2993 | nil | |
96b83743 | 2994 | (allout-end-of-entry t) |
d82979ea EZ |
2995 | (if (not (= pre-body (point))) |
2996 | (buffer-substring-no-properties (1+ pre-body) (point)))) | |
2997 | ) | |
2998 | ) | |
2999 | ) | |
3000 | ) | |
1977b8f6 | 3001 | |
c567ac01 | 3002 | ;;;_ - Depth-wise |
fd5359c6 MR |
3003 | ;;;_ > allout-ascend-to-depth (depth) |
3004 | (defun allout-ascend-to-depth (depth) | |
c567ac01 | 3005 | "Ascend to depth DEPTH, returning depth if successful, nil if not." |
fd5359c6 | 3006 | (if (and (> depth 0)(<= depth (allout-depth))) |
d8350998 CY |
3007 | (let (last-ascended) |
3008 | (while (and (< depth allout-recent-depth) | |
3009 | (setq last-ascended (allout-ascend)))) | |
3010 | (goto-char allout-recent-prefix-beginning) | |
1c9b9df0 | 3011 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
d8350998 | 3012 | (and last-ascended allout-recent-depth)))) |
1c9b9df0 | 3013 | ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful) |
c07583cd KS |
3014 | (defun allout-ascend (&optional dont-move-if-unsuccessful) |
3015 | "Ascend one level, returning resulting depth if successful, nil if not. | |
3016 | ||
3017 | Point is left at the beginning of the level whether or not | |
3018 | successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in | |
3019 | which case point is returned to its original starting location." | |
3020 | (if dont-move-if-unsuccessful | |
3021 | (setq dont-move-if-unsuccessful (point))) | |
d82979ea EZ |
3022 | (prog1 |
3023 | (if (allout-beginning-of-level) | |
498a6493 CY |
3024 | (let ((bolevel (point)) |
3025 | (bolevel-depth allout-recent-depth)) | |
3026 | (allout-previous-heading) | |
c07583cd KS |
3027 | (cond ((< allout-recent-depth bolevel-depth) |
3028 | allout-recent-depth) | |
3029 | ((= allout-recent-depth bolevel-depth) | |
3030 | (if dont-move-if-unsuccessful | |
3031 | (goto-char dont-move-if-unsuccessful)) | |
3032 | (allout-depth) | |
3033 | nil) | |
3034 | (t | |
3035 | ;; some topic after very first is lower depth than first: | |
3036 | (goto-char bolevel) | |
3037 | (allout-depth) | |
3038 | nil)))) | |
1c9b9df0 | 3039 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 MR |
3040 | ;;;_ > allout-descend-to-depth (depth) |
3041 | (defun allout-descend-to-depth (depth) | |
19b84ba3 RS |
3042 | "Descend to depth DEPTH within current topic. |
3043 | ||
3044 | Returning depth if successful, nil if not." | |
1977b8f6 | 3045 | (let ((start-point (point)) |
fd5359c6 | 3046 | (start-depth (allout-depth))) |
1977b8f6 | 3047 | (while |
fd5359c6 | 3048 | (and (> (allout-depth) 0) |
d8350998 | 3049 | (not (= depth allout-recent-depth)) ; ... not there yet |
fd5359c6 | 3050 | (allout-next-heading) ; ... go further |
d8350998 | 3051 | (< start-depth allout-recent-depth))) ; ... still in topic |
fd5359c6 | 3052 | (if (and (> (allout-depth) 0) |
d8350998 | 3053 | (= allout-recent-depth depth)) |
1977b8f6 RS |
3054 | depth |
3055 | (goto-char start-point) | |
3056 | nil)) | |
3057 | ) | |
d8350998 CY |
3058 | ;;;_ > allout-up-current-level (arg) |
3059 | (defun allout-up-current-level (arg) | |
3060 | "Move out ARG levels from current visible topic." | |
d82979ea | 3061 | (interactive "p") |
8a559d4e EZ |
3062 | (let ((start-point (point))) |
3063 | (allout-back-to-current-heading) | |
3064 | (if (not (allout-ascend)) | |
3065 | (progn (goto-char start-point) | |
3066 | (error "Can't ascend past outermost level")) | |
1c9b9df0 | 3067 | (if (allout-called-interactively-p) (allout-end-of-prefix)) |
8a559d4e | 3068 | allout-recent-prefix-beginning))) |
1977b8f6 | 3069 | |
c567ac01 | 3070 | ;;;_ - Linear |
fd5359c6 MR |
3071 | ;;;_ > allout-next-sibling (&optional depth backward) |
3072 | (defun allout-next-sibling (&optional depth backward) | |
2265e017 | 3073 | "Like `allout-forward-current-level', but respects invisible topics. |
1977b8f6 | 3074 | |
c567ac01 | 3075 | Traverse at optional DEPTH, or current depth if none specified. |
1977b8f6 | 3076 | |
c567ac01 | 3077 | Go backward if optional arg BACKWARD is non-nil. |
1977b8f6 | 3078 | |
d8350998 | 3079 | Return the start point of the new topic if successful, nil otherwise." |
1977b8f6 | 3080 | |
d8350998 | 3081 | (if (if backward (bobp) (eobp)) |
1977b8f6 | 3082 | nil |
d8350998 | 3083 | (let ((target-depth (or depth (allout-depth))) |
1977b8f6 | 3084 | (start-point (point)) |
ede4ac6a | 3085 | (start-prefix-beginning allout-recent-prefix-beginning) |
d8350998 CY |
3086 | (count 0) |
3087 | leaping | |
c567ac01 | 3088 | last-depth) |
d8350998 CY |
3089 | (while (and |
3090 | ;; done too few single steps to resort to the leap routine: | |
3091 | (not leaping) | |
3092 | ;; not at limit: | |
3093 | (not (if backward (bobp) (eobp))) | |
3094 | ;; still traversable: | |
3095 | (if backward (allout-previous-heading) (allout-next-heading)) | |
3096 | ;; we're below the target depth | |
3097 | (> (setq last-depth allout-recent-depth) target-depth)) | |
3098 | (setq count (1+ count)) | |
3099 | (if (> count 7) ; lists are commonly 7 +- 2, right?-) | |
3100 | (setq leaping t))) | |
3101 | (cond (leaping | |
3102 | (or (allout-next-sibling-leap target-depth backward) | |
3103 | (progn | |
3104 | (goto-char start-point) | |
3105 | (if depth (allout-depth) target-depth) | |
3106 | nil))) | |
3107 | ((and (not (eobp)) | |
3108 | (and (> (or last-depth (allout-depth)) 0) | |
ede4ac6a KS |
3109 | (= allout-recent-depth target-depth)) |
3110 | (not (= start-prefix-beginning | |
3111 | allout-recent-prefix-beginning))) | |
d8350998 CY |
3112 | allout-recent-prefix-beginning) |
3113 | (t | |
3114 | (goto-char start-point) | |
3115 | (if depth (allout-depth) target-depth) | |
3116 | nil))))) | |
3117 | ;;;_ > allout-next-sibling-leap (&optional depth backward) | |
3118 | (defun allout-next-sibling-leap (&optional depth backward) | |
3119 | "Like `allout-next-sibling', but by direct search for topic at depth. | |
3120 | ||
3121 | Traverse at optional DEPTH, or current depth if none specified. | |
3122 | ||
3123 | Go backward if optional arg BACKWARD is non-nil. | |
3124 | ||
3125 | Return the start point of the new topic if successful, nil otherwise. | |
3126 | ||
3127 | Costs more than regular `allout-next-sibling' for short traversals: | |
3128 | ||
ee7683eb | 3129 | - we have to check the prior (next, if traveling backwards) |
d8350998 CY |
3130 | item to confirm connectivity with the prior topic, and |
3131 | - if confirmed, we have to reestablish the allout-recent-* settings with | |
3132 | some extra navigation | |
3133 | - if confirmation fails, we have to do more work to recover | |
3134 | ||
3135 | It is an increasingly big win when there are many intervening | |
3136 | offspring before the next sibling, however, so | |
3137 | `allout-next-sibling' resorts to this if it finds itself in that | |
3138 | situation." | |
3139 | ||
3140 | (if (if backward (bobp) (eobp)) | |
3141 | nil | |
3142 | (let* ((start-point (point)) | |
3143 | (target-depth (or depth (allout-depth))) | |
3144 | (search-whitespace-regexp nil) | |
3145 | (depth-biased (- target-depth 2)) | |
3146 | (expression (if (<= target-depth 1) | |
3147 | allout-depth-one-regexp | |
3148 | (format allout-depth-specific-regexp | |
3149 | depth-biased depth-biased))) | |
3150 | found | |
3151 | done) | |
3152 | (while (not done) | |
2a1408fd DN |
3153 | (setq found (save-match-data |
3154 | (if backward | |
3155 | (re-search-backward expression nil 'to-limit) | |
3156 | (forward-char 1) | |
3157 | (re-search-forward expression nil 'to-limit)))) | |
d8350998 CY |
3158 | (if (and found (allout-aberrant-container-p)) |
3159 | (setq found nil)) | |
3160 | (setq done (or found (if backward (bobp) (eobp))))) | |
3161 | (if (not found) | |
3162 | (progn (goto-char start-point) | |
3163 | nil) | |
3164 | ;; rationale: if any intervening items were at a lower depth, we | |
60c7bbd2 | 3165 | ;; would now be on the first offspring at the target depth -- ie, |
97610156 | 3166 | ;; the preceding item (per the search direction) must be at a |
d8350998 CY |
3167 | ;; lesser depth. that's all we need to check. |
3168 | (if backward (allout-next-heading) (allout-previous-heading)) | |
3169 | (if (< allout-recent-depth target-depth) | |
3170 | ;; return to start and reestablish allout-recent-*: | |
3171 | (progn | |
3172 | (goto-char start-point) | |
3173 | (allout-depth) | |
3174 | nil) | |
3175 | (goto-char found) | |
3176 | ;; locate cursor and set allout-recent-*: | |
3177 | (allout-goto-prefix)))))) | |
fd5359c6 MR |
3178 | ;;;_ > allout-previous-sibling (&optional depth backward) |
3179 | (defun allout-previous-sibling (&optional depth backward) | |
d82979ea | 3180 | "Like `allout-forward-current-level' backwards, respecting invisible topics. |
1977b8f6 | 3181 | |
c567ac01 | 3182 | Optional DEPTH specifies depth to traverse, default current depth. |
1977b8f6 | 3183 | |
c567ac01 | 3184 | Optional BACKWARD reverses direction. |
1977b8f6 | 3185 | |
c567ac01 | 3186 | Return depth if successful, nil otherwise." |
fd5359c6 | 3187 | (allout-next-sibling depth (not backward)) |
1977b8f6 | 3188 | ) |
fd5359c6 MR |
3189 | ;;;_ > allout-snug-back () |
3190 | (defun allout-snug-back () | |
539d7736 | 3191 | "Position cursor at end of previous topic. |
19b84ba3 RS |
3192 | |
3193 | Presumes point is at the start of a topic prefix." | |
c567ac01 RS |
3194 | (if (or (bobp) (eobp)) |
3195 | nil | |
3196 | (forward-char -1)) | |
96b83743 | 3197 | (if (or (bobp) (not (= ?\n (preceding-char)))) |
c567ac01 | 3198 | nil |
96b83743 | 3199 | (forward-char -1)) |
c567ac01 | 3200 | (point)) |
fd5359c6 MR |
3201 | ;;;_ > allout-beginning-of-level () |
3202 | (defun allout-beginning-of-level () | |
c567ac01 | 3203 | "Go back to the first sibling at this level, visible or not." |
fd5359c6 MR |
3204 | (allout-end-of-level 'backward)) |
3205 | ;;;_ > allout-end-of-level (&optional backward) | |
3206 | (defun allout-end-of-level (&optional backward) | |
c567ac01 | 3207 | "Go to the last sibling at this level, visible or not." |
1977b8f6 | 3208 | |
fd5359c6 MR |
3209 | (let ((depth (allout-depth))) |
3210 | (while (allout-previous-sibling depth nil)) | |
d8350998 | 3211 | (prog1 allout-recent-depth |
1c9b9df0 | 3212 | (if (allout-called-interactively-p) (allout-end-of-prefix))))) |
fd5359c6 MR |
3213 | ;;;_ > allout-next-visible-heading (arg) |
3214 | (defun allout-next-visible-heading (arg) | |
20db1522 | 3215 | "Move to the next ARGth visible heading line, backward if ARG is negative. |
c567ac01 | 3216 | |
96b83743 | 3217 | Move to buffer limit in indicated direction if headings are exhausted." |
1977b8f6 | 3218 | |
1977b8f6 | 3219 | (interactive "p") |
0458fa80 EZ |
3220 | (let* ((inhibit-field-text-motion t) |
3221 | (backward (if (< arg 0) (setq arg (* -1 arg)))) | |
c567ac01 | 3222 | (step (if backward -1 1)) |
82b392a4 | 3223 | (progress (allout-current-bullet-pos)) |
c567ac01 RS |
3224 | prev got) |
3225 | ||
d8350998 CY |
3226 | (while (> arg 0) |
3227 | (while (and | |
3228 | ;; Boundary condition: | |
3229 | (not (if backward (bobp)(eobp))) | |
3230 | ;; Move, skipping over all concealed lines in one fell swoop: | |
3231 | (prog1 (condition-case nil (or (line-move step) t) | |
3232 | (error nil)) | |
82b392a4 KM |
3233 | (allout-beginning-of-current-line) |
3234 | ;; line-move can wind up on the same line if long. | |
3235 | ;; when moving forward, that would yield no-progress | |
3236 | (when (and (not backward) | |
3237 | (<= (point) progress)) | |
3238 | ;; ensure progress by doing line-move from end-of-line: | |
3239 | (end-of-line) | |
3240 | (condition-case nil (or (line-move step) t) | |
3241 | (error nil)) | |
3242 | (allout-beginning-of-current-line) | |
3243 | (setq progress (point)))) | |
d8350998 | 3244 | ;; Deal with apparent header line: |
2a1408fd DN |
3245 | (save-match-data |
3246 | (if (not (looking-at allout-regexp)) | |
3247 | ;; not a header line, keep looking: | |
d8350998 | 3248 | t |
2a1408fd DN |
3249 | (allout-prefix-data) |
3250 | (if (and (allout-do-doublecheck) | |
3251 | (allout-aberrant-container-p)) | |
3252 | ;; skip this aberrant prospective header line: | |
3253 | t | |
8dd59f01 | 3254 | ;; this prospective headerline qualifies -- register: |
2a1408fd DN |
3255 | (setq got allout-recent-prefix-beginning) |
3256 | ;; and break the loop: | |
3257 | nil))))) | |
c567ac01 RS |
3258 | ;; Register this got, it may be the last: |
3259 | (if got (setq prev got)) | |
3260 | (setq arg (1- arg))) | |
3261 | (cond (got ; Last move was to a prefix: | |
d8350998 | 3262 | (allout-end-of-prefix)) |
c567ac01 | 3263 | (prev ; Last move wasn't, but prev was: |
d8350998 CY |
3264 | (goto-char prev) |
3265 | (allout-end-of-prefix)) | |
c567ac01 | 3266 | ((not backward) (end-of-line) nil)))) |
fd5359c6 MR |
3267 | ;;;_ > allout-previous-visible-heading (arg) |
3268 | (defun allout-previous-visible-heading (arg) | |
c567ac01 | 3269 | "Move to the previous heading line. |
1977b8f6 | 3270 | |
c567ac01 | 3271 | With argument, repeats or can move forward if negative. |
2265e017 | 3272 | A heading line is one that starts with a `*' (or that `allout-regexp' |
c567ac01 | 3273 | matches)." |
1977b8f6 | 3274 | (interactive "p") |
d8350998 | 3275 | (prog1 (allout-next-visible-heading (- arg)) |
1c9b9df0 | 3276 | (if (allout-called-interactively-p) (allout-end-of-prefix)))) |
fd5359c6 | 3277 | ;;;_ > allout-forward-current-level (arg) |
d82979ea | 3278 | (defun allout-forward-current-level (arg) |
19b84ba3 | 3279 | "Position point at the next heading of the same level. |
1977b8f6 | 3280 | |
19b84ba3 | 3281 | Takes optional repeat-count, goes backward if count is negative. |
1977b8f6 | 3282 | |
19b84ba3 | 3283 | Returns resulting position, else nil if none found." |
d82979ea | 3284 | (interactive "p") |
fd5359c6 | 3285 | (let ((start-depth (allout-current-depth)) |
19b84ba3 | 3286 | (start-arg arg) |
d8350998 | 3287 | (backward (> 0 arg))) |
19b84ba3 RS |
3288 | (if (= 0 start-depth) |
3289 | (error "No siblings, not in a topic...")) | |
3290 | (if backward (setq arg (* -1 arg))) | |
d8350998 CY |
3291 | (allout-back-to-current-heading) |
3292 | (while (and (not (zerop arg)) | |
3293 | (if backward | |
3294 | (allout-previous-sibling) | |
3295 | (allout-next-sibling))) | |
3296 | (setq arg (1- arg))) | |
1c9b9df0 | 3297 | (if (not (allout-called-interactively-p)) |
d8350998 CY |
3298 | nil |
3299 | (allout-end-of-prefix) | |
3300 | (if (not (zerop arg)) | |
3301 | (error "Hit %s level %d topic, traversed %d of %d requested" | |
3302 | (if backward "first" "last") | |
3303 | allout-recent-depth | |
3304 | (- (abs start-arg) arg) | |
3305 | (abs start-arg)))))) | |
fd5359c6 | 3306 | ;;;_ > allout-backward-current-level (arg) |
d82979ea | 3307 | (defun allout-backward-current-level (arg) |
fd5359c6 | 3308 | "Inverse of `allout-forward-current-level'." |
d82979ea | 3309 | (interactive "p") |
1c9b9df0 | 3310 | (if (allout-called-interactively-p) |
19b84ba3 | 3311 | (let ((current-prefix-arg (* -1 arg))) |
fd5359c6 MR |
3312 | (call-interactively 'allout-forward-current-level)) |
3313 | (allout-forward-current-level (* -1 arg)))) | |
c567ac01 | 3314 | |
19b84ba3 | 3315 | ;;;_ #5 Alteration |
c567ac01 RS |
3316 | |
3317 | ;;;_ - Fundamental | |
fd5359c6 MR |
3318 | ;;;_ = allout-post-goto-bullet |
3319 | (defvar allout-post-goto-bullet nil | |
3320 | "Outline internal var, for `allout-pre-command-business' hot-spot operation. | |
19b84ba3 RS |
3321 | |
3322 | When set, tells post-processing to reposition on topic bullet, and | |
2265e017 | 3323 | then unset it. Set by `allout-pre-command-business' when implementing |
19b84ba3 RS |
3324 | hot-spot operation, where literal characters typed over a topic bullet |
3325 | are mapped to the command of the corresponding control-key on the | |
d3e51865 | 3326 | `allout-mode-map-value'.") |
fd5359c6 | 3327 | (make-variable-buffer-local 'allout-post-goto-bullet) |
48bd8440 EZ |
3328 | ;;;_ = allout-command-counter |
3329 | (defvar allout-command-counter 0 | |
3330 | "Counter that monotonically increases in allout-mode buffers. | |
3331 | ||
3332 | Set by `allout-pre-command-business', to support allout addons in | |
3333 | coordinating with allout activity.") | |
3334 | (make-variable-buffer-local 'allout-command-counter) | |
3f2b07f8 KM |
3335 | ;;;_ = allout-this-command-hid-text |
3336 | (defvar allout-this-command-hid-text nil | |
3337 | "True if the most recent allout-mode command hid any text.") | |
3338 | (make-variable-buffer-local 'allout-this-command-hid-text) | |
fd5359c6 MR |
3339 | ;;;_ > allout-post-command-business () |
3340 | (defun allout-post-command-business () | |
2265e017 | 3341 | "Outline `post-command-hook' function. |
c567ac01 | 3342 | |
2265e017 | 3343 | - Implement (and clear) `allout-post-goto-bullet', for hot-spot |
c567ac01 RS |
3344 | outline commands. |
3345 | ||
3f2b07f8 KM |
3346 | - Move the cursor to the beginning of the entry if it is hidden |
3347 | and collapsing activity just happened. | |
3348 | ||
13aa217b KM |
3349 | - If the command we're following was an undo, check for change in |
3350 | the status of encrypted items and adjust auto-save inhibitions | |
3351 | accordingly. | |
3352 | ||
96b83743 | 3353 | - Decrypt topic currently being edited if it was encrypted for a save." |
c567ac01 | 3354 | |
fd5359c6 | 3355 | (if (not (allout-mode-p)) ; In allout-mode. |
19b84ba3 | 3356 | nil |
d82979ea | 3357 | |
13aa217b KM |
3358 | (when allout-just-did-undo |
3359 | (setq allout-just-did-undo nil) | |
919d884a | 3360 | (run-hooks 'allout-post-undo-hook) |
13aa217b KM |
3361 | (cond ((and (= buffer-saved-size -1) |
3362 | allout-auto-save-temporarily-disabled) | |
99d99081 | 3363 | ;; user possibly undid a decryption, disinhibit auto-save: |
13aa217b KM |
3364 | (allout-maybe-resume-auto-save-info-after-encryption)) |
3365 | ((save-excursion | |
3366 | (save-restriction | |
3367 | (widen) | |
3368 | (goto-char (point-min)) | |
3369 | (not (allout-next-topic-pending-encryption)))) | |
3370 | ;; plain-text encrypted items are present, inhibit auto-save: | |
3371 | (allout-inhibit-auto-save-info-for-decryption (buffer-size))))) | |
3372 | ||
d82979ea EZ |
3373 | (if (and (boundp 'allout-after-save-decrypt) |
3374 | allout-after-save-decrypt) | |
3375 | (allout-after-saves-handler)) | |
3376 | ||
48bd8440 | 3377 | ;; Implement allout-post-goto-bullet, if set: |
fd5359c6 MR |
3378 | (if (and allout-post-goto-bullet |
3379 | (allout-current-bullet-pos)) | |
3380 | (progn (goto-char (allout-current-bullet-pos)) | |
3f2b07f8 KM |
3381 | (setq allout-post-goto-bullet nil)) |
3382 | (when (and (allout-hidden-p) allout-this-command-hid-text) | |
3383 | (allout-beginning-of-current-entry))))) | |
fd5359c6 MR |
3384 | ;;;_ > allout-pre-command-business () |
3385 | (defun allout-pre-command-business () | |
2265e017 | 3386 | "Outline `pre-command-hook' function for outline buffers. |
48bd8440 EZ |
3387 | |
3388 | Among other things, implements special behavior when the cursor is on the | |
3389 | topic bullet character. | |
c567ac01 | 3390 | |
d3e51865 KM |
3391 | When the cursor is on the bullet character, self-insert |
3392 | characters are reinterpreted as the corresponding | |
3393 | control-character in the `allout-mode-map-value'. The | |
3394 | `allout-mode' `post-command-hook' insures that the cursor which | |
3395 | has moved as a result of such reinterpretation is positioned on | |
3396 | the bullet character of the destination topic. | |
c567ac01 | 3397 | |
c07583cd | 3398 | The upshot is that you can get easy, single (ie, unmodified) key |
9179616f | 3399 | outline maneuvering operations by positioning the cursor on the bullet |
58edceeb JB |
3400 | char. When in this mode you can use regular cursor-positioning |
3401 | command/keystrokes to relocate the cursor off of a bullet character to | |
3402 | return to regular interpretation of self-insert characters." | |
d82979ea | 3403 | |
fd5359c6 | 3404 | (if (not (allout-mode-p)) |
9179616f | 3405 | nil |
48bd8440 | 3406 | (setq allout-command-counter (1+ allout-command-counter)) |
3f2b07f8 | 3407 | (setq allout-this-command-hid-text nil) |
48bd8440 | 3408 | ;; Do hot-spot navigation. |
9179616f | 3409 | (if (and (eq this-command 'self-insert-command) |
fd5359c6 | 3410 | (eq (point)(allout-current-bullet-pos))) |
01fc9422 EZ |
3411 | (allout-hotspot-key-handler)))) |
3412 | ;;;_ > allout-hotspot-key-handler () | |
3413 | (defun allout-hotspot-key-handler () | |
3414 | "Catchall handling of key bindings in hot-spots. | |
3415 | ||
3416 | Translates unmodified keystrokes to corresponding allout commands, when | |
20db1522 JB |
3417 | they would qualify if prefixed with the `allout-command-prefix', and sets |
3418 | `this-command' accordingly. | |
01fc9422 EZ |
3419 | |
3420 | Returns the qualifying command, if any, else nil." | |
3421 | (interactive) | |
1c9b9df0 | 3422 | (let* ((modified (event-modifiers last-command-event)) |
8989a920 | 3423 | (key-num (cond ((numberp last-command-event) last-command-event) |
01fc9422 EZ |
3424 | ;; for XEmacs character type: |
3425 | ((and (fboundp 'characterp) | |
8989a920 GM |
3426 | (apply 'characterp (list last-command-event))) |
3427 | (apply 'char-to-int (list last-command-event))) | |
01fc9422 | 3428 | (t 0))) |
d8350998 | 3429 | mapped-binding) |
01fc9422 EZ |
3430 | |
3431 | (if (zerop key-num) | |
3432 | nil | |
3433 | ||
d8350998 CY |
3434 | (if (and |
3435 | ;; exclude control chars and escape: | |
1c9b9df0 | 3436 | (not modified) |
d8350998 CY |
3437 | (<= 33 key-num) |
3438 | (setq mapped-binding | |
642f3c5c KM |
3439 | (or |
3440 | ;; try control-modified versions of keys: | |
3441 | (key-binding (vconcat allout-command-prefix | |
3442 | (vector | |
3443 | (if (and (<= 97 key-num) ; "a" | |
3444 | (>= 122 key-num)) ; "z" | |
3445 | (- key-num 96) key-num))) | |
3446 | t) | |
3447 | ;; try non-modified versions of keys: | |
3448 | (key-binding (vconcat allout-command-prefix | |
3449 | (vector key-num)) | |
3450 | t)))) | |
60c7bbd2 | 3451 | ;; Qualified as an allout command -- do hot-spot operation. |
01fc9422 | 3452 | (setq allout-post-goto-bullet t) |
1c9b9df0 KM |
3453 | ;; accept-defaults nil, or else we get allout-item-icon-key-handler. |
3454 | (setq mapped-binding (key-binding (vector key-num)))) | |
01fc9422 EZ |
3455 | |
3456 | (while (keymapp mapped-binding) | |
3457 | (setq mapped-binding | |
d8350998 | 3458 | (lookup-key mapped-binding (vector (read-char))))) |
01fc9422 | 3459 | |
1c9b9df0 KM |
3460 | (when mapped-binding |
3461 | (setq this-command mapped-binding))))) | |
01fc9422 | 3462 | |
fd5359c6 MR |
3463 | ;;;_ > allout-find-file-hook () |
3464 | (defun allout-find-file-hook () | |
4034b0e2 | 3465 | "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'. |
fd5359c6 | 3466 | |
11c46e15 | 3467 | See `allout-auto-activation' for setup instructions." |
fd5359c6 MR |
3468 | (if (and allout-auto-activation |
3469 | (not (allout-mode-p)) | |
3470 | allout-layout) | |
2576c28f | 3471 | (allout-mode))) |
c567ac01 RS |
3472 | |
3473 | ;;;_ - Topic Format Assessment | |
fd5359c6 MR |
3474 | ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet) |
3475 | (defun allout-solicit-alternate-bullet (depth &optional current-bullet) | |
1977b8f6 | 3476 | |
19b84ba3 RS |
3477 | "Prompt for and return a bullet char as an alternative to the current one. |
3478 | ||
3479 | Offer one suitable for current depth DEPTH as default." | |
1977b8f6 | 3480 | |
9179616f | 3481 | (let* ((default-bullet (or (and (stringp current-bullet) current-bullet) |
fd5359c6 MR |
3482 | (allout-bullet-for-depth depth))) |
3483 | (sans-escapes (regexp-sans-escapes allout-bullets-string)) | |
9179616f DL |
3484 | choice) |
3485 | (save-excursion | |
fd5359c6 | 3486 | (goto-char (allout-current-bullet-pos)) |
9179616f DL |
3487 | (setq choice (solicit-char-in-string |
3488 | (format "Select bullet: %s ('%s' default): " | |
3489 | sans-escapes | |
1c9b9df0 | 3490 | (allout-substring-no-properties default-bullet)) |
9179616f DL |
3491 | sans-escapes |
3492 | t))) | |
3493 | (message "") | |
1977b8f6 RS |
3494 | (if (string= choice "") default-bullet choice)) |
3495 | ) | |
fd5359c6 MR |
3496 | ;;;_ > allout-distinctive-bullet (bullet) |
3497 | (defun allout-distinctive-bullet (bullet) | |
e126900f | 3498 | "True if BULLET is one of those on `allout-distinctive-bullets-string'." |
fd5359c6 MR |
3499 | (string-match (regexp-quote bullet) allout-distinctive-bullets-string)) |
3500 | ;;;_ > allout-numbered-type-prefix (&optional prefix) | |
3501 | (defun allout-numbered-type-prefix (&optional prefix) | |
c567ac01 | 3502 | "True if current header prefix bullet is numbered bullet." |
fd5359c6 MR |
3503 | (and allout-numbered-bullet |
3504 | (string= allout-numbered-bullet | |
1977b8f6 | 3505 | (if prefix |
fd5359c6 MR |
3506 | (allout-get-prefix-bullet prefix) |
3507 | (allout-get-bullet))))) | |
d82979ea EZ |
3508 | ;;;_ > allout-encrypted-type-prefix (&optional prefix) |
3509 | (defun allout-encrypted-type-prefix (&optional prefix) | |
c07583cd | 3510 | "True if current header prefix bullet is for an encrypted entry (body)." |
d82979ea EZ |
3511 | (and allout-topic-encryption-bullet |
3512 | (string= allout-topic-encryption-bullet | |
3513 | (if prefix | |
3514 | (allout-get-prefix-bullet prefix) | |
3515 | (allout-get-bullet))))) | |
fd5359c6 MR |
3516 | ;;;_ > allout-bullet-for-depth (&optional depth) |
3517 | (defun allout-bullet-for-depth (&optional depth) | |
19b84ba3 | 3518 | "Return outline topic bullet suited to optional DEPTH, or current depth." |
1977b8f6 | 3519 | ;; Find bullet in plain-bullets-string modulo DEPTH. |
fd5359c6 MR |
3520 | (if allout-stylish-prefixes |
3521 | (char-to-string (aref allout-plain-bullets-string | |
1977b8f6 | 3522 | (% (max 0 (- depth 2)) |
fd5359c6 MR |
3523 | allout-plain-bullets-string-len))) |
3524 | allout-primary-bullet) | |
1977b8f6 RS |
3525 | ) |
3526 | ||
c567ac01 | 3527 | ;;;_ - Topic Production |
fd5359c6 MR |
3528 | ;;;_ > allout-make-topic-prefix (&optional prior-bullet |
3529 | (defun allout-make-topic-prefix (&optional prior-bullet | |
1977b8f6 RS |
3530 | new |
3531 | depth | |
b6a5875b | 3532 | instead |
1977b8f6 RS |
3533 | number-control |
3534 | index) | |
3535 | ;; Depth null means use current depth, non-null means we're either | |
3536 | ;; opening a new topic after current topic, lower or higher, or we're | |
3537 | ;; changing level of current topic. | |
b6a5875b | 3538 | ;; Instead dominates specified bullet-char. |
c567ac01 | 3539 | ;;;_ . Doc string: |
19b84ba3 | 3540 | "Generate a topic prefix suitable for optional arg DEPTH, or current depth. |
c567ac01 RS |
3541 | |
3542 | All the arguments are optional. | |
3543 | ||
3544 | PRIOR-BULLET indicates the bullet of the prefix being changed, or | |
3545 | nil if none. This bullet may be preserved (other options | |
2265e017 | 3546 | notwithstanding) if it is on the `allout-distinctive-bullets-string', |
c567ac01 RS |
3547 | for instance. |
3548 | ||
3549 | Second arg NEW indicates that a new topic is being opened after the | |
3550 | topic at point, if non-nil. Default bullet for new topics, eg, may | |
3551 | be set (contingent to other args) to numbered bullets if previous | |
3552 | sibling is one. The implication otherwise is that the current topic | |
60c7bbd2 | 3553 | is being adjusted -- shifted or rebulleted -- and we don't consider |
c567ac01 RS |
3554 | bullet or previous sibling. |
3555 | ||
3556 | Third arg DEPTH forces the topic prefix to that depth, regardless of | |
3557 | the current topics' depth. | |
3558 | ||
b6a5875b KM |
3559 | If INSTEAD is: |
3560 | ||
3561 | - nil, then the bullet char for the context is used, per distinction or depth | |
20db1522 | 3562 | - a (numeric) character, then character's string representation is used |
2dab465b | 3563 | - a string, then the user is asked for bullet with the first char as default |
b6a5875b KM |
3564 | - anything else, the user is solicited with bullet char per context as default |
3565 | ||
3566 | \(INSTEAD overrides other options, including, eg, a distinctive | |
3567 | PRIOR-BULLET.) | |
c567ac01 | 3568 | |
fd5359c6 | 3569 | Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet' |
b6a5875b | 3570 | is non-nil *and* no specific INSTEAD was specified. Then |
c567ac01 | 3571 | NUMBER-CONTROL non-nil forces prefix to either numbered or |
4c36be58 | 3572 | unnumbered format, depending on the value of the sixth arg, INDEX. |
c567ac01 RS |
3573 | |
3574 | \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...) | |
3575 | ||
3576 | If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then | |
3577 | the prefix of the topic is forced to be numbered. Non-nil | |
3578 | NUMBER-CONTROL and nil INDEX forces non-numbered format on the | |
3579 | bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means | |
3580 | that the index for the numbered prefix will be derived, by counting | |
3581 | siblings back to start of level. If INDEX is a number, then that | |
3582 | number is used as the index for the numbered prefix (allowing, eg, | |
a0776d6b | 3583 | sequential renumbering to not require this function counting back the |
c567ac01 RS |
3584 | index for each successive sibling)." |
3585 | ;;;_ . Code: | |
c5e87d10 | 3586 | ;; The options are ordered in likely frequency of use, most common |
1977b8f6 RS |
3587 | ;; highest, least lowest. Ie, more likely to be doing prefix |
3588 | ;; adjustments than soliciting, and yet more than numbering. | |
3589 | ;; Current prefix is least dominant, but most likely to be commonly | |
3590 | ;; specified... | |
3591 | ||
3592 | (let* (body | |
3593 | numbering | |
3594 | denumbering | |
fd5359c6 MR |
3595 | (depth (or depth (allout-depth))) |
3596 | (header-lead allout-header-prefix) | |
1977b8f6 RS |
3597 | (bullet-char |
3598 | ||
3599 | ;; Getting value for bullet char is practically the whole job: | |
3600 | ||
3601 | (cond | |
60c7bbd2 | 3602 | ; Simplest situation -- level 1: |
fd5359c6 | 3603 | ((<= depth 1) (setq header-lead "") allout-primary-bullet) |
1977b8f6 | 3604 | ; Simple, too: all asterisks: |
fd5359c6 | 3605 | (allout-old-style-prefixes |
60c7bbd2 | 3606 | ;; Cheat -- make body the whole thing, null out header-lead and |
1977b8f6 RS |
3607 | ;; bullet-char: |
3608 | (setq body (make-string depth | |
fd5359c6 | 3609 | (string-to-char allout-primary-bullet))) |
1977b8f6 RS |
3610 | (setq header-lead "") |
3611 | "") | |
3612 | ||
3613 | ;; (Neither level 1 nor old-style, so we're space padding. | |
3614 | ;; Sneak it in the condition of the next case, whatever it is.) | |
3615 | ||
3616 | ;; Solicitation overrides numbering and other cases: | |
3617 | ((progn (setq body (make-string (- depth 2) ?\ )) | |
3618 | ;; The actual condition: | |
b6a5875b | 3619 | instead) |
2dab465b KM |
3620 | (let ((got (cond ((stringp instead) |
3621 | (if (> (length instead) 0) | |
3622 | (allout-solicit-alternate-bullet | |
3623 | depth (substring instead 0 1)))) | |
3624 | ((characterp instead) (char-to-string instead)) | |
3625 | (t (allout-solicit-alternate-bullet depth))))) | |
1977b8f6 | 3626 | ;; Gotta check whether we're numbering and got a numbered bullet: |
fd5359c6 | 3627 | (setq numbering (and allout-numbered-bullet |
1977b8f6 | 3628 | (not (and number-control (not index))) |
fd5359c6 | 3629 | (string= got allout-numbered-bullet))) |
1977b8f6 RS |
3630 | ;; Now return what we got, regardless: |
3631 | got)) | |
3632 | ||
3633 | ;; Numbering invoked through args: | |
fd5359c6 | 3634 | ((and allout-numbered-bullet number-control) |
1977b8f6 | 3635 | (if (setq numbering (not (setq denumbering (not index)))) |
fd5359c6 | 3636 | allout-numbered-bullet |
19b84ba3 | 3637 | (if (and prior-bullet |
fd5359c6 | 3638 | (not (string= allout-numbered-bullet |
19b84ba3 RS |
3639 | prior-bullet))) |
3640 | prior-bullet | |
fd5359c6 | 3641 | (allout-bullet-for-depth depth)))) |
1977b8f6 RS |
3642 | |
3643 | ;;; Neither soliciting nor controlled numbering ;;; | |
3644 | ;;; (may be controlled denumbering, tho) ;;; | |
3645 | ||
3646 | ;; Check wrt previous sibling: | |
3647 | ((and new ; only check for new prefixes | |
fd5359c6 MR |
3648 | (<= depth (allout-depth)) |
3649 | allout-numbered-bullet ; ... & numbering enabled | |
1977b8f6 RS |
3650 | (not denumbering) |
3651 | (let ((sibling-bullet | |
3652 | (save-excursion | |
3653 | ;; Locate correct sibling: | |
fd5359c6 MR |
3654 | (or (>= depth (allout-depth)) |
3655 | (allout-ascend-to-depth depth)) | |
3656 | (allout-get-bullet)))) | |
1977b8f6 | 3657 | (if (and sibling-bullet |
fd5359c6 | 3658 | (string= allout-numbered-bullet sibling-bullet)) |
1977b8f6 RS |
3659 | (setq numbering sibling-bullet))))) |
3660 | ||
3661 | ;; Distinctive prior bullet? | |
3662 | ((and prior-bullet | |
fd5359c6 | 3663 | (allout-distinctive-bullet prior-bullet) |
1977b8f6 | 3664 | ;; Either non-numbered: |
fd5359c6 MR |
3665 | (or (not (and allout-numbered-bullet |
3666 | (string= prior-bullet allout-numbered-bullet))) | |
1977b8f6 RS |
3667 | ;; or numbered, and not denumbering: |
3668 | (setq numbering (not denumbering))) | |
3669 | ;; Here 'tis: | |
3670 | prior-bullet)) | |
3671 | ||
3672 | ;; Else, standard bullet per depth: | |
fd5359c6 | 3673 | ((allout-bullet-for-depth depth))))) |
1977b8f6 RS |
3674 | |
3675 | (concat header-lead | |
3676 | body | |
3677 | bullet-char | |
3678 | (if numbering | |
3679 | (format "%d" (cond ((and index (numberp index)) index) | |
fd5359c6 MR |
3680 | (new (1+ (allout-sibling-index depth))) |
3681 | ((allout-sibling-index)))))) | |
1977b8f6 RS |
3682 | ) |
3683 | ) | |
96b83743 EZ |
3684 | ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet) |
3685 | (defun allout-open-topic (relative-depth &optional before offer-recent-bullet) | |
d82979ea | 3686 | "Open a new topic at depth DEPTH. |
19b84ba3 RS |
3687 | |
3688 | New topic is situated after current one, unless optional flag BEFORE | |
60c7bbd2 RS |
3689 | is non-nil, or unless current line is completely empty -- lacking even |
3690 | whitespace -- in which case open is done on the current line. | |
96b83743 EZ |
3691 | |
3692 | When adding an offspring, it will be added immediately after the parent if | |
3693 | the other offspring are exposed, or after the last child if the offspring | |
c07583cd | 3694 | are hidden. (The intervening offspring will be exposed in the latter |
96b83743 | 3695 | case.) |
c567ac01 | 3696 | |
96b83743 | 3697 | If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling. |
9179616f | 3698 | |
c567ac01 RS |
3699 | Nuances: |
3700 | ||
3701 | - Creation of new topics is with respect to the visible topic | |
3702 | containing the cursor, regardless of intervening concealed ones. | |
3703 | ||
3704 | - New headers are generally created after/before the body of a | |
3705 | topic. However, they are created right at cursor location if the | |
3706 | cursor is on a blank line, even if that breaks the current topic | |
3707 | body. This is intentional, to provide a simple means for | |
3708 | deliberately dividing topic bodies. | |
3709 | ||
3710 | - Double spacing of topic lists is preserved. Also, the first | |
3711 | level two topic is created double-spaced (and so would be | |
3712 | subsequent siblings, if that's left intact). Otherwise, | |
3713 | single-spacing is used. | |
3714 | ||
3715 | - Creation of sibling or nested topics is with respect to the topic | |
3716 | you're starting from, even when creating backwards. This way you | |
3717 | can easily create a sibling in front of the current topic without | |
a0776d6b | 3718 | having to go to its preceding sibling, and then open forward |
c567ac01 | 3719 | from there." |
1977b8f6 | 3720 | |
96b83743 | 3721 | (allout-beginning-of-current-line) |
2a1408fd DN |
3722 | (save-match-data |
3723 | (let* ((inhibit-field-text-motion t) | |
3724 | (depth (+ (allout-current-depth) relative-depth)) | |
3725 | (opening-on-blank (if (looking-at "^\$") | |
3726 | (not (setq before nil)))) | |
3727 | ;; bunch o vars set while computing ref-topic | |
3728 | opening-numbered | |
3729 | ref-depth | |
3730 | ref-bullet | |
3731 | (ref-topic (save-excursion | |
3732 | (cond ((< relative-depth 0) | |
3733 | (allout-ascend-to-depth depth)) | |
3734 | ((>= relative-depth 1) nil) | |
3735 | (t (allout-back-to-current-heading))) | |
3736 | (setq ref-depth allout-recent-depth) | |
3737 | (setq ref-bullet | |
3738 | (if (> allout-recent-prefix-end 1) | |
3739 | (allout-recent-bullet) | |
3740 | "")) | |
3741 | (setq opening-numbered | |
3742 | (save-excursion | |
3743 | (and allout-numbered-bullet | |
3744 | (or (<= relative-depth 0) | |
3745 | (allout-descend-to-depth depth)) | |
3746 | (if (allout-numbered-type-prefix) | |
3747 | allout-numbered-bullet)))) | |
3748 | (point))) | |
3749 | dbl-space | |
3750 | doing-beginning | |
3751 | start end) | |
3752 | ||
3753 | (if (not opening-on-blank) | |
1977b8f6 | 3754 | ; Positioning and vertical |
60c7bbd2 | 3755 | ; padding -- only if not |
1977b8f6 | 3756 | ; opening-on-blank: |
2a1408fd DN |
3757 | (progn |
3758 | (goto-char ref-topic) | |
3759 | (setq dbl-space ; Determine double space action: | |
3760 | (or (and (<= relative-depth 0) ; not descending; | |
3761 | (save-excursion | |
3762 | ;; at b-o-b or preceded by a blank line? | |
3763 | (or (> 0 (forward-line -1)) | |
3764 | (looking-at "^\\s-*$") | |
3765 | (bobp))) | |
3766 | (save-excursion | |
3767 | ;; succeeded by a blank line? | |
3768 | (allout-end-of-current-subtree) | |
3769 | (looking-at "\n\n"))) | |
3770 | (and (= ref-depth 1) | |
3771 | (or before | |
3772 | (= depth 1) | |
3773 | (save-excursion | |
3774 | ;; Don't already have following | |
3775 | ;; vertical padding: | |
3776 | (not (allout-pre-next-prefix))))))) | |
3777 | ||
3778 | ;; Position to prior heading, if inserting backwards, and not | |
3779 | ;; going outwards: | |
3780 | (if (and before (>= relative-depth 0)) | |
3781 | (progn (allout-back-to-current-heading) | |
3782 | (setq doing-beginning (bobp)) | |
3783 | (if (not (bobp)) | |
3784 | (allout-previous-heading))) | |
3785 | (if (and before (bobp)) | |
3786 | (open-line 1))) | |
3787 | ||
3788 | (if (<= relative-depth 0) | |
3789 | ;; Not going inwards, don't snug up: | |
3790 | (if doing-beginning | |
3791 | (if (not dbl-space) | |
3792 | (open-line 1) | |
3793 | (open-line 2)) | |
3794 | (if before | |
3795 | (progn (end-of-line) | |
3796 | (allout-pre-next-prefix) | |
3797 | (while (and (= ?\n (following-char)) | |
3798 | (save-excursion | |
3799 | (forward-char 1) | |
3800 | (allout-hidden-p))) | |
3801 | (forward-char 1)) | |
3802 | (if (not (looking-at "^$")) | |
3803 | (open-line 1))) | |
3804 | (allout-end-of-current-subtree) | |
3805 | (if (looking-at "\n\n") (forward-char 1)))) | |
8dd59f01 | 3806 | ;; Going inwards -- double-space if first offspring is |
2a1408fd DN |
3807 | ;; double-spaced, otherwise snug up. |
3808 | (allout-end-of-entry) | |
3809 | (if (eobp) | |
3810 | (newline 1) | |
3811 | (line-move 1)) | |
3812 | (allout-beginning-of-current-line) | |
3813 | (backward-char 1) | |
3814 | (if (bolp) | |
3815 | ;; Blank lines between current header body and next | |
8dd59f01 | 3816 | ;; header -- get to last substantive (non-white-space) |
2a1408fd DN |
3817 | ;; line in body: |
3818 | (progn (setq dbl-space t) | |
3819 | (re-search-backward "[^ \t\n]" nil t))) | |
3820 | (if (looking-at "\n\n") | |
3821 | (setq dbl-space t)) | |
3822 | (if (save-excursion | |
3823 | (allout-next-heading) | |
3824 | (when (> allout-recent-depth ref-depth) | |
3825 | ;; This is an offspring. | |
3826 | (forward-line -1) | |
3827 | (looking-at "^\\s-*$"))) | |
3828 | (progn (forward-line 1) | |
96b83743 | 3829 | (open-line 1) |
2a1408fd DN |
3830 | (forward-line 1))) |
3831 | (allout-end-of-current-line)) | |
3832 | ||
3833 | ;;(if doing-beginning (goto-char doing-beginning)) | |
3834 | (if (not (bobp)) | |
3835 | ;; We insert a newline char rather than using open-line to | |
0b381c7e | 3836 | ;; avoid rear-stickiness inheritance of read-only property. |
2a1408fd DN |
3837 | (progn (if (and (not (> depth ref-depth)) |
3838 | (not before)) | |
3839 | (open-line 1) | |
3840 | (if (and (not dbl-space) (> depth ref-depth)) | |
3841 | (newline 1) | |
3842 | (if dbl-space | |
3843 | (open-line 1) | |
3844 | (if (not before) | |
3845 | (newline 1))))) | |
3846 | (if (and dbl-space (not (> relative-depth 0))) | |
3847 | (newline 1)) | |
3848 | (if (and (not (eobp)) | |
3849 | (or (not (bolp)) | |
3850 | (and (not (bobp)) | |
c7015153 | 3851 | ;; bolp doesn't detect concealed |
2a1408fd DN |
3852 | ;; trailing newlines, compensate: |
3853 | (save-excursion | |
3854 | (forward-char -1) | |
3855 | (allout-hidden-p))))) | |
3856 | (forward-char 1)))) | |
3857 | )) | |
3858 | (setq start (point)) | |
3859 | (insert (concat (allout-make-topic-prefix opening-numbered t depth) | |
3860 | " ")) | |
3861 | (setq end (1+ (point))) | |
3862 | ||
3863 | (allout-rebullet-heading (and offer-recent-bullet ref-bullet) | |
3864 | depth nil nil t) | |
3865 | (if (> relative-depth 0) | |
3866 | (save-excursion (goto-char ref-topic) | |
3867 | (allout-show-children))) | |
3868 | (end-of-line) | |
48bd8440 | 3869 | |
7b97c764 | 3870 | (run-hook-with-args 'allout-structure-added-functions start end) |
2a1408fd | 3871 | ) |
1977b8f6 RS |
3872 | ) |
3873 | ) | |
fd5359c6 MR |
3874 | ;;;_ > allout-open-subtopic (arg) |
3875 | (defun allout-open-subtopic (arg) | |
c567ac01 RS |
3876 | "Open new topic header at deeper level than the current one. |
3877 | ||
20db1522 | 3878 | Negative universal ARG means to open deeper, but place the new topic |
c567ac01 | 3879 | prior to the current one." |
1977b8f6 | 3880 | (interactive "p") |
d82979ea | 3881 | (allout-open-topic 1 (> 0 arg) (< 1 arg))) |
fd5359c6 MR |
3882 | ;;;_ > allout-open-sibtopic (arg) |
3883 | (defun allout-open-sibtopic (arg) | |
19b84ba3 RS |
3884 | "Open new topic header at same level as the current one. |
3885 | ||
20db1522 | 3886 | Positive universal ARG means to use the bullet of the prior sibling. |
9179616f | 3887 | |
20db1522 | 3888 | Negative universal ARG means to place the new topic prior to the current |
c567ac01 | 3889 | one." |
1977b8f6 | 3890 | (interactive "p") |
d82979ea | 3891 | (allout-open-topic 0 (> 0 arg) (not (= 1 arg)))) |
fd5359c6 MR |
3892 | ;;;_ > allout-open-supertopic (arg) |
3893 | (defun allout-open-supertopic (arg) | |
c567ac01 | 3894 | "Open new topic header at shallower level than the current one. |
19b84ba3 | 3895 | |
20db1522 | 3896 | Negative universal ARG means to open shallower, but place the new |
c567ac01 | 3897 | topic prior to the current one." |
1977b8f6 RS |
3898 | |
3899 | (interactive "p") | |
d82979ea | 3900 | (allout-open-topic -1 (> 0 arg) (< 1 arg))) |
c567ac01 RS |
3901 | |
3902 | ;;;_ - Outline Alteration | |
3903 | ;;;_ : Topic Modification | |
fd5359c6 MR |
3904 | ;;;_ = allout-former-auto-filler |
3905 | (defvar allout-former-auto-filler nil | |
2265e017 | 3906 | "Name of modal fill function being wrapped by `allout-auto-fill'.") |
fd5359c6 MR |
3907 | ;;;_ > allout-auto-fill () |
3908 | (defun allout-auto-fill () | |
aad94676 | 3909 | "`allout-mode' autofill function. |
19b84ba3 RS |
3910 | |
3911 | Maintains outline hanging topic indentation if | |
fd5359c6 | 3912 | `allout-use-hanging-indents' is set." |
01fc9422 | 3913 | |
381987c3 KM |
3914 | (when (and (not allout-inhibit-auto-fill) |
3915 | (or (not allout-inhibit-auto-fill-on-headline) | |
3916 | (not (allout-on-current-heading-p)))) | |
01fc9422 EZ |
3917 | (let ((fill-prefix (if allout-use-hanging-indents |
3918 | ;; Check for topic header indentation: | |
2a1408fd DN |
3919 | (save-match-data |
3920 | (save-excursion | |
3921 | (beginning-of-line) | |
3922 | (if (looking-at allout-regexp) | |
3923 | ;; ... construct indentation to account for | |
3924 | ;; length of topic prefix: | |
3925 | (make-string (progn (allout-end-of-prefix) | |
3926 | (current-column)) | |
3927 | ?\ )))))) | |
7927f48d KM |
3928 | (use-auto-fill-function |
3929 | (if (and (eq allout-outside-normal-auto-fill-function | |
3930 | 'allout-auto-fill) | |
3931 | (eq auto-fill-function 'allout-auto-fill)) | |
3932 | 'do-auto-fill | |
3933 | (or allout-outside-normal-auto-fill-function | |
3934 | auto-fill-function)))) | |
01fc9422 EZ |
3935 | (if (or allout-former-auto-filler allout-use-hanging-indents) |
3936 | (funcall use-auto-fill-function))))) | |
fd5359c6 MR |
3937 | ;;;_ > allout-reindent-body (old-depth new-depth &optional number) |
3938 | (defun allout-reindent-body (old-depth new-depth &optional number) | |
e126900f | 3939 | "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH. |
c567ac01 RS |
3940 | |
3941 | Optional arg NUMBER indicates numbering is being added, and it must | |
a0776d6b | 3942 | be accommodated. |
c567ac01 RS |
3943 | |
3944 | Note that refill of indented paragraphs is not done." | |
1977b8f6 RS |
3945 | |
3946 | (save-excursion | |
fd5359c6 | 3947 | (allout-end-of-prefix) |
c567ac01 RS |
3948 | (let* ((new-margin (current-column)) |
3949 | excess old-indent-begin old-indent-end | |
c567ac01 RS |
3950 | ;; We want the column where the header-prefix text started |
3951 | ;; *before* the prefix was changed, so we infer it relative | |
3952 | ;; to the new margin and the shift in depth: | |
3953 | (old-margin (+ old-depth (- new-margin new-depth)))) | |
353e2ef2 | 3954 | |
c567ac01 | 3955 | ;; Process lines up to (but excluding) next topic header: |
fd5359c6 | 3956 | (allout-unprotected |
c567ac01 RS |
3957 | (save-match-data |
3958 | (while | |
96b83743 | 3959 | (and (re-search-forward "\n\\(\\s-*\\)" |
c567ac01 RS |
3960 | nil |
3961 | t) | |
3962 | ;; Register the indent data, before we reset the | |
353e2ef2 | 3963 | ;; match data with a subsequent `looking-at': |
c567ac01 RS |
3964 | (setq old-indent-begin (match-beginning 1) |
3965 | old-indent-end (match-end 1)) | |
fd5359c6 | 3966 | (not (looking-at allout-regexp))) |
d82979ea EZ |
3967 | (if (> 0 (setq excess (- (- old-indent-end old-indent-begin) |
3968 | old-margin))) | |
60c7bbd2 | 3969 | ;; Text starts left of old margin -- don't adjust: |
c567ac01 | 3970 | nil |
ea18b2b1 | 3971 | ;; Text was hanging at or right of old left margin -- |
c567ac01 RS |
3972 | ;; reindent it, preserving its existing indentation |
3973 | ;; beyond the old margin: | |
3974 | (delete-region old-indent-begin old-indent-end) | |
d82979ea | 3975 | (indent-to (+ new-margin excess (current-column)))))))))) |
fd5359c6 MR |
3976 | ;;;_ > allout-rebullet-current-heading (arg) |
3977 | (defun allout-rebullet-current-heading (arg) | |
9179616f DL |
3978 | "Solicit new bullet for current visible heading." |
3979 | (interactive "p") | |
3980 | (let ((initial-col (current-column)) | |
fd5359c6 | 3981 | (on-bullet (eq (point)(allout-current-bullet-pos))) |
d8350998 | 3982 | from to |
9179616f DL |
3983 | (backwards (if (< arg 0) |
3984 | (setq arg (* arg -1))))) | |
3985 | (while (> arg 0) | |
fd5359c6 MR |
3986 | (save-excursion (allout-back-to-current-heading) |
3987 | (allout-end-of-prefix) | |
d8350998 CY |
3988 | (setq from allout-recent-prefix-beginning |
3989 | to allout-recent-prefix-end) | |
b6a5875b | 3990 | (allout-rebullet-heading t ;;; instead |
9179616f DL |
3991 | nil ;;; depth |
3992 | nil ;;; number-control | |
3993 | nil ;;; index | |
d8350998 | 3994 | t) ;;; do-successors |
7b97c764 | 3995 | (run-hook-with-args 'allout-exposure-change-functions |
d8350998 | 3996 | from to t)) |
9179616f DL |
3997 | (setq arg (1- arg)) |
3998 | (if (<= arg 0) | |
3999 | nil | |
4000 | (setq initial-col nil) ; Override positioning back to init col | |
4001 | (if (not backwards) | |
fd5359c6 | 4002 | (allout-next-visible-heading 1) |
d8350998 | 4003 | (allout-goto-prefix-doublechecked) |
fd5359c6 | 4004 | (allout-next-visible-heading -1)))) |
9179616f | 4005 | (message "Done.") |
fd5359c6 | 4006 | (cond (on-bullet (goto-char (allout-current-bullet-pos))) |
9179616f | 4007 | (initial-col (move-to-column initial-col))))) |
b6a5875b KM |
4008 | ;;;_ > allout-rebullet-heading (&optional instead ...) |
4009 | (defun allout-rebullet-heading (&optional instead | |
1977b8f6 RS |
4010 | new-depth |
4011 | number-control | |
4012 | index | |
4013 | do-successors) | |
4014 | ||
c567ac01 | 4015 | "Adjust bullet of current topic prefix. |
1977b8f6 | 4016 | |
d82979ea EZ |
4017 | All args are optional. |
4018 | ||
b6a5875b KM |
4019 | If INSTEAD is: |
4020 | - nil, then the bullet char for the context is used, per distinction or depth | |
20db1522 | 4021 | - a (numeric) character, then character's string representation is used |
2dab465b | 4022 | - a string, then the user is asked for bullet with the first char as default |
b6a5875b | 4023 | - anything else, the user is solicited with bullet char per context as default |
1977b8f6 | 4024 | |
d82979ea | 4025 | Second arg DEPTH forces the topic prefix to that depth, regardless |
9179616f | 4026 | of the topic's current depth. |
1977b8f6 | 4027 | |
c567ac01 | 4028 | Third arg NUMBER-CONTROL can force the prefix to or away from |
fd5359c6 | 4029 | numbered form. It has effect only if `allout-numbered-bullet' is |
c567ac01 RS |
4030 | non-nil and soliciting was not explicitly invoked (via first arg). |
4031 | Its effect, numbering or denumbering, then depends on the setting | |
75bcb912 | 4032 | of the fourth arg, INDEX. |
1977b8f6 | 4033 | |
75bcb912 | 4034 | If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the |
c567ac01 RS |
4035 | prefix of the topic is forced to be non-numbered. Null index and |
4036 | non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and | |
4037 | non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil | |
4038 | INDEX is a number, then that number is used for the numbered | |
4039 | prefix. Non-nil and non-number means that the index for the | |
d82979ea | 4040 | numbered prefix will be derived by allout-make-topic-prefix. |
1977b8f6 | 4041 | |
c567ac01 RS |
4042 | Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding |
4043 | siblings. | |
1977b8f6 | 4044 | |
fd5359c6 MR |
4045 | Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes', |
4046 | and `allout-numbered-bullet', which all affect the behavior of | |
c567ac01 | 4047 | this function." |
1977b8f6 | 4048 | |
fd5359c6 | 4049 | (let* ((current-depth (allout-depth)) |
1977b8f6 | 4050 | (new-depth (or new-depth current-depth)) |
fd5359c6 MR |
4051 | (mb allout-recent-prefix-beginning) |
4052 | (me allout-recent-prefix-end) | |
d8350998 | 4053 | (current-bullet (buffer-substring-no-properties (- me 1) me)) |
ede4ac6a | 4054 | (has-annotation (get-text-property mb 'allout-was-hidden)) |
fd5359c6 | 4055 | (new-prefix (allout-make-topic-prefix current-bullet |
1977b8f6 RS |
4056 | nil |
4057 | new-depth | |
b6a5875b | 4058 | instead |
1977b8f6 RS |
4059 | number-control |
4060 | index))) | |
4061 | ||
20db1522 | 4062 | ;; Is new one identical to old? |
1977b8f6 RS |
4063 | (if (and (= current-depth new-depth) |
4064 | (string= current-bullet | |
4065 | (substring new-prefix (1- (length new-prefix))))) | |
c567ac01 | 4066 | ;; Nothing to do: |
1977b8f6 RS |
4067 | t |
4068 | ||
4069 | ;; New prefix probably different from old: | |
c567ac01 | 4070 | ; get rid of old one: |
fd5359c6 | 4071 | (allout-unprotected (delete-region mb me)) |
1977b8f6 | 4072 | (goto-char mb) |
c567ac01 RS |
4073 | ; Dispense with number if |
4074 | ; numbered-bullet prefix: | |
2a1408fd DN |
4075 | (save-match-data |
4076 | (if (and allout-numbered-bullet | |
4077 | (string= allout-numbered-bullet current-bullet) | |
4078 | (looking-at "[0-9]+")) | |
4079 | (allout-unprotected | |
4080 | (delete-region (match-beginning 0)(match-end 0))))) | |
1977b8f6 | 4081 | |
ede4ac6a KS |
4082 | ;; convey 'allout-was-hidden annotation, if original had it: |
4083 | (if has-annotation | |
4084 | (put-text-property 0 (length new-prefix) 'allout-was-hidden t | |
4085 | new-prefix)) | |
4086 | ||
c567ac01 | 4087 | ; Put in new prefix: |
fd5359c6 | 4088 | (allout-unprotected (insert new-prefix)) |
1977b8f6 | 4089 | |
d82979ea | 4090 | ;; Reindent the body if elected, margin changed, and not encrypted body: |
fd5359c6 | 4091 | (if (and allout-reindent-bodies |
d82979ea EZ |
4092 | (not (= new-depth current-depth)) |
4093 | (not (allout-encrypted-topic-p))) | |
fd5359c6 | 4094 | (allout-reindent-body current-depth new-depth)) |
1977b8f6 | 4095 | |
7b97c764 | 4096 | (run-hook-with-args 'allout-exposure-change-functions mb me nil) |
e47ca23b | 4097 | |
c567ac01 RS |
4098 | ;; Recursively rectify successive siblings of orig topic if |
4099 | ;; caller elected for it: | |
4100 | (if do-successors | |
4101 | (save-excursion | |
fd5359c6 | 4102 | (while (allout-next-sibling new-depth nil) |
c567ac01 RS |
4103 | (setq index |
4104 | (cond ((numberp index) (1+ index)) | |
fd5359c6 MR |
4105 | ((not number-control) (allout-sibling-index)))) |
4106 | (if (allout-numbered-type-prefix) | |
b6a5875b | 4107 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4108 | new-depth ;;; new-depth |
4109 | number-control;;; number-control | |
4110 | index ;;; index | |
4111 | nil))))) ;;;(dont!)do-successors | |
4112 | ) ; (if (and (= current-depth new-depth)...)) | |
fd5359c6 | 4113 | ) ; let* ((current-depth (allout-depth))...) |
c567ac01 | 4114 | ) ; defun |
fd5359c6 | 4115 | ;;;_ > allout-rebullet-topic (arg) |
d8350998 | 4116 | (defun allout-rebullet-topic (arg &optional sans-offspring) |
d82979ea | 4117 | "Rebullet the visible topic containing point and all contained subtopics. |
19b84ba3 | 4118 | |
c567ac01 | 4119 | Descends into invisible as well as visible topics, however. |
1977b8f6 | 4120 | |
75bcb912 | 4121 | When optional SANS-OFFSPRING is non-nil, subtopics are not |
c07583cd | 4122 | shifted. (Shifting a topic outwards without shifting its |
d8350998 CY |
4123 | offspring is disallowed, since this would create a \"containment |
4124 | discontinuity\", where the depth difference between a topic and | |
4125 | its immediate offspring is greater than one.) | |
4126 | ||
c567ac01 | 4127 | With repeat count, shift topic depth by that amount." |
1977b8f6 | 4128 | (interactive "P") |
96b83743 | 4129 | (let ((start-col (current-column))) |
1977b8f6 RS |
4130 | (save-excursion |
4131 | ;; Normalize arg: | |
4132 | (cond ((null arg) (setq arg 0)) | |
4133 | ((listp arg) (setq arg (car arg)))) | |
4134 | ;; Fill the user in, in case we're shifting a big topic: | |
4135 | (if (not (zerop arg)) (message "Shifting...")) | |
fd5359c6 | 4136 | (allout-back-to-current-heading) |
d8350998 | 4137 | (if (<= (+ allout-recent-depth arg) 0) |
1977b8f6 | 4138 | (error "Attempt to shift topic below level 1")) |
d8350998 | 4139 | (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring) |
1977b8f6 | 4140 | (if (not (zerop arg)) (message "Shifting... done."))) |
c567ac01 | 4141 | (move-to-column (max 0 (+ start-col arg))))) |
d8350998 | 4142 | ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...) |
fd5359c6 | 4143 | (defun allout-rebullet-topic-grunt (&optional relative-depth |
1977b8f6 RS |
4144 | starting-depth |
4145 | starting-point | |
4146 | index | |
d8350998 CY |
4147 | do-successors |
4148 | sans-offspring) | |
d82979ea EZ |
4149 | "Like `allout-rebullet-topic', but on nearest containing topic |
4150 | \(visible or not). | |
1977b8f6 | 4151 | |
d82979ea | 4152 | See `allout-rebullet-heading' for rebulleting behavior. |
1977b8f6 | 4153 | |
d82979ea | 4154 | All arguments are optional. |
1977b8f6 | 4155 | |
d82979ea EZ |
4156 | First arg RELATIVE-DEPTH means to shift the depth of the entire |
4157 | topic that amount. | |
e126900f | 4158 | |
d8350998 CY |
4159 | Several subsequent args are for internal recursive use by the function |
4160 | itself: STARTING-DEPTH, STARTING-POINT, and INDEX. | |
4161 | ||
4162 | Finally, if optional SANS-OFFSPRING is non-nil then the offspring | |
c07583cd | 4163 | are not shifted. (Shifting a topic outwards without shifting |
d8350998 CY |
4164 | its offspring is disallowed, since this would create a |
4165 | \"containment discontinuity\", where the depth difference between | |
75bcb912 | 4166 | a topic and its immediate offspring is greater than one.)" |
d8350998 CY |
4167 | |
4168 | ;; XXX the recursion here is peculiar, and in general the routine may | |
4169 | ;; need simplification with refactoring. | |
4170 | ||
4171 | (if (and sans-offspring | |
4172 | relative-depth | |
4173 | (< relative-depth 0)) | |
4174 | (error (concat "Attempt to shift topic outwards without offspring," | |
4175 | " would cause containment discontinuity."))) | |
1977b8f6 RS |
4176 | |
4177 | (let* ((relative-depth (or relative-depth 0)) | |
fd5359c6 | 4178 | (new-depth (allout-depth)) |
1977b8f6 RS |
4179 | (starting-depth (or starting-depth new-depth)) |
4180 | (on-starting-call (null starting-point)) | |
4181 | (index (or index | |
4182 | ;; Leave index null on starting call, so rebullet-heading | |
4183 | ;; calculates it at what might be new depth: | |
4184 | (and (or (zerop relative-depth) | |
4185 | (not on-starting-call)) | |
fd5359c6 | 4186 | (allout-sibling-index)))) |
d8350998 | 4187 | (starting-index index) |
1977b8f6 | 4188 | (moving-outwards (< 0 relative-depth)) |
d8350998 CY |
4189 | (starting-point (or starting-point (point))) |
4190 | (local-point (point))) | |
1977b8f6 RS |
4191 | |
4192 | ;; Sanity check for excessive promotion done only on starting call: | |
4193 | (and on-starting-call | |
4194 | moving-outwards | |
4195 | (> 0 (+ starting-depth relative-depth)) | |
d8350998 | 4196 | (error "Attempt to shift topic out beyond level 1")) |
1977b8f6 RS |
4197 | |
4198 | (cond ((= starting-depth new-depth) | |
d8350998 CY |
4199 | ;; We're at depth to work on this one. |
4200 | ||
4201 | ;; When shifting out we work on the children before working on | |
4202 | ;; the parent to avoid interim `allout-aberrant-container-p' | |
4203 | ;; aberrancy, and vice-versa when shifting in: | |
4204 | (if (>= relative-depth 0) | |
4205 | (allout-rebullet-heading nil | |
4206 | (+ starting-depth relative-depth) | |
4207 | nil ;;; number | |
4208 | index | |
4209 | nil)) ;;; do-successors | |
4210 | (when (not sans-offspring) | |
4211 | ;; ... and work on subsequent ones which are at greater depth: | |
4212 | (setq index 0) | |
4213 | (allout-next-heading) | |
4214 | (while (and (not (eobp)) | |
4215 | (< starting-depth (allout-depth))) | |
4216 | (setq index (1+ index)) | |
4217 | (allout-rebullet-topic-grunt relative-depth | |
4218 | (1+ starting-depth) | |
4219 | starting-point | |
4220 | index))) | |
4221 | (when (< relative-depth 0) | |
4222 | (save-excursion | |
4223 | (goto-char local-point) | |
b6a5875b | 4224 | (allout-rebullet-heading nil ;;; instead |
d8350998 CY |
4225 | (+ starting-depth relative-depth) |
4226 | nil ;;; number | |
4227 | starting-index | |
4228 | nil)))) ;;; do-successors | |
1977b8f6 RS |
4229 | |
4230 | ((< starting-depth new-depth) | |
60c7bbd2 | 4231 | ;; Rare case -- subtopic more than one level deeper than parent. |
1977b8f6 | 4232 | ;; Treat this one at an even deeper level: |
d8350998 CY |
4233 | (allout-rebullet-topic-grunt relative-depth |
4234 | new-depth | |
4235 | starting-point | |
4236 | index | |
4237 | sans-offspring))) | |
1977b8f6 RS |
4238 | |
4239 | (if on-starting-call | |
4240 | (progn | |
4241 | ;; Rectify numbering of former siblings of the adjusted topic, | |
4242 | ;; if topic has changed depth | |
4243 | (if (or do-successors | |
4244 | (and (not (zerop relative-depth)) | |
d8350998 CY |
4245 | (or (= allout-recent-depth starting-depth) |
4246 | (= allout-recent-depth (+ starting-depth | |
1977b8f6 | 4247 | relative-depth))))) |
fd5359c6 | 4248 | (allout-rebullet-heading nil nil nil nil t)) |
1977b8f6 RS |
4249 | ;; Now rectify numbering of new siblings of the adjusted topic, |
4250 | ;; if depth has been changed: | |
4251 | (progn (goto-char starting-point) | |
4252 | (if (not (zerop relative-depth)) | |
fd5359c6 | 4253 | (allout-rebullet-heading nil nil nil nil t))))) |
1977b8f6 RS |
4254 | ) |
4255 | ) | |
fd5359c6 MR |
4256 | ;;;_ > allout-renumber-to-depth (&optional depth) |
4257 | (defun allout-renumber-to-depth (&optional depth) | |
19b84ba3 RS |
4258 | "Renumber siblings at current depth. |
4259 | ||
4260 | Affects superior topics if optional arg DEPTH is less than current depth. | |
c567ac01 RS |
4261 | |
4262 | Returns final depth." | |
4263 | ||
4264 | ;; Proceed by level, processing subsequent siblings on each, | |
4265 | ;; ascending until we get shallower than the start depth: | |
4266 | ||
fd5359c6 | 4267 | (let ((ascender (allout-depth)) |
9179616f | 4268 | was-eobp) |
c567ac01 | 4269 | (while (and (not (eobp)) |
fd5359c6 | 4270 | (allout-depth) |
d8350998 | 4271 | (>= allout-recent-depth depth) |
c567ac01 RS |
4272 | (>= ascender depth)) |
4273 | ; Skip over all topics at | |
4274 | ; lesser depths, which can not | |
4275 | ; have been disturbed: | |
9179616f | 4276 | (while (and (not (setq was-eobp (eobp))) |
d8350998 | 4277 | (> allout-recent-depth ascender)) |
fd5359c6 | 4278 | (allout-next-heading)) |
c567ac01 | 4279 | ; Prime ascender for ascension: |
d8350998 CY |
4280 | (setq ascender (1- allout-recent-depth)) |
4281 | (if (>= allout-recent-depth depth) | |
b6a5875b | 4282 | (allout-rebullet-heading nil ;;; instead |
c567ac01 RS |
4283 | nil ;;; depth |
4284 | nil ;;; number-control | |
4285 | nil ;;; index | |
9179616f DL |
4286 | t)) ;;; do-successors |
4287 | (if was-eobp (goto-char (point-max))))) | |
d8350998 | 4288 | allout-recent-depth) |
fd5359c6 MR |
4289 | ;;;_ > allout-number-siblings (&optional denumber) |
4290 | (defun allout-number-siblings (&optional denumber) | |
c567ac01 | 4291 | "Assign numbered topic prefix to this topic and its siblings. |
1977b8f6 | 4292 | |
60c7bbd2 | 4293 | With universal argument, denumber -- assign default bullet to this |
c567ac01 | 4294 | topic and its siblings. |
1977b8f6 | 4295 | |
c567ac01 RS |
4296 | With repeated universal argument (`^U^U'), solicit bullet for each |
4297 | rebulleting each topic at this level." | |
1977b8f6 RS |
4298 | |
4299 | (interactive "P") | |
4300 | ||
4301 | (save-excursion | |
fd5359c6 MR |
4302 | (allout-back-to-current-heading) |
4303 | (allout-beginning-of-level) | |
d8350998 | 4304 | (let ((depth allout-recent-depth) |
c567ac01 | 4305 | (index (if (not denumber) 1)) |
1977b8f6 RS |
4306 | (use-bullet (equal '(16) denumber)) |
4307 | (more t)) | |
4308 | (while more | |
b6a5875b | 4309 | (allout-rebullet-heading use-bullet ;;; instead |
c567ac01 | 4310 | depth ;;; depth |
1977b8f6 RS |
4311 | t ;;; number-control |
4312 | index ;;; index | |
4313 | nil) ;;; do-successors | |
4314 | (if index (setq index (1+ index))) | |
fd5359c6 MR |
4315 | (setq more (allout-next-sibling depth nil)))))) |
4316 | ;;;_ > allout-shift-in (arg) | |
4317 | (defun allout-shift-in (arg) | |
d8350998 CY |
4318 | "Increase depth of current heading and any items collapsed within it. |
4319 | ||
4320 | With a negative argument, the item is shifted out using | |
4321 | `allout-shift-out', instead. | |
4322 | ||
4323 | With an argument greater than one, shift-in the item but not its | |
4324 | offspring, making the item into a sibling of its former children, | |
97610156 | 4325 | and a child of sibling that formerly preceded it. |
d8350998 CY |
4326 | |
4327 | You are not allowed to shift the first offspring of a topic | |
4328 | inwards, because that would yield a \"containment | |
4329 | discontinuity\", where the depth difference between a topic and | |
4330 | its immediate offspring is greater than one. The first topic in | |
4331 | the file can be adjusted to any positive depth, however." | |
d82979ea | 4332 | |
1977b8f6 | 4333 | (interactive "p") |
d8350998 CY |
4334 | (if (< arg 0) |
4335 | (allout-shift-out (* arg -1)) | |
4336 | ;; refuse to create a containment discontinuity: | |
4337 | (save-excursion | |
4338 | (allout-back-to-current-heading) | |
4339 | (if (not (bobp)) | |
4340 | (let* ((current-depth allout-recent-depth) | |
4341 | (start-point (point)) | |
4342 | (predecessor-depth (progn | |
4343 | (forward-char -1) | |
4344 | (allout-goto-prefix-doublechecked) | |
4345 | (if (< (point) start-point) | |
4346 | allout-recent-depth | |
4347 | 0)))) | |
4348 | (if (and (> predecessor-depth 0) | |
4349 | (> (1+ current-depth) | |
4350 | (1+ predecessor-depth))) | |
4351 | (error (concat "Disallowed shift deeper than" | |
498a6493 CY |
4352 | " containing topic's children.")) |
4353 | (allout-back-to-current-heading) | |
4354 | (if (< allout-recent-depth (1+ current-depth)) | |
4355 | (allout-show-children)))))) | |
d8350998 CY |
4356 | (let ((where (point))) |
4357 | (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring)) | |
7b97c764 | 4358 | (run-hook-with-args 'allout-structure-shifted-functions arg where)))) |
fd5359c6 MR |
4359 | ;;;_ > allout-shift-out (arg) |
4360 | (defun allout-shift-out (arg) | |
d82979ea | 4361 | "Decrease depth of current heading and any topics collapsed within it. |
d8350998 CY |
4362 | This will make the item a sibling of its former container. |
4363 | ||
4364 | With a negative argument, the item is shifted in using | |
4365 | `allout-shift-in', instead. | |
4366 | ||
4367 | With an argument greater than one, shift-out the item's offspring | |
4368 | but not the item itself, making the former children siblings of | |
4369 | the item. | |
d82979ea | 4370 | |
d8350998 CY |
4371 | With an argument greater than 1, the item's offspring are shifted |
4372 | out without shifting the item. This will make the immediate | |
4373 | subtopics into siblings of the item." | |
1977b8f6 | 4374 | (interactive "p") |
d8350998 CY |
4375 | (if (< arg 0) |
4376 | (allout-shift-in (* arg -1)) | |
4377 | ;; Get proper exposure in this area: | |
4378 | (save-excursion (if (allout-ascend) | |
4379 | (allout-show-children))) | |
4380 | ;; Show collapsed children if there's a successor which will become | |
4381 | ;; their sibling: | |
4382 | (if (and (allout-current-topic-collapsed-p) | |
4383 | (save-excursion (allout-next-sibling))) | |
4384 | (allout-show-children)) | |
4385 | (let ((where (and (allout-depth) allout-recent-prefix-beginning))) | |
4386 | (save-excursion | |
4387 | (if (> arg 1) | |
4388 | ;; Shift the offspring but not the topic: | |
4389 | (let ((children-chart (allout-chart-subtree 1))) | |
4390 | (if (listp (car children-chart)) | |
4391 | ;; whoops: | |
4392 | (setq children-chart (allout-flatten children-chart))) | |
4393 | (save-excursion | |
4394 | (dolist (child-point children-chart) | |
4395 | (goto-char child-point) | |
4396 | (allout-shift-out 1)))) | |
4397 | (allout-rebullet-topic (* arg -1)))) | |
7b97c764 | 4398 | (run-hook-with-args 'allout-structure-shifted-functions (* arg -1) where)))) |
c567ac01 | 4399 | ;;;_ : Surgery (kill-ring) functions with special provisions for outlines: |
fd5359c6 MR |
4400 | ;;;_ > allout-kill-line (&optional arg) |
4401 | (defun allout-kill-line (&optional arg) | |
c567ac01 | 4402 | "Kill line, adjusting subsequent lines suitably for outline mode." |
1977b8f6 RS |
4403 | |
4404 | (interactive "*P") | |
d82979ea | 4405 | |
96b83743 EZ |
4406 | (if (or (not (allout-mode-p)) |
4407 | (not (bolp)) | |
2a1408fd | 4408 | (not (save-match-data (looking-at allout-regexp)))) |
4034b0e2 | 4409 | ;; Just do a regular kill: |
96b83743 EZ |
4410 | (kill-line arg) |
4411 | ;; Ah, have to watch out for adjustments: | |
4412 | (let* ((beg (point)) | |
d8350998 | 4413 | end |
96b83743 EZ |
4414 | (beg-hidden (allout-hidden-p)) |
4415 | (end-hidden (save-excursion (allout-end-of-current-line) | |
d8350998 | 4416 | (setq end (point)) |
96b83743 | 4417 | (allout-hidden-p))) |
d8350998 | 4418 | (depth (allout-depth))) |
96b83743 | 4419 | |
d8350998 | 4420 | (allout-annotate-hidden beg end) |
4ec28e14 KM |
4421 | (unwind-protect |
4422 | (if (and (not beg-hidden) (not end-hidden)) | |
4423 | (allout-unprotected (kill-line arg)) | |
4424 | (kill-line arg)) | |
11c46e15 | 4425 | (run-hooks 'allout-after-copy-or-kill-hook) |
4ec28e14 KM |
4426 | (allout-deannotate-hidden beg end) |
4427 | ||
4428 | (if allout-numbered-bullet | |
4429 | (save-excursion ; Renumber subsequent topics if needed: | |
4430 | (if (not (save-match-data (looking-at allout-regexp))) | |
4431 | (allout-next-heading)) | |
4432 | (allout-renumber-to-depth depth))) | |
7b97c764 | 4433 | (run-hook-with-args 'allout-structure-deleted-functions depth (point)))))) |
1b4d97b2 CY |
4434 | ;;;_ > allout-copy-line-as-kill () |
4435 | (defun allout-copy-line-as-kill () | |
20db1522 | 4436 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4437 | (interactive) |
4438 | (let ((buffer-read-only t)) | |
4439 | (condition-case nil | |
4440 | (allout-kill-line) | |
4441 | (buffer-read-only nil)))) | |
fd5359c6 MR |
4442 | ;;;_ > allout-kill-topic () |
4443 | (defun allout-kill-topic () | |
c567ac01 RS |
4444 | "Kill topic together with subtopics. |
4445 | ||
96b83743 EZ |
4446 | Trailing whitespace is killed with a topic if that whitespace: |
4447 | ||
4448 | - would separate the topic from a subsequent sibling | |
4449 | - would separate the topic from the end of buffer | |
4450 | - would not be added to whitespace already separating the topic from the | |
4451 | previous one. | |
4452 | ||
d8350998 | 4453 | Topic exposure is marked with text-properties, to be used by |
75bcb912 | 4454 | `allout-yank-processing' for exposure recovery." |
1977b8f6 RS |
4455 | |
4456 | (interactive) | |
0458fa80 | 4457 | (let* ((inhibit-field-text-motion t) |
96b83743 | 4458 | (beg (prog1 (allout-back-to-current-heading) (beginning-of-line))) |
ede4ac6a | 4459 | end |
d8350998 | 4460 | (depth allout-recent-depth)) |
fd5359c6 | 4461 | (allout-end-of-current-subtree) |
96b83743 EZ |
4462 | (if (and (/= (current-column) 0) (not (eobp))) |
4463 | (forward-char 1)) | |
1977b8f6 | 4464 | (if (not (eobp)) |
2a1408fd | 4465 | (if (and (save-match-data (looking-at "\n")) |
96b83743 EZ |
4466 | (or (save-excursion |
4467 | (or (not (allout-next-heading)) | |
d8350998 | 4468 | (= depth allout-recent-depth))) |
96b83743 EZ |
4469 | (and (> (- beg (point-min)) 3) |
4470 | (string= (buffer-substring (- beg 2) beg) "\n\n")))) | |
c567ac01 | 4471 | (forward-char 1))) |
353e2ef2 | 4472 | |
ede4ac6a | 4473 | (allout-annotate-hidden beg (setq end (point))) |
4ec28e14 | 4474 | (unwind-protect ; for possible barf-if-buffer-read-only. |
ede4ac6a | 4475 | (allout-unprotected (kill-region beg end)) |
4ec28e14 | 4476 | (allout-deannotate-hidden beg end) |
11c46e15 | 4477 | (run-hooks 'allout-after-copy-or-kill-hook) |
d8350998 | 4478 | |
4ec28e14 KM |
4479 | (save-excursion |
4480 | (allout-renumber-to-depth depth)) | |
7b97c764 | 4481 | (run-hook-with-args 'allout-structure-deleted-functions depth (point))))) |
1b4d97b2 CY |
4482 | ;;;_ > allout-copy-topic-as-kill () |
4483 | (defun allout-copy-topic-as-kill () | |
75bcb912 | 4484 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4485 | (interactive) |
4486 | (let ((buffer-read-only t)) | |
4487 | (condition-case nil | |
4488 | (allout-kill-topic) | |
4489 | (buffer-read-only (message "Topic copied..."))))) | |
d8350998 CY |
4490 | ;;;_ > allout-annotate-hidden (begin end) |
4491 | (defun allout-annotate-hidden (begin end) | |
4492 | "Qualify text with properties to indicate exposure status." | |
4493 | ||
1b4d97b2 CY |
4494 | (let ((was-modified (buffer-modified-p)) |
4495 | (buffer-read-only nil)) | |
ede4ac6a | 4496 | (allout-deannotate-hidden begin end) |
d8350998 CY |
4497 | (save-excursion |
4498 | (goto-char begin) | |
4499 | (let (done next prev overlay) | |
4500 | (while (not done) | |
4501 | ;; at or advance to start of next hidden region: | |
4502 | (if (not (allout-hidden-p)) | |
4503 | (setq next | |
1b4d97b2 | 4504 | (max (1+ (point)) |
1c9b9df0 KM |
4505 | (allout-next-single-char-property-change (point) |
4506 | 'invisible | |
4507 | nil end)))) | |
d8350998 | 4508 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4509 | ;; still not at start of hidden area -- must not be any left. |
d8350998 CY |
4510 | (setq done t) |
4511 | (goto-char next) | |
4512 | (setq prev next) | |
4513 | (if (not (allout-hidden-p)) | |
4514 | ;; still not at start of hidden area. | |
4515 | (setq done t) | |
4516 | (setq overlay (allout-get-invisibility-overlay)) | |
4517 | (setq next (overlay-end overlay) | |
4518 | prev next) | |
4519 | ;; advance to end of this hidden area: | |
4520 | (when next | |
4521 | (goto-char next) | |
4522 | (allout-unprotected | |
ede4ac6a KS |
4523 | (let ((buffer-undo-list t)) |
4524 | (put-text-property (overlay-start overlay) next | |
4525 | 'allout-was-hidden t))))))))) | |
d8350998 | 4526 | (set-buffer-modified-p was-modified))) |
ede4ac6a KS |
4527 | ;;;_ > allout-deannotate-hidden (begin end) |
4528 | (defun allout-deannotate-hidden (begin end) | |
4529 | "Remove allout hidden-text annotation between BEGIN and END." | |
4530 | ||
4531 | (allout-unprotected | |
4532 | (let ((inhibit-read-only t) | |
4533 | (buffer-undo-list t)) | |
11c46e15 KM |
4534 | (remove-text-properties begin (min end (point-max)) |
4535 | '(allout-was-hidden t))))) | |
d8350998 CY |
4536 | ;;;_ > allout-hide-by-annotation (begin end) |
4537 | (defun allout-hide-by-annotation (begin end) | |
4538 | "Translate text properties indicating exposure status into actual exposure." | |
4539 | (save-excursion | |
4540 | (goto-char begin) | |
4541 | (let ((was-modified (buffer-modified-p)) | |
4542 | done next prev) | |
4543 | (while (not done) | |
4544 | ;; at or advance to start of next annotation: | |
4545 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
1c9b9df0 KM |
4546 | (setq next (allout-next-single-char-property-change |
4547 | (point) 'allout-was-hidden nil end))) | |
d8350998 | 4548 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4549 | ;; no more or not advancing -- must not be any left. |
d8350998 CY |
4550 | (setq done t) |
4551 | (goto-char next) | |
4552 | (setq prev next) | |
4553 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
4554 | ;; still not at start of annotation. | |
4555 | (setq done t) | |
4556 | ;; advance to just after end of this annotation: | |
1c9b9df0 KM |
4557 | (setq next (allout-next-single-char-property-change |
4558 | (point) 'allout-was-hidden nil end)) | |
d806ab68 KM |
4559 | (let ((o (make-overlay prev next nil 'front-advance))) |
4560 | (overlay-put o 'category 'allout-exposure-category) | |
4561 | (overlay-put o 'evaporate t)) | |
ede4ac6a | 4562 | (allout-deannotate-hidden prev next) |
d8350998 CY |
4563 | (setq prev next) |
4564 | (if next (goto-char next))))) | |
4565 | (set-buffer-modified-p was-modified)))) | |
fd5359c6 MR |
4566 | ;;;_ > allout-yank-processing () |
4567 | (defun allout-yank-processing (&optional arg) | |
c567ac01 | 4568 | |
96b83743 | 4569 | "Incidental allout-specific business to be done just after text yanks. |
19b84ba3 | 4570 | |
c567ac01 | 4571 | Does depth adjustment of yanked topics, when: |
1977b8f6 | 4572 | |
c567ac01 RS |
4573 | 1 the stuff being yanked starts with a valid outline header prefix, and |
4574 | 2 it is being yanked at the end of a line which consists of only a valid | |
1977b8f6 RS |
4575 | topic prefix. |
4576 | ||
a0776d6b | 4577 | Also, adjusts numbering of subsequent siblings when appropriate. |
1977b8f6 | 4578 | |
c567ac01 RS |
4579 | Depth adjustment alters the depth of all the topics being yanked |
4580 | the amount it takes to make the first topic have the depth of the | |
4581 | header into which it's being yanked. | |
1977b8f6 | 4582 | |
c567ac01 RS |
4583 | The point is left in front of yanked, adjusted topics, rather than |
4584 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
d82979ea | 4585 | however, are left exactly like normal, non-allout-specific yanks." |
c567ac01 RS |
4586 | |
4587 | (interactive "*P") | |
4588 | ; Get to beginning, leaving | |
4589 | ; region around subject: | |
96b83743 | 4590 | (if (< (allout-mark-marker t) (point)) |
c567ac01 | 4591 | (exchange-point-and-mark)) |
2a1408fd DN |
4592 | (save-match-data |
4593 | (let* ((subj-beg (point)) | |
4594 | (into-bol (bolp)) | |
4595 | (subj-end (allout-mark-marker t)) | |
4596 | ;; 'resituate' if yanking an entire topic into topic header: | |
4597 | (resituate (and (let ((allout-inhibit-aberrance-doublecheck t)) | |
4598 | (allout-e-o-prefix-p)) | |
4599 | (looking-at allout-regexp) | |
4600 | (allout-prefix-data))) | |
4601 | ;; `rectify-numbering' if resituating (where several topics may | |
4602 | ;; be resituating) or yanking a topic into a topic slot (bol): | |
4603 | (rectify-numbering (or resituate | |
8dd59f01 | 4604 | (and into-bol (looking-at allout-regexp))))) |
2a1408fd | 4605 | (if resituate |
8dd59f01 | 4606 | ;; Yanking a topic into the start of a topic -- reconcile to fit: |
2a1408fd DN |
4607 | (let* ((inhibit-field-text-motion t) |
4608 | (prefix-len (if (not (match-end 1)) | |
4609 | 1 | |
4610 | (- (match-end 1) subj-beg))) | |
4611 | (subj-depth allout-recent-depth) | |
4612 | (prefix-bullet (allout-recent-bullet)) | |
4613 | (adjust-to-depth | |
4614 | ;; Nil if adjustment unnecessary, otherwise depth to which | |
4615 | ;; adjustment should be made: | |
4616 | (save-excursion | |
4617 | (and (goto-char subj-end) | |
4618 | (eolp) | |
4619 | (goto-char subj-beg) | |
4620 | (and (looking-at allout-regexp) | |
4621 | (progn | |
4622 | (beginning-of-line) | |
4623 | (not (= (point) subj-beg))) | |
4624 | (looking-at allout-regexp) | |
4625 | (allout-prefix-data)) | |
4626 | allout-recent-depth))) | |
4627 | (more t)) | |
4628 | (setq rectify-numbering allout-numbered-bullet) | |
4629 | (if adjust-to-depth | |
c567ac01 | 4630 | ; Do the adjustment: |
2a1408fd DN |
4631 | (progn |
4632 | (save-restriction | |
4633 | (narrow-to-region subj-beg subj-end) | |
c567ac01 RS |
4634 | ; Trim off excessive blank |
4635 | ; line at end, if any: | |
2a1408fd DN |
4636 | (goto-char (point-max)) |
4637 | (if (looking-at "^$") | |
4638 | (allout-unprotected (delete-char -1))) | |
c567ac01 RS |
4639 | ; Work backwards, with each |
4640 | ; shallowest level, | |
4641 | ; successively excluding the | |
4642 | ; last processed topic from | |
4643 | ; the narrow region: | |
2a1408fd DN |
4644 | (while more |
4645 | (allout-back-to-current-heading) | |
c567ac01 | 4646 | ; go as high as we can in each bunch: |
2a1408fd DN |
4647 | (while (allout-ascend t)) |
4648 | (save-excursion | |
4649 | (allout-unprotected | |
4650 | (allout-rebullet-topic-grunt (- adjust-to-depth | |
4651 | subj-depth))) | |
4652 | (allout-depth)) | |
4653 | (if (setq more (not (bobp))) | |
4654 | (progn (widen) | |
4655 | (forward-char -1) | |
4656 | (narrow-to-region subj-beg (point)))))) | |
b6a5875b KM |
4657 | ;; Remove new heading prefix: |
4658 | (allout-unprotected | |
4659 | (progn | |
4660 | (delete-region (point) (+ (point) | |
4661 | prefix-len | |
4662 | (- adjust-to-depth | |
4663 | subj-depth))) | |
c567ac01 RS |
4664 | ; and delete residual subj |
4665 | ; prefix digits and space: | |
b6a5875b | 4666 | (while (looking-at "[0-9]") (delete-char 1)) |
e47ca23b KM |
4667 | (delete-char -1) |
4668 | (if (not (eolp)) | |
4669 | (forward-char)))) | |
b6a5875b | 4670 | ;; Assert new topic's bullet - minimal effort if unchanged: |
b0911414 | 4671 | (allout-rebullet-heading (string-to-char prefix-bullet))) |
2a1408fd DN |
4672 | (exchange-point-and-mark)))) |
4673 | (if rectify-numbering | |
4674 | (progn | |
4675 | (save-excursion | |
c567ac01 | 4676 | ; Give some preliminary feedback: |
2a1408fd | 4677 | (message "... reconciling numbers") |
c567ac01 | 4678 | ; ... and renumber, in case necessary: |
2a1408fd DN |
4679 | (goto-char subj-beg) |
4680 | (if (allout-goto-prefix-doublechecked) | |
4681 | (allout-unprotected | |
b6a5875b | 4682 | (allout-rebullet-heading nil ;;; instead |
2a1408fd DN |
4683 | (allout-depth) ;;; depth |
4684 | nil ;;; number-control | |
4685 | nil ;;; index | |
4686 | t))) | |
4687 | (message "")))) | |
4688 | (if (or into-bol resituate) | |
4689 | (allout-hide-by-annotation (point) (allout-mark-marker t)) | |
4690 | (allout-deannotate-hidden (allout-mark-marker t) (point))) | |
4691 | (if (not resituate) | |
4692 | (exchange-point-and-mark)) | |
7b97c764 | 4693 | (run-hook-with-args 'allout-structure-added-functions subj-beg subj-end)))) |
fd5359c6 MR |
4694 | ;;;_ > allout-yank (&optional arg) |
4695 | (defun allout-yank (&optional arg) | |
aad94676 | 4696 | "`allout-mode' yank, with depth and numbering adjustment of yanked topics. |
19b84ba3 | 4697 | |
a0776d6b | 4698 | Non-topic yanks work no differently than normal yanks. |
c567ac01 RS |
4699 | |
4700 | If a topic is being yanked into a bare topic prefix, the depth of the | |
4701 | yanked topic is adjusted to the depth of the topic prefix. | |
4702 | ||
2265e017 | 4703 | 1 we're yanking in an `allout-mode' buffer |
c567ac01 RS |
4704 | 2 the stuff being yanked starts with a valid outline header prefix, and |
4705 | 3 it is being yanked at the end of a line which consists of only a valid | |
4706 | topic prefix. | |
4707 | ||
4708 | If these conditions hold then the depth of the yanked topics are all | |
4709 | adjusted the amount it takes to make the first one at the depth of the | |
4710 | header into which it's being yanked. | |
4711 | ||
4712 | The point is left in front of yanked, adjusted topics, rather than | |
4713 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
4714 | however, (ones that don't qualify for adjustment) are handled | |
4715 | exactly like normal yanks. | |
4716 | ||
a0776d6b | 4717 | Numbering of yanked topics, and the successive siblings at the depth |
c567ac01 RS |
4718 | into which they're being yanked, is adjusted. |
4719 | ||
539d7736 JB |
4720 | `allout-yank-pop' works with `allout-yank' just like normal `yank-pop' |
4721 | works with normal `yank' in non-outline buffers." | |
1977b8f6 RS |
4722 | |
4723 | (interactive "*P") | |
4724 | (setq this-command 'yank) | |
48bd8440 EZ |
4725 | (allout-unprotected |
4726 | (yank arg)) | |
fd5359c6 | 4727 | (if (allout-mode-p) |
48bd8440 | 4728 | (allout-yank-processing))) |
fd5359c6 MR |
4729 | ;;;_ > allout-yank-pop (&optional arg) |
4730 | (defun allout-yank-pop (&optional arg) | |
2265e017 | 4731 | "Yank-pop like `allout-yank' when popping to bare outline prefixes. |
19b84ba3 RS |
4732 | |
4733 | Adapts level of popped topics to level of fresh prefix. | |
c567ac01 | 4734 | |
60c7bbd2 | 4735 | Note -- prefix changes to distinctive bullets will stick, if followed |
c567ac01 | 4736 | by pops to non-distinctive yanks. Bug..." |
1977b8f6 RS |
4737 | |
4738 | (interactive "*p") | |
1977b8f6 | 4739 | (setq this-command 'yank) |
c567ac01 | 4740 | (yank-pop arg) |
fd5359c6 MR |
4741 | (if (allout-mode-p) |
4742 | (allout-yank-processing))) | |
1977b8f6 | 4743 | |
c567ac01 RS |
4744 | ;;;_ - Specialty bullet functions |
4745 | ;;;_ : File Cross references | |
fd5359c6 MR |
4746 | ;;;_ > allout-resolve-xref () |
4747 | (defun allout-resolve-xref () | |
19b84ba3 RS |
4748 | "Pop to file associated with current heading, if it has an xref bullet. |
4749 | ||
fd5359c6 | 4750 | \(Works according to setting of `allout-file-xref-bullet')." |
1977b8f6 | 4751 | (interactive) |
fd5359c6 | 4752 | (if (not allout-file-xref-bullet) |
1977b8f6 | 4753 | (error |
60c7bbd2 | 4754 | "Outline cross references disabled -- no `allout-file-xref-bullet'") |
fd5359c6 | 4755 | (if (not (string= (allout-current-bullet) allout-file-xref-bullet)) |
635ca796 | 4756 | (error "Current heading lacks cross-reference bullet `%s'" |
fd5359c6 | 4757 | allout-file-xref-bullet) |
0458fa80 EZ |
4758 | (let ((inhibit-field-text-motion t) |
4759 | file-name) | |
2a1408fd DN |
4760 | (save-match-data |
4761 | (save-excursion | |
4762 | (let* ((text-start allout-recent-prefix-end) | |
9b026d9f | 4763 | (heading-end (point-at-eol))) |
2a1408fd DN |
4764 | (goto-char text-start) |
4765 | (setq file-name | |
4766 | (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t) | |
4767 | (buffer-substring (match-beginning 1) | |
4768 | (match-end 1))))))) | |
69027dea | 4769 | (setq file-name (expand-file-name file-name)) |
1977b8f6 RS |
4770 | (if (or (file-exists-p file-name) |
4771 | (if (file-writable-p file-name) | |
4772 | (y-or-n-p (format "%s not there, create one? " | |
4773 | file-name)) | |
4774 | (error "%s not found and can't be created" file-name))) | |
4775 | (condition-case failure | |
4776 | (find-file-other-window file-name) | |
d8350998 | 4777 | (error failure)) |
1977b8f6 RS |
4778 | (error "%s not found" file-name)) |
4779 | ) | |
4780 | ) | |
4781 | ) | |
4782 | ) | |
19b84ba3 | 4783 | |
9179616f | 4784 | ;;;_ #6 Exposure Control |
c567ac01 RS |
4785 | |
4786 | ;;;_ - Fundamental | |
d82979ea EZ |
4787 | ;;;_ > allout-flag-region (from to flag) |
4788 | (defun allout-flag-region (from to flag) | |
48bd8440 | 4789 | "Conceal text between FROM and TO if FLAG is non-nil, else reveal it. |
7b97c764 CY |
4790 | After the exposure changes are made, run the abnormal hook |
4791 | `allout-exposure-change-functions' with the same arguments as | |
4792 | this function." | |
96b83743 | 4793 | |
96b83743 | 4794 | ;; We use outline invisibility spec. |
01fc9422 | 4795 | (remove-overlays from to 'category 'allout-exposure-category) |
96b83743 | 4796 | (when flag |
2a1408fd | 4797 | (let ((o (make-overlay from to nil 'front-advance))) |
01fc9422 | 4798 | (overlay-put o 'category 'allout-exposure-category) |
68ba37fb | 4799 | (overlay-put o 'evaporate t) |
96b83743 | 4800 | (when (featurep 'xemacs) |
01fc9422 | 4801 | (let ((props (symbol-plist 'allout-exposure-category))) |
96b83743 | 4802 | (while props |
1c9b9df0 KM |
4803 | (condition-case nil |
4804 | ;; as of 2008-02-27, xemacs lacks modification-hooks | |
4805 | (overlay-put o (pop props) (pop props)) | |
3f2b07f8 KM |
4806 | (error nil)))))) |
4807 | (setq allout-this-command-hid-text t)) | |
7b97c764 | 4808 | (run-hook-with-args 'allout-exposure-change-functions from to flag)) |
fd5359c6 MR |
4809 | ;;;_ > allout-flag-current-subtree (flag) |
4810 | (defun allout-flag-current-subtree (flag) | |
96b83743 | 4811 | "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it." |
19b84ba3 | 4812 | |
c567ac01 | 4813 | (save-excursion |
fd5359c6 | 4814 | (allout-back-to-current-heading) |
0458fa80 EZ |
4815 | (let ((inhibit-field-text-motion t)) |
4816 | (end-of-line)) | |
96b83743 EZ |
4817 | (allout-flag-region (point) |
4818 | ;; Exposing must not leave trailing blanks hidden, | |
4819 | ;; but can leave them exposed when hiding, so we | |
4820 | ;; can use flag's inverse as the | |
4821 | ;; include-trailing-blank cue: | |
4822 | (allout-end-of-current-subtree (not flag)) | |
4823 | flag))) | |
c567ac01 | 4824 | |
c567ac01 | 4825 | ;;;_ - Topic-specific |
01fc9422 EZ |
4826 | ;;;_ > allout-show-entry () |
4827 | (defun allout-show-entry () | |
4828 | "Like `allout-show-current-entry', but reveals entries in hidden topics. | |
c567ac01 RS |
4829 | |
4830 | This is a way to give restricted peek at a concealed locality without the | |
4831 | expense of exposing its context, but can leave the outline with aberrant | |
96b83743 EZ |
4832 | exposure. `allout-show-offshoot' should be used after the peek to rectify |
4833 | the exposure." | |
c567ac01 RS |
4834 | |
4835 | (interactive) | |
4836 | (save-excursion | |
96b83743 | 4837 | (let (beg end) |
d8350998 | 4838 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4839 | (setq beg (if (allout-hidden-p) (1- (point)) (point))) |
4840 | (setq end (allout-pre-next-prefix)) | |
4841 | (allout-flag-region beg end nil) | |
9179616f | 4842 | (list beg end)))) |
fd5359c6 MR |
4843 | ;;;_ > allout-show-children (&optional level strict) |
4844 | (defun allout-show-children (&optional level strict) | |
c567ac01 RS |
4845 | |
4846 | "If point is visible, show all direct subheadings of this heading. | |
19b84ba3 | 4847 | |
2265e017 | 4848 | Otherwise, do `allout-show-to-offshoot', and then show subheadings. |
c567ac01 RS |
4849 | |
4850 | Optional LEVEL specifies how many levels below the current level | |
4851 | should be shown, or all levels if t. Default is 1. | |
4852 | ||
4853 | Optional STRICT means don't resort to -show-to-offshoot, no matter | |
4854 | what. This is basically so -show-to-offshoot, which is called by | |
4855 | this function, can employ the pure offspring-revealing capabilities of | |
19b84ba3 RS |
4856 | it. |
4857 | ||
4858 | Returns point at end of subtree that was opened, if any. (May get a | |
4859 | point of non-opened subtree?)" | |
c567ac01 RS |
4860 | |
4861 | (interactive "p") | |
96b83743 | 4862 | (let ((start-point (point))) |
19b84ba3 | 4863 | (if (and (not strict) |
96b83743 | 4864 | (allout-hidden-p)) |
c567ac01 | 4865 | |
96b83743 EZ |
4866 | (progn (allout-show-to-offshoot) ; Point's concealed, open to |
4867 | ; expose it. | |
4868 | ;; Then recurse, but with "strict" set so we don't | |
4869 | ;; infinite regress: | |
4870 | (allout-show-children level t)) | |
c567ac01 | 4871 | |
19b84ba3 | 4872 | (save-excursion |
96b83743 EZ |
4873 | (allout-beginning-of-current-line) |
4874 | (save-restriction | |
d8350998 | 4875 | (let* (depth |
65e7eb3d EZ |
4876 | ;; translate the level spec for this routine to the ones |
4877 | ;; used by -chart-subtree and -chart-to-reveal: | |
4878 | (chart-level (cond ((not level) 1) | |
4879 | ((eq level t) nil) | |
4880 | (t level))) | |
4881 | (chart (allout-chart-subtree chart-level)) | |
4882 | (to-reveal (or (allout-chart-to-reveal chart chart-level) | |
d8350998 CY |
4883 | ;; interactive, show discontinuous children: |
4884 | (and chart | |
1c9b9df0 | 4885 | (allout-called-interactively-p) |
d8350998 CY |
4886 | (save-excursion |
4887 | (allout-back-to-current-heading) | |
4888 | (setq depth (allout-current-depth)) | |
4889 | (and (allout-next-heading) | |
4890 | (> allout-recent-depth | |
4891 | (1+ depth)))) | |
4892 | (message | |
4893 | "Discontinuous offspring; use `%s %s'%s." | |
4894 | (substitute-command-keys | |
4895 | "\\[universal-argument]") | |
4896 | (substitute-command-keys | |
4897 | "\\[allout-shift-out]") | |
4898 | " to elevate them.") | |
4899 | (allout-chart-to-reveal | |
4900 | chart (- allout-recent-depth depth)))))) | |
96b83743 EZ |
4901 | (goto-char start-point) |
4902 | (when (and strict (allout-hidden-p)) | |
4903 | ;; Concealed root would already have been taken care of, | |
4904 | ;; unless strict was set. | |
4905 | (allout-flag-region (point) (allout-snug-back) nil) | |
4906 | (when allout-show-bodies | |
4907 | (goto-char (car to-reveal)) | |
4908 | (allout-show-current-entry))) | |
4909 | (while to-reveal | |
4910 | (goto-char (car to-reveal)) | |
4911 | (allout-flag-region (save-excursion (allout-snug-back) (point)) | |
4912 | (progn (search-forward "\n" nil t) | |
4913 | (1- (point))) | |
4914 | nil) | |
4915 | (when allout-show-bodies | |
4916 | (goto-char (car to-reveal)) | |
4917 | (allout-show-current-entry)) | |
4918 | (setq to-reveal (cdr to-reveal))))))) | |
4919 | ;; Compensate for `save-excursion's maintenance of point | |
4920 | ;; within invisible text: | |
4921 | (goto-char start-point))) | |
fd5359c6 MR |
4922 | ;;;_ > allout-show-to-offshoot () |
4923 | (defun allout-show-to-offshoot () | |
2265e017 | 4924 | "Like `allout-show-entry', but reveals all concealed ancestors, as well. |
c567ac01 | 4925 | |
96b83743 | 4926 | Useful for coherently exposing to a random point in a hidden region." |
c567ac01 RS |
4927 | (interactive) |
4928 | (save-excursion | |
0458fa80 EZ |
4929 | (let ((inhibit-field-text-motion t) |
4930 | (orig-pt (point)) | |
d8350998 | 4931 | (orig-pref (allout-goto-prefix-doublechecked)) |
c567ac01 | 4932 | (last-at (point)) |
65e7eb3d EZ |
4933 | (bag-it 0)) |
4934 | (while (or (> bag-it 1) (allout-hidden-p)) | |
96b83743 | 4935 | (while (allout-hidden-p) |
d8350998 | 4936 | (move-beginning-of-line 1) |
96b83743 | 4937 | (if (allout-hidden-p) (forward-char -1))) |
c567ac01 | 4938 | (if (= last-at (setq last-at (point))) |
65e7eb3d EZ |
4939 | ;; Oops, we're not making any progress! Show the current topic |
4940 | ;; completely, and try one more time here, if we haven't already. | |
c567ac01 | 4941 | (progn (beginning-of-line) |
fd5359c6 | 4942 | (allout-show-current-subtree) |
c567ac01 | 4943 | (goto-char orig-pt) |
65e7eb3d EZ |
4944 | (setq bag-it (1+ bag-it)) |
4945 | (if (> bag-it 1) | |
4946 | (error "allout-show-to-offshoot: %s" | |
4947 | "Stumped by aberrant nesting."))) | |
4948 | (if (> bag-it 0) (setq bag-it 0)) | |
d8350998 CY |
4949 | (allout-show-children) |
4950 | (goto-char orig-pref))) | |
19b84ba3 | 4951 | (goto-char orig-pt))) |
fd5359c6 MR |
4952 | (if (allout-hidden-p) |
4953 | (allout-show-entry))) | |
4954 | ;;;_ > allout-hide-current-entry () | |
4955 | (defun allout-hide-current-entry () | |
c567ac01 RS |
4956 | "Hide the body directly following this heading." |
4957 | (interactive) | |
fd5359c6 | 4958 | (allout-back-to-current-heading) |
c567ac01 | 4959 | (save-excursion |
0458fa80 EZ |
4960 | (let ((inhibit-field-text-motion t)) |
4961 | (end-of-line)) | |
96b83743 | 4962 | (allout-flag-region (point) |
d82979ea | 4963 | (progn (allout-end-of-entry) (point)) |
96b83743 | 4964 | t))) |
fd5359c6 MR |
4965 | ;;;_ > allout-show-current-entry (&optional arg) |
4966 | (defun allout-show-current-entry (&optional arg) | |
96b83743 | 4967 | "Show body following current heading, or hide entry with universal argument." |
c567ac01 RS |
4968 | |
4969 | (interactive "P") | |
4970 | (if arg | |
fd5359c6 | 4971 | (allout-hide-current-entry) |
96b83743 | 4972 | (save-excursion (allout-show-to-offshoot)) |
c567ac01 | 4973 | (save-excursion |
fd5359c6 | 4974 | (allout-flag-region (point) |
96b83743 EZ |
4975 | (progn (allout-end-of-entry t) (point)) |
4976 | nil) | |
d82979ea | 4977 | ))) |
fd5359c6 MR |
4978 | ;;;_ > allout-show-current-subtree (&optional arg) |
4979 | (defun allout-show-current-subtree (&optional arg) | |
75bcb912 JB |
4980 | "Show everything within the current topic. |
4981 | With a repeat-count, expose this topic and its siblings." | |
19b84ba3 RS |
4982 | (interactive "P") |
4983 | (save-excursion | |
fd5359c6 | 4984 | (if (<= (allout-current-depth) 0) |
60c7bbd2 | 4985 | ;; Outside any topics -- try to get to the first: |
fd5359c6 | 4986 | (if (not (allout-next-heading)) |
6a05d05f | 4987 | (error "No topics") |
60c7bbd2 RS |
4988 | ;; got to first, outermost topic -- set to expose it and siblings: |
4989 | (message "Above outermost topic -- exposing all.") | |
96b83743 EZ |
4990 | (allout-flag-region (point-min)(point-max) nil)) |
4991 | (allout-beginning-of-current-line) | |
19b84ba3 | 4992 | (if (not arg) |
96b83743 | 4993 | (allout-flag-current-subtree nil) |
fd5359c6 MR |
4994 | (allout-beginning-of-level) |
4995 | (allout-expose-topic '(* :)))))) | |
96b83743 EZ |
4996 | ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners) |
4997 | (defun allout-current-topic-collapsed-p (&optional include-single-liners) | |
4998 | "True if the currently visible containing topic is already collapsed. | |
4999 | ||
64686e6d RS |
5000 | Single line topics intrinsically can be considered as being both |
5001 | collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is | |
5002 | true, then single-line topics are considered to be collapsed. By | |
5003 | default, they are treated as being uncollapsed." | |
2a1408fd DN |
5004 | (save-match-data |
5005 | (save-excursion | |
5006 | (and | |
5007 | ;; Is the topic all on one line (allowing for trailing blank line)? | |
5008 | (>= (progn (allout-back-to-current-heading) | |
82b392a4 KM |
5009 | (let ((inhibit-field-text-motion t)) |
5010 | (move-end-of-line 1)) | |
2a1408fd DN |
5011 | (point)) |
5012 | (allout-end-of-current-subtree (not (looking-at "\n\n")))) | |
5013 | ||
5014 | (or include-single-liners | |
5015 | (progn (backward-char 1) (allout-hidden-p))))))) | |
fd5359c6 MR |
5016 | ;;;_ > allout-hide-current-subtree (&optional just-close) |
5017 | (defun allout-hide-current-subtree (&optional just-close) | |
19b84ba3 | 5018 | "Close the current topic, or containing topic if this one is already closed. |
c567ac01 | 5019 | |
19b84ba3 | 5020 | If this topic is closed and it's a top level topic, close this topic |
353e2ef2 | 5021 | and its siblings. |
19b84ba3 | 5022 | |
96b83743 | 5023 | If optional arg JUST-CLOSE is non-nil, do not close the parent or |
19b84ba3 | 5024 | siblings, even if the target topic is already closed." |
c567ac01 RS |
5025 | |
5026 | (interactive) | |
96b83743 | 5027 | (let* ((from (point)) |
60c7bbd2 | 5028 | (sibs-msg "Top-level topic already closed -- closing siblings...") |
96b83743 EZ |
5029 | (current-exposed (not (allout-current-topic-collapsed-p t)))) |
5030 | (cond (current-exposed (allout-flag-current-subtree t)) | |
5031 | (just-close nil) | |
d8350998 | 5032 | ((allout-ascend) (allout-hide-current-subtree)) |
96b83743 EZ |
5033 | (t (goto-char 0) |
5034 | (message sibs-msg) | |
d8350998 | 5035 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
5036 | (allout-expose-topic '(0 :)) |
5037 | (message (concat sibs-msg " Done.")))) | |
5038 | (goto-char from))) | |
2a1408fd DN |
5039 | ;;;_ > allout-toggle-current-subtree-exposure |
5040 | (defun allout-toggle-current-subtree-exposure () | |
5041 | "Show or hide the current subtree depending on its current state." | |
5042 | ;; thanks to tassilo for suggesting this. | |
5043 | (interactive) | |
5044 | (save-excursion | |
5045 | (allout-back-to-heading) | |
5046 | (if (allout-hidden-p (point-at-eol)) | |
5047 | (allout-show-current-subtree) | |
5048 | (allout-hide-current-subtree)))) | |
fd5359c6 MR |
5049 | ;;;_ > allout-show-current-branches () |
5050 | (defun allout-show-current-branches () | |
c567ac01 RS |
5051 | "Show all subheadings of this heading, but not their bodies." |
5052 | (interactive) | |
0458fa80 EZ |
5053 | (let ((inhibit-field-text-motion t)) |
5054 | (beginning-of-line)) | |
fd5359c6 MR |
5055 | (allout-show-children t)) |
5056 | ;;;_ > allout-hide-current-leaves () | |
5057 | (defun allout-hide-current-leaves () | |
353e2ef2 | 5058 | "Hide the bodies of the current topic and all its offspring." |
c567ac01 | 5059 | (interactive) |
fd5359c6 MR |
5060 | (allout-back-to-current-heading) |
5061 | (allout-hide-region-body (point) (progn (allout-end-of-current-subtree) | |
c567ac01 RS |
5062 | (point)))) |
5063 | ||
5064 | ;;;_ - Region and beyond | |
fd5359c6 MR |
5065 | ;;;_ > allout-show-all () |
5066 | (defun allout-show-all () | |
c567ac01 RS |
5067 | "Show all of the text in the buffer." |
5068 | (interactive) | |
19b84ba3 | 5069 | (message "Exposing entire buffer...") |
96b83743 | 5070 | (allout-flag-region (point-min) (point-max) nil) |
19b84ba3 | 5071 | (message "Exposing entire buffer... Done.")) |
fd5359c6 MR |
5072 | ;;;_ > allout-hide-bodies () |
5073 | (defun allout-hide-bodies () | |
c567ac01 RS |
5074 | "Hide all of buffer except headings." |
5075 | (interactive) | |
fd5359c6 MR |
5076 | (allout-hide-region-body (point-min) (point-max))) |
5077 | ;;;_ > allout-hide-region-body (start end) | |
5078 | (defun allout-hide-region-body (start end) | |
c567ac01 | 5079 | "Hide all body lines in the region, but not headings." |
2a1408fd DN |
5080 | (save-match-data |
5081 | (save-excursion | |
5082 | (save-restriction | |
5083 | (narrow-to-region start end) | |
5084 | (goto-char (point-min)) | |
5085 | (let ((inhibit-field-text-motion t)) | |
5086 | (while (not (eobp)) | |
5087 | (end-of-line) | |
5088 | (allout-flag-region (point) (allout-end-of-entry) t) | |
5089 | (if (not (eobp)) | |
5090 | (forward-char | |
5091 | (if (looking-at "\n\n") | |
5092 | 2 1))))))))) | |
c567ac01 | 5093 | |
fd5359c6 MR |
5094 | ;;;_ > allout-expose-topic (spec) |
5095 | (defun allout-expose-topic (spec) | |
19b84ba3 | 5096 | "Apply exposure specs to successive outline topic items. |
c567ac01 | 5097 | |
fd5359c6 MR |
5098 | Use the more convenient frontend, `allout-new-exposure', if you don't |
5099 | need evaluation of the arguments, or even better, the `allout-layout' | |
19b84ba3 RS |
5100 | variable-keyed mode-activation/auto-exposure feature of allout outline |
5101 | mode. See the respective documentation strings for more details. | |
c567ac01 RS |
5102 | |
5103 | Cursor is left at start position. | |
5104 | ||
19b84ba3 RS |
5105 | SPEC is either a number or a list. |
5106 | ||
5107 | Successive specs on a list are applied to successive sibling topics. | |
c567ac01 | 5108 | |
c07583cd | 5109 | A simple spec (either a number, one of a few symbols, or the null |
19b84ba3 RS |
5110 | list) dictates the exposure for the corresponding topic. |
5111 | ||
5112 | Non-null lists recursively designate exposure specs for respective | |
5113 | subtopics of the current topic. | |
c567ac01 | 5114 | |
353e2ef2 | 5115 | The `:' repeat spec is used to specify exposure for any number of |
19b84ba3 | 5116 | successive siblings, up to the trailing ones for which there are |
353e2ef2 | 5117 | explicit specs following the `:'. |
c567ac01 RS |
5118 | |
5119 | Simple (numeric and null-list) specs are interpreted as follows: | |
5120 | ||
19b84ba3 RS |
5121 | Numbers indicate the relative depth to open the corresponding topic. |
5122 | - negative numbers force the topic to be closed before opening to the | |
5123 | absolute value of the number, so all siblings are open only to | |
5124 | that level. | |
5125 | - positive numbers open to the relative depth indicated by the | |
5126 | number, but do not force already opened subtopics to be closed. | |
60c7bbd2 | 5127 | - 0 means to close topic -- hide all offspring. |
353e2ef2 | 5128 | : - `repeat' |
c567ac01 | 5129 | apply prior element to all siblings at current level, *up to* |
353e2ef2 | 5130 | those siblings that would be covered by specs following the `:' |
c567ac01 | 5131 | on the list. Ie, apply to all topics at level but the last |
c07583cd | 5132 | ones. (Only first of multiple colons at same level is |
60c7bbd2 | 5133 | respected -- subsequent ones are discarded.) |
19b84ba3 RS |
5134 | * - completely opens the topic, including bodies. |
5135 | + - shows all the sub headers, but not the bodies | |
5136 | - - exposes the body of the corresponding topic. | |
c567ac01 RS |
5137 | |
5138 | Examples: | |
fd5359c6 | 5139 | \(allout-expose-topic '(-1 : 0)) |
c567ac01 RS |
5140 | Close this and all following topics at current level, exposing |
5141 | only their immediate children, but close down the last topic | |
5142 | at this current level completely. | |
fd5359c6 | 5143 | \(allout-expose-topic '(-1 () : 1 0)) |
c567ac01 RS |
5144 | Close current topic so only the immediate subtopics are shown; |
5145 | show the children in the second to last topic, and completely | |
5146 | close the last one. | |
fd5359c6 | 5147 | \(allout-expose-topic '(-2 : -1 *)) |
c567ac01 RS |
5148 | Expose children and grandchildren of all topics at current |
5149 | level except the last two; expose children of the second to | |
5150 | last and completely open the last one." | |
5151 | ||
5152 | (interactive "xExposure spec: ") | |
19b84ba3 RS |
5153 | (if (not (listp spec)) |
5154 | nil | |
fd5359c6 | 5155 | (let ((depth (allout-depth)) |
19b84ba3 RS |
5156 | (max-pos 0) |
5157 | prev-elem curr-elem | |
96b83743 | 5158 | stay) |
19b84ba3 RS |
5159 | (while spec |
5160 | (setq prev-elem curr-elem | |
5161 | curr-elem (car spec) | |
5162 | spec (cdr spec)) | |
5163 | (cond ; Do current element: | |
5164 | ((null curr-elem) nil) | |
5165 | ((symbolp curr-elem) | |
fd5359c6 MR |
5166 | (cond ((eq curr-elem '*) (allout-show-current-subtree) |
5167 | (if (> allout-recent-end-of-subtree max-pos) | |
5168 | (setq max-pos allout-recent-end-of-subtree))) | |
65e7eb3d EZ |
5169 | ((eq curr-elem '+) |
5170 | (if (not (allout-hidden-p)) | |
5171 | (save-excursion (allout-hide-current-subtree t))) | |
5172 | (allout-show-current-branches) | |
fd5359c6 MR |
5173 | (if (> allout-recent-end-of-subtree max-pos) |
5174 | (setq max-pos allout-recent-end-of-subtree))) | |
5175 | ((eq curr-elem '-) (allout-show-current-entry)) | |
19b84ba3 RS |
5176 | ((eq curr-elem ':) |
5177 | (setq stay t) | |
353e2ef2 | 5178 | ;; Expand the `repeat' spec to an explicit version, |
19b84ba3 RS |
5179 | ;; w.r.t. remaining siblings: |
5180 | (let ((residue ; = # of sibs not covered by remaining spec | |
60c7bbd2 | 5181 | ;; Dang, could be nice to make use of the chart, sigh: |
fd5359c6 | 5182 | (- (length (allout-chart-siblings)) |
19b84ba3 RS |
5183 | (length spec)))) |
5184 | (if (< 0 residue) | |
60c7bbd2 | 5185 | ;; Some residue -- cover it with prev-elem: |
19b84ba3 RS |
5186 | (setq spec (append (make-list residue prev-elem) |
5187 | spec))))))) | |
5188 | ((numberp curr-elem) | |
96b83743 | 5189 | (if (and (>= 0 curr-elem) (not (allout-hidden-p))) |
fd5359c6 | 5190 | (save-excursion (allout-hide-current-subtree t) |
19b84ba3 RS |
5191 | (if (> 0 curr-elem) |
5192 | nil | |
fd5359c6 | 5193 | (if (> allout-recent-end-of-subtree max-pos) |
19b84ba3 | 5194 | (setq max-pos |
fd5359c6 | 5195 | allout-recent-end-of-subtree))))) |
19b84ba3 | 5196 | (if (> (abs curr-elem) 0) |
fd5359c6 MR |
5197 | (progn (allout-show-children (abs curr-elem)) |
5198 | (if (> allout-recent-end-of-subtree max-pos) | |
5199 | (setq max-pos allout-recent-end-of-subtree))))) | |
19b84ba3 | 5200 | ((listp curr-elem) |
fd5359c6 MR |
5201 | (if (allout-descend-to-depth (1+ depth)) |
5202 | (let ((got (allout-expose-topic curr-elem))) | |
19b84ba3 RS |
5203 | (if (and got (> got max-pos)) (setq max-pos got)))))) |
5204 | (cond (stay (setq stay nil)) | |
5205 | ((listp (car spec)) nil) | |
5206 | ((> max-pos (point)) | |
5207 | ;; Capitalize on max-pos state to get us nearer next sibling: | |
5208 | (progn (goto-char (min (point-max) max-pos)) | |
fd5359c6 MR |
5209 | (allout-next-heading))) |
5210 | ((allout-next-sibling depth)))) | |
19b84ba3 | 5211 | max-pos))) |
fd5359c6 MR |
5212 | ;;;_ > allout-old-expose-topic (spec &rest followers) |
5213 | (defun allout-old-expose-topic (spec &rest followers) | |
d82979ea | 5214 | |
c07583cd | 5215 | "Deprecated. Use `allout-expose-topic' (with different schema |
d82979ea EZ |
5216 | format) instead. |
5217 | ||
5218 | Dictate wholesale exposure scheme for current topic, according to SPEC. | |
c567ac01 RS |
5219 | |
5220 | SPEC is either a number or a list. Optional successive args | |
5221 | dictate exposure for subsequent siblings of current topic. | |
5222 | ||
5223 | A simple spec (either a number, a special symbol, or the null list) | |
5224 | dictates the overall exposure for a topic. Non null lists are | |
5225 | composite specs whose first element dictates the overall exposure for | |
5226 | a topic, with the subsequent elements in the list interpreted as specs | |
5227 | that dictate the exposure for the successive offspring of the topic. | |
5228 | ||
5229 | Simple (numeric and null-list) specs are interpreted as follows: | |
5230 | ||
5231 | - Numbers indicate the relative depth to open the corresponding topic: | |
5232 | - negative numbers force the topic to be close before opening to the | |
5233 | absolute value of the number. | |
5234 | - positive numbers just open to the relative depth indicated by the number. | |
5235 | - 0 just closes | |
353e2ef2 KH |
5236 | - `*' completely opens the topic, including bodies. |
5237 | - `+' shows all the sub headers, but not the bodies | |
5238 | - `-' exposes the body and immediate offspring of the corresponding topic. | |
c567ac01 RS |
5239 | |
5240 | If the spec is a list, the first element must be a number, which | |
5241 | dictates the exposure depth of the topic as a whole. Subsequent | |
5242 | elements of the list are nested SPECs, dictating the specific exposure | |
5243 | for the corresponding offspring of the topic. | |
5244 | ||
e126900f | 5245 | Optional FOLLOWERS arguments dictate exposure for succeeding siblings." |
c567ac01 RS |
5246 | |
5247 | (interactive "xExposure spec: ") | |
0458fa80 EZ |
5248 | (let ((inhibit-field-text-motion t) |
5249 | (depth (allout-current-depth)) | |
c567ac01 RS |
5250 | max-pos) |
5251 | (cond ((null spec) nil) | |
5252 | ((symbolp spec) | |
fd5359c6 MR |
5253 | (if (eq spec '*) (allout-show-current-subtree)) |
5254 | (if (eq spec '+) (allout-show-current-branches)) | |
5255 | (if (eq spec '-) (allout-show-current-entry))) | |
c567ac01 RS |
5256 | ((numberp spec) |
5257 | (if (>= 0 spec) | |
fd5359c6 | 5258 | (save-excursion (allout-hide-current-subtree t) |
c567ac01 RS |
5259 | (end-of-line) |
5260 | (if (or (not max-pos) | |
5261 | (> (point) max-pos)) | |
5262 | (setq max-pos (point))) | |
5263 | (if (> 0 spec) | |
5264 | (setq spec (* -1 spec))))) | |
5265 | (if (> spec 0) | |
fd5359c6 | 5266 | (allout-show-children spec))) |
c567ac01 | 5267 | ((listp spec) |
fd5359c6 | 5268 | ;(let ((got (allout-old-expose-topic (car spec)))) |
c567ac01 RS |
5269 | ; (if (and got (or (not max-pos) (> got max-pos))) |
5270 | ; (setq max-pos got))) | |
fd5359c6 | 5271 | (let ((new-depth (+ (allout-current-depth) 1)) |
c567ac01 | 5272 | got) |
fd5359c6 | 5273 | (setq max-pos (allout-old-expose-topic (car spec))) |
c567ac01 RS |
5274 | (setq spec (cdr spec)) |
5275 | (if (and spec | |
fd5359c6 MR |
5276 | (allout-descend-to-depth new-depth) |
5277 | (not (allout-hidden-p))) | |
5278 | (progn (setq got (apply 'allout-old-expose-topic spec)) | |
c567ac01 RS |
5279 | (if (and got (or (not max-pos) (> got max-pos))) |
5280 | (setq max-pos got))))))) | |
5281 | (while (and followers | |
5282 | (progn (if (and max-pos (< (point) max-pos)) | |
5283 | (progn (goto-char max-pos) | |
5284 | (setq max-pos nil))) | |
5285 | (end-of-line) | |
fd5359c6 MR |
5286 | (allout-next-sibling depth))) |
5287 | (allout-old-expose-topic (car followers)) | |
c567ac01 RS |
5288 | (setq followers (cdr followers))) |
5289 | max-pos)) | |
fd5359c6 MR |
5290 | ;;;_ > allout-new-exposure '() |
5291 | (defmacro allout-new-exposure (&rest spec) | |
5292 | "Literal frontend for `allout-expose-topic', doesn't evaluate arguments. | |
2265e017 MR |
5293 | Some arguments that would need to be quoted in `allout-expose-topic' |
5294 | need not be quoted in `allout-new-exposure'. | |
c567ac01 RS |
5295 | |
5296 | Cursor is left at start position. | |
5297 | ||
d82979ea EZ |
5298 | Use this instead of obsolete `allout-exposure'. |
5299 | ||
c567ac01 | 5300 | Examples: |
bff05d9e | 5301 | \(allout-new-exposure (-1 () () () 1) 0) |
c567ac01 RS |
5302 | Close current topic at current level so only the immediate |
5303 | subtopics are shown, except also show the children of the | |
5304 | third subtopic; and close the next topic at the current level. | |
bff05d9e | 5305 | \(allout-new-exposure : -1 0) |
c567ac01 RS |
5306 | Close all topics at current level to expose only their |
5307 | immediate children, except for the last topic at the current | |
353e2ef2 | 5308 | level, in which even its immediate children are hidden. |
bff05d9e | 5309 | \(allout-new-exposure -2 : -1 *) |
c567ac01 RS |
5310 | Expose children and grandchildren of first topic at current |
5311 | level, and expose children of subsequent topics at current | |
5312 | level *except* for the last, which should be opened completely." | |
651eaf36 AS |
5313 | `(save-excursion |
5314 | (if (not (or (allout-goto-prefix-doublechecked) | |
5315 | (allout-next-heading))) | |
5316 | (error "allout-new-exposure: Can't find any outline topics")) | |
5317 | (allout-expose-topic ',spec))) | |
c567ac01 | 5318 | |
60c7bbd2 | 5319 | ;;;_ #7 Systematic outline presentation -- copying, printing, flattening |
19b84ba3 | 5320 | |
9179616f DL |
5321 | ;;;_ - Mapping and processing of topics |
5322 | ;;;_ ( See also Subtree Charting, in Navigation code.) | |
fd5359c6 MR |
5323 | ;;;_ > allout-stringify-flat-index (flat-index) |
5324 | (defun allout-stringify-flat-index (flat-index &optional context) | |
9179616f DL |
5325 | "Convert list representing section/subsection/... to document string. |
5326 | ||
5327 | Optional arg CONTEXT indicates interior levels to include." | |
5328 | (let ((delim ".") | |
71296446 | 5329 | result |
9179616f DL |
5330 | numstr |
5331 | (context-depth (or (and context 2) 1))) | |
5332 | ;; Take care of the explicit context: | |
5333 | (while (> context-depth 0) | |
5334 | (setq numstr (int-to-string (car flat-index)) | |
5335 | flat-index (cdr flat-index) | |
5336 | result (if flat-index | |
5337 | (cons delim (cons numstr result)) | |
5338 | (cons numstr result)) | |
5339 | context-depth (if flat-index (1- context-depth) 0))) | |
5340 | (setq delim " ") | |
5341 | ;; Take care of the indentation: | |
5342 | (if flat-index | |
5343 | (progn | |
5344 | (while flat-index | |
5345 | (setq result | |
5346 | (cons delim | |
5347 | (cons (make-string | |
5348 | (1+ (truncate (if (zerop (car flat-index)) | |
5349 | 1 | |
5350 | (log10 (car flat-index))))) | |
5351 | ? ) | |
5352 | result))) | |
5353 | (setq flat-index (cdr flat-index))) | |
5354 | ;; Dispose of single extra delim: | |
5355 | (setq result (cdr result)))) | |
5356 | (apply 'concat result))) | |
fd5359c6 MR |
5357 | ;;;_ > allout-stringify-flat-index-plain (flat-index) |
5358 | (defun allout-stringify-flat-index-plain (flat-index) | |
9179616f DL |
5359 | "Convert list representing section/subsection/... to document string." |
5360 | (let ((delim ".") | |
5361 | result) | |
5362 | (while flat-index | |
5363 | (setq result (cons (int-to-string (car flat-index)) | |
5364 | (if result | |
5365 | (cons delim result)))) | |
5366 | (setq flat-index (cdr flat-index))) | |
5367 | (apply 'concat result))) | |
fd5359c6 MR |
5368 | ;;;_ > allout-stringify-flat-index-indented (flat-index) |
5369 | (defun allout-stringify-flat-index-indented (flat-index) | |
9179616f DL |
5370 | "Convert list representing section/subsection/... to document string." |
5371 | (let ((delim ".") | |
71296446 | 5372 | result |
9179616f DL |
5373 | numstr) |
5374 | ;; Take care of the explicit context: | |
5375 | (setq numstr (int-to-string (car flat-index)) | |
5376 | flat-index (cdr flat-index) | |
5377 | result (if flat-index | |
5378 | (cons delim (cons numstr result)) | |
5379 | (cons numstr result))) | |
5380 | (setq delim " ") | |
5381 | ;; Take care of the indentation: | |
5382 | (if flat-index | |
5383 | (progn | |
5384 | (while flat-index | |
5385 | (setq result | |
5386 | (cons delim | |
5387 | (cons (make-string | |
5388 | (1+ (truncate (if (zerop (car flat-index)) | |
5389 | 1 | |
5390 | (log10 (car flat-index))))) | |
5391 | ? ) | |
5392 | result))) | |
5393 | (setq flat-index (cdr flat-index))) | |
5394 | ;; Dispose of single extra delim: | |
5395 | (setq result (cdr result)))) | |
5396 | (apply 'concat result))) | |
fd5359c6 MR |
5397 | ;;;_ > allout-listify-exposed (&optional start end format) |
5398 | (defun allout-listify-exposed (&optional start end format) | |
19b84ba3 | 5399 | |
9179616f | 5400 | "Produce a list representing exposed topics in current region. |
c567ac01 | 5401 | |
fd5359c6 | 5402 | This list can then be used by `allout-process-exposed' to manipulate |
9179616f | 5403 | the subject region. |
353e2ef2 | 5404 | |
9179616f | 5405 | Optional START and END indicate bounds of region. |
19b84ba3 | 5406 | |
75bcb912 | 5407 | Optional arg, FORMAT, designates an alternate presentation form for |
9179616f | 5408 | the prefix: |
c567ac01 | 5409 | |
60c7bbd2 | 5410 | list -- Present prefix as numeric section.subsection..., starting with |
9179616f | 5411 | section indicated by the list, innermost nesting first. |
60c7bbd2 | 5412 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5413 | except for distinctive bullets. |
c567ac01 | 5414 | |
9179616f DL |
5415 | The elements of the list produced are lists that represents a topic |
5416 | header and body. The elements of that list are: | |
c567ac01 | 5417 | |
9179616f DL |
5418 | - a number representing the depth of the topic, |
5419 | - a string representing the header-prefix, including trailing whitespace and | |
5420 | bullet. | |
5421 | - a string representing the bullet character, | |
5422 | - and a series of strings, each containing one line of the exposed | |
5423 | portion of the topic entry." | |
c567ac01 | 5424 | |
9179616f DL |
5425 | (interactive "r") |
5426 | (save-excursion | |
5427 | (let* | |
0458fa80 EZ |
5428 | ((inhibit-field-text-motion t) |
5429 | ;; state vars: | |
5430 | strings prefix result depth new-depth out gone-out bullet beg | |
9179616f | 5431 | next done) |
c567ac01 | 5432 | |
9179616f DL |
5433 | (goto-char start) |
5434 | (beginning-of-line) | |
97610156 | 5435 | ;; Goto initial topic, and register preceding stuff, if any: |
d8350998 | 5436 | (if (> (allout-goto-prefix-doublechecked) start) |
60c7bbd2 | 5437 | ;; First topic follows beginning point -- register preliminary stuff: |
3e2ee889 KM |
5438 | (setq result |
5439 | (list (list 0 "" nil | |
5440 | (buffer-substring-no-properties start | |
5441 | (1- (point))))))) | |
9179616f DL |
5442 | (while (and (not done) |
5443 | (not (eobp)) ; Loop until we've covered the region. | |
5444 | (not (> (point) end))) | |
d8350998 | 5445 | (setq depth allout-recent-depth ; Current topics depth, |
fd5359c6 MR |
5446 | bullet (allout-recent-bullet) ; ... bullet, |
5447 | prefix (allout-recent-prefix) | |
5448 | beg (progn (allout-end-of-prefix t) (point))) ; and beginning. | |
9179616f | 5449 | (setq done ; The boundary for the current topic: |
fd5359c6 | 5450 | (not (allout-next-visible-heading 1))) |
d8350998 | 5451 | (setq new-depth allout-recent-depth) |
9179616f DL |
5452 | (setq gone-out out |
5453 | out (< new-depth depth)) | |
5454 | (beginning-of-line) | |
5455 | (setq next (point)) | |
5456 | (goto-char beg) | |
5457 | (setq strings nil) | |
5458 | (while (> next (point)) ; Get all the exposed text in | |
5459 | (setq strings | |
3e2ee889 | 5460 | (cons (buffer-substring-no-properties |
9179616f DL |
5461 | beg |
5462 | ;To hidden text or end of line: | |
5463 | (progn | |
96b83743 EZ |
5464 | (end-of-line) |
5465 | (allout-back-to-visible-text))) | |
9179616f | 5466 | strings)) |
96b83743 | 5467 | (when (< (point) next) ; Resume from after hid text, if any. |
1b4d97b2 CY |
5468 | (line-move 1) |
5469 | (beginning-of-line)) | |
9179616f DL |
5470 | (setq beg (point))) |
5471 | ;; Accumulate list for this topic: | |
5472 | (setq strings (nreverse strings)) | |
5473 | (setq result | |
5474 | (cons | |
5475 | (if format | |
5476 | (let ((special (if (string-match | |
5477 | (regexp-quote bullet) | |
fd5359c6 | 5478 | allout-distinctive-bullets-string) |
9179616f DL |
5479 | bullet))) |
5480 | (cond ((listp format) | |
5481 | (list depth | |
96497653 | 5482 | (if allout-flattened-numbering-abbreviation |
fd5359c6 | 5483 | (allout-stringify-flat-index format |
9179616f | 5484 | gone-out) |
fd5359c6 | 5485 | (allout-stringify-flat-index-plain |
9179616f DL |
5486 | format)) |
5487 | strings | |
5488 | special)) | |
5489 | ((eq format 'indent) | |
5490 | (if special | |
5491 | (list depth | |
5492 | (concat (make-string (1+ depth) ? ) | |
5493 | (substring prefix -1)) | |
5494 | strings) | |
5495 | (list depth | |
5496 | (make-string depth ? ) | |
5497 | strings))) | |
fd5359c6 | 5498 | (t (error "allout-listify-exposed: %s %s" |
9179616f DL |
5499 | "invalid format" format)))) |
5500 | (list depth prefix strings)) | |
5501 | result)) | |
09e80d9f | 5502 | ;; Reassess format, if any: |
9179616f DL |
5503 | (if (and format (listp format)) |
5504 | (cond ((= new-depth depth) | |
5505 | (setq format (cons (1+ (car format)) | |
5506 | (cdr format)))) | |
60c7bbd2 | 5507 | ((> new-depth depth) ; descending -- assume by 1: |
9179616f DL |
5508 | (setq format (cons 1 format))) |
5509 | (t | |
5510 | ; Pop the residue: | |
5511 | (while (< new-depth depth) | |
5512 | (setq format (cdr format)) | |
5513 | (setq depth (1- depth))) | |
5514 | ; And increment the current one: | |
5515 | (setq format | |
5516 | (cons (1+ (or (car format) | |
5517 | -1)) | |
5518 | (cdr format))))))) | |
5519 | ;; Put the list with first at front, to last at back: | |
5520 | (nreverse result)))) | |
c60d543d RS |
5521 | ;;;_ > allout-region-active-p () |
5522 | (defmacro allout-region-active-p () | |
42c3e51c KM |
5523 | (cond ((fboundp 'use-region-p) '(use-region-p)) |
5524 | ((fboundp 'region-active-p) '(region-active-p)) | |
5525 | (t 'mark-active))) | |
5526 | ;;_ > allout-process-exposed (&optional func from to frombuf | |
9179616f | 5527 | ;;; tobuf format) |
fd5359c6 | 5528 | (defun allout-process-exposed (&optional func from to frombuf tobuf |
96b83743 | 5529 | format start-num) |
9179616f | 5530 | "Map function on exposed parts of current topic; results to another buffer. |
353e2ef2 | 5531 | |
d82979ea EZ |
5532 | All args are options; default values itemized below. |
5533 | ||
5534 | Apply FUNCTION to exposed portions FROM position TO position in buffer | |
9179616f DL |
5535 | FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an |
5536 | alternate presentation form: | |
c567ac01 | 5537 | |
60c7bbd2 | 5538 | `flat' -- Present prefix as numeric section.subsection..., starting with |
75bcb912 | 5539 | section indicated by the START-NUM, innermost nesting first. |
60c7bbd2 | 5540 | X`flat-indented' -- Prefix is like `flat' for first topic at each |
9179616f DL |
5541 | X level, but subsequent topics have only leaf topic |
5542 | X number, padded with blanks to line up with first. | |
60c7bbd2 | 5543 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5544 | except for distinctive bullets. |
c567ac01 | 5545 | |
9179616f | 5546 | Defaults: |
d82979ea | 5547 | FUNCTION: `allout-insert-listified' |
9179616f DL |
5548 | FROM: region start, if region active, else start of buffer |
5549 | TO: region end, if region active, else end of buffer | |
5550 | FROMBUF: current buffer | |
5551 | TOBUF: buffer name derived: \"*current-buffer-name exposed*\" | |
5552 | FORMAT: nil" | |
5553 | ||
5554 | ; Resolve arguments, | |
5555 | ; defaulting if necessary: | |
fd5359c6 | 5556 | (if (not func) (setq func 'allout-insert-listified)) |
9179616f | 5557 | (if (not (and from to)) |
c60d543d | 5558 | (if (allout-region-active-p) |
9179616f DL |
5559 | (setq from (region-beginning) to (region-end)) |
5560 | (setq from (point-min) to (point-max)))) | |
5561 | (if frombuf | |
5562 | (if (not (bufferp frombuf)) | |
60c7bbd2 | 5563 | ;; Specified but not a buffer -- get it: |
9179616f DL |
5564 | (let ((got (get-buffer frombuf))) |
5565 | (if (not got) | |
fd5359c6 | 5566 | (error (concat "allout-process-exposed: source buffer " |
9179616f DL |
5567 | frombuf |
5568 | " not found.")) | |
5569 | (setq frombuf got)))) | |
60c7bbd2 | 5570 | ;; not specified -- default it: |
9179616f DL |
5571 | (setq frombuf (current-buffer))) |
5572 | (if tobuf | |
5573 | (if (not (bufferp tobuf)) | |
5574 | (setq tobuf (get-buffer-create tobuf))) | |
60c7bbd2 | 5575 | ;; not specified -- default it: |
9179616f DL |
5576 | (setq tobuf (concat "*" (buffer-name frombuf) " exposed*"))) |
5577 | (if (listp format) | |
5578 | (nreverse format)) | |
5579 | ||
5580 | (let* ((listified | |
5581 | (progn (set-buffer frombuf) | |
fd5359c6 | 5582 | (allout-listify-exposed from to format)))) |
9179616f | 5583 | (set-buffer tobuf) |
5110e166 | 5584 | (mapc func listified) |
9179616f DL |
5585 | (pop-to-buffer tobuf))) |
5586 | ||
5587 | ;;;_ - Copy exposed | |
fd5359c6 MR |
5588 | ;;;_ > allout-insert-listified (listified) |
5589 | (defun allout-insert-listified (listified) | |
9179616f DL |
5590 | "Insert contents of listified outline portion in current buffer. |
5591 | ||
e126900f | 5592 | LISTIFIED is a list representing each topic header and body: |
9179616f DL |
5593 | |
5594 | \`(depth prefix text)' | |
5595 | ||
d82979ea | 5596 | or \`(depth prefix text bullet-plus)' |
9179616f DL |
5597 | |
5598 | If `bullet-plus' is specified, it is inserted just after the entire prefix." | |
5599 | (setq listified (cdr listified)) | |
5600 | (let ((prefix (prog1 | |
5601 | (car listified) | |
5602 | (setq listified (cdr listified)))) | |
5603 | (text (prog1 | |
5604 | (car listified) | |
5605 | (setq listified (cdr listified)))) | |
5606 | (bullet-plus (car listified))) | |
eac9cf5f PJ |
5607 | (insert prefix) |
5608 | (if bullet-plus (insert (concat " " bullet-plus))) | |
9179616f | 5609 | (while text |
eac9cf5f | 5610 | (insert (car text)) |
9179616f | 5611 | (if (setq text (cdr text)) |
0949617b | 5612 | (insert "\n"))) |
eac9cf5f | 5613 | (insert "\n"))) |
fd5359c6 MR |
5614 | ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format) |
5615 | (defun allout-copy-exposed-to-buffer (&optional arg tobuf format) | |
9179616f DL |
5616 | "Duplicate exposed portions of current outline to another buffer. |
5617 | ||
5618 | Other buffer has current buffers name with \" exposed\" appended to it. | |
5619 | ||
5620 | With repeat count, copy the exposed parts of only the current topic. | |
5621 | ||
5622 | Optional second arg TOBUF is target buffer name. | |
5623 | ||
5624 | Optional third arg FORMAT, if non-nil, symbolically designates an | |
5625 | alternate presentation format for the outline: | |
5626 | ||
5627 | `flat' - Convert topic header prefixes to numeric | |
5628 | section.subsection... identifiers. | |
5629 | `indent' - Convert header prefixes to all white space, except for | |
5630 | distinctive bullets. | |
5631 | `indent-flat' - The best of both - only the first of each level has | |
5632 | the full path, the rest have only the section number | |
5633 | of the leaf, preceded by the right amount of indentation." | |
c567ac01 RS |
5634 | |
5635 | (interactive "P") | |
5636 | (if (not tobuf) | |
5637 | (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*")))) | |
5638 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5639 | (beg (if arg (allout-back-to-current-heading) (point-min))) |
5640 | (end (if arg (allout-end-of-current-subtree) (point-max))) | |
9179616f DL |
5641 | (buf (current-buffer)) |
5642 | (start-list ())) | |
5643 | (if (eq format 'flat) | |
5644 | (setq format (if arg (save-excursion | |
5645 | (goto-char beg) | |
fd5359c6 | 5646 | (allout-topic-flat-index)) |
9179616f | 5647 | '(1)))) |
7fdbcd83 | 5648 | (with-current-buffer tobuf (erase-buffer)) |
fd5359c6 | 5649 | (allout-process-exposed 'allout-insert-listified |
c567ac01 RS |
5650 | beg |
5651 | end | |
5652 | (current-buffer) | |
9179616f DL |
5653 | tobuf |
5654 | format start-list) | |
c567ac01 RS |
5655 | (goto-char (point-min)) |
5656 | (pop-to-buffer buf) | |
5657 | (goto-char start-pt))) | |
fd5359c6 MR |
5658 | ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf) |
5659 | (defun allout-flatten-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5660 | "Present numeric outline of outline's exposed portions in another buffer. |
5661 | ||
60c7bbd2 | 5662 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5663 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5664 | |
fd5359c6 | 5665 | Use `allout-indented-exposed-to-buffer' for indented presentation. |
9179616f DL |
5666 | |
5667 | With repeat count, copy the exposed portions of only current topic. | |
5668 | ||
e126900f | 5669 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5670 | it, unless optional second arg TOBUF is specified, in which case it is |
5671 | used verbatim." | |
5672 | (interactive "P") | |
fd5359c6 MR |
5673 | (allout-copy-exposed-to-buffer arg tobuf 'flat)) |
5674 | ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf) | |
5675 | (defun allout-indented-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5676 | "Present indented outline of outline's exposed portions in another buffer. |
5677 | ||
60c7bbd2 | 5678 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5679 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5680 | |
fd5359c6 | 5681 | Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation. |
9179616f DL |
5682 | |
5683 | With repeat count, copy the exposed portions of only current topic. | |
5684 | ||
e126900f | 5685 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5686 | it, unless optional second arg TOBUF is specified, in which case it is |
5687 | used verbatim." | |
5688 | (interactive "P") | |
fd5359c6 | 5689 | (allout-copy-exposed-to-buffer arg tobuf 'indent)) |
c567ac01 RS |
5690 | |
5691 | ;;;_ - LaTeX formatting | |
e126900f JB |
5692 | ;;;_ > allout-latex-verb-quote (string &optional flow) |
5693 | (defun allout-latex-verb-quote (string &optional flow) | |
539d7736 | 5694 | "Return copy of STRING for literal reproduction across LaTeX processing. |
c07583cd | 5695 | Expresses the original characters (including carriage returns) of the |
539d7736 | 5696 | string across LaTeX processing." |
9179616f DL |
5697 | (mapconcat (function |
5698 | (lambda (char) | |
c567ac01 RS |
5699 | (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*)) |
5700 | (concat "\\char" (number-to-string char) "{}")) | |
5701 | ((= char ?\n) "\\\\") | |
9179616f | 5702 | (t (char-to-string char))))) |
e126900f | 5703 | string |
c567ac01 | 5704 | "")) |
fd5359c6 MR |
5705 | ;;;_ > allout-latex-verbatim-quote-curr-line () |
5706 | (defun allout-latex-verbatim-quote-curr-line () | |
c07583cd | 5707 | "Express line for exact (literal) representation across LaTeX processing. |
19b84ba3 | 5708 | |
c07583cd | 5709 | Adjust line contents so it is unaltered (from the original line) |
539d7736 | 5710 | across LaTeX processing, within the context of a `verbatim' |
c567ac01 | 5711 | environment. Leaves point at the end of the line." |
0458fa80 EZ |
5712 | (let ((inhibit-field-text-motion t)) |
5713 | (beginning-of-line) | |
5714 | (let ((beg (point)) | |
626b459f | 5715 | (end (point-at-eol))) |
2a1408fd DN |
5716 | (save-match-data |
5717 | (while (re-search-forward "\\\\" | |
5718 | ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#" | |
5719 | end ; bounded by end-of-line | |
5720 | 1) ; no matches, move to end & return nil | |
5721 | (goto-char (match-beginning 2)) | |
5722 | (insert "\\") | |
5723 | (setq end (1+ end)) | |
5724 | (goto-char (1+ (match-end 2)))))))) | |
e126900f JB |
5725 | ;;;_ > allout-insert-latex-header (buffer) |
5726 | (defun allout-insert-latex-header (buffer) | |
539d7736 | 5727 | "Insert initial LaTeX commands at point in BUFFER." |
c567ac01 RS |
5728 | ;; Much of this is being derived from the stuff in appendix of E in |
5729 | ;; the TeXBook, pg 421. | |
e126900f | 5730 | (set-buffer buffer) |
c567ac01 RS |
5731 | (let ((doc-style (format "\n\\documentstyle{%s}\n" |
5732 | "report")) | |
fd5359c6 | 5733 | (page-numbering (if allout-number-pages |
c567ac01 RS |
5734 | "\\pagestyle{empty}\n" |
5735 | "")) | |
c567ac01 | 5736 | (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5737 | allout-title-style)) |
c567ac01 | 5738 | (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n" |
fd5359c6 | 5739 | allout-label-style)) |
c567ac01 | 5740 | (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5741 | allout-head-line-style)) |
c567ac01 | 5742 | (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5743 | allout-body-line-style)) |
c567ac01 RS |
5744 | (setlength (format "%s%s%s%s" |
5745 | "\\newlength{\\stepsize}\n" | |
5746 | "\\setlength{\\stepsize}{" | |
fd5359c6 | 5747 | allout-indent |
c567ac01 RS |
5748 | "}\n")) |
5749 | (oneheadline (format "%s%s%s%s%s%s%s" | |
5750 | "\\newcommand{\\OneHeadLine}[3]{%\n" | |
5751 | "\\noindent%\n" | |
5752 | "\\hspace*{#2\\stepsize}%\n" | |
5753 | "\\labelcmd{#1}\\hspace*{.2cm}" | |
5754 | "\\headlinecmd{#3}\\\\[" | |
fd5359c6 | 5755 | allout-line-skip |
c567ac01 RS |
5756 | "]\n}\n")) |
5757 | (onebodyline (format "%s%s%s%s%s%s" | |
5758 | "\\newcommand{\\OneBodyLine}[2]{%\n" | |
5759 | "\\noindent%\n" | |
5760 | "\\hspace*{#1\\stepsize}%\n" | |
5761 | "\\bodylinecmd{#2}\\\\[" | |
fd5359c6 | 5762 | allout-line-skip |
c567ac01 RS |
5763 | "]\n}\n")) |
5764 | (begindoc "\\begin{document}\n\\begin{center}\n") | |
5765 | (title (format "%s%s%s%s" | |
5766 | "\\titlecmd{" | |
fd5359c6 | 5767 | (allout-latex-verb-quote (if allout-title |
96b83743 | 5768 | (condition-case nil |
fd5359c6 | 5769 | (eval allout-title) |
d8350998 | 5770 | (error "<unnamed buffer>")) |
c567ac01 RS |
5771 | "Unnamed Outline")) |
5772 | "}\n" | |
5773 | "\\end{center}\n\n")) | |
5774 | (hsize "\\hsize = 7.5 true in\n") | |
5775 | (hoffset "\\hoffset = -1.5 true in\n") | |
5776 | (vspace "\\vspace{.1cm}\n\n")) | |
5777 | (insert (concat doc-style | |
5778 | page-numbering | |
5779 | titlecmd | |
5780 | labelcmd | |
5781 | headlinecmd | |
5782 | bodylinecmd | |
5783 | setlength | |
5784 | oneheadline | |
5785 | onebodyline | |
5786 | begindoc | |
5787 | title | |
5788 | hsize | |
5789 | hoffset | |
5790 | vspace) | |
5791 | ))) | |
e126900f JB |
5792 | ;;;_ > allout-insert-latex-trailer (buffer) |
5793 | (defun allout-insert-latex-trailer (buffer) | |
539d7736 | 5794 | "Insert concluding LaTeX commands at point in BUFFER." |
e126900f | 5795 | (set-buffer buffer) |
c567ac01 | 5796 | (insert "\n\\end{document}\n")) |
fd5359c6 MR |
5797 | ;;;_ > allout-latexify-one-item (depth prefix bullet text) |
5798 | (defun allout-latexify-one-item (depth prefix bullet text) | |
19b84ba3 RS |
5799 | "Insert LaTeX commands for formatting one outline item. |
5800 | ||
9179616f | 5801 | Args are the topics numeric DEPTH, the header PREFIX lead string, the |
19b84ba3 | 5802 | BULLET string, and a list of TEXT strings for the body." |
c567ac01 RS |
5803 | (let* ((head-line (if text (car text))) |
5804 | (body-lines (cdr text)) | |
5805 | (curr-line) | |
5806 | body-content bop) | |
5807 | ; Do the head line: | |
71296446 | 5808 | (insert (concat "\\OneHeadLine{\\verb\1 " |
d82979ea EZ |
5809 | (allout-latex-verb-quote bullet) |
5810 | "\1}{" | |
5811 | depth | |
5812 | "}{\\verb\1 " | |
5813 | (if head-line | |
5814 | (allout-latex-verb-quote head-line) | |
5815 | "") | |
5816 | "\1}\n")) | |
c567ac01 RS |
5817 | (if (not body-lines) |
5818 | nil | |
eac9cf5f PJ |
5819 | ;;(insert "\\beginlines\n") |
5820 | (insert "\\begin{verbatim}\n") | |
c567ac01 RS |
5821 | (while body-lines |
5822 | (setq curr-line (car body-lines)) | |
5823 | (if (and (not body-content) | |
5824 | (not (string-match "^\\s-*$" curr-line))) | |
5825 | (setq body-content t)) | |
5826 | ; Mangle any occurrences of | |
5827 | ; "\end{verbatim}" in text, | |
5828 | ; it's special: | |
5829 | (if (and body-content | |
5830 | (setq bop (string-match "\\end{verbatim}" curr-line))) | |
5831 | (setq curr-line (concat (substring curr-line 0 bop) | |
5832 | ">" | |
5833 | (substring curr-line bop)))) | |
eac9cf5f PJ |
5834 | ;;(insert "|" (car body-lines) "|") |
5835 | (insert curr-line) | |
fd5359c6 | 5836 | (allout-latex-verbatim-quote-curr-line) |
eac9cf5f | 5837 | (insert "\n") |
c567ac01 RS |
5838 | (setq body-lines (cdr body-lines))) |
5839 | (if body-content | |
5840 | (setq body-content nil) | |
5841 | (forward-char -1) | |
eac9cf5f | 5842 | (insert "\\ ") |
c567ac01 | 5843 | (forward-char 1)) |
eac9cf5f PJ |
5844 | ;;(insert "\\endlines\n") |
5845 | (insert "\\end{verbatim}\n") | |
c567ac01 | 5846 | ))) |
fd5359c6 MR |
5847 | ;;;_ > allout-latexify-exposed (arg &optional tobuf) |
5848 | (defun allout-latexify-exposed (arg &optional tobuf) | |
539d7736 | 5849 | "Format current topics exposed portions to TOBUF for LaTeX processing. |
19b84ba3 RS |
5850 | TOBUF defaults to a buffer named the same as the current buffer, but |
5851 | with \"*\" prepended and \" latex-formed*\" appended. | |
c567ac01 RS |
5852 | |
5853 | With repeat count, copy the exposed portions of entire buffer." | |
5854 | ||
5855 | (interactive "P") | |
5856 | (if (not tobuf) | |
5857 | (setq tobuf | |
5858 | (get-buffer-create (concat "*" (buffer-name) " latexified*")))) | |
5859 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5860 | (beg (if arg (point-min) (allout-back-to-current-heading))) |
5861 | (end (if arg (point-max) (allout-end-of-current-subtree))) | |
c567ac01 RS |
5862 | (buf (current-buffer))) |
5863 | (set-buffer tobuf) | |
1977b8f6 | 5864 | (erase-buffer) |
fd5359c6 | 5865 | (allout-insert-latex-header tobuf) |
c567ac01 | 5866 | (goto-char (point-max)) |
fd5359c6 | 5867 | (allout-process-exposed 'allout-latexify-one-item |
c567ac01 RS |
5868 | beg |
5869 | end | |
5870 | buf | |
5871 | tobuf) | |
5872 | (goto-char (point-max)) | |
fd5359c6 | 5873 | (allout-insert-latex-trailer tobuf) |
1977b8f6 | 5874 | (goto-char (point-min)) |
c567ac01 RS |
5875 | (pop-to-buffer buf) |
5876 | (goto-char start-pt))) | |
5877 | ||
d82979ea | 5878 | ;;;_ #8 Encryption |
29fac3fe KM |
5879 | ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue) |
5880 | (defun allout-toggle-current-subtree-encryption (&optional keymode-cue) | |
5881 | "Encrypt clear or decrypt encoded topic text. | |
5882 | ||
20db1522 | 5883 | Allout uses Emacs 'epg' library to perform encryption. Symmetric |
29fac3fe KM |
5884 | and keypair encryption are supported. All encryption is ascii |
5885 | armored. | |
5886 | ||
075746e2 | 5887 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 5888 | recipients are associated with the file (see |
075746e2 KM |
5889 | `epa-file-encrypt-to') or the function is invoked with a |
5890 | \(KEYMODE-CUE) universal argument greater than 1. | |
5891 | ||
5892 | When encrypting, KEYMODE-CUE universal argument greater than 1 | |
5893 | causes prompting for recipients for public-key keypair | |
5894 | encryption. Selecting no recipients results in symmetric key | |
29fac3fe KM |
5895 | encryption. |
5896 | ||
075746e2 KM |
5897 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5898 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5899 | the specified recipients with the file, replacing those currently | |
99d99081 | 5900 | associated with it. This can be used to dissociate any |
075746e2 KM |
5901 | recipients with the file, by selecting no recipients in the |
5902 | dialog. | |
5903 | ||
29fac3fe KM |
5904 | Encrypted topic's bullets are set to a `~' to signal that the |
5905 | contents of the topic (body and subtopics, but not heading) is | |
5906 | pending encryption or encrypted. `*' asterisk immediately after | |
5907 | the bullet signals that the body is encrypted, its absence means | |
5908 | the topic is meant to be encrypted but is not currently. When a | |
5909 | file with topics pending encryption is saved, topics pending | |
20db1522 | 5910 | encryption are encrypted. See `allout-encrypt-unencrypted-on-saves' |
29fac3fe | 5911 | for auto-encryption specifics. |
0949617b | 5912 | |
6eb0a10d | 5913 | \*NOTE WELL* that automatic encryption that happens during saves will |
60c7bbd2 | 5914 | default to symmetric encryption -- you must deliberately (re)encrypt key-pair |
0949617b | 5915 | encrypted topics if you want them to continue to use the key-pair cipher. |
d82979ea | 5916 | |
d8350998 | 5917 | Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be |
d82979ea | 5918 | encrypted. If you want to encrypt the contents of a top-level topic, use |
29fac3fe | 5919 | \\[allout-shift-in] to increase its depth." |
69027dea EZ |
5920 | (interactive "P") |
5921 | (save-excursion | |
5922 | (allout-back-to-current-heading) | |
29fac3fe KM |
5923 | (allout-toggle-subtree-encryption keymode-cue))) |
5924 | ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue) | |
5925 | (defun allout-toggle-subtree-encryption (&optional keymode-cue) | |
c07583cd | 5926 | "Encrypt clear text or decrypt encoded topic contents (body and subtopics.) |
69027dea | 5927 | |
075746e2 | 5928 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 5929 | recipients are associated with the file (see |
075746e2 KM |
5930 | `epa-file-encrypt-to') or the function is invoked with a |
5931 | \(KEYMODE-CUE) universal argument greater than 1. | |
69027dea | 5932 | |
075746e2 KM |
5933 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
5934 | causes prompting for recipients for public-key keypair | |
5935 | encryption. Selecting no recipients results in symmetric key | |
5936 | encryption. | |
69027dea | 5937 | |
075746e2 KM |
5938 | Further, encrypting with a KEYMODE-CUE universal argument greater |
5939 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
5940 | the specified recipients with the file, replacing those currently | |
99d99081 | 5941 | associated with it. This can be used to dissociate any |
075746e2 KM |
5942 | recipients with the file, by selecting no recipients in the |
5943 | dialog. | |
5944 | ||
20db1522 | 5945 | Encryption and decryption uses the Emacs 'epg' library. |
69027dea | 5946 | |
29fac3fe | 5947 | Encrypted text will be ascii-armored. |
69027dea EZ |
5948 | |
5949 | See `allout-toggle-current-subtree-encryption' for more details." | |
d82979ea EZ |
5950 | |
5951 | (interactive "P") | |
5952 | (save-excursion | |
5953 | (allout-end-of-prefix t) | |
5954 | ||
d8350998 | 5955 | (if (= allout-recent-depth 1) |
d82979ea EZ |
5956 | (error (concat "Cannot encrypt or decrypt level 1 topics -" |
5957 | " shift it in to make it encryptable"))) | |
5958 | ||
d82979ea | 5959 | (let* ((allout-buffer (current-buffer)) |
13aa217b KM |
5960 | ;; for use with allout-auto-save-temporarily-disabled, if necessary: |
5961 | (was-buffer-saved-size buffer-saved-size) | |
498a6493 | 5962 | ;; Assess location: |
d8350998 | 5963 | (bullet-pos allout-recent-prefix-beginning) |
d82979ea EZ |
5964 | (after-bullet-pos (point)) |
5965 | (was-encrypted | |
5966 | (progn (if (= (point-max) after-bullet-pos) | |
5967 | (error "no body to encrypt")) | |
0949617b | 5968 | (allout-encrypted-topic-p))) |
96b83743 | 5969 | (was-collapsed (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
5970 | nil |
5971 | (backward-char 1) | |
96b83743 | 5972 | (allout-hidden-p))) |
d82979ea EZ |
5973 | (subtree-beg (1+ (point))) |
5974 | (subtree-end (allout-end-of-subtree)) | |
5975 | (subject-text (buffer-substring-no-properties subtree-beg | |
5976 | subtree-end)) | |
5977 | (subtree-end-char (char-after (1- subtree-end))) | |
96b83743 | 5978 | (subtree-trailing-char (char-after subtree-end)) |
60c7bbd2 | 5979 | ;; kluge -- result-text needs to be nil, but we also want to |
96b83743 EZ |
5980 | ;; check for the error condition |
5981 | (result-text (if (or (string= "" subject-text) | |
5982 | (string= "\n" subject-text)) | |
5983 | (error "No topic contents to %scrypt" | |
5984 | (if was-encrypted "de" "en")) | |
5985 | nil)) | |
d82979ea | 5986 | ;; Assess key parameters: |
498a6493 CY |
5987 | (was-coding-system buffer-file-coding-system)) |
5988 | ||
5989 | (when (not was-encrypted) | |
5990 | ;; ensure that non-ascii chars pending encryption are noticed before | |
116f996b | 5991 | ;; they're encrypted, so the coding system is set to accommodate |
498a6493 CY |
5992 | ;; them. |
5993 | (setq buffer-file-coding-system | |
1c9b9df0 | 5994 | (allout-select-safe-coding-system subtree-beg subtree-end)) |
498a6493 CY |
5995 | ;; if the coding system for the text being encrypted is different |
5996 | ;; than that prevailing, then there a real risk that the coding | |
5997 | ;; system can't be noticed by emacs when the file is visited. to | |
5998 | ;; mitigate that, offer to preserve the coding system using a file | |
5999 | ;; local variable. | |
6000 | (if (and (not (equal buffer-file-coding-system | |
6001 | was-coding-system)) | |
6002 | (yes-or-no-p | |
6003 | (format (concat "Register coding system %s as file local" | |
6004 | " var? Necessary when only encrypted text" | |
6005 | " is in that coding system. ") | |
6006 | buffer-file-coding-system))) | |
6007 | (allout-adjust-file-variable "buffer-file-coding-system" | |
6008 | buffer-file-coding-system))) | |
d82979ea EZ |
6009 | |
6010 | (setq result-text | |
6011 | (allout-encrypt-string subject-text was-encrypted | |
075746e2 | 6012 | (current-buffer) keymode-cue)) |
d82979ea EZ |
6013 | |
6014 | ;; Replace the subtree with the processed product. | |
6015 | (allout-unprotected | |
6016 | (progn | |
6017 | (set-buffer allout-buffer) | |
6018 | (delete-region subtree-beg subtree-end) | |
6019 | (insert result-text) | |
6020 | (if was-collapsed | |
96b83743 EZ |
6021 | (allout-flag-region (1- subtree-beg) (point) t)) |
6022 | ;; adjust trailing-blank-lines to preserve topic spacing: | |
d82979ea | 6023 | (if (not was-encrypted) |
96b83743 EZ |
6024 | (if (and (= subtree-end-char ?\n) |
6025 | (= subtree-trailing-char ?\n)) | |
6026 | (insert subtree-trailing-char))) | |
d82979ea EZ |
6027 | ;; Ensure that the item has an encrypted-entry bullet: |
6028 | (if (not (string= (buffer-substring-no-properties | |
6029 | (1- after-bullet-pos) after-bullet-pos) | |
6030 | allout-topic-encryption-bullet)) | |
6031 | (progn (goto-char (1- after-bullet-pos)) | |
6032 | (delete-char 1) | |
6033 | (insert allout-topic-encryption-bullet))) | |
6034 | (if was-encrypted | |
6035 | ;; Remove the is-encrypted bullet qualifier: | |
6036 | (progn (goto-char after-bullet-pos) | |
6037 | (delete-char 1)) | |
6038 | ;; Add the is-encrypted bullet qualifier: | |
6039 | (goto-char after-bullet-pos) | |
d8350998 | 6040 | (insert "*")))) |
13aa217b KM |
6041 | |
6042 | ;; adjust buffer's auto-save eligibility: | |
6043 | (if was-encrypted | |
6044 | (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size) | |
6045 | (allout-maybe-resume-auto-save-info-after-encryption)) | |
6046 | ||
7b97c764 | 6047 | (run-hook-with-args 'allout-structure-added-functions |
1b4d97b2 | 6048 | bullet-pos subtree-end)))) |
075746e2 | 6049 | ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 6050 | ;;; &optional rejected) |
075746e2 | 6051 | (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue |
29fac3fe | 6052 | &optional rejected) |
0949617b | 6053 | "Encrypt or decrypt message TEXT. |
d82979ea | 6054 | |
ff3e8c8e | 6055 | Returns the resulting string, or nil if the transformation fails. |
d82979ea | 6056 | |
ff3e8c8e | 6057 | If DECRYPT is true (default false), then decrypt instead of encrypt. |
d82979ea | 6058 | |
ff3e8c8e | 6059 | ALLOUT-BUFFER identifies the buffer containing the text. |
d82979ea | 6060 | |
075746e2 | 6061 | Entry encryption defaults to symmetric key mode unless keypair |
20db1522 | 6062 | recipients are associated with the file (see |
075746e2 KM |
6063 | `epa-file-encrypt-to') or the function is invoked with a |
6064 | \(KEYMODE-CUE) universal argument greater than 1. | |
d82979ea | 6065 | |
075746e2 KM |
6066 | When encrypting, KEYMODE-CUE universal argument greater than 1 |
6067 | causes prompting for recipients for public-key keypair | |
6068 | encryption. Selecting no recipients results in symmetric key | |
6069 | encryption. | |
0949617b | 6070 | |
075746e2 KM |
6071 | Further, encrypting with a KEYMODE-CUE universal argument greater |
6072 | than 4 - eg, preceded by a doubled Ctrl-U - causes association of | |
6073 | the specified recipients with the file, replacing those currently | |
99d99081 | 6074 | associated with it. This can be used to dissociate any |
075746e2 KM |
6075 | recipients with the file, by selecting no recipients in the |
6076 | dialog. | |
d82979ea | 6077 | |
29fac3fe | 6078 | Optional REJECTED is for internal use, to convey the number of |
48bd8440 EZ |
6079 | rejections due to matches against |
6080 | `allout-encryption-ciphertext-rejection-regexps', as limited by | |
6081 | `allout-encryption-ciphertext-rejection-ceiling'. | |
6082 | ||
2576c28f KM |
6083 | NOTE: A few GnuPG v2 versions improperly preserve incorrect |
6084 | symmetric decryption keys, preventing entry of the correct key on | |
6085 | subsequent decryption attempts until the cache times-out. That | |
20db1522 | 6086 | can take several minutes. (Decryption of other entries is not |
2576c28f KM |
6087 | affected.) Upgrade your EasyPG version, if you can, and you can |
6088 | deliberately clear your gpg-agent's cache by sending it a '-HUP' | |
6089 | signal." | |
48bd8440 | 6090 | |
ff3e8c8e | 6091 | (require 'epg) |
29fac3fe | 6092 | (require 'epa) |
0949617b | 6093 | |
075746e2 KM |
6094 | (let* ((epg-context (let* ((context (epg-make-context nil t))) |
6095 | (epg-context-set-passphrase-callback | |
6096 | context #'epa-passphrase-callback-function) | |
6097 | context)) | |
13aa217b | 6098 | |
498a6493 CY |
6099 | (encoding (with-current-buffer allout-buffer |
6100 | buffer-file-coding-system)) | |
6101 | (multibyte (with-current-buffer allout-buffer | |
ff3e8c8e | 6102 | enable-multibyte-characters)) |
29fac3fe KM |
6103 | ;; "sanitization" avoids encryption results that are outline structure. |
6104 | (sani-regexps 'allout-encryption-plaintext-sanitization-regexps) | |
6105 | (strip-plaintext-regexps (if (not decrypt) | |
6106 | (allout-get-configvar-values | |
6107 | sani-regexps))) | |
6108 | (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps) | |
6109 | (reject-ciphertext-regexps (if (not decrypt) | |
6110 | (allout-get-configvar-values | |
6111 | rejection-regexps))) | |
48bd8440 EZ |
6112 | (rejected (or rejected 0)) |
6113 | (rejections-left (- allout-encryption-ciphertext-rejection-ceiling | |
6114 | rejected)) | |
075746e2 KM |
6115 | (keypair-mode (cond (decrypt 'decrypting) |
6116 | ((<= (prefix-numeric-value keymode-cue) 1) | |
6117 | 'default) | |
6118 | ((<= (prefix-numeric-value keymode-cue) 4) | |
6119 | 'prompt) | |
6120 | ((> (prefix-numeric-value keymode-cue) 4) | |
6121 | 'prompt-save))) | |
6122 | (keypair-message (concat "Select encryption recipients.\n" | |
6123 | "Symmetric encryption is done if no" | |
6124 | " recipients are selected. ")) | |
6125 | (encrypt-to (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to)) | |
29fac3fe KM |
6126 | recipients |
6127 | massaged-text | |
6128 | result-text | |
38b2ca53 | 6129 | ) |
0949617b | 6130 | |
ff3e8c8e KM |
6131 | ;; Massage the subject text for encoding and filtering. |
6132 | (with-temp-buffer | |
6133 | (insert text) | |
6134 | ;; convey the text characteristics of the original buffer: | |
96497653 | 6135 | (set-buffer-multibyte multibyte) |
ff3e8c8e KM |
6136 | (when encoding |
6137 | (set-buffer-file-coding-system encoding) | |
6138 | (if (not decrypt) | |
6139 | (encode-coding-region (point-min) (point-max) encoding))) | |
6140 | ||
6141 | ;; remove sanitization regexps matches before encrypting: | |
6142 | (when (and strip-plaintext-regexps (not decrypt)) | |
6143 | (dolist (re strip-plaintext-regexps) | |
6144 | (let ((re (if (listp re) (car re) re)) | |
6145 | (replacement (if (listp re) (cadr re) ""))) | |
6146 | (goto-char (point-min)) | |
6147 | (save-match-data | |
6148 | (while (re-search-forward re nil t) | |
6149 | (replace-match replacement nil nil)))))) | |
6150 | (setq massaged-text (buffer-substring-no-properties (point-min) | |
6151 | (point-max)))) | |
075746e2 KM |
6152 | ;; determine key mode and, if keypair, recipients: |
6153 | (setq recipients | |
6154 | (case keypair-mode | |
6155 | ||
6156 | (decrypting nil) | |
6157 | ||
6158 | (default (if encrypt-to (epg-list-keys epg-context encrypt-to))) | |
6159 | ||
6160 | ((prompt prompt-save) | |
6161 | (save-window-excursion | |
6162 | (epa-select-keys epg-context keypair-message))))) | |
6163 | ||
ff3e8c8e | 6164 | (setq result-text |
ff3e8c8e | 6165 | (if decrypt |
2a095cec KM |
6166 | (condition-case err |
6167 | (epg-decrypt-string epg-context | |
6168 | (encode-coding-string massaged-text | |
6169 | (or encoding 'utf-8))) | |
6170 | (epg-error | |
6171 | (signal 'egp-error | |
6172 | (cons (concat (cadr err) " - gpg version problem?") | |
6173 | (cddr err))))) | |
0af8c88b KM |
6174 | (replace-regexp-in-string "\n$" "" |
6175 | (epg-encrypt-string epg-context | |
6176 | (encode-coding-string massaged-text | |
6177 | (or encoding 'utf-8)) | |
6178 | recipients)))) | |
ff3e8c8e KM |
6179 | |
6180 | ;; validate result -- non-empty | |
075746e2 KM |
6181 | (if (not result-text) |
6182 | (error "%scryption failed." (if decrypt "De" "En"))) | |
6183 | ||
29fac3fe | 6184 | |
075746e2 KM |
6185 | (when (eq keypair-mode 'prompt-save) |
6186 | ;; set epa-file-encrypt-to in the buffer: | |
6187 | (setq epa-file-encrypt-to (mapcar (lambda (key) | |
6188 | (epg-user-id-string | |
6189 | (car (epg-key-user-id-list key)))) | |
6190 | recipients)) | |
6191 | ;; change the file variable: | |
6192 | (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to)) | |
d82979ea | 6193 | |
075746e2 | 6194 | (cond |
29fac3fe KM |
6195 | ;; Retry (within limit) if ciphertext contains rejections: |
6196 | ((and (not decrypt) | |
6197 | ;; Check for disqualification of this ciphertext: | |
6198 | (let ((regexps reject-ciphertext-regexps) | |
6199 | reject-it) | |
6200 | (while (and regexps (not reject-it)) | |
6201 | (setq reject-it (string-match (car regexps) result-text)) | |
6202 | (pop regexps)) | |
6203 | reject-it)) | |
6204 | (setq rejections-left (1- rejections-left)) | |
6205 | (if (<= rejections-left 0) | |
6206 | (error (concat "Ciphertext rejected too many times" | |
6207 | " (%s), per `%s'") | |
6208 | allout-encryption-ciphertext-rejection-ceiling | |
6209 | 'allout-encryption-ciphertext-rejection-regexps) | |
6210 | ;; try again (gpg-agent may have the key cached): | |
6211 | (allout-encrypt-string text decrypt allout-buffer keypair-mode | |
6212 | (1+ rejected)))) | |
6213 | ||
6214 | ;; Barf if encryption yields extraordinary control chars: | |
6215 | ((and (not decrypt) | |
6216 | (string-match "[\C-a\C-k\C-o-\C-z\C-@]" | |
6217 | result-text)) | |
6218 | (error (concat "Encryption produced non-armored text, which" | |
6219 | "conflicts with allout mode -- reconfigure!"))) | |
29fac3fe | 6220 | (t result-text)))) |
13aa217b KM |
6221 | ;;;_ > allout-inhibit-auto-save-info-for-decryption |
6222 | (defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size) | |
6223 | "Temporarily prevent auto-saves in this buffer when an item is decrypted. | |
6224 | ||
20db1522 | 6225 | WAS-BUFFER-SAVED-SIZE is the value of `buffer-saved-size' *before* |
13aa217b KM |
6226 | the decryption." |
6227 | (when (not (or (= buffer-saved-size -1) (= was-buffer-saved-size -1))) | |
6228 | (setq allout-auto-save-temporarily-disabled was-buffer-saved-size | |
6229 | buffer-saved-size -1))) | |
6230 | ;;;_ > allout-maybe-resume-auto-save-info-after-encryption () | |
6231 | (defun allout-maybe-resume-auto-save-info-after-encryption () | |
6232 | "Restore auto-save info, *if* there are no topics pending encryption." | |
6233 | (when (and allout-auto-save-temporarily-disabled | |
6234 | (= buffer-saved-size -1) | |
6235 | (save-excursion | |
6236 | (save-restriction | |
6237 | (widen) | |
6238 | (goto-char (point-min)) | |
6239 | (not (allout-next-topic-pending-encryption))))) | |
6240 | (setq buffer-saved-size allout-auto-save-temporarily-disabled | |
6241 | allout-auto-save-temporarily-disabled nil))) | |
6242 | ||
d82979ea EZ |
6243 | ;;;_ > allout-encrypted-topic-p () |
6244 | (defun allout-encrypted-topic-p () | |
6245 | "True if the current topic is encryptable and encrypted." | |
6246 | (save-excursion | |
6247 | (allout-end-of-prefix t) | |
6248 | (and (string= (buffer-substring-no-properties (1- (point)) (point)) | |
6249 | allout-topic-encryption-bullet) | |
2a1408fd | 6250 | (save-match-data (looking-at "\\*"))) |
d82979ea EZ |
6251 | ) |
6252 | ) | |
13aa217b KM |
6253 | ;;;_ > allout-next-topic-pending-encryption () |
6254 | (defun allout-next-topic-pending-encryption () | |
d82979ea EZ |
6255 | "Return the point of the next topic pending encryption, or nil if none. |
6256 | ||
75bcb912 | 6257 | Such a topic has the `allout-topic-encryption-bullet' without an |
20db1522 JB |
6258 | immediately following '*' that would mark the topic as being encrypted. |
6259 | It must also have content." | |
d82979ea | 6260 | (let (done got content-beg) |
2a1408fd DN |
6261 | (save-match-data |
6262 | (while (not done) | |
d82979ea | 6263 | |
2a1408fd DN |
6264 | (if (not (re-search-forward |
6265 | (format "\\(\\`\\|\n\\)%s *%s[^*]" | |
6266 | (regexp-quote allout-header-prefix) | |
6267 | (regexp-quote allout-topic-encryption-bullet)) | |
6268 | nil t)) | |
6269 | (setq got nil | |
6270 | done t) | |
6271 | (goto-char (setq got (match-beginning 0))) | |
6272 | (if (save-match-data (looking-at "\n")) | |
6273 | (forward-char 1)) | |
6274 | (setq got (point))) | |
6275 | ||
6276 | (cond ((not got) | |
6277 | (setq done t)) | |
6278 | ||
6279 | ((not (search-forward "\n")) | |
6280 | (setq got nil | |
6281 | done t)) | |
6282 | ||
6283 | ((eobp) | |
6284 | (setq got nil | |
6285 | done t)) | |
6286 | ||
6287 | (t | |
6288 | (setq content-beg (point)) | |
6289 | (backward-char 1) | |
6290 | (allout-end-of-subtree) | |
13aa217b | 6291 | (if (<= (point) content-beg) |
2a1408fd DN |
6292 | ;; Continue looking |
6293 | (setq got nil) | |
6294 | ;; Got it! | |
6295 | (setq done t))) | |
6296 | ) | |
6297 | ) | |
6298 | (if got | |
6299 | (goto-char got)) | |
d82979ea | 6300 | ) |
d82979ea EZ |
6301 | ) |
6302 | ) | |
13aa217b KM |
6303 | ;;;_ > allout-encrypt-decrypted () |
6304 | (defun allout-encrypt-decrypted () | |
d82979ea EZ |
6305 | "Encrypt topics pending encryption except those containing exemption point. |
6306 | ||
d82979ea EZ |
6307 | If a topic that is currently being edited was encrypted, we return a list |
6308 | containing the location of the topic and the location of the cursor just | |
6309 | before the topic was encrypted. This can be used, eg, to decrypt the topic | |
6310 | and exactly resituate the cursor if this is being done as part of a file | |
6311 | save. See `allout-encrypt-unencrypted-on-saves' for more info." | |
6312 | ||
6313 | (interactive "p") | |
2a1408fd DN |
6314 | (save-match-data |
6315 | (save-excursion | |
6316 | (let* ((current-mark (point-marker)) | |
6317 | (current-mark-position (marker-position current-mark)) | |
6318 | was-modified | |
6319 | bo-subtree | |
6320 | editing-topic editing-point) | |
6321 | (goto-char (point-min)) | |
13aa217b | 6322 | (while (allout-next-topic-pending-encryption) |
2a1408fd DN |
6323 | (setq was-modified (buffer-modified-p)) |
6324 | (when (save-excursion | |
6325 | (and (boundp 'allout-encrypt-unencrypted-on-saves) | |
6326 | allout-encrypt-unencrypted-on-saves | |
6327 | (setq bo-subtree (re-search-forward "$")) | |
6328 | (not (allout-hidden-p)) | |
6329 | (>= current-mark (point)) | |
6330 | (allout-end-of-current-subtree) | |
6331 | (<= current-mark (point)))) | |
d82979ea EZ |
6332 | (setq editing-topic (point) |
6333 | ;; we had to wait for this 'til now so prior topics are | |
6334 | ;; encrypted, any relevant text shifts are in place: | |
96b83743 EZ |
6335 | editing-point (- current-mark-position |
6336 | (count-trailing-whitespace-region | |
6337 | bo-subtree current-mark-position)))) | |
2a1408fd DN |
6338 | (allout-toggle-subtree-encryption) |
6339 | (if (not was-modified) | |
6340 | (set-buffer-modified-p nil)) | |
6341 | ) | |
d82979ea EZ |
6342 | (if (not was-modified) |
6343 | (set-buffer-modified-p nil)) | |
2a1408fd | 6344 | (if editing-topic (list editing-topic editing-point)) |
d82979ea | 6345 | ) |
d82979ea EZ |
6346 | ) |
6347 | ) | |
6348 | ) | |
6349 | ||
6350 | ;;;_ #9 miscellaneous | |
d8350998 CY |
6351 | ;;;_ : Mode: |
6352 | ;;;_ > outlineify-sticky () | |
19b84ba3 | 6353 | ;; outlinify-sticky is correct spelling; provide this alias for sticklers: |
0949617b | 6354 | ;;;###autoload |
19b84ba3 | 6355 | (defalias 'outlinify-sticky 'outlineify-sticky) |
0949617b | 6356 | ;;;###autoload |
c567ac01 | 6357 | (defun outlineify-sticky (&optional arg) |
a0776d6b | 6358 | "Activate outline mode and establish file var so it is started subsequently. |
1977b8f6 | 6359 | |
11c46e15 | 6360 | See `allout-layout' and customization of `allout-auto-activation' |
20db1522 | 6361 | for details on preparing Emacs for automatic allout activation." |
19b84ba3 RS |
6362 | |
6363 | (interactive "P") | |
6364 | ||
2576c28f KM |
6365 | (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate... |
6366 | (allout-mode) | |
19b84ba3 RS |
6367 | |
6368 | (save-excursion | |
6369 | (goto-char (point-min)) | |
ede4ac6a | 6370 | (if (allout-goto-prefix) |
19b84ba3 | 6371 | t |
fd5359c6 | 6372 | (allout-open-topic 2) |
60c7bbd2 | 6373 | (insert (concat "Dummy outline topic header -- see" |
d82979ea EZ |
6374 | "`allout-mode' docstring: `^Hm'.")) |
6375 | (allout-adjust-file-variable | |
4034b0e2 | 6376 | "allout-layout" (or allout-layout '(-1 : 0)))))) |
d8350998 | 6377 | ;;;_ > allout-file-vars-section-data () |
d82979ea EZ |
6378 | (defun allout-file-vars-section-data () |
6379 | "Return data identifying the file-vars section, or nil if none. | |
6380 | ||
60c7bbd2 | 6381 | Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)." |
d82979ea EZ |
6382 | ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function. |
6383 | (let (beg prefix suffix) | |
6384 | (save-excursion | |
1977b8f6 | 6385 | (goto-char (point-max)) |
d82979ea EZ |
6386 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
6387 | (if (let ((case-fold-search t)) | |
6388 | (not (search-forward "Local Variables:" nil t))) | |
6389 | nil | |
6390 | (setq beg (- (point) 16)) | |
6391 | (setq suffix (buffer-substring-no-properties | |
6392 | (point) | |
96b83743 | 6393 | (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6394 | (forward-char -1)) |
6395 | (point)))) | |
6396 | (setq prefix (buffer-substring-no-properties | |
96b83743 | 6397 | (progn (if (search-backward "\n" nil t) |
d82979ea EZ |
6398 | (forward-char 1)) |
6399 | (point)) | |
6400 | beg)) | |
6401 | (list beg prefix suffix)) | |
6402 | ) | |
6403 | ) | |
6404 | ) | |
d8350998 | 6405 | ;;;_ > allout-adjust-file-variable (varname value) |
d82979ea | 6406 | (defun allout-adjust-file-variable (varname value) |
a0a022d5 | 6407 | "Adjust the setting of an Emacs file variable named VARNAME to VALUE. |
d82979ea | 6408 | |
20db1522 | 6409 | This activity is inhibited if either `enable-local-variables' or |
d82979ea EZ |
6410 | `allout-enable-file-variable-adjustment' are nil. |
6411 | ||
6412 | When enabled, an entry for the variable is created if not already present, | |
6413 | or changed if established with a different value. The section for the file | |
6414 | variables, itself, is created if not already present. When created, the | |
c07583cd | 6415 | section lines (including the section line) exist as second-level topics in |
d82979ea EZ |
6416 | a top-level topic at the end of the file. |
6417 | ||
a0a022d5 | 6418 | `enable-local-variables' must be true for any of this to happen." |
d82979ea EZ |
6419 | (if (not (and enable-local-variables |
6420 | allout-enable-file-variable-adjustment)) | |
6421 | nil | |
6422 | (save-excursion | |
0458fa80 EZ |
6423 | (let ((inhibit-field-text-motion t) |
6424 | (section-data (allout-file-vars-section-data)) | |
d82979ea EZ |
6425 | beg prefix suffix) |
6426 | (if section-data | |
6427 | (setq beg (car section-data) | |
6428 | prefix (cadr section-data) | |
6429 | suffix (car (cddr section-data))) | |
6430 | ;; create the section | |
6431 | (goto-char (point-max)) | |
6432 | (open-line 1) | |
6433 | (allout-open-topic 0) | |
6434 | (end-of-line) | |
6435 | (insert "Local emacs vars.\n") | |
6436 | (allout-open-topic 1) | |
6437 | (setq beg (point) | |
6438 | suffix "" | |
6439 | prefix (buffer-substring-no-properties (progn | |
6440 | (beginning-of-line) | |
6441 | (point)) | |
6442 | beg)) | |
6443 | (goto-char beg) | |
6444 | (insert "Local variables:\n") | |
6445 | (allout-open-topic 0) | |
6446 | (insert "End:\n") | |
6447 | ) | |
6448 | ;; look for existing entry or create one, leaving point for insertion | |
6449 | ;; of new value: | |
6450 | (goto-char beg) | |
6451 | (allout-show-to-offshoot) | |
6452 | (if (search-forward (concat "\n" prefix varname ":") nil t) | |
6453 | (let* ((value-beg (point)) | |
96b83743 | 6454 | (line-end (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6455 | (forward-char -1)) |
6456 | (point))) | |
6457 | (value-end (- line-end (length suffix)))) | |
6458 | (if (> value-end value-beg) | |
6459 | (delete-region value-beg value-end))) | |
6460 | (end-of-line) | |
6461 | (open-line 1) | |
6462 | (forward-line 1) | |
6463 | (insert (concat prefix varname ":"))) | |
6464 | (insert (format " %S%s" value suffix)) | |
6465 | ) | |
6466 | ) | |
6467 | ) | |
6468 | ) | |
d8350998 CY |
6469 | ;;;_ > allout-get-configvar-values (varname) |
6470 | (defun allout-get-configvar-values (configvar-name) | |
6471 | "Return a list of values of the symbols in list bound to CONFIGVAR-NAME. | |
6472 | ||
6473 | The user is prompted for removal of symbols that are unbound, and they | |
6474 | otherwise are ignored. | |
6475 | ||
6476 | CONFIGVAR-NAME should be the name of the configuration variable, | |
6477 | not its value." | |
6478 | ||
6479 | (let ((configvar-value (symbol-value configvar-name)) | |
6480 | got) | |
6481 | (dolist (sym configvar-value) | |
6482 | (if (not (boundp sym)) | |
60c7bbd2 | 6483 | (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? " |
d8350998 CY |
6484 | configvar-name sym)) |
6485 | (delq sym (symbol-value configvar-name))) | |
6486 | (push (symbol-value sym) got))) | |
6487 | (reverse got))) | |
6488 | ;;;_ : Topics: | |
6489 | ;;;_ > allout-mark-topic () | |
6490 | (defun allout-mark-topic () | |
6491 | "Put the region around topic currently containing point." | |
6492 | (interactive) | |
6493 | (let ((inhibit-field-text-motion t)) | |
6494 | (beginning-of-line)) | |
6495 | (allout-goto-prefix-doublechecked) | |
6496 | (push-mark (point)) | |
6497 | (allout-end-of-current-subtree) | |
6498 | (exchange-point-and-mark)) | |
6499 | ;;;_ : UI: | |
6500 | ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting) | |
1977b8f6 | 6501 | (defun solicit-char-in-string (prompt string &optional do-defaulting) |
c567ac01 | 6502 | "Solicit (with first arg PROMPT) choice of a character from string STRING. |
1977b8f6 | 6503 | |
c567ac01 | 6504 | Optional arg DO-DEFAULTING indicates to accept empty input (CR)." |
1977b8f6 RS |
6505 | |
6506 | (let ((new-prompt prompt) | |
6507 | got) | |
6508 | ||
6509 | (while (not got) | |
6510 | (message "%s" new-prompt) | |
6511 | ||
6512 | ;; We do our own reading here, so we can circumvent, eg, special | |
9179616f | 6513 | ;; treatment for `?' character. (Oughta use minibuffer keymap instead.) |
1977b8f6 | 6514 | (setq got |
c567ac01 | 6515 | (char-to-string (let ((cursor-in-echo-area nil)) (read-char)))) |
1977b8f6 | 6516 | |
9179616f DL |
6517 | (setq got |
6518 | (cond ((string-match (regexp-quote got) string) got) | |
6519 | ((and do-defaulting (string= got "\r")) | |
6520 | ;; Return empty string to default: | |
6521 | "") | |
6522 | ((string= got "\C-g") (signal 'quit nil)) | |
6523 | (t | |
6524 | (setq new-prompt (concat prompt | |
6525 | got | |
6526 | " ...pick from: " | |
6527 | string | |
6528 | "")) | |
6529 | nil)))) | |
60c7bbd2 | 6530 | ;; got something out of loop -- return it: |
9179616f | 6531 | got) |
1977b8f6 | 6532 | ) |
d8350998 CY |
6533 | ;;;_ : Strings: |
6534 | ;;;_ > regexp-sans-escapes (string) | |
c567ac01 RS |
6535 | (defun regexp-sans-escapes (regexp &optional successive-backslashes) |
6536 | "Return a copy of REGEXP with all character escapes stripped out. | |
19b84ba3 | 6537 | |
60c7bbd2 | 6538 | Representations of actual backslashes -- '\\\\\\\\' -- are left as a |
c567ac01 RS |
6539 | single backslash. |
6540 | ||
d82979ea | 6541 | Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion." |
c567ac01 RS |
6542 | |
6543 | (if (string= regexp "") | |
6544 | "" | |
6545 | ;; Set successive-backslashes to number if current char is | |
6546 | ;; backslash, or else to nil: | |
6547 | (setq successive-backslashes | |
6548 | (if (= (aref regexp 0) ?\\) | |
6549 | (if successive-backslashes (1+ successive-backslashes) 1) | |
6550 | nil)) | |
6551 | (if (or (not successive-backslashes) (= 2 successive-backslashes)) | |
6552 | ;; Include first char: | |
6553 | (concat (substring regexp 0 1) | |
6554 | (regexp-sans-escapes (substring regexp 1))) | |
6555 | ;; Exclude first char, but maintain count: | |
6556 | (regexp-sans-escapes (substring regexp 1) successive-backslashes)))) | |
d8350998 | 6557 | ;;;_ > count-trailing-whitespace-region (beg end) |
96b83743 EZ |
6558 | (defun count-trailing-whitespace-region (beg end) |
6559 | "Return number of trailing whitespace chars between BEG and END. | |
6560 | ||
6561 | If BEG is bigger than END we return 0." | |
6562 | (if (> beg end) | |
6563 | 0 | |
2a1408fd DN |
6564 | (save-match-data |
6565 | (save-excursion | |
6566 | (goto-char beg) | |
6567 | (let ((count 0)) | |
6568 | (while (re-search-forward "[ ][ ]*$" end t) | |
6569 | (goto-char (1+ (match-beginning 2))) | |
6570 | (setq count (1+ count))) | |
6571 | count))))) | |
d8350998 CY |
6572 | ;;;_ > allout-format-quote (string) |
6573 | (defun allout-format-quote (string) | |
6574 | "Return a copy of string with all \"%\" characters doubled." | |
6575 | (apply 'concat | |
6576 | (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char))) | |
6577 | string))) | |
6578 | ;;;_ : lists | |
6579 | ;;;_ > allout-flatten (list) | |
6580 | (defun allout-flatten (list) | |
6581 | "Return a list of all atoms in list." | |
6582 | ;; classic. | |
6583 | (cond ((null list) nil) | |
8a559d4e EZ |
6584 | ((atom (car list)) (cons (car list) (allout-flatten (cdr list)))) |
6585 | (t (append (allout-flatten (car list)) (allout-flatten (cdr list)))))) | |
75bcb912 | 6586 | ;;;_ : Compatibility: |
1c9b9df0 KM |
6587 | ;;;_ : xemacs undo-in-progress provision: |
6588 | (unless (boundp 'undo-in-progress) | |
6589 | (defvar undo-in-progress nil | |
6590 | "Placeholder defvar for XEmacs compatibility from allout.el.") | |
6591 | (defadvice undo-more (around allout activate) | |
6592 | ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs. | |
6593 | (let ((undo-in-progress t)) ad-do-it))) | |
6594 | ||
d8350998 | 6595 | ;;;_ > allout-mark-marker to accommodate divergent emacsen: |
96b83743 EZ |
6596 | (defun allout-mark-marker (&optional force buffer) |
6597 | "Accommodate the different signature for `mark-marker' across Emacsen. | |
6598 | ||
3bda1277 | 6599 | XEmacs takes two optional args, while Emacs does not, |
96b83743 EZ |
6600 | so pass them along when appropriate." |
6601 | (if (featurep 'xemacs) | |
6602 | (apply 'mark-marker force buffer) | |
6603 | (mark-marker))) | |
d8350998 | 6604 | ;;;_ > subst-char-in-string if necessary |
d82979ea EZ |
6605 | (if (not (fboundp 'subst-char-in-string)) |
6606 | (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
6607 | "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
6608 | Unless optional argument INPLACE is non-nil, return a new string." | |
6609 | (let ((i (length string)) | |
6610 | (newstr (if inplace string (copy-sequence string)))) | |
6611 | (while (> i 0) | |
6612 | (setq i (1- i)) | |
6613 | (if (eq (aref newstr i) fromchar) | |
6614 | (aset newstr i tochar))) | |
6615 | newstr))) | |
d8350998 | 6616 | ;;;_ > wholenump if necessary |
96b83743 EZ |
6617 | (if (not (fboundp 'wholenump)) |
6618 | (defalias 'wholenump 'natnump)) | |
d8350998 | 6619 | ;;;_ > remove-overlays if necessary |
96b83743 EZ |
6620 | (if (not (fboundp 'remove-overlays)) |
6621 | (defun remove-overlays (&optional beg end name val) | |
6622 | "Clear BEG and END of overlays whose property NAME has value VAL. | |
6623 | Overlays might be moved and/or split. | |
6624 | BEG and END default respectively to the beginning and end of buffer." | |
6625 | (unless beg (setq beg (point-min))) | |
6626 | (unless end (setq end (point-max))) | |
6627 | (if (< end beg) | |
6628 | (setq beg (prog1 end (setq end beg)))) | |
6629 | (save-excursion | |
6630 | (dolist (o (overlays-in beg end)) | |
6631 | (when (eq (overlay-get o name) val) | |
6632 | ;; Either push this overlay outside beg...end | |
6633 | ;; or split it to exclude beg...end | |
6634 | ;; or delete it entirely (if it is contained in beg...end). | |
6635 | (if (< (overlay-start o) beg) | |
6636 | (if (> (overlay-end o) end) | |
6637 | (progn | |
6638 | (move-overlay (copy-overlay o) | |
6639 | (overlay-start o) beg) | |
6640 | (move-overlay o end (overlay-end o))) | |
6641 | (move-overlay o (overlay-start o) beg)) | |
6642 | (if (> (overlay-end o) end) | |
6643 | (move-overlay o end (overlay-end o)) | |
6644 | (delete-overlay o))))))) | |
6645 | ) | |
60c7bbd2 | 6646 | ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6647 | (if (not (fboundp 'copy-overlay)) |
6648 | (defun copy-overlay (o) | |
6649 | "Return a copy of overlay O." | |
6650 | (let ((o1 (make-overlay (overlay-start o) (overlay-end o) | |
6651 | ;; FIXME: there's no easy way to find the | |
6652 | ;; insertion-type of the two markers. | |
6653 | (overlay-buffer o))) | |
6654 | (props (overlay-properties o))) | |
6655 | (while props | |
6656 | (overlay-put o1 (pop props) (pop props))) | |
6657 | o1))) | |
60c7bbd2 | 6658 | ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6659 | (if (not (fboundp 'add-to-invisibility-spec)) |
6660 | (defun add-to-invisibility-spec (element) | |
6661 | "Add ELEMENT to `buffer-invisibility-spec'. | |
6662 | See documentation for `buffer-invisibility-spec' for the kind of elements | |
6663 | that can be added." | |
6664 | (if (eq buffer-invisibility-spec t) | |
6665 | (setq buffer-invisibility-spec (list t))) | |
6666 | (setq buffer-invisibility-spec | |
6667 | (cons element buffer-invisibility-spec)))) | |
60c7bbd2 | 6668 | ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6669 | (if (not (fboundp 'remove-from-invisibility-spec)) |
6670 | (defun remove-from-invisibility-spec (element) | |
6671 | "Remove ELEMENT from `buffer-invisibility-spec'." | |
6672 | (if (consp buffer-invisibility-spec) | |
6673 | (setq buffer-invisibility-spec (delete element | |
6674 | buffer-invisibility-spec))))) | |
60c7bbd2 | 6675 | ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs |
96b83743 EZ |
6676 | (if (not (fboundp 'move-beginning-of-line)) |
6677 | (defun move-beginning-of-line (arg) | |
6678 | "Move point to beginning of current line as displayed. | |
6679 | \(This disregards invisible newlines such as those | |
6680 | which are part of the text that an image rests on.) | |
6681 | ||
6682 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6683 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6684 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6685 | (interactive "p") |
6686 | (or arg (setq arg 1)) | |
6687 | (if (/= arg 1) | |
6688 | (condition-case nil (line-move (1- arg)) (error nil))) | |
6689 | ||
99d99081 | 6690 | ;; Move to beginning-of-line, ignoring fields and invisible text. |
8570ce80 | 6691 | (skip-chars-backward "^\n") |
2a1408fd DN |
6692 | (while (and (not (bobp)) |
6693 | (let ((prop | |
6694 | (get-char-property (1- (point)) 'invisible))) | |
6695 | (if (eq buffer-invisibility-spec t) | |
6696 | prop | |
6697 | (or (memq prop buffer-invisibility-spec) | |
6698 | (assq prop buffer-invisibility-spec))))) | |
8570ce80 SM |
6699 | (goto-char (if (featurep 'xemacs) |
6700 | (previous-property-change (point)) | |
6701 | (previous-char-property-change (point)))) | |
6702 | (skip-chars-backward "^\n")) | |
6703 | (vertical-motion 0)) | |
96b83743 | 6704 | ) |
9b026d9f | 6705 | ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs |
96b83743 EZ |
6706 | (if (not (fboundp 'move-end-of-line)) |
6707 | (defun move-end-of-line (arg) | |
6708 | "Move point to end of current line as displayed. | |
6709 | \(This disregards invisible newlines such as those | |
6710 | which are part of the text that an image rests on.) | |
6711 | ||
6712 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6713 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6714 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6715 | (interactive "p") |
6716 | (or arg (setq arg 1)) | |
8570ce80 | 6717 | (let (done) |
96b83743 EZ |
6718 | (while (not done) |
6719 | (let ((newpos | |
6720 | (save-excursion | |
6721 | (let ((goal-column 0)) | |
6722 | (and (condition-case nil | |
6723 | (or (line-move arg) t) | |
6724 | (error nil)) | |
6725 | (not (bobp)) | |
6726 | (progn | |
2a1408fd DN |
6727 | (while |
6728 | (and | |
6729 | (not (bobp)) | |
6730 | (let ((prop | |
6731 | (get-char-property (1- (point)) | |
6732 | 'invisible))) | |
6733 | (if (eq buffer-invisibility-spec t) | |
6734 | prop | |
6735 | (or (memq prop | |
6736 | buffer-invisibility-spec) | |
6737 | (assq prop | |
6738 | buffer-invisibility-spec))))) | |
8570ce80 SM |
6739 | (goto-char |
6740 | (previous-char-property-change (point)))) | |
96b83743 EZ |
6741 | (backward-char 1))) |
6742 | (point))))) | |
6743 | (goto-char newpos) | |
6744 | (if (and (> (point) newpos) | |
6745 | (eq (preceding-char) ?\n)) | |
6746 | (backward-char 1) | |
6747 | (if (and (> (point) newpos) (not (eobp)) | |
6748 | (not (eq (following-char) ?\n))) | |
6749 | ;; If we skipped something intangible | |
6750 | ;; and now we're not really at eol, | |
6751 | ;; keep going. | |
6752 | (setq arg 1) | |
8570ce80 | 6753 | (setq done t))))))) |
96b83743 | 6754 | ) |
1c9b9df0 KM |
6755 | ;;;_ > allout-next-single-char-property-change -- alias unless lacking |
6756 | (defalias 'allout-next-single-char-property-change | |
6757 | (if (fboundp 'next-single-char-property-change) | |
6758 | 'next-single-char-property-change | |
6759 | 'next-single-property-change) | |
6760 | ;; No docstring because xemacs defalias doesn't support it. | |
6761 | ) | |
6762 | ;;;_ > allout-previous-single-char-property-change -- alias unless lacking | |
6763 | (defalias 'allout-previous-single-char-property-change | |
6764 | (if (fboundp 'previous-single-char-property-change) | |
6765 | 'previous-single-char-property-change | |
6766 | 'previous-single-property-change) | |
6767 | ;; No docstring because xemacs defalias doesn't support it. | |
6768 | ) | |
1c9b9df0 KM |
6769 | ;;;_ > allout-select-safe-coding-system |
6770 | (defalias 'allout-select-safe-coding-system | |
6771 | (if (fboundp 'select-safe-coding-system) | |
6772 | 'select-safe-coding-system | |
6773 | 'detect-coding-region) | |
6774 | ) | |
6775 | ;;;_ > allout-substring-no-properties | |
6776 | ;; define as alias first, so byte compiler is happy. | |
6777 | (defalias 'allout-substring-no-properties 'substring-no-properties) | |
6778 | ;; then supplant with definition if underlying alias absent. | |
6779 | (if (not (fboundp 'substring-no-properties)) | |
6780 | (defun allout-substring-no-properties (string &optional start end) | |
6781 | (substring string (or start 0) end)) | |
6782 | ) | |
96b83743 | 6783 | |
96b83743 | 6784 | ;;;_ #10 Unfinished |
fd5359c6 MR |
6785 | ;;;_ > allout-bullet-isearch (&optional bullet) |
6786 | (defun allout-bullet-isearch (&optional bullet) | |
c07583cd | 6787 | "Isearch (regexp) for topic with bullet BULLET." |
c567ac01 RS |
6788 | (interactive) |
6789 | (if (not bullet) | |
6790 | (setq bullet (solicit-char-in-string | |
6791 | "ISearch for topic with bullet: " | |
fd5359c6 | 6792 | (regexp-sans-escapes allout-bullets-string)))) |
353e2ef2 | 6793 | |
c567ac01 RS |
6794 | (let ((isearch-regexp t) |
6795 | (isearch-string (concat "^" | |
fd5359c6 | 6796 | allout-header-prefix |
c567ac01 RS |
6797 | "[ \t]*" |
6798 | bullet))) | |
6799 | (isearch-repeat 'forward) | |
6800 | (isearch-mode t))) | |
96b83743 | 6801 | |
60c7bbd2 | 6802 | ;;;_ #11 Unit tests -- this should be last item before "Provide" |
01fc9422 EZ |
6803 | ;;;_ > allout-run-unit-tests () |
6804 | (defun allout-run-unit-tests () | |
6805 | "Run the various allout unit tests." | |
6806 | (message "Running allout tests...") | |
6807 | (allout-test-resumptions) | |
6808 | (message "Running allout tests... Done.") | |
6809 | (sit-for .5)) | |
6810 | ;;;_ : test resumptions: | |
6811 | ;;;_ > allout-tests-obliterate-variable (name) | |
6812 | (defun allout-tests-obliterate-variable (name) | |
6813 | "Completely unbind variable with NAME." | |
1c9b9df0 | 6814 | (if (local-variable-p name (current-buffer)) (kill-local-variable name)) |
01fc9422 EZ |
6815 | (while (boundp name) (makunbound name))) |
6816 | ;;;_ > allout-test-resumptions () | |
6817 | (defvar allout-tests-globally-unbound nil | |
60c7bbd2 | 6818 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6819 | (defvar allout-tests-globally-true nil |
60c7bbd2 | 6820 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 6821 | (defvar allout-tests-locally-true nil |
60c7bbd2 | 6822 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 EZ |
6823 | (defun allout-test-resumptions () |
6824 | "Exercise allout resumptions." | |
6825 | ;; for each resumption case, we also test that the right local/global | |
6826 | ;; scopes are affected during resumption effects: | |
6827 | ||
6828 | ;; ensure that previously unbound variables return to the unbound state. | |
6829 | (with-temp-buffer | |
6830 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6831 | (allout-add-resumptions '(allout-tests-globally-unbound t)) | |
6832 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6833 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6834 | (assert (boundp 'allout-tests-globally-unbound)) |
6835 | (assert (equal allout-tests-globally-unbound t)) | |
6836 | (allout-do-resumptions) | |
1c9b9df0 KM |
6837 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6838 | (current-buffer)))) | |
01fc9422 EZ |
6839 | (assert (not (boundp 'allout-tests-globally-unbound)))) |
6840 | ||
6841 | ;; ensure that variable with prior global value is resumed | |
6842 | (with-temp-buffer | |
6843 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6844 | (setq allout-tests-globally-true t) | |
6845 | (allout-add-resumptions '(allout-tests-globally-true nil)) | |
6846 | (assert (equal (default-value 'allout-tests-globally-true) t)) | |
1c9b9df0 | 6847 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6848 | (assert (equal allout-tests-globally-true nil)) |
6849 | (allout-do-resumptions) | |
1c9b9df0 KM |
6850 | (assert (not (local-variable-p 'allout-tests-globally-true |
6851 | (current-buffer)))) | |
01fc9422 EZ |
6852 | (assert (boundp 'allout-tests-globally-true)) |
6853 | (assert (equal allout-tests-globally-true t))) | |
6854 | ||
6855 | ;; ensure that prior local value is resumed | |
6856 | (with-temp-buffer | |
6857 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6858 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6859 | (assert (not (default-boundp 'allout-tests-locally-true)) | |
60c7bbd2 | 6860 | nil (concat "Test setup mistake -- variable supposed to" |
01fc9422 | 6861 | " not have global binding, but it does.")) |
1c9b9df0 | 6862 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer)) |
60c7bbd2 | 6863 | nil (concat "Test setup mistake -- variable supposed to have" |
01fc9422 EZ |
6864 | " local binding, but it lacks one.")) |
6865 | (allout-add-resumptions '(allout-tests-locally-true nil)) | |
6866 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6867 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6868 | (assert (equal allout-tests-locally-true nil)) |
6869 | (allout-do-resumptions) | |
6870 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6871 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6872 | (assert (equal allout-tests-locally-true t)) |
6873 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6874 | ||
6875 | ;; ensure that last of multiple resumptions holds, for various scopes. | |
6876 | (with-temp-buffer | |
6877 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6878 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6879 | (setq allout-tests-globally-true t) | |
6880 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6881 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6882 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6883 | '(allout-tests-globally-true nil) | |
6884 | '(allout-tests-locally-true nil)) | |
6885 | (allout-add-resumptions '(allout-tests-globally-unbound 2) | |
6886 | '(allout-tests-globally-true 3) | |
6887 | '(allout-tests-locally-true 4)) | |
6888 | ;; reestablish many of the basic conditions are maintained after re-add: | |
6889 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
1c9b9df0 | 6890 | (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer))) |
01fc9422 EZ |
6891 | (assert (equal allout-tests-globally-unbound 2)) |
6892 | (assert (default-boundp 'allout-tests-globally-true)) | |
1c9b9df0 | 6893 | (assert (local-variable-p 'allout-tests-globally-true (current-buffer))) |
01fc9422 EZ |
6894 | (assert (equal allout-tests-globally-true 3)) |
6895 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
1c9b9df0 | 6896 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6897 | (assert (equal allout-tests-locally-true 4)) |
6898 | (allout-do-resumptions) | |
1c9b9df0 KM |
6899 | (assert (not (local-variable-p 'allout-tests-globally-unbound |
6900 | (current-buffer)))) | |
01fc9422 | 6901 | (assert (not (boundp 'allout-tests-globally-unbound))) |
1c9b9df0 KM |
6902 | (assert (not (local-variable-p 'allout-tests-globally-true |
6903 | (current-buffer)))) | |
01fc9422 EZ |
6904 | (assert (boundp 'allout-tests-globally-true)) |
6905 | (assert (equal allout-tests-globally-true t)) | |
6906 | (assert (boundp 'allout-tests-locally-true)) | |
1c9b9df0 | 6907 | (assert (local-variable-p 'allout-tests-locally-true (current-buffer))) |
01fc9422 EZ |
6908 | (assert (equal allout-tests-locally-true t)) |
6909 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
6910 | ||
6911 | ;; ensure that deliberately unbinding registered variables doesn't foul things | |
6912 | (with-temp-buffer | |
6913 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6914 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6915 | (setq allout-tests-globally-true t) | |
6916 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6917 | (set (make-local-variable 'allout-tests-locally-true) t) | |
6918 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
6919 | '(allout-tests-globally-true nil) | |
6920 | '(allout-tests-locally-true nil)) | |
6921 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
6922 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
6923 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
6924 | (allout-do-resumptions)) | |
6925 | ) | |
6926 | ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true: | |
6927 | (when allout-run-unit-tests-on-load | |
6928 | (allout-run-unit-tests)) | |
6929 | ||
6930 | ;;;_ #12 Provide | |
96b83743 | 6931 | (provide 'allout) |
1977b8f6 RS |
6932 | |
6933 | ;;;_* Local emacs vars. | |
31468dcb SM |
6934 | ;; The following `allout-layout' local variable setting: |
6935 | ;; - closes all topics from the first topic to just before the third-to-last, | |
6936 | ;; - shows the children of the third to last (config vars) | |
6937 | ;; - and the second to last (code section), | |
6938 | ;; - and closes the last topic (this local-variables section). | |
6939 | ;;Local variables: | |
6940 | ;;allout-layout: (0 : -1 -1 0) | |
6941 | ;;End: | |
6942 | ||
6a05d05f | 6943 | ;;; allout.el ends here |