Commit | Line | Data |
---|---|---|
6a05d05f | 1 | ;;; allout.el --- extensive outline mode for use alone and with other modes |
19b84ba3 | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1992, 1993, 1994, 2001, 2002, 2003, 2004, |
409cc4a3 | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
1977b8f6 | 5 | |
d82979ea EZ |
6 | ;; Author: Ken Manheimer <ken dot manheimer at gmail dot com> |
7 | ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail dot com> | |
60c7bbd2 | 8 | ;; Created: Dec 1991 -- first release to usenet |
4034b0e2 | 9 | ;; Version: 2.2.1 |
d82979ea | 10 | ;; Keywords: outlines wp languages |
01fc9422 | 11 | ;; Website: http://myriadicity.net/Sundry/EmacsAllout |
1977b8f6 RS |
12 | |
13 | ;; This file is part of GNU Emacs. | |
14 | ||
eb3fa2cf | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
59243403 | 16 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
17 | ;; the Free Software Foundation, either version 3 of the License, or |
18 | ;; (at your option) any later version. | |
59243403 | 19 | |
1977b8f6 | 20 | ;; GNU Emacs is distributed in the hope that it will be useful, |
59243403 RS |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
1977b8f6 | 27 | |
6a05d05f | 28 | ;;; Commentary: |
19b84ba3 | 29 | |
96b83743 EZ |
30 | ;; Allout outline minor mode provides extensive outline formatting and |
31 | ;; and manipulation beyond standard emacs outline mode. Some features: | |
71296446 | 32 | ;; |
96b83743 EZ |
33 | ;; - Classic outline-mode topic-oriented navigation and exposure adjustment |
34 | ;; - Topic-oriented editing including coherent topic and subtopic | |
35 | ;; creation, promotion, demotion, cut/paste across depths, etc. | |
36 | ;; - Incremental search with dynamic exposure and reconcealment of text | |
60c7bbd2 | 37 | ;; - Customizable bullet format -- enables programming-language specific |
96b83743 | 38 | ;; outlining, for code-folding editing. (Allout code itself is to try it; |
60c7bbd2 | 39 | ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but |
96b83743 | 40 | ;; emacs local file variables need to be enabled when the |
60c7bbd2 | 41 | ;; file was visited -- see `enable-local-variables'.) |
96b83743 EZ |
42 | ;; - Configurable per-file initial exposure settings |
43 | ;; - Symmetric-key and key-pair topic encryption, plus symmetric passphrase | |
0949617b EZ |
44 | ;; mnemonic support, with verification against an established passphrase |
45 | ;; (using a stashed encrypted dummy string) and user-supplied hint | |
e14adf87 CY |
46 | ;; maintenance. (See allout-toggle-current-subtree-encryption docstring. |
47 | ;; Currently only GnuPG encryption is supported, and integration | |
48 | ;; with gpg-agent is not yet implemented.) | |
96b83743 EZ |
49 | ;; - Automatic topic-number maintenance |
50 | ;; - "Hot-spot" operation, for single-keystroke maneuvering and | |
d82979ea | 51 | ;; exposure control (see the allout-mode docstring) |
96b83743 | 52 | ;; - Easy rendering of exposed portions into numbered, latex, indented, etc |
d82979ea | 53 | ;; outline styles |
60c7bbd2 | 54 | ;; - Careful attention to whitespace -- enabling blank lines between items |
96b83743 EZ |
55 | ;; and maintenance of hanging indentation (in paragraph auto-fill and |
56 | ;; across topic promotion and demotion) of topic bodies consistent with | |
57 | ;; indentation of their topic header. | |
71296446 | 58 | ;; |
d82979ea | 59 | ;; and more. |
71296446 | 60 | ;; |
96b83743 | 61 | ;; See the `allout-mode' function's docstring for an introduction to the |
01fc9422 EZ |
62 | ;; mode. |
63 | ;; | |
64 | ;; The latest development version and helpful notes are available at | |
96b83743 EZ |
65 | ;; http://myriadicity.net/Sundry/EmacsAllout . |
66 | ;; | |
9179616f | 67 | ;; The outline menubar additions provide quick reference to many of |
d82979ea | 68 | ;; the features, and see the docstring of the variable `allout-init' |
a0a022d5 | 69 | ;; for instructions on priming your Emacs session for automatic |
d82979ea | 70 | ;; activation of allout-mode. |
71296446 | 71 | ;; |
fd5359c6 MR |
72 | ;; See the docstring of the variables `allout-layout' and |
73 | ;; `allout-auto-activation' for details on automatic activation of | |
d82979ea | 74 | ;; `allout-mode' as a minor mode. (It has changed since allout |
19b84ba3 | 75 | ;; 3.x, for those of you that depend on the old method.) |
c567ac01 | 76 | ;; |
60c7bbd2 | 77 | ;; Note -- the lines beginning with `;;;_' are outline topic headers. |
ac052b48 | 78 | ;; Just `ESC-x eval-buffer' to give it a whirl. |
19b84ba3 | 79 | |
d82979ea | 80 | ;; ken manheimer (ken dot manheimer at gmail dot com) |
c567ac01 | 81 | |
6a05d05f PJ |
82 | ;;; Code: |
83 | ||
d82979ea | 84 | ;;;_* Dependency autoloads |
96b83743 | 85 | (require 'overlay) |
01fc9422 EZ |
86 | (eval-when-compile |
87 | ;; Most of the requires here are for stuff covered by autoloads. | |
88 | ;; Since just byte-compiling doesn't trigger autoloads, so that | |
89 | ;; "function not found" warnings would occur without these requires. | |
90 | (progn | |
91 | (require 'pgg) | |
92 | (require 'pgg-gpg) | |
93 | (require 'overlay) | |
94 | ;; `cl' is required for `assert'. `assert' is not covered by a standard | |
95 | ;; autoload, but it is a macro, so that eval-when-compile is sufficient | |
96 | ;; to byte-compile it in, or to do the require when the buffer evalled. | |
97 | (require 'cl) | |
98 | )) | |
d82979ea | 99 | |
19b84ba3 | 100 | ;;;_* USER CUSTOMIZATION VARIABLES: |
96b83743 EZ |
101 | |
102 | ;;;_ > defgroup allout | |
4bef9110 SE |
103 | (defgroup allout nil |
104 | "Extensive outline mode for use alone and with other modes." | |
fd5359c6 | 105 | :prefix "allout-" |
d82979ea | 106 | :group 'outlines) |
19b84ba3 RS |
107 | |
108 | ;;;_ + Layout, Mode, and Topic Header Configuration | |
109 | ||
2a1408fd DN |
110 | ;;;_ = allout-command-prefix |
111 | (defcustom allout-command-prefix "\C-c " | |
112 | "*Key sequence to be used as prefix for outline mode command key bindings. | |
113 | ||
114 | Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're | |
115 | willing to let allout use a bunch of \C-c keybindings." | |
116 | :type 'string | |
117 | :group 'allout) | |
8dd59f01 | 118 | |
2a1408fd | 119 | ;;;_ = allout-keybindings-list |
8dd59f01 | 120 | ;;; You have to reactivate allout-mode -- `(allout-mode t)' -- to |
2a1408fd DN |
121 | ;;; institute changes to this var. |
122 | (defvar allout-keybindings-list () | |
123 | "*List of `allout-mode' key / function bindings, for `allout-mode-map'. | |
2a1408fd DN |
124 | String or vector key will be prefaced with `allout-command-prefix', |
125 | unless optional third, non-nil element is present.") | |
126 | (setq allout-keybindings-list | |
127 | '( | |
128 | ; Motion commands: | |
129 | ("\C-n" allout-next-visible-heading) | |
130 | ("\C-p" allout-previous-visible-heading) | |
131 | ("\C-u" allout-up-current-level) | |
132 | ("\C-f" allout-forward-current-level) | |
133 | ("\C-b" allout-backward-current-level) | |
134 | ("\C-a" allout-beginning-of-current-entry) | |
135 | ("\C-e" allout-end-of-entry) | |
136 | ; Exposure commands: | |
137 | ("\C-i" allout-show-children) | |
138 | ("\C-s" allout-show-current-subtree) | |
a471d898 | 139 | ("\C-h" allout-hide-current-subtree) |
2a1408fd DN |
140 | ("\C-t" allout-toggle-current-subtree-exposure) |
141 | ("h" allout-hide-current-subtree) | |
142 | ("\C-o" allout-show-current-entry) | |
143 | ("!" allout-show-all) | |
144 | ("x" allout-toggle-current-subtree-encryption) | |
145 | ; Alteration commands: | |
146 | (" " allout-open-sibtopic) | |
147 | ("." allout-open-subtopic) | |
148 | ("," allout-open-supertopic) | |
149 | ("'" allout-shift-in) | |
150 | (">" allout-shift-in) | |
151 | ("<" allout-shift-out) | |
152 | ("\C-m" allout-rebullet-topic) | |
153 | ("*" allout-rebullet-current-heading) | |
154 | ("#" allout-number-siblings) | |
155 | ("\C-k" allout-kill-line t) | |
42c3e51c | 156 | ([?\M-k] allout-copy-line-as-kill t) |
2a1408fd | 157 | ("\C-y" allout-yank t) |
42c3e51c | 158 | ([?\M-y] allout-yank-pop t) |
2a1408fd | 159 | ("\C-k" allout-kill-topic) |
42c3e51c | 160 | ([?\M-k] allout-copy-topic-as-kill) |
2a1408fd DN |
161 | ; Miscellaneous commands: |
162 | ;([?\C-\ ] allout-mark-topic) | |
163 | ("@" allout-resolve-xref) | |
164 | ("=c" allout-copy-exposed-to-buffer) | |
165 | ("=i" allout-indented-exposed-to-buffer) | |
166 | ("=t" allout-latexify-exposed) | |
167 | ("=p" allout-flatten-exposed-to-buffer))) | |
168 | ||
fd5359c6 MR |
169 | ;;;_ = allout-auto-activation |
170 | (defcustom allout-auto-activation nil | |
60c7bbd2 | 171 | "*Regulates auto-activation modality of allout outlines -- see `allout-init'. |
19b84ba3 | 172 | |
fd5359c6 | 173 | Setq-default by `allout-init' to regulate whether or not allout |
19b84ba3 | 174 | outline mode is automatically activated when the buffer-specific |
fd5359c6 MR |
175 | variable `allout-layout' is non-nil, and whether or not the layout |
176 | dictated by `allout-layout' should be imposed on mode activation. | |
19b84ba3 | 177 | |
24190da5 | 178 | With value t, auto-mode-activation and auto-layout are enabled. |
aad94676 | 179 | \(This also depends on `allout-find-file-hook' being installed in |
95c12694 | 180 | `find-file-hook', which is also done by `allout-init'.) |
19b84ba3 RS |
181 | |
182 | With value `ask', auto-mode-activation is enabled, and endorsement for | |
183 | performing auto-layout is asked of the user each time. | |
184 | ||
71296446 | 185 | With value `activate', only auto-mode-activation is enabled, |
353e2ef2 | 186 | auto-layout is not. |
19b84ba3 | 187 | |
24190da5 | 188 | With value nil, neither auto-mode-activation nor auto-layout are |
19b84ba3 RS |
189 | enabled. |
190 | ||
fd5359c6 | 191 | See the docstring for `allout-init' for the proper interface to |
9179616f DL |
192 | this variable." |
193 | :type '(choice (const :tag "On" t) | |
194 | (const :tag "Ask about layout" "ask") | |
195 | (const :tag "Mode only" "activate") | |
196 | (const :tag "Off" nil)) | |
197 | :group 'allout) | |
4034b0e2 LT |
198 | ;;;_ = allout-default-layout |
199 | (defcustom allout-default-layout '(-2 : 0) | |
200 | "*Default allout outline layout specification. | |
201 | ||
202 | This setting specifies the outline exposure to use when | |
203 | `allout-layout' has the local value `t'. This docstring describes the | |
204 | layout specifications. | |
205 | ||
206 | A list value specifies a default layout for the current buffer, | |
207 | to be applied upon activation of `allout-mode'. Any non-nil | |
208 | value will automatically trigger `allout-mode', provided | |
209 | `allout-init' has been called to enable this behavior. | |
210 | ||
211 | The types of elements in the layout specification are: | |
212 | ||
60c7bbd2 RS |
213 | INTEGER -- dictate the relative depth to open the corresponding topic(s), |
214 | where: | |
215 | -- negative numbers force the topic to be closed before opening | |
216 | to the absolute value of the number, so all siblings are open | |
217 | only to that level. | |
218 | -- positive numbers open to the relative depth indicated by the | |
219 | number, but do not force already opened subtopics to be closed. | |
220 | -- 0 means to close topic -- hide all subitems. | |
221 | : -- repeat spec -- apply the preceeding element to all siblings at | |
222 | current level, *up to* those siblings that would be covered by specs | |
223 | following the `:' on the list. Ie, apply to all topics at level but | |
224 | trailing ones accounted for by trailing specs. (Only the first of | |
225 | multiple colons at the same level is honored -- later ones are ignored.) | |
226 | * -- completely exposes the topic, including bodies | |
227 | + -- exposes all subtopics, but not the bodies | |
228 | - -- exposes the body of the corresponding topic, but not subtopics | |
229 | LIST -- a nested layout spec, to be applied intricately to its | |
4034b0e2 | 230 | corresponding item(s) |
1977b8f6 | 231 | |
4034b0e2 | 232 | Examples: |
60c7bbd2 | 233 | (-2 : 0) |
4034b0e2 LT |
234 | Collapse the top-level topics to show their children and |
235 | grandchildren, but completely collapse the final top-level topic. | |
60c7bbd2 | 236 | (-1 () : 1 0) |
4034b0e2 LT |
237 | Close the first topic so only the immediate subtopics are shown, |
238 | leave the subsequent topics exposed as they are until the second | |
239 | second to last topic, which is exposed at least one level, and | |
240 | completely close the last topic. | |
60c7bbd2 | 241 | (-2 : -1 *) |
4034b0e2 LT |
242 | Expose children and grandchildren of all topics at current |
243 | level except the last two; expose children of the second to | |
244 | last and completely expose the last one, including its subtopics. | |
19b84ba3 | 245 | |
4034b0e2 | 246 | See `allout-expose-topic' for more about the exposure process. |
19b84ba3 | 247 | |
353e2ef2 KH |
248 | Also, allout's mode-specific provisions will make topic prefixes default |
249 | to the comment-start string, if any, of the language of the file. This | |
4034b0e2 LT |
250 | is modulo the setting of `allout-use-mode-specific-leader', which see." |
251 | :type 'allout-layout-type | |
252 | :group 'allout) | |
253 | ;;;_ : allout-layout-type | |
254 | (define-widget 'allout-layout-type 'lazy | |
255 | "Allout layout format customization basic building blocks." | |
256 | :type '(repeat | |
257 | (choice (integer :tag "integer (<= zero is strict)") | |
258 | (const :tag ": (repeat prior)" :) | |
259 | (const :tag "* (completely expose)" *) | |
260 | (const :tag "+ (expose all offspring, headlines only)" +) | |
261 | (const :tag "- (expose topic body but not offspring)" -) | |
262 | (allout-layout-type :tag "<Nested layout>")))) | |
263 | ||
2a1408fd DN |
264 | ;;;_ = allout-inhibit-auto-fill |
265 | (defcustom allout-inhibit-auto-fill nil | |
266 | "*If non-nil, auto-fill will be inhibited in the allout buffers. | |
267 | ||
268 | You can customize this setting to set it for all allout buffers, or set it | |
269 | in individual buffers if you want to inhibit auto-fill only in particular | |
270 | buffers. (You could use a function on `allout-mode-hook' to inhibit | |
271 | auto-fill according, eg, to the major mode.) | |
272 | ||
273 | If you don't set this and auto-fill-mode is enabled, allout will use the | |
274 | value that `normal-auto-fill-function', if any, when allout mode starts, or | |
275 | else allout's special hanging-indent maintaining auto-fill function, | |
276 | `allout-auto-fill'." | |
277 | :type 'boolean | |
278 | :group 'allout) | |
279 | (make-variable-buffer-local 'allout-inhibit-auto-fill) | |
280 | ;;;_ = allout-use-hanging-indents | |
281 | (defcustom allout-use-hanging-indents t | |
282 | "*If non-nil, topic body text auto-indent defaults to indent of the header. | |
283 | Ie, it is indented to be just past the header prefix. This is | |
8dd59f01 | 284 | relevant mostly for use with `indented-text-mode', or other situations |
2a1408fd DN |
285 | where auto-fill occurs." |
286 | :type 'boolean | |
287 | :group 'allout) | |
288 | (make-variable-buffer-local 'allout-use-hanging-indents) | |
289 | ;;;###autoload | |
290 | (put 'allout-use-hanging-indents 'safe-local-variable | |
291 | (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) | |
292 | ;;;_ = allout-reindent-bodies | |
293 | (defcustom allout-reindent-bodies (if allout-use-hanging-indents | |
294 | 'text) | |
295 | "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts. | |
296 | ||
297 | When active, topic body lines that are indented even with or beyond | |
298 | their topic header are reindented to correspond with depth shifts of | |
299 | the header. | |
300 | ||
301 | A value of t enables reindent in non-programming-code buffers, ie | |
302 | those that do not have the variable `comment-start' set. A value of | |
303 | `force' enables reindent whether or not `comment-start' is set." | |
304 | :type '(choice (const nil) (const t) (const text) (const force)) | |
305 | :group 'allout) | |
306 | ||
307 | (make-variable-buffer-local 'allout-reindent-bodies) | |
308 | ;;;###autoload | |
309 | (put 'allout-reindent-bodies 'safe-local-variable | |
310 | '(lambda (x) (memq x '(nil t text force)))) | |
311 | ||
fd5359c6 MR |
312 | ;;;_ = allout-show-bodies |
313 | (defcustom allout-show-bodies nil | |
9179616f DL |
314 | "*If non-nil, show entire body when exposing a topic, rather than |
315 | just the header." | |
316 | :type 'boolean | |
317 | :group 'allout) | |
fd5359c6 | 318 | (make-variable-buffer-local 'allout-show-bodies) |
8570ce80 SM |
319 | ;;;###autoload |
320 | (put 'allout-show-bodies 'safe-local-variable | |
64686e6d | 321 | (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) |
1977b8f6 | 322 | |
48bd8440 EZ |
323 | ;;;_ = allout-beginning-of-line-cycles |
324 | (defcustom allout-beginning-of-line-cycles t | |
325 | "*If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options. | |
326 | ||
327 | Cycling only happens on when the command is repeated, not when it | |
328 | follows a different command. | |
329 | ||
330 | Smart-placement means that repeated calls to this function will | |
331 | advance as follows: | |
332 | ||
333 | - if the cursor is on a non-headline body line and not on the first column: | |
334 | then it goes to the first column | |
335 | - if the cursor is on the first column of a non-headline body line: | |
336 | then it goes to the start of the headline within the item body | |
337 | - if the cursor is on the headline and not the start of the headline: | |
338 | then it goes to the start of the headline | |
339 | - if the cursor is on the start of the headline: | |
c07583cd | 340 | then it goes to the bullet character (for hotspot navigation) |
48bd8440 | 341 | - if the cursor is on the bullet character: |
c07583cd | 342 | then it goes to the first column of that line (the headline) |
48bd8440 EZ |
343 | - if the cursor is on the first column of the headline: |
344 | then it goes to the start of the headline within the item body. | |
345 | ||
346 | In this fashion, you can use the beginning-of-line command to do | |
347 | its normal job and then, when repeated, advance through the | |
348 | entry, cycling back to start. | |
349 | ||
350 | If this configuration variable is nil, then the cursor is just | |
351 | advanced to the beginning of the line and remains there on | |
352 | repeated calls." | |
353 | :type 'boolean :group 'allout) | |
354 | ;;;_ = allout-end-of-line-cycles | |
355 | (defcustom allout-end-of-line-cycles t | |
356 | "*If non-nil, \\[allout-end-of-line] will cycle through smart-placement options. | |
357 | ||
358 | Cycling only happens on when the command is repeated, not when it | |
359 | follows a different command. | |
360 | ||
60c7bbd2 | 361 | Smart placement means that repeated calls to this function will |
48bd8440 EZ |
362 | advance as follows: |
363 | ||
364 | - if the cursor is not on the end-of-line, | |
365 | then it goes to the end-of-line | |
366 | - if the cursor is on the end-of-line but not the end-of-entry, | |
367 | then it goes to the end-of-entry, exposing it if necessary | |
368 | - if the cursor is on the end-of-entry, | |
369 | then it goes to the end of the head line | |
370 | ||
371 | In this fashion, you can use the end-of-line command to do its | |
372 | normal job and then, when repeated, advance through the entry, | |
373 | cycling back to start. | |
374 | ||
375 | If this configuration variable is nil, then the cursor is just | |
376 | advanced to the end of the line and remains there on repeated | |
377 | calls." | |
378 | :type 'boolean :group 'allout) | |
379 | ||
fd5359c6 MR |
380 | ;;;_ = allout-header-prefix |
381 | (defcustom allout-header-prefix "." | |
48bd8440 EZ |
382 | ;; this string is treated as literal match. it will be `regexp-quote'd, so |
383 | ;; one cannot use regular expressions to match varying header prefixes. | |
19b84ba3 RS |
384 | "*Leading string which helps distinguish topic headers. |
385 | ||
386 | Outline topic header lines are identified by a leading topic | |
c567ac01 | 387 | header prefix, which mostly have the value of this var at their front. |
48bd8440 EZ |
388 | Level 1 topics are exceptions. They consist of only a single |
389 | character, which is typically set to the `allout-primary-bullet'." | |
4bef9110 SE |
390 | :type 'string |
391 | :group 'allout) | |
fd5359c6 | 392 | (make-variable-buffer-local 'allout-header-prefix) |
8570ce80 SM |
393 | ;;;###autoload |
394 | (put 'allout-header-prefix 'safe-local-variable 'stringp) | |
fd5359c6 MR |
395 | ;;;_ = allout-primary-bullet |
396 | (defcustom allout-primary-bullet "*" | |
19b84ba3 RS |
397 | "Bullet used for top-level outline topics. |
398 | ||
399 | Outline topic header lines are identified by a leading topic header | |
c567ac01 | 400 | prefix, which is concluded by bullets that includes the value of this |
fd5359c6 | 401 | var and the respective allout-*-bullets-string vars. |
c567ac01 | 402 | |
353e2ef2 | 403 | The value of an asterisk (`*') provides for backwards compatibility |
e126900f | 404 | with the original Emacs outline mode. See `allout-plain-bullets-string' |
2265e017 | 405 | and `allout-distinctive-bullets-string' for the range of available |
4bef9110 SE |
406 | bullets." |
407 | :type 'string | |
408 | :group 'allout) | |
fd5359c6 | 409 | (make-variable-buffer-local 'allout-primary-bullet) |
8570ce80 SM |
410 | ;;;###autoload |
411 | (put 'allout-primary-bullet 'safe-local-variable 'stringp) | |
fd5359c6 | 412 | ;;;_ = allout-plain-bullets-string |
d82979ea | 413 | (defcustom allout-plain-bullets-string ".," |
19b84ba3 RS |
414 | "*The bullets normally used in outline topic prefixes. |
415 | ||
fd5359c6 | 416 | See `allout-distinctive-bullets-string' for the other kind of |
c567ac01 | 417 | bullets. |
1977b8f6 | 418 | |
353e2ef2 | 419 | DO NOT include the close-square-bracket, `]', as a bullet. |
1977b8f6 | 420 | |
c567ac01 | 421 | Outline mode has to be reactivated in order for changes to the value |
4bef9110 SE |
422 | of this var to take effect." |
423 | :type 'string | |
424 | :group 'allout) | |
fd5359c6 | 425 | (make-variable-buffer-local 'allout-plain-bullets-string) |
8570ce80 SM |
426 | ;;;###autoload |
427 | (put 'allout-plain-bullets-string 'safe-local-variable 'stringp) | |
fd5359c6 | 428 | ;;;_ = allout-distinctive-bullets-string |
d82979ea | 429 | (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^" |
19b84ba3 | 430 | "*Persistent outline header bullets used to distinguish special topics. |
1977b8f6 | 431 | |
38b2ca53 NR |
432 | These bullets are distinguish topics with particular character. |
433 | They are not used by default in the topic creation routines, but | |
434 | are offered as options when you modify topic creation with a | |
435 | universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]). | |
436 | ||
437 | Distinctive bullets are not cycled when topics are shifted or | |
438 | otherwise automatically rebulleted, so their marking is | |
439 | persistent until deliberately changed. Their significance is | |
440 | purely by convention, however. Some conventions suggest | |
441 | themselves: | |
442 | ||
60c7bbd2 RS |
443 | `(' - open paren -- an aside or incidental point |
444 | `?' - question mark -- uncertain or outright question | |
445 | `!' - exclamation point/bang -- emphatic | |
446 | `[' - open square bracket -- meta-note, about item instead of item's subject | |
447 | `\"' - double quote -- a quotation or other citation | |
448 | `=' - equal sign -- an assignement, equating a name with some connotation | |
449 | `^' - carat -- relates to something above | |
38b2ca53 NR |
450 | |
451 | Some are more elusive, but their rationale may be recognizable: | |
452 | ||
60c7bbd2 RS |
453 | `+' - plus -- pending consideration, completion |
454 | `_' - underscore -- done, completed | |
455 | `&' - ampersand -- addendum, furthermore | |
38b2ca53 NR |
456 | |
457 | \(Some other non-plain bullets have special meaning to the | |
458 | software. By default: | |
459 | ||
60c7bbd2 RS |
460 | `~' marks encryptable topics -- see `allout-topic-encryption-bullet' |
461 | `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.) | |
38b2ca53 NR |
462 | |
463 | See `allout-plain-bullets-string' for the standard, alternating | |
464 | bullets. | |
1977b8f6 | 465 | |
fd5359c6 | 466 | You must run `set-allout-regexp' in order for outline mode to |
38b2ca53 | 467 | adopt changes of this value. |
19b84ba3 | 468 | |
353e2ef2 | 469 | DO NOT include the close-square-bracket, `]', on either of the bullet |
4bef9110 SE |
470 | strings." |
471 | :type 'string | |
472 | :group 'allout) | |
fd5359c6 | 473 | (make-variable-buffer-local 'allout-distinctive-bullets-string) |
8570ce80 SM |
474 | ;;;###autoload |
475 | (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp) | |
1977b8f6 | 476 | |
fd5359c6 MR |
477 | ;;;_ = allout-use-mode-specific-leader |
478 | (defcustom allout-use-mode-specific-leader t | |
19b84ba3 RS |
479 | "*When non-nil, use mode-specific topic-header prefixes. |
480 | ||
48bd8440 EZ |
481 | Allout outline mode will use the mode-specific `allout-mode-leaders' or |
482 | comment-start string, if any, to lead the topic prefix string, so topic | |
483 | headers look like comments in the programming language. It will also use | |
484 | the comment-start string, with an '_' appended, for `allout-primary-bullet'. | |
19b84ba3 | 485 | |
48bd8440 EZ |
486 | String values are used as literals, not regular expressions, so |
487 | do not escape any regulare-expression characters. | |
19b84ba3 | 488 | |
24190da5 | 489 | Value t means to first check for assoc value in `allout-mode-leaders' |
c07583cd | 490 | alist, then use comment-start string, if any, then use default (`.'). |
9179616f | 491 | \(See note about use of comment-start strings, below.) |
19b84ba3 | 492 | |
fd5359c6 | 493 | Set to the symbol for either of `allout-mode-leaders' or |
19b84ba3 RS |
494 | `comment-start' to use only one of them, respectively. |
495 | ||
c07583cd | 496 | Value nil means to always use the default (`.') and leave |
48bd8440 EZ |
497 | `allout-primary-bullet' unaltered. |
498 | ||
499 | comment-start strings that do not end in spaces are tripled in | |
500 | the header-prefix, and an `_' underscore is tacked on the end, to | |
501 | distinguish them from regular comment strings. comment-start | |
502 | strings that do end in spaces are not tripled, but an underscore | |
75bcb912 | 503 | is substituted for the space. [This presumes that the space is |
48bd8440 EZ |
504 | for appearance, not comment syntax. You can use |
505 | `allout-mode-leaders' to override this behavior, when | |
506 | undesired.]" | |
71296446 | 507 | :type '(choice (const t) (const nil) string |
fd5359c6 | 508 | (const allout-mode-leaders) |
4bef9110 SE |
509 | (const comment-start)) |
510 | :group 'allout) | |
8570ce80 SM |
511 | ;;;###autoload |
512 | (put 'allout-use-mode-specific-leader 'safe-local-variable | |
da506f05 RS |
513 | '(lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start)) |
514 | (stringp x)))) | |
fd5359c6 MR |
515 | ;;;_ = allout-mode-leaders |
516 | (defvar allout-mode-leaders '() | |
517 | "Specific allout-prefix leading strings per major modes. | |
19b84ba3 | 518 | |
48bd8440 EZ |
519 | Use this if the mode's comment-start string isn't what you |
520 | prefer, or if the mode lacks a comment-start string. See | |
521 | `allout-use-mode-specific-leader' for more details. | |
19b84ba3 RS |
522 | |
523 | If you're constructing a string that will comment-out outline | |
524 | structuring so it can be included in program code, append an extra | |
525 | character, like an \"_\" underscore, to distinguish the lead string | |
48bd8440 | 526 | from regular comments that start at the beginning-of-line.") |
19b84ba3 | 527 | |
fd5359c6 MR |
528 | ;;;_ = allout-old-style-prefixes |
529 | (defcustom allout-old-style-prefixes nil | |
aad94676 | 530 | "*When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. |
19b84ba3 RS |
531 | |
532 | Non-nil restricts the topic creation and modification | |
c567ac01 | 533 | functions to asterix-padded prefixes, so they look exactly |
e126900f | 534 | like the original Emacs-outline style prefixes. |
1977b8f6 | 535 | |
c567ac01 | 536 | Whatever the setting of this variable, both old and new style prefixes |
4bef9110 SE |
537 | are always respected by the topic maneuvering functions." |
538 | :type 'boolean | |
539 | :group 'allout) | |
fd5359c6 | 540 | (make-variable-buffer-local 'allout-old-style-prefixes) |
8570ce80 SM |
541 | ;;;###autoload |
542 | (put 'allout-old-style-prefixes 'safe-local-variable | |
64686e6d | 543 | (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) |
60c7bbd2 | 544 | ;;;_ = allout-stylish-prefixes -- alternating bullets |
fd5359c6 | 545 | (defcustom allout-stylish-prefixes t |
19b84ba3 | 546 | "*Do fancy stuff with topic prefix bullets according to level, etc. |
c567ac01 | 547 | |
19b84ba3 RS |
548 | Non-nil enables topic creation, modification, and repositioning |
549 | functions to vary the topic bullet char (the char that marks the topic | |
550 | depth) just preceding the start of the topic text) according to level. | |
353e2ef2 | 551 | Otherwise, only asterisks (`*') and distinctive bullets are used. |
19b84ba3 RS |
552 | |
553 | This is how an outline can look (but sans indentation) with stylish | |
554 | prefixes: | |
c567ac01 RS |
555 | |
556 | * Top level | |
557 | .* A topic | |
558 | . + One level 3 subtopic | |
559 | . . One level 4 subtopic | |
19b84ba3 | 560 | . . A second 4 subtopic |
c567ac01 | 561 | . + Another level 3 subtopic |
19b84ba3 RS |
562 | . #1 A numbered level 4 subtopic |
563 | . #2 Another | |
564 | . ! Another level 4 subtopic with a different distinctive bullet | |
565 | . #4 And another numbered level 4 subtopic | |
c567ac01 | 566 | |
19b84ba3 RS |
567 | This would be an outline with stylish prefixes inhibited (but the |
568 | numbered and other distinctive bullets retained): | |
c567ac01 RS |
569 | |
570 | * Top level | |
571 | .* A topic | |
19b84ba3 RS |
572 | . * One level 3 subtopic |
573 | . * One level 4 subtopic | |
574 | . * A second 4 subtopic | |
575 | . * Another level 3 subtopic | |
576 | . #1 A numbered level 4 subtopic | |
577 | . #2 Another | |
578 | . ! Another level 4 subtopic with a different distinctive bullet | |
579 | . #4 And another numbered level 4 subtopic | |
c567ac01 RS |
580 | |
581 | Stylish and constant prefixes (as well as old-style prefixes) are | |
582 | always respected by the topic maneuvering functions, regardless of | |
583 | this variable setting. | |
584 | ||
2265e017 | 585 | The setting of this var is not relevant when `allout-old-style-prefixes' |
4bef9110 SE |
586 | is non-nil." |
587 | :type 'boolean | |
588 | :group 'allout) | |
fd5359c6 | 589 | (make-variable-buffer-local 'allout-stylish-prefixes) |
8570ce80 SM |
590 | ;;;###autoload |
591 | (put 'allout-stylish-prefixes 'safe-local-variable | |
64686e6d | 592 | (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) |
1977b8f6 | 593 | |
fd5359c6 MR |
594 | ;;;_ = allout-numbered-bullet |
595 | (defcustom allout-numbered-bullet "#" | |
19b84ba3 RS |
596 | "*String designating bullet of topics that have auto-numbering; nil for none. |
597 | ||
a0776d6b | 598 | Topics having this bullet have automatic maintenance of a sibling |
19b84ba3 | 599 | sequence-number tacked on, just after the bullet. Conventionally set |
c567ac01 | 600 | to \"#\", you can set it to a bullet of your choice. A nil value |
4bef9110 SE |
601 | disables numbering maintenance." |
602 | :type '(choice (const nil) string) | |
603 | :group 'allout) | |
fd5359c6 | 604 | (make-variable-buffer-local 'allout-numbered-bullet) |
8570ce80 | 605 | ;;;###autoload |
64686e6d RS |
606 | (put 'allout-numbered-bullet 'safe-local-variable |
607 | (if (fboundp 'string-or-null-p) | |
608 | 'string-or-null-p | |
609 | '(lambda (x) (or (stringp x) (null x))))) | |
fd5359c6 MR |
610 | ;;;_ = allout-file-xref-bullet |
611 | (defcustom allout-file-xref-bullet "@" | |
612 | "*Bullet signifying file cross-references, for `allout-resolve-xref'. | |
19b84ba3 | 613 | |
9179616f | 614 | Set this var to the bullet you want to use for file cross-references." |
4bef9110 SE |
615 | :type '(choice (const nil) string) |
616 | :group 'allout) | |
8570ce80 | 617 | ;;;###autoload |
64686e6d RS |
618 | (put 'allout-file-xref-bullet 'safe-local-variable |
619 | (if (fboundp 'string-or-null-p) | |
620 | 'string-or-null-p | |
621 | '(lambda (x) (or (stringp x) (null x))))) | |
fd5359c6 MR |
622 | ;;;_ = allout-presentation-padding |
623 | (defcustom allout-presentation-padding 2 | |
9179616f DL |
624 | "*Presentation-format white-space padding factor, for greater indent." |
625 | :type 'integer | |
626 | :group 'allout) | |
627 | ||
fd5359c6 | 628 | (make-variable-buffer-local 'allout-presentation-padding) |
8570ce80 SM |
629 | ;;;###autoload |
630 | (put 'allout-presentation-padding 'safe-local-variable 'integerp) | |
9179616f | 631 | |
fd5359c6 MR |
632 | ;;;_ = allout-abbreviate-flattened-numbering |
633 | (defcustom allout-abbreviate-flattened-numbering nil | |
634 | "*If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic | |
9179616f DL |
635 | numbers to minimal amount with some context. Otherwise, entire |
636 | numbers are always used." | |
637 | :type 'boolean | |
638 | :group 'allout) | |
639 | ||
c567ac01 | 640 | ;;;_ + LaTeX formatting |
fd5359c6 MR |
641 | ;;;_ - allout-number-pages |
642 | (defcustom allout-number-pages nil | |
4bef9110 SE |
643 | "*Non-nil turns on page numbering for LaTeX formatting of an outline." |
644 | :type 'boolean | |
645 | :group 'allout) | |
fd5359c6 MR |
646 | ;;;_ - allout-label-style |
647 | (defcustom allout-label-style "\\large\\bf" | |
4bef9110 SE |
648 | "*Font and size of labels for LaTeX formatting of an outline." |
649 | :type 'string | |
650 | :group 'allout) | |
fd5359c6 MR |
651 | ;;;_ - allout-head-line-style |
652 | (defcustom allout-head-line-style "\\large\\sl " | |
4bef9110 SE |
653 | "*Font and size of entries for LaTeX formatting of an outline." |
654 | :type 'string | |
655 | :group 'allout) | |
fd5359c6 MR |
656 | ;;;_ - allout-body-line-style |
657 | (defcustom allout-body-line-style " " | |
4bef9110 SE |
658 | "*Font and size of entries for LaTeX formatting of an outline." |
659 | :type 'string | |
660 | :group 'allout) | |
fd5359c6 MR |
661 | ;;;_ - allout-title-style |
662 | (defcustom allout-title-style "\\Large\\bf" | |
4bef9110 SE |
663 | "*Font and size of titles for LaTeX formatting of an outline." |
664 | :type 'string | |
665 | :group 'allout) | |
fd5359c6 | 666 | ;;;_ - allout-title |
d82979ea | 667 | (defcustom allout-title '(or buffer-file-name (buffer-name)) |
c567ac01 | 668 | "*Expression to be evaluated to determine the title for LaTeX |
4bef9110 SE |
669 | formatted copy." |
670 | :type 'sexp | |
671 | :group 'allout) | |
fd5359c6 MR |
672 | ;;;_ - allout-line-skip |
673 | (defcustom allout-line-skip ".05cm" | |
4bef9110 SE |
674 | "*Space between lines for LaTeX formatting of an outline." |
675 | :type 'string | |
676 | :group 'allout) | |
fd5359c6 MR |
677 | ;;;_ - allout-indent |
678 | (defcustom allout-indent ".3cm" | |
4bef9110 SE |
679 | "*LaTeX formatted depth-indent spacing." |
680 | :type 'string | |
681 | :group 'allout) | |
c567ac01 | 682 | |
d82979ea | 683 | ;;;_ + Topic encryption |
8570ce80 SM |
684 | ;;;_ = allout-encryption group |
685 | (defgroup allout-encryption nil | |
686 | "Settings for topic encryption features of allout outliner." | |
687 | :group 'allout) | |
d82979ea EZ |
688 | ;;;_ = allout-topic-encryption-bullet |
689 | (defcustom allout-topic-encryption-bullet "~" | |
690 | "*Bullet signifying encryption of the entry's body." | |
691 | :type '(choice (const nil) string) | |
21e8bc99 | 692 | :version "22.1" |
8570ce80 | 693 | :group 'allout-encryption) |
0949617b EZ |
694 | ;;;_ = allout-passphrase-verifier-handling |
695 | (defcustom allout-passphrase-verifier-handling t | |
696 | "*Enable use of symmetric encryption passphrase verifier if non-nil. | |
d82979ea EZ |
697 | |
698 | See the docstring for the `allout-enable-file-variable-adjustment' | |
699 | variable for details about allout ajustment of file variables." | |
0949617b | 700 | :type 'boolean |
21e8bc99 | 701 | :version "22.1" |
8570ce80 | 702 | :group 'allout-encryption) |
0949617b EZ |
703 | (make-variable-buffer-local 'allout-passphrase-verifier-handling) |
704 | ;;;_ = allout-passphrase-hint-handling | |
705 | (defcustom allout-passphrase-hint-handling 'always | |
706 | "*Dictate outline encryption passphrase reminder handling: | |
d82979ea | 707 | |
60c7bbd2 RS |
708 | always -- always show reminder when prompting |
709 | needed -- show reminder on passphrase entry failure | |
710 | disabled -- never present or adjust reminder | |
d82979ea EZ |
711 | |
712 | See the docstring for the `allout-enable-file-variable-adjustment' | |
713 | variable for details about allout ajustment of file variables." | |
714 | :type '(choice (const always) | |
715 | (const needed) | |
d82979ea | 716 | (const disabled)) |
21e8bc99 | 717 | :version "22.1" |
8570ce80 | 718 | :group 'allout-encryption) |
0949617b | 719 | (make-variable-buffer-local 'allout-passphrase-hint-handling) |
d82979ea | 720 | ;;;_ = allout-encrypt-unencrypted-on-saves |
96b83743 | 721 | (defcustom allout-encrypt-unencrypted-on-saves t |
d82979ea EZ |
722 | "*When saving, should topics pending encryption be encrypted? |
723 | ||
724 | The idea is to prevent file-system exposure of any un-encrypted stuff, and | |
725 | mostly covers both deliberate file writes and auto-saves. | |
726 | ||
727 | - Yes: encrypt all topics pending encryption, even if it's the one | |
c07583cd | 728 | currently being edited. (In that case, the currently edited topic |
d82979ea EZ |
729 | will be automatically decrypted before any user interaction, so they |
730 | can continue editing but the copy on the file system will be | |
731 | encrypted.) | |
732 | Auto-saves will use the \"All except current topic\" mode if this | |
60c7bbd2 | 733 | one is selected, to avoid practical difficulties -- see below. |
d82979ea EZ |
734 | - All except current topic: skip the topic currently being edited, even if |
735 | it's pending encryption. This may expose the current topic on the | |
736 | file sytem, but avoids the nuisance of prompts for the encryption | |
0949617b | 737 | passphrase in the middle of editing for, eg, autosaves. |
d82979ea EZ |
738 | This mode is used for auto-saves for both this option and \"Yes\". |
739 | - No: leave it to the user to encrypt any unencrypted topics. | |
740 | ||
741 | For practical reasons, auto-saves always use the 'except-current policy | |
c07583cd | 742 | when auto-encryption is enabled. (Otherwise, spurious passphrase prompts |
0949617b EZ |
743 | and unavoidable timing collisions are too disruptive.) If security for a |
744 | file requires that even the current topic is never auto-saved in the clear, | |
d82979ea EZ |
745 | disable auto-saves for that file." |
746 | ||
747 | :type '(choice (const :tag "Yes" t) | |
748 | (const :tag "All except current topic" except-current) | |
749 | (const :tag "No" nil)) | |
21e8bc99 | 750 | :version "22.1" |
8570ce80 | 751 | :group 'allout-encryption) |
d82979ea EZ |
752 | (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) |
753 | ||
01fc9422 EZ |
754 | ;;;_ + Developer |
755 | ;;;_ = allout-developer group | |
756 | (defgroup allout-developer nil | |
757 | "Settings for topic encryption features of allout outliner." | |
758 | :group 'allout) | |
759 | ;;;_ = allout-run-unit-tests-on-load | |
760 | (defcustom allout-run-unit-tests-on-load nil | |
761 | "*When non-nil, unit tests will be run at end of loading the allout module. | |
762 | ||
763 | Generally, allout code developers are the only ones who'll want to set this. | |
764 | ||
765 | \(If set, this makes it an even better practice to exercise changes by | |
5204800f NR |
766 | doing byte-compilation with a repeat count, so the file is loaded after |
767 | compilation.) | |
01fc9422 EZ |
768 | |
769 | See `allout-run-unit-tests' to see what's run." | |
770 | :type 'boolean | |
771 | :group 'allout-developer) | |
772 | ||
c567ac01 RS |
773 | ;;;_ + Miscellaneous customization |
774 | ||
d82979ea EZ |
775 | ;;;_ = allout-enable-file-variable-adjustment |
776 | (defcustom allout-enable-file-variable-adjustment t | |
0949617b | 777 | "*If non-nil, some allout outline actions edit Emacs local file var text. |
d82979ea EZ |
778 | |
779 | This can range from changes to existing entries, addition of new ones, | |
780 | and creation of a new local variables section when necessary. | |
19b84ba3 | 781 | |
d82979ea EZ |
782 | Emacs file variables adjustments are also inhibited if `enable-local-variables' |
783 | is nil. | |
c567ac01 | 784 | |
d82979ea | 785 | Operations potentially causing edits include allout encryption routines. |
69027dea | 786 | For details, see `allout-toggle-current-subtree-encryption's docstring." |
4bef9110 SE |
787 | :type 'boolean |
788 | :group 'allout) | |
d82979ea | 789 | (make-variable-buffer-local 'allout-enable-file-variable-adjustment) |
c567ac01 | 790 | |
60c7bbd2 | 791 | ;;;_* CODE -- no user customizations below. |
c567ac01 | 792 | |
9179616f DL |
793 | ;;;_ #1 Internal Outline Formatting and Configuration |
794 | ;;;_ : Version | |
fd5359c6 | 795 | ;;;_ = allout-version |
4034b0e2 | 796 | (defvar allout-version "2.2.1" |
c07583cd | 797 | "Version of currently loaded outline package. (allout.el)") |
fd5359c6 MR |
798 | ;;;_ > allout-version |
799 | (defun allout-version (&optional here) | |
19b84ba3 RS |
800 | "Return string describing the loaded outline version." |
801 | (interactive "P") | |
fd5359c6 | 802 | (let ((msg (concat "Allout Outline Mode v " allout-version))) |
eac9cf5f | 803 | (if here (insert msg)) |
19b84ba3 RS |
804 | (message "%s" msg) |
805 | msg)) | |
69027dea EZ |
806 | ;;;_ : Mode activation (defined here because it's referenced early) |
807 | ;;;_ = allout-mode | |
808 | (defvar allout-mode nil "Allout outline mode minor-mode flag.") | |
809 | (make-variable-buffer-local 'allout-mode) | |
4034b0e2 | 810 | ;;;_ = allout-layout nil |
60c7bbd2 | 811 | (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring. |
4034b0e2 LT |
812 | "Buffer-specific setting for allout layout. |
813 | ||
c07583cd | 814 | In buffers where this is non-nil (and if `allout-init' has been run, to |
4034b0e2 LT |
815 | enable this behavior), `allout-mode' will be automatically activated. The |
816 | layout dictated by the value will be used to set the initial exposure when | |
817 | `allout-mode' is activated. | |
818 | ||
819 | \*You should not setq-default this variable non-nil unless you want every | |
820 | visited file to be treated as an allout file.* | |
821 | ||
822 | The value would typically be set by a file local variable. For | |
823 | example, the following lines at the bottom of an Emacs Lisp file: | |
824 | ||
825 | ;;;Local variables: | |
c07583cd | 826 | ;;;allout-layout: (0 : -1 -1 0) |
4034b0e2 LT |
827 | ;;;End: |
828 | ||
829 | dictate activation of `allout-mode' mode when the file is visited | |
830 | \(presuming allout-init was already run), followed by the | |
c07583cd | 831 | equivalent of `(allout-expose-topic 0 : -1 -1 0)'. (This is |
4034b0e2 LT |
832 | the layout used for the allout.el source file.) |
833 | ||
834 | `allout-default-layout' describes the specification format. | |
835 | `allout-layout' can additionally have the value `t', in which | |
836 | case the value of `allout-default-layout' is used.") | |
837 | (make-variable-buffer-local 'allout-layout) | |
b1a569b5 | 838 | ;;;###autoload |
8570ce80 | 839 | (put 'allout-layout 'safe-local-variable |
da506f05 | 840 | '(lambda (x) (or (numberp x) (listp x) (memq x '(: * + -))))) |
4034b0e2 | 841 | |
9179616f | 842 | ;;;_ : Topic header format |
fd5359c6 MR |
843 | ;;;_ = allout-regexp |
844 | (defvar allout-regexp "" | |
c567ac01 | 845 | "*Regular expression to match the beginning of a heading line. |
19b84ba3 | 846 | |
c567ac01 RS |
847 | Any line whose beginning matches this regexp is considered a |
848 | heading. This var is set according to the user configuration vars | |
2265e017 | 849 | by `set-allout-regexp'.") |
fd5359c6 MR |
850 | (make-variable-buffer-local 'allout-regexp) |
851 | ;;;_ = allout-bullets-string | |
852 | (defvar allout-bullets-string "" | |
19b84ba3 RS |
853 | "A string dictating the valid set of outline topic bullets. |
854 | ||
60c7bbd2 | 855 | This var should *not* be set by the user -- it is set by `set-allout-regexp', |
fd5359c6 MR |
856 | and is produced from the elements of `allout-plain-bullets-string' |
857 | and `allout-distinctive-bullets-string'.") | |
858 | (make-variable-buffer-local 'allout-bullets-string) | |
859 | ;;;_ = allout-bullets-string-len | |
860 | (defvar allout-bullets-string-len 0 | |
2265e017 | 861 | "Length of current buffers' `allout-plain-bullets-string'.") |
fd5359c6 | 862 | (make-variable-buffer-local 'allout-bullets-string-len) |
d8350998 CY |
863 | ;;;_ = allout-depth-specific-regexp |
864 | (defvar allout-depth-specific-regexp "" | |
865 | "*Regular expression to match a heading line prefix for a particular depth. | |
866 | ||
867 | This expression is used to search for depth-specific topic | |
868 | headers at depth 2 and greater. Use `allout-depth-one-regexp' | |
869 | for to seek topics at depth one. | |
870 | ||
871 | This var is set according to the user configuration vars by | |
872 | `set-allout-regexp'. It is prepared with format strings for two | |
873 | decimal numbers, which should each be one less than the depth of the | |
874 | topic prefix to be matched.") | |
875 | (make-variable-buffer-local 'allout-depth-specific-regexp) | |
876 | ;;;_ = allout-depth-one-regexp | |
877 | (defvar allout-depth-one-regexp "" | |
878 | "*Regular expression to match a heading line prefix for depth one. | |
879 | ||
880 | This var is set according to the user configuration vars by | |
881 | `set-allout-regexp'. It is prepared with format strings for two | |
882 | decimal numbers, which should each be one less than the depth of the | |
883 | topic prefix to be matched.") | |
884 | (make-variable-buffer-local 'allout-depth-one-regexp) | |
fd5359c6 MR |
885 | ;;;_ = allout-line-boundary-regexp |
886 | (defvar allout-line-boundary-regexp () | |
42c3e51c | 887 | "`allout-regexp' prepended with a newline for the search target. |
19b84ba3 | 888 | |
d8350998 | 889 | This is properly set by `set-allout-regexp'.") |
fd5359c6 MR |
890 | (make-variable-buffer-local 'allout-line-boundary-regexp) |
891 | ;;;_ = allout-bob-regexp | |
892 | (defvar allout-bob-regexp () | |
d8350998 | 893 | "Like `allout-line-boundary-regexp', for headers at beginning of buffer.") |
fd5359c6 MR |
894 | (make-variable-buffer-local 'allout-bob-regexp) |
895 | ;;;_ = allout-header-subtraction | |
896 | (defvar allout-header-subtraction (1- (length allout-header-prefix)) | |
897 | "Allout-header prefix length to subtract when computing topic depth.") | |
898 | (make-variable-buffer-local 'allout-header-subtraction) | |
899 | ;;;_ = allout-plain-bullets-string-len | |
900 | (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) | |
2265e017 | 901 | "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") |
fd5359c6 MR |
902 | (make-variable-buffer-local 'allout-plain-bullets-string-len) |
903 | ||
d8350998 | 904 | ;;;_ = allout-doublecheck-at-and-shallower |
2a1408fd | 905 | (defconst allout-doublecheck-at-and-shallower 3 |
ede4ac6a | 906 | "Validate apparent topics of this depth and shallower as being non-aberrant. |
fd5359c6 | 907 | |
2a1408fd DN |
908 | Verified with `allout-aberrant-container-p'. The usefulness of |
909 | this check is limited to shallow depths, because the | |
910 | determination of aberrance is according to the mistaken item | |
911 | being followed by a legitimate item of excessively greater depth. | |
912 | ||
913 | The classic example of a mistaken item, for a standard allout | |
914 | outline configuration, is a body line that begins with an '...' | |
915 | ellipsis. This happens to contain a legitimate depth-2 header | |
916 | prefix, constituted by two '..' dots at the beginning of the | |
917 | line. The only thing that can distinguish it *in principle* from | |
918 | a legitimate one is if the following real header is at a depth | |
919 | that is discontinuous from the depth of 2 implied by the | |
920 | ellipsis, ie depth 4 or more. As the depth being tested gets | |
921 | greater, the likelihood of this kind of disqualification is | |
922 | lower, and the usefulness of this test is lower. | |
923 | ||
924 | Extending the depth of the doublecheck increases the amount it is | |
925 | applied, increasing the cost of the test - on casual estimation, | |
926 | for outlines with many deep topics, geometrically (O(n)?). | |
927 | Taken together with decreasing likelihood that the test will be | |
928 | useful at greater depths, more modest doublecheck limits are more | |
929 | suitably economical.") | |
fd5359c6 MR |
930 | ;;;_ X allout-reset-header-lead (header-lead) |
931 | (defun allout-reset-header-lead (header-lead) | |
c567ac01 | 932 | "*Reset the leading string used to identify topic headers." |
1977b8f6 | 933 | (interactive "sNew lead string: ") |
fd5359c6 MR |
934 | (setq allout-header-prefix header-lead) |
935 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
936 | (set-allout-regexp)) | |
937 | ;;;_ X allout-lead-with-comment-string (header-lead) | |
938 | (defun allout-lead-with-comment-string (&optional header-lead) | |
19b84ba3 RS |
939 | "*Set the topic-header leading string to specified string. |
940 | ||
941 | Useful when for encapsulating outline structure in programming | |
942 | language comments. Returns the leading string." | |
1977b8f6 RS |
943 | |
944 | (interactive "P") | |
945 | (if (not (stringp header-lead)) | |
946 | (setq header-lead (read-string | |
947 | "String prefix for topic headers: "))) | |
fd5359c6 MR |
948 | (setq allout-reindent-bodies nil) |
949 | (allout-reset-header-lead header-lead) | |
1977b8f6 | 950 | header-lead) |
48bd8440 EZ |
951 | ;;;_ > allout-infer-header-lead-and-primary-bullet () |
952 | (defun allout-infer-header-lead-and-primary-bullet () | |
953 | "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'. | |
19b84ba3 RS |
954 | |
955 | Works according to settings of: | |
956 | ||
8d118843 | 957 | `comment-start' |
fd5359c6 MR |
958 | `allout-header-prefix' (default) |
959 | `allout-use-mode-specific-leader' | |
960 | and `allout-mode-leaders'. | |
19b84ba3 | 961 | |
c07583cd | 962 | Apply this via (re)activation of `allout-mode', rather than |
8d118843 | 963 | invoking it directly." |
fd5359c6 MR |
964 | (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) |
965 | (if (or (stringp allout-use-mode-specific-leader) | |
966 | (memq allout-use-mode-specific-leader | |
967 | '(allout-mode-leaders | |
19b84ba3 RS |
968 | comment-start |
969 | t))) | |
fd5359c6 | 970 | allout-use-mode-specific-leader |
60c7bbd2 | 971 | ;; Oops -- garbled value, equate with effect of t: |
19b84ba3 RS |
972 | t))) |
973 | (leader | |
974 | (cond | |
975 | ((not use-leader) nil) | |
976 | ;; Use the explicitly designated leader: | |
977 | ((stringp use-leader) use-leader) | |
fd5359c6 | 978 | (t (or (and (memq use-leader '(t allout-mode-leaders)) |
19b84ba3 | 979 | ;; Get it from outline mode leaders? |
fd5359c6 MR |
980 | (cdr (assq major-mode allout-mode-leaders))) |
981 | ;; ... didn't get from allout-mode-leaders... | |
19b84ba3 RS |
982 | (and (memq use-leader '(t comment-start)) |
983 | comment-start | |
984 | ;; Use comment-start, maybe tripled, and with | |
353e2ef2 | 985 | ;; underscore: |
19b84ba3 RS |
986 | (concat |
987 | (if (string= " " | |
988 | (substring comment-start | |
989 | (1- (length comment-start)))) | |
990 | ;; Use comment-start, sans trailing space: | |
991 | (substring comment-start 0 -1) | |
992 | (concat comment-start comment-start comment-start)) | |
993 | ;; ... and append underscore, whichever: | |
994 | "_"))))))) | |
995 | (if (not leader) | |
996 | nil | |
48bd8440 EZ |
997 | (setq allout-header-prefix leader) |
998 | (if (not allout-old-style-prefixes) | |
ea18b2b1 | 999 | ;; setting allout-primary-bullet makes the top level topics use -- |
60c7bbd2 | 1000 | ;; actually, be -- the special prefix: |
48bd8440 EZ |
1001 | (setq allout-primary-bullet leader)) |
1002 | allout-header-prefix))) | |
1003 | (defalias 'allout-infer-header-lead | |
1004 | 'allout-infer-header-lead-and-primary-bullet) | |
fd5359c6 MR |
1005 | ;;;_ > allout-infer-body-reindent () |
1006 | (defun allout-infer-body-reindent () | |
1007 | "Determine proper setting for `allout-reindent-bodies'. | |
8d118843 | 1008 | |
c07583cd | 1009 | Depends on default setting of `allout-reindent-bodies' (which see) |
8d118843 RS |
1010 | and presence of setting for `comment-start', to tell whether the |
1011 | file is programming code." | |
fd5359c6 | 1012 | (if (and allout-reindent-bodies |
8d118843 | 1013 | comment-start |
fd5359c6 MR |
1014 | (not (eq 'force allout-reindent-bodies))) |
1015 | (setq allout-reindent-bodies nil))) | |
1016 | ;;;_ > set-allout-regexp () | |
1017 | (defun set-allout-regexp () | |
19b84ba3 RS |
1018 | "Generate proper topic-header regexp form for outline functions. |
1019 | ||
fd5359c6 | 1020 | Works with respect to `allout-plain-bullets-string' and |
d8350998 CY |
1021 | `allout-distinctive-bullets-string'. |
1022 | ||
1023 | Also refresh various data structures that hinge on the regexp." | |
1977b8f6 RS |
1024 | |
1025 | (interactive) | |
fd5359c6 MR |
1026 | ;; Derive allout-bullets-string from user configured components: |
1027 | (setq allout-bullets-string "") | |
1028 | (let ((strings (list 'allout-plain-bullets-string | |
1029 | 'allout-distinctive-bullets-string | |
1030 | 'allout-primary-bullet)) | |
1977b8f6 RS |
1031 | cur-string |
1032 | cur-len | |
c567ac01 | 1033 | cur-char |
96b83743 | 1034 | index) |
1977b8f6 | 1035 | (while strings |
96b83743 | 1036 | (setq index 0) |
1977b8f6 RS |
1037 | (setq cur-len (length (setq cur-string (symbol-value (car strings))))) |
1038 | (while (< index cur-len) | |
1039 | (setq cur-char (aref cur-string index)) | |
fd5359c6 MR |
1040 | (setq allout-bullets-string |
1041 | (concat allout-bullets-string | |
1977b8f6 RS |
1042 | (cond |
1043 | ; Single dash would denote a | |
1044 | ; sequence, repeated denotes | |
1045 | ; a dash: | |
1046 | ((eq cur-char ?-) "--") | |
1047 | ; literal close-square-bracket | |
1048 | ; doesn't work right in the | |
1049 | ; expr, exclude it: | |
1050 | ((eq cur-char ?\]) "") | |
1051 | (t (regexp-quote (char-to-string cur-char)))))) | |
1052 | (setq index (1+ index))) | |
1053 | (setq strings (cdr strings))) | |
1054 | ) | |
fd5359c6 MR |
1055 | ;; Derive next for repeated use in allout-pending-bullet: |
1056 | (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) | |
1057 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
d8350998 | 1058 | |
42c3e51c | 1059 | (let (new-part old-part formfeed-part) |
d8350998 CY |
1060 | (setq new-part (concat "\\(" |
1061 | (regexp-quote allout-header-prefix) | |
1062 | "[ \t]*" | |
1063 | ;; already regexp-quoted in a custom way: | |
1064 | "[" allout-bullets-string "]" | |
1065 | "\\)") | |
1066 | old-part (concat "\\(" | |
1067 | (regexp-quote allout-primary-bullet) | |
1068 | "\\|" | |
1069 | (regexp-quote allout-header-prefix) | |
1070 | "\\)" | |
1071 | "+" | |
1072 | " ?[^" allout-primary-bullet "]") | |
42c3e51c KM |
1073 | formfeed-part "\\(\^L\\)" |
1074 | ||
d8350998 CY |
1075 | allout-regexp (concat new-part |
1076 | "\\|" | |
1077 | old-part | |
42c3e51c KM |
1078 | "\\|" |
1079 | formfeed-part) | |
d8350998 CY |
1080 | |
1081 | allout-line-boundary-regexp (concat "\n" new-part | |
1082 | "\\|" | |
42c3e51c KM |
1083 | "\n" old-part |
1084 | "\\|" | |
1085 | "\n" formfeed-part) | |
d8350998 CY |
1086 | |
1087 | allout-bob-regexp (concat "\\`" new-part | |
1088 | "\\|" | |
42c3e51c KM |
1089 | "\\`" old-part |
1090 | "\\|" | |
1091 | "\\`" formfeed-part | |
1092 | )) | |
d8350998 CY |
1093 | |
1094 | (setq allout-depth-specific-regexp | |
1095 | (concat "\\(^\\|\\`\\)" | |
1096 | "\\(" | |
1097 | ||
1098 | ;; new-style spacers-then-bullet string: | |
1099 | "\\(" | |
1100 | (allout-format-quote (regexp-quote allout-header-prefix)) | |
1101 | " \\{%s\\}" | |
1102 | "[" (allout-format-quote allout-bullets-string) "]" | |
1103 | "\\)" | |
1104 | ||
1105 | ;; old-style all-bullets string, if primary not multi-char: | |
1106 | (if (< 0 allout-header-subtraction) | |
1107 | "" | |
1108 | (concat "\\|\\(" | |
1109 | (allout-format-quote | |
1110 | (regexp-quote allout-primary-bullet)) | |
1111 | (allout-format-quote | |
1112 | (regexp-quote allout-primary-bullet)) | |
1113 | (allout-format-quote | |
1114 | (regexp-quote allout-primary-bullet)) | |
1115 | "\\{%s\\}" | |
1116 | ;; disqualify greater depths: | |
1117 | "[^" | |
1118 | (allout-format-quote allout-primary-bullet) | |
1119 | "]\\)" | |
1120 | )) | |
1121 | "\\)" | |
1122 | )) | |
1123 | (setq allout-depth-one-regexp | |
1124 | (concat "\\(^\\|\\`\\)" | |
1125 | "\\(" | |
1126 | ||
1127 | "\\(" | |
1128 | (regexp-quote allout-header-prefix) | |
1129 | ;; disqualify any bullet char following any amount of | |
1130 | ;; intervening whitespace: | |
1131 | " *" | |
1132 | (concat "[^ " allout-bullets-string "]") | |
1133 | "\\)" | |
1134 | (if (< 0 allout-header-subtraction) | |
1135 | ;; Need not support anything like the old | |
1136 | ;; bullet style if the prefix is multi-char. | |
1137 | "" | |
1138 | (concat "\\|" | |
1139 | (regexp-quote allout-primary-bullet) | |
1140 | ;; disqualify deeper primary-bullet sequences: | |
1141 | "[^" allout-primary-bullet "]")) | |
1142 | "\\)" | |
1143 | )))) | |
9179616f | 1144 | ;;;_ : Key bindings |
fd5359c6 MR |
1145 | ;;;_ = allout-mode-map |
1146 | (defvar allout-mode-map nil "Keybindings for (allout) outline minor mode.") | |
1147 | ;;;_ > produce-allout-mode-map (keymap-alist &optional base-map) | |
1148 | (defun produce-allout-mode-map (keymap-list &optional base-map) | |
75bcb912 | 1149 | "Produce keymap for use as `allout-mode-map', from KEYMAP-LIST. |
19b84ba3 RS |
1150 | |
1151 | Built on top of optional BASE-MAP, or empty sparse map if none specified. | |
75bcb912 | 1152 | See doc string for `allout-keybindings-list' for format of binding list." |
9179616f | 1153 | (let ((map (or base-map (make-sparse-keymap))) |
fd5359c6 | 1154 | (pref (list allout-command-prefix))) |
5110e166 | 1155 | (mapc (function |
2a1408fd DN |
1156 | (lambda (cell) |
1157 | (let ((add-pref (null (cdr (cdr cell)))) | |
1158 | (key-suff (list (car cell)))) | |
1159 | (apply 'define-key | |
1160 | (list map | |
1161 | (apply 'vconcat (if add-pref | |
1162 | (append pref key-suff) | |
1163 | key-suff)) | |
1164 | (car (cdr cell))))))) | |
1165 | keymap-list) | |
19b84ba3 | 1166 | map)) |
9179616f | 1167 | ;;;_ : Menu bar |
95c12694 RS |
1168 | (defvar allout-mode-exposure-menu) |
1169 | (defvar allout-mode-editing-menu) | |
1170 | (defvar allout-mode-navigation-menu) | |
1171 | (defvar allout-mode-misc-menu) | |
fd5359c6 | 1172 | (defun produce-allout-mode-menubar-entries () |
9179616f | 1173 | (require 'easymenu) |
fd5359c6 MR |
1174 | (easy-menu-define allout-mode-exposure-menu |
1175 | allout-mode-map | |
9179616f DL |
1176 | "Allout outline exposure menu." |
1177 | '("Exposure" | |
fd5359c6 MR |
1178 | ["Show Entry" allout-show-current-entry t] |
1179 | ["Show Children" allout-show-children t] | |
1180 | ["Show Subtree" allout-show-current-subtree t] | |
1181 | ["Hide Subtree" allout-hide-current-subtree t] | |
1182 | ["Hide Leaves" allout-hide-current-leaves t] | |
9179616f | 1183 | "----" |
fd5359c6 MR |
1184 | ["Show All" allout-show-all t])) |
1185 | (easy-menu-define allout-mode-editing-menu | |
1186 | allout-mode-map | |
9179616f DL |
1187 | "Allout outline editing menu." |
1188 | '("Headings" | |
fd5359c6 MR |
1189 | ["Open Sibling" allout-open-sibtopic t] |
1190 | ["Open Subtopic" allout-open-subtopic t] | |
1191 | ["Open Supertopic" allout-open-supertopic t] | |
9179616f | 1192 | "----" |
fd5359c6 MR |
1193 | ["Shift Topic In" allout-shift-in t] |
1194 | ["Shift Topic Out" allout-shift-out t] | |
1195 | ["Rebullet Topic" allout-rebullet-topic t] | |
1196 | ["Rebullet Heading" allout-rebullet-current-heading t] | |
d82979ea EZ |
1197 | ["Number Siblings" allout-number-siblings t] |
1198 | "----" | |
1199 | ["Toggle Topic Encryption" | |
1200 | allout-toggle-current-subtree-encryption | |
1201 | (> (allout-current-depth) 1)])) | |
fd5359c6 MR |
1202 | (easy-menu-define allout-mode-navigation-menu |
1203 | allout-mode-map | |
9179616f DL |
1204 | "Allout outline navigation menu." |
1205 | '("Navigation" | |
fd5359c6 | 1206 | ["Next Visible Heading" allout-next-visible-heading t] |
9179616f | 1207 | ["Previous Visible Heading" |
fd5359c6 | 1208 | allout-previous-visible-heading t] |
9179616f | 1209 | "----" |
fd5359c6 MR |
1210 | ["Up Level" allout-up-current-level t] |
1211 | ["Forward Current Level" allout-forward-current-level t] | |
9179616f | 1212 | ["Backward Current Level" |
fd5359c6 | 1213 | allout-backward-current-level t] |
9179616f DL |
1214 | "----" |
1215 | ["Beginning of Entry" | |
fd5359c6 | 1216 | allout-beginning-of-current-entry t] |
d82979ea | 1217 | ["End of Entry" allout-end-of-entry t] |
fd5359c6 MR |
1218 | ["End of Subtree" allout-end-of-current-subtree t])) |
1219 | (easy-menu-define allout-mode-misc-menu | |
1220 | allout-mode-map | |
9179616f DL |
1221 | "Allout outlines miscellaneous bindings." |
1222 | '("Misc" | |
fd5359c6 | 1223 | ["Version" allout-version t] |
9179616f | 1224 | "----" |
fd5359c6 | 1225 | ["Duplicate Exposed" allout-copy-exposed-to-buffer t] |
9179616f | 1226 | ["Duplicate Exposed, numbered" |
71296446 | 1227 | allout-flatten-exposed-to-buffer t] |
9179616f | 1228 | ["Duplicate Exposed, indented" |
71296446 | 1229 | allout-indented-exposed-to-buffer t] |
9179616f | 1230 | "----" |
fd5359c6 MR |
1231 | ["Set Header Lead" allout-reset-header-lead t] |
1232 | ["Set New Exposure" allout-expose-topic t]))) | |
01fc9422 | 1233 | ;;;_ : Allout Modal-Variables Utilities |
fd5359c6 MR |
1234 | ;;;_ = allout-mode-prior-settings |
1235 | (defvar allout-mode-prior-settings nil | |
01fc9422 | 1236 | "Internal `allout-mode' use; settings to be resumed on mode deactivation. |
1977b8f6 | 1237 | |
01fc9422 EZ |
1238 | See `allout-add-resumptions' and `allout-do-resumptions'.") |
1239 | (make-variable-buffer-local 'allout-mode-prior-settings) | |
1240 | ;;;_ > allout-add-resumptions (&rest pairs) | |
1241 | (defun allout-add-resumptions (&rest pairs) | |
48bd8440 | 1242 | "Set name/value PAIRS. |
01fc9422 EZ |
1243 | |
1244 | Old settings are preserved for later resumption using `allout-do-resumptions'. | |
1245 | ||
48bd8440 EZ |
1246 | The new values are set as a buffer local. On resumption, the prior buffer |
1247 | scope of the variable is restored along with its value. If it was a void | |
1248 | buffer-local value, then it is left as nil on resumption. | |
1249 | ||
01fc9422 | 1250 | The pairs are lists whose car is the name of the variable and car of the |
48bd8440 EZ |
1251 | cdr is the new value: '(some-var some-value)'. The pairs can actually be |
1252 | triples, where the third element qualifies the disposition of the setting, | |
1253 | as described further below. | |
01fc9422 | 1254 | |
48bd8440 EZ |
1255 | If the optional third element is the symbol 'extend, then the new value |
1256 | created by `cons'ing the second element of the pair onto the front of the | |
1257 | existing value. | |
01fc9422 | 1258 | |
48bd8440 EZ |
1259 | If the optional third element is the symbol 'append, then the new value is |
1260 | extended from the existing one by `append'ing a list containing the second | |
1261 | element of the pair onto the end of the existing value. | |
01fc9422 | 1262 | |
48bd8440 | 1263 | Extension, and resumptions in general, should not be used for hook |
60c7bbd2 | 1264 | functions -- use the 'local mode of `add-hook' for that, instead. |
01fc9422 EZ |
1265 | |
1266 | The settings are stored on `allout-mode-prior-settings'." | |
1267 | (while pairs | |
1268 | (let* ((pair (pop pairs)) | |
1269 | (name (car pair)) | |
48bd8440 EZ |
1270 | (value (cadr pair)) |
1271 | (qualifier (if (> (length pair) 2) | |
1272 | (caddr pair))) | |
1273 | prior-value) | |
01fc9422 EZ |
1274 | (if (not (symbolp name)) |
1275 | (error "Pair's name, %S, must be a symbol, not %s" | |
1276 | name (type-of name))) | |
d8350998 | 1277 | (setq prior-value (condition-case nil |
48bd8440 EZ |
1278 | (symbol-value name) |
1279 | (void-variable nil))) | |
01fc9422 EZ |
1280 | (when (not (assoc name allout-mode-prior-settings)) |
1281 | ;; Not already added as a resumption, create the prior setting entry. | |
1282 | (if (local-variable-p name) | |
60c7bbd2 | 1283 | ;; is already local variable -- preserve the prior value: |
48bd8440 | 1284 | (push (list name prior-value) allout-mode-prior-settings) |
01fc9422 EZ |
1285 | ;; wasn't local variable, indicate so for resumption by killing |
1286 | ;; local value, and make it local: | |
1287 | (push (list name) allout-mode-prior-settings) | |
1288 | (make-local-variable name))) | |
48bd8440 EZ |
1289 | (if qualifier |
1290 | (cond ((eq qualifier 'extend) | |
1291 | (if (not (listp prior-value)) | |
1292 | (error "extension of non-list prior value attempted") | |
1293 | (set name (cons value prior-value)))) | |
1294 | ((eq qualifier 'append) | |
1295 | (if (not (listp prior-value)) | |
1296 | (error "appending of non-list prior value attempted") | |
1297 | (set name (append prior-value (list value))))) | |
1298 | (t (error "unrecognized setting qualifier `%s' encountered" | |
1299 | qualifier))) | |
1300 | (set name value))))) | |
01fc9422 EZ |
1301 | ;;;_ > allout-do-resumptions () |
1302 | (defun allout-do-resumptions () | |
1303 | "Resume all name/value settings registered by `allout-add-resumptions'. | |
1304 | ||
1305 | This is used when concluding allout-mode, to resume selected variables to | |
1306 | their settings before allout-mode was started." | |
1307 | ||
1308 | (while allout-mode-prior-settings | |
1309 | (let* ((pair (pop allout-mode-prior-settings)) | |
1310 | (name (car pair)) | |
1311 | (value-cell (cdr pair))) | |
1312 | (if (not value-cell) | |
1313 | ;; Prior value was global: | |
1314 | (kill-local-variable name) | |
1315 | ;; Prior value was explicit: | |
1316 | (set name (car value-cell)))))) | |
9179616f | 1317 | ;;;_ : Mode-specific incidentals |
fd5359c6 | 1318 | ;;;_ > allout-unprotected (expr) |
d82979ea | 1319 | (defmacro allout-unprotected (expr) |
96b83743 | 1320 | "Enable internal outline operations to alter invisible text." |
1b4d97b2 | 1321 | `(let ((inhibit-read-only (if (not buffer-read-only) t)) |
0458fa80 | 1322 | (inhibit-field-text-motion t)) |
96b83743 EZ |
1323 | ,expr)) |
1324 | ;;;_ = allout-mode-hook | |
1325 | (defvar allout-mode-hook nil | |
1326 | "*Hook that's run when allout mode starts.") | |
01fc9422 EZ |
1327 | ;;;_ = allout-mode-deactivate-hook |
1328 | (defvar allout-mode-deactivate-hook nil | |
1329 | "*Hook that's run when allout mode ends.") | |
1330 | ;;;_ = allout-exposure-category | |
1331 | (defvar allout-exposure-category nil | |
1332 | "Symbol for use as allout invisible-text overlay category.") | |
da506f05 | 1333 | ;;;_ x allout-view-change-hook |
96b83743 | 1334 | (defvar allout-view-change-hook nil |
c07583cd | 1335 | "*(Deprecated) A hook run after allout outline exposure changes. |
da506f05 | 1336 | |
48bd8440 EZ |
1337 | Switch to using `allout-exposure-change-hook' instead. Both hooks are |
1338 | currently respected, but the other conveys the details of the exposure | |
1339 | change via explicit parameters, and this one will eventually be disabled in | |
1340 | a subsequent allout version.") | |
da506f05 RS |
1341 | ;;;_ = allout-exposure-change-hook |
1342 | (defvar allout-exposure-change-hook nil | |
48bd8440 EZ |
1343 | "*Hook that's run after allout outline subtree exposure changes. |
1344 | ||
1345 | It is run at the conclusion of `allout-flag-region'. | |
1346 | ||
1347 | Functions on the hook must take three arguments: | |
1348 | ||
60c7bbd2 RS |
1349 | - FROM -- integer indicating the point at the start of the change. |
1350 | - TO -- integer indicating the point of the end of the change. | |
1351 | - FLAG -- change mode: nil for exposure, otherwise concealment. | |
48bd8440 EZ |
1352 | |
1353 | This hook might be invoked multiple times by a single command. | |
1354 | ||
1355 | This hook is replacing `allout-view-change-hook', which is being deprecated | |
1356 | and eventually will not be invoked.") | |
1357 | ;;;_ = allout-structure-added-hook | |
1358 | (defvar allout-structure-added-hook nil | |
1359 | "*Hook that's run after addition of items to the outline. | |
1360 | ||
1361 | Functions on the hook should take two arguments: | |
1362 | ||
60c7bbd2 RS |
1363 | - NEW-START -- integer indicating position of start of the first new item. |
1364 | - NEW-END -- integer indicating position of end of the last new item. | |
48bd8440 | 1365 | |
60c7bbd2 | 1366 | Some edits that introduce new items may missed by this hook: |
48bd8440 EZ |
1367 | specifically edits that native allout routines do not control. |
1368 | ||
1369 | This hook might be invoked multiple times by a single command.") | |
1370 | ;;;_ = allout-structure-deleted-hook | |
1371 | (defvar allout-structure-deleted-hook nil | |
1372 | "*Hook that's run after disciplined deletion of subtrees from the outline. | |
1373 | ||
1374 | Functions on the hook must take two arguments: | |
1375 | ||
60c7bbd2 RS |
1376 | - DEPTH -- integer indicating the depth of the subtree that was deleted. |
1377 | - REMOVED-FROM -- integer indicating the point where the subtree was removed. | |
da506f05 | 1378 | |
60c7bbd2 | 1379 | Some edits that remove or invalidate items may missed by this hook: |
48bd8440 | 1380 | specifically edits that native allout routines do not control. |
96b83743 | 1381 | |
48bd8440 EZ |
1382 | This hook might be invoked multiple times by a single command.") |
1383 | ;;;_ = allout-structure-shifted-hook | |
1384 | (defvar allout-structure-shifted-hook nil | |
1385 | "*Hook that's run after shifting of items in the outline. | |
1386 | ||
1387 | Functions on the hook should take two arguments: | |
1388 | ||
60c7bbd2 RS |
1389 | - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease |
1390 | - START -- integer indicating the start point of the shifted parent item. | |
48bd8440 | 1391 | |
60c7bbd2 | 1392 | Some edits that shift items can be missed by this hook: specifically edits |
48bd8440 EZ |
1393 | that native allout routines do not control. |
1394 | ||
1395 | This hook might be invoked multiple times by a single command.") | |
96b83743 EZ |
1396 | ;;;_ = allout-outside-normal-auto-fill-function |
1397 | (defvar allout-outside-normal-auto-fill-function nil | |
1398 | "Value of normal-auto-fill-function outside of allout mode. | |
1399 | ||
1400 | Used by allout-auto-fill to do the mandated normal-auto-fill-function | |
1401 | wrapped within allout's automatic fill-prefix setting.") | |
1402 | (make-variable-buffer-local 'allout-outside-normal-auto-fill-function) | |
19b84ba3 | 1403 | ;;;_ = file-var-bug hack |
fd5359c6 | 1404 | (defvar allout-v18/19-file-var-hack nil |
c567ac01 | 1405 | "Horrible hack used to prevent invalid multiple triggering of outline |
2265e017 | 1406 | mode from prop-line file-var activation. Used by `allout-mode' function |
c567ac01 | 1407 | to track repeats.") |
0949617b EZ |
1408 | ;;;_ = allout-passphrase-verifier-string |
1409 | (defvar allout-passphrase-verifier-string nil | |
1410 | "Setting used to test solicited encryption passphrases against the one | |
1411 | already associated with a file. | |
1412 | ||
1413 | It consists of an encrypted random string useful only to verify that a | |
1414 | passphrase entered by the user is effective for decryption. The passphrase | |
1415 | itself is \*not* recorded in the file anywhere, and the encrypted contents | |
1416 | are random binary characters to avoid exposing greater susceptibility to | |
1417 | search attacks. | |
d82979ea EZ |
1418 | |
1419 | The verifier string is retained as an Emacs file variable, as well as in | |
a0a022d5 | 1420 | the Emacs buffer state, if file variable adjustments are enabled. See |
d82979ea | 1421 | `allout-enable-file-variable-adjustment' for details about that.") |
0949617b | 1422 | (make-variable-buffer-local 'allout-passphrase-verifier-string) |
8570ce80 | 1423 | ;;;###autoload |
7e5d77dc | 1424 | (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp) |
0949617b EZ |
1425 | ;;;_ = allout-passphrase-hint-string |
1426 | (defvar allout-passphrase-hint-string "" | |
1427 | "Variable used to retain reminder string for file's encryption passphrase. | |
d82979ea | 1428 | |
0949617b | 1429 | See the description of `allout-passphrase-hint-handling' for details about how |
d82979ea EZ |
1430 | the reminder is deployed. |
1431 | ||
a0a022d5 | 1432 | The hint is retained as an Emacs file variable, as well as in the Emacs buffer |
d82979ea EZ |
1433 | state, if file variable adjustments are enabled. See |
1434 | `allout-enable-file-variable-adjustment' for details about that.") | |
0949617b EZ |
1435 | (make-variable-buffer-local 'allout-passphrase-hint-string) |
1436 | (setq-default allout-passphrase-hint-string "") | |
8570ce80 SM |
1437 | ;;;###autoload |
1438 | (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp) | |
d82979ea EZ |
1439 | ;;;_ = allout-after-save-decrypt |
1440 | (defvar allout-after-save-decrypt nil | |
1441 | "Internal variable, is nil or has the value of two points: | |
1442 | ||
1443 | - the location of a topic to be decrypted after saving is done | |
1444 | - where to situate the cursor after the decryption is performed | |
1445 | ||
1446 | This is used to decrypt the topic that was currently being edited, if it | |
1447 | was encrypted automatically as part of a file write or autosave.") | |
1448 | (make-variable-buffer-local 'allout-after-save-decrypt) | |
48bd8440 EZ |
1449 | ;;;_ = allout-encryption-plaintext-sanitization-regexps |
1450 | (defvar allout-encryption-plaintext-sanitization-regexps nil | |
1451 | "List of regexps whose matches are removed from plaintext before encryption. | |
1452 | ||
1453 | This is for the sake of removing artifacts, like escapes, that are added on | |
1454 | and not actually part of the original plaintext. The removal is done just | |
1455 | prior to encryption. | |
1456 | ||
1457 | Entries must be symbols that are bound to the desired values. | |
1458 | ||
1459 | Each value can be a regexp or a list with a regexp followed by a | |
1460 | substitution string. If it's just a regexp, all its matches are removed | |
1461 | before the text is encrypted. If it's a regexp and a substitution, the | |
1462 | substition is used against the regexp matches, a la `replace-match'.") | |
1463 | (make-variable-buffer-local 'allout-encryption-text-removal-regexps) | |
1464 | ;;;_ = allout-encryption-ciphertext-rejection-regexps | |
1465 | (defvar allout-encryption-ciphertext-rejection-regexps nil | |
1466 | "Variable for regexps matching plaintext to remove before encryption. | |
1467 | ||
1468 | This is for the sake of redoing encryption in cases where the ciphertext | |
ea18b2b1 | 1469 | incidentally contains strings that would disrupt mode operation -- |
48bd8440 EZ |
1470 | for example, a line that happens to look like an allout-mode topic prefix. |
1471 | ||
1472 | Entries must be symbols that are bound to the desired regexp values. | |
1473 | ||
1474 | The encryption will be retried up to | |
1475 | `allout-encryption-ciphertext-rejection-limit' times, after which an error | |
1476 | is raised.") | |
1477 | ||
1478 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps) | |
1479 | ;;;_ = allout-encryption-ciphertext-rejection-ceiling | |
1480 | (defvar allout-encryption-ciphertext-rejection-ceiling 5 | |
1481 | "Limit on number of times encryption ciphertext is rejected. | |
1482 | ||
1483 | See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.") | |
1484 | (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling) | |
69027dea EZ |
1485 | ;;;_ > allout-mode-p () |
1486 | ;; Must define this macro above any uses, or byte compilation will lack | |
60c7bbd2 | 1487 | ;; proper def, if file isn't loaded -- eg, during emacs build! |
69027dea EZ |
1488 | (defmacro allout-mode-p () |
1489 | "Return t if `allout-mode' is active in current buffer." | |
1490 | 'allout-mode) | |
d82979ea EZ |
1491 | ;;;_ > allout-write-file-hook-handler () |
1492 | (defun allout-write-file-hook-handler () | |
1493 | "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes." | |
1494 | ||
0949617b EZ |
1495 | (if (or (not (allout-mode-p)) |
1496 | (not (boundp 'allout-encrypt-unencrypted-on-saves)) | |
d82979ea EZ |
1497 | (not allout-encrypt-unencrypted-on-saves)) |
1498 | nil | |
1499 | (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves | |
1500 | 'except-current) | |
1501 | (point-marker)))) | |
1502 | (if (save-excursion (goto-char (point-min)) | |
1503 | (allout-next-topic-pending-encryption except-mark)) | |
1504 | (progn | |
1505 | (message "auto-encrypting pending topics") | |
96b83743 | 1506 | (sit-for 0) |
d82979ea EZ |
1507 | (condition-case failure |
1508 | (setq allout-after-save-decrypt | |
1509 | (allout-encrypt-decrypted except-mark)) | |
42c3e51c KM |
1510 | (error (message |
1511 | "allout-write-file-hook-handler suppressing error %s" | |
1512 | failure) | |
1513 | (sit-for 2))))) | |
d82979ea | 1514 | )) |
42c3e51c | 1515 | nil) |
d82979ea EZ |
1516 | ;;;_ > allout-auto-save-hook-handler () |
1517 | (defun allout-auto-save-hook-handler () | |
69027dea | 1518 | "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save." |
d82979ea | 1519 | |
0949617b | 1520 | (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves) |
d82979ea EZ |
1521 | ;; Always implement 'except-current policy when enabled. |
1522 | (let ((allout-encrypt-unencrypted-on-saves 'except-current)) | |
1523 | (allout-write-file-hook-handler)))) | |
1524 | ;;;_ > allout-after-saves-handler () | |
1525 | (defun allout-after-saves-handler () | |
1526 | "Decrypt topic encrypted for save, if it's currently being edited. | |
1527 | ||
1528 | Ie, if it was pending encryption and contained the point in its body before | |
1529 | the save. | |
1530 | ||
1531 | We use values stored in `allout-after-save-decrypt' to locate the topic | |
1532 | and the place for the cursor after the decryption is done." | |
1533 | (if (not (and (allout-mode-p) | |
1534 | (boundp 'allout-after-save-decrypt) | |
1535 | allout-after-save-decrypt)) | |
1536 | t | |
1537 | (goto-char (car allout-after-save-decrypt)) | |
1538 | (let ((was-modified (buffer-modified-p))) | |
69027dea | 1539 | (allout-toggle-subtree-encryption) |
d82979ea EZ |
1540 | (if (not was-modified) |
1541 | (set-buffer-modified-p nil))) | |
1542 | (goto-char (cadr allout-after-save-decrypt)) | |
1543 | (setq allout-after-save-decrypt nil)) | |
1544 | ) | |
498a6493 CY |
1545 | ;;;_ = allout-inhibit-aberrance-doublecheck nil |
1546 | ;; In some exceptional moments, disparate topic depths need to be allowed | |
1547 | ;; momentarily, eg when one topic is being yanked into another and they're | |
1548 | ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck | |
1549 | ;; prevents the aberrance doublecheck to allow, eg, the reconciliation | |
1550 | ;; processing to happen in the presence of such discrepancies. It should | |
1551 | ;; almost never be needed, however. | |
1552 | (defvar allout-inhibit-aberrance-doublecheck nil | |
1553 | "Internal state, for momentarily inhibits aberrance doublecheck. | |
1554 | ||
1555 | This should only be momentarily let-bound non-nil, not set | |
1556 | non-nil in a lasting way.") | |
19b84ba3 RS |
1557 | |
1558 | ;;;_ #2 Mode activation | |
fd5359c6 MR |
1559 | ;;;_ = allout-explicitly-deactivated |
1560 | (defvar allout-explicitly-deactivated nil | |
d82979ea | 1561 | "If t, `allout-mode's last deactivation was deliberate. |
2265e017 | 1562 | So `allout-post-command-business' should not reactivate it...") |
fd5359c6 MR |
1563 | (make-variable-buffer-local 'allout-explicitly-deactivated) |
1564 | ;;;_ > allout-init (&optional mode) | |
1565 | (defun allout-init (&optional mode) | |
2265e017 | 1566 | "Prime `allout-mode' to enable/disable auto-activation, wrt `allout-layout'. |
19b84ba3 | 1567 | |
8d118843 | 1568 | MODE is one of the following symbols: |
19b84ba3 | 1569 | |
c07583cd | 1570 | - nil (or no argument) deactivate auto-activation/layout; |
353e2ef2 KH |
1571 | - `activate', enable auto-activation only; |
1572 | - `ask', enable auto-activation, and enable auto-layout but with | |
a0776d6b | 1573 | confirmation for layout operation solicited from user each time; |
353e2ef2 | 1574 | - `report', just report and return the current auto-activation state; |
c07583cd | 1575 | - anything else (eg, t) for auto-activation and auto-layout, without |
8d118843 | 1576 | any confirmation check. |
19b84ba3 | 1577 | |
e126900f | 1578 | Use this function to setup your Emacs session for automatic activation |
19b84ba3 | 1579 | of allout outline mode, contingent to the buffer-specific setting of |
fd5359c6 MR |
1580 | the `allout-layout' variable. (See `allout-layout' and |
1581 | `allout-expose-topic' docstrings for more details on auto layout). | |
19b84ba3 | 1582 | |
d82979ea EZ |
1583 | `allout-init' works by setting up (or removing) the `allout-mode' |
1584 | find-file-hook, and giving `allout-auto-activation' a suitable | |
1585 | setting. | |
19b84ba3 | 1586 | |
e126900f JB |
1587 | To prime your Emacs session for full auto-outline operation, include |
1588 | the following two lines in your Emacs init file: | |
19b84ba3 RS |
1589 | |
1590 | \(require 'allout) | |
fd5359c6 | 1591 | \(allout-init t)" |
19b84ba3 | 1592 | |
d82979ea EZ |
1593 | (interactive) |
1594 | (if (interactive-p) | |
1595 | (progn | |
1596 | (setq mode | |
1597 | (completing-read | |
1598 | (concat "Select outline auto setup mode " | |
1599 | "(empty for report, ? for options) ") | |
1600 | '(("nil")("full")("activate")("deactivate") | |
1601 | ("ask") ("report") ("")) | |
1602 | nil | |
1603 | t)) | |
1604 | (if (string= mode "") | |
1605 | (setq mode 'report) | |
1606 | (setq mode (intern-soft mode))))) | |
8d118843 RS |
1607 | (let |
1608 | ;; convenience aliases, for consistent ref to respective vars: | |
fd5359c6 | 1609 | ((hook 'allout-find-file-hook) |
0949617b EZ |
1610 | (find-file-hook-var-name (if (boundp 'find-file-hook) |
1611 | 'find-file-hook | |
1612 | 'find-file-hooks)) | |
fd5359c6 | 1613 | (curr-mode 'allout-auto-activation)) |
353e2ef2 | 1614 | |
8d118843 | 1615 | (cond ((not mode) |
0949617b EZ |
1616 | (set find-file-hook-var-name |
1617 | (delq hook (symbol-value find-file-hook-var-name))) | |
8d118843 RS |
1618 | (if (interactive-p) |
1619 | (message "Allout outline mode auto-activation inhibited."))) | |
1620 | ((eq mode 'report) | |
0949617b | 1621 | (if (not (memq hook (symbol-value find-file-hook-var-name))) |
d82979ea EZ |
1622 | (allout-init nil) |
1623 | ;; Just punt and use the reports from each of the modes: | |
1624 | (allout-init (symbol-value curr-mode)))) | |
0949617b | 1625 | (t (add-hook find-file-hook-var-name hook) |
353e2ef2 | 1626 | (set curr-mode ; `set', not `setq'! |
8d118843 RS |
1627 | (cond ((eq mode 'activate) |
1628 | (message | |
1629 | "Outline mode auto-activation enabled.") | |
1630 | 'activate) | |
1631 | ((eq mode 'report) | |
1632 | ;; Return the current mode setting: | |
fd5359c6 | 1633 | (allout-init mode)) |
8d118843 RS |
1634 | ((eq mode 'ask) |
1635 | (message | |
1636 | (concat "Outline mode auto-activation and " | |
c07583cd | 1637 | "-layout (upon confirmation) enabled.")) |
8d118843 RS |
1638 | 'ask) |
1639 | ((message | |
1640 | "Outline mode auto-activation and -layout enabled.") | |
1641 | 'full))))))) | |
fd5359c6 MR |
1642 | ;;;_ > allout-setup-menubar () |
1643 | (defun allout-setup-menubar () | |
aad94676 | 1644 | "Populate the current buffer's menubar with `allout-mode' stuff." |
fd5359c6 MR |
1645 | (let ((menus (list allout-mode-exposure-menu |
1646 | allout-mode-editing-menu | |
1647 | allout-mode-navigation-menu | |
1648 | allout-mode-misc-menu)) | |
9179616f DL |
1649 | cur) |
1650 | (while menus | |
1651 | (setq cur (car menus) | |
1652 | menus (cdr menus)) | |
1653 | (easy-menu-add cur)))) | |
01fc9422 EZ |
1654 | ;;;_ > allout-overlay-preparations |
1655 | (defun allout-overlay-preparations () | |
1656 | "Set the properties of the allout invisible-text overlay and others." | |
1657 | (setplist 'allout-exposure-category nil) | |
1658 | (put 'allout-exposure-category 'invisible 'allout) | |
1659 | (put 'allout-exposure-category 'evaporate t) | |
96b83743 | 1660 | ;; XXX We use isearch-open-invisible *and* isearch-mode-end-hook. The |
ea18b2b1 | 1661 | ;; latter would be sufficient, but it seems that a separate behavior -- |
60c7bbd2 RS |
1662 | ;; the _transient_ opening of invisible text during isearch -- is keyed to |
1663 | ;; presence of the isearch-open-invisible property -- even though this | |
96b83743 | 1664 | ;; property controls the isearch _arrival_ behavior. This is the case at |
21e8bc99 | 1665 | ;; least in emacs 21, 22.1, and xemacs 21.4. |
01fc9422 | 1666 | (put 'allout-exposure-category 'isearch-open-invisible |
96b83743 EZ |
1667 | 'allout-isearch-end-handler) |
1668 | (if (featurep 'xemacs) | |
01fc9422 EZ |
1669 | (put 'allout-exposure-category 'start-open t) |
1670 | (put 'allout-exposure-category 'insert-in-front-hooks | |
96b83743 | 1671 | '(allout-overlay-insert-in-front-handler))) |
01fc9422 EZ |
1672 | (put 'allout-exposure-category 'modification-hooks |
1673 | '(allout-overlay-interior-modification-handler))) | |
fd5359c6 | 1674 | ;;;_ > allout-mode (&optional toggle) |
19b84ba3 | 1675 | ;;;_ : Defun: |
0949617b | 1676 | ;;;###autoload |
fd5359c6 | 1677 | (defun allout-mode (&optional toggle) |
c567ac01 | 1678 | ;;;_ . Doc string: |
19b84ba3 | 1679 | "Toggle minor mode for controlling exposure and editing of text outlines. |
96b83743 | 1680 | \\<allout-mode-map> |
19b84ba3 | 1681 | |
4837b516 GM |
1682 | Optional prefix argument TOGGLE forces the mode to re-initialize |
1683 | if it is positive, otherwise it turns the mode off. Allout | |
1684 | outline mode always runs as a minor mode. | |
19b84ba3 | 1685 | |
aad94676 | 1686 | Allout outline mode provides extensive outline oriented formatting and |
9179616f DL |
1687 | manipulation. It enables structural editing of outlines, as well as |
1688 | navigation and exposure. It also is specifically aimed at | |
c07583cd | 1689 | accommodating syntax-sensitive text like programming languages. (For |
9179616f DL |
1690 | an example, see the allout code itself, which is organized as an allout |
1691 | outline.) | |
19b84ba3 | 1692 | |
c07583cd | 1693 | In addition to typical outline navigation and exposure, allout includes: |
19b84ba3 | 1694 | |
c07583cd KS |
1695 | - topic-oriented authoring, including keystroke-based topic creation, |
1696 | repositioning, promotion/demotion, cut, and paste | |
9179616f | 1697 | - incremental search with dynamic exposure and reconcealment of hidden text |
c07583cd | 1698 | - adjustable format, so programming code can be developed in outline-structure |
d82979ea | 1699 | - easy topic encryption and decryption |
c07583cd KS |
1700 | - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control |
1701 | - integral outline layout, for automatic initial exposure when visiting a file | |
1702 | - independent extensibility, using comprehensive exposure and authoring hooks | |
9179616f DL |
1703 | |
1704 | and many other features. | |
19b84ba3 | 1705 | |
c07583cd | 1706 | Below is a description of the key bindings, and then explanation of |
2265e017 | 1707 | special `allout-mode' features and terminology. See also the outline |
9179616f | 1708 | menubar additions for quick reference to many of the features, and see |
f134d28b | 1709 | the docstring of the function `allout-init' for instructions on |
d82979ea | 1710 | priming your emacs session for automatic activation of `allout-mode'. |
9179616f | 1711 | |
c07583cd KS |
1712 | The bindings are dictated by the customizable `allout-keybindings-list' |
1713 | variable. We recommend customizing `allout-command-prefix' to use just | |
1714 | `\\C-c' as the command prefix, if the allout bindings don't conflict with | |
1715 | any personal bindings you have on \\C-c. In any case, outline structure | |
1716 | navigation and authoring is simplified by positioning the cursor on an | |
60c7bbd2 | 1717 | item's bullet character, the \"hot-spot\" -- then you can invoke allout |
c07583cd KS |
1718 | commands with just the un-prefixed, un-control-shifted command letters. |
1719 | This is described further in the HOT-SPOT Operation section. | |
1720 | ||
1721 | Exposure Control: | |
1722 | ---------------- | |
1723 | \\[allout-hide-current-subtree] `allout-hide-current-subtree' | |
1724 | \\[allout-show-children] `allout-show-children' | |
1725 | \\[allout-show-current-subtree] `allout-show-current-subtree' | |
1726 | \\[allout-show-current-entry] `allout-show-current-entry' | |
1727 | \\[allout-show-all] `allout-show-all' | |
1728 | ||
1729 | Navigation: | |
1730 | ---------- | |
1731 | \\[allout-next-visible-heading] `allout-next-visible-heading' | |
1732 | \\[allout-previous-visible-heading] `allout-previous-visible-heading' | |
1733 | \\[allout-up-current-level] `allout-up-current-level' | |
1734 | \\[allout-forward-current-level] `allout-forward-current-level' | |
1735 | \\[allout-backward-current-level] `allout-backward-current-level' | |
1736 | \\[allout-end-of-entry] `allout-end-of-entry' | |
1737 | \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot) | |
60c7bbd2 | 1738 | \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but |
c07583cd KS |
1739 | if immediately repeated cycles to the beginning of the current item |
1740 | and then to the hot-spot (if `allout-beginning-of-line-cycles' is set). | |
1741 | ||
1742 | ||
1743 | Topic Header Production: | |
1744 | ----------------------- | |
1745 | \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic. | |
1746 | \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic. | |
1747 | \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent. | |
1748 | ||
1749 | Topic Level and Prefix Adjustment: | |
1750 | --------------------------------- | |
1751 | \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper | |
1752 | \\[allout-shift-out] `allout-shift-out' ... less deep | |
1753 | \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for | |
1754 | current topic | |
1755 | \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and | |
60c7bbd2 | 1756 | its' offspring -- distinctive bullets are not changed, others |
c07583cd | 1757 | are alternated according to nesting depth. |
ea18b2b1 | 1758 | \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -- |
c07583cd KS |
1759 | the offspring are not affected. |
1760 | With repeat count, revoke numbering. | |
1761 | ||
1762 | Topic-oriented Killing and Yanking: | |
1763 | ---------------------------------- | |
1764 | \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring. | |
1765 | \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring. | |
1766 | \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure. | |
1767 | \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it. | |
1768 | \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to | |
1769 | depth of heading if yanking into bare topic | |
1770 | heading (ie, prefix sans text). | |
1771 | \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank | |
1772 | ||
1773 | Topic-oriented Encryption: | |
1774 | ------------------------- | |
1775 | \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption' | |
1776 | Encrypt/Decrypt topic content | |
1777 | ||
1778 | Misc commands: | |
1779 | ------------- | |
1780 | M-x outlineify-sticky Activate outline mode for current buffer, | |
1781 | and establish a default file-var setting | |
1782 | for `allout-layout'. | |
1783 | \\[allout-mark-topic] `allout-mark-topic' | |
1784 | \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer' | |
1785 | Duplicate outline, sans concealed text, to | |
1786 | buffer with name derived from derived from that | |
60c7bbd2 | 1787 | of current buffer -- \"*BUFFERNAME exposed*\". |
c07583cd KS |
1788 | \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer' |
1789 | Like above 'copy-exposed', but convert topic | |
1790 | prefixes to section.subsection... numeric | |
1791 | format. | |
1792 | \\[eval-expression] (allout-init t) Setup Emacs session for outline mode | |
1793 | auto-activation. | |
1977b8f6 | 1794 | |
96b83743 | 1795 | Topic Encryption |
d82979ea | 1796 | |
96b83743 EZ |
1797 | Outline mode supports gpg encryption of topics, with support for |
1798 | symmetric and key-pair modes, passphrase timeout, passphrase | |
1799 | consistency checking, user-provided hinting for symmetric key | |
1800 | mode, and auto-encryption of topics pending encryption on save. | |
d82979ea | 1801 | |
c07583cd KS |
1802 | Topics pending encryption are, by default, automatically |
1803 | encrypted during file saves. If the contents of the topic | |
1804 | containing the cursor was encrypted for a save, it is | |
1805 | automatically decrypted for continued editing. | |
1806 | ||
1807 | The aim of these measures is reliable topic privacy while | |
1808 | preventing accidents like neglected encryption before saves, | |
1809 | forgetting which passphrase was used, and other practical | |
1810 | pitfalls. | |
1811 | ||
1812 | See `allout-toggle-current-subtree-encryption' function docstring | |
1813 | and `allout-encrypt-unencrypted-on-saves' customization variable | |
1814 | for details. | |
d82979ea | 1815 | |
c07583cd | 1816 | HOT-SPOT Operation |
c567ac01 | 1817 | |
19b84ba3 RS |
1818 | Hot-spot operation provides a means for easy, single-keystroke outline |
1819 | navigation and exposure control. | |
c567ac01 | 1820 | |
19b84ba3 RS |
1821 | When the text cursor is positioned directly on the bullet character of |
1822 | a topic, regular characters (a to z) invoke the commands of the | |
fd5359c6 | 1823 | corresponding allout-mode keymap control chars. For example, \"f\" |
96b83743 | 1824 | would invoke the command typically bound to \"C-c<space>C-f\" |
fd5359c6 | 1825 | \(\\[allout-forward-current-level] `allout-forward-current-level'). |
19b84ba3 | 1826 | |
96b83743 EZ |
1827 | Thus, by positioning the cursor on a topic bullet, you can |
1828 | execute the outline navigation and manipulation commands with a | |
c07583cd | 1829 | single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get |
96b83743 | 1830 | this special translation, so you can use them to get out of the |
c07583cd KS |
1831 | hot-spot and back to normal editing operation. |
1832 | ||
d41b91e6 | 1833 | In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is |
c07583cd KS |
1834 | replaced with one that makes it easy to get to the hot-spot. If you |
1835 | repeat it immediately it cycles (if `allout-beginning-of-line-cycles' | |
1836 | is set) to the beginning of the item and then, if you hit it again | |
1837 | immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry' | |
1838 | \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located | |
1839 | at the beginning of the current entry. | |
1840 | ||
1841 | Extending Allout | |
c567ac01 | 1842 | |
c07583cd KS |
1843 | Allout exposure and authoring activites all have associated |
1844 | hooks, by which independent code can cooperate with allout | |
1845 | without changes to the allout core. Here are key ones: | |
1977b8f6 | 1846 | |
c07583cd KS |
1847 | `allout-mode-hook' |
1848 | `allout-mode-deactivate-hook' | |
1849 | `allout-exposure-change-hook' | |
1850 | `allout-structure-added-hook' | |
1851 | `allout-structure-deleted-hook' | |
1852 | `allout-structure-shifted-hook' | |
1853 | ||
1854 | Terminology | |
1977b8f6 | 1855 | |
60c7bbd2 | 1856 | Topic hierarchy constituents -- TOPICS and SUBTOPICS: |
c567ac01 | 1857 | |
c07583cd KS |
1858 | ITEM: A unitary outline element, including the HEADER and ENTRY text. |
1859 | TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH | |
1860 | and with no intervening items of lower DEPTH than the container. | |
1861 | CURRENT ITEM: | |
1862 | The visible ITEM most immediately containing the cursor. | |
1863 | DEPTH: The degree of nesting of an ITEM; it increases with containment. | |
1864 | The DEPTH is determined by the HEADER PREFIX. The DEPTH is also | |
1865 | called the: | |
1866 | LEVEL: The same as DEPTH. | |
c567ac01 RS |
1867 | |
1868 | ANCESTORS: | |
c07583cd KS |
1869 | Those ITEMs whose TOPICs contain an ITEM. |
1870 | PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that | |
1871 | of the ITEM. | |
c567ac01 | 1872 | OFFSPRING: |
c07583cd | 1873 | The ITEMs contained within an ITEM's TOPIC. |
19b84ba3 | 1874 | SUBTOPIC: |
c07583cd KS |
1875 | An OFFSPRING of its ANCESTOR TOPICs. |
1876 | CHILD: | |
1877 | An immediate SUBTOPIC of its PARENT. | |
c567ac01 | 1878 | SIBLINGS: |
c07583cd | 1879 | TOPICs having the same PARENT and DEPTH. |
353e2ef2 | 1880 | |
c567ac01 RS |
1881 | Topic text constituents: |
1882 | ||
c07583cd KS |
1883 | HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER |
1884 | text. | |
1885 | ENTRY: The text content of an ITEM, before any OFFSPRING, but including | |
1886 | the HEADER text and distinct from the ITEM PREFIX. | |
1887 | BODY: Same as ENTRY. | |
1888 | PREFIX: The leading text of an ITEM which distinguishes it from normal | |
1889 | ENTRY text. Allout recognizes the outline structure according | |
1890 | to the strict PREFIX format. It consists of a PREFIX-LEAD string, | |
1891 | PREFIX-PADDING, and a BULLET. The BULLET might be followed by a | |
d82979ea | 1892 | number, indicating the ordinal number of the topic among its |
c07583cd KS |
1893 | siblings, or an asterisk indicating encryption, plus an optional |
1894 | space. After that is the ITEM HEADER text, which is not part of | |
1895 | the PREFIX. | |
c567ac01 | 1896 | |
c07583cd KS |
1897 | The relative length of the PREFIX determines the nesting DEPTH |
1898 | of the ITEM. | |
c567ac01 | 1899 | PREFIX-LEAD: |
c07583cd KS |
1900 | The string at the beginning of a HEADER PREFIX, by default a `.'. |
1901 | It can be customized by changing the setting of | |
1902 | `allout-header-prefix' and then reinitializing `allout-mode'. | |
1903 | ||
1904 | When the PREFIX-LEAD is set to the comment-string of a | |
1905 | programming language, outline structuring can be embedded in | |
1906 | program code without interfering with processing of the text | |
1907 | (by emacs or the language processor) as program code. This | |
1908 | setting happens automatically when allout mode is used in | |
1909 | programming-mode buffers. See `allout-use-mode-specific-leader' | |
1910 | docstring for more detail. | |
c567ac01 | 1911 | PREFIX-PADDING: |
c07583cd KS |
1912 | Spaces or asterisks which separate the PREFIX-LEAD and the |
1913 | bullet, determining the ITEM's DEPTH. | |
1914 | BULLET: A character at the end of the ITEM PREFIX, it must be one of | |
1915 | the characters listed on `allout-plain-bullets-string' or | |
38b2ca53 NR |
1916 | `allout-distinctive-bullets-string'. When creating a TOPIC, |
1917 | plain BULLETs are by default used, according to the DEPTH of the | |
1918 | TOPIC. Choice among the distinctive BULLETs is offered when you | |
1919 | provide a universal argugment \(\\[universal-argument]) to the | |
1920 | TOPIC creation command, or when explictly rebulleting a TOPIC. The | |
1921 | significance of the various distinctive bullets is purely by | |
1922 | convention. See the documentation for the above bullet strings for | |
1923 | more details. | |
c567ac01 | 1924 | EXPOSURE: |
c07583cd KS |
1925 | The state of a TOPIC which determines the on-screen visibility |
1926 | of its OFFSPRING and contained ENTRY text. | |
c567ac01 | 1927 | CONCEALED: |
c07583cd KS |
1928 | TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed |
1929 | text is represented by \"...\" ellipses. | |
c567ac01 | 1930 | |
c07583cd KS |
1931 | CONCEALED TOPICs are effectively collapsed within an ANCESTOR. |
1932 | CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED. | |
1933 | OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be." | |
c567ac01 | 1934 | ;;;_ . Code |
1977b8f6 RS |
1935 | (interactive "P") |
1936 | ||
c567ac01 | 1937 | (let* ((active (and (not (equal major-mode 'outline)) |
fd5359c6 | 1938 | (allout-mode-p))) |
353e2ef2 | 1939 | ; Massage universal-arg `toggle' val: |
c567ac01 | 1940 | (toggle (and toggle |
19b84ba3 RS |
1941 | (or (and (listp toggle)(car toggle)) |
1942 | toggle))) | |
a0776d6b | 1943 | ; Activation specifically demanded? |
69027dea | 1944 | (explicit-activation (and toggle |
19b84ba3 | 1945 | (or (symbolp toggle) |
69027dea EZ |
1946 | (and (wholenump toggle) |
1947 | (not (zerop toggle)))))) | |
fd5359c6 MR |
1948 | ;; allout-mode already called once during this complex command? |
1949 | (same-complex-command (eq allout-v18/19-file-var-hack | |
19b84ba3 | 1950 | (car command-history))) |
96b83743 EZ |
1951 | (write-file-hook-var-name (cond ((boundp 'write-file-functions) |
1952 | 'write-file-functions) | |
1953 | ((boundp 'write-file-hooks) | |
1954 | 'write-file-hooks) | |
1955 | (t 'local-write-file-hooks))) | |
19b84ba3 RS |
1956 | do-layout |
1957 | ) | |
c567ac01 | 1958 | |
19b84ba3 | 1959 | ; See comments below re v19.18,.19 bug. |
fd5359c6 | 1960 | (setq allout-v18/19-file-var-hack (car command-history)) |
c567ac01 | 1961 | |
1977b8f6 RS |
1962 | (cond |
1963 | ||
ea18b2b1 | 1964 | ;; Provision for v19.18, 19.19 bug -- |
c567ac01 RS |
1965 | ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated |
1966 | ;; modes twice when file is visited. We have to avoid toggling mode | |
1967 | ;; off on second invocation, so we detect it as best we can, and | |
1968 | ;; skip everything. | |
1969 | ((and same-complex-command ; Still in same complex command | |
d82979ea | 1970 | ; as last time `allout-mode' invoked. |
19b84ba3 RS |
1971 | active ; Already activated. |
1972 | (not explicit-activation) ; Prop-line file-vars don't have args. | |
1973 | (string-match "^19.1[89]" ; Bug only known to be in v19.18 and | |
1974 | emacs-version)); 19.19. | |
c567ac01 | 1975 | t) |
353e2ef2 | 1976 | |
19b84ba3 | 1977 | ;; Deactivation: |
c567ac01 | 1978 | ((and (not explicit-activation) |
19b84ba3 RS |
1979 | (or active toggle)) |
1980 | ; Activation not explicitly | |
1981 | ; requested, and either in | |
1982 | ; active state or *de*activation | |
1983 | ; specifically requested: | |
fd5359c6 | 1984 | (setq allout-explicitly-deactivated t) |
c567ac01 | 1985 | |
01fc9422 EZ |
1986 | (allout-do-resumptions) |
1987 | ||
96b83743 | 1988 | (remove-from-invisibility-spec '(allout . t)) |
01fc9422 EZ |
1989 | (remove-hook 'pre-command-hook 'allout-pre-command-business t) |
1990 | (remove-hook 'post-command-hook 'allout-post-command-business t) | |
d8350998 | 1991 | (remove-hook 'before-change-functions 'allout-before-change-handler t) |
01fc9422 EZ |
1992 | (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) |
1993 | (remove-hook write-file-hook-var-name 'allout-write-file-hook-handler t) | |
1994 | (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t) | |
1995 | ||
1996 | (remove-overlays (point-min) (point-max) | |
1997 | 'category 'allout-exposure-category) | |
1998 | ||
48bd8440 EZ |
1999 | (setq allout-mode nil) |
2000 | (run-hooks 'allout-mode-deactivate-hook)) | |
1977b8f6 | 2001 | |
19b84ba3 | 2002 | ;; Activation: |
1977b8f6 | 2003 | ((not active) |
fd5359c6 MR |
2004 | (setq allout-explicitly-deactivated nil) |
2005 | (if allout-old-style-prefixes | |
01fc9422 | 2006 | ;; Inhibit all the fancy formatting: |
48bd8440 | 2007 | (allout-add-resumptions '(allout-primary-bullet "*"))) |
19b84ba3 | 2008 | |
01fc9422 | 2009 | (allout-overlay-preparations) ; Doesn't hurt to redo this. |
96b83743 | 2010 | |
d8350998 | 2011 | (allout-infer-header-lead-and-primary-bullet) |
fd5359c6 | 2012 | (allout-infer-body-reindent) |
19b84ba3 | 2013 | |
fd5359c6 | 2014 | (set-allout-regexp) |
48bd8440 EZ |
2015 | (allout-add-resumptions |
2016 | '(allout-encryption-ciphertext-rejection-regexps | |
2017 | allout-line-boundary-regexp | |
2018 | extend) | |
2019 | '(allout-encryption-ciphertext-rejection-regexps | |
2020 | allout-bob-regexp | |
2021 | extend)) | |
19b84ba3 | 2022 | |
01fc9422 | 2023 | ;; Produce map from current version of allout-keybindings-list: |
c07583cd | 2024 | (allout-setup-mode-map) |
01fc9422 | 2025 | (produce-allout-mode-menubar-entries) |
01fc9422 EZ |
2026 | |
2027 | ;; Include on minor-mode-map-alist, if not already there: | |
2028 | (if (not (member '(allout-mode . allout-mode-map) | |
2029 | minor-mode-map-alist)) | |
2030 | (setq minor-mode-map-alist | |
2031 | (cons '(allout-mode . allout-mode-map) | |
2032 | minor-mode-map-alist))) | |
353e2ef2 | 2033 | |
96b83743 | 2034 | (add-to-invisibility-spec '(allout . t)) |
38b2ca53 | 2035 | |
01fc9422 EZ |
2036 | (allout-add-resumptions '(line-move-ignore-invisible t)) |
2037 | (add-hook 'pre-command-hook 'allout-pre-command-business nil t) | |
2038 | (add-hook 'post-command-hook 'allout-post-command-business nil t) | |
d8350998 CY |
2039 | (add-hook 'before-change-functions 'allout-before-change-handler |
2040 | nil t) | |
01fc9422 EZ |
2041 | (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) |
2042 | (add-hook write-file-hook-var-name 'allout-write-file-hook-handler | |
2043 | nil t) | |
2044 | (add-hook 'auto-save-hook 'allout-auto-save-hook-handler | |
2045 | nil t) | |
2046 | ||
2047 | ;; Stash auto-fill settings and adjust so custom allout auto-fill | |
2048 | ;; func will be used if auto-fill is active or activated. (The | |
2049 | ;; custom func respects topic headline, maintains hanging-indents, | |
2050 | ;; etc.) | |
2051 | (if (and auto-fill-function (not allout-inhibit-auto-fill)) | |
2052 | ;; allout-auto-fill will use the stashed values and so forth. | |
2053 | (allout-add-resumptions '(auto-fill-function allout-auto-fill))) | |
2054 | (allout-add-resumptions (list 'allout-former-auto-filler | |
2055 | auto-fill-function) | |
2056 | ;; Register allout-auto-fill to be used if | |
2057 | ;; filling is active: | |
2058 | (list 'allout-outside-normal-auto-fill-function | |
2059 | normal-auto-fill-function) | |
2060 | '(normal-auto-fill-function allout-auto-fill) | |
2061 | ;; Paragraphs are broken by topic headlines. | |
2062 | (list 'paragraph-start | |
2063 | (concat paragraph-start "\\|^\\(" | |
2064 | allout-regexp "\\)")) | |
2065 | (list 'paragraph-separate | |
2066 | (concat paragraph-separate "\\|^\\(" | |
2067 | allout-regexp "\\)"))) | |
fd5359c6 | 2068 | (or (assq 'allout-mode minor-mode-alist) |
c567ac01 | 2069 | (setq minor-mode-alist |
aad94676 | 2070 | (cons '(allout-mode " Allout") minor-mode-alist))) |
19b84ba3 | 2071 | |
fd5359c6 | 2072 | (allout-setup-menubar) |
9179616f | 2073 | |
fd5359c6 | 2074 | (if allout-layout |
19b84ba3 | 2075 | (setq do-layout t)) |
1977b8f6 | 2076 | |
48bd8440 EZ |
2077 | (setq allout-mode t) |
2078 | (run-hooks 'allout-mode-hook)) | |
19b84ba3 RS |
2079 | |
2080 | ;; Reactivation: | |
8d118843 | 2081 | ((setq do-layout t) |
fd5359c6 | 2082 | (allout-infer-body-reindent)) |
01fc9422 | 2083 | ) ;; end of activation-mode cases. |
19b84ba3 | 2084 | |
01fc9422 | 2085 | ;; Do auto layout if warranted: |
4034b0e2 LT |
2086 | (let ((use-layout (if (listp allout-layout) |
2087 | allout-layout | |
2088 | allout-default-layout))) | |
2089 | (if (and do-layout | |
2090 | allout-auto-activation | |
2091 | use-layout | |
2092 | (and (not (eq allout-auto-activation 'activate)) | |
2093 | (if (eq allout-auto-activation 'ask) | |
2094 | (if (y-or-n-p (format "Expose %s with layout '%s'? " | |
2095 | (buffer-name) | |
2096 | use-layout)) | |
2097 | t | |
2098 | (message "Skipped %s layout." (buffer-name)) | |
2099 | nil) | |
2100 | t))) | |
2101 | (save-excursion | |
2102 | (message "Adjusting '%s' exposure..." (buffer-name)) | |
2103 | (goto-char 0) | |
2104 | (allout-this-or-next-heading) | |
2105 | (condition-case err | |
2106 | (progn | |
2107 | (apply 'allout-expose-topic (list use-layout)) | |
2108 | (message "Adjusting '%s' exposure... done." (buffer-name))) | |
60c7bbd2 | 2109 | ;; Problem applying exposure -- notify user, but don't |
4034b0e2 LT |
2110 | ;; interrupt, eg, file visit: |
2111 | (error (message "%s" (car (cdr err))) | |
2112 | (sit-for 1)))))) | |
fd5359c6 | 2113 | allout-mode |
c567ac01 | 2114 | ) ; let* |
19b84ba3 | 2115 | ) ; defun |
c07583cd KS |
2116 | |
2117 | (defun allout-setup-mode-map () | |
2118 | "Establish allout-mode bindings." | |
2119 | (setq-default allout-mode-map | |
2120 | (produce-allout-mode-map allout-keybindings-list)) | |
2121 | (setq allout-mode-map | |
2122 | (produce-allout-mode-map allout-keybindings-list)) | |
2123 | (substitute-key-definition 'beginning-of-line | |
2124 | 'allout-beginning-of-line | |
2125 | allout-mode-map global-map) | |
2126 | (substitute-key-definition 'move-beginning-of-line | |
2127 | 'allout-beginning-of-line | |
2128 | allout-mode-map global-map) | |
2129 | (substitute-key-definition 'end-of-line | |
2130 | 'allout-end-of-line | |
2131 | allout-mode-map global-map) | |
2132 | (substitute-key-definition 'move-end-of-line | |
2133 | 'allout-end-of-line | |
2134 | allout-mode-map global-map) | |
2135 | (fset 'allout-mode-map allout-mode-map)) | |
2136 | ||
2137 | ;; ensure that allout-mode-map has some setting even if allout-mode hasn't | |
2138 | ;; been invoked: | |
2139 | (allout-setup-mode-map) | |
2140 | ||
46771bb3 EZ |
2141 | ;;;_ > allout-minor-mode |
2142 | (defalias 'allout-minor-mode 'allout-mode) | |
773e7e48 | 2143 | |
41ff6d0a JB |
2144 | ;;;_ > allout-unload-function |
2145 | (defun allout-unload-function () | |
2146 | "Unload the allout outline library." | |
2147 | (save-current-buffer | |
2148 | (dolist (buffer (buffer-list)) | |
2149 | (set-buffer buffer) | |
2150 | (when allout-mode (allout-mode -1)))) | |
2151 | ;; continue standard unloading | |
2152 | nil) | |
2153 | ||
773e7e48 EZ |
2154 | ;;;_ - Position Assessment |
2155 | ;;;_ > allout-hidden-p (&optional pos) | |
2156 | (defsubst allout-hidden-p (&optional pos) | |
2157 | "Non-nil if the character after point is invisible." | |
da506f05 | 2158 | (eq (get-char-property (or pos (point)) 'invisible) 'allout)) |
773e7e48 | 2159 | |
96b83743 EZ |
2160 | ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end |
2161 | ;;; &optional prelen) | |
2162 | (defun allout-overlay-insert-in-front-handler (ol after beg end | |
2163 | &optional prelen) | |
2a1408fd | 2164 | "Shift the overlay so stuff inserted in front of it is excluded." |
96b83743 | 2165 | (if after |
2a1408fd DN |
2166 | ;; XXX Shouldn't moving the overlay should be unnecessary, if overlay |
2167 | ;; front-advance on the overlay worked as it should? | |
96b83743 EZ |
2168 | (move-overlay ol (1+ beg) (overlay-end ol)))) |
2169 | ;;;_ > allout-overlay-interior-modification-handler (ol after beg end | |
2170 | ;;; &optional prelen) | |
2171 | (defun allout-overlay-interior-modification-handler (ol after beg end | |
2172 | &optional prelen) | |
2173 | "Get confirmation before making arbitrary changes to invisible text. | |
2174 | ||
2175 | We expose the invisible text and ask for confirmation. Refusal or | |
75bcb912 | 2176 | `keyboard-quit' abandons the changes, with keyboard-quit additionally |
96b83743 EZ |
2177 | reclosing the opened text. |
2178 | ||
60c7bbd2 | 2179 | No confirmation is necessary when `inhibit-read-only' is set -- eg, allout |
96b83743 EZ |
2180 | internal functions use this feature cohesively bunch changes." |
2181 | ||
2182 | (when (and (not inhibit-read-only) (not after)) | |
2183 | (let ((start (point)) | |
2184 | (ol-start (overlay-start ol)) | |
2185 | (ol-end (overlay-end ol)) | |
96b83743 EZ |
2186 | first) |
2187 | (goto-char beg) | |
2188 | (while (< (point) end) | |
2189 | (when (allout-hidden-p) | |
2190 | (allout-show-to-offshoot) | |
2191 | (if (allout-hidden-p) | |
2192 | (save-excursion (forward-char 1) | |
2193 | (allout-show-to-offshoot))) | |
2194 | (when (not first) | |
96b83743 EZ |
2195 | (setq first (point)))) |
2196 | (goto-char (if (featurep 'xemacs) | |
2197 | (next-property-change (1+ (point)) nil end) | |
2198 | (next-char-property-change (1+ (point)) end)))) | |
2199 | (when first | |
2200 | (goto-char first) | |
2201 | (condition-case nil | |
2202 | (if (not | |
2203 | (yes-or-no-p | |
2204 | (substitute-command-keys | |
4034b0e2 | 2205 | (concat "Modify concealed text? (\"no\" just aborts," |
96b83743 EZ |
2206 | " \\[keyboard-quit] also reconceals) ")))) |
2207 | (progn (goto-char start) | |
2208 | (error "Concealed-text change refused."))) | |
2209 | (quit (allout-flag-region ol-start ol-end nil) | |
2210 | (allout-flag-region ol-start ol-end t) | |
2211 | (error "Concealed-text change abandoned, text reconcealed.")))) | |
2212 | (goto-char start)))) | |
2213 | ;;;_ > allout-before-change-handler (beg end) | |
2214 | (defun allout-before-change-handler (beg end) | |
2215 | "Protect against changes to invisible text. | |
2216 | ||
60c7bbd2 | 2217 | See `allout-overlay-interior-modification-handler' for details." |
d8350998 CY |
2218 | |
2219 | (if (and (allout-mode-p) undo-in-progress (allout-hidden-p)) | |
2220 | (allout-show-to-offshoot)) | |
2221 | ||
01fc9422 EZ |
2222 | ;; allout-overlay-interior-modification-handler on an overlay handles |
2223 | ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. | |
2224 | (when (and (featurep 'xemacs) (allout-mode-p)) | |
2225 | ;; process all of the pending overlays: | |
d8350998 | 2226 | (save-excursion |
f520c6f2 | 2227 | (goto-char beg) |
d8350998 CY |
2228 | (let ((overlay (allout-get-invisibility-overlay))) |
2229 | (allout-overlay-interior-modification-handler | |
2230 | overlay nil beg end nil))))) | |
96b83743 EZ |
2231 | ;;;_ > allout-isearch-end-handler (&optional overlay) |
2232 | (defun allout-isearch-end-handler (&optional overlay) | |
2233 | "Reconcile allout outline exposure on arriving in hidden text after isearch. | |
2234 | ||
2235 | Optional OVERLAY parameter is for when this function is used by | |
2236 | `isearch-open-invisible' overlay property. It is otherwise unused, so this | |
2237 | function can also be used as an `isearch-mode-end-hook'." | |
2238 | ||
2239 | (if (and (allout-mode-p) (allout-hidden-p)) | |
2240 | (allout-show-to-offshoot))) | |
2241 | ||
60c7bbd2 | 2242 | ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs |
19b84ba3 | 2243 | ;;; All the basic outline functions that directly do string matches to |
1977b8f6 | 2244 | ;;; evaluate heading prefix location set the variables |
fd5359c6 MR |
2245 | ;;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' |
2246 | ;;; when successful. Functions starting with `allout-recent-' all | |
19b84ba3 RS |
2247 | ;;; use this state, providing the means to avoid redundant searches |
2248 | ;;; for just-established data. This optimization can provide | |
2249 | ;;; significant speed improvement, but it must be employed carefully. | |
fd5359c6 MR |
2250 | ;;;_ = allout-recent-prefix-beginning |
2251 | (defvar allout-recent-prefix-beginning 0 | |
c567ac01 | 2252 | "Buffer point of the start of the last topic prefix encountered.") |
fd5359c6 MR |
2253 | (make-variable-buffer-local 'allout-recent-prefix-beginning) |
2254 | ;;;_ = allout-recent-prefix-end | |
2255 | (defvar allout-recent-prefix-end 0 | |
c567ac01 | 2256 | "Buffer point of the end of the last topic prefix encountered.") |
fd5359c6 | 2257 | (make-variable-buffer-local 'allout-recent-prefix-end) |
d8350998 CY |
2258 | ;;;_ = allout-recent-depth |
2259 | (defvar allout-recent-depth 0 | |
2260 | "Depth of the last topic prefix encountered.") | |
2261 | (make-variable-buffer-local 'allout-recent-depth) | |
fd5359c6 MR |
2262 | ;;;_ = allout-recent-end-of-subtree |
2263 | (defvar allout-recent-end-of-subtree 0 | |
2265e017 | 2264 | "Buffer point last returned by `allout-end-of-current-subtree'.") |
fd5359c6 | 2265 | (make-variable-buffer-local 'allout-recent-end-of-subtree) |
d8350998 CY |
2266 | ;;;_ > allout-prefix-data () |
2267 | (defsubst allout-prefix-data () | |
2268 | "Register allout-prefix state data. | |
fd5359c6 | 2269 | |
75bcb912 JB |
2270 | For reference by `allout-recent' funcs. Return |
2271 | the new value of `allout-recent-prefix-beginning'." | |
42c3e51c | 2272 | (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3)) |
d8350998 | 2273 | allout-recent-prefix-beginning (or (match-beginning 1) |
42c3e51c KM |
2274 | (match-beginning 2) |
2275 | (match-beginning 3)) | |
d8350998 CY |
2276 | allout-recent-depth (max 1 (- allout-recent-prefix-end |
2277 | allout-recent-prefix-beginning | |
2278 | allout-header-subtraction))) | |
2279 | allout-recent-prefix-beginning) | |
2280 | ;;;_ > nullify-allout-prefix-data () | |
2281 | (defsubst nullify-allout-prefix-data () | |
2282 | "Mark allout prefix data as being uninformative." | |
2283 | (setq allout-recent-prefix-end (point) | |
2284 | allout-recent-prefix-beginning (point) | |
2285 | allout-recent-depth 0) | |
2286 | allout-recent-prefix-beginning) | |
fd5359c6 | 2287 | ;;;_ > allout-recent-depth () |
d8350998 | 2288 | (defsubst allout-recent-depth () |
19b84ba3 | 2289 | "Return depth of last heading encountered by an outline maneuvering function. |
c567ac01 RS |
2290 | |
2291 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2292 | headings set the variables `allout-recent-prefix-beginning' and |
2293 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 RS |
2294 | to return the current depth." |
2295 | ||
d8350998 | 2296 | allout-recent-depth) |
fd5359c6 | 2297 | ;;;_ > allout-recent-prefix () |
d8350998 | 2298 | (defsubst allout-recent-prefix () |
2265e017 | 2299 | "Like `allout-recent-depth', but returns text of last encountered prefix. |
c567ac01 RS |
2300 | |
2301 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2302 | headings set the variables `allout-recent-prefix-beginning' and |
2303 | `allout-recent-prefix-end' if successful. This function uses those settings | |
d8350998 CY |
2304 | to return the current prefix." |
2305 | (buffer-substring-no-properties allout-recent-prefix-beginning | |
2306 | allout-recent-prefix-end)) | |
fd5359c6 MR |
2307 | ;;;_ > allout-recent-bullet () |
2308 | (defmacro allout-recent-bullet () | |
2309 | "Like allout-recent-prefix, but returns bullet of last encountered prefix. | |
c567ac01 RS |
2310 | |
2311 | All outline functions which directly do string matches to assess | |
2265e017 MR |
2312 | headings set the variables `allout-recent-prefix-beginning' and |
2313 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 2314 | to return the current depth of the most recently matched topic." |
d8350998 CY |
2315 | '(buffer-substring-no-properties (1- allout-recent-prefix-end) |
2316 | allout-recent-prefix-end)) | |
c567ac01 | 2317 | |
19b84ba3 | 2318 | ;;;_ #4 Navigation |
c567ac01 | 2319 | |
46771bb3 | 2320 | ;;;_ - Position Assessment |
c567ac01 | 2321 | ;;;_ : Location Predicates |
ede4ac6a KS |
2322 | ;;;_ > allout-do-doublecheck () |
2323 | (defsubst allout-do-doublecheck () | |
2324 | "True if current item conditions qualify for checking on topic aberrance." | |
2325 | (and | |
60c7bbd2 | 2326 | ;; presume integrity of outline and yanked content during yank -- necessary |
ede4ac6a | 2327 | ;; to allow for level disparity of yank location and yanked text: |
498a6493 | 2328 | (not allout-inhibit-aberrance-doublecheck) |
ede4ac6a KS |
2329 | ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck: |
2330 | (<= allout-recent-depth allout-doublecheck-at-and-shallower))) | |
2331 | ;;;_ > allout-aberrant-container-p () | |
d8350998 CY |
2332 | (defun allout-aberrant-container-p () |
2333 | "True if topic, or next sibling with children, contains them discontinuously. | |
2334 | ||
2335 | Discontinuous means an immediate offspring that is nested more | |
2336 | than one level deeper than the topic. | |
2337 | ||
2338 | If topic has no offspring, then the next sibling with offspring will | |
2339 | determine whether or not this one is determined to be aberrant. | |
2340 | ||
2341 | If true, then the allout-recent-* settings are calibrated on the | |
2342 | offspring that qaulifies it as aberrant, ie with depth that | |
2343 | exceeds the topic by more than one." | |
2344 | ||
2345 | ;; This is most clearly understood when considering standard-prefix-leader | |
2346 | ;; low-level topics, which can all too easily match text not intended as | |
2347 | ;; headers. For example, any line with a leading '.' or '*' and lacking a | |
2348 | ;; following bullet qualifies without this protection. (A sequence of | |
2349 | ;; them can occur naturally, eg a typical textual bullet list.) We | |
2350 | ;; disqualify such low-level sequences when they are followed by a | |
2351 | ;; discontinuously contained child, inferring that the sequences are not | |
2352 | ;; actually connected with their prospective context. | |
2353 | ||
2354 | (let ((depth (allout-depth)) | |
2355 | (start-point (point)) | |
2356 | done aberrant) | |
2a1408fd DN |
2357 | (save-match-data |
2358 | (save-excursion | |
2359 | (while (and (not done) | |
2360 | (re-search-forward allout-line-boundary-regexp nil 0)) | |
2361 | (allout-prefix-data) | |
2362 | (goto-char allout-recent-prefix-beginning) | |
2363 | (cond | |
8dd59f01 | 2364 | ;; sibling -- continue: |
2a1408fd | 2365 | ((eq allout-recent-depth depth)) |
8dd59f01 | 2366 | ;; first offspring is excessive -- aberrant: |
2a1408fd DN |
2367 | ((> allout-recent-depth (1+ depth)) |
2368 | (setq done t aberrant t)) | |
8dd59f01 | 2369 | ;; next non-sibling is lower-depth -- not aberrant: |
2a1408fd | 2370 | (t (setq done t)))))) |
d8350998 CY |
2371 | (if aberrant |
2372 | aberrant | |
2373 | (goto-char start-point) | |
2374 | ;; recalibrate allout-recent-* | |
2375 | (allout-depth) | |
2376 | nil))) | |
ede4ac6a KS |
2377 | ;;;_ > allout-on-current-heading-p () |
2378 | (defun allout-on-current-heading-p () | |
2379 | "Return non-nil if point is on current visible topics' header line. | |
2380 | ||
2381 | Actually, returns prefix beginning point." | |
2382 | (save-excursion | |
2383 | (allout-beginning-of-current-line) | |
2a1408fd DN |
2384 | (save-match-data |
2385 | (and (looking-at allout-regexp) | |
2386 | (allout-prefix-data) | |
2387 | (or (not (allout-do-doublecheck)) | |
2388 | (not (allout-aberrant-container-p))))))) | |
ede4ac6a KS |
2389 | ;;;_ > allout-on-heading-p () |
2390 | (defalias 'allout-on-heading-p 'allout-on-current-heading-p) | |
2391 | ;;;_ > allout-e-o-prefix-p () | |
2392 | (defun allout-e-o-prefix-p () | |
2393 | "True if point is located where current topic prefix ends, heading begins." | |
2a1408fd DN |
2394 | (and (save-match-data |
2395 | (save-excursion (let ((inhibit-field-text-motion t)) | |
2396 | (beginning-of-line)) | |
2397 | (looking-at allout-regexp)) | |
2398 | (= (point) (save-excursion (allout-end-of-prefix)(point)))))) | |
c567ac01 | 2399 | ;;;_ : Location attributes |
fd5359c6 | 2400 | ;;;_ > allout-depth () |
96b83743 EZ |
2401 | (defun allout-depth () |
2402 | "Return depth of topic most immediately containing point. | |
2403 | ||
42c3e51c KM |
2404 | Does not do doublecheck for aberrant topic header. |
2405 | ||
96b83743 EZ |
2406 | Return zero if point is not within any topic. |
2407 | ||
2408 | Like `allout-current-depth', but respects hidden as well as visible topics." | |
9179616f | 2409 | (save-excursion |
96b83743 EZ |
2410 | (let ((start-point (point))) |
2411 | (if (and (allout-goto-prefix) | |
2412 | (not (< start-point (point)))) | |
d8350998 | 2413 | allout-recent-depth |
96b83743 | 2414 | (progn |
d8350998 CY |
2415 | ;; Oops, no prefix, nullify it: |
2416 | (nullify-allout-prefix-data) | |
96b83743 EZ |
2417 | ;; ... and return 0: |
2418 | 0))))) | |
fd5359c6 | 2419 | ;;;_ > allout-current-depth () |
96b83743 EZ |
2420 | (defun allout-current-depth () |
2421 | "Return depth of visible topic most immediately containing point. | |
2422 | ||
2423 | Return zero if point is not within any topic." | |
2424 | (save-excursion | |
2425 | (if (allout-back-to-current-heading) | |
2426 | (max 1 | |
2427 | (- allout-recent-prefix-end | |
2428 | allout-recent-prefix-beginning | |
2429 | allout-header-subtraction)) | |
2430 | 0))) | |
fd5359c6 MR |
2431 | ;;;_ > allout-get-current-prefix () |
2432 | (defun allout-get-current-prefix () | |
c567ac01 | 2433 | "Topic prefix of the current topic." |
1977b8f6 | 2434 | (save-excursion |
fd5359c6 MR |
2435 | (if (allout-goto-prefix) |
2436 | (allout-recent-prefix)))) | |
2437 | ;;;_ > allout-get-bullet () | |
2438 | (defun allout-get-bullet () | |
c567ac01 | 2439 | "Return bullet of containing topic (visible or not)." |
1977b8f6 | 2440 | (save-excursion |
fd5359c6 MR |
2441 | (and (allout-goto-prefix) |
2442 | (allout-recent-bullet)))) | |
2443 | ;;;_ > allout-current-bullet () | |
2444 | (defun allout-current-bullet () | |
c567ac01 | 2445 | "Return bullet of current (visible) topic heading, or none if none found." |
96b83743 | 2446 | (condition-case nil |
1977b8f6 | 2447 | (save-excursion |
fd5359c6 | 2448 | (allout-back-to-current-heading) |
d8350998 CY |
2449 | (buffer-substring-no-properties (- allout-recent-prefix-end 1) |
2450 | allout-recent-prefix-end)) | |
1977b8f6 | 2451 | ;; Quick and dirty provision, ostensibly for missing bullet: |
d8350998 | 2452 | (args-out-of-range nil)) |
1977b8f6 | 2453 | ) |
fd5359c6 MR |
2454 | ;;;_ > allout-get-prefix-bullet (prefix) |
2455 | (defun allout-get-prefix-bullet (prefix) | |
c567ac01 | 2456 | "Return the bullet of the header prefix string PREFIX." |
1977b8f6 RS |
2457 | ;; Doesn't make sense if we're old-style prefixes, but this just |
2458 | ;; oughtn't be called then, so forget about it... | |
fd5359c6 | 2459 | (if (string-match allout-regexp prefix) |
d8350998 | 2460 | (substring prefix (1- (match-end 2)) (match-end 2)))) |
fd5359c6 MR |
2461 | ;;;_ > allout-sibling-index (&optional depth) |
2462 | (defun allout-sibling-index (&optional depth) | |
9179616f DL |
2463 | "Item number of this prospective topic among its siblings. |
2464 | ||
e126900f | 2465 | If optional arg DEPTH is greater than current depth, then we're |
9179616f DL |
2466 | opening a new level, and return 0. |
2467 | ||
2468 | If less than this depth, ascend to that depth and count..." | |
2469 | ||
2470 | (save-excursion | |
2471 | (cond ((and depth (<= depth 0) 0)) | |
65e7eb3d | 2472 | ((or (null depth) (= depth (allout-depth))) |
9179616f | 2473 | (let ((index 1)) |
d8350998 | 2474 | (while (allout-previous-sibling allout-recent-depth nil) |
9179616f DL |
2475 | (setq index (1+ index))) |
2476 | index)) | |
d8350998 | 2477 | ((< depth allout-recent-depth) |
fd5359c6 MR |
2478 | (allout-ascend-to-depth depth) |
2479 | (allout-sibling-index)) | |
9179616f | 2480 | (0)))) |
fd5359c6 MR |
2481 | ;;;_ > allout-topic-flat-index () |
2482 | (defun allout-topic-flat-index () | |
9179616f DL |
2483 | "Return a list indicating point's numeric section.subsect.subsubsect... |
2484 | Outermost is first." | |
fd5359c6 MR |
2485 | (let* ((depth (allout-depth)) |
2486 | (next-index (allout-sibling-index depth)) | |
9179616f DL |
2487 | (rev-sibls nil)) |
2488 | (while (> next-index 0) | |
2489 | (setq rev-sibls (cons next-index rev-sibls)) | |
2490 | (setq depth (1- depth)) | |
fd5359c6 | 2491 | (setq next-index (allout-sibling-index depth))) |
9179616f DL |
2492 | rev-sibls) |
2493 | ) | |
1977b8f6 | 2494 | |
96b83743 EZ |
2495 | ;;;_ - Navigation routines |
2496 | ;;;_ > allout-beginning-of-current-line () | |
2497 | (defun allout-beginning-of-current-line () | |
2498 | "Like beginning of line, but to visible text." | |
2499 | ||
5204800f NR |
2500 | ;; This combination of move-beginning-of-line and beginning-of-line is |
2501 | ;; deliberate, but the (beginning-of-line) may now be superfluous. | |
0458fa80 EZ |
2502 | (let ((inhibit-field-text-motion t)) |
2503 | (move-beginning-of-line 1) | |
96b83743 | 2504 | (beginning-of-line) |
0458fa80 EZ |
2505 | (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p))) |
2506 | (beginning-of-line) | |
2507 | (if (or (allout-hidden-p) (not (bolp))) | |
2508 | (forward-char -1))))) | |
96b83743 EZ |
2509 | ;;;_ > allout-end-of-current-line () |
2510 | (defun allout-end-of-current-line () | |
2511 | "Move to the end of line, past concealed text if any." | |
ea18b2b1 | 2512 | ;; XXX This is for symmetry with `allout-beginning-of-current-line' -- |
96b83743 EZ |
2513 | ;; `move-end-of-line' doesn't suffer the same problem as |
2514 | ;; `move-beginning-of-line'. | |
0458fa80 | 2515 | (let ((inhibit-field-text-motion t)) |
96b83743 | 2516 | (end-of-line) |
0458fa80 EZ |
2517 | (while (allout-hidden-p) |
2518 | (end-of-line) | |
2519 | (if (allout-hidden-p) (forward-char 1))))) | |
48bd8440 EZ |
2520 | ;;;_ > allout-beginning-of-line () |
2521 | (defun allout-beginning-of-line () | |
2522 | "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set." | |
2523 | ||
2524 | (interactive) | |
2525 | ||
2526 | (if (or (not allout-beginning-of-line-cycles) | |
2527 | (not (equal last-command this-command))) | |
2a1408fd DN |
2528 | (progn |
2529 | (if (and (not (bolp)) | |
2530 | (allout-hidden-p (1- (point)))) | |
2531 | (goto-char (previous-single-char-property-change | |
2532 | (1- (point)) 'invisible))) | |
2533 | (move-beginning-of-line 1)) | |
d8350998 CY |
2534 | (allout-depth) |
2535 | (let ((beginning-of-body | |
2536 | (save-excursion | |
ede4ac6a | 2537 | (while (and (allout-do-doublecheck) |
d8350998 CY |
2538 | (allout-aberrant-container-p) |
2539 | (allout-previous-visible-heading 1))) | |
2540 | (allout-beginning-of-current-entry) | |
2541 | (point)))) | |
48bd8440 | 2542 | (cond ((= (current-column) 0) |
d8350998 | 2543 | (goto-char beginning-of-body)) |
48bd8440 EZ |
2544 | ((< (point) beginning-of-body) |
2545 | (allout-beginning-of-current-line)) | |
2546 | ((= (point) beginning-of-body) | |
2547 | (goto-char (allout-current-bullet-pos))) | |
2548 | (t (allout-beginning-of-current-line) | |
2549 | (if (< (point) beginning-of-body) | |
2550 | ;; we were on the headline after its start: | |
d8350998 | 2551 | (goto-char beginning-of-body))))))) |
48bd8440 EZ |
2552 | ;;;_ > allout-end-of-line () |
2553 | (defun allout-end-of-line () | |
2554 | "End-of-line with `allout-end-of-line-cycles' behavior, if set." | |
2555 | ||
2556 | (interactive) | |
2557 | ||
2558 | (if (or (not allout-end-of-line-cycles) | |
2559 | (not (equal last-command this-command))) | |
2560 | (allout-end-of-current-line) | |
2561 | (let ((end-of-entry (save-excursion | |
2562 | (allout-end-of-entry) | |
2563 | (point)))) | |
2564 | (cond ((not (eolp)) | |
2565 | (allout-end-of-current-line)) | |
2566 | ((or (allout-hidden-p) (save-excursion | |
2567 | (forward-char -1) | |
2568 | (allout-hidden-p))) | |
2569 | (allout-back-to-current-heading) | |
2570 | (allout-show-current-entry) | |
d8350998 | 2571 | (allout-show-children) |
48bd8440 EZ |
2572 | (allout-end-of-entry)) |
2573 | ((>= (point) end-of-entry) | |
2574 | (allout-back-to-current-heading) | |
2575 | (allout-end-of-current-line)) | |
2a1408fd DN |
2576 | (t |
2577 | (if (not (and transient-mark-mode mark-active)) | |
2578 | (push-mark)) | |
2579 | (allout-end-of-entry)))))) | |
fd5359c6 MR |
2580 | ;;;_ > allout-next-heading () |
2581 | (defsubst allout-next-heading () | |
c07583cd | 2582 | "Move to the heading for the topic (possibly invisible) after this one. |
c567ac01 | 2583 | |
d8350998 | 2584 | Returns the location of the heading, or nil if none found. |
c567ac01 | 2585 | |
75bcb912 | 2586 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
2a1408fd DN |
2587 | (save-match-data |
2588 | ||
2589 | (if (looking-at allout-regexp) | |
2590 | (forward-char 1)) | |
2591 | ||
2592 | (when (re-search-forward allout-line-boundary-regexp nil 0) | |
2593 | (allout-prefix-data) | |
42c3e51c KM |
2594 | (goto-char allout-recent-prefix-beginning) |
2595 | (while (not (bolp)) | |
2596 | (forward-char -1)) | |
2a1408fd DN |
2597 | (and (allout-do-doublecheck) |
2598 | ;; this will set allout-recent-* on the first non-aberrant topic, | |
2599 | ;; whether it's the current one or one that disqualifies it: | |
2600 | (allout-aberrant-container-p)) | |
42c3e51c | 2601 | ;; this may or may not be the same as above depending on doublecheck: |
2a1408fd | 2602 | (goto-char allout-recent-prefix-beginning)))) |
96b83743 | 2603 | ;;;_ > allout-this-or-next-heading |
fd5359c6 | 2604 | (defun allout-this-or-next-heading () |
8d118843 | 2605 | "Position cursor on current or next heading." |
fd5359c6 MR |
2606 | ;; A throwaway non-macro that is defined after allout-next-heading |
2607 | ;; and usable by allout-mode. | |
d8350998 | 2608 | (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading))) |
fd5359c6 | 2609 | ;;;_ > allout-previous-heading () |
8a559d4e | 2610 | (defun allout-previous-heading () |
c07583cd | 2611 | "Move to the prior (possibly invisible) heading line. |
c567ac01 | 2612 | |
d8350998 CY |
2613 | Return the location of the beginning of the heading, or nil if not found. |
2614 | ||
75bcb912 | 2615 | We skip anomalous low-level topics, a la `allout-aberrant-container-p'." |
d8350998 CY |
2616 | |
2617 | (if (bobp) | |
2618 | nil | |
d8350998 | 2619 | (let ((start-point (point))) |
ede4ac6a | 2620 | ;; allout-goto-prefix-doublechecked calls us, so we can't use it here. |
d8350998 | 2621 | (allout-goto-prefix) |
2a1408fd DN |
2622 | (save-match-data |
2623 | (when (or (re-search-backward allout-line-boundary-regexp nil 0) | |
2624 | (looking-at allout-bob-regexp)) | |
2625 | (goto-char (allout-prefix-data)) | |
2626 | (if (and (allout-do-doublecheck) | |
2627 | (allout-aberrant-container-p)) | |
2628 | (or (allout-previous-heading) | |
2629 | (and (goto-char start-point) | |
2630 | ;; recalibrate allout-recent-*: | |
2631 | (allout-depth) | |
2632 | nil)) | |
2633 | (point))))))) | |
96b83743 EZ |
2634 | ;;;_ > allout-get-invisibility-overlay () |
2635 | (defun allout-get-invisibility-overlay () | |
2636 | "Return the overlay at point that dictates allout invisibility." | |
2637 | (let ((overlays (overlays-at (point))) | |
2638 | got) | |
2639 | (while (and overlays (not got)) | |
2640 | (if (equal (overlay-get (car overlays) 'invisible) 'allout) | |
d8350998 CY |
2641 | (setq got (car overlays)) |
2642 | (pop overlays))) | |
96b83743 EZ |
2643 | got)) |
2644 | ;;;_ > allout-back-to-visible-text () | |
2645 | (defun allout-back-to-visible-text () | |
2646 | "Move to most recent prior character that is visible, and return point." | |
2647 | (if (allout-hidden-p) | |
2648 | (goto-char (overlay-start (allout-get-invisibility-overlay)))) | |
2649 | (point)) | |
c567ac01 RS |
2650 | |
2651 | ;;;_ - Subtree Charting | |
2652 | ;;;_ " These routines either produce or assess charts, which are | |
2653 | ;;; nested lists of the locations of topics within a subtree. | |
2654 | ;;; | |
d8350998 CY |
2655 | ;;; Charts enable efficient subtree navigation by providing a reusable basis |
2656 | ;;; for elaborate, compound assessment and adjustment of a subtree. | |
c567ac01 | 2657 | |
48bd8440 EZ |
2658 | ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth) |
2659 | (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth) | |
19b84ba3 RS |
2660 | "Produce a location \"chart\" of subtopics of the containing topic. |
2661 | ||
c07583cd | 2662 | Optional argument LEVELS specifies a depth limit (relative to start |
65e7eb3d | 2663 | depth) for the chart. Null LEVELS means no limit. |
48bd8440 EZ |
2664 | |
2665 | When optional argument VISIBLE is non-nil, the chart includes | |
2666 | only the visible subelements of the charted subjects. | |
2667 | ||
65e7eb3d | 2668 | The remaining optional args are for internal use by the function. |
d82979ea EZ |
2669 | |
2670 | Point is left at the end of the subtree. | |
19b84ba3 | 2671 | |
d82979ea | 2672 | Charts are used to capture outline structure, so that outline-altering |
19b84ba3 RS |
2673 | routines need assess the structure only once, and then use the chart |
2674 | for their elaborate manipulations. | |
2675 | ||
d8350998 CY |
2676 | The chart entries for the topics are in reverse order, so the |
2677 | last topic is listed first. The entry for each topic consists of | |
2678 | an integer indicating the point at the beginning of the topic | |
2679 | prefix. Charts for offspring consists of a list containing, | |
2680 | recursively, the charts for the respective subtopics. The chart | |
2681 | for a topics' offspring precedes the entry for the topic itself. | |
19b84ba3 | 2682 | |
d82979ea EZ |
2683 | The other function parameters are for internal recursion, and should |
2684 | not be specified by external callers. ORIG-DEPTH is depth of topic at | |
2685 | starting point, and PREV-DEPTH is depth of prior topic." | |
19b84ba3 | 2686 | |
353e2ef2 | 2687 | (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. |
19b84ba3 RS |
2688 | chart curr-depth) |
2689 | ||
2690 | (if original ; Just starting? | |
2691 | ; Register initial settings and | |
2692 | ; position to first offspring: | |
fd5359c6 | 2693 | (progn (setq orig-depth (allout-depth)) |
19b84ba3 | 2694 | (or prev-depth (setq prev-depth (1+ orig-depth))) |
48bd8440 EZ |
2695 | (if visible |
2696 | (allout-next-visible-heading 1) | |
2697 | (allout-next-heading)))) | |
c567ac01 | 2698 | |
19b84ba3 RS |
2699 | ;; Loop over the current levels' siblings. Besides being more |
2700 | ;; efficient than tail-recursing over a level, it avoids exceeding | |
e126900f | 2701 | ;; the typically quite constrained Emacs max-lisp-eval-depth. |
9179616f | 2702 | ;; |
19b84ba3 RS |
2703 | ;; Probably would speed things up to implement loop-based stack |
2704 | ;; operation rather than recursing for lower levels. Bah. | |
9179616f | 2705 | |
c567ac01 | 2706 | (while (and (not (eobp)) |
19b84ba3 | 2707 | ; Still within original topic? |
d8350998 | 2708 | (< orig-depth (setq curr-depth allout-recent-depth)) |
19b84ba3 RS |
2709 | (cond ((= prev-depth curr-depth) |
2710 | ;; Register this one and move on: | |
d8350998 | 2711 | (setq chart (cons allout-recent-prefix-beginning chart)) |
19b84ba3 | 2712 | (if (and levels (<= levels 1)) |
60c7bbd2 | 2713 | ;; At depth limit -- skip sublevels: |
fd5359c6 | 2714 | (or (allout-next-sibling curr-depth) |
60c7bbd2 | 2715 | ;; or no more siblings -- proceed to |
19b84ba3 | 2716 | ;; next heading at lesser depth: |
e6a9aec7 | 2717 | (while (and (<= curr-depth |
d8350998 | 2718 | allout-recent-depth) |
48bd8440 EZ |
2719 | (if visible |
2720 | (allout-next-visible-heading 1) | |
2721 | (allout-next-heading))))) | |
2722 | (if visible | |
2723 | (allout-next-visible-heading 1) | |
2724 | (allout-next-heading)))) | |
19b84ba3 RS |
2725 | |
2726 | ((and (< prev-depth curr-depth) | |
2727 | (or (not levels) | |
2728 | (> levels 0))) | |
2729 | ;; Recurse on deeper level of curr topic: | |
2730 | (setq chart | |
fd5359c6 | 2731 | (cons (allout-chart-subtree (and levels |
19b84ba3 | 2732 | (1- levels)) |
48bd8440 EZ |
2733 | visible |
2734 | orig-depth | |
2735 | curr-depth) | |
19b84ba3 RS |
2736 | chart)) |
2737 | ;; ... then continue with this one. | |
2738 | ) | |
2739 | ||
2740 | ;; ... else nil if we've ascended back to prev-depth. | |
2741 | ||
2742 | ))) | |
2743 | ||
2744 | (if original ; We're at the last sibling on | |
2745 | ; the original level. Position | |
2746 | ; to the end of it: | |
c567ac01 | 2747 | (progn (and (not (eobp)) (forward-char -1)) |
96b83743 EZ |
2748 | (and (= (preceding-char) ?\n) |
2749 | (= (aref (buffer-substring (max 1 (- (point) 3)) | |
2750 | (point)) | |
2751 | 1) | |
2752 | ?\n) | |
19b84ba3 | 2753 | (forward-char -1)) |
fd5359c6 | 2754 | (setq allout-recent-end-of-subtree (point)))) |
353e2ef2 | 2755 | |
c567ac01 RS |
2756 | chart ; (nreverse chart) not necessary, |
2757 | ; and maybe not preferable. | |
2758 | )) | |
fd5359c6 MR |
2759 | ;;;_ > allout-chart-siblings (&optional start end) |
2760 | (defun allout-chart-siblings (&optional start end) | |
c567ac01 | 2761 | "Produce a list of locations of this and succeeding sibling topics. |
fd5359c6 | 2762 | Effectively a top-level chart of siblings. See `allout-chart-subtree' |
c567ac01 RS |
2763 | for an explanation of charts." |
2764 | (save-excursion | |
d8350998 CY |
2765 | (when (allout-goto-prefix-doublechecked) |
2766 | (let ((chart (list (point)))) | |
2767 | (while (allout-next-sibling) | |
2768 | (setq chart (cons (point) chart))) | |
2769 | (if chart (setq chart (nreverse chart))))))) | |
fd5359c6 MR |
2770 | ;;;_ > allout-chart-to-reveal (chart depth) |
2771 | (defun allout-chart-to-reveal (chart depth) | |
c567ac01 | 2772 | |
19b84ba3 | 2773 | "Return a flat list of hidden points in subtree CHART, up to DEPTH. |
c567ac01 | 2774 | |
65e7eb3d EZ |
2775 | If DEPTH is nil, include hidden points at any depth. |
2776 | ||
19b84ba3 | 2777 | Note that point can be left at any of the points on chart, or at the |
c567ac01 RS |
2778 | start point." |
2779 | ||
2780 | (let (result here) | |
65e7eb3d | 2781 | (while (and (or (null depth) (> depth 0)) |
c567ac01 RS |
2782 | chart) |
2783 | (setq here (car chart)) | |
2784 | (if (listp here) | |
65e7eb3d EZ |
2785 | (let ((further (allout-chart-to-reveal here (if (null depth) |
2786 | depth | |
2787 | (1- depth))))) | |
60c7bbd2 | 2788 | ;; We're on the start of a subtree -- recurse with it, if there's |
c567ac01 RS |
2789 | ;; more depth to go: |
2790 | (if further (setq result (append further result))) | |
2791 | (setq chart (cdr chart))) | |
2792 | (goto-char here) | |
96b83743 | 2793 | (if (allout-hidden-p) |
c567ac01 RS |
2794 | (setq result (cons here result))) |
2795 | (setq chart (cdr chart)))) | |
2796 | result)) | |
fd5359c6 | 2797 | ;;;_ X allout-chart-spec (chart spec &optional exposing) |
e126900f | 2798 | ;; (defun allout-chart-spec (chart spec &optional exposing) |
c07583cd | 2799 | ;; "Not yet (if ever) implemented. |
e126900f JB |
2800 | |
2801 | ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC. | |
2802 | ||
2803 | ;; Exposure spec indicates the locations to be exposed and the prescribed | |
2804 | ;; exposure status. Optional arg EXPOSING is an integer, with 0 | |
2805 | ;; indicating pending concealment, anything higher indicating depth to | |
2806 | ;; which subtopic headers should be exposed, and negative numbers | |
2807 | ;; indicating (negative of) the depth to which subtopic headers and | |
2808 | ;; bodies should be exposed. | |
2809 | ||
2810 | ;; The produced list can have two types of entries. Bare numbers | |
2811 | ;; indicate points in the buffer where topic headers that should be | |
2812 | ;; exposed reside. | |
2813 | ||
2814 | ;; - bare negative numbers indicates that the topic starting at the | |
2815 | ;; point which is the negative of the number should be opened, | |
2816 | ;; including their entries. | |
2817 | ;; - bare positive values indicate that this topic header should be | |
2818 | ;; opened. | |
2819 | ;; - Lists signify the beginning and end points of regions that should | |
c07583cd | 2820 | ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and |
e126900f JB |
2821 | ;; exposure:" |
2822 | ;; (while spec | |
2823 | ;; (cond ((listp spec) | |
2824 | ;; ) | |
2825 | ;; ) | |
2826 | ;; (setq spec (cdr spec))) | |
2827 | ;; ) | |
c567ac01 RS |
2828 | |
2829 | ;;;_ - Within Topic | |
fd5359c6 MR |
2830 | ;;;_ > allout-goto-prefix () |
2831 | (defun allout-goto-prefix () | |
9179616f | 2832 | "Put point at beginning of immediately containing outline topic. |
19b84ba3 | 2833 | |
9179616f | 2834 | Goes to most immediate subsequent topic if none immediately containing. |
19b84ba3 RS |
2835 | |
2836 | Not sensitive to topic visibility. | |
c567ac01 | 2837 | |
d27081f5 | 2838 | Returns the point at the beginning of the prefix, or nil if none." |
c567ac01 | 2839 | |
2a1408fd DN |
2840 | (save-match-data |
2841 | (let (done) | |
2842 | (while (and (not done) | |
2843 | (search-backward "\n" nil 1)) | |
2844 | (forward-char 1) | |
2845 | (if (looking-at allout-regexp) | |
2846 | (setq done (allout-prefix-data)) | |
2847 | (forward-char -1))) | |
2848 | (if (bobp) | |
2849 | (cond ((looking-at allout-regexp) | |
2850 | (allout-prefix-data)) | |
2851 | ((allout-next-heading)) | |
2852 | (done)) | |
2853 | done)))) | |
d8350998 CY |
2854 | ;;;_ > allout-goto-prefix-doublechecked () |
2855 | (defun allout-goto-prefix-doublechecked () | |
2856 | "Put point at beginning of immediately containing outline topic. | |
2857 | ||
c07583cd | 2858 | Like `allout-goto-prefix', but shallow topics (according to |
65e7eb3d EZ |
2859 | `allout-doublecheck-at-and-shallower') are checked and |
2860 | disqualified for child containment discontinuity, according to | |
2861 | `allout-aberrant-container-p'." | |
ede4ac6a KS |
2862 | (if (allout-goto-prefix) |
2863 | (if (and (allout-do-doublecheck) | |
2864 | (allout-aberrant-container-p)) | |
2865 | (allout-previous-heading) | |
2866 | (point)))) | |
d8350998 | 2867 | |
fd5359c6 MR |
2868 | ;;;_ > allout-end-of-prefix () |
2869 | (defun allout-end-of-prefix (&optional ignore-decorations) | |
19b84ba3 RS |
2870 | "Position cursor at beginning of header text. |
2871 | ||
2872 | If optional IGNORE-DECORATIONS is non-nil, put just after bullet, | |
2873 | otherwise skip white space between bullet and ensuing text." | |
c567ac01 | 2874 | |
d8350998 | 2875 | (if (not (allout-goto-prefix-doublechecked)) |
1977b8f6 | 2876 | nil |
d8350998 | 2877 | (goto-char allout-recent-prefix-end) |
2a1408fd DN |
2878 | (save-match-data |
2879 | (if ignore-decorations | |
2880 | t | |
2881 | (while (looking-at "[0-9]") (forward-char 1)) | |
2882 | (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))) | |
1977b8f6 | 2883 | ;; Reestablish where we are: |
fd5359c6 MR |
2884 | (allout-current-depth))) |
2885 | ;;;_ > allout-current-bullet-pos () | |
2886 | (defun allout-current-bullet-pos () | |
c07583cd | 2887 | "Return position of current (visible) topic's bullet." |
c567ac01 | 2888 | |
8a559d4e | 2889 | (if (not (allout-current-depth)) |
c567ac01 | 2890 | nil |
8a559d4e | 2891 | (1- allout-recent-prefix-end))) |
fd5359c6 MR |
2892 | ;;;_ > allout-back-to-current-heading () |
2893 | (defun allout-back-to-current-heading () | |
80f66ef4 | 2894 | "Move to heading line of current topic, or beginning if not in a topic. |
96b83743 | 2895 | |
80f66ef4 CY |
2896 | If interactive, we position at the end of the prefix. |
2897 | ||
2898 | Return value of resulting point, unless we started outside | |
2899 | of (before any) topics, in which case we return nil." | |
96b83743 EZ |
2900 | |
2901 | (allout-beginning-of-current-line) | |
80f66ef4 | 2902 | (let ((bol-point (point))) |
ede4ac6a KS |
2903 | (if (allout-goto-prefix-doublechecked) |
2904 | (if (<= (point) bol-point) | |
2905 | (if (interactive-p) | |
2906 | (allout-end-of-prefix) | |
2907 | (point)) | |
2908 | (goto-char (point-min)) | |
2909 | nil)))) | |
fd5359c6 MR |
2910 | ;;;_ > allout-back-to-heading () |
2911 | (defalias 'allout-back-to-heading 'allout-back-to-current-heading) | |
96b83743 EZ |
2912 | ;;;_ > allout-pre-next-prefix () |
2913 | (defun allout-pre-next-prefix () | |
1977b8f6 RS |
2914 | "Skip forward to just before the next heading line. |
2915 | ||
c567ac01 | 2916 | Returns that character position." |
1977b8f6 | 2917 | |
8a559d4e EZ |
2918 | (if (allout-next-heading) |
2919 | (goto-char (1- allout-recent-prefix-beginning)))) | |
96b83743 EZ |
2920 | ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank) |
2921 | (defun allout-end-of-subtree (&optional current include-trailing-blank) | |
d82979ea EZ |
2922 | "Put point at the end of the last leaf in the containing topic. |
2923 | ||
96b83743 EZ |
2924 | Optional CURRENT means put point at the end of the containing |
2925 | visible topic. | |
2926 | ||
2927 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if | |
2928 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2929 | excluded as delimiting whitespace between topics. | |
d82979ea EZ |
2930 | |
2931 | Returns the value of point." | |
2932 | (interactive "P") | |
2933 | (if current | |
2934 | (allout-back-to-current-heading) | |
d8350998 CY |
2935 | (allout-goto-prefix-doublechecked)) |
2936 | (let ((level allout-recent-depth)) | |
fd5359c6 | 2937 | (allout-next-heading) |
1977b8f6 | 2938 | (while (and (not (eobp)) |
d8350998 | 2939 | (> allout-recent-depth level)) |
fd5359c6 | 2940 | (allout-next-heading)) |
48bd8440 EZ |
2941 | (if (eobp) |
2942 | (allout-end-of-entry) | |
2943 | (forward-char -1)) | |
96b83743 | 2944 | (if (and (not include-trailing-blank) (= ?\n (preceding-char))) |
c567ac01 | 2945 | (forward-char -1)) |
fd5359c6 | 2946 | (setq allout-recent-end-of-subtree (point)))) |
96b83743 EZ |
2947 | ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank) |
2948 | (defun allout-end-of-current-subtree (&optional include-trailing-blank) | |
2949 | ||
d82979ea EZ |
2950 | "Put point at end of last leaf in currently visible containing topic. |
2951 | ||
96b83743 EZ |
2952 | Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if |
2953 | any, as part of the subtree. Otherwise, that trailing blank will be | |
2954 | excluded as delimiting whitespace between topics. | |
2955 | ||
d82979ea EZ |
2956 | Returns the value of point." |
2957 | (interactive) | |
96b83743 | 2958 | (allout-end-of-subtree t include-trailing-blank)) |
fd5359c6 MR |
2959 | ;;;_ > allout-beginning-of-current-entry () |
2960 | (defun allout-beginning-of-current-entry () | |
d82979ea | 2961 | "When not already there, position point at beginning of current topic header. |
c567ac01 RS |
2962 | |
2963 | If already there, move cursor to bullet for hot-spot operation. | |
46771bb3 | 2964 | \(See `allout-mode' doc string for details of hot-spot operation.)" |
1977b8f6 | 2965 | (interactive) |
c567ac01 | 2966 | (let ((start-point (point))) |
46771bb3 | 2967 | (move-beginning-of-line 1) |
d8350998 CY |
2968 | (if (< 0 (allout-current-depth)) |
2969 | (goto-char allout-recent-prefix-end) | |
2970 | (goto-char (point-min))) | |
fd5359c6 | 2971 | (allout-end-of-prefix) |
c567ac01 RS |
2972 | (if (and (interactive-p) |
2973 | (= (point) start-point)) | |
fd5359c6 | 2974 | (goto-char (allout-current-bullet-pos))))) |
96b83743 EZ |
2975 | ;;;_ > allout-end-of-entry (&optional inclusive) |
2976 | (defun allout-end-of-entry (&optional inclusive) | |
2977 | "Position the point at the end of the current topics' entry. | |
2978 | ||
2979 | Optional INCLUSIVE means also include trailing empty line, if any. When | |
2980 | unset, whitespace between items separates them even when the items are | |
2981 | collapsed." | |
1977b8f6 | 2982 | (interactive) |
96b83743 EZ |
2983 | (allout-pre-next-prefix) |
2984 | (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char))) | |
2985 | (forward-char -1)) | |
2986 | (point)) | |
fd5359c6 MR |
2987 | ;;;_ > allout-end-of-current-heading () |
2988 | (defun allout-end-of-current-heading () | |
9179616f | 2989 | (interactive) |
fd5359c6 | 2990 | (allout-beginning-of-current-entry) |
96b83743 | 2991 | (search-forward "\n" nil t) |
d82979ea | 2992 | (forward-char -1)) |
fd5359c6 | 2993 | (defalias 'allout-end-of-heading 'allout-end-of-current-heading) |
d82979ea EZ |
2994 | ;;;_ > allout-get-body-text () |
2995 | (defun allout-get-body-text () | |
2996 | "Return the unmangled body text of the topic immediately containing point." | |
2997 | (save-excursion | |
2998 | (allout-end-of-prefix) | |
96b83743 | 2999 | (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
3000 | nil |
3001 | (backward-char 1) | |
3002 | (let ((pre-body (point))) | |
3003 | (if (not pre-body) | |
3004 | nil | |
96b83743 | 3005 | (allout-end-of-entry t) |
d82979ea EZ |
3006 | (if (not (= pre-body (point))) |
3007 | (buffer-substring-no-properties (1+ pre-body) (point)))) | |
3008 | ) | |
3009 | ) | |
3010 | ) | |
3011 | ) | |
1977b8f6 | 3012 | |
c567ac01 | 3013 | ;;;_ - Depth-wise |
fd5359c6 MR |
3014 | ;;;_ > allout-ascend-to-depth (depth) |
3015 | (defun allout-ascend-to-depth (depth) | |
c567ac01 | 3016 | "Ascend to depth DEPTH, returning depth if successful, nil if not." |
fd5359c6 | 3017 | (if (and (> depth 0)(<= depth (allout-depth))) |
d8350998 CY |
3018 | (let (last-ascended) |
3019 | (while (and (< depth allout-recent-depth) | |
3020 | (setq last-ascended (allout-ascend)))) | |
3021 | (goto-char allout-recent-prefix-beginning) | |
3022 | (if (interactive-p) (allout-end-of-prefix)) | |
3023 | (and last-ascended allout-recent-depth)))) | |
fd5359c6 | 3024 | ;;;_ > allout-ascend () |
c07583cd KS |
3025 | (defun allout-ascend (&optional dont-move-if-unsuccessful) |
3026 | "Ascend one level, returning resulting depth if successful, nil if not. | |
3027 | ||
3028 | Point is left at the beginning of the level whether or not | |
3029 | successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in | |
3030 | which case point is returned to its original starting location." | |
3031 | (if dont-move-if-unsuccessful | |
3032 | (setq dont-move-if-unsuccessful (point))) | |
d82979ea EZ |
3033 | (prog1 |
3034 | (if (allout-beginning-of-level) | |
498a6493 CY |
3035 | (let ((bolevel (point)) |
3036 | (bolevel-depth allout-recent-depth)) | |
3037 | (allout-previous-heading) | |
c07583cd KS |
3038 | (cond ((< allout-recent-depth bolevel-depth) |
3039 | allout-recent-depth) | |
3040 | ((= allout-recent-depth bolevel-depth) | |
3041 | (if dont-move-if-unsuccessful | |
3042 | (goto-char dont-move-if-unsuccessful)) | |
3043 | (allout-depth) | |
3044 | nil) | |
3045 | (t | |
3046 | ;; some topic after very first is lower depth than first: | |
3047 | (goto-char bolevel) | |
3048 | (allout-depth) | |
3049 | nil)))) | |
d82979ea | 3050 | (if (interactive-p) (allout-end-of-prefix)))) |
fd5359c6 MR |
3051 | ;;;_ > allout-descend-to-depth (depth) |
3052 | (defun allout-descend-to-depth (depth) | |
19b84ba3 RS |
3053 | "Descend to depth DEPTH within current topic. |
3054 | ||
3055 | Returning depth if successful, nil if not." | |
1977b8f6 | 3056 | (let ((start-point (point)) |
fd5359c6 | 3057 | (start-depth (allout-depth))) |
1977b8f6 | 3058 | (while |
fd5359c6 | 3059 | (and (> (allout-depth) 0) |
d8350998 | 3060 | (not (= depth allout-recent-depth)) ; ... not there yet |
fd5359c6 | 3061 | (allout-next-heading) ; ... go further |
d8350998 | 3062 | (< start-depth allout-recent-depth))) ; ... still in topic |
fd5359c6 | 3063 | (if (and (> (allout-depth) 0) |
d8350998 | 3064 | (= allout-recent-depth depth)) |
1977b8f6 RS |
3065 | depth |
3066 | (goto-char start-point) | |
3067 | nil)) | |
3068 | ) | |
d8350998 CY |
3069 | ;;;_ > allout-up-current-level (arg) |
3070 | (defun allout-up-current-level (arg) | |
3071 | "Move out ARG levels from current visible topic." | |
d82979ea | 3072 | (interactive "p") |
8a559d4e EZ |
3073 | (let ((start-point (point))) |
3074 | (allout-back-to-current-heading) | |
3075 | (if (not (allout-ascend)) | |
3076 | (progn (goto-char start-point) | |
3077 | (error "Can't ascend past outermost level")) | |
3078 | (if (interactive-p) (allout-end-of-prefix)) | |
3079 | allout-recent-prefix-beginning))) | |
1977b8f6 | 3080 | |
c567ac01 | 3081 | ;;;_ - Linear |
fd5359c6 MR |
3082 | ;;;_ > allout-next-sibling (&optional depth backward) |
3083 | (defun allout-next-sibling (&optional depth backward) | |
2265e017 | 3084 | "Like `allout-forward-current-level', but respects invisible topics. |
1977b8f6 | 3085 | |
c567ac01 | 3086 | Traverse at optional DEPTH, or current depth if none specified. |
1977b8f6 | 3087 | |
c567ac01 | 3088 | Go backward if optional arg BACKWARD is non-nil. |
1977b8f6 | 3089 | |
d8350998 | 3090 | Return the start point of the new topic if successful, nil otherwise." |
1977b8f6 | 3091 | |
d8350998 | 3092 | (if (if backward (bobp) (eobp)) |
1977b8f6 | 3093 | nil |
d8350998 | 3094 | (let ((target-depth (or depth (allout-depth))) |
1977b8f6 | 3095 | (start-point (point)) |
ede4ac6a | 3096 | (start-prefix-beginning allout-recent-prefix-beginning) |
d8350998 CY |
3097 | (count 0) |
3098 | leaping | |
c567ac01 | 3099 | last-depth) |
d8350998 CY |
3100 | (while (and |
3101 | ;; done too few single steps to resort to the leap routine: | |
3102 | (not leaping) | |
3103 | ;; not at limit: | |
3104 | (not (if backward (bobp) (eobp))) | |
3105 | ;; still traversable: | |
3106 | (if backward (allout-previous-heading) (allout-next-heading)) | |
3107 | ;; we're below the target depth | |
3108 | (> (setq last-depth allout-recent-depth) target-depth)) | |
3109 | (setq count (1+ count)) | |
3110 | (if (> count 7) ; lists are commonly 7 +- 2, right?-) | |
3111 | (setq leaping t))) | |
3112 | (cond (leaping | |
3113 | (or (allout-next-sibling-leap target-depth backward) | |
3114 | (progn | |
3115 | (goto-char start-point) | |
3116 | (if depth (allout-depth) target-depth) | |
3117 | nil))) | |
3118 | ((and (not (eobp)) | |
3119 | (and (> (or last-depth (allout-depth)) 0) | |
ede4ac6a KS |
3120 | (= allout-recent-depth target-depth)) |
3121 | (not (= start-prefix-beginning | |
3122 | allout-recent-prefix-beginning))) | |
d8350998 CY |
3123 | allout-recent-prefix-beginning) |
3124 | (t | |
3125 | (goto-char start-point) | |
3126 | (if depth (allout-depth) target-depth) | |
3127 | nil))))) | |
3128 | ;;;_ > allout-next-sibling-leap (&optional depth backward) | |
3129 | (defun allout-next-sibling-leap (&optional depth backward) | |
3130 | "Like `allout-next-sibling', but by direct search for topic at depth. | |
3131 | ||
3132 | Traverse at optional DEPTH, or current depth if none specified. | |
3133 | ||
3134 | Go backward if optional arg BACKWARD is non-nil. | |
3135 | ||
3136 | Return the start point of the new topic if successful, nil otherwise. | |
3137 | ||
3138 | Costs more than regular `allout-next-sibling' for short traversals: | |
3139 | ||
c07583cd | 3140 | - we have to check the prior (next, if travelling backwards) |
d8350998 CY |
3141 | item to confirm connectivity with the prior topic, and |
3142 | - if confirmed, we have to reestablish the allout-recent-* settings with | |
3143 | some extra navigation | |
3144 | - if confirmation fails, we have to do more work to recover | |
3145 | ||
3146 | It is an increasingly big win when there are many intervening | |
3147 | offspring before the next sibling, however, so | |
3148 | `allout-next-sibling' resorts to this if it finds itself in that | |
3149 | situation." | |
3150 | ||
3151 | (if (if backward (bobp) (eobp)) | |
3152 | nil | |
3153 | (let* ((start-point (point)) | |
3154 | (target-depth (or depth (allout-depth))) | |
3155 | (search-whitespace-regexp nil) | |
3156 | (depth-biased (- target-depth 2)) | |
3157 | (expression (if (<= target-depth 1) | |
3158 | allout-depth-one-regexp | |
3159 | (format allout-depth-specific-regexp | |
3160 | depth-biased depth-biased))) | |
3161 | found | |
3162 | done) | |
3163 | (while (not done) | |
2a1408fd DN |
3164 | (setq found (save-match-data |
3165 | (if backward | |
3166 | (re-search-backward expression nil 'to-limit) | |
3167 | (forward-char 1) | |
3168 | (re-search-forward expression nil 'to-limit)))) | |
d8350998 CY |
3169 | (if (and found (allout-aberrant-container-p)) |
3170 | (setq found nil)) | |
3171 | (setq done (or found (if backward (bobp) (eobp))))) | |
3172 | (if (not found) | |
3173 | (progn (goto-char start-point) | |
3174 | nil) | |
3175 | ;; rationale: if any intervening items were at a lower depth, we | |
60c7bbd2 | 3176 | ;; would now be on the first offspring at the target depth -- ie, |
d8350998 CY |
3177 | ;; the preceeding item (per the search direction) must be at a |
3178 | ;; lesser depth. that's all we need to check. | |
3179 | (if backward (allout-next-heading) (allout-previous-heading)) | |
3180 | (if (< allout-recent-depth target-depth) | |
3181 | ;; return to start and reestablish allout-recent-*: | |
3182 | (progn | |
3183 | (goto-char start-point) | |
3184 | (allout-depth) | |
3185 | nil) | |
3186 | (goto-char found) | |
3187 | ;; locate cursor and set allout-recent-*: | |
3188 | (allout-goto-prefix)))))) | |
fd5359c6 MR |
3189 | ;;;_ > allout-previous-sibling (&optional depth backward) |
3190 | (defun allout-previous-sibling (&optional depth backward) | |
d82979ea | 3191 | "Like `allout-forward-current-level' backwards, respecting invisible topics. |
1977b8f6 | 3192 | |
c567ac01 | 3193 | Optional DEPTH specifies depth to traverse, default current depth. |
1977b8f6 | 3194 | |
c567ac01 | 3195 | Optional BACKWARD reverses direction. |
1977b8f6 | 3196 | |
c567ac01 | 3197 | Return depth if successful, nil otherwise." |
fd5359c6 | 3198 | (allout-next-sibling depth (not backward)) |
1977b8f6 | 3199 | ) |
fd5359c6 MR |
3200 | ;;;_ > allout-snug-back () |
3201 | (defun allout-snug-back () | |
539d7736 | 3202 | "Position cursor at end of previous topic. |
19b84ba3 RS |
3203 | |
3204 | Presumes point is at the start of a topic prefix." | |
c567ac01 RS |
3205 | (if (or (bobp) (eobp)) |
3206 | nil | |
3207 | (forward-char -1)) | |
96b83743 | 3208 | (if (or (bobp) (not (= ?\n (preceding-char)))) |
c567ac01 | 3209 | nil |
96b83743 | 3210 | (forward-char -1)) |
c567ac01 | 3211 | (point)) |
fd5359c6 MR |
3212 | ;;;_ > allout-beginning-of-level () |
3213 | (defun allout-beginning-of-level () | |
c567ac01 | 3214 | "Go back to the first sibling at this level, visible or not." |
fd5359c6 MR |
3215 | (allout-end-of-level 'backward)) |
3216 | ;;;_ > allout-end-of-level (&optional backward) | |
3217 | (defun allout-end-of-level (&optional backward) | |
c567ac01 | 3218 | "Go to the last sibling at this level, visible or not." |
1977b8f6 | 3219 | |
fd5359c6 MR |
3220 | (let ((depth (allout-depth))) |
3221 | (while (allout-previous-sibling depth nil)) | |
d8350998 | 3222 | (prog1 allout-recent-depth |
d82979ea | 3223 | (if (interactive-p) (allout-end-of-prefix))))) |
fd5359c6 MR |
3224 | ;;;_ > allout-next-visible-heading (arg) |
3225 | (defun allout-next-visible-heading (arg) | |
19b84ba3 | 3226 | "Move to the next ARG'th visible heading line, backward if arg is negative. |
c567ac01 | 3227 | |
96b83743 | 3228 | Move to buffer limit in indicated direction if headings are exhausted." |
1977b8f6 | 3229 | |
1977b8f6 | 3230 | (interactive "p") |
0458fa80 EZ |
3231 | (let* ((inhibit-field-text-motion t) |
3232 | (backward (if (< arg 0) (setq arg (* -1 arg)))) | |
c567ac01 RS |
3233 | (step (if backward -1 1)) |
3234 | prev got) | |
3235 | ||
d8350998 CY |
3236 | (while (> arg 0) |
3237 | (while (and | |
3238 | ;; Boundary condition: | |
3239 | (not (if backward (bobp)(eobp))) | |
3240 | ;; Move, skipping over all concealed lines in one fell swoop: | |
3241 | (prog1 (condition-case nil (or (line-move step) t) | |
3242 | (error nil)) | |
3243 | (allout-beginning-of-current-line)) | |
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 CY |
3275 | (prog1 (allout-next-visible-heading (- arg)) |
3276 | (if (interactive-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))) | |
3297 | (if (not (interactive-p)) | |
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 EZ |
3309 | (interactive "p") |
3310 | (if (interactive-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 | |
2265e017 | 3326 | `allout-mode-map'.") |
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) | |
fd5359c6 MR |
3335 | ;;;_ > allout-post-command-business () |
3336 | (defun allout-post-command-business () | |
2265e017 | 3337 | "Outline `post-command-hook' function. |
c567ac01 | 3338 | |
2265e017 | 3339 | - Implement (and clear) `allout-post-goto-bullet', for hot-spot |
c567ac01 RS |
3340 | outline commands. |
3341 | ||
96b83743 | 3342 | - Decrypt topic currently being edited if it was encrypted for a save." |
c567ac01 RS |
3343 | |
3344 | ; Apply any external change func: | |
fd5359c6 | 3345 | (if (not (allout-mode-p)) ; In allout-mode. |
19b84ba3 | 3346 | nil |
d82979ea EZ |
3347 | |
3348 | (if (and (boundp 'allout-after-save-decrypt) | |
3349 | allout-after-save-decrypt) | |
3350 | (allout-after-saves-handler)) | |
3351 | ||
48bd8440 | 3352 | ;; Implement allout-post-goto-bullet, if set: |
fd5359c6 MR |
3353 | (if (and allout-post-goto-bullet |
3354 | (allout-current-bullet-pos)) | |
3355 | (progn (goto-char (allout-current-bullet-pos)) | |
3356 | (setq allout-post-goto-bullet nil))) | |
19b84ba3 | 3357 | )) |
fd5359c6 MR |
3358 | ;;;_ > allout-pre-command-business () |
3359 | (defun allout-pre-command-business () | |
2265e017 | 3360 | "Outline `pre-command-hook' function for outline buffers. |
48bd8440 EZ |
3361 | |
3362 | Among other things, implements special behavior when the cursor is on the | |
3363 | topic bullet character. | |
c567ac01 | 3364 | |
58edceeb JB |
3365 | When the cursor is on the bullet character, self-insert characters are |
3366 | reinterpreted as the corresponding control-character in the | |
3367 | `allout-mode-map'. The `allout-mode' `post-command-hook' insures that | |
3368 | the cursor which has moved as a result of such reinterpretation is | |
3369 | positioned on the bullet character of the destination topic. | |
c567ac01 | 3370 | |
c07583cd | 3371 | The upshot is that you can get easy, single (ie, unmodified) key |
9179616f | 3372 | outline maneuvering operations by positioning the cursor on the bullet |
58edceeb JB |
3373 | char. When in this mode you can use regular cursor-positioning |
3374 | command/keystrokes to relocate the cursor off of a bullet character to | |
3375 | return to regular interpretation of self-insert characters." | |
d82979ea | 3376 | |
fd5359c6 | 3377 | (if (not (allout-mode-p)) |
9179616f | 3378 | nil |
48bd8440 EZ |
3379 | ;; Increment allout-command-counter |
3380 | (setq allout-command-counter (1+ allout-command-counter)) | |
3381 | ;; Do hot-spot navigation. | |
9179616f | 3382 | (if (and (eq this-command 'self-insert-command) |
fd5359c6 | 3383 | (eq (point)(allout-current-bullet-pos))) |
01fc9422 EZ |
3384 | (allout-hotspot-key-handler)))) |
3385 | ;;;_ > allout-hotspot-key-handler () | |
3386 | (defun allout-hotspot-key-handler () | |
3387 | "Catchall handling of key bindings in hot-spots. | |
3388 | ||
3389 | Translates unmodified keystrokes to corresponding allout commands, when | |
3390 | they would qualify if prefixed with the allout-command-prefix, and sets | |
3391 | this-command accordingly. | |
3392 | ||
3393 | Returns the qualifying command, if any, else nil." | |
3394 | (interactive) | |
d8350998 CY |
3395 | (let* ((key-string (if (numberp last-command-char) |
3396 | (char-to-string last-command-char))) | |
3397 | (key-num (cond ((numberp last-command-char) last-command-char) | |
01fc9422 EZ |
3398 | ;; for XEmacs character type: |
3399 | ((and (fboundp 'characterp) | |
3400 | (apply 'characterp (list last-command-char))) | |
3401 | (apply 'char-to-int (list last-command-char))) | |
3402 | (t 0))) | |
d8350998 | 3403 | mapped-binding) |
01fc9422 EZ |
3404 | |
3405 | (if (zerop key-num) | |
3406 | nil | |
3407 | ||
d8350998 CY |
3408 | (if (and |
3409 | ;; exclude control chars and escape: | |
3410 | (<= 33 key-num) | |
3411 | (setq mapped-binding | |
3412 | (or (and (assoc key-string allout-keybindings-list) | |
3413 | ;; translate literal membership on list: | |
3414 | (cadr (assoc key-string allout-keybindings-list))) | |
3415 | ;; translate as a keybinding: | |
2a1408fd | 3416 | (key-binding (vconcat allout-command-prefix |
01fc9422 | 3417 | (char-to-string |
d8350998 | 3418 | (if (and (<= 97 key-num) ; "a" |
01fc9422 EZ |
3419 | (>= 122 key-num)) ; "z" |
3420 | (- key-num 96) key-num))) | |
d8350998 | 3421 | t)))) |
60c7bbd2 | 3422 | ;; Qualified as an allout command -- do hot-spot operation. |
01fc9422 EZ |
3423 | (setq allout-post-goto-bullet t) |
3424 | ;; accept-defaults nil, or else we'll get allout-item-icon-key-handler. | |
3425 | (setq mapped-binding (key-binding (char-to-string key-num)))) | |
3426 | ||
3427 | (while (keymapp mapped-binding) | |
3428 | (setq mapped-binding | |
d8350998 | 3429 | (lookup-key mapped-binding (vector (read-char))))) |
01fc9422 EZ |
3430 | |
3431 | (if mapped-binding | |
5204800f | 3432 | (setq this-command mapped-binding))))) |
01fc9422 | 3433 | |
fd5359c6 MR |
3434 | ;;;_ > allout-find-file-hook () |
3435 | (defun allout-find-file-hook () | |
4034b0e2 | 3436 | "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'. |
fd5359c6 MR |
3437 | |
3438 | See `allout-init' for setup instructions." | |
3439 | (if (and allout-auto-activation | |
3440 | (not (allout-mode-p)) | |
3441 | allout-layout) | |
3442 | (allout-mode t))) | |
c567ac01 RS |
3443 | |
3444 | ;;;_ - Topic Format Assessment | |
fd5359c6 MR |
3445 | ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet) |
3446 | (defun allout-solicit-alternate-bullet (depth &optional current-bullet) | |
1977b8f6 | 3447 | |
19b84ba3 RS |
3448 | "Prompt for and return a bullet char as an alternative to the current one. |
3449 | ||
3450 | Offer one suitable for current depth DEPTH as default." | |
1977b8f6 | 3451 | |
9179616f | 3452 | (let* ((default-bullet (or (and (stringp current-bullet) current-bullet) |
fd5359c6 MR |
3453 | (allout-bullet-for-depth depth))) |
3454 | (sans-escapes (regexp-sans-escapes allout-bullets-string)) | |
9179616f DL |
3455 | choice) |
3456 | (save-excursion | |
fd5359c6 | 3457 | (goto-char (allout-current-bullet-pos)) |
9179616f DL |
3458 | (setq choice (solicit-char-in-string |
3459 | (format "Select bullet: %s ('%s' default): " | |
3460 | sans-escapes | |
d8350998 | 3461 | (substring-no-properties default-bullet)) |
9179616f DL |
3462 | sans-escapes |
3463 | t))) | |
3464 | (message "") | |
1977b8f6 RS |
3465 | (if (string= choice "") default-bullet choice)) |
3466 | ) | |
fd5359c6 MR |
3467 | ;;;_ > allout-distinctive-bullet (bullet) |
3468 | (defun allout-distinctive-bullet (bullet) | |
e126900f | 3469 | "True if BULLET is one of those on `allout-distinctive-bullets-string'." |
fd5359c6 MR |
3470 | (string-match (regexp-quote bullet) allout-distinctive-bullets-string)) |
3471 | ;;;_ > allout-numbered-type-prefix (&optional prefix) | |
3472 | (defun allout-numbered-type-prefix (&optional prefix) | |
c567ac01 | 3473 | "True if current header prefix bullet is numbered bullet." |
fd5359c6 MR |
3474 | (and allout-numbered-bullet |
3475 | (string= allout-numbered-bullet | |
1977b8f6 | 3476 | (if prefix |
fd5359c6 MR |
3477 | (allout-get-prefix-bullet prefix) |
3478 | (allout-get-bullet))))) | |
d82979ea EZ |
3479 | ;;;_ > allout-encrypted-type-prefix (&optional prefix) |
3480 | (defun allout-encrypted-type-prefix (&optional prefix) | |
c07583cd | 3481 | "True if current header prefix bullet is for an encrypted entry (body)." |
d82979ea EZ |
3482 | (and allout-topic-encryption-bullet |
3483 | (string= allout-topic-encryption-bullet | |
3484 | (if prefix | |
3485 | (allout-get-prefix-bullet prefix) | |
3486 | (allout-get-bullet))))) | |
fd5359c6 MR |
3487 | ;;;_ > allout-bullet-for-depth (&optional depth) |
3488 | (defun allout-bullet-for-depth (&optional depth) | |
19b84ba3 | 3489 | "Return outline topic bullet suited to optional DEPTH, or current depth." |
1977b8f6 | 3490 | ;; Find bullet in plain-bullets-string modulo DEPTH. |
fd5359c6 MR |
3491 | (if allout-stylish-prefixes |
3492 | (char-to-string (aref allout-plain-bullets-string | |
1977b8f6 | 3493 | (% (max 0 (- depth 2)) |
fd5359c6 MR |
3494 | allout-plain-bullets-string-len))) |
3495 | allout-primary-bullet) | |
1977b8f6 RS |
3496 | ) |
3497 | ||
c567ac01 | 3498 | ;;;_ - Topic Production |
fd5359c6 MR |
3499 | ;;;_ > allout-make-topic-prefix (&optional prior-bullet |
3500 | (defun allout-make-topic-prefix (&optional prior-bullet | |
1977b8f6 RS |
3501 | new |
3502 | depth | |
3503 | solicit | |
3504 | number-control | |
3505 | index) | |
3506 | ;; Depth null means use current depth, non-null means we're either | |
3507 | ;; opening a new topic after current topic, lower or higher, or we're | |
3508 | ;; changing level of current topic. | |
3509 | ;; Solicit dominates specified bullet-char. | |
c567ac01 | 3510 | ;;;_ . Doc string: |
19b84ba3 | 3511 | "Generate a topic prefix suitable for optional arg DEPTH, or current depth. |
c567ac01 RS |
3512 | |
3513 | All the arguments are optional. | |
3514 | ||
3515 | PRIOR-BULLET indicates the bullet of the prefix being changed, or | |
3516 | nil if none. This bullet may be preserved (other options | |
2265e017 | 3517 | notwithstanding) if it is on the `allout-distinctive-bullets-string', |
c567ac01 RS |
3518 | for instance. |
3519 | ||
3520 | Second arg NEW indicates that a new topic is being opened after the | |
3521 | topic at point, if non-nil. Default bullet for new topics, eg, may | |
3522 | be set (contingent to other args) to numbered bullets if previous | |
3523 | sibling is one. The implication otherwise is that the current topic | |
60c7bbd2 | 3524 | is being adjusted -- shifted or rebulleted -- and we don't consider |
c567ac01 RS |
3525 | bullet or previous sibling. |
3526 | ||
3527 | Third arg DEPTH forces the topic prefix to that depth, regardless of | |
3528 | the current topics' depth. | |
3529 | ||
9179616f DL |
3530 | If SOLICIT is non-nil, then the choice of bullet is solicited from |
3531 | user. If it's a character, then that character is offered as the | |
c07583cd KS |
3532 | default, otherwise the one suited to the context (according to |
3533 | distinction or depth) is offered. (This overrides other options, | |
9179616f DL |
3534 | including, eg, a distinctive PRIOR-BULLET.) If non-nil, then the |
3535 | context-specific bullet is used. | |
c567ac01 | 3536 | |
fd5359c6 | 3537 | Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet' |
c567ac01 RS |
3538 | is non-nil *and* soliciting was not explicitly invoked. Then |
3539 | NUMBER-CONTROL non-nil forces prefix to either numbered or | |
3540 | denumbered format, depending on the value of the sixth arg, INDEX. | |
3541 | ||
3542 | \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...) | |
3543 | ||
3544 | If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then | |
3545 | the prefix of the topic is forced to be numbered. Non-nil | |
3546 | NUMBER-CONTROL and nil INDEX forces non-numbered format on the | |
3547 | bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means | |
3548 | that the index for the numbered prefix will be derived, by counting | |
3549 | siblings back to start of level. If INDEX is a number, then that | |
3550 | number is used as the index for the numbered prefix (allowing, eg, | |
a0776d6b | 3551 | sequential renumbering to not require this function counting back the |
c567ac01 RS |
3552 | index for each successive sibling)." |
3553 | ;;;_ . Code: | |
1977b8f6 RS |
3554 | ;; The options are ordered in likely frequence of use, most common |
3555 | ;; highest, least lowest. Ie, more likely to be doing prefix | |
3556 | ;; adjustments than soliciting, and yet more than numbering. | |
3557 | ;; Current prefix is least dominant, but most likely to be commonly | |
3558 | ;; specified... | |
3559 | ||
3560 | (let* (body | |
3561 | numbering | |
3562 | denumbering | |
fd5359c6 MR |
3563 | (depth (or depth (allout-depth))) |
3564 | (header-lead allout-header-prefix) | |
1977b8f6 RS |
3565 | (bullet-char |
3566 | ||
3567 | ;; Getting value for bullet char is practically the whole job: | |
3568 | ||
3569 | (cond | |
60c7bbd2 | 3570 | ; Simplest situation -- level 1: |
fd5359c6 | 3571 | ((<= depth 1) (setq header-lead "") allout-primary-bullet) |
1977b8f6 | 3572 | ; Simple, too: all asterisks: |
fd5359c6 | 3573 | (allout-old-style-prefixes |
60c7bbd2 | 3574 | ;; Cheat -- make body the whole thing, null out header-lead and |
1977b8f6 RS |
3575 | ;; bullet-char: |
3576 | (setq body (make-string depth | |
fd5359c6 | 3577 | (string-to-char allout-primary-bullet))) |
1977b8f6 RS |
3578 | (setq header-lead "") |
3579 | "") | |
3580 | ||
3581 | ;; (Neither level 1 nor old-style, so we're space padding. | |
3582 | ;; Sneak it in the condition of the next case, whatever it is.) | |
3583 | ||
3584 | ;; Solicitation overrides numbering and other cases: | |
3585 | ((progn (setq body (make-string (- depth 2) ?\ )) | |
3586 | ;; The actual condition: | |
3587 | solicit) | |
fd5359c6 | 3588 | (let* ((got (allout-solicit-alternate-bullet depth solicit))) |
1977b8f6 | 3589 | ;; Gotta check whether we're numbering and got a numbered bullet: |
fd5359c6 | 3590 | (setq numbering (and allout-numbered-bullet |
1977b8f6 | 3591 | (not (and number-control (not index))) |
fd5359c6 | 3592 | (string= got allout-numbered-bullet))) |
1977b8f6 RS |
3593 | ;; Now return what we got, regardless: |
3594 | got)) | |
3595 | ||
3596 | ;; Numbering invoked through args: | |
fd5359c6 | 3597 | ((and allout-numbered-bullet number-control) |
1977b8f6 | 3598 | (if (setq numbering (not (setq denumbering (not index)))) |
fd5359c6 | 3599 | allout-numbered-bullet |
19b84ba3 | 3600 | (if (and prior-bullet |
fd5359c6 | 3601 | (not (string= allout-numbered-bullet |
19b84ba3 RS |
3602 | prior-bullet))) |
3603 | prior-bullet | |
fd5359c6 | 3604 | (allout-bullet-for-depth depth)))) |
1977b8f6 RS |
3605 | |
3606 | ;;; Neither soliciting nor controlled numbering ;;; | |
3607 | ;;; (may be controlled denumbering, tho) ;;; | |
3608 | ||
3609 | ;; Check wrt previous sibling: | |
3610 | ((and new ; only check for new prefixes | |
fd5359c6 MR |
3611 | (<= depth (allout-depth)) |
3612 | allout-numbered-bullet ; ... & numbering enabled | |
1977b8f6 RS |
3613 | (not denumbering) |
3614 | (let ((sibling-bullet | |
3615 | (save-excursion | |
3616 | ;; Locate correct sibling: | |
fd5359c6 MR |
3617 | (or (>= depth (allout-depth)) |
3618 | (allout-ascend-to-depth depth)) | |
3619 | (allout-get-bullet)))) | |
1977b8f6 | 3620 | (if (and sibling-bullet |
fd5359c6 | 3621 | (string= allout-numbered-bullet sibling-bullet)) |
1977b8f6 RS |
3622 | (setq numbering sibling-bullet))))) |
3623 | ||
3624 | ;; Distinctive prior bullet? | |
3625 | ((and prior-bullet | |
fd5359c6 | 3626 | (allout-distinctive-bullet prior-bullet) |
1977b8f6 | 3627 | ;; Either non-numbered: |
fd5359c6 MR |
3628 | (or (not (and allout-numbered-bullet |
3629 | (string= prior-bullet allout-numbered-bullet))) | |
1977b8f6 RS |
3630 | ;; or numbered, and not denumbering: |
3631 | (setq numbering (not denumbering))) | |
3632 | ;; Here 'tis: | |
3633 | prior-bullet)) | |
3634 | ||
3635 | ;; Else, standard bullet per depth: | |
fd5359c6 | 3636 | ((allout-bullet-for-depth depth))))) |
1977b8f6 RS |
3637 | |
3638 | (concat header-lead | |
3639 | body | |
3640 | bullet-char | |
3641 | (if numbering | |
3642 | (format "%d" (cond ((and index (numberp index)) index) | |
fd5359c6 MR |
3643 | (new (1+ (allout-sibling-index depth))) |
3644 | ((allout-sibling-index)))))) | |
1977b8f6 RS |
3645 | ) |
3646 | ) | |
96b83743 EZ |
3647 | ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet) |
3648 | (defun allout-open-topic (relative-depth &optional before offer-recent-bullet) | |
d82979ea | 3649 | "Open a new topic at depth DEPTH. |
19b84ba3 RS |
3650 | |
3651 | New topic is situated after current one, unless optional flag BEFORE | |
60c7bbd2 RS |
3652 | is non-nil, or unless current line is completely empty -- lacking even |
3653 | whitespace -- in which case open is done on the current line. | |
96b83743 EZ |
3654 | |
3655 | When adding an offspring, it will be added immediately after the parent if | |
3656 | the other offspring are exposed, or after the last child if the offspring | |
c07583cd | 3657 | are hidden. (The intervening offspring will be exposed in the latter |
96b83743 | 3658 | case.) |
c567ac01 | 3659 | |
96b83743 | 3660 | If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling. |
9179616f | 3661 | |
c567ac01 RS |
3662 | Nuances: |
3663 | ||
3664 | - Creation of new topics is with respect to the visible topic | |
3665 | containing the cursor, regardless of intervening concealed ones. | |
3666 | ||
3667 | - New headers are generally created after/before the body of a | |
3668 | topic. However, they are created right at cursor location if the | |
3669 | cursor is on a blank line, even if that breaks the current topic | |
3670 | body. This is intentional, to provide a simple means for | |
3671 | deliberately dividing topic bodies. | |
3672 | ||
3673 | - Double spacing of topic lists is preserved. Also, the first | |
3674 | level two topic is created double-spaced (and so would be | |
3675 | subsequent siblings, if that's left intact). Otherwise, | |
3676 | single-spacing is used. | |
3677 | ||
3678 | - Creation of sibling or nested topics is with respect to the topic | |
3679 | you're starting from, even when creating backwards. This way you | |
3680 | can easily create a sibling in front of the current topic without | |
a0776d6b | 3681 | having to go to its preceding sibling, and then open forward |
c567ac01 | 3682 | from there." |
1977b8f6 | 3683 | |
96b83743 | 3684 | (allout-beginning-of-current-line) |
2a1408fd DN |
3685 | (save-match-data |
3686 | (let* ((inhibit-field-text-motion t) | |
3687 | (depth (+ (allout-current-depth) relative-depth)) | |
3688 | (opening-on-blank (if (looking-at "^\$") | |
3689 | (not (setq before nil)))) | |
3690 | ;; bunch o vars set while computing ref-topic | |
3691 | opening-numbered | |
3692 | ref-depth | |
3693 | ref-bullet | |
3694 | (ref-topic (save-excursion | |
3695 | (cond ((< relative-depth 0) | |
3696 | (allout-ascend-to-depth depth)) | |
3697 | ((>= relative-depth 1) nil) | |
3698 | (t (allout-back-to-current-heading))) | |
3699 | (setq ref-depth allout-recent-depth) | |
3700 | (setq ref-bullet | |
3701 | (if (> allout-recent-prefix-end 1) | |
3702 | (allout-recent-bullet) | |
3703 | "")) | |
3704 | (setq opening-numbered | |
3705 | (save-excursion | |
3706 | (and allout-numbered-bullet | |
3707 | (or (<= relative-depth 0) | |
3708 | (allout-descend-to-depth depth)) | |
3709 | (if (allout-numbered-type-prefix) | |
3710 | allout-numbered-bullet)))) | |
3711 | (point))) | |
3712 | dbl-space | |
3713 | doing-beginning | |
3714 | start end) | |
3715 | ||
3716 | (if (not opening-on-blank) | |
1977b8f6 | 3717 | ; Positioning and vertical |
60c7bbd2 | 3718 | ; padding -- only if not |
1977b8f6 | 3719 | ; opening-on-blank: |
2a1408fd DN |
3720 | (progn |
3721 | (goto-char ref-topic) | |
3722 | (setq dbl-space ; Determine double space action: | |
3723 | (or (and (<= relative-depth 0) ; not descending; | |
3724 | (save-excursion | |
3725 | ;; at b-o-b or preceded by a blank line? | |
3726 | (or (> 0 (forward-line -1)) | |
3727 | (looking-at "^\\s-*$") | |
3728 | (bobp))) | |
3729 | (save-excursion | |
3730 | ;; succeeded by a blank line? | |
3731 | (allout-end-of-current-subtree) | |
3732 | (looking-at "\n\n"))) | |
3733 | (and (= ref-depth 1) | |
3734 | (or before | |
3735 | (= depth 1) | |
3736 | (save-excursion | |
3737 | ;; Don't already have following | |
3738 | ;; vertical padding: | |
3739 | (not (allout-pre-next-prefix))))))) | |
3740 | ||
3741 | ;; Position to prior heading, if inserting backwards, and not | |
3742 | ;; going outwards: | |
3743 | (if (and before (>= relative-depth 0)) | |
3744 | (progn (allout-back-to-current-heading) | |
3745 | (setq doing-beginning (bobp)) | |
3746 | (if (not (bobp)) | |
3747 | (allout-previous-heading))) | |
3748 | (if (and before (bobp)) | |
3749 | (open-line 1))) | |
3750 | ||
3751 | (if (<= relative-depth 0) | |
3752 | ;; Not going inwards, don't snug up: | |
3753 | (if doing-beginning | |
3754 | (if (not dbl-space) | |
3755 | (open-line 1) | |
3756 | (open-line 2)) | |
3757 | (if before | |
3758 | (progn (end-of-line) | |
3759 | (allout-pre-next-prefix) | |
3760 | (while (and (= ?\n (following-char)) | |
3761 | (save-excursion | |
3762 | (forward-char 1) | |
3763 | (allout-hidden-p))) | |
3764 | (forward-char 1)) | |
3765 | (if (not (looking-at "^$")) | |
3766 | (open-line 1))) | |
3767 | (allout-end-of-current-subtree) | |
3768 | (if (looking-at "\n\n") (forward-char 1)))) | |
8dd59f01 | 3769 | ;; Going inwards -- double-space if first offspring is |
2a1408fd DN |
3770 | ;; double-spaced, otherwise snug up. |
3771 | (allout-end-of-entry) | |
3772 | (if (eobp) | |
3773 | (newline 1) | |
3774 | (line-move 1)) | |
3775 | (allout-beginning-of-current-line) | |
3776 | (backward-char 1) | |
3777 | (if (bolp) | |
3778 | ;; Blank lines between current header body and next | |
8dd59f01 | 3779 | ;; header -- get to last substantive (non-white-space) |
2a1408fd DN |
3780 | ;; line in body: |
3781 | (progn (setq dbl-space t) | |
3782 | (re-search-backward "[^ \t\n]" nil t))) | |
3783 | (if (looking-at "\n\n") | |
3784 | (setq dbl-space t)) | |
3785 | (if (save-excursion | |
3786 | (allout-next-heading) | |
3787 | (when (> allout-recent-depth ref-depth) | |
3788 | ;; This is an offspring. | |
3789 | (forward-line -1) | |
3790 | (looking-at "^\\s-*$"))) | |
3791 | (progn (forward-line 1) | |
96b83743 | 3792 | (open-line 1) |
2a1408fd DN |
3793 | (forward-line 1))) |
3794 | (allout-end-of-current-line)) | |
3795 | ||
3796 | ;;(if doing-beginning (goto-char doing-beginning)) | |
3797 | (if (not (bobp)) | |
3798 | ;; We insert a newline char rather than using open-line to | |
3799 | ;; avoid rear-stickiness inheritence of read-only property. | |
3800 | (progn (if (and (not (> depth ref-depth)) | |
3801 | (not before)) | |
3802 | (open-line 1) | |
3803 | (if (and (not dbl-space) (> depth ref-depth)) | |
3804 | (newline 1) | |
3805 | (if dbl-space | |
3806 | (open-line 1) | |
3807 | (if (not before) | |
3808 | (newline 1))))) | |
3809 | (if (and dbl-space (not (> relative-depth 0))) | |
3810 | (newline 1)) | |
3811 | (if (and (not (eobp)) | |
3812 | (or (not (bolp)) | |
3813 | (and (not (bobp)) | |
3814 | ;; bolp doesnt detect concealed | |
3815 | ;; trailing newlines, compensate: | |
3816 | (save-excursion | |
3817 | (forward-char -1) | |
3818 | (allout-hidden-p))))) | |
3819 | (forward-char 1)))) | |
3820 | )) | |
3821 | (setq start (point)) | |
3822 | (insert (concat (allout-make-topic-prefix opening-numbered t depth) | |
3823 | " ")) | |
3824 | (setq end (1+ (point))) | |
3825 | ||
3826 | (allout-rebullet-heading (and offer-recent-bullet ref-bullet) | |
3827 | depth nil nil t) | |
3828 | (if (> relative-depth 0) | |
3829 | (save-excursion (goto-char ref-topic) | |
3830 | (allout-show-children))) | |
3831 | (end-of-line) | |
48bd8440 | 3832 | |
2a1408fd DN |
3833 | (run-hook-with-args 'allout-structure-added-hook start end) |
3834 | ) | |
1977b8f6 RS |
3835 | ) |
3836 | ) | |
fd5359c6 MR |
3837 | ;;;_ > allout-open-subtopic (arg) |
3838 | (defun allout-open-subtopic (arg) | |
c567ac01 RS |
3839 | "Open new topic header at deeper level than the current one. |
3840 | ||
3841 | Negative universal arg means to open deeper, but place the new topic | |
3842 | prior to the current one." | |
1977b8f6 | 3843 | (interactive "p") |
d82979ea | 3844 | (allout-open-topic 1 (> 0 arg) (< 1 arg))) |
fd5359c6 MR |
3845 | ;;;_ > allout-open-sibtopic (arg) |
3846 | (defun allout-open-sibtopic (arg) | |
19b84ba3 RS |
3847 | "Open new topic header at same level as the current one. |
3848 | ||
9179616f DL |
3849 | Positive universal arg means to use the bullet of the prior sibling. |
3850 | ||
19b84ba3 | 3851 | Negative universal arg means to place the new topic prior to the current |
c567ac01 | 3852 | one." |
1977b8f6 | 3853 | (interactive "p") |
d82979ea | 3854 | (allout-open-topic 0 (> 0 arg) (not (= 1 arg)))) |
fd5359c6 MR |
3855 | ;;;_ > allout-open-supertopic (arg) |
3856 | (defun allout-open-supertopic (arg) | |
c567ac01 | 3857 | "Open new topic header at shallower level than the current one. |
19b84ba3 | 3858 | |
c567ac01 RS |
3859 | Negative universal arg means to open shallower, but place the new |
3860 | topic prior to the current one." | |
1977b8f6 RS |
3861 | |
3862 | (interactive "p") | |
d82979ea | 3863 | (allout-open-topic -1 (> 0 arg) (< 1 arg))) |
c567ac01 RS |
3864 | |
3865 | ;;;_ - Outline Alteration | |
3866 | ;;;_ : Topic Modification | |
fd5359c6 MR |
3867 | ;;;_ = allout-former-auto-filler |
3868 | (defvar allout-former-auto-filler nil | |
2265e017 | 3869 | "Name of modal fill function being wrapped by `allout-auto-fill'.") |
fd5359c6 MR |
3870 | ;;;_ > allout-auto-fill () |
3871 | (defun allout-auto-fill () | |
aad94676 | 3872 | "`allout-mode' autofill function. |
19b84ba3 RS |
3873 | |
3874 | Maintains outline hanging topic indentation if | |
fd5359c6 | 3875 | `allout-use-hanging-indents' is set." |
01fc9422 EZ |
3876 | |
3877 | (when (not allout-inhibit-auto-fill) | |
3878 | (let ((fill-prefix (if allout-use-hanging-indents | |
3879 | ;; Check for topic header indentation: | |
2a1408fd DN |
3880 | (save-match-data |
3881 | (save-excursion | |
3882 | (beginning-of-line) | |
3883 | (if (looking-at allout-regexp) | |
3884 | ;; ... construct indentation to account for | |
3885 | ;; length of topic prefix: | |
3886 | (make-string (progn (allout-end-of-prefix) | |
3887 | (current-column)) | |
3888 | ?\ )))))) | |
01fc9422 EZ |
3889 | (use-auto-fill-function (or allout-outside-normal-auto-fill-function |
3890 | auto-fill-function | |
3891 | 'do-auto-fill))) | |
3892 | (if (or allout-former-auto-filler allout-use-hanging-indents) | |
3893 | (funcall use-auto-fill-function))))) | |
fd5359c6 MR |
3894 | ;;;_ > allout-reindent-body (old-depth new-depth &optional number) |
3895 | (defun allout-reindent-body (old-depth new-depth &optional number) | |
e126900f | 3896 | "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH. |
c567ac01 RS |
3897 | |
3898 | Optional arg NUMBER indicates numbering is being added, and it must | |
a0776d6b | 3899 | be accommodated. |
c567ac01 RS |
3900 | |
3901 | Note that refill of indented paragraphs is not done." | |
1977b8f6 RS |
3902 | |
3903 | (save-excursion | |
fd5359c6 | 3904 | (allout-end-of-prefix) |
c567ac01 RS |
3905 | (let* ((new-margin (current-column)) |
3906 | excess old-indent-begin old-indent-end | |
c567ac01 RS |
3907 | ;; We want the column where the header-prefix text started |
3908 | ;; *before* the prefix was changed, so we infer it relative | |
3909 | ;; to the new margin and the shift in depth: | |
3910 | (old-margin (+ old-depth (- new-margin new-depth)))) | |
353e2ef2 | 3911 | |
c567ac01 | 3912 | ;; Process lines up to (but excluding) next topic header: |
fd5359c6 | 3913 | (allout-unprotected |
c567ac01 RS |
3914 | (save-match-data |
3915 | (while | |
96b83743 | 3916 | (and (re-search-forward "\n\\(\\s-*\\)" |
c567ac01 RS |
3917 | nil |
3918 | t) | |
3919 | ;; Register the indent data, before we reset the | |
353e2ef2 | 3920 | ;; match data with a subsequent `looking-at': |
c567ac01 RS |
3921 | (setq old-indent-begin (match-beginning 1) |
3922 | old-indent-end (match-end 1)) | |
fd5359c6 | 3923 | (not (looking-at allout-regexp))) |
d82979ea EZ |
3924 | (if (> 0 (setq excess (- (- old-indent-end old-indent-begin) |
3925 | old-margin))) | |
60c7bbd2 | 3926 | ;; Text starts left of old margin -- don't adjust: |
c567ac01 | 3927 | nil |
ea18b2b1 | 3928 | ;; Text was hanging at or right of old left margin -- |
c567ac01 RS |
3929 | ;; reindent it, preserving its existing indentation |
3930 | ;; beyond the old margin: | |
3931 | (delete-region old-indent-begin old-indent-end) | |
d82979ea | 3932 | (indent-to (+ new-margin excess (current-column)))))))))) |
fd5359c6 MR |
3933 | ;;;_ > allout-rebullet-current-heading (arg) |
3934 | (defun allout-rebullet-current-heading (arg) | |
9179616f DL |
3935 | "Solicit new bullet for current visible heading." |
3936 | (interactive "p") | |
3937 | (let ((initial-col (current-column)) | |
fd5359c6 | 3938 | (on-bullet (eq (point)(allout-current-bullet-pos))) |
d8350998 | 3939 | from to |
9179616f DL |
3940 | (backwards (if (< arg 0) |
3941 | (setq arg (* arg -1))))) | |
3942 | (while (> arg 0) | |
fd5359c6 MR |
3943 | (save-excursion (allout-back-to-current-heading) |
3944 | (allout-end-of-prefix) | |
d8350998 CY |
3945 | (setq from allout-recent-prefix-beginning |
3946 | to allout-recent-prefix-end) | |
fd5359c6 | 3947 | (allout-rebullet-heading t ;;; solicit |
9179616f DL |
3948 | nil ;;; depth |
3949 | nil ;;; number-control | |
3950 | nil ;;; index | |
d8350998 CY |
3951 | t) ;;; do-successors |
3952 | (run-hook-with-args 'allout-exposure-change-hook | |
3953 | from to t)) | |
9179616f DL |
3954 | (setq arg (1- arg)) |
3955 | (if (<= arg 0) | |
3956 | nil | |
3957 | (setq initial-col nil) ; Override positioning back to init col | |
3958 | (if (not backwards) | |
fd5359c6 | 3959 | (allout-next-visible-heading 1) |
d8350998 | 3960 | (allout-goto-prefix-doublechecked) |
fd5359c6 | 3961 | (allout-next-visible-heading -1)))) |
9179616f | 3962 | (message "Done.") |
fd5359c6 | 3963 | (cond (on-bullet (goto-char (allout-current-bullet-pos))) |
9179616f | 3964 | (initial-col (move-to-column initial-col))))) |
fd5359c6 MR |
3965 | ;;;_ > allout-rebullet-heading (&optional solicit ...) |
3966 | (defun allout-rebullet-heading (&optional solicit | |
1977b8f6 RS |
3967 | new-depth |
3968 | number-control | |
3969 | index | |
3970 | do-successors) | |
3971 | ||
c567ac01 | 3972 | "Adjust bullet of current topic prefix. |
1977b8f6 | 3973 | |
d82979ea EZ |
3974 | All args are optional. |
3975 | ||
9179616f DL |
3976 | If SOLICIT is non-nil, then the choice of bullet is solicited from |
3977 | user. If it's a character, then that character is offered as the | |
c07583cd | 3978 | default, otherwise the one suited to the context (according to |
9179616f DL |
3979 | distinction or depth) is offered. If non-nil, then the |
3980 | context-specific bullet is just used. | |
1977b8f6 | 3981 | |
d82979ea | 3982 | Second arg DEPTH forces the topic prefix to that depth, regardless |
9179616f | 3983 | of the topic's current depth. |
1977b8f6 | 3984 | |
c567ac01 | 3985 | Third arg NUMBER-CONTROL can force the prefix to or away from |
fd5359c6 | 3986 | numbered form. It has effect only if `allout-numbered-bullet' is |
c567ac01 RS |
3987 | non-nil and soliciting was not explicitly invoked (via first arg). |
3988 | Its effect, numbering or denumbering, then depends on the setting | |
75bcb912 | 3989 | of the fourth arg, INDEX. |
1977b8f6 | 3990 | |
75bcb912 | 3991 | If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the |
c567ac01 RS |
3992 | prefix of the topic is forced to be non-numbered. Null index and |
3993 | non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and | |
3994 | non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil | |
3995 | INDEX is a number, then that number is used for the numbered | |
3996 | prefix. Non-nil and non-number means that the index for the | |
d82979ea | 3997 | numbered prefix will be derived by allout-make-topic-prefix. |
1977b8f6 | 3998 | |
c567ac01 RS |
3999 | Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding |
4000 | siblings. | |
1977b8f6 | 4001 | |
fd5359c6 MR |
4002 | Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes', |
4003 | and `allout-numbered-bullet', which all affect the behavior of | |
c567ac01 | 4004 | this function." |
1977b8f6 | 4005 | |
fd5359c6 | 4006 | (let* ((current-depth (allout-depth)) |
1977b8f6 | 4007 | (new-depth (or new-depth current-depth)) |
fd5359c6 MR |
4008 | (mb allout-recent-prefix-beginning) |
4009 | (me allout-recent-prefix-end) | |
d8350998 | 4010 | (current-bullet (buffer-substring-no-properties (- me 1) me)) |
ede4ac6a | 4011 | (has-annotation (get-text-property mb 'allout-was-hidden)) |
fd5359c6 | 4012 | (new-prefix (allout-make-topic-prefix current-bullet |
1977b8f6 RS |
4013 | nil |
4014 | new-depth | |
4015 | solicit | |
4016 | number-control | |
4017 | index))) | |
4018 | ||
c567ac01 | 4019 | ;; Is new one is identical to old? |
1977b8f6 RS |
4020 | (if (and (= current-depth new-depth) |
4021 | (string= current-bullet | |
4022 | (substring new-prefix (1- (length new-prefix))))) | |
c567ac01 | 4023 | ;; Nothing to do: |
1977b8f6 RS |
4024 | t |
4025 | ||
4026 | ;; New prefix probably different from old: | |
c567ac01 | 4027 | ; get rid of old one: |
fd5359c6 | 4028 | (allout-unprotected (delete-region mb me)) |
1977b8f6 | 4029 | (goto-char mb) |
c567ac01 RS |
4030 | ; Dispense with number if |
4031 | ; numbered-bullet prefix: | |
2a1408fd DN |
4032 | (save-match-data |
4033 | (if (and allout-numbered-bullet | |
4034 | (string= allout-numbered-bullet current-bullet) | |
4035 | (looking-at "[0-9]+")) | |
4036 | (allout-unprotected | |
4037 | (delete-region (match-beginning 0)(match-end 0))))) | |
1977b8f6 | 4038 | |
ede4ac6a KS |
4039 | ;; convey 'allout-was-hidden annotation, if original had it: |
4040 | (if has-annotation | |
4041 | (put-text-property 0 (length new-prefix) 'allout-was-hidden t | |
4042 | new-prefix)) | |
4043 | ||
c567ac01 | 4044 | ; Put in new prefix: |
fd5359c6 | 4045 | (allout-unprotected (insert new-prefix)) |
1977b8f6 | 4046 | |
d82979ea | 4047 | ;; Reindent the body if elected, margin changed, and not encrypted body: |
fd5359c6 | 4048 | (if (and allout-reindent-bodies |
d82979ea EZ |
4049 | (not (= new-depth current-depth)) |
4050 | (not (allout-encrypted-topic-p))) | |
fd5359c6 | 4051 | (allout-reindent-body current-depth new-depth)) |
1977b8f6 | 4052 | |
c567ac01 RS |
4053 | ;; Recursively rectify successive siblings of orig topic if |
4054 | ;; caller elected for it: | |
4055 | (if do-successors | |
4056 | (save-excursion | |
fd5359c6 | 4057 | (while (allout-next-sibling new-depth nil) |
c567ac01 RS |
4058 | (setq index |
4059 | (cond ((numberp index) (1+ index)) | |
fd5359c6 MR |
4060 | ((not number-control) (allout-sibling-index)))) |
4061 | (if (allout-numbered-type-prefix) | |
4062 | (allout-rebullet-heading nil ;;; solicit | |
c567ac01 RS |
4063 | new-depth ;;; new-depth |
4064 | number-control;;; number-control | |
4065 | index ;;; index | |
4066 | nil))))) ;;;(dont!)do-successors | |
4067 | ) ; (if (and (= current-depth new-depth)...)) | |
fd5359c6 | 4068 | ) ; let* ((current-depth (allout-depth))...) |
c567ac01 | 4069 | ) ; defun |
fd5359c6 | 4070 | ;;;_ > allout-rebullet-topic (arg) |
d8350998 | 4071 | (defun allout-rebullet-topic (arg &optional sans-offspring) |
d82979ea | 4072 | "Rebullet the visible topic containing point and all contained subtopics. |
19b84ba3 | 4073 | |
c567ac01 | 4074 | Descends into invisible as well as visible topics, however. |
1977b8f6 | 4075 | |
75bcb912 | 4076 | When optional SANS-OFFSPRING is non-nil, subtopics are not |
c07583cd | 4077 | shifted. (Shifting a topic outwards without shifting its |
d8350998 CY |
4078 | offspring is disallowed, since this would create a \"containment |
4079 | discontinuity\", where the depth difference between a topic and | |
4080 | its immediate offspring is greater than one.) | |
4081 | ||
c567ac01 | 4082 | With repeat count, shift topic depth by that amount." |
1977b8f6 | 4083 | (interactive "P") |
96b83743 | 4084 | (let ((start-col (current-column))) |
1977b8f6 RS |
4085 | (save-excursion |
4086 | ;; Normalize arg: | |
4087 | (cond ((null arg) (setq arg 0)) | |
4088 | ((listp arg) (setq arg (car arg)))) | |
4089 | ;; Fill the user in, in case we're shifting a big topic: | |
4090 | (if (not (zerop arg)) (message "Shifting...")) | |
fd5359c6 | 4091 | (allout-back-to-current-heading) |
d8350998 | 4092 | (if (<= (+ allout-recent-depth arg) 0) |
1977b8f6 | 4093 | (error "Attempt to shift topic below level 1")) |
d8350998 | 4094 | (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring) |
1977b8f6 | 4095 | (if (not (zerop arg)) (message "Shifting... done."))) |
c567ac01 | 4096 | (move-to-column (max 0 (+ start-col arg))))) |
d8350998 | 4097 | ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...) |
fd5359c6 | 4098 | (defun allout-rebullet-topic-grunt (&optional relative-depth |
1977b8f6 RS |
4099 | starting-depth |
4100 | starting-point | |
4101 | index | |
d8350998 CY |
4102 | do-successors |
4103 | sans-offspring) | |
d82979ea EZ |
4104 | "Like `allout-rebullet-topic', but on nearest containing topic |
4105 | \(visible or not). | |
1977b8f6 | 4106 | |
d82979ea | 4107 | See `allout-rebullet-heading' for rebulleting behavior. |
1977b8f6 | 4108 | |
d82979ea | 4109 | All arguments are optional. |
1977b8f6 | 4110 | |
d82979ea EZ |
4111 | First arg RELATIVE-DEPTH means to shift the depth of the entire |
4112 | topic that amount. | |
e126900f | 4113 | |
d8350998 CY |
4114 | Several subsequent args are for internal recursive use by the function |
4115 | itself: STARTING-DEPTH, STARTING-POINT, and INDEX. | |
4116 | ||
4117 | Finally, if optional SANS-OFFSPRING is non-nil then the offspring | |
c07583cd | 4118 | are not shifted. (Shifting a topic outwards without shifting |
d8350998 CY |
4119 | its offspring is disallowed, since this would create a |
4120 | \"containment discontinuity\", where the depth difference between | |
75bcb912 | 4121 | a topic and its immediate offspring is greater than one.)" |
d8350998 CY |
4122 | |
4123 | ;; XXX the recursion here is peculiar, and in general the routine may | |
4124 | ;; need simplification with refactoring. | |
4125 | ||
4126 | (if (and sans-offspring | |
4127 | relative-depth | |
4128 | (< relative-depth 0)) | |
4129 | (error (concat "Attempt to shift topic outwards without offspring," | |
4130 | " would cause containment discontinuity."))) | |
1977b8f6 RS |
4131 | |
4132 | (let* ((relative-depth (or relative-depth 0)) | |
fd5359c6 | 4133 | (new-depth (allout-depth)) |
1977b8f6 RS |
4134 | (starting-depth (or starting-depth new-depth)) |
4135 | (on-starting-call (null starting-point)) | |
4136 | (index (or index | |
4137 | ;; Leave index null on starting call, so rebullet-heading | |
4138 | ;; calculates it at what might be new depth: | |
4139 | (and (or (zerop relative-depth) | |
4140 | (not on-starting-call)) | |
fd5359c6 | 4141 | (allout-sibling-index)))) |
d8350998 | 4142 | (starting-index index) |
1977b8f6 | 4143 | (moving-outwards (< 0 relative-depth)) |
d8350998 CY |
4144 | (starting-point (or starting-point (point))) |
4145 | (local-point (point))) | |
1977b8f6 RS |
4146 | |
4147 | ;; Sanity check for excessive promotion done only on starting call: | |
4148 | (and on-starting-call | |
4149 | moving-outwards | |
4150 | (> 0 (+ starting-depth relative-depth)) | |
d8350998 | 4151 | (error "Attempt to shift topic out beyond level 1")) |
1977b8f6 RS |
4152 | |
4153 | (cond ((= starting-depth new-depth) | |
d8350998 CY |
4154 | ;; We're at depth to work on this one. |
4155 | ||
4156 | ;; When shifting out we work on the children before working on | |
4157 | ;; the parent to avoid interim `allout-aberrant-container-p' | |
4158 | ;; aberrancy, and vice-versa when shifting in: | |
4159 | (if (>= relative-depth 0) | |
4160 | (allout-rebullet-heading nil | |
4161 | (+ starting-depth relative-depth) | |
4162 | nil ;;; number | |
4163 | index | |
4164 | nil)) ;;; do-successors | |
4165 | (when (not sans-offspring) | |
4166 | ;; ... and work on subsequent ones which are at greater depth: | |
4167 | (setq index 0) | |
4168 | (allout-next-heading) | |
4169 | (while (and (not (eobp)) | |
4170 | (< starting-depth (allout-depth))) | |
4171 | (setq index (1+ index)) | |
4172 | (allout-rebullet-topic-grunt relative-depth | |
4173 | (1+ starting-depth) | |
4174 | starting-point | |
4175 | index))) | |
4176 | (when (< relative-depth 0) | |
4177 | (save-excursion | |
4178 | (goto-char local-point) | |
4179 | (allout-rebullet-heading nil ;;; solicit | |
4180 | (+ starting-depth relative-depth) | |
4181 | nil ;;; number | |
4182 | starting-index | |
4183 | nil)))) ;;; do-successors | |
1977b8f6 RS |
4184 | |
4185 | ((< starting-depth new-depth) | |
60c7bbd2 | 4186 | ;; Rare case -- subtopic more than one level deeper than parent. |
1977b8f6 | 4187 | ;; Treat this one at an even deeper level: |
d8350998 CY |
4188 | (allout-rebullet-topic-grunt relative-depth |
4189 | new-depth | |
4190 | starting-point | |
4191 | index | |
4192 | sans-offspring))) | |
1977b8f6 RS |
4193 | |
4194 | (if on-starting-call | |
4195 | (progn | |
4196 | ;; Rectify numbering of former siblings of the adjusted topic, | |
4197 | ;; if topic has changed depth | |
4198 | (if (or do-successors | |
4199 | (and (not (zerop relative-depth)) | |
d8350998 CY |
4200 | (or (= allout-recent-depth starting-depth) |
4201 | (= allout-recent-depth (+ starting-depth | |
1977b8f6 | 4202 | relative-depth))))) |
fd5359c6 | 4203 | (allout-rebullet-heading nil nil nil nil t)) |
1977b8f6 RS |
4204 | ;; Now rectify numbering of new siblings of the adjusted topic, |
4205 | ;; if depth has been changed: | |
4206 | (progn (goto-char starting-point) | |
4207 | (if (not (zerop relative-depth)) | |
fd5359c6 | 4208 | (allout-rebullet-heading nil nil nil nil t))))) |
1977b8f6 RS |
4209 | ) |
4210 | ) | |
fd5359c6 MR |
4211 | ;;;_ > allout-renumber-to-depth (&optional depth) |
4212 | (defun allout-renumber-to-depth (&optional depth) | |
19b84ba3 RS |
4213 | "Renumber siblings at current depth. |
4214 | ||
4215 | Affects superior topics if optional arg DEPTH is less than current depth. | |
c567ac01 RS |
4216 | |
4217 | Returns final depth." | |
4218 | ||
4219 | ;; Proceed by level, processing subsequent siblings on each, | |
4220 | ;; ascending until we get shallower than the start depth: | |
4221 | ||
fd5359c6 | 4222 | (let ((ascender (allout-depth)) |
9179616f | 4223 | was-eobp) |
c567ac01 | 4224 | (while (and (not (eobp)) |
fd5359c6 | 4225 | (allout-depth) |
d8350998 | 4226 | (>= allout-recent-depth depth) |
c567ac01 RS |
4227 | (>= ascender depth)) |
4228 | ; Skip over all topics at | |
4229 | ; lesser depths, which can not | |
4230 | ; have been disturbed: | |
9179616f | 4231 | (while (and (not (setq was-eobp (eobp))) |
d8350998 | 4232 | (> allout-recent-depth ascender)) |
fd5359c6 | 4233 | (allout-next-heading)) |
c567ac01 | 4234 | ; Prime ascender for ascension: |
d8350998 CY |
4235 | (setq ascender (1- allout-recent-depth)) |
4236 | (if (>= allout-recent-depth depth) | |
fd5359c6 | 4237 | (allout-rebullet-heading nil ;;; solicit |
c567ac01 RS |
4238 | nil ;;; depth |
4239 | nil ;;; number-control | |
4240 | nil ;;; index | |
9179616f DL |
4241 | t)) ;;; do-successors |
4242 | (if was-eobp (goto-char (point-max))))) | |
d8350998 | 4243 | allout-recent-depth) |
fd5359c6 MR |
4244 | ;;;_ > allout-number-siblings (&optional denumber) |
4245 | (defun allout-number-siblings (&optional denumber) | |
c567ac01 | 4246 | "Assign numbered topic prefix to this topic and its siblings. |
1977b8f6 | 4247 | |
60c7bbd2 | 4248 | With universal argument, denumber -- assign default bullet to this |
c567ac01 | 4249 | topic and its siblings. |
1977b8f6 | 4250 | |
c567ac01 RS |
4251 | With repeated universal argument (`^U^U'), solicit bullet for each |
4252 | rebulleting each topic at this level." | |
1977b8f6 RS |
4253 | |
4254 | (interactive "P") | |
4255 | ||
4256 | (save-excursion | |
fd5359c6 MR |
4257 | (allout-back-to-current-heading) |
4258 | (allout-beginning-of-level) | |
d8350998 | 4259 | (let ((depth allout-recent-depth) |
c567ac01 | 4260 | (index (if (not denumber) 1)) |
1977b8f6 RS |
4261 | (use-bullet (equal '(16) denumber)) |
4262 | (more t)) | |
4263 | (while more | |
fd5359c6 | 4264 | (allout-rebullet-heading use-bullet ;;; solicit |
c567ac01 | 4265 | depth ;;; depth |
1977b8f6 RS |
4266 | t ;;; number-control |
4267 | index ;;; index | |
4268 | nil) ;;; do-successors | |
4269 | (if index (setq index (1+ index))) | |
fd5359c6 MR |
4270 | (setq more (allout-next-sibling depth nil)))))) |
4271 | ;;;_ > allout-shift-in (arg) | |
4272 | (defun allout-shift-in (arg) | |
d8350998 CY |
4273 | "Increase depth of current heading and any items collapsed within it. |
4274 | ||
4275 | With a negative argument, the item is shifted out using | |
4276 | `allout-shift-out', instead. | |
4277 | ||
4278 | With an argument greater than one, shift-in the item but not its | |
4279 | offspring, making the item into a sibling of its former children, | |
4280 | and a child of sibling that formerly preceeded it. | |
4281 | ||
4282 | You are not allowed to shift the first offspring of a topic | |
4283 | inwards, because that would yield a \"containment | |
4284 | discontinuity\", where the depth difference between a topic and | |
4285 | its immediate offspring is greater than one. The first topic in | |
4286 | the file can be adjusted to any positive depth, however." | |
d82979ea | 4287 | |
1977b8f6 | 4288 | (interactive "p") |
d8350998 CY |
4289 | (if (< arg 0) |
4290 | (allout-shift-out (* arg -1)) | |
4291 | ;; refuse to create a containment discontinuity: | |
4292 | (save-excursion | |
4293 | (allout-back-to-current-heading) | |
4294 | (if (not (bobp)) | |
4295 | (let* ((current-depth allout-recent-depth) | |
4296 | (start-point (point)) | |
4297 | (predecessor-depth (progn | |
4298 | (forward-char -1) | |
4299 | (allout-goto-prefix-doublechecked) | |
4300 | (if (< (point) start-point) | |
4301 | allout-recent-depth | |
4302 | 0)))) | |
4303 | (if (and (> predecessor-depth 0) | |
4304 | (> (1+ current-depth) | |
4305 | (1+ predecessor-depth))) | |
4306 | (error (concat "Disallowed shift deeper than" | |
498a6493 CY |
4307 | " containing topic's children.")) |
4308 | (allout-back-to-current-heading) | |
4309 | (if (< allout-recent-depth (1+ current-depth)) | |
4310 | (allout-show-children)))))) | |
d8350998 CY |
4311 | (let ((where (point))) |
4312 | (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring)) | |
4313 | (run-hook-with-args 'allout-structure-shifted-hook arg where)))) | |
fd5359c6 MR |
4314 | ;;;_ > allout-shift-out (arg) |
4315 | (defun allout-shift-out (arg) | |
d82979ea | 4316 | "Decrease depth of current heading and any topics collapsed within it. |
d8350998 CY |
4317 | This will make the item a sibling of its former container. |
4318 | ||
4319 | With a negative argument, the item is shifted in using | |
4320 | `allout-shift-in', instead. | |
4321 | ||
4322 | With an argument greater than one, shift-out the item's offspring | |
4323 | but not the item itself, making the former children siblings of | |
4324 | the item. | |
d82979ea | 4325 | |
d8350998 CY |
4326 | With an argument greater than 1, the item's offspring are shifted |
4327 | out without shifting the item. This will make the immediate | |
4328 | subtopics into siblings of the item." | |
1977b8f6 | 4329 | (interactive "p") |
d8350998 CY |
4330 | (if (< arg 0) |
4331 | (allout-shift-in (* arg -1)) | |
4332 | ;; Get proper exposure in this area: | |
4333 | (save-excursion (if (allout-ascend) | |
4334 | (allout-show-children))) | |
4335 | ;; Show collapsed children if there's a successor which will become | |
4336 | ;; their sibling: | |
4337 | (if (and (allout-current-topic-collapsed-p) | |
4338 | (save-excursion (allout-next-sibling))) | |
4339 | (allout-show-children)) | |
4340 | (let ((where (and (allout-depth) allout-recent-prefix-beginning))) | |
4341 | (save-excursion | |
4342 | (if (> arg 1) | |
4343 | ;; Shift the offspring but not the topic: | |
4344 | (let ((children-chart (allout-chart-subtree 1))) | |
4345 | (if (listp (car children-chart)) | |
4346 | ;; whoops: | |
4347 | (setq children-chart (allout-flatten children-chart))) | |
4348 | (save-excursion | |
4349 | (dolist (child-point children-chart) | |
4350 | (goto-char child-point) | |
4351 | (allout-shift-out 1)))) | |
4352 | (allout-rebullet-topic (* arg -1)))) | |
4353 | (run-hook-with-args 'allout-structure-shifted-hook (* arg -1) where)))) | |
c567ac01 | 4354 | ;;;_ : Surgery (kill-ring) functions with special provisions for outlines: |
fd5359c6 MR |
4355 | ;;;_ > allout-kill-line (&optional arg) |
4356 | (defun allout-kill-line (&optional arg) | |
c567ac01 | 4357 | "Kill line, adjusting subsequent lines suitably for outline mode." |
1977b8f6 RS |
4358 | |
4359 | (interactive "*P") | |
d82979ea | 4360 | |
96b83743 EZ |
4361 | (if (or (not (allout-mode-p)) |
4362 | (not (bolp)) | |
2a1408fd | 4363 | (not (save-match-data (looking-at allout-regexp)))) |
4034b0e2 | 4364 | ;; Just do a regular kill: |
96b83743 EZ |
4365 | (kill-line arg) |
4366 | ;; Ah, have to watch out for adjustments: | |
4367 | (let* ((beg (point)) | |
d8350998 | 4368 | end |
96b83743 EZ |
4369 | (beg-hidden (allout-hidden-p)) |
4370 | (end-hidden (save-excursion (allout-end-of-current-line) | |
d8350998 | 4371 | (setq end (point)) |
96b83743 | 4372 | (allout-hidden-p))) |
d8350998 | 4373 | (depth (allout-depth))) |
96b83743 | 4374 | |
d8350998 | 4375 | (allout-annotate-hidden beg end) |
96b83743 EZ |
4376 | (if (and (not beg-hidden) (not end-hidden)) |
4377 | (allout-unprotected (kill-line arg)) | |
4378 | (kill-line arg)) | |
ede4ac6a KS |
4379 | (allout-deannotate-hidden beg end) |
4380 | ||
96b83743 EZ |
4381 | (if allout-numbered-bullet |
4382 | (save-excursion ; Renumber subsequent topics if needed: | |
2a1408fd | 4383 | (if (not (save-match-data (looking-at allout-regexp))) |
d82979ea | 4384 | (allout-next-heading)) |
48bd8440 EZ |
4385 | (allout-renumber-to-depth depth))) |
4386 | (run-hook-with-args 'allout-structure-deleted-hook depth (point))))) | |
1b4d97b2 CY |
4387 | ;;;_ > allout-copy-line-as-kill () |
4388 | (defun allout-copy-line-as-kill () | |
4389 | "Like allout-kill-topic, but save to kill ring instead of deleting." | |
4390 | (interactive) | |
4391 | (let ((buffer-read-only t)) | |
4392 | (condition-case nil | |
4393 | (allout-kill-line) | |
4394 | (buffer-read-only nil)))) | |
fd5359c6 MR |
4395 | ;;;_ > allout-kill-topic () |
4396 | (defun allout-kill-topic () | |
c567ac01 RS |
4397 | "Kill topic together with subtopics. |
4398 | ||
96b83743 EZ |
4399 | Trailing whitespace is killed with a topic if that whitespace: |
4400 | ||
4401 | - would separate the topic from a subsequent sibling | |
4402 | - would separate the topic from the end of buffer | |
4403 | - would not be added to whitespace already separating the topic from the | |
4404 | previous one. | |
4405 | ||
d8350998 | 4406 | Topic exposure is marked with text-properties, to be used by |
75bcb912 | 4407 | `allout-yank-processing' for exposure recovery." |
1977b8f6 RS |
4408 | |
4409 | (interactive) | |
0458fa80 | 4410 | (let* ((inhibit-field-text-motion t) |
96b83743 | 4411 | (beg (prog1 (allout-back-to-current-heading) (beginning-of-line))) |
ede4ac6a | 4412 | end |
d8350998 | 4413 | (depth allout-recent-depth)) |
fd5359c6 | 4414 | (allout-end-of-current-subtree) |
96b83743 EZ |
4415 | (if (and (/= (current-column) 0) (not (eobp))) |
4416 | (forward-char 1)) | |
1977b8f6 | 4417 | (if (not (eobp)) |
2a1408fd | 4418 | (if (and (save-match-data (looking-at "\n")) |
96b83743 EZ |
4419 | (or (save-excursion |
4420 | (or (not (allout-next-heading)) | |
d8350998 | 4421 | (= depth allout-recent-depth))) |
96b83743 EZ |
4422 | (and (> (- beg (point-min)) 3) |
4423 | (string= (buffer-substring (- beg 2) beg) "\n\n")))) | |
c567ac01 | 4424 | (forward-char 1))) |
353e2ef2 | 4425 | |
ede4ac6a KS |
4426 | (allout-annotate-hidden beg (setq end (point))) |
4427 | (unwind-protect | |
4428 | (allout-unprotected (kill-region beg end)) | |
4429 | (if buffer-read-only | |
4430 | ;; eg, during copy-as-kill. | |
4431 | (allout-deannotate-hidden beg end))) | |
d8350998 | 4432 | |
1977b8f6 | 4433 | (save-excursion |
48bd8440 EZ |
4434 | (allout-renumber-to-depth depth)) |
4435 | (run-hook-with-args 'allout-structure-deleted-hook depth (point)))) | |
1b4d97b2 CY |
4436 | ;;;_ > allout-copy-topic-as-kill () |
4437 | (defun allout-copy-topic-as-kill () | |
75bcb912 | 4438 | "Like `allout-kill-topic', but save to kill ring instead of deleting." |
1b4d97b2 CY |
4439 | (interactive) |
4440 | (let ((buffer-read-only t)) | |
4441 | (condition-case nil | |
4442 | (allout-kill-topic) | |
4443 | (buffer-read-only (message "Topic copied..."))))) | |
d8350998 CY |
4444 | ;;;_ > allout-annotate-hidden (begin end) |
4445 | (defun allout-annotate-hidden (begin end) | |
4446 | "Qualify text with properties to indicate exposure status." | |
4447 | ||
1b4d97b2 CY |
4448 | (let ((was-modified (buffer-modified-p)) |
4449 | (buffer-read-only nil)) | |
ede4ac6a | 4450 | (allout-deannotate-hidden begin end) |
d8350998 CY |
4451 | (save-excursion |
4452 | (goto-char begin) | |
4453 | (let (done next prev overlay) | |
4454 | (while (not done) | |
4455 | ;; at or advance to start of next hidden region: | |
4456 | (if (not (allout-hidden-p)) | |
4457 | (setq next | |
1b4d97b2 CY |
4458 | (max (1+ (point)) |
4459 | (next-single-char-property-change (point) | |
4460 | 'invisible | |
4461 | nil end)))) | |
d8350998 | 4462 | (if (or (not next) (eq prev next)) |
60c7bbd2 | 4463 | ;; still not at start of hidden area -- must not be any left. |
d8350998 CY |
4464 | (setq done t) |
4465 | (goto-char next) | |
4466 | (setq prev next) | |
4467 | (if (not (allout-hidden-p)) | |
4468 | ;; still not at start of hidden area. | |
4469 | (setq done t) | |
4470 | (setq overlay (allout-get-invisibility-overlay)) | |
4471 | (setq next (overlay-end overlay) | |
4472 | prev next) | |
4473 | ;; advance to end of this hidden area: | |
4474 | (when next | |
4475 | (goto-char next) | |
4476 | (allout-unprotected | |
ede4ac6a KS |
4477 | (let ((buffer-undo-list t)) |
4478 | (put-text-property (overlay-start overlay) next | |
4479 | 'allout-was-hidden t))))))))) | |
d8350998 | 4480 | (set-buffer-modified-p was-modified))) |
ede4ac6a KS |
4481 | ;;;_ > allout-deannotate-hidden (begin end) |
4482 | (defun allout-deannotate-hidden (begin end) | |
4483 | "Remove allout hidden-text annotation between BEGIN and END." | |
4484 | ||
4485 | (allout-unprotected | |
4486 | (let ((inhibit-read-only t) | |
4487 | (buffer-undo-list t)) | |
4488 | ;(remove-text-properties begin end '(allout-was-hidden t)) | |
4489 | ))) | |
d8350998 CY |
4490 | ;;;_ > allout-hide-by-annotation (begin end) |
4491 | (defun allout-hide-by-annotation (begin end) | |
4492 | "Translate text properties indicating exposure status into actual exposure." | |
4493 | (save-excursion | |
4494 | (goto-char begin) | |
4495 | (let ((was-modified (buffer-modified-p)) | |
4496 | done next prev) | |
4497 | (while (not done) | |
4498 | ;; at or advance to start of next annotation: | |
4499 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
4500 | (setq next (next-single-char-property-change (point) | |
4501 | 'allout-was-hidden | |
4502 | nil end))) | |
4503 | (if (or (not next) (eq prev next)) | |
60c7bbd2 | 4504 | ;; no more or not advancing -- must not be any left. |
d8350998 CY |
4505 | (setq done t) |
4506 | (goto-char next) | |
4507 | (setq prev next) | |
4508 | (if (not (get-text-property (point) 'allout-was-hidden)) | |
4509 | ;; still not at start of annotation. | |
4510 | (setq done t) | |
4511 | ;; advance to just after end of this annotation: | |
4512 | (setq next (next-single-char-property-change (point) | |
4513 | 'allout-was-hidden | |
4514 | nil end)) | |
2a1408fd | 4515 | (overlay-put (make-overlay prev next nil 'front-advance) |
d8350998 | 4516 | 'category 'allout-exposure-category) |
ede4ac6a | 4517 | (allout-deannotate-hidden prev next) |
d8350998 CY |
4518 | (setq prev next) |
4519 | (if next (goto-char next))))) | |
4520 | (set-buffer-modified-p was-modified)))) | |
fd5359c6 MR |
4521 | ;;;_ > allout-yank-processing () |
4522 | (defun allout-yank-processing (&optional arg) | |
c567ac01 | 4523 | |
96b83743 | 4524 | "Incidental allout-specific business to be done just after text yanks. |
19b84ba3 | 4525 | |
c567ac01 | 4526 | Does depth adjustment of yanked topics, when: |
1977b8f6 | 4527 | |
c567ac01 RS |
4528 | 1 the stuff being yanked starts with a valid outline header prefix, and |
4529 | 2 it is being yanked at the end of a line which consists of only a valid | |
1977b8f6 RS |
4530 | topic prefix. |
4531 | ||
a0776d6b | 4532 | Also, adjusts numbering of subsequent siblings when appropriate. |
1977b8f6 | 4533 | |
c567ac01 RS |
4534 | Depth adjustment alters the depth of all the topics being yanked |
4535 | the amount it takes to make the first topic have the depth of the | |
4536 | header into which it's being yanked. | |
1977b8f6 | 4537 | |
c567ac01 RS |
4538 | The point is left in front of yanked, adjusted topics, rather than |
4539 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
d82979ea | 4540 | however, are left exactly like normal, non-allout-specific yanks." |
c567ac01 RS |
4541 | |
4542 | (interactive "*P") | |
4543 | ; Get to beginning, leaving | |
4544 | ; region around subject: | |
96b83743 | 4545 | (if (< (allout-mark-marker t) (point)) |
c567ac01 | 4546 | (exchange-point-and-mark)) |
2a1408fd DN |
4547 | (save-match-data |
4548 | (let* ((subj-beg (point)) | |
4549 | (into-bol (bolp)) | |
4550 | (subj-end (allout-mark-marker t)) | |
4551 | ;; 'resituate' if yanking an entire topic into topic header: | |
4552 | (resituate (and (let ((allout-inhibit-aberrance-doublecheck t)) | |
4553 | (allout-e-o-prefix-p)) | |
4554 | (looking-at allout-regexp) | |
4555 | (allout-prefix-data))) | |
4556 | ;; `rectify-numbering' if resituating (where several topics may | |
4557 | ;; be resituating) or yanking a topic into a topic slot (bol): | |
4558 | (rectify-numbering (or resituate | |
8dd59f01 | 4559 | (and into-bol (looking-at allout-regexp))))) |
2a1408fd | 4560 | (if resituate |
8dd59f01 | 4561 | ;; Yanking a topic into the start of a topic -- reconcile to fit: |
2a1408fd DN |
4562 | (let* ((inhibit-field-text-motion t) |
4563 | (prefix-len (if (not (match-end 1)) | |
4564 | 1 | |
4565 | (- (match-end 1) subj-beg))) | |
4566 | (subj-depth allout-recent-depth) | |
4567 | (prefix-bullet (allout-recent-bullet)) | |
4568 | (adjust-to-depth | |
4569 | ;; Nil if adjustment unnecessary, otherwise depth to which | |
4570 | ;; adjustment should be made: | |
4571 | (save-excursion | |
4572 | (and (goto-char subj-end) | |
4573 | (eolp) | |
4574 | (goto-char subj-beg) | |
4575 | (and (looking-at allout-regexp) | |
4576 | (progn | |
4577 | (beginning-of-line) | |
4578 | (not (= (point) subj-beg))) | |
4579 | (looking-at allout-regexp) | |
4580 | (allout-prefix-data)) | |
4581 | allout-recent-depth))) | |
4582 | (more t)) | |
4583 | (setq rectify-numbering allout-numbered-bullet) | |
4584 | (if adjust-to-depth | |
c567ac01 | 4585 | ; Do the adjustment: |
2a1408fd DN |
4586 | (progn |
4587 | (save-restriction | |
4588 | (narrow-to-region subj-beg subj-end) | |
c567ac01 RS |
4589 | ; Trim off excessive blank |
4590 | ; line at end, if any: | |
2a1408fd DN |
4591 | (goto-char (point-max)) |
4592 | (if (looking-at "^$") | |
4593 | (allout-unprotected (delete-char -1))) | |
c567ac01 RS |
4594 | ; Work backwards, with each |
4595 | ; shallowest level, | |
4596 | ; successively excluding the | |
4597 | ; last processed topic from | |
4598 | ; the narrow region: | |
2a1408fd DN |
4599 | (while more |
4600 | (allout-back-to-current-heading) | |
c567ac01 | 4601 | ; go as high as we can in each bunch: |
2a1408fd DN |
4602 | (while (allout-ascend t)) |
4603 | (save-excursion | |
4604 | (allout-unprotected | |
4605 | (allout-rebullet-topic-grunt (- adjust-to-depth | |
4606 | subj-depth))) | |
4607 | (allout-depth)) | |
4608 | (if (setq more (not (bobp))) | |
4609 | (progn (widen) | |
4610 | (forward-char -1) | |
4611 | (narrow-to-region subj-beg (point)))))) | |
4612 | ;; Preserve new bullet if it's a distinctive one, otherwise | |
4613 | ;; use old one: | |
4614 | (if (string-match (regexp-quote prefix-bullet) | |
4615 | allout-distinctive-bullets-string) | |
c567ac01 RS |
4616 | ; Delete from bullet of old to |
4617 | ; before bullet of new: | |
2a1408fd DN |
4618 | (progn |
4619 | (beginning-of-line) | |
4620 | (allout-unprotected | |
4621 | (delete-region (point) subj-beg)) | |
4622 | (set-marker (allout-mark-marker t) subj-end) | |
4623 | (goto-char subj-beg) | |
4624 | (allout-end-of-prefix)) | |
c567ac01 RS |
4625 | ; Delete base subj prefix, |
4626 | ; leaving old one: | |
2a1408fd DN |
4627 | (allout-unprotected |
4628 | (progn | |
4629 | (delete-region (point) (+ (point) | |
4630 | prefix-len | |
4631 | (- adjust-to-depth | |
4632 | subj-depth))) | |
c567ac01 RS |
4633 | ; and delete residual subj |
4634 | ; prefix digits and space: | |
2a1408fd DN |
4635 | (while (looking-at "[0-9]") (delete-char 1)) |
4636 | (if (looking-at " ") | |
4637 | (delete-char 1)))))) | |
4638 | (exchange-point-and-mark)))) | |
4639 | (if rectify-numbering | |
4640 | (progn | |
4641 | (save-excursion | |
c567ac01 | 4642 | ; Give some preliminary feedback: |
2a1408fd | 4643 | (message "... reconciling numbers") |
c567ac01 | 4644 | ; ... and renumber, in case necessary: |
2a1408fd DN |
4645 | (goto-char subj-beg) |
4646 | (if (allout-goto-prefix-doublechecked) | |
4647 | (allout-unprotected | |
4648 | (allout-rebullet-heading nil ;;; solicit | |
4649 | (allout-depth) ;;; depth | |
4650 | nil ;;; number-control | |
4651 | nil ;;; index | |
4652 | t))) | |
4653 | (message "")))) | |
4654 | (if (or into-bol resituate) | |
4655 | (allout-hide-by-annotation (point) (allout-mark-marker t)) | |
4656 | (allout-deannotate-hidden (allout-mark-marker t) (point))) | |
4657 | (if (not resituate) | |
4658 | (exchange-point-and-mark)) | |
4659 | (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end)))) | |
fd5359c6 MR |
4660 | ;;;_ > allout-yank (&optional arg) |
4661 | (defun allout-yank (&optional arg) | |
aad94676 | 4662 | "`allout-mode' yank, with depth and numbering adjustment of yanked topics. |
19b84ba3 | 4663 | |
a0776d6b | 4664 | Non-topic yanks work no differently than normal yanks. |
c567ac01 RS |
4665 | |
4666 | If a topic is being yanked into a bare topic prefix, the depth of the | |
4667 | yanked topic is adjusted to the depth of the topic prefix. | |
4668 | ||
2265e017 | 4669 | 1 we're yanking in an `allout-mode' buffer |
c567ac01 RS |
4670 | 2 the stuff being yanked starts with a valid outline header prefix, and |
4671 | 3 it is being yanked at the end of a line which consists of only a valid | |
4672 | topic prefix. | |
4673 | ||
4674 | If these conditions hold then the depth of the yanked topics are all | |
4675 | adjusted the amount it takes to make the first one at the depth of the | |
4676 | header into which it's being yanked. | |
4677 | ||
4678 | The point is left in front of yanked, adjusted topics, rather than | |
4679 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
4680 | however, (ones that don't qualify for adjustment) are handled | |
4681 | exactly like normal yanks. | |
4682 | ||
a0776d6b | 4683 | Numbering of yanked topics, and the successive siblings at the depth |
c567ac01 RS |
4684 | into which they're being yanked, is adjusted. |
4685 | ||
539d7736 JB |
4686 | `allout-yank-pop' works with `allout-yank' just like normal `yank-pop' |
4687 | works with normal `yank' in non-outline buffers." | |
1977b8f6 RS |
4688 | |
4689 | (interactive "*P") | |
4690 | (setq this-command 'yank) | |
48bd8440 EZ |
4691 | (allout-unprotected |
4692 | (yank arg)) | |
fd5359c6 | 4693 | (if (allout-mode-p) |
48bd8440 | 4694 | (allout-yank-processing))) |
fd5359c6 MR |
4695 | ;;;_ > allout-yank-pop (&optional arg) |
4696 | (defun allout-yank-pop (&optional arg) | |
2265e017 | 4697 | "Yank-pop like `allout-yank' when popping to bare outline prefixes. |
19b84ba3 RS |
4698 | |
4699 | Adapts level of popped topics to level of fresh prefix. | |
c567ac01 | 4700 | |
60c7bbd2 | 4701 | Note -- prefix changes to distinctive bullets will stick, if followed |
c567ac01 | 4702 | by pops to non-distinctive yanks. Bug..." |
1977b8f6 RS |
4703 | |
4704 | (interactive "*p") | |
1977b8f6 | 4705 | (setq this-command 'yank) |
c567ac01 | 4706 | (yank-pop arg) |
fd5359c6 MR |
4707 | (if (allout-mode-p) |
4708 | (allout-yank-processing))) | |
1977b8f6 | 4709 | |
c567ac01 RS |
4710 | ;;;_ - Specialty bullet functions |
4711 | ;;;_ : File Cross references | |
fd5359c6 MR |
4712 | ;;;_ > allout-resolve-xref () |
4713 | (defun allout-resolve-xref () | |
19b84ba3 RS |
4714 | "Pop to file associated with current heading, if it has an xref bullet. |
4715 | ||
fd5359c6 | 4716 | \(Works according to setting of `allout-file-xref-bullet')." |
1977b8f6 | 4717 | (interactive) |
fd5359c6 | 4718 | (if (not allout-file-xref-bullet) |
1977b8f6 | 4719 | (error |
60c7bbd2 | 4720 | "Outline cross references disabled -- no `allout-file-xref-bullet'") |
fd5359c6 | 4721 | (if (not (string= (allout-current-bullet) allout-file-xref-bullet)) |
635ca796 | 4722 | (error "Current heading lacks cross-reference bullet `%s'" |
fd5359c6 | 4723 | allout-file-xref-bullet) |
0458fa80 EZ |
4724 | (let ((inhibit-field-text-motion t) |
4725 | file-name) | |
2a1408fd DN |
4726 | (save-match-data |
4727 | (save-excursion | |
4728 | (let* ((text-start allout-recent-prefix-end) | |
4729 | (heading-end (progn (end-of-line) (point)))) | |
4730 | (goto-char text-start) | |
4731 | (setq file-name | |
4732 | (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t) | |
4733 | (buffer-substring (match-beginning 1) | |
4734 | (match-end 1))))))) | |
69027dea | 4735 | (setq file-name (expand-file-name file-name)) |
1977b8f6 RS |
4736 | (if (or (file-exists-p file-name) |
4737 | (if (file-writable-p file-name) | |
4738 | (y-or-n-p (format "%s not there, create one? " | |
4739 | file-name)) | |
4740 | (error "%s not found and can't be created" file-name))) | |
4741 | (condition-case failure | |
4742 | (find-file-other-window file-name) | |
d8350998 | 4743 | (error failure)) |
1977b8f6 RS |
4744 | (error "%s not found" file-name)) |
4745 | ) | |
4746 | ) | |
4747 | ) | |
4748 | ) | |
19b84ba3 | 4749 | |
9179616f | 4750 | ;;;_ #6 Exposure Control |
c567ac01 RS |
4751 | |
4752 | ;;;_ - Fundamental | |
d82979ea EZ |
4753 | ;;;_ > allout-flag-region (from to flag) |
4754 | (defun allout-flag-region (from to flag) | |
48bd8440 EZ |
4755 | "Conceal text between FROM and TO if FLAG is non-nil, else reveal it. |
4756 | ||
4757 | Exposure-change hook `allout-exposure-change-hook' is run with the same | |
c07583cd | 4758 | arguments as this function, after the exposure changes are made. (The old |
48bd8440 | 4759 | `allout-view-change-hook' is being deprecated, and eventually will not be |
c07583cd | 4760 | invoked.)" |
96b83743 | 4761 | |
96b83743 | 4762 | ;; We use outline invisibility spec. |
01fc9422 | 4763 | (remove-overlays from to 'category 'allout-exposure-category) |
96b83743 | 4764 | (when flag |
2a1408fd | 4765 | (let ((o (make-overlay from to nil 'front-advance))) |
01fc9422 | 4766 | (overlay-put o 'category 'allout-exposure-category) |
96b83743 | 4767 | (when (featurep 'xemacs) |
01fc9422 | 4768 | (let ((props (symbol-plist 'allout-exposure-category))) |
96b83743 EZ |
4769 | (while props |
4770 | (overlay-put o (pop props) (pop props))))))) | |
da506f05 | 4771 | (run-hooks 'allout-view-change-hook) |
48bd8440 | 4772 | (run-hook-with-args 'allout-exposure-change-hook from to flag)) |
fd5359c6 MR |
4773 | ;;;_ > allout-flag-current-subtree (flag) |
4774 | (defun allout-flag-current-subtree (flag) | |
96b83743 | 4775 | "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it." |
19b84ba3 | 4776 | |
c567ac01 | 4777 | (save-excursion |
fd5359c6 | 4778 | (allout-back-to-current-heading) |
0458fa80 EZ |
4779 | (let ((inhibit-field-text-motion t)) |
4780 | (end-of-line)) | |
96b83743 EZ |
4781 | (allout-flag-region (point) |
4782 | ;; Exposing must not leave trailing blanks hidden, | |
4783 | ;; but can leave them exposed when hiding, so we | |
4784 | ;; can use flag's inverse as the | |
4785 | ;; include-trailing-blank cue: | |
4786 | (allout-end-of-current-subtree (not flag)) | |
4787 | flag))) | |
c567ac01 | 4788 | |
c567ac01 | 4789 | ;;;_ - Topic-specific |
01fc9422 EZ |
4790 | ;;;_ > allout-show-entry () |
4791 | (defun allout-show-entry () | |
4792 | "Like `allout-show-current-entry', but reveals entries in hidden topics. | |
c567ac01 RS |
4793 | |
4794 | This is a way to give restricted peek at a concealed locality without the | |
4795 | expense of exposing its context, but can leave the outline with aberrant | |
96b83743 EZ |
4796 | exposure. `allout-show-offshoot' should be used after the peek to rectify |
4797 | the exposure." | |
c567ac01 RS |
4798 | |
4799 | (interactive) | |
4800 | (save-excursion | |
96b83743 | 4801 | (let (beg end) |
d8350998 | 4802 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4803 | (setq beg (if (allout-hidden-p) (1- (point)) (point))) |
4804 | (setq end (allout-pre-next-prefix)) | |
4805 | (allout-flag-region beg end nil) | |
9179616f | 4806 | (list beg end)))) |
fd5359c6 MR |
4807 | ;;;_ > allout-show-children (&optional level strict) |
4808 | (defun allout-show-children (&optional level strict) | |
c567ac01 RS |
4809 | |
4810 | "If point is visible, show all direct subheadings of this heading. | |
19b84ba3 | 4811 | |
2265e017 | 4812 | Otherwise, do `allout-show-to-offshoot', and then show subheadings. |
c567ac01 RS |
4813 | |
4814 | Optional LEVEL specifies how many levels below the current level | |
4815 | should be shown, or all levels if t. Default is 1. | |
4816 | ||
4817 | Optional STRICT means don't resort to -show-to-offshoot, no matter | |
4818 | what. This is basically so -show-to-offshoot, which is called by | |
4819 | this function, can employ the pure offspring-revealing capabilities of | |
19b84ba3 RS |
4820 | it. |
4821 | ||
4822 | Returns point at end of subtree that was opened, if any. (May get a | |
4823 | point of non-opened subtree?)" | |
c567ac01 RS |
4824 | |
4825 | (interactive "p") | |
96b83743 | 4826 | (let ((start-point (point))) |
19b84ba3 | 4827 | (if (and (not strict) |
96b83743 | 4828 | (allout-hidden-p)) |
c567ac01 | 4829 | |
96b83743 EZ |
4830 | (progn (allout-show-to-offshoot) ; Point's concealed, open to |
4831 | ; expose it. | |
4832 | ;; Then recurse, but with "strict" set so we don't | |
4833 | ;; infinite regress: | |
4834 | (allout-show-children level t)) | |
c567ac01 | 4835 | |
19b84ba3 | 4836 | (save-excursion |
96b83743 EZ |
4837 | (allout-beginning-of-current-line) |
4838 | (save-restriction | |
d8350998 | 4839 | (let* (depth |
65e7eb3d EZ |
4840 | ;; translate the level spec for this routine to the ones |
4841 | ;; used by -chart-subtree and -chart-to-reveal: | |
4842 | (chart-level (cond ((not level) 1) | |
4843 | ((eq level t) nil) | |
4844 | (t level))) | |
4845 | (chart (allout-chart-subtree chart-level)) | |
4846 | (to-reveal (or (allout-chart-to-reveal chart chart-level) | |
d8350998 CY |
4847 | ;; interactive, show discontinuous children: |
4848 | (and chart | |
4849 | (interactive-p) | |
4850 | (save-excursion | |
4851 | (allout-back-to-current-heading) | |
4852 | (setq depth (allout-current-depth)) | |
4853 | (and (allout-next-heading) | |
4854 | (> allout-recent-depth | |
4855 | (1+ depth)))) | |
4856 | (message | |
4857 | "Discontinuous offspring; use `%s %s'%s." | |
4858 | (substitute-command-keys | |
4859 | "\\[universal-argument]") | |
4860 | (substitute-command-keys | |
4861 | "\\[allout-shift-out]") | |
4862 | " to elevate them.") | |
4863 | (allout-chart-to-reveal | |
4864 | chart (- allout-recent-depth depth)))))) | |
96b83743 EZ |
4865 | (goto-char start-point) |
4866 | (when (and strict (allout-hidden-p)) | |
4867 | ;; Concealed root would already have been taken care of, | |
4868 | ;; unless strict was set. | |
4869 | (allout-flag-region (point) (allout-snug-back) nil) | |
4870 | (when allout-show-bodies | |
4871 | (goto-char (car to-reveal)) | |
4872 | (allout-show-current-entry))) | |
4873 | (while to-reveal | |
4874 | (goto-char (car to-reveal)) | |
4875 | (allout-flag-region (save-excursion (allout-snug-back) (point)) | |
4876 | (progn (search-forward "\n" nil t) | |
4877 | (1- (point))) | |
4878 | nil) | |
4879 | (when allout-show-bodies | |
4880 | (goto-char (car to-reveal)) | |
4881 | (allout-show-current-entry)) | |
4882 | (setq to-reveal (cdr to-reveal))))))) | |
4883 | ;; Compensate for `save-excursion's maintenance of point | |
4884 | ;; within invisible text: | |
4885 | (goto-char start-point))) | |
fd5359c6 MR |
4886 | ;;;_ > allout-show-to-offshoot () |
4887 | (defun allout-show-to-offshoot () | |
2265e017 | 4888 | "Like `allout-show-entry', but reveals all concealed ancestors, as well. |
c567ac01 | 4889 | |
96b83743 | 4890 | Useful for coherently exposing to a random point in a hidden region." |
c567ac01 RS |
4891 | (interactive) |
4892 | (save-excursion | |
0458fa80 EZ |
4893 | (let ((inhibit-field-text-motion t) |
4894 | (orig-pt (point)) | |
d8350998 | 4895 | (orig-pref (allout-goto-prefix-doublechecked)) |
c567ac01 | 4896 | (last-at (point)) |
65e7eb3d EZ |
4897 | (bag-it 0)) |
4898 | (while (or (> bag-it 1) (allout-hidden-p)) | |
96b83743 | 4899 | (while (allout-hidden-p) |
d8350998 | 4900 | (move-beginning-of-line 1) |
96b83743 | 4901 | (if (allout-hidden-p) (forward-char -1))) |
c567ac01 | 4902 | (if (= last-at (setq last-at (point))) |
65e7eb3d EZ |
4903 | ;; Oops, we're not making any progress! Show the current topic |
4904 | ;; completely, and try one more time here, if we haven't already. | |
c567ac01 | 4905 | (progn (beginning-of-line) |
fd5359c6 | 4906 | (allout-show-current-subtree) |
c567ac01 | 4907 | (goto-char orig-pt) |
65e7eb3d EZ |
4908 | (setq bag-it (1+ bag-it)) |
4909 | (if (> bag-it 1) | |
4910 | (error "allout-show-to-offshoot: %s" | |
4911 | "Stumped by aberrant nesting."))) | |
4912 | (if (> bag-it 0) (setq bag-it 0)) | |
d8350998 CY |
4913 | (allout-show-children) |
4914 | (goto-char orig-pref))) | |
19b84ba3 | 4915 | (goto-char orig-pt))) |
fd5359c6 MR |
4916 | (if (allout-hidden-p) |
4917 | (allout-show-entry))) | |
4918 | ;;;_ > allout-hide-current-entry () | |
4919 | (defun allout-hide-current-entry () | |
c567ac01 RS |
4920 | "Hide the body directly following this heading." |
4921 | (interactive) | |
fd5359c6 | 4922 | (allout-back-to-current-heading) |
c567ac01 | 4923 | (save-excursion |
0458fa80 EZ |
4924 | (let ((inhibit-field-text-motion t)) |
4925 | (end-of-line)) | |
96b83743 | 4926 | (allout-flag-region (point) |
d82979ea | 4927 | (progn (allout-end-of-entry) (point)) |
96b83743 | 4928 | t))) |
fd5359c6 MR |
4929 | ;;;_ > allout-show-current-entry (&optional arg) |
4930 | (defun allout-show-current-entry (&optional arg) | |
96b83743 | 4931 | "Show body following current heading, or hide entry with universal argument." |
c567ac01 RS |
4932 | |
4933 | (interactive "P") | |
4934 | (if arg | |
fd5359c6 | 4935 | (allout-hide-current-entry) |
96b83743 | 4936 | (save-excursion (allout-show-to-offshoot)) |
c567ac01 | 4937 | (save-excursion |
fd5359c6 | 4938 | (allout-flag-region (point) |
96b83743 EZ |
4939 | (progn (allout-end-of-entry t) (point)) |
4940 | nil) | |
d82979ea | 4941 | ))) |
fd5359c6 MR |
4942 | ;;;_ > allout-show-current-subtree (&optional arg) |
4943 | (defun allout-show-current-subtree (&optional arg) | |
75bcb912 JB |
4944 | "Show everything within the current topic. |
4945 | With a repeat-count, expose this topic and its siblings." | |
19b84ba3 RS |
4946 | (interactive "P") |
4947 | (save-excursion | |
fd5359c6 | 4948 | (if (<= (allout-current-depth) 0) |
60c7bbd2 | 4949 | ;; Outside any topics -- try to get to the first: |
fd5359c6 | 4950 | (if (not (allout-next-heading)) |
6a05d05f | 4951 | (error "No topics") |
60c7bbd2 RS |
4952 | ;; got to first, outermost topic -- set to expose it and siblings: |
4953 | (message "Above outermost topic -- exposing all.") | |
96b83743 EZ |
4954 | (allout-flag-region (point-min)(point-max) nil)) |
4955 | (allout-beginning-of-current-line) | |
19b84ba3 | 4956 | (if (not arg) |
96b83743 | 4957 | (allout-flag-current-subtree nil) |
fd5359c6 MR |
4958 | (allout-beginning-of-level) |
4959 | (allout-expose-topic '(* :)))))) | |
96b83743 EZ |
4960 | ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners) |
4961 | (defun allout-current-topic-collapsed-p (&optional include-single-liners) | |
4962 | "True if the currently visible containing topic is already collapsed. | |
4963 | ||
64686e6d RS |
4964 | Single line topics intrinsically can be considered as being both |
4965 | collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is | |
4966 | true, then single-line topics are considered to be collapsed. By | |
4967 | default, they are treated as being uncollapsed." | |
2a1408fd DN |
4968 | (save-match-data |
4969 | (save-excursion | |
4970 | (and | |
4971 | ;; Is the topic all on one line (allowing for trailing blank line)? | |
4972 | (>= (progn (allout-back-to-current-heading) | |
4973 | (move-end-of-line 1) | |
4974 | (point)) | |
4975 | (allout-end-of-current-subtree (not (looking-at "\n\n")))) | |
4976 | ||
4977 | (or include-single-liners | |
4978 | (progn (backward-char 1) (allout-hidden-p))))))) | |
fd5359c6 MR |
4979 | ;;;_ > allout-hide-current-subtree (&optional just-close) |
4980 | (defun allout-hide-current-subtree (&optional just-close) | |
19b84ba3 | 4981 | "Close the current topic, or containing topic if this one is already closed. |
c567ac01 | 4982 | |
19b84ba3 | 4983 | If this topic is closed and it's a top level topic, close this topic |
353e2ef2 | 4984 | and its siblings. |
19b84ba3 | 4985 | |
96b83743 | 4986 | If optional arg JUST-CLOSE is non-nil, do not close the parent or |
19b84ba3 | 4987 | siblings, even if the target topic is already closed." |
c567ac01 RS |
4988 | |
4989 | (interactive) | |
96b83743 | 4990 | (let* ((from (point)) |
60c7bbd2 | 4991 | (sibs-msg "Top-level topic already closed -- closing siblings...") |
96b83743 EZ |
4992 | (current-exposed (not (allout-current-topic-collapsed-p t)))) |
4993 | (cond (current-exposed (allout-flag-current-subtree t)) | |
4994 | (just-close nil) | |
d8350998 | 4995 | ((allout-ascend) (allout-hide-current-subtree)) |
96b83743 EZ |
4996 | (t (goto-char 0) |
4997 | (message sibs-msg) | |
d8350998 | 4998 | (allout-goto-prefix-doublechecked) |
96b83743 EZ |
4999 | (allout-expose-topic '(0 :)) |
5000 | (message (concat sibs-msg " Done.")))) | |
5001 | (goto-char from))) | |
2a1408fd DN |
5002 | ;;;_ > allout-toggle-current-subtree-exposure |
5003 | (defun allout-toggle-current-subtree-exposure () | |
5004 | "Show or hide the current subtree depending on its current state." | |
5005 | ;; thanks to tassilo for suggesting this. | |
5006 | (interactive) | |
5007 | (save-excursion | |
5008 | (allout-back-to-heading) | |
5009 | (if (allout-hidden-p (point-at-eol)) | |
5010 | (allout-show-current-subtree) | |
5011 | (allout-hide-current-subtree)))) | |
fd5359c6 MR |
5012 | ;;;_ > allout-show-current-branches () |
5013 | (defun allout-show-current-branches () | |
c567ac01 RS |
5014 | "Show all subheadings of this heading, but not their bodies." |
5015 | (interactive) | |
0458fa80 EZ |
5016 | (let ((inhibit-field-text-motion t)) |
5017 | (beginning-of-line)) | |
fd5359c6 MR |
5018 | (allout-show-children t)) |
5019 | ;;;_ > allout-hide-current-leaves () | |
5020 | (defun allout-hide-current-leaves () | |
353e2ef2 | 5021 | "Hide the bodies of the current topic and all its offspring." |
c567ac01 | 5022 | (interactive) |
fd5359c6 MR |
5023 | (allout-back-to-current-heading) |
5024 | (allout-hide-region-body (point) (progn (allout-end-of-current-subtree) | |
c567ac01 RS |
5025 | (point)))) |
5026 | ||
5027 | ;;;_ - Region and beyond | |
fd5359c6 MR |
5028 | ;;;_ > allout-show-all () |
5029 | (defun allout-show-all () | |
c567ac01 RS |
5030 | "Show all of the text in the buffer." |
5031 | (interactive) | |
19b84ba3 | 5032 | (message "Exposing entire buffer...") |
96b83743 | 5033 | (allout-flag-region (point-min) (point-max) nil) |
19b84ba3 | 5034 | (message "Exposing entire buffer... Done.")) |
fd5359c6 MR |
5035 | ;;;_ > allout-hide-bodies () |
5036 | (defun allout-hide-bodies () | |
c567ac01 RS |
5037 | "Hide all of buffer except headings." |
5038 | (interactive) | |
fd5359c6 MR |
5039 | (allout-hide-region-body (point-min) (point-max))) |
5040 | ;;;_ > allout-hide-region-body (start end) | |
5041 | (defun allout-hide-region-body (start end) | |
c567ac01 | 5042 | "Hide all body lines in the region, but not headings." |
2a1408fd DN |
5043 | (save-match-data |
5044 | (save-excursion | |
5045 | (save-restriction | |
5046 | (narrow-to-region start end) | |
5047 | (goto-char (point-min)) | |
5048 | (let ((inhibit-field-text-motion t)) | |
5049 | (while (not (eobp)) | |
5050 | (end-of-line) | |
5051 | (allout-flag-region (point) (allout-end-of-entry) t) | |
5052 | (if (not (eobp)) | |
5053 | (forward-char | |
5054 | (if (looking-at "\n\n") | |
5055 | 2 1))))))))) | |
c567ac01 | 5056 | |
fd5359c6 MR |
5057 | ;;;_ > allout-expose-topic (spec) |
5058 | (defun allout-expose-topic (spec) | |
19b84ba3 | 5059 | "Apply exposure specs to successive outline topic items. |
c567ac01 | 5060 | |
fd5359c6 MR |
5061 | Use the more convenient frontend, `allout-new-exposure', if you don't |
5062 | need evaluation of the arguments, or even better, the `allout-layout' | |
19b84ba3 RS |
5063 | variable-keyed mode-activation/auto-exposure feature of allout outline |
5064 | mode. See the respective documentation strings for more details. | |
c567ac01 RS |
5065 | |
5066 | Cursor is left at start position. | |
5067 | ||
19b84ba3 RS |
5068 | SPEC is either a number or a list. |
5069 | ||
5070 | Successive specs on a list are applied to successive sibling topics. | |
c567ac01 | 5071 | |
c07583cd | 5072 | A simple spec (either a number, one of a few symbols, or the null |
19b84ba3 RS |
5073 | list) dictates the exposure for the corresponding topic. |
5074 | ||
5075 | Non-null lists recursively designate exposure specs for respective | |
5076 | subtopics of the current topic. | |
c567ac01 | 5077 | |
353e2ef2 | 5078 | The `:' repeat spec is used to specify exposure for any number of |
19b84ba3 | 5079 | successive siblings, up to the trailing ones for which there are |
353e2ef2 | 5080 | explicit specs following the `:'. |
c567ac01 RS |
5081 | |
5082 | Simple (numeric and null-list) specs are interpreted as follows: | |
5083 | ||
19b84ba3 RS |
5084 | Numbers indicate the relative depth to open the corresponding topic. |
5085 | - negative numbers force the topic to be closed before opening to the | |
5086 | absolute value of the number, so all siblings are open only to | |
5087 | that level. | |
5088 | - positive numbers open to the relative depth indicated by the | |
5089 | number, but do not force already opened subtopics to be closed. | |
60c7bbd2 | 5090 | - 0 means to close topic -- hide all offspring. |
353e2ef2 | 5091 | : - `repeat' |
c567ac01 | 5092 | apply prior element to all siblings at current level, *up to* |
353e2ef2 | 5093 | those siblings that would be covered by specs following the `:' |
c567ac01 | 5094 | on the list. Ie, apply to all topics at level but the last |
c07583cd | 5095 | ones. (Only first of multiple colons at same level is |
60c7bbd2 | 5096 | respected -- subsequent ones are discarded.) |
19b84ba3 RS |
5097 | * - completely opens the topic, including bodies. |
5098 | + - shows all the sub headers, but not the bodies | |
5099 | - - exposes the body of the corresponding topic. | |
c567ac01 RS |
5100 | |
5101 | Examples: | |
fd5359c6 | 5102 | \(allout-expose-topic '(-1 : 0)) |
c567ac01 RS |
5103 | Close this and all following topics at current level, exposing |
5104 | only their immediate children, but close down the last topic | |
5105 | at this current level completely. | |
fd5359c6 | 5106 | \(allout-expose-topic '(-1 () : 1 0)) |
c567ac01 RS |
5107 | Close current topic so only the immediate subtopics are shown; |
5108 | show the children in the second to last topic, and completely | |
5109 | close the last one. | |
fd5359c6 | 5110 | \(allout-expose-topic '(-2 : -1 *)) |
c567ac01 RS |
5111 | Expose children and grandchildren of all topics at current |
5112 | level except the last two; expose children of the second to | |
5113 | last and completely open the last one." | |
5114 | ||
5115 | (interactive "xExposure spec: ") | |
19b84ba3 RS |
5116 | (if (not (listp spec)) |
5117 | nil | |
fd5359c6 | 5118 | (let ((depth (allout-depth)) |
19b84ba3 RS |
5119 | (max-pos 0) |
5120 | prev-elem curr-elem | |
96b83743 | 5121 | stay) |
19b84ba3 RS |
5122 | (while spec |
5123 | (setq prev-elem curr-elem | |
5124 | curr-elem (car spec) | |
5125 | spec (cdr spec)) | |
5126 | (cond ; Do current element: | |
5127 | ((null curr-elem) nil) | |
5128 | ((symbolp curr-elem) | |
fd5359c6 MR |
5129 | (cond ((eq curr-elem '*) (allout-show-current-subtree) |
5130 | (if (> allout-recent-end-of-subtree max-pos) | |
5131 | (setq max-pos allout-recent-end-of-subtree))) | |
65e7eb3d EZ |
5132 | ((eq curr-elem '+) |
5133 | (if (not (allout-hidden-p)) | |
5134 | (save-excursion (allout-hide-current-subtree t))) | |
5135 | (allout-show-current-branches) | |
fd5359c6 MR |
5136 | (if (> allout-recent-end-of-subtree max-pos) |
5137 | (setq max-pos allout-recent-end-of-subtree))) | |
5138 | ((eq curr-elem '-) (allout-show-current-entry)) | |
19b84ba3 RS |
5139 | ((eq curr-elem ':) |
5140 | (setq stay t) | |
353e2ef2 | 5141 | ;; Expand the `repeat' spec to an explicit version, |
19b84ba3 RS |
5142 | ;; w.r.t. remaining siblings: |
5143 | (let ((residue ; = # of sibs not covered by remaining spec | |
60c7bbd2 | 5144 | ;; Dang, could be nice to make use of the chart, sigh: |
fd5359c6 | 5145 | (- (length (allout-chart-siblings)) |
19b84ba3 RS |
5146 | (length spec)))) |
5147 | (if (< 0 residue) | |
60c7bbd2 | 5148 | ;; Some residue -- cover it with prev-elem: |
19b84ba3 RS |
5149 | (setq spec (append (make-list residue prev-elem) |
5150 | spec))))))) | |
5151 | ((numberp curr-elem) | |
96b83743 | 5152 | (if (and (>= 0 curr-elem) (not (allout-hidden-p))) |
fd5359c6 | 5153 | (save-excursion (allout-hide-current-subtree t) |
19b84ba3 RS |
5154 | (if (> 0 curr-elem) |
5155 | nil | |
fd5359c6 | 5156 | (if (> allout-recent-end-of-subtree max-pos) |
19b84ba3 | 5157 | (setq max-pos |
fd5359c6 | 5158 | allout-recent-end-of-subtree))))) |
19b84ba3 | 5159 | (if (> (abs curr-elem) 0) |
fd5359c6 MR |
5160 | (progn (allout-show-children (abs curr-elem)) |
5161 | (if (> allout-recent-end-of-subtree max-pos) | |
5162 | (setq max-pos allout-recent-end-of-subtree))))) | |
19b84ba3 | 5163 | ((listp curr-elem) |
fd5359c6 MR |
5164 | (if (allout-descend-to-depth (1+ depth)) |
5165 | (let ((got (allout-expose-topic curr-elem))) | |
19b84ba3 RS |
5166 | (if (and got (> got max-pos)) (setq max-pos got)))))) |
5167 | (cond (stay (setq stay nil)) | |
5168 | ((listp (car spec)) nil) | |
5169 | ((> max-pos (point)) | |
5170 | ;; Capitalize on max-pos state to get us nearer next sibling: | |
5171 | (progn (goto-char (min (point-max) max-pos)) | |
fd5359c6 MR |
5172 | (allout-next-heading))) |
5173 | ((allout-next-sibling depth)))) | |
19b84ba3 | 5174 | max-pos))) |
fd5359c6 MR |
5175 | ;;;_ > allout-old-expose-topic (spec &rest followers) |
5176 | (defun allout-old-expose-topic (spec &rest followers) | |
d82979ea | 5177 | |
c07583cd | 5178 | "Deprecated. Use `allout-expose-topic' (with different schema |
d82979ea EZ |
5179 | format) instead. |
5180 | ||
5181 | Dictate wholesale exposure scheme for current topic, according to SPEC. | |
c567ac01 RS |
5182 | |
5183 | SPEC is either a number or a list. Optional successive args | |
5184 | dictate exposure for subsequent siblings of current topic. | |
5185 | ||
5186 | A simple spec (either a number, a special symbol, or the null list) | |
5187 | dictates the overall exposure for a topic. Non null lists are | |
5188 | composite specs whose first element dictates the overall exposure for | |
5189 | a topic, with the subsequent elements in the list interpreted as specs | |
5190 | that dictate the exposure for the successive offspring of the topic. | |
5191 | ||
5192 | Simple (numeric and null-list) specs are interpreted as follows: | |
5193 | ||
5194 | - Numbers indicate the relative depth to open the corresponding topic: | |
5195 | - negative numbers force the topic to be close before opening to the | |
5196 | absolute value of the number. | |
5197 | - positive numbers just open to the relative depth indicated by the number. | |
5198 | - 0 just closes | |
353e2ef2 KH |
5199 | - `*' completely opens the topic, including bodies. |
5200 | - `+' shows all the sub headers, but not the bodies | |
5201 | - `-' exposes the body and immediate offspring of the corresponding topic. | |
c567ac01 RS |
5202 | |
5203 | If the spec is a list, the first element must be a number, which | |
5204 | dictates the exposure depth of the topic as a whole. Subsequent | |
5205 | elements of the list are nested SPECs, dictating the specific exposure | |
5206 | for the corresponding offspring of the topic. | |
5207 | ||
e126900f | 5208 | Optional FOLLOWERS arguments dictate exposure for succeeding siblings." |
c567ac01 RS |
5209 | |
5210 | (interactive "xExposure spec: ") | |
0458fa80 EZ |
5211 | (let ((inhibit-field-text-motion t) |
5212 | (depth (allout-current-depth)) | |
c567ac01 RS |
5213 | max-pos) |
5214 | (cond ((null spec) nil) | |
5215 | ((symbolp spec) | |
fd5359c6 MR |
5216 | (if (eq spec '*) (allout-show-current-subtree)) |
5217 | (if (eq spec '+) (allout-show-current-branches)) | |
5218 | (if (eq spec '-) (allout-show-current-entry))) | |
c567ac01 RS |
5219 | ((numberp spec) |
5220 | (if (>= 0 spec) | |
fd5359c6 | 5221 | (save-excursion (allout-hide-current-subtree t) |
c567ac01 RS |
5222 | (end-of-line) |
5223 | (if (or (not max-pos) | |
5224 | (> (point) max-pos)) | |
5225 | (setq max-pos (point))) | |
5226 | (if (> 0 spec) | |
5227 | (setq spec (* -1 spec))))) | |
5228 | (if (> spec 0) | |
fd5359c6 | 5229 | (allout-show-children spec))) |
c567ac01 | 5230 | ((listp spec) |
fd5359c6 | 5231 | ;(let ((got (allout-old-expose-topic (car spec)))) |
c567ac01 RS |
5232 | ; (if (and got (or (not max-pos) (> got max-pos))) |
5233 | ; (setq max-pos got))) | |
fd5359c6 | 5234 | (let ((new-depth (+ (allout-current-depth) 1)) |
c567ac01 | 5235 | got) |
fd5359c6 | 5236 | (setq max-pos (allout-old-expose-topic (car spec))) |
c567ac01 RS |
5237 | (setq spec (cdr spec)) |
5238 | (if (and spec | |
fd5359c6 MR |
5239 | (allout-descend-to-depth new-depth) |
5240 | (not (allout-hidden-p))) | |
5241 | (progn (setq got (apply 'allout-old-expose-topic spec)) | |
c567ac01 RS |
5242 | (if (and got (or (not max-pos) (> got max-pos))) |
5243 | (setq max-pos got))))))) | |
5244 | (while (and followers | |
5245 | (progn (if (and max-pos (< (point) max-pos)) | |
5246 | (progn (goto-char max-pos) | |
5247 | (setq max-pos nil))) | |
5248 | (end-of-line) | |
fd5359c6 MR |
5249 | (allout-next-sibling depth))) |
5250 | (allout-old-expose-topic (car followers)) | |
c567ac01 RS |
5251 | (setq followers (cdr followers))) |
5252 | max-pos)) | |
fd5359c6 MR |
5253 | ;;;_ > allout-new-exposure '() |
5254 | (defmacro allout-new-exposure (&rest spec) | |
5255 | "Literal frontend for `allout-expose-topic', doesn't evaluate arguments. | |
2265e017 MR |
5256 | Some arguments that would need to be quoted in `allout-expose-topic' |
5257 | need not be quoted in `allout-new-exposure'. | |
c567ac01 RS |
5258 | |
5259 | Cursor is left at start position. | |
5260 | ||
d82979ea EZ |
5261 | Use this instead of obsolete `allout-exposure'. |
5262 | ||
c567ac01 | 5263 | Examples: |
bff05d9e | 5264 | \(allout-new-exposure (-1 () () () 1) 0) |
c567ac01 RS |
5265 | Close current topic at current level so only the immediate |
5266 | subtopics are shown, except also show the children of the | |
5267 | third subtopic; and close the next topic at the current level. | |
bff05d9e | 5268 | \(allout-new-exposure : -1 0) |
c567ac01 RS |
5269 | Close all topics at current level to expose only their |
5270 | immediate children, except for the last topic at the current | |
353e2ef2 | 5271 | level, in which even its immediate children are hidden. |
bff05d9e | 5272 | \(allout-new-exposure -2 : -1 *) |
c567ac01 RS |
5273 | Expose children and grandchildren of first topic at current |
5274 | level, and expose children of subsequent topics at current | |
5275 | level *except* for the last, which should be opened completely." | |
5276 | (list 'save-excursion | |
d8350998 | 5277 | '(if (not (or (allout-goto-prefix-doublechecked) |
fd5359c6 MR |
5278 | (allout-next-heading))) |
5279 | (error "allout-new-exposure: Can't find any outline topics")) | |
5280 | (list 'allout-expose-topic (list 'quote spec)))) | |
c567ac01 | 5281 | |
60c7bbd2 | 5282 | ;;;_ #7 Systematic outline presentation -- copying, printing, flattening |
19b84ba3 | 5283 | |
9179616f DL |
5284 | ;;;_ - Mapping and processing of topics |
5285 | ;;;_ ( See also Subtree Charting, in Navigation code.) | |
fd5359c6 MR |
5286 | ;;;_ > allout-stringify-flat-index (flat-index) |
5287 | (defun allout-stringify-flat-index (flat-index &optional context) | |
9179616f DL |
5288 | "Convert list representing section/subsection/... to document string. |
5289 | ||
5290 | Optional arg CONTEXT indicates interior levels to include." | |
5291 | (let ((delim ".") | |
71296446 | 5292 | result |
9179616f DL |
5293 | numstr |
5294 | (context-depth (or (and context 2) 1))) | |
5295 | ;; Take care of the explicit context: | |
5296 | (while (> context-depth 0) | |
5297 | (setq numstr (int-to-string (car flat-index)) | |
5298 | flat-index (cdr flat-index) | |
5299 | result (if flat-index | |
5300 | (cons delim (cons numstr result)) | |
5301 | (cons numstr result)) | |
5302 | context-depth (if flat-index (1- context-depth) 0))) | |
5303 | (setq delim " ") | |
5304 | ;; Take care of the indentation: | |
5305 | (if flat-index | |
5306 | (progn | |
5307 | (while flat-index | |
5308 | (setq result | |
5309 | (cons delim | |
5310 | (cons (make-string | |
5311 | (1+ (truncate (if (zerop (car flat-index)) | |
5312 | 1 | |
5313 | (log10 (car flat-index))))) | |
5314 | ? ) | |
5315 | result))) | |
5316 | (setq flat-index (cdr flat-index))) | |
5317 | ;; Dispose of single extra delim: | |
5318 | (setq result (cdr result)))) | |
5319 | (apply 'concat result))) | |
fd5359c6 MR |
5320 | ;;;_ > allout-stringify-flat-index-plain (flat-index) |
5321 | (defun allout-stringify-flat-index-plain (flat-index) | |
9179616f DL |
5322 | "Convert list representing section/subsection/... to document string." |
5323 | (let ((delim ".") | |
5324 | result) | |
5325 | (while flat-index | |
5326 | (setq result (cons (int-to-string (car flat-index)) | |
5327 | (if result | |
5328 | (cons delim result)))) | |
5329 | (setq flat-index (cdr flat-index))) | |
5330 | (apply 'concat result))) | |
fd5359c6 MR |
5331 | ;;;_ > allout-stringify-flat-index-indented (flat-index) |
5332 | (defun allout-stringify-flat-index-indented (flat-index) | |
9179616f DL |
5333 | "Convert list representing section/subsection/... to document string." |
5334 | (let ((delim ".") | |
71296446 | 5335 | result |
9179616f DL |
5336 | numstr) |
5337 | ;; Take care of the explicit context: | |
5338 | (setq numstr (int-to-string (car flat-index)) | |
5339 | flat-index (cdr flat-index) | |
5340 | result (if flat-index | |
5341 | (cons delim (cons numstr result)) | |
5342 | (cons numstr result))) | |
5343 | (setq delim " ") | |
5344 | ;; Take care of the indentation: | |
5345 | (if flat-index | |
5346 | (progn | |
5347 | (while flat-index | |
5348 | (setq result | |
5349 | (cons delim | |
5350 | (cons (make-string | |
5351 | (1+ (truncate (if (zerop (car flat-index)) | |
5352 | 1 | |
5353 | (log10 (car flat-index))))) | |
5354 | ? ) | |
5355 | result))) | |
5356 | (setq flat-index (cdr flat-index))) | |
5357 | ;; Dispose of single extra delim: | |
5358 | (setq result (cdr result)))) | |
5359 | (apply 'concat result))) | |
fd5359c6 MR |
5360 | ;;;_ > allout-listify-exposed (&optional start end format) |
5361 | (defun allout-listify-exposed (&optional start end format) | |
19b84ba3 | 5362 | |
9179616f | 5363 | "Produce a list representing exposed topics in current region. |
c567ac01 | 5364 | |
fd5359c6 | 5365 | This list can then be used by `allout-process-exposed' to manipulate |
9179616f | 5366 | the subject region. |
353e2ef2 | 5367 | |
9179616f | 5368 | Optional START and END indicate bounds of region. |
19b84ba3 | 5369 | |
75bcb912 | 5370 | Optional arg, FORMAT, designates an alternate presentation form for |
9179616f | 5371 | the prefix: |
c567ac01 | 5372 | |
60c7bbd2 | 5373 | list -- Present prefix as numeric section.subsection..., starting with |
9179616f | 5374 | section indicated by the list, innermost nesting first. |
60c7bbd2 | 5375 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5376 | except for distinctive bullets. |
c567ac01 | 5377 | |
9179616f DL |
5378 | The elements of the list produced are lists that represents a topic |
5379 | header and body. The elements of that list are: | |
c567ac01 | 5380 | |
9179616f DL |
5381 | - a number representing the depth of the topic, |
5382 | - a string representing the header-prefix, including trailing whitespace and | |
5383 | bullet. | |
5384 | - a string representing the bullet character, | |
5385 | - and a series of strings, each containing one line of the exposed | |
5386 | portion of the topic entry." | |
c567ac01 | 5387 | |
9179616f DL |
5388 | (interactive "r") |
5389 | (save-excursion | |
5390 | (let* | |
0458fa80 EZ |
5391 | ((inhibit-field-text-motion t) |
5392 | ;; state vars: | |
5393 | strings prefix result depth new-depth out gone-out bullet beg | |
9179616f | 5394 | next done) |
c567ac01 | 5395 | |
9179616f DL |
5396 | (goto-char start) |
5397 | (beginning-of-line) | |
5398 | ;; Goto initial topic, and register preceeding stuff, if any: | |
d8350998 | 5399 | (if (> (allout-goto-prefix-doublechecked) start) |
60c7bbd2 | 5400 | ;; First topic follows beginning point -- register preliminary stuff: |
9179616f DL |
5401 | (setq result (list (list 0 "" nil |
5402 | (buffer-substring start (1- (point))))))) | |
5403 | (while (and (not done) | |
5404 | (not (eobp)) ; Loop until we've covered the region. | |
5405 | (not (> (point) end))) | |
d8350998 | 5406 | (setq depth allout-recent-depth ; Current topics depth, |
fd5359c6 MR |
5407 | bullet (allout-recent-bullet) ; ... bullet, |
5408 | prefix (allout-recent-prefix) | |
5409 | beg (progn (allout-end-of-prefix t) (point))) ; and beginning. | |
9179616f | 5410 | (setq done ; The boundary for the current topic: |
fd5359c6 | 5411 | (not (allout-next-visible-heading 1))) |
d8350998 | 5412 | (setq new-depth allout-recent-depth) |
9179616f DL |
5413 | (setq gone-out out |
5414 | out (< new-depth depth)) | |
5415 | (beginning-of-line) | |
5416 | (setq next (point)) | |
5417 | (goto-char beg) | |
5418 | (setq strings nil) | |
5419 | (while (> next (point)) ; Get all the exposed text in | |
5420 | (setq strings | |
5421 | (cons (buffer-substring | |
5422 | beg | |
5423 | ;To hidden text or end of line: | |
5424 | (progn | |
96b83743 EZ |
5425 | (end-of-line) |
5426 | (allout-back-to-visible-text))) | |
9179616f | 5427 | strings)) |
96b83743 | 5428 | (when (< (point) next) ; Resume from after hid text, if any. |
1b4d97b2 CY |
5429 | (line-move 1) |
5430 | (beginning-of-line)) | |
9179616f DL |
5431 | (setq beg (point))) |
5432 | ;; Accumulate list for this topic: | |
5433 | (setq strings (nreverse strings)) | |
5434 | (setq result | |
5435 | (cons | |
5436 | (if format | |
5437 | (let ((special (if (string-match | |
5438 | (regexp-quote bullet) | |
fd5359c6 | 5439 | allout-distinctive-bullets-string) |
9179616f DL |
5440 | bullet))) |
5441 | (cond ((listp format) | |
5442 | (list depth | |
fd5359c6 MR |
5443 | (if allout-abbreviate-flattened-numbering |
5444 | (allout-stringify-flat-index format | |
9179616f | 5445 | gone-out) |
fd5359c6 | 5446 | (allout-stringify-flat-index-plain |
9179616f DL |
5447 | format)) |
5448 | strings | |
5449 | special)) | |
5450 | ((eq format 'indent) | |
5451 | (if special | |
5452 | (list depth | |
5453 | (concat (make-string (1+ depth) ? ) | |
5454 | (substring prefix -1)) | |
5455 | strings) | |
5456 | (list depth | |
5457 | (make-string depth ? ) | |
5458 | strings))) | |
fd5359c6 | 5459 | (t (error "allout-listify-exposed: %s %s" |
9179616f DL |
5460 | "invalid format" format)))) |
5461 | (list depth prefix strings)) | |
5462 | result)) | |
5463 | ;; Reasses format, if any: | |
5464 | (if (and format (listp format)) | |
5465 | (cond ((= new-depth depth) | |
5466 | (setq format (cons (1+ (car format)) | |
5467 | (cdr format)))) | |
60c7bbd2 | 5468 | ((> new-depth depth) ; descending -- assume by 1: |
9179616f DL |
5469 | (setq format (cons 1 format))) |
5470 | (t | |
5471 | ; Pop the residue: | |
5472 | (while (< new-depth depth) | |
5473 | (setq format (cdr format)) | |
5474 | (setq depth (1- depth))) | |
5475 | ; And increment the current one: | |
5476 | (setq format | |
5477 | (cons (1+ (or (car format) | |
5478 | -1)) | |
5479 | (cdr format))))))) | |
5480 | ;; Put the list with first at front, to last at back: | |
5481 | (nreverse result)))) | |
c60d543d RS |
5482 | ;;;_ > allout-region-active-p () |
5483 | (defmacro allout-region-active-p () | |
42c3e51c KM |
5484 | (cond ((fboundp 'use-region-p) '(use-region-p)) |
5485 | ((fboundp 'region-active-p) '(region-active-p)) | |
5486 | (t 'mark-active))) | |
5487 | ;;_ > allout-process-exposed (&optional func from to frombuf | |
9179616f | 5488 | ;;; tobuf format) |
fd5359c6 | 5489 | (defun allout-process-exposed (&optional func from to frombuf tobuf |
96b83743 | 5490 | format start-num) |
9179616f | 5491 | "Map function on exposed parts of current topic; results to another buffer. |
353e2ef2 | 5492 | |
d82979ea EZ |
5493 | All args are options; default values itemized below. |
5494 | ||
5495 | Apply FUNCTION to exposed portions FROM position TO position in buffer | |
9179616f DL |
5496 | FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an |
5497 | alternate presentation form: | |
c567ac01 | 5498 | |
60c7bbd2 | 5499 | `flat' -- Present prefix as numeric section.subsection..., starting with |
75bcb912 | 5500 | section indicated by the START-NUM, innermost nesting first. |
60c7bbd2 | 5501 | X`flat-indented' -- Prefix is like `flat' for first topic at each |
9179616f DL |
5502 | X level, but subsequent topics have only leaf topic |
5503 | X number, padded with blanks to line up with first. | |
60c7bbd2 | 5504 | `indent' (symbol) -- Convert header prefixes to all white space, |
9179616f | 5505 | except for distinctive bullets. |
c567ac01 | 5506 | |
9179616f | 5507 | Defaults: |
d82979ea | 5508 | FUNCTION: `allout-insert-listified' |
9179616f DL |
5509 | FROM: region start, if region active, else start of buffer |
5510 | TO: region end, if region active, else end of buffer | |
5511 | FROMBUF: current buffer | |
5512 | TOBUF: buffer name derived: \"*current-buffer-name exposed*\" | |
5513 | FORMAT: nil" | |
5514 | ||
5515 | ; Resolve arguments, | |
5516 | ; defaulting if necessary: | |
fd5359c6 | 5517 | (if (not func) (setq func 'allout-insert-listified)) |
9179616f | 5518 | (if (not (and from to)) |
c60d543d | 5519 | (if (allout-region-active-p) |
9179616f DL |
5520 | (setq from (region-beginning) to (region-end)) |
5521 | (setq from (point-min) to (point-max)))) | |
5522 | (if frombuf | |
5523 | (if (not (bufferp frombuf)) | |
60c7bbd2 | 5524 | ;; Specified but not a buffer -- get it: |
9179616f DL |
5525 | (let ((got (get-buffer frombuf))) |
5526 | (if (not got) | |
fd5359c6 | 5527 | (error (concat "allout-process-exposed: source buffer " |
9179616f DL |
5528 | frombuf |
5529 | " not found.")) | |
5530 | (setq frombuf got)))) | |
60c7bbd2 | 5531 | ;; not specified -- default it: |
9179616f DL |
5532 | (setq frombuf (current-buffer))) |
5533 | (if tobuf | |
5534 | (if (not (bufferp tobuf)) | |
5535 | (setq tobuf (get-buffer-create tobuf))) | |
60c7bbd2 | 5536 | ;; not specified -- default it: |
9179616f DL |
5537 | (setq tobuf (concat "*" (buffer-name frombuf) " exposed*"))) |
5538 | (if (listp format) | |
5539 | (nreverse format)) | |
5540 | ||
5541 | (let* ((listified | |
5542 | (progn (set-buffer frombuf) | |
fd5359c6 | 5543 | (allout-listify-exposed from to format)))) |
9179616f | 5544 | (set-buffer tobuf) |
5110e166 | 5545 | (mapc func listified) |
9179616f DL |
5546 | (pop-to-buffer tobuf))) |
5547 | ||
5548 | ;;;_ - Copy exposed | |
fd5359c6 MR |
5549 | ;;;_ > allout-insert-listified (listified) |
5550 | (defun allout-insert-listified (listified) | |
9179616f DL |
5551 | "Insert contents of listified outline portion in current buffer. |
5552 | ||
e126900f | 5553 | LISTIFIED is a list representing each topic header and body: |
9179616f DL |
5554 | |
5555 | \`(depth prefix text)' | |
5556 | ||
d82979ea | 5557 | or \`(depth prefix text bullet-plus)' |
9179616f DL |
5558 | |
5559 | If `bullet-plus' is specified, it is inserted just after the entire prefix." | |
5560 | (setq listified (cdr listified)) | |
5561 | (let ((prefix (prog1 | |
5562 | (car listified) | |
5563 | (setq listified (cdr listified)))) | |
5564 | (text (prog1 | |
5565 | (car listified) | |
5566 | (setq listified (cdr listified)))) | |
5567 | (bullet-plus (car listified))) | |
eac9cf5f PJ |
5568 | (insert prefix) |
5569 | (if bullet-plus (insert (concat " " bullet-plus))) | |
9179616f | 5570 | (while text |
eac9cf5f | 5571 | (insert (car text)) |
9179616f | 5572 | (if (setq text (cdr text)) |
0949617b | 5573 | (insert "\n"))) |
eac9cf5f | 5574 | (insert "\n"))) |
fd5359c6 MR |
5575 | ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format) |
5576 | (defun allout-copy-exposed-to-buffer (&optional arg tobuf format) | |
9179616f DL |
5577 | "Duplicate exposed portions of current outline to another buffer. |
5578 | ||
5579 | Other buffer has current buffers name with \" exposed\" appended to it. | |
5580 | ||
5581 | With repeat count, copy the exposed parts of only the current topic. | |
5582 | ||
5583 | Optional second arg TOBUF is target buffer name. | |
5584 | ||
5585 | Optional third arg FORMAT, if non-nil, symbolically designates an | |
5586 | alternate presentation format for the outline: | |
5587 | ||
5588 | `flat' - Convert topic header prefixes to numeric | |
5589 | section.subsection... identifiers. | |
5590 | `indent' - Convert header prefixes to all white space, except for | |
5591 | distinctive bullets. | |
5592 | `indent-flat' - The best of both - only the first of each level has | |
5593 | the full path, the rest have only the section number | |
5594 | of the leaf, preceded by the right amount of indentation." | |
c567ac01 RS |
5595 | |
5596 | (interactive "P") | |
5597 | (if (not tobuf) | |
5598 | (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*")))) | |
5599 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5600 | (beg (if arg (allout-back-to-current-heading) (point-min))) |
5601 | (end (if arg (allout-end-of-current-subtree) (point-max))) | |
9179616f DL |
5602 | (buf (current-buffer)) |
5603 | (start-list ())) | |
5604 | (if (eq format 'flat) | |
5605 | (setq format (if arg (save-excursion | |
5606 | (goto-char beg) | |
fd5359c6 | 5607 | (allout-topic-flat-index)) |
9179616f | 5608 | '(1)))) |
c567ac01 | 5609 | (save-excursion (set-buffer tobuf)(erase-buffer)) |
fd5359c6 | 5610 | (allout-process-exposed 'allout-insert-listified |
c567ac01 RS |
5611 | beg |
5612 | end | |
5613 | (current-buffer) | |
9179616f DL |
5614 | tobuf |
5615 | format start-list) | |
c567ac01 RS |
5616 | (goto-char (point-min)) |
5617 | (pop-to-buffer buf) | |
5618 | (goto-char start-pt))) | |
fd5359c6 MR |
5619 | ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf) |
5620 | (defun allout-flatten-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5621 | "Present numeric outline of outline's exposed portions in another buffer. |
5622 | ||
60c7bbd2 | 5623 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5624 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5625 | |
fd5359c6 | 5626 | Use `allout-indented-exposed-to-buffer' for indented presentation. |
9179616f DL |
5627 | |
5628 | With repeat count, copy the exposed portions of only current topic. | |
5629 | ||
e126900f | 5630 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5631 | it, unless optional second arg TOBUF is specified, in which case it is |
5632 | used verbatim." | |
5633 | (interactive "P") | |
fd5359c6 MR |
5634 | (allout-copy-exposed-to-buffer arg tobuf 'flat)) |
5635 | ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf) | |
5636 | (defun allout-indented-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
5637 | "Present indented outline of outline's exposed portions in another buffer. |
5638 | ||
60c7bbd2 | 5639 | The resulting outline is not compatible with outline mode -- use |
fd5359c6 | 5640 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 5641 | |
fd5359c6 | 5642 | Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation. |
9179616f DL |
5643 | |
5644 | With repeat count, copy the exposed portions of only current topic. | |
5645 | ||
e126900f | 5646 | Other buffer has current buffer's name with \" exposed\" appended to |
9179616f DL |
5647 | it, unless optional second arg TOBUF is specified, in which case it is |
5648 | used verbatim." | |
5649 | (interactive "P") | |
fd5359c6 | 5650 | (allout-copy-exposed-to-buffer arg tobuf 'indent)) |
c567ac01 RS |
5651 | |
5652 | ;;;_ - LaTeX formatting | |
e126900f JB |
5653 | ;;;_ > allout-latex-verb-quote (string &optional flow) |
5654 | (defun allout-latex-verb-quote (string &optional flow) | |
539d7736 | 5655 | "Return copy of STRING for literal reproduction across LaTeX processing. |
c07583cd | 5656 | Expresses the original characters (including carriage returns) of the |
539d7736 | 5657 | string across LaTeX processing." |
9179616f DL |
5658 | (mapconcat (function |
5659 | (lambda (char) | |
c567ac01 RS |
5660 | (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*)) |
5661 | (concat "\\char" (number-to-string char) "{}")) | |
5662 | ((= char ?\n) "\\\\") | |
9179616f | 5663 | (t (char-to-string char))))) |
e126900f | 5664 | string |
c567ac01 | 5665 | "")) |
fd5359c6 MR |
5666 | ;;;_ > allout-latex-verbatim-quote-curr-line () |
5667 | (defun allout-latex-verbatim-quote-curr-line () | |
c07583cd | 5668 | "Express line for exact (literal) representation across LaTeX processing. |
19b84ba3 | 5669 | |
c07583cd | 5670 | Adjust line contents so it is unaltered (from the original line) |
539d7736 | 5671 | across LaTeX processing, within the context of a `verbatim' |
c567ac01 | 5672 | environment. Leaves point at the end of the line." |
0458fa80 EZ |
5673 | (let ((inhibit-field-text-motion t)) |
5674 | (beginning-of-line) | |
5675 | (let ((beg (point)) | |
5676 | (end (progn (end-of-line)(point)))) | |
5677 | (goto-char beg) | |
2a1408fd DN |
5678 | (save-match-data |
5679 | (while (re-search-forward "\\\\" | |
5680 | ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#" | |
5681 | end ; bounded by end-of-line | |
5682 | 1) ; no matches, move to end & return nil | |
5683 | (goto-char (match-beginning 2)) | |
5684 | (insert "\\") | |
5685 | (setq end (1+ end)) | |
5686 | (goto-char (1+ (match-end 2)))))))) | |
e126900f JB |
5687 | ;;;_ > allout-insert-latex-header (buffer) |
5688 | (defun allout-insert-latex-header (buffer) | |
539d7736 | 5689 | "Insert initial LaTeX commands at point in BUFFER." |
c567ac01 RS |
5690 | ;; Much of this is being derived from the stuff in appendix of E in |
5691 | ;; the TeXBook, pg 421. | |
e126900f | 5692 | (set-buffer buffer) |
c567ac01 RS |
5693 | (let ((doc-style (format "\n\\documentstyle{%s}\n" |
5694 | "report")) | |
fd5359c6 | 5695 | (page-numbering (if allout-number-pages |
c567ac01 RS |
5696 | "\\pagestyle{empty}\n" |
5697 | "")) | |
c567ac01 | 5698 | (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5699 | allout-title-style)) |
c567ac01 | 5700 | (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n" |
fd5359c6 | 5701 | allout-label-style)) |
c567ac01 | 5702 | (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5703 | allout-head-line-style)) |
c567ac01 | 5704 | (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 5705 | allout-body-line-style)) |
c567ac01 RS |
5706 | (setlength (format "%s%s%s%s" |
5707 | "\\newlength{\\stepsize}\n" | |
5708 | "\\setlength{\\stepsize}{" | |
fd5359c6 | 5709 | allout-indent |
c567ac01 RS |
5710 | "}\n")) |
5711 | (oneheadline (format "%s%s%s%s%s%s%s" | |
5712 | "\\newcommand{\\OneHeadLine}[3]{%\n" | |
5713 | "\\noindent%\n" | |
5714 | "\\hspace*{#2\\stepsize}%\n" | |
5715 | "\\labelcmd{#1}\\hspace*{.2cm}" | |
5716 | "\\headlinecmd{#3}\\\\[" | |
fd5359c6 | 5717 | allout-line-skip |
c567ac01 RS |
5718 | "]\n}\n")) |
5719 | (onebodyline (format "%s%s%s%s%s%s" | |
5720 | "\\newcommand{\\OneBodyLine}[2]{%\n" | |
5721 | "\\noindent%\n" | |
5722 | "\\hspace*{#1\\stepsize}%\n" | |
5723 | "\\bodylinecmd{#2}\\\\[" | |
fd5359c6 | 5724 | allout-line-skip |
c567ac01 RS |
5725 | "]\n}\n")) |
5726 | (begindoc "\\begin{document}\n\\begin{center}\n") | |
5727 | (title (format "%s%s%s%s" | |
5728 | "\\titlecmd{" | |
fd5359c6 | 5729 | (allout-latex-verb-quote (if allout-title |
96b83743 | 5730 | (condition-case nil |
fd5359c6 | 5731 | (eval allout-title) |
d8350998 | 5732 | (error "<unnamed buffer>")) |
c567ac01 RS |
5733 | "Unnamed Outline")) |
5734 | "}\n" | |
5735 | "\\end{center}\n\n")) | |
5736 | (hsize "\\hsize = 7.5 true in\n") | |
5737 | (hoffset "\\hoffset = -1.5 true in\n") | |
5738 | (vspace "\\vspace{.1cm}\n\n")) | |
5739 | (insert (concat doc-style | |
5740 | page-numbering | |
5741 | titlecmd | |
5742 | labelcmd | |
5743 | headlinecmd | |
5744 | bodylinecmd | |
5745 | setlength | |
5746 | oneheadline | |
5747 | onebodyline | |
5748 | begindoc | |
5749 | title | |
5750 | hsize | |
5751 | hoffset | |
5752 | vspace) | |
5753 | ))) | |
e126900f JB |
5754 | ;;;_ > allout-insert-latex-trailer (buffer) |
5755 | (defun allout-insert-latex-trailer (buffer) | |
539d7736 | 5756 | "Insert concluding LaTeX commands at point in BUFFER." |
e126900f | 5757 | (set-buffer buffer) |
c567ac01 | 5758 | (insert "\n\\end{document}\n")) |
fd5359c6 MR |
5759 | ;;;_ > allout-latexify-one-item (depth prefix bullet text) |
5760 | (defun allout-latexify-one-item (depth prefix bullet text) | |
19b84ba3 RS |
5761 | "Insert LaTeX commands for formatting one outline item. |
5762 | ||
9179616f | 5763 | Args are the topics numeric DEPTH, the header PREFIX lead string, the |
19b84ba3 | 5764 | BULLET string, and a list of TEXT strings for the body." |
c567ac01 RS |
5765 | (let* ((head-line (if text (car text))) |
5766 | (body-lines (cdr text)) | |
5767 | (curr-line) | |
5768 | body-content bop) | |
5769 | ; Do the head line: | |
71296446 | 5770 | (insert (concat "\\OneHeadLine{\\verb\1 " |
d82979ea EZ |
5771 | (allout-latex-verb-quote bullet) |
5772 | "\1}{" | |
5773 | depth | |
5774 | "}{\\verb\1 " | |
5775 | (if head-line | |
5776 | (allout-latex-verb-quote head-line) | |
5777 | "") | |
5778 | "\1}\n")) | |
c567ac01 RS |
5779 | (if (not body-lines) |
5780 | nil | |
eac9cf5f PJ |
5781 | ;;(insert "\\beginlines\n") |
5782 | (insert "\\begin{verbatim}\n") | |
c567ac01 RS |
5783 | (while body-lines |
5784 | (setq curr-line (car body-lines)) | |
5785 | (if (and (not body-content) | |
5786 | (not (string-match "^\\s-*$" curr-line))) | |
5787 | (setq body-content t)) | |
5788 | ; Mangle any occurrences of | |
5789 | ; "\end{verbatim}" in text, | |
5790 | ; it's special: | |
5791 | (if (and body-content | |
5792 | (setq bop (string-match "\\end{verbatim}" curr-line))) | |
5793 | (setq curr-line (concat (substring curr-line 0 bop) | |
5794 | ">" | |
5795 | (substring curr-line bop)))) | |
eac9cf5f PJ |
5796 | ;;(insert "|" (car body-lines) "|") |
5797 | (insert curr-line) | |
fd5359c6 | 5798 | (allout-latex-verbatim-quote-curr-line) |
eac9cf5f | 5799 | (insert "\n") |
c567ac01 RS |
5800 | (setq body-lines (cdr body-lines))) |
5801 | (if body-content | |
5802 | (setq body-content nil) | |
5803 | (forward-char -1) | |
eac9cf5f | 5804 | (insert "\\ ") |
c567ac01 | 5805 | (forward-char 1)) |
eac9cf5f PJ |
5806 | ;;(insert "\\endlines\n") |
5807 | (insert "\\end{verbatim}\n") | |
c567ac01 | 5808 | ))) |
fd5359c6 MR |
5809 | ;;;_ > allout-latexify-exposed (arg &optional tobuf) |
5810 | (defun allout-latexify-exposed (arg &optional tobuf) | |
539d7736 | 5811 | "Format current topics exposed portions to TOBUF for LaTeX processing. |
19b84ba3 RS |
5812 | TOBUF defaults to a buffer named the same as the current buffer, but |
5813 | with \"*\" prepended and \" latex-formed*\" appended. | |
c567ac01 RS |
5814 | |
5815 | With repeat count, copy the exposed portions of entire buffer." | |
5816 | ||
5817 | (interactive "P") | |
5818 | (if (not tobuf) | |
5819 | (setq tobuf | |
5820 | (get-buffer-create (concat "*" (buffer-name) " latexified*")))) | |
5821 | (let* ((start-pt (point)) | |
fd5359c6 MR |
5822 | (beg (if arg (point-min) (allout-back-to-current-heading))) |
5823 | (end (if arg (point-max) (allout-end-of-current-subtree))) | |
c567ac01 RS |
5824 | (buf (current-buffer))) |
5825 | (set-buffer tobuf) | |
1977b8f6 | 5826 | (erase-buffer) |
fd5359c6 | 5827 | (allout-insert-latex-header tobuf) |
c567ac01 | 5828 | (goto-char (point-max)) |
fd5359c6 | 5829 | (allout-process-exposed 'allout-latexify-one-item |
c567ac01 RS |
5830 | beg |
5831 | end | |
5832 | buf | |
5833 | tobuf) | |
5834 | (goto-char (point-max)) | |
fd5359c6 | 5835 | (allout-insert-latex-trailer tobuf) |
1977b8f6 | 5836 | (goto-char (point-min)) |
c567ac01 RS |
5837 | (pop-to-buffer buf) |
5838 | (goto-char start-pt))) | |
5839 | ||
d82979ea | 5840 | ;;;_ #8 Encryption |
0949617b EZ |
5841 | ;;;_ > allout-toggle-current-subtree-encryption (&optional fetch-pass) |
5842 | (defun allout-toggle-current-subtree-encryption (&optional fetch-pass) | |
69027dea | 5843 | "Encrypt clear or decrypt encoded text of visibly-containing topic's contents. |
d82979ea | 5844 | |
0949617b | 5845 | Optional FETCH-PASS universal argument provokes key-pair encryption with |
c07583cd | 5846 | single universal argument. With doubled universal argument (value = 16), |
0949617b EZ |
5847 | it forces prompting for the passphrase regardless of availability from the |
5848 | passphrase cache. With no universal argument, the appropriate passphrase | |
69027dea | 5849 | is obtained from the cache, if available, else from the user. |
d82979ea | 5850 | |
6eb0a10d | 5851 | Only GnuPG encryption is supported. |
d82979ea | 5852 | |
6eb0a10d | 5853 | \*NOTE WELL* that the encrypted text must be ascii-armored. For gnupg |
d82979ea EZ |
5854 | encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file. |
5855 | ||
5856 | Both symmetric-key and key-pair encryption is implemented. Symmetric is | |
c07583cd | 5857 | the default, use a single (x4) universal argument for keypair mode. |
d82979ea EZ |
5858 | |
5859 | Encrypted topic's bullet is set to a `~' to signal that the contents of the | |
c07583cd | 5860 | topic (body and subtopics, but not heading) is pending encryption or |
0949617b EZ |
5861 | encrypted. `*' asterisk immediately after the bullet signals that the body |
5862 | is encrypted, its' absence means the topic is meant to be encrypted but is | |
5863 | not. When a file with topics pending encryption is saved, topics pending | |
5864 | encryption are encrypted. See allout-encrypt-unencrypted-on-saves for | |
5865 | auto-encryption specifics. | |
5866 | ||
6eb0a10d | 5867 | \*NOTE WELL* that automatic encryption that happens during saves will |
60c7bbd2 | 5868 | default to symmetric encryption -- you must deliberately (re)encrypt key-pair |
0949617b | 5869 | encrypted topics if you want them to continue to use the key-pair cipher. |
d82979ea | 5870 | |
d8350998 | 5871 | Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be |
d82979ea EZ |
5872 | encrypted. If you want to encrypt the contents of a top-level topic, use |
5873 | \\[allout-shift-in] to increase its depth. | |
5874 | ||
0949617b EZ |
5875 | Passphrase Caching |
5876 | ||
5877 | The encryption passphrase is solicited if not currently available in the | |
5878 | passphrase cache from a recent encryption action. | |
5879 | ||
6eb0a10d EZ |
5880 | The solicited passphrase is retained for reuse in a cache, if enabled. See |
5881 | `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry' for details. | |
0949617b EZ |
5882 | |
5883 | Symmetric Passphrase Hinting and Verification | |
5884 | ||
5885 | If the file previously had no associated passphrase, or had a different | |
5886 | passphrase than specified, the user is prompted to repeat the new one for | |
5887 | corroboration. A random string encrypted by the new passphrase is set on | |
5888 | the buffer-specific variable `allout-passphrase-verifier-string', for | |
5889 | confirmation of the passphrase when next obtained, before encrypting or | |
5890 | decrypting anything with it. This helps avoid mistakenly shifting between | |
5891 | keys. | |
5892 | ||
5893 | If allout customization var `allout-passphrase-verifier-handling' is | |
5894 | non-nil, an entry for `allout-passphrase-verifier-string' and its value is | |
5895 | added to an Emacs 'local variables' section at the end of the file, which | |
5896 | is created if necessary. That setting is for retention of the passphrase | |
a0a022d5 | 5897 | verifier across Emacs sessions. |
0949617b EZ |
5898 | |
5899 | Similarly, `allout-passphrase-hint-string' stores a user-provided reminder | |
5900 | about their passphrase, and `allout-passphrase-hint-handling' specifies | |
5901 | when the hint is presented, or if passphrase hints are disabled. If | |
c07583cd | 5902 | enabled (see the `allout-passphrase-hint-handling' docstring for details), |
0949617b EZ |
5903 | the hint string is stored in the local-variables section of the file, and |
5904 | solicited whenever the passphrase is changed." | |
69027dea EZ |
5905 | (interactive "P") |
5906 | (save-excursion | |
5907 | (allout-back-to-current-heading) | |
96b83743 | 5908 | (allout-toggle-subtree-encryption fetch-pass) |
69027dea EZ |
5909 | ) |
5910 | ) | |
5911 | ;;;_ > allout-toggle-subtree-encryption (&optional fetch-pass) | |
5912 | (defun allout-toggle-subtree-encryption (&optional fetch-pass) | |
c07583cd | 5913 | "Encrypt clear text or decrypt encoded topic contents (body and subtopics.) |
69027dea EZ |
5914 | |
5915 | Optional FETCH-PASS universal argument provokes key-pair encryption with | |
c07583cd | 5916 | single universal argument. With doubled universal argument (value = 16), |
69027dea EZ |
5917 | it forces prompting for the passphrase regardless of availability from the |
5918 | passphrase cache. With no universal argument, the appropriate passphrase | |
5919 | is obtained from the cache, if available, else from the user. | |
5920 | ||
e14adf87 CY |
5921 | Currently only GnuPG encryption is supported, and integration |
5922 | with gpg-agent is not yet implemented. | |
69027dea EZ |
5923 | |
5924 | \**NOTE WELL** that the encrypted text must be ascii-armored. For gnupg | |
5925 | encryption, include the option ``armor'' in your ~/.gnupg/gpg.conf file. | |
5926 | ||
5927 | See `allout-toggle-current-subtree-encryption' for more details." | |
d82979ea EZ |
5928 | |
5929 | (interactive "P") | |
5930 | (save-excursion | |
5931 | (allout-end-of-prefix t) | |
5932 | ||
d8350998 | 5933 | (if (= allout-recent-depth 1) |
d82979ea EZ |
5934 | (error (concat "Cannot encrypt or decrypt level 1 topics -" |
5935 | " shift it in to make it encryptable"))) | |
5936 | ||
d82979ea | 5937 | (let* ((allout-buffer (current-buffer)) |
498a6493 | 5938 | ;; Assess location: |
d8350998 | 5939 | (bullet-pos allout-recent-prefix-beginning) |
d82979ea EZ |
5940 | (after-bullet-pos (point)) |
5941 | (was-encrypted | |
5942 | (progn (if (= (point-max) after-bullet-pos) | |
5943 | (error "no body to encrypt")) | |
0949617b | 5944 | (allout-encrypted-topic-p))) |
96b83743 | 5945 | (was-collapsed (if (not (search-forward "\n" nil t)) |
d82979ea EZ |
5946 | nil |
5947 | (backward-char 1) | |
96b83743 | 5948 | (allout-hidden-p))) |
d82979ea EZ |
5949 | (subtree-beg (1+ (point))) |
5950 | (subtree-end (allout-end-of-subtree)) | |
5951 | (subject-text (buffer-substring-no-properties subtree-beg | |
5952 | subtree-end)) | |
5953 | (subtree-end-char (char-after (1- subtree-end))) | |
96b83743 | 5954 | (subtree-trailing-char (char-after subtree-end)) |
60c7bbd2 | 5955 | ;; kluge -- result-text needs to be nil, but we also want to |
96b83743 EZ |
5956 | ;; check for the error condition |
5957 | (result-text (if (or (string= "" subject-text) | |
5958 | (string= "\n" subject-text)) | |
5959 | (error "No topic contents to %scrypt" | |
5960 | (if was-encrypted "de" "en")) | |
5961 | nil)) | |
d82979ea | 5962 | ;; Assess key parameters: |
0949617b | 5963 | (key-info (or |
d82979ea EZ |
5964 | ;; detect the type by which it is already encrypted |
5965 | (and was-encrypted | |
0949617b EZ |
5966 | (allout-encrypted-key-info subject-text)) |
5967 | (and (member fetch-pass '(4 (4))) | |
5968 | '(keypair nil)) | |
5969 | '(symmetric nil))) | |
5970 | (for-key-type (car key-info)) | |
5971 | (for-key-identity (cadr key-info)) | |
498a6493 CY |
5972 | (fetch-pass (and fetch-pass (member fetch-pass '(16 (16))))) |
5973 | (was-coding-system buffer-file-coding-system)) | |
5974 | ||
5975 | (when (not was-encrypted) | |
5976 | ;; ensure that non-ascii chars pending encryption are noticed before | |
116f996b | 5977 | ;; they're encrypted, so the coding system is set to accommodate |
498a6493 CY |
5978 | ;; them. |
5979 | (setq buffer-file-coding-system | |
5980 | (select-safe-coding-system subtree-beg subtree-end)) | |
5981 | ;; if the coding system for the text being encrypted is different | |
5982 | ;; than that prevailing, then there a real risk that the coding | |
5983 | ;; system can't be noticed by emacs when the file is visited. to | |
5984 | ;; mitigate that, offer to preserve the coding system using a file | |
5985 | ;; local variable. | |
5986 | (if (and (not (equal buffer-file-coding-system | |
5987 | was-coding-system)) | |
5988 | (yes-or-no-p | |
5989 | (format (concat "Register coding system %s as file local" | |
5990 | " var? Necessary when only encrypted text" | |
5991 | " is in that coding system. ") | |
5992 | buffer-file-coding-system))) | |
5993 | (allout-adjust-file-variable "buffer-file-coding-system" | |
5994 | buffer-file-coding-system))) | |
d82979ea EZ |
5995 | |
5996 | (setq result-text | |
5997 | (allout-encrypt-string subject-text was-encrypted | |
0949617b EZ |
5998 | (current-buffer) |
5999 | for-key-type for-key-identity fetch-pass)) | |
d82979ea EZ |
6000 | |
6001 | ;; Replace the subtree with the processed product. | |
6002 | (allout-unprotected | |
6003 | (progn | |
6004 | (set-buffer allout-buffer) | |
6005 | (delete-region subtree-beg subtree-end) | |
6006 | (insert result-text) | |
6007 | (if was-collapsed | |
96b83743 EZ |
6008 | (allout-flag-region (1- subtree-beg) (point) t)) |
6009 | ;; adjust trailing-blank-lines to preserve topic spacing: | |
d82979ea | 6010 | (if (not was-encrypted) |
96b83743 EZ |
6011 | (if (and (= subtree-end-char ?\n) |
6012 | (= subtree-trailing-char ?\n)) | |
6013 | (insert subtree-trailing-char))) | |
d82979ea EZ |
6014 | ;; Ensure that the item has an encrypted-entry bullet: |
6015 | (if (not (string= (buffer-substring-no-properties | |
6016 | (1- after-bullet-pos) after-bullet-pos) | |
6017 | allout-topic-encryption-bullet)) | |
6018 | (progn (goto-char (1- after-bullet-pos)) | |
6019 | (delete-char 1) | |
6020 | (insert allout-topic-encryption-bullet))) | |
6021 | (if was-encrypted | |
6022 | ;; Remove the is-encrypted bullet qualifier: | |
6023 | (progn (goto-char after-bullet-pos) | |
6024 | (delete-char 1)) | |
6025 | ;; Add the is-encrypted bullet qualifier: | |
6026 | (goto-char after-bullet-pos) | |
d8350998 | 6027 | (insert "*")))) |
1b4d97b2 CY |
6028 | (run-hook-with-args 'allout-structure-added-hook |
6029 | bullet-pos subtree-end)))) | |
0949617b EZ |
6030 | ;;;_ > allout-encrypt-string (text decrypt allout-buffer key-type for-key |
6031 | ;;; fetch-pass &optional retried verifying | |
6032 | ;;; passphrase) | |
6033 | (defun allout-encrypt-string (text decrypt allout-buffer key-type for-key | |
48bd8440 EZ |
6034 | fetch-pass &optional retried rejected |
6035 | verifying passphrase) | |
0949617b | 6036 | "Encrypt or decrypt message TEXT. |
d82979ea | 6037 | |
0949617b | 6038 | If DECRYPT is true (default false), then decrypt instead of encrypt. |
d82979ea | 6039 | |
0949617b | 6040 | FETCH-PASS (default false) forces fresh prompting for the passphrase. |
d82979ea | 6041 | |
60c7bbd2 RS |
6042 | KEY-TYPE, either `symmetric' or `keypair', specifies which type |
6043 | of cypher to use. | |
d82979ea | 6044 | |
0949617b EZ |
6045 | FOR-KEY is human readable identification of the first of the user's |
6046 | eligible secret keys a keypair decryption targets, or else nil. | |
d82979ea | 6047 | |
60c7bbd2 | 6048 | Optional RETRIED is for internal use -- conveys the number of failed keys |
0949617b EZ |
6049 | that have been solicited in sequence leading to this current call. |
6050 | ||
6051 | Optional PASSPHRASE enables explicit delivery of the decryption passphrase, | |
6052 | for verification purposes. | |
d82979ea | 6053 | |
60c7bbd2 | 6054 | Optional REJECTED is for internal use -- conveys the number of |
48bd8440 EZ |
6055 | rejections due to matches against |
6056 | `allout-encryption-ciphertext-rejection-regexps', as limited by | |
6057 | `allout-encryption-ciphertext-rejection-ceiling'. | |
6058 | ||
0949617b | 6059 | Returns the resulting string, or nil if the transformation fails." |
d82979ea | 6060 | |
0949617b EZ |
6061 | (require 'pgg) |
6062 | ||
69027dea EZ |
6063 | (if (not (fboundp 'pgg-encrypt-symmetric)) |
6064 | (error "Allout encryption depends on a newer version of pgg")) | |
6065 | ||
0949617b EZ |
6066 | (let* ((scheme (upcase |
6067 | (format "%s" (or pgg-scheme pgg-default-scheme "GPG")))) | |
6068 | (for-key (and (equal key-type 'keypair) | |
6069 | (or for-key | |
6070 | (split-string (read-string | |
6071 | (format "%s message recipients: " | |
6072 | scheme)) | |
6073 | "[ \t,]+")))) | |
6074 | (target-prompt-id (if (equal key-type 'keypair) | |
6075 | (if (= (length for-key) 1) | |
6076 | (car for-key) for-key) | |
6077 | (buffer-name allout-buffer))) | |
6078 | (target-cache-id (format "%s-%s" | |
6079 | key-type | |
6080 | (if (equal key-type 'keypair) | |
6081 | target-prompt-id | |
6082 | (or (buffer-file-name allout-buffer) | |
6083 | target-prompt-id)))) | |
498a6493 CY |
6084 | (encoding (with-current-buffer allout-buffer |
6085 | buffer-file-coding-system)) | |
6086 | (multibyte (with-current-buffer allout-buffer | |
6087 | enable-multibyte-characters)) | |
48bd8440 EZ |
6088 | (strip-plaintext-regexps |
6089 | (if (not decrypt) | |
6090 | (allout-get-configvar-values | |
6091 | 'allout-encryption-plaintext-sanitization-regexps))) | |
6092 | (reject-ciphertext-regexps | |
6093 | (if (not decrypt) | |
6094 | (allout-get-configvar-values | |
6095 | 'allout-encryption-ciphertext-rejection-regexps))) | |
6096 | (rejected (or rejected 0)) | |
6097 | (rejections-left (- allout-encryption-ciphertext-rejection-ceiling | |
6098 | rejected)) | |
e14adf87 | 6099 | result-text status |
38b2ca53 | 6100 | ) |
0949617b EZ |
6101 | |
6102 | (if (and fetch-pass (not passphrase)) | |
6103 | ;; Force later fetch by evicting passphrase from the cache. | |
6104 | (pgg-remove-passphrase-from-cache target-cache-id t)) | |
6105 | ||
6106 | (catch 'encryption-failed | |
6107 | ||
6eb0a10d EZ |
6108 | ;; We handle only symmetric-key passphrase caching. |
6109 | (if (and (not passphrase) | |
6110 | (not (equal key-type 'keypair))) | |
0949617b EZ |
6111 | (setq passphrase (allout-obtain-passphrase for-key |
6112 | target-cache-id | |
6113 | target-prompt-id | |
6114 | key-type | |
6115 | allout-buffer | |
6116 | retried fetch-pass))) | |
48bd8440 | 6117 | |
0949617b EZ |
6118 | (with-temp-buffer |
6119 | ||
96b83743 | 6120 | (insert text) |
d82979ea | 6121 | |
498a6493 CY |
6122 | ;; convey the text characteristics of the original buffer: |
6123 | (set-buffer-multibyte multibyte) | |
6124 | (when encoding | |
6125 | (set-buffer-file-coding-system encoding) | |
6126 | (if (not decrypt) | |
6127 | (encode-coding-region (point-min) (point-max) encoding))) | |
6128 | ||
48bd8440 EZ |
6129 | (when (and strip-plaintext-regexps (not decrypt)) |
6130 | (dolist (re strip-plaintext-regexps) | |
6131 | (let ((re (if (listp re) (car re) re)) | |
6132 | (replacement (if (listp re) (cadr re) ""))) | |
6133 | (goto-char (point-min)) | |
2a1408fd DN |
6134 | (save-match-data |
6135 | (while (re-search-forward re nil t) | |
6136 | (replace-match replacement nil nil)))))) | |
48bd8440 | 6137 | |
0949617b | 6138 | (cond |
d82979ea | 6139 | |
0949617b EZ |
6140 | ;; symmetric: |
6141 | ((equal key-type 'symmetric) | |
6142 | (setq status | |
6143 | (if decrypt | |
6144 | ||
6145 | (pgg-decrypt (point-min) (point-max) passphrase) | |
6146 | ||
6147 | (pgg-encrypt-symmetric (point-min) (point-max) | |
6148 | passphrase))) | |
6149 | ||
6150 | (if status | |
6151 | (pgg-situate-output (point-min) (point-max)) | |
60c7bbd2 | 6152 | ;; failed -- handle passphrase caching |
0949617b EZ |
6153 | (if verifying |
6154 | (throw 'encryption-failed nil) | |
6155 | (pgg-remove-passphrase-from-cache target-cache-id t) | |
60c7bbd2 | 6156 | (error "Symmetric-cipher %scryption failed -- %s" |
48bd8440 | 6157 | (if decrypt "de" "en") |
60c7bbd2 | 6158 | "try again with different passphrase")))) |
0949617b | 6159 | |
ea18b2b1 | 6160 | ;; encrypt `keypair': |
0949617b EZ |
6161 | ((not decrypt) |
6162 | ||
6163 | (setq status | |
6164 | ||
6165 | (pgg-encrypt for-key | |
6166 | nil (point-min) (point-max) passphrase)) | |
6167 | ||
6168 | (if status | |
6169 | (pgg-situate-output (point-min) (point-max)) | |
6170 | (error (pgg-remove-passphrase-from-cache target-cache-id t) | |
6171 | (error "encryption failed")))) | |
6172 | ||
ea18b2b1 | 6173 | ;; decrypt `keypair': |
0949617b EZ |
6174 | (t |
6175 | ||
6176 | (setq status | |
6177 | (pgg-decrypt (point-min) (point-max) passphrase)) | |
6178 | ||
6179 | (if status | |
6180 | (pgg-situate-output (point-min) (point-max)) | |
6181 | (error (pgg-remove-passphrase-from-cache target-cache-id t) | |
48bd8440 | 6182 | (error "decryption failed"))))) |
0949617b EZ |
6183 | |
6184 | (setq result-text | |
d8350998 CY |
6185 | (buffer-substring-no-properties |
6186 | 1 (- (point-max) (if decrypt 0 1)))) | |
d82979ea | 6187 | ) |
48bd8440 | 6188 | |
60c7bbd2 | 6189 | ;; validate result -- non-empty |
48bd8440 EZ |
6190 | (cond ((not result-text) |
6191 | (if verifying | |
6192 | nil | |
6193 | ;; transform was fruitless, retry w/new passphrase. | |
6194 | (pgg-remove-passphrase-from-cache target-cache-id t) | |
6195 | (allout-encrypt-string text decrypt allout-buffer | |
6196 | key-type for-key nil | |
6197 | (if retried (1+ retried) 1) | |
6198 | rejected verifying nil))) | |
6199 | ||
6200 | ;; Retry (within limit) if ciphertext contains rejections: | |
6201 | ((and (not decrypt) | |
6202 | ;; Check for disqualification of this ciphertext: | |
6203 | (let ((regexps reject-ciphertext-regexps) | |
6204 | reject-it) | |
6205 | (while (and regexps (not reject-it)) | |
6206 | (setq reject-it (string-match (car regexps) | |
6207 | result-text)) | |
6208 | (pop regexps)) | |
6209 | reject-it)) | |
6210 | (setq rejections-left (1- rejections-left)) | |
6211 | (if (<= rejections-left 0) | |
6212 | (error (concat "Ciphertext rejected too many times" | |
6213 | " (%s), per `%s'") | |
6214 | allout-encryption-ciphertext-rejection-ceiling | |
6215 | 'allout-encryption-ciphertext-rejection-regexps) | |
6216 | (allout-encrypt-string text decrypt allout-buffer | |
6217 | key-type for-key nil | |
6218 | retried (1+ rejected) | |
6219 | verifying passphrase))) | |
6220 | ;; Barf if encryption yields extraordinary control chars: | |
6221 | ((and (not decrypt) | |
6222 | (string-match "[\C-a\C-k\C-o-\C-z\C-@]" | |
6223 | result-text)) | |
6224 | (error (concat "Encryption produced non-armored text, which" | |
60c7bbd2 | 6225 | "conflicts with allout mode -- reconfigure!"))) |
48bd8440 EZ |
6226 | |
6227 | ;; valid result and just verifying or non-symmetric: | |
6228 | ((or verifying (not (equal key-type 'symmetric))) | |
6229 | (if (or verifying decrypt) | |
6230 | (pgg-add-passphrase-to-cache target-cache-id | |
6231 | passphrase t)) | |
6232 | result-text) | |
6233 | ||
60c7bbd2 | 6234 | ;; valid result and regular symmetric -- "register" |
48bd8440 EZ |
6235 | ;; passphrase with mnemonic aids/cache. |
6236 | (t | |
6237 | (set-buffer allout-buffer) | |
6238 | (if passphrase | |
6239 | (pgg-add-passphrase-to-cache target-cache-id | |
6240 | passphrase t)) | |
6241 | (allout-update-passphrase-mnemonic-aids for-key passphrase | |
6242 | allout-buffer) | |
6243 | result-text) | |
6244 | ) | |
d82979ea | 6245 | ) |
d82979ea EZ |
6246 | ) |
6247 | ) | |
0949617b EZ |
6248 | ;;;_ > allout-obtain-passphrase (for-key cache-id prompt-id key-type |
6249 | ;;; allout-buffer retried fetch-pass) | |
4034b0e2 | 6250 | (defun allout-obtain-passphrase (for-key cache-id prompt-id key-type |
0949617b EZ |
6251 | allout-buffer retried fetch-pass) |
6252 | "Obtain passphrase for a key from the cache or else from the user. | |
6253 | ||
6254 | When obtaining from the user, symmetric-cipher passphrases are verified | |
6255 | against either, if available and enabled, a random string that was | |
6256 | encrypted against the passphrase, or else against repeated entry by the | |
6257 | user for corroboration. | |
6258 | ||
6259 | FOR-KEY is the key for which the passphrase is being obtained. | |
6260 | ||
6261 | CACHE-ID is the cache id of the key for the passphrase. | |
6262 | ||
6263 | PROMPT-ID is the id for use when prompting the user. | |
6264 | ||
60c7bbd2 | 6265 | KEY-TYPE is either `symmetric' or `keypair'. |
0949617b EZ |
6266 | |
6267 | ALLOUT-BUFFER is the buffer containing the entry being en/decrypted. | |
6268 | ||
6269 | RETRIED is the number of this attempt to obtain this passphrase. | |
6270 | ||
6271 | FETCH-PASS causes the passphrase to be solicited from the user, regardless | |
6272 | of the availability of a cached copy." | |
d82979ea EZ |
6273 | |
6274 | (if (not (equal key-type 'symmetric)) | |
0949617b EZ |
6275 | ;; do regular passphrase read on non-symmetric passphrase: |
6276 | (pgg-read-passphrase (format "%s passphrase%s: " | |
6277 | (upcase (format "%s" (or pgg-scheme | |
6278 | pgg-default-scheme | |
6279 | "GPG"))) | |
6280 | (if prompt-id | |
6281 | (format " for %s" prompt-id) | |
6282 | "")) | |
6283 | cache-id t) | |
d82979ea EZ |
6284 | |
6285 | ;; Symmetric hereon: | |
6286 | ||
6287 | (save-excursion | |
6288 | (set-buffer allout-buffer) | |
0949617b EZ |
6289 | (let* ((hint (if (and (not (string= allout-passphrase-hint-string "")) |
6290 | (or (equal allout-passphrase-hint-handling 'always) | |
6291 | (and (equal allout-passphrase-hint-handling | |
6292 | 'needed) | |
d82979ea | 6293 | retried))) |
0949617b | 6294 | (format " [%s]" allout-passphrase-hint-string) |
d82979ea EZ |
6295 | "")) |
6296 | (retry-message (if retried (format " (%s retry)" retried) "")) | |
0949617b EZ |
6297 | (prompt-sans-hint (format "'%s' symmetric passphrase%s: " |
6298 | prompt-id retry-message)) | |
6299 | (full-prompt (format "'%s' symmetric passphrase%s%s: " | |
6300 | prompt-id hint retry-message)) | |
d82979ea | 6301 | (prompt full-prompt) |
0949617b EZ |
6302 | (verifier-string (allout-get-encryption-passphrase-verifier)) |
6303 | ||
6304 | (cached (and (not fetch-pass) | |
6305 | (pgg-read-passphrase-from-cache cache-id t))) | |
6306 | (got-pass (or cached | |
6307 | (pgg-read-passphrase full-prompt cache-id t))) | |
d82979ea EZ |
6308 | confirmation) |
6309 | ||
0949617b | 6310 | (if (not got-pass) |
d82979ea EZ |
6311 | nil |
6312 | ||
0949617b | 6313 | ;; Duplicate our handle on the passphrase so it's not clobbered by |
d82979ea | 6314 | ;; deactivate-passwd memory clearing: |
48bd8440 | 6315 | (setq got-pass (copy-sequence got-pass)) |
d82979ea EZ |
6316 | |
6317 | (cond (verifier-string | |
0949617b EZ |
6318 | (save-window-excursion |
6319 | (if (allout-encrypt-string verifier-string 'decrypt | |
6320 | allout-buffer 'symmetric | |
48bd8440 EZ |
6321 | for-key nil 0 0 'verifying |
6322 | (copy-sequence got-pass)) | |
0949617b EZ |
6323 | (setq confirmation (format "%s" got-pass)))) |
6324 | ||
6325 | (if (and (not confirmation) | |
d82979ea | 6326 | (if (yes-or-no-p |
0949617b | 6327 | (concat "Passphrase differs from established" |
60c7bbd2 | 6328 | " -- use new one instead? ")) |
d82979ea EZ |
6329 | ;; deactivate password for subsequent |
6330 | ;; confirmation: | |
0949617b EZ |
6331 | (progn |
6332 | (pgg-remove-passphrase-from-cache cache-id t) | |
6333 | (setq prompt prompt-sans-hint) | |
6334 | nil) | |
d82979ea | 6335 | t)) |
0949617b EZ |
6336 | (progn (pgg-remove-passphrase-from-cache cache-id t) |
6337 | (error "Wrong passphrase.")))) | |
60c7bbd2 | 6338 | ;; No verifier string -- force confirmation by repetition of |
0949617b EZ |
6339 | ;; (new) passphrase: |
6340 | ((or fetch-pass (not cached)) | |
6341 | (pgg-remove-passphrase-from-cache cache-id t)))) | |
60c7bbd2 | 6342 | ;; confirmation vs new input -- doing pgg-read-passphrase will do the |
d82979ea | 6343 | ;; right thing, in either case: |
0949617b EZ |
6344 | (if (not confirmation) |
6345 | (setq confirmation | |
6346 | (pgg-read-passphrase (concat prompt | |
6347 | " ... confirm spelling: ") | |
6348 | cache-id t))) | |
d82979ea | 6349 | (prog1 |
0949617b | 6350 | (if (equal got-pass confirmation) |
d82979ea EZ |
6351 | confirmation |
6352 | (if (yes-or-no-p (concat "spelling of original and" | |
60c7bbd2 | 6353 | " confirmation differ -- retry? ")) |
d82979ea | 6354 | (progn (setq retried (if retried (1+ retried) 1)) |
0949617b | 6355 | (pgg-remove-passphrase-from-cache cache-id t) |
d82979ea | 6356 | ;; recurse to this routine: |
0949617b EZ |
6357 | (pgg-read-passphrase prompt-sans-hint cache-id t)) |
6358 | (pgg-remove-passphrase-from-cache cache-id t) | |
48bd8440 | 6359 | (error "Confirmation failed.")))))))) |
d82979ea EZ |
6360 | ;;;_ > allout-encrypted-topic-p () |
6361 | (defun allout-encrypted-topic-p () | |
6362 | "True if the current topic is encryptable and encrypted." | |
6363 | (save-excursion | |
6364 | (allout-end-of-prefix t) | |
6365 | (and (string= (buffer-substring-no-properties (1- (point)) (point)) | |
6366 | allout-topic-encryption-bullet) | |
2a1408fd | 6367 | (save-match-data (looking-at "\\*"))) |
d82979ea EZ |
6368 | ) |
6369 | ) | |
0949617b EZ |
6370 | ;;;_ > allout-encrypted-key-info (text) |
6371 | ;; XXX gpg-specific, alas | |
6372 | (defun allout-encrypted-key-info (text) | |
6373 | "Return a pair of the key type and identity of a recipient's secret key. | |
6374 | ||
60c7bbd2 | 6375 | The key type is one of `symmetric' or `keypair'. |
d82979ea | 6376 | |
60c7bbd2 | 6377 | If `keypair', and some of the user's secret keys are among those for which |
75bcb912 | 6378 | the message was encoded, return the identity of the first. Otherwise, |
0949617b | 6379 | return nil for the second item of the pair. |
d82979ea | 6380 | |
0949617b EZ |
6381 | An error is raised if the text is not encrypted." |
6382 | (require 'pgg-parse) | |
d82979ea | 6383 | (save-excursion |
0949617b | 6384 | (with-temp-buffer |
96b83743 | 6385 | (insert text) |
0949617b EZ |
6386 | (let* ((parsed-armor (pgg-parse-armor-region (point-min) (point-max))) |
6387 | (type (if (pgg-gpg-symmetric-key-p parsed-armor) | |
6388 | 'symmetric | |
6389 | 'keypair)) | |
6390 | secret-keys first-secret-key for-key-owner) | |
6391 | (if (equal type 'keypair) | |
6392 | (setq secret-keys (pgg-gpg-lookup-all-secret-keys) | |
6393 | first-secret-key (pgg-gpg-select-matching-key parsed-armor | |
6394 | secret-keys) | |
6395 | for-key-owner (and first-secret-key | |
6396 | (pgg-gpg-lookup-key-owner | |
6397 | first-secret-key)))) | |
6398 | (list type (pgg-gpg-key-id-from-key-owner for-key-owner)) | |
6399 | ) | |
d82979ea EZ |
6400 | ) |
6401 | ) | |
6402 | ) | |
0949617b EZ |
6403 | ;;;_ > allout-create-encryption-passphrase-verifier (passphrase) |
6404 | (defun allout-create-encryption-passphrase-verifier (passphrase) | |
6405 | "Encrypt random message for later validation of symmetric key's passphrase." | |
d82979ea EZ |
6406 | ;; use 20 random ascii characters, across the entire ascii range. |
6407 | (random t) | |
6408 | (let ((spew (make-string 20 ?\0))) | |
6409 | (dotimes (i (length spew)) | |
6410 | (aset spew i (1+ (random 254)))) | |
0949617b | 6411 | (allout-encrypt-string spew nil (current-buffer) 'symmetric |
48bd8440 | 6412 | nil nil 0 0 passphrase)) |
d82979ea | 6413 | ) |
0949617b | 6414 | ;;;_ > allout-update-passphrase-mnemonic-aids (for-key passphrase |
4034b0e2 | 6415 | ;;; outline-buffer) |
0949617b EZ |
6416 | (defun allout-update-passphrase-mnemonic-aids (for-key passphrase |
6417 | outline-buffer) | |
6418 | "Update passphrase verifier and hint strings if necessary. | |
6419 | ||
6420 | See `allout-passphrase-verifier-string' and `allout-passphrase-hint-string' | |
6421 | settings. | |
6422 | ||
75bcb912 | 6423 | PASSPHRASE is the passphrase being mnemonicized. |
0949617b EZ |
6424 | |
6425 | OUTLINE-BUFFER is the buffer of the outline being adjusted. | |
6426 | ||
6427 | These are used to help the user keep track of the passphrase they use for | |
6428 | symmetric encryption in the file. | |
6429 | ||
6430 | Behavior is governed by `allout-passphrase-verifier-handling', | |
6431 | `allout-passphrase-hint-handling', and also, controlling whether the values | |
6432 | are preserved on Emacs local file variables, | |
6433 | `allout-enable-file-variable-adjustment'." | |
6434 | ||
6435 | ;; If passphrase doesn't agree with current verifier: | |
6436 | ;; - adjust the verifier | |
6437 | ;; - if passphrase hint handling is enabled, adjust the passphrase hint | |
6438 | ;; - if file var settings are enabled, adjust the file vars | |
6439 | ||
6440 | (let* ((new-verifier-needed (not (allout-verify-passphrase | |
6441 | for-key passphrase outline-buffer))) | |
6442 | (new-verifier-string | |
6443 | (if new-verifier-needed | |
6444 | ;; Collapse to a single line and enclose in string quotes: | |
6445 | (subst-char-in-string | |
6446 | ?\n ?\C-a (allout-create-encryption-passphrase-verifier | |
6447 | passphrase)))) | |
6448 | new-hint) | |
6449 | (when new-verifier-string | |
6450 | ;; do the passphrase hint first, since it's interactive | |
6451 | (when (and allout-passphrase-hint-handling | |
6452 | (not (equal allout-passphrase-hint-handling 'disabled))) | |
6453 | (setq new-hint | |
6454 | (read-from-minibuffer "Passphrase hint to jog your memory: " | |
6455 | allout-passphrase-hint-string)) | |
6456 | (when (not (string= new-hint allout-passphrase-hint-string)) | |
6457 | (setq allout-passphrase-hint-string new-hint) | |
6458 | (allout-adjust-file-variable "allout-passphrase-hint-string" | |
6459 | allout-passphrase-hint-string))) | |
6460 | (when allout-passphrase-verifier-handling | |
6461 | (setq allout-passphrase-verifier-string new-verifier-string) | |
6462 | (allout-adjust-file-variable "allout-passphrase-verifier-string" | |
6463 | allout-passphrase-verifier-string)) | |
6464 | ) | |
d82979ea EZ |
6465 | ) |
6466 | ) | |
0949617b EZ |
6467 | ;;;_ > allout-get-encryption-passphrase-verifier () |
6468 | (defun allout-get-encryption-passphrase-verifier () | |
6469 | "Return text of the encrypt passphrase verifier, unmassaged, or nil if none. | |
d82979ea | 6470 | |
4034b0e2 | 6471 | Derived from value of `allout-passphrase-verifier-string'." |
d82979ea | 6472 | |
0949617b EZ |
6473 | (let ((verifier-string (and (boundp 'allout-passphrase-verifier-string) |
6474 | allout-passphrase-verifier-string))) | |
d82979ea EZ |
6475 | (if verifier-string |
6476 | ;; Return it uncollapsed | |
0949617b | 6477 | (subst-char-in-string ?\C-a ?\n verifier-string)) |
d82979ea EZ |
6478 | ) |
6479 | ) | |
0949617b EZ |
6480 | ;;;_ > allout-verify-passphrase (key passphrase allout-buffer) |
6481 | (defun allout-verify-passphrase (key passphrase allout-buffer) | |
6482 | "True if passphrase successfully decrypts verifier, nil otherwise. | |
d82979ea | 6483 | |
0949617b | 6484 | \"Otherwise\" includes absence of passphrase verifier." |
d82979ea EZ |
6485 | (save-excursion |
6486 | (set-buffer allout-buffer) | |
0949617b EZ |
6487 | (and (boundp 'allout-passphrase-verifier-string) |
6488 | allout-passphrase-verifier-string | |
6489 | (allout-encrypt-string (allout-get-encryption-passphrase-verifier) | |
d82979ea | 6490 | 'decrypt allout-buffer 'symmetric |
48bd8440 | 6491 | key nil 0 0 'verifying passphrase) |
d82979ea EZ |
6492 | t))) |
6493 | ;;;_ > allout-next-topic-pending-encryption (&optional except-mark) | |
6494 | (defun allout-next-topic-pending-encryption (&optional except-mark) | |
6495 | "Return the point of the next topic pending encryption, or nil if none. | |
6496 | ||
6497 | EXCEPT-MARK identifies a point whose containing topics should be excluded | |
6498 | from encryption. This supports 'except-current mode of | |
6499 | `allout-encrypt-unencrypted-on-saves'. | |
6500 | ||
75bcb912 | 6501 | Such a topic has the `allout-topic-encryption-bullet' without an |
d82979ea EZ |
6502 | immediately following '*' that would mark the topic as being encrypted. It |
6503 | must also have content." | |
6504 | (let (done got content-beg) | |
2a1408fd DN |
6505 | (save-match-data |
6506 | (while (not done) | |
d82979ea | 6507 | |
2a1408fd DN |
6508 | (if (not (re-search-forward |
6509 | (format "\\(\\`\\|\n\\)%s *%s[^*]" | |
6510 | (regexp-quote allout-header-prefix) | |
6511 | (regexp-quote allout-topic-encryption-bullet)) | |
6512 | nil t)) | |
6513 | (setq got nil | |
6514 | done t) | |
6515 | (goto-char (setq got (match-beginning 0))) | |
6516 | (if (save-match-data (looking-at "\n")) | |
6517 | (forward-char 1)) | |
6518 | (setq got (point))) | |
6519 | ||
6520 | (cond ((not got) | |
6521 | (setq done t)) | |
6522 | ||
6523 | ((not (search-forward "\n")) | |
6524 | (setq got nil | |
6525 | done t)) | |
6526 | ||
6527 | ((eobp) | |
6528 | (setq got nil | |
6529 | done t)) | |
6530 | ||
6531 | (t | |
6532 | (setq content-beg (point)) | |
6533 | (backward-char 1) | |
6534 | (allout-end-of-subtree) | |
6535 | (if (or (<= (point) content-beg) | |
6536 | (and except-mark | |
6537 | (<= content-beg except-mark) | |
6538 | (>= (point) except-mark))) | |
6539 | ;; Continue looking | |
6540 | (setq got nil) | |
6541 | ;; Got it! | |
6542 | (setq done t))) | |
6543 | ) | |
6544 | ) | |
6545 | (if got | |
6546 | (goto-char got)) | |
d82979ea | 6547 | ) |
d82979ea EZ |
6548 | ) |
6549 | ) | |
6550 | ;;;_ > allout-encrypt-decrypted (&optional except-mark) | |
6551 | (defun allout-encrypt-decrypted (&optional except-mark) | |
6552 | "Encrypt topics pending encryption except those containing exemption point. | |
6553 | ||
6554 | EXCEPT-MARK identifies a point whose containing topics should be excluded | |
60c7bbd2 | 6555 | from encryption. This supports the `except-current' mode of |
d82979ea EZ |
6556 | `allout-encrypt-unencrypted-on-saves'. |
6557 | ||
6558 | If a topic that is currently being edited was encrypted, we return a list | |
6559 | containing the location of the topic and the location of the cursor just | |
6560 | before the topic was encrypted. This can be used, eg, to decrypt the topic | |
6561 | and exactly resituate the cursor if this is being done as part of a file | |
6562 | save. See `allout-encrypt-unencrypted-on-saves' for more info." | |
6563 | ||
6564 | (interactive "p") | |
2a1408fd DN |
6565 | (save-match-data |
6566 | (save-excursion | |
6567 | (let* ((current-mark (point-marker)) | |
6568 | (current-mark-position (marker-position current-mark)) | |
6569 | was-modified | |
6570 | bo-subtree | |
6571 | editing-topic editing-point) | |
6572 | (goto-char (point-min)) | |
6573 | (while (allout-next-topic-pending-encryption except-mark) | |
6574 | (setq was-modified (buffer-modified-p)) | |
6575 | (when (save-excursion | |
6576 | (and (boundp 'allout-encrypt-unencrypted-on-saves) | |
6577 | allout-encrypt-unencrypted-on-saves | |
6578 | (setq bo-subtree (re-search-forward "$")) | |
6579 | (not (allout-hidden-p)) | |
6580 | (>= current-mark (point)) | |
6581 | (allout-end-of-current-subtree) | |
6582 | (<= current-mark (point)))) | |
d82979ea EZ |
6583 | (setq editing-topic (point) |
6584 | ;; we had to wait for this 'til now so prior topics are | |
6585 | ;; encrypted, any relevant text shifts are in place: | |
96b83743 EZ |
6586 | editing-point (- current-mark-position |
6587 | (count-trailing-whitespace-region | |
6588 | bo-subtree current-mark-position)))) | |
2a1408fd DN |
6589 | (allout-toggle-subtree-encryption) |
6590 | (if (not was-modified) | |
6591 | (set-buffer-modified-p nil)) | |
6592 | ) | |
d82979ea EZ |
6593 | (if (not was-modified) |
6594 | (set-buffer-modified-p nil)) | |
2a1408fd | 6595 | (if editing-topic (list editing-topic editing-point)) |
d82979ea | 6596 | ) |
d82979ea EZ |
6597 | ) |
6598 | ) | |
6599 | ) | |
6600 | ||
6601 | ;;;_ #9 miscellaneous | |
d8350998 CY |
6602 | ;;;_ : Mode: |
6603 | ;;;_ > outlineify-sticky () | |
19b84ba3 | 6604 | ;; outlinify-sticky is correct spelling; provide this alias for sticklers: |
0949617b | 6605 | ;;;###autoload |
19b84ba3 | 6606 | (defalias 'outlinify-sticky 'outlineify-sticky) |
0949617b | 6607 | ;;;###autoload |
c567ac01 | 6608 | (defun outlineify-sticky (&optional arg) |
a0776d6b | 6609 | "Activate outline mode and establish file var so it is started subsequently. |
1977b8f6 | 6610 | |
fd5359c6 | 6611 | See doc-string for `allout-layout' and `allout-init' for details on |
19b84ba3 RS |
6612 | setup for auto-startup." |
6613 | ||
6614 | (interactive "P") | |
6615 | ||
fd5359c6 | 6616 | (allout-mode t) |
19b84ba3 RS |
6617 | |
6618 | (save-excursion | |
6619 | (goto-char (point-min)) | |
ede4ac6a | 6620 | (if (allout-goto-prefix) |
19b84ba3 | 6621 | t |
fd5359c6 | 6622 | (allout-open-topic 2) |
60c7bbd2 | 6623 | (insert (concat "Dummy outline topic header -- see" |
d82979ea EZ |
6624 | "`allout-mode' docstring: `^Hm'.")) |
6625 | (allout-adjust-file-variable | |
4034b0e2 | 6626 | "allout-layout" (or allout-layout '(-1 : 0)))))) |
d8350998 | 6627 | ;;;_ > allout-file-vars-section-data () |
d82979ea EZ |
6628 | (defun allout-file-vars-section-data () |
6629 | "Return data identifying the file-vars section, or nil if none. | |
6630 | ||
60c7bbd2 | 6631 | Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)." |
d82979ea EZ |
6632 | ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function. |
6633 | (let (beg prefix suffix) | |
6634 | (save-excursion | |
1977b8f6 | 6635 | (goto-char (point-max)) |
d82979ea EZ |
6636 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
6637 | (if (let ((case-fold-search t)) | |
6638 | (not (search-forward "Local Variables:" nil t))) | |
6639 | nil | |
6640 | (setq beg (- (point) 16)) | |
6641 | (setq suffix (buffer-substring-no-properties | |
6642 | (point) | |
96b83743 | 6643 | (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6644 | (forward-char -1)) |
6645 | (point)))) | |
6646 | (setq prefix (buffer-substring-no-properties | |
96b83743 | 6647 | (progn (if (search-backward "\n" nil t) |
d82979ea EZ |
6648 | (forward-char 1)) |
6649 | (point)) | |
6650 | beg)) | |
6651 | (list beg prefix suffix)) | |
6652 | ) | |
6653 | ) | |
6654 | ) | |
d8350998 | 6655 | ;;;_ > allout-adjust-file-variable (varname value) |
d82979ea | 6656 | (defun allout-adjust-file-variable (varname value) |
a0a022d5 | 6657 | "Adjust the setting of an Emacs file variable named VARNAME to VALUE. |
d82979ea EZ |
6658 | |
6659 | This activity is inhibited if either `enable-local-variables' | |
6660 | `allout-enable-file-variable-adjustment' are nil. | |
6661 | ||
6662 | When enabled, an entry for the variable is created if not already present, | |
6663 | or changed if established with a different value. The section for the file | |
6664 | variables, itself, is created if not already present. When created, the | |
c07583cd | 6665 | section lines (including the section line) exist as second-level topics in |
d82979ea EZ |
6666 | a top-level topic at the end of the file. |
6667 | ||
a0a022d5 | 6668 | `enable-local-variables' must be true for any of this to happen." |
d82979ea EZ |
6669 | (if (not (and enable-local-variables |
6670 | allout-enable-file-variable-adjustment)) | |
6671 | nil | |
6672 | (save-excursion | |
0458fa80 EZ |
6673 | (let ((inhibit-field-text-motion t) |
6674 | (section-data (allout-file-vars-section-data)) | |
d82979ea EZ |
6675 | beg prefix suffix) |
6676 | (if section-data | |
6677 | (setq beg (car section-data) | |
6678 | prefix (cadr section-data) | |
6679 | suffix (car (cddr section-data))) | |
6680 | ;; create the section | |
6681 | (goto-char (point-max)) | |
6682 | (open-line 1) | |
6683 | (allout-open-topic 0) | |
6684 | (end-of-line) | |
6685 | (insert "Local emacs vars.\n") | |
6686 | (allout-open-topic 1) | |
6687 | (setq beg (point) | |
6688 | suffix "" | |
6689 | prefix (buffer-substring-no-properties (progn | |
6690 | (beginning-of-line) | |
6691 | (point)) | |
6692 | beg)) | |
6693 | (goto-char beg) | |
6694 | (insert "Local variables:\n") | |
6695 | (allout-open-topic 0) | |
6696 | (insert "End:\n") | |
6697 | ) | |
6698 | ;; look for existing entry or create one, leaving point for insertion | |
6699 | ;; of new value: | |
6700 | (goto-char beg) | |
6701 | (allout-show-to-offshoot) | |
6702 | (if (search-forward (concat "\n" prefix varname ":") nil t) | |
6703 | (let* ((value-beg (point)) | |
96b83743 | 6704 | (line-end (progn (if (search-forward "\n" nil t) |
d82979ea EZ |
6705 | (forward-char -1)) |
6706 | (point))) | |
6707 | (value-end (- line-end (length suffix)))) | |
6708 | (if (> value-end value-beg) | |
6709 | (delete-region value-beg value-end))) | |
6710 | (end-of-line) | |
6711 | (open-line 1) | |
6712 | (forward-line 1) | |
6713 | (insert (concat prefix varname ":"))) | |
6714 | (insert (format " %S%s" value suffix)) | |
6715 | ) | |
6716 | ) | |
6717 | ) | |
6718 | ) | |
d8350998 CY |
6719 | ;;;_ > allout-get-configvar-values (varname) |
6720 | (defun allout-get-configvar-values (configvar-name) | |
6721 | "Return a list of values of the symbols in list bound to CONFIGVAR-NAME. | |
6722 | ||
6723 | The user is prompted for removal of symbols that are unbound, and they | |
6724 | otherwise are ignored. | |
6725 | ||
6726 | CONFIGVAR-NAME should be the name of the configuration variable, | |
6727 | not its value." | |
6728 | ||
6729 | (let ((configvar-value (symbol-value configvar-name)) | |
6730 | got) | |
6731 | (dolist (sym configvar-value) | |
6732 | (if (not (boundp sym)) | |
60c7bbd2 | 6733 | (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? " |
d8350998 CY |
6734 | configvar-name sym)) |
6735 | (delq sym (symbol-value configvar-name))) | |
6736 | (push (symbol-value sym) got))) | |
6737 | (reverse got))) | |
6738 | ;;;_ : Topics: | |
6739 | ;;;_ > allout-mark-topic () | |
6740 | (defun allout-mark-topic () | |
6741 | "Put the region around topic currently containing point." | |
6742 | (interactive) | |
6743 | (let ((inhibit-field-text-motion t)) | |
6744 | (beginning-of-line)) | |
6745 | (allout-goto-prefix-doublechecked) | |
6746 | (push-mark (point)) | |
6747 | (allout-end-of-current-subtree) | |
6748 | (exchange-point-and-mark)) | |
6749 | ;;;_ : UI: | |
6750 | ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting) | |
1977b8f6 | 6751 | (defun solicit-char-in-string (prompt string &optional do-defaulting) |
c567ac01 | 6752 | "Solicit (with first arg PROMPT) choice of a character from string STRING. |
1977b8f6 | 6753 | |
c567ac01 | 6754 | Optional arg DO-DEFAULTING indicates to accept empty input (CR)." |
1977b8f6 RS |
6755 | |
6756 | (let ((new-prompt prompt) | |
6757 | got) | |
6758 | ||
6759 | (while (not got) | |
6760 | (message "%s" new-prompt) | |
6761 | ||
6762 | ;; We do our own reading here, so we can circumvent, eg, special | |
9179616f | 6763 | ;; treatment for `?' character. (Oughta use minibuffer keymap instead.) |
1977b8f6 | 6764 | (setq got |
c567ac01 | 6765 | (char-to-string (let ((cursor-in-echo-area nil)) (read-char)))) |
1977b8f6 | 6766 | |
9179616f DL |
6767 | (setq got |
6768 | (cond ((string-match (regexp-quote got) string) got) | |
6769 | ((and do-defaulting (string= got "\r")) | |
6770 | ;; Return empty string to default: | |
6771 | "") | |
6772 | ((string= got "\C-g") (signal 'quit nil)) | |
6773 | (t | |
6774 | (setq new-prompt (concat prompt | |
6775 | got | |
6776 | " ...pick from: " | |
6777 | string | |
6778 | "")) | |
6779 | nil)))) | |
60c7bbd2 | 6780 | ;; got something out of loop -- return it: |
9179616f | 6781 | got) |
1977b8f6 | 6782 | ) |
d8350998 CY |
6783 | ;;;_ : Strings: |
6784 | ;;;_ > regexp-sans-escapes (string) | |
c567ac01 RS |
6785 | (defun regexp-sans-escapes (regexp &optional successive-backslashes) |
6786 | "Return a copy of REGEXP with all character escapes stripped out. | |
19b84ba3 | 6787 | |
60c7bbd2 | 6788 | Representations of actual backslashes -- '\\\\\\\\' -- are left as a |
c567ac01 RS |
6789 | single backslash. |
6790 | ||
d82979ea | 6791 | Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion." |
c567ac01 RS |
6792 | |
6793 | (if (string= regexp "") | |
6794 | "" | |
6795 | ;; Set successive-backslashes to number if current char is | |
6796 | ;; backslash, or else to nil: | |
6797 | (setq successive-backslashes | |
6798 | (if (= (aref regexp 0) ?\\) | |
6799 | (if successive-backslashes (1+ successive-backslashes) 1) | |
6800 | nil)) | |
6801 | (if (or (not successive-backslashes) (= 2 successive-backslashes)) | |
6802 | ;; Include first char: | |
6803 | (concat (substring regexp 0 1) | |
6804 | (regexp-sans-escapes (substring regexp 1))) | |
6805 | ;; Exclude first char, but maintain count: | |
6806 | (regexp-sans-escapes (substring regexp 1) successive-backslashes)))) | |
d8350998 | 6807 | ;;;_ > count-trailing-whitespace-region (beg end) |
96b83743 EZ |
6808 | (defun count-trailing-whitespace-region (beg end) |
6809 | "Return number of trailing whitespace chars between BEG and END. | |
6810 | ||
6811 | If BEG is bigger than END we return 0." | |
6812 | (if (> beg end) | |
6813 | 0 | |
2a1408fd DN |
6814 | (save-match-data |
6815 | (save-excursion | |
6816 | (goto-char beg) | |
6817 | (let ((count 0)) | |
6818 | (while (re-search-forward "[ ][ ]*$" end t) | |
6819 | (goto-char (1+ (match-beginning 2))) | |
6820 | (setq count (1+ count))) | |
6821 | count))))) | |
d8350998 CY |
6822 | ;;;_ > allout-format-quote (string) |
6823 | (defun allout-format-quote (string) | |
6824 | "Return a copy of string with all \"%\" characters doubled." | |
6825 | (apply 'concat | |
6826 | (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char))) | |
6827 | string))) | |
6828 | ;;;_ : lists | |
6829 | ;;;_ > allout-flatten (list) | |
6830 | (defun allout-flatten (list) | |
6831 | "Return a list of all atoms in list." | |
6832 | ;; classic. | |
6833 | (cond ((null list) nil) | |
8a559d4e EZ |
6834 | ((atom (car list)) (cons (car list) (allout-flatten (cdr list)))) |
6835 | (t (append (allout-flatten (car list)) (allout-flatten (cdr list)))))) | |
75bcb912 | 6836 | ;;;_ : Compatibility: |
d8350998 | 6837 | ;;;_ > allout-mark-marker to accommodate divergent emacsen: |
96b83743 EZ |
6838 | (defun allout-mark-marker (&optional force buffer) |
6839 | "Accommodate the different signature for `mark-marker' across Emacsen. | |
6840 | ||
6841 | XEmacs takes two optional args, while mainline GNU Emacs does not, | |
6842 | so pass them along when appropriate." | |
6843 | (if (featurep 'xemacs) | |
6844 | (apply 'mark-marker force buffer) | |
6845 | (mark-marker))) | |
d8350998 | 6846 | ;;;_ > subst-char-in-string if necessary |
d82979ea EZ |
6847 | (if (not (fboundp 'subst-char-in-string)) |
6848 | (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
6849 | "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
6850 | Unless optional argument INPLACE is non-nil, return a new string." | |
6851 | (let ((i (length string)) | |
6852 | (newstr (if inplace string (copy-sequence string)))) | |
6853 | (while (> i 0) | |
6854 | (setq i (1- i)) | |
6855 | (if (eq (aref newstr i) fromchar) | |
6856 | (aset newstr i tochar))) | |
6857 | newstr))) | |
d8350998 | 6858 | ;;;_ > wholenump if necessary |
96b83743 EZ |
6859 | (if (not (fboundp 'wholenump)) |
6860 | (defalias 'wholenump 'natnump)) | |
d8350998 | 6861 | ;;;_ > remove-overlays if necessary |
96b83743 EZ |
6862 | (if (not (fboundp 'remove-overlays)) |
6863 | (defun remove-overlays (&optional beg end name val) | |
6864 | "Clear BEG and END of overlays whose property NAME has value VAL. | |
6865 | Overlays might be moved and/or split. | |
6866 | BEG and END default respectively to the beginning and end of buffer." | |
6867 | (unless beg (setq beg (point-min))) | |
6868 | (unless end (setq end (point-max))) | |
6869 | (if (< end beg) | |
6870 | (setq beg (prog1 end (setq end beg)))) | |
6871 | (save-excursion | |
6872 | (dolist (o (overlays-in beg end)) | |
6873 | (when (eq (overlay-get o name) val) | |
6874 | ;; Either push this overlay outside beg...end | |
6875 | ;; or split it to exclude beg...end | |
6876 | ;; or delete it entirely (if it is contained in beg...end). | |
6877 | (if (< (overlay-start o) beg) | |
6878 | (if (> (overlay-end o) end) | |
6879 | (progn | |
6880 | (move-overlay (copy-overlay o) | |
6881 | (overlay-start o) beg) | |
6882 | (move-overlay o end (overlay-end o))) | |
6883 | (move-overlay o (overlay-start o) beg)) | |
6884 | (if (> (overlay-end o) end) | |
6885 | (move-overlay o end (overlay-end o)) | |
6886 | (delete-overlay o))))))) | |
6887 | ) | |
60c7bbd2 | 6888 | ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6889 | (if (not (fboundp 'copy-overlay)) |
6890 | (defun copy-overlay (o) | |
6891 | "Return a copy of overlay O." | |
6892 | (let ((o1 (make-overlay (overlay-start o) (overlay-end o) | |
6893 | ;; FIXME: there's no easy way to find the | |
6894 | ;; insertion-type of the two markers. | |
6895 | (overlay-buffer o))) | |
6896 | (props (overlay-properties o))) | |
6897 | (while props | |
6898 | (overlay-put o1 (pop props) (pop props))) | |
6899 | o1))) | |
60c7bbd2 | 6900 | ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6901 | (if (not (fboundp 'add-to-invisibility-spec)) |
6902 | (defun add-to-invisibility-spec (element) | |
6903 | "Add ELEMENT to `buffer-invisibility-spec'. | |
6904 | See documentation for `buffer-invisibility-spec' for the kind of elements | |
6905 | that can be added." | |
6906 | (if (eq buffer-invisibility-spec t) | |
6907 | (setq buffer-invisibility-spec (list t))) | |
6908 | (setq buffer-invisibility-spec | |
6909 | (cons element buffer-invisibility-spec)))) | |
60c7bbd2 | 6910 | ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4 |
96b83743 EZ |
6911 | (if (not (fboundp 'remove-from-invisibility-spec)) |
6912 | (defun remove-from-invisibility-spec (element) | |
6913 | "Remove ELEMENT from `buffer-invisibility-spec'." | |
6914 | (if (consp buffer-invisibility-spec) | |
6915 | (setq buffer-invisibility-spec (delete element | |
6916 | buffer-invisibility-spec))))) | |
60c7bbd2 | 6917 | ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs |
96b83743 EZ |
6918 | (if (not (fboundp 'move-beginning-of-line)) |
6919 | (defun move-beginning-of-line (arg) | |
6920 | "Move point to beginning of current line as displayed. | |
6921 | \(This disregards invisible newlines such as those | |
6922 | which are part of the text that an image rests on.) | |
6923 | ||
6924 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6925 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6926 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6927 | (interactive "p") |
6928 | (or arg (setq arg 1)) | |
6929 | (if (/= arg 1) | |
6930 | (condition-case nil (line-move (1- arg)) (error nil))) | |
6931 | ||
8570ce80 SM |
6932 | ;; Move to beginning-of-line, ignoring fields and invisibles. |
6933 | (skip-chars-backward "^\n") | |
2a1408fd DN |
6934 | (while (and (not (bobp)) |
6935 | (let ((prop | |
6936 | (get-char-property (1- (point)) 'invisible))) | |
6937 | (if (eq buffer-invisibility-spec t) | |
6938 | prop | |
6939 | (or (memq prop buffer-invisibility-spec) | |
6940 | (assq prop buffer-invisibility-spec))))) | |
8570ce80 SM |
6941 | (goto-char (if (featurep 'xemacs) |
6942 | (previous-property-change (point)) | |
6943 | (previous-char-property-change (point)))) | |
6944 | (skip-chars-backward "^\n")) | |
6945 | (vertical-motion 0)) | |
96b83743 | 6946 | ) |
60c7bbd2 | 6947 | ;;;_ > move-end-of-line if necessary -- older emacs, xemacs |
96b83743 EZ |
6948 | (if (not (fboundp 'move-end-of-line)) |
6949 | (defun move-end-of-line (arg) | |
6950 | "Move point to end of current line as displayed. | |
6951 | \(This disregards invisible newlines such as those | |
6952 | which are part of the text that an image rests on.) | |
6953 | ||
6954 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | |
6955 | If point reaches the beginning or end of buffer, it stops there. | |
4034b0e2 | 6956 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
96b83743 EZ |
6957 | (interactive "p") |
6958 | (or arg (setq arg 1)) | |
8570ce80 | 6959 | (let (done) |
96b83743 EZ |
6960 | (while (not done) |
6961 | (let ((newpos | |
6962 | (save-excursion | |
6963 | (let ((goal-column 0)) | |
6964 | (and (condition-case nil | |
6965 | (or (line-move arg) t) | |
6966 | (error nil)) | |
6967 | (not (bobp)) | |
6968 | (progn | |
2a1408fd DN |
6969 | (while |
6970 | (and | |
6971 | (not (bobp)) | |
6972 | (let ((prop | |
6973 | (get-char-property (1- (point)) | |
6974 | 'invisible))) | |
6975 | (if (eq buffer-invisibility-spec t) | |
6976 | prop | |
6977 | (or (memq prop | |
6978 | buffer-invisibility-spec) | |
6979 | (assq prop | |
6980 | buffer-invisibility-spec))))) | |
8570ce80 SM |
6981 | (goto-char |
6982 | (previous-char-property-change (point)))) | |
96b83743 EZ |
6983 | (backward-char 1))) |
6984 | (point))))) | |
6985 | (goto-char newpos) | |
6986 | (if (and (> (point) newpos) | |
6987 | (eq (preceding-char) ?\n)) | |
6988 | (backward-char 1) | |
6989 | (if (and (> (point) newpos) (not (eobp)) | |
6990 | (not (eq (following-char) ?\n))) | |
6991 | ;; If we skipped something intangible | |
6992 | ;; and now we're not really at eol, | |
6993 | ;; keep going. | |
6994 | (setq arg 1) | |
8570ce80 | 6995 | (setq done t))))))) |
96b83743 | 6996 | ) |
96b83743 | 6997 | |
96b83743 | 6998 | ;;;_ #10 Unfinished |
fd5359c6 MR |
6999 | ;;;_ > allout-bullet-isearch (&optional bullet) |
7000 | (defun allout-bullet-isearch (&optional bullet) | |
c07583cd | 7001 | "Isearch (regexp) for topic with bullet BULLET." |
c567ac01 RS |
7002 | (interactive) |
7003 | (if (not bullet) | |
7004 | (setq bullet (solicit-char-in-string | |
7005 | "ISearch for topic with bullet: " | |
fd5359c6 | 7006 | (regexp-sans-escapes allout-bullets-string)))) |
353e2ef2 | 7007 | |
c567ac01 RS |
7008 | (let ((isearch-regexp t) |
7009 | (isearch-string (concat "^" | |
fd5359c6 | 7010 | allout-header-prefix |
c567ac01 RS |
7011 | "[ \t]*" |
7012 | bullet))) | |
7013 | (isearch-repeat 'forward) | |
7014 | (isearch-mode t))) | |
96b83743 | 7015 | |
60c7bbd2 | 7016 | ;;;_ #11 Unit tests -- this should be last item before "Provide" |
01fc9422 EZ |
7017 | ;;;_ > allout-run-unit-tests () |
7018 | (defun allout-run-unit-tests () | |
7019 | "Run the various allout unit tests." | |
7020 | (message "Running allout tests...") | |
7021 | (allout-test-resumptions) | |
7022 | (message "Running allout tests... Done.") | |
7023 | (sit-for .5)) | |
7024 | ;;;_ : test resumptions: | |
7025 | ;;;_ > allout-tests-obliterate-variable (name) | |
7026 | (defun allout-tests-obliterate-variable (name) | |
7027 | "Completely unbind variable with NAME." | |
7028 | (if (local-variable-p name) (kill-local-variable name)) | |
7029 | (while (boundp name) (makunbound name))) | |
7030 | ;;;_ > allout-test-resumptions () | |
7031 | (defvar allout-tests-globally-unbound nil | |
60c7bbd2 | 7032 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 7033 | (defvar allout-tests-globally-true nil |
60c7bbd2 | 7034 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 | 7035 | (defvar allout-tests-locally-true nil |
60c7bbd2 | 7036 | "Fodder for allout resumptions tests -- defvar just for byte compiler.") |
01fc9422 EZ |
7037 | (defun allout-test-resumptions () |
7038 | "Exercise allout resumptions." | |
7039 | ;; for each resumption case, we also test that the right local/global | |
7040 | ;; scopes are affected during resumption effects: | |
7041 | ||
7042 | ;; ensure that previously unbound variables return to the unbound state. | |
7043 | (with-temp-buffer | |
7044 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
7045 | (allout-add-resumptions '(allout-tests-globally-unbound t)) | |
7046 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
7047 | (assert (local-variable-p 'allout-tests-globally-unbound)) | |
7048 | (assert (boundp 'allout-tests-globally-unbound)) | |
7049 | (assert (equal allout-tests-globally-unbound t)) | |
7050 | (allout-do-resumptions) | |
7051 | (assert (not (local-variable-p 'allout-tests-globally-unbound))) | |
7052 | (assert (not (boundp 'allout-tests-globally-unbound)))) | |
7053 | ||
7054 | ;; ensure that variable with prior global value is resumed | |
7055 | (with-temp-buffer | |
7056 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
7057 | (setq allout-tests-globally-true t) | |
7058 | (allout-add-resumptions '(allout-tests-globally-true nil)) | |
7059 | (assert (equal (default-value 'allout-tests-globally-true) t)) | |
7060 | (assert (local-variable-p 'allout-tests-globally-true)) | |
7061 | (assert (equal allout-tests-globally-true nil)) | |
7062 | (allout-do-resumptions) | |
7063 | (assert (not (local-variable-p 'allout-tests-globally-true))) | |
7064 | (assert (boundp 'allout-tests-globally-true)) | |
7065 | (assert (equal allout-tests-globally-true t))) | |
7066 | ||
7067 | ;; ensure that prior local value is resumed | |
7068 | (with-temp-buffer | |
7069 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
7070 | (set (make-local-variable 'allout-tests-locally-true) t) | |
7071 | (assert (not (default-boundp 'allout-tests-locally-true)) | |
60c7bbd2 | 7072 | nil (concat "Test setup mistake -- variable supposed to" |
01fc9422 EZ |
7073 | " not have global binding, but it does.")) |
7074 | (assert (local-variable-p 'allout-tests-locally-true) | |
60c7bbd2 | 7075 | nil (concat "Test setup mistake -- variable supposed to have" |
01fc9422 EZ |
7076 | " local binding, but it lacks one.")) |
7077 | (allout-add-resumptions '(allout-tests-locally-true nil)) | |
7078 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
7079 | (assert (local-variable-p 'allout-tests-locally-true)) | |
7080 | (assert (equal allout-tests-locally-true nil)) | |
7081 | (allout-do-resumptions) | |
7082 | (assert (boundp 'allout-tests-locally-true)) | |
7083 | (assert (local-variable-p 'allout-tests-locally-true)) | |
7084 | (assert (equal allout-tests-locally-true t)) | |
7085 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
7086 | ||
7087 | ;; ensure that last of multiple resumptions holds, for various scopes. | |
7088 | (with-temp-buffer | |
7089 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
7090 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
7091 | (setq allout-tests-globally-true t) | |
7092 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
7093 | (set (make-local-variable 'allout-tests-locally-true) t) | |
7094 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
7095 | '(allout-tests-globally-true nil) | |
7096 | '(allout-tests-locally-true nil)) | |
7097 | (allout-add-resumptions '(allout-tests-globally-unbound 2) | |
7098 | '(allout-tests-globally-true 3) | |
7099 | '(allout-tests-locally-true 4)) | |
7100 | ;; reestablish many of the basic conditions are maintained after re-add: | |
7101 | (assert (not (default-boundp 'allout-tests-globally-unbound))) | |
7102 | (assert (local-variable-p 'allout-tests-globally-unbound)) | |
7103 | (assert (equal allout-tests-globally-unbound 2)) | |
7104 | (assert (default-boundp 'allout-tests-globally-true)) | |
7105 | (assert (local-variable-p 'allout-tests-globally-true)) | |
7106 | (assert (equal allout-tests-globally-true 3)) | |
7107 | (assert (not (default-boundp 'allout-tests-locally-true))) | |
7108 | (assert (local-variable-p 'allout-tests-locally-true)) | |
7109 | (assert (equal allout-tests-locally-true 4)) | |
7110 | (allout-do-resumptions) | |
7111 | (assert (not (local-variable-p 'allout-tests-globally-unbound))) | |
7112 | (assert (not (boundp 'allout-tests-globally-unbound))) | |
7113 | (assert (not (local-variable-p 'allout-tests-globally-true))) | |
7114 | (assert (boundp 'allout-tests-globally-true)) | |
7115 | (assert (equal allout-tests-globally-true t)) | |
7116 | (assert (boundp 'allout-tests-locally-true)) | |
7117 | (assert (local-variable-p 'allout-tests-locally-true)) | |
7118 | (assert (equal allout-tests-locally-true t)) | |
7119 | (assert (not (default-boundp 'allout-tests-locally-true)))) | |
7120 | ||
7121 | ;; ensure that deliberately unbinding registered variables doesn't foul things | |
7122 | (with-temp-buffer | |
7123 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
7124 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
7125 | (setq allout-tests-globally-true t) | |
7126 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
7127 | (set (make-local-variable 'allout-tests-locally-true) t) | |
7128 | (allout-add-resumptions '(allout-tests-globally-unbound t) | |
7129 | '(allout-tests-globally-true nil) | |
7130 | '(allout-tests-locally-true nil)) | |
7131 | (allout-tests-obliterate-variable 'allout-tests-globally-unbound) | |
7132 | (allout-tests-obliterate-variable 'allout-tests-globally-true) | |
7133 | (allout-tests-obliterate-variable 'allout-tests-locally-true) | |
7134 | (allout-do-resumptions)) | |
7135 | ) | |
7136 | ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true: | |
7137 | (when allout-run-unit-tests-on-load | |
7138 | (allout-run-unit-tests)) | |
7139 | ||
7140 | ;;;_ #12 Provide | |
96b83743 | 7141 | (provide 'allout) |
1977b8f6 RS |
7142 | |
7143 | ;;;_* Local emacs vars. | |
31468dcb SM |
7144 | ;; The following `allout-layout' local variable setting: |
7145 | ;; - closes all topics from the first topic to just before the third-to-last, | |
7146 | ;; - shows the children of the third to last (config vars) | |
7147 | ;; - and the second to last (code section), | |
7148 | ;; - and closes the last topic (this local-variables section). | |
7149 | ;;Local variables: | |
7150 | ;;allout-layout: (0 : -1 -1 0) | |
7151 | ;;End: | |
7152 | ||
7153 | ;; arch-tag: cf38fbc3-c044-450f-8bff-afed8ba5681c | |
6a05d05f | 7154 | ;;; allout.el ends here |