(compilation-parse-errors):
[emacs.git] / lisp / allout.el
blobdb41d4af169d0992fd7febe080dcde408e3177ec
1 ;;; allout.el --- Extensive outline mode for use alone and with other modes.
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <klm@nist.gov>
6 ;; Maintainer: Ken Manheimer <klm@nist.gov>
7 ;; Created: Dec 1991 - first release to usenet
8 ;; Version: Id: allout.el,v 4.3 1994/05/12 17:43:08 klm Exp ||
9 ;; Keywords: outline mode
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
28 ;;;_* Commentary:
30 ;; Allout outline mode provides extensive outline formatting and
31 ;; manipulation capabilities, subsuming and well beyond that of
32 ;; standard emacs outline mode. It is specifically aimed at
33 ;; supporting outline structuring and manipulation of syntax-
34 ;; sensitive text, eg programming languages. (For an example, see the
35 ;; allout code itself, which is organized in outline structure.)
36 ;;
37 ;; It also includes such things as topic-oriented repositioning, cut, and
38 ;; paste; integral outline exposure-layout; incremental search with
39 ;; dynamic exposure/concealment of concealed text; automatic topic-number
40 ;; maintenance; and many other features.
41 ;;
42 ;; See the docstring of the variables `outline-layout' and
43 ;; `outline-auto-activation' for details on automatic activation of
44 ;; allout outline-mode as a minor mode. (It has changed since allout
45 ;; 3.x, for those of you that depend on the old method.)
47 ;; Note - the lines beginning with ';;;_' are outline topic headers.
48 ;; Just 'ESC-x eval-current-buffer' to give it a whirl.
50 ;;Ken Manheimer 301 975-3539
51 ;;ken.manheimer@nist.gov FAX: 301 963-9137
53 ;;Computer Systems and Communications Division
55 ;; Nat'l Institute of Standards and Technology
56 ;; Technology A151
57 ;; Gaithersburg, MD 20899
59 ;;;_* Provide
60 (provide 'outline)
61 (provide 'allout)
63 ;;;_* USER CUSTOMIZATION VARIABLES:
65 ;;;_ + Layout, Mode, and Topic Header Configuration
67 ;;;_ = outline-auto-activation
68 (defvar outline-auto-activation nil
69 "*Regulates auto-activation modality of allout outlines - see `outline-init'.
71 Setq-default by `outline-init' to regulate whether or not allout
72 outline mode is automatically activated when the buffer-specific
73 variable `outline-layout' is non-nil, and whether or not the layout
74 dictated by `outline-layout' should be imposed on mode activation.
76 With value `t', auto-mode-activation and auto-layout are enabled.
77 \(This also depends on `outline-find-file-hooks' being installed in
78 `find-file-hooks', which is also done by `outline-init'.)
80 With value `ask', auto-mode-activation is enabled, and endorsement for
81 performing auto-layout is asked of the user each time.
83 With value `activate', only auto-mode-activation is enabled, auto-
84 layout is not.
86 With value `nil', neither auto-mode-activation nor auto-layout are
87 enabled.
89 See the docstring for `outline-init' for the proper interface to
90 this variable.")
91 ;;;_ = outline-layout
92 (defvar outline-layout nil
93 "*Layout specification and provisional mode trigger for allout outlines.
95 Buffer-specific.
97 A list value specifies a default layout for the current buffer, to be
98 applied upon activation of allout outline-mode. Any non-nil value
99 will automatically trigger allout outline-mode, provided `outline-
100 init' has been called to enable it.
102 See the docstring for `outline-init' for details on setting up for
103 auto-mode-activation, and for `outline-expose-topic' for the format of
104 the layout specification.
106 You can associate a particular outline layout with a file by setting
107 this var via the file's local variables. For example, the following
108 lines at the bottom of an Emacs Lisp file:
110 ;;;Local variables:
111 ;;;outline-layout: \(0 : -1 -1 0\)
112 ;;;End:
114 will, modulo the above-mentioned conditions, cause the mode to be
115 activated when the file is visited, followed by the equivalent of
116 `\(outline-expose-topic 0 : -1 -1 0\)'. \(This is the layout used for
117 the allout.el, itself.)
119 Also, allout's mode-specific provisions will make topic prefixes
120 default to the comment-start string, if any, of the language of the
121 file. This is modulo the setting of `outline-use-mode-specific-
122 leader', which see.")
123 (make-variable-buffer-local 'outline-layout)
125 ;;;_ = outline-header-prefix
126 (defvar outline-header-prefix "."
127 "*Leading string which helps distinguish topic headers.
129 Outline topic header lines are identified by a leading topic
130 header prefix, which mostly have the value of this var at their front.
131 \(Level 1 topics are exceptions. They consist of only a single
132 character, which is typically set to the outline-primary-bullet. Many
133 outlines start at level 2 to avoid this discrepancy.")
134 (make-variable-buffer-local 'outline-header-prefix)
135 ;;;_ = outline-primary-bullet
136 (defvar outline-primary-bullet "*"
137 "Bullet used for top-level outline topics.
139 Outline topic header lines are identified by a leading topic header
140 prefix, which is concluded by bullets that includes the value of this
141 var and the respective outline-*-bullets-string vars.
143 The value of an asterisk ('*') provides for backwards compatibility
144 with the original emacs outline mode. See outline-plain-bullets-string
145 and outline-distinctive-bullets-string for the range of available
146 bullets.")
147 (make-variable-buffer-local 'outline-primary-bullet)
148 ;;;_ = outline-plain-bullets-string
149 (defvar outline-plain-bullets-string (concat outline-primary-bullet
150 "+-:.;,")
151 "*The bullets normally used in outline topic prefixes.
153 See 'outline-distinctive-bullets-string' for the other kind of
154 bullets.
156 DO NOT include the close-square-bracket, ']', as a bullet.
158 Outline mode has to be reactivated in order for changes to the value
159 of this var to take effect.")
160 (make-variable-buffer-local 'outline-plain-bullets-string)
161 ;;;_ = outline-distinctive-bullets-string
162 (defvar outline-distinctive-bullets-string "=>([{}&!?#%\"X@$~\\"
163 "*Persistent outline header bullets used to distinguish special topics.
165 These bullets are not offered among the regular, level-specific
166 rotation, and are not altered by automatic rebulleting, as when
167 shifting the level of a topic. See `outline-plain-bullets-string' for
168 the selection of alternating bullets.
170 You must run 'set-outline-regexp' in order for changes
171 to the value of this var to effect outline-mode operation.
173 DO NOT include the close-square-bracket, ']', on either of the bullet
174 strings.")
175 (make-variable-buffer-local 'outline-distinctive-bullets-string)
177 ;;;_ = outline-use-mode-specific-leader
178 (defvar outline-use-mode-specific-leader t
179 "*When non-nil, use mode-specific topic-header prefixes.
181 Allout outline mode will use the mode-specific `outline-mode-leaders'
182 and/or comment-start string, if any, to lead the topic prefix string,
183 so topic headers look like comments in the programming language.
185 String values are used as they stand.
187 Value `t' means to first check for assoc value in `outline-mode-leaders'
188 alist, then use comment-start string, if any, then use default \(`.').
189 \(See note about use of comment-start strings, below.\)
191 Set to the symbol for either of `outline-mode-leaders' or
192 `comment-start' to use only one of them, respectively.
194 Value `nil' means to always use the default \(`.'\).
196 comment-start strings that do not end in spaces are tripled, and an
197 '_' underscore is tacked on the end, to distinguish them from regular
198 comment strings. comment-start strings that do end in spaces are not
199 tripled, but an underscore is substituted for the space. \[This
200 presumes that the space is for appearance, not comment syntax. You
201 can use `outline-mode-leaders' to override this behavior, when
202 incorrect.\]")
203 ;;;_ = outline-mode-leaders
204 (defvar outline-mode-leaders '()
205 "Specific outline-prefix leading strings per major modes.
207 Entries will be used in the stead (or lieu) of mode-specific
208 comment-start strings. See also `outline-use-mode-specific-leader'.
210 If you're constructing a string that will comment-out outline
211 structuring so it can be included in program code, append an extra
212 character, like an \"_\" underscore, to distinguish the lead string
213 from regular comments that start at bol.")
215 ;;;_ = outline-old-style-prefixes
216 (defvar outline-old-style-prefixes nil
217 "*When non-nil, use only old-and-crusty outline-mode '*' topic prefixes.
219 Non-nil restricts the topic creation and modification
220 functions to asterix-padded prefixes, so they look exactly
221 like the original emacs-outline style prefixes.
223 Whatever the setting of this variable, both old and new style prefixes
224 are always respected by the topic maneuvering functions.")
225 (make-variable-buffer-local 'outline-old-style-prefixes)
226 ;;;_ = outline-stylish-prefixes - alternating bullets
227 (defvar outline-stylish-prefixes t
228 "*Do fancy stuff with topic prefix bullets according to level, etc.
230 Non-nil enables topic creation, modification, and repositioning
231 functions to vary the topic bullet char (the char that marks the topic
232 depth) just preceding the start of the topic text) according to level.
233 Otherwise, only asterisks ('*') and distinctive bullets are used.
235 This is how an outline can look (but sans indentation) with stylish
236 prefixes:
238 * Top level
239 .* A topic
240 . + One level 3 subtopic
241 . . One level 4 subtopic
242 . . A second 4 subtopic
243 . + Another level 3 subtopic
244 . #1 A numbered level 4 subtopic
245 . #2 Another
246 . ! Another level 4 subtopic with a different distinctive bullet
247 . #4 And another numbered level 4 subtopic
249 This would be an outline with stylish prefixes inhibited (but the
250 numbered and other distinctive bullets retained):
252 * Top level
253 .* A topic
254 . * One level 3 subtopic
255 . * One level 4 subtopic
256 . * A second 4 subtopic
257 . * Another level 3 subtopic
258 . #1 A numbered level 4 subtopic
259 . #2 Another
260 . ! Another level 4 subtopic with a different distinctive bullet
261 . #4 And another numbered level 4 subtopic
263 Stylish and constant prefixes (as well as old-style prefixes) are
264 always respected by the topic maneuvering functions, regardless of
265 this variable setting.
267 The setting of this var is not relevant when outline-old-style-prefixes
268 is non-nil.")
269 (make-variable-buffer-local 'outline-stylish-prefixes)
271 ;;;_ = outline-numbered-bullet
272 (defvar outline-numbered-bullet "#"
273 "*String designating bullet of topics that have auto-numbering; nil for none.
275 Topics having this bullet have automatic maintenance of a sibling
276 sequence-number tacked on, just after the bullet. Conventionally set
277 to \"#\", you can set it to a bullet of your choice. A nil value
278 disables numbering maintenance.")
279 (make-variable-buffer-local 'outline-numbered-bullet)
280 ;;;_ = outline-file-xref-bullet
281 (defvar outline-file-xref-bullet "@"
282 "*Bullet signifying file cross-references, for `outline-resolve-xref'.
284 Set this var to the bullet you want to use for file cross-references.
285 Set it 'nil' if you want to inhibit this capability.")
287 ;;;_ + LaTeX formatting
288 ;;;_ - outline-number-pages
289 (defvar outline-number-pages nil
290 "*Non-nil turns on page numbering for LaTeX formatting of an outline.")
291 ;;;_ - outline-label-style
292 (defvar outline-label-style "\\large\\bf"
293 "*Font and size of labels for LaTeX formatting of an outline.")
294 ;;;_ - outline-head-line-style
295 (defvar outline-head-line-style "\\large\\sl "
296 "*Font and size of entries for LaTeX formatting of an outline.")
297 ;;;_ - outline-body-line-style
298 (defvar outline-body-line-style " "
299 "*Font and size of entries for LaTeX formatting of an outline.")
300 ;;;_ - outline-title-style
301 (defvar outline-title-style "\\Large\\bf"
302 "*Font and size of titles for LaTeX formatting of an outline.")
303 ;;;_ - outline-title
304 (defvar outline-title '(or buffer-file-name (current-buffer-name))
305 "*Expression to be evaluated to determine the title for LaTeX
306 formatted copy.")
307 ;;;_ - outline-line-skip
308 (defvar outline-line-skip ".05cm"
309 "*Space between lines for LaTeX formatting of an outline.")
310 ;;;_ - outline-indent
311 (defvar outline-indent ".3cm"
312 "*LaTeX formatted depth-indent spacing.")
314 ;;;_ + Miscellaneous customization
316 ;;;_ = outline-keybindings-list
317 ;;; You have to reactivate outline-mode - '(outline-mode t)' - to
318 ;;; institute changes to this var.
319 (defvar outline-keybindings-list ()
320 "*List of outline-mode key / function bindings.
322 These bindings will be locally bound on the outline-mode-map. The
323 keys will be prefixed by outline-command-prefix, unless the cell
324 contains a third, no-nil element, in which case the initial string
325 will be used as is.")
326 (setq outline-keybindings-list
328 ; Motion commands:
329 ("?t" outline-latexify-exposed)
330 ("\C-n" outline-next-visible-heading)
331 ("\C-p" outline-previous-visible-heading)
332 ("\C-u" outline-up-current-level)
333 ("\C-f" outline-forward-current-level)
334 ("\C-b" outline-backward-current-level)
335 ("\C-a" outline-beginning-of-current-entry)
336 ("\C-e" outline-end-of-current-entry)
337 ;;("\C-n" outline-next-line-or-topic)
338 ;;("\C-p" outline-previous-line-or-topic)
339 ; Exposure commands:
340 ("\C-i" outline-show-children)
341 ("\C-s" outline-show-current-subtree)
342 ("\C-h" outline-hide-current-subtree)
343 ("\C-o" outline-show-current-entry)
344 ("!" outline-show-all)
345 ; Alteration commands:
346 (" " outline-open-sibtopic)
347 ("." outline-open-subtopic)
348 ("," outline-open-supertopic)
349 ("'" outline-shift-in)
350 (">" outline-shift-in)
351 ("<" outline-shift-out)
352 ("\C-m" outline-rebullet-topic)
353 ("*" outline-rebullet-current-heading)
354 ("#" outline-number-siblings)
355 ("\C-k" outline-kill-line t)
356 ("\C-y" outline-yank t)
357 ("\M-y" outline-yank-pop t)
358 ("\C-k" outline-kill-topic)
359 ; Miscellaneous commands:
360 ("\C-@" outline-mark-topic)
361 ("@" outline-resolve-xref)
362 ("?c" outline-copy-exposed)))
364 ;;;_ = outline-command-prefix
365 (defvar outline-command-prefix "\C-c"
366 "*Key sequence to be used as prefix for outline mode command key bindings.")
368 ;;;_ = outline-enwrap-isearch-mode
369 (defvar outline-enwrap-isearch-mode t
370 "*Set non-nil to enable automatic exposure of concealed isearch targets.
372 If non-nil, isearch will expose hidden text encountered in the course
373 of a search, and to reconceal it if the search is continued past it.")
375 ;;;_ = outline-use-hanging-indents
376 (defvar outline-use-hanging-indents t
377 "*If non-nil, topic body text auto-indent defaults to indent of the header.
378 Ie, it is indented to be just past the header prefix. This is
379 relevant mostly for use with indented-text-mode, or other situations
380 where auto-fill occurs.
382 [This feature no longer depends in any way on the 'filladapt.el'
383 lisp-archive package.]")
384 (make-variable-buffer-local 'outline-use-hanging-indents)
386 ;;;_ = outline-reindent-bodies
387 (defvar outline-reindent-bodies (if outline-use-hanging-indents
388 'text)
389 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
391 When active, topic body lines that are indented even with or beyond
392 their topic header are reindented to correspond with depth shifts of
393 the header.
395 A value of `t' enables reindent in non-programming-code buffers, ie
396 those that do not have the variable `comment-start' set. A value of
397 `force' enables reindent whether or not `comment-start' is set.")
399 (make-variable-buffer-local 'outline-reindent-bodies)
401 ;;;_ = outline-inhibit-protection
402 (defvar outline-inhibit-protection nil
403 "*Non-nil disables warnings and confirmation-checks for concealed-text edits.
405 Outline mode uses emacs change-triggered functions to detect unruly
406 changes to concealed regions. Set this var non-nil to disable the
407 protection, potentially increasing text-entry responsiveness a bit.
409 This var takes effect at outline-mode activation, so you may have to
410 deactivate and then reactivate the mode if you want to toggle the
411 behavior.")
413 ;;;_* CODE - no user customizations below.
415 ;;;_ #1 Internal Outline Formatting and Configuration
416 ;;;_ - Version
417 ;;;_ = outline-version
418 (defvar outline-version
419 (let ((rcs-rev "Revision: 4.3"))
420 (condition-case err
421 (save-match-data
422 (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev)
423 (substring rcs-rev (match-beginning 1) (match-end 1)))
424 (error rcs-rev)))
425 "Revision number of currently loaded outline package. \(allout.el)")
426 ;;;_ > outline-version
427 (defun outline-version (&optional here)
428 "Return string describing the loaded outline version."
429 (interactive "P")
430 (let ((msg (concat "Allout Outline Mode v " outline-version)))
431 (if here (insert-string msg))
432 (message "%s" msg)
433 msg))
434 ;;;_ - Topic header format
435 ;;;_ = outline-regexp
436 (defvar outline-regexp ""
437 "*Regular expression to match the beginning of a heading line.
439 Any line whose beginning matches this regexp is considered a
440 heading. This var is set according to the user configuration vars
441 by set-outline-regexp.")
442 (make-variable-buffer-local 'outline-regexp)
443 ;;;_ = outline-bullets-string
444 (defvar outline-bullets-string ""
445 "A string dictating the valid set of outline topic bullets.
447 This var should *not* be set by the user - it is set by 'set-outline-regexp',
448 and is produced from the elements of 'outline-plain-bullets-string'
449 and 'outline-distinctive-bullets-string'.")
450 (make-variable-buffer-local 'outline-bullets-string)
451 ;;;_ = outline-bullets-string-len
452 (defvar outline-bullets-string-len 0
453 "Length of current buffers' outline-plain-bullets-string.")
454 (make-variable-buffer-local 'outline-bullets-string-len)
455 ;;;_ = outline-line-boundary-regexp
456 (defvar outline-line-boundary-regexp ()
457 "Outline-regexp with outline-style beginning-of-line anchor.
459 \(Ie, C-j, *or* C-m, for prefixes of hidden topics). This is properly
460 set when outline-regexp is produced by 'set-outline-regexp', so
461 that (match-beginning 2) and (match-end 2) delimit the prefix.")
462 (make-variable-buffer-local 'outline-line-boundary-regexp)
463 ;;;_ = outline-bob-regexp
464 (defvar outline-bob-regexp ()
465 "Like outline-line-boundary-regexp, for headers at beginning of buffer.
466 \(match-beginning 2) and (match-end 2) delimit the prefix.")
467 (make-variable-buffer-local 'outline-bob-regexp)
468 ;;;_ = outline-header-subtraction
469 (defvar outline-header-subtraction (1- (length outline-header-prefix))
470 "Outline-header prefix length to subtract when computing topic depth.")
471 (make-variable-buffer-local 'outline-header-subtraction)
472 ;;;_ = outline-plain-bullets-string-len
473 (defvar outline-plain-bullets-string-len (length outline-plain-bullets-string)
474 "Length of outline-plain-bullets-string, updated by set-outline-regexp.")
475 (make-variable-buffer-local 'outline-plain-bullets-string-len)
478 ;;;_ X outline-reset-header-lead (header-lead)
479 (defun outline-reset-header-lead (header-lead)
480 "*Reset the leading string used to identify topic headers."
481 (interactive "sNew lead string: ")
482 (setq outline-header-prefix header-lead)
483 (setq outline-header-subtraction (1- (length outline-header-prefix)))
484 (set-outline-regexp))
485 ;;;_ X outline-lead-with-comment-string (header-lead)
486 (defun outline-lead-with-comment-string (&optional header-lead)
487 "*Set the topic-header leading string to specified string.
489 Useful when for encapsulating outline structure in programming
490 language comments. Returns the leading string."
492 (interactive "P")
493 (if (not (stringp header-lead))
494 (setq header-lead (read-string
495 "String prefix for topic headers: ")))
496 (setq outline-reindent-bodies nil)
497 (outline-reset-header-lead header-lead)
498 header-lead)
499 ;;;_ > outline-infer-header-lead ()
500 (defun outline-infer-header-lead ()
501 "Determine appropriate `outline-header-prefix'.
503 Works according to settings of:
505 `comment-start'
506 `outline-header-prefix' (default)
507 `outline-use-mode-specific-leader'
508 and `outline-mode-leaders'.
510 Apply this via \(re\)activation of `outline-mode', rather than
511 invoking it directly."
512 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader)
513 (if (or (stringp outline-use-mode-specific-leader)
514 (memq outline-use-mode-specific-leader
515 '(outline-mode-leaders
516 comment-start
517 t)))
518 outline-use-mode-specific-leader
519 ;; Oops - garbled value, equate with effect of 't:
520 t)))
521 (leader
522 (cond
523 ((not use-leader) nil)
524 ;; Use the explicitly designated leader:
525 ((stringp use-leader) use-leader)
526 (t (or (and (memq use-leader '(t outline-mode-leaders))
527 ;; Get it from outline mode leaders?
528 (cdr (assq major-mode outline-mode-leaders)))
529 ;; ... didn't get from outline-mode-leaders...
530 (and (memq use-leader '(t comment-start))
531 comment-start
532 ;; Use comment-start, maybe tripled, and with
533 ;; underscore:
534 (concat
535 (if (string= " "
536 (substring comment-start
537 (1- (length comment-start))))
538 ;; Use comment-start, sans trailing space:
539 (substring comment-start 0 -1)
540 (concat comment-start comment-start comment-start))
541 ;; ... and append underscore, whichever:
542 "_")))))))
543 (if (not leader)
545 (if (string= leader outline-header-prefix)
546 nil ; no change, nothing to do.
547 (setq outline-header-prefix leader)
548 outline-header-prefix))))
549 ;;;_ > outline-infer-body-reindent ()
550 (defun outline-infer-body-reindent ()
551 "Determine proper setting for `outline-reindent-bodies'.
553 Depends on default setting of `outline-reindent-bodies' \(which see)
554 and presence of setting for `comment-start', to tell whether the
555 file is programming code."
556 (if (and outline-reindent-bodies
557 comment-start
558 (not (eq 'force outline-reindent-bodies)))
559 (setq outline-reindent-bodies nil)))
560 ;;;_ > set-outline-regexp ()
561 (defun set-outline-regexp ()
562 "Generate proper topic-header regexp form for outline functions.
564 Works with respect to `outline-plain-bullets-string' and
565 `outline-distinctive-bullets-string'."
567 (interactive)
568 ;; Derive outline-bullets-string from user configured components:
569 (setq outline-bullets-string "")
570 (let ((strings (list 'outline-plain-bullets-string
571 'outline-distinctive-bullets-string))
572 cur-string
573 cur-len
574 cur-char
575 cur-char-string
576 index
577 new-string)
578 (while strings
579 (setq new-string "") (setq index 0)
580 (setq cur-len (length (setq cur-string (symbol-value (car strings)))))
581 (while (< index cur-len)
582 (setq cur-char (aref cur-string index))
583 (setq outline-bullets-string
584 (concat outline-bullets-string
585 (cond
586 ; Single dash would denote a
587 ; sequence, repeated denotes
588 ; a dash:
589 ((eq cur-char ?-) "--")
590 ; literal close-square-bracket
591 ; doesn't work right in the
592 ; expr, exclude it:
593 ((eq cur-char ?\]) "")
594 (t (regexp-quote (char-to-string cur-char))))))
595 (setq index (1+ index)))
596 (setq strings (cdr strings)))
598 ;; Derive next for repeated use in outline-pending-bullet:
599 (setq outline-plain-bullets-string-len (length outline-plain-bullets-string))
600 (setq outline-header-subtraction (1- (length outline-header-prefix)))
601 ;; Produce the new outline-regexp:
602 (setq outline-regexp (concat "\\(\\"
603 outline-header-prefix
604 "[ \t]*["
605 outline-bullets-string
606 "]\\)\\|\\"
607 outline-primary-bullet
608 "+\\|\^l"))
609 (setq outline-line-boundary-regexp
610 (concat "\\([\n\r]\\)\\(" outline-regexp "\\)"))
611 (setq outline-bob-regexp
612 (concat "\\(\\`\\)\\(" outline-regexp "\\)"))
614 ;;;_ - Key bindings
615 ;;;_ = outline-mode-map
616 (defvar outline-mode-map nil "Keybindings for (allout) outline minor mode.")
617 ;;;_ > produce-outline-mode-map (keymap-alist &optional base-map)
618 (defun produce-outline-mode-map (keymap-list &optional base-map)
619 "Produce keymap for use as outline-mode-map, from keymap-list.
621 Built on top of optional BASE-MAP, or empty sparse map if none specified.
622 See doc string for outline-keybindings-list for format of binding list."
623 (let ((map (or base-map (make-sparse-keymap))))
624 (mapcar (lambda (cell)
625 (apply 'define-key map (if (null (cdr (cdr cell)))
626 (cons (concat outline-command-prefix
627 (car cell))
628 (cdr cell))
629 (list (car cell) (car (cdr cell))))))
630 keymap-list)
631 map))
632 ;;;_ = outline-prior-bindings - being deprecated.
633 (defvar outline-prior-bindings nil
634 "Variable for use in V18, with outline-added-bindings, for
635 resurrecting, on mode deactivation, bindings that existed before
636 activation. Being deprecated.")
637 ;;;_ = outline-added-bindings - being deprecated
638 (defvar outline-added-bindings nil
639 "Variable for use in V18, with outline-prior-bindings, for
640 resurrecting, on mode deactivation, bindings that existed before
641 activation. Being deprecated.")
642 ;;;_ - Mode-Specific Variable Maintenance Utilities
643 ;;;_ = outline-mode-prior-settings
644 (defvar outline-mode-prior-settings nil
645 "Internal outline mode use; settings to be resumed on mode deactivation.")
646 (make-variable-buffer-local 'outline-mode-prior-settings)
647 ;;;_ > outline-resumptions (name &optional value)
648 (defun outline-resumptions (name &optional value)
650 "Registers or resumes settings over outline-mode activation/deactivation.
652 First arg is NAME of variable affected. Optional second arg is list
653 containing outline-mode-specific VALUE to be imposed on named
654 variable, and to be registered. (It's a list so you can specify
655 registrations of null values.) If no value is specified, the
656 registered value is returned (encapsulated in the list, so the caller
657 can distinguish nil vs no value), and the registration is popped
658 from the list."
660 (let ((on-list (assq name outline-mode-prior-settings))
661 prior-capsule ; By 'capsule' i mean a list
662 ; containing a value, so we can
663 ; distinguish nil from no value.
666 (if value
668 ;; Registering:
669 (progn
670 (if on-list
671 nil ; Already preserved prior value - don't mess with it.
672 ;; Register the old value, or nil if previously unbound:
673 (setq outline-mode-prior-settings
674 (cons (list name
675 (if (boundp name) (list (symbol-value name))))
676 outline-mode-prior-settings)))
677 ; And impose the new value, locally:
678 (progn (make-local-variable name)
679 (set name (car value))))
681 ;; Relinquishing:
682 (if (not on-list)
684 ;; Oops, not registered - leave it be:
687 ;; Some registration:
688 ; reestablish it:
689 (setq prior-capsule (car (cdr on-list)))
690 (if prior-capsule
691 (set name (car prior-capsule)) ; Some prior value - reestablish it.
692 (makunbound name)) ; Previously unbound - demolish var.
693 ; Remove registration:
694 (let (rebuild)
695 (while outline-mode-prior-settings
696 (if (not (eq (car outline-mode-prior-settings)
697 on-list))
698 (setq rebuild
699 (cons (car outline-mode-prior-settings)
700 rebuild)))
701 (setq outline-mode-prior-settings
702 (cdr outline-mode-prior-settings)))
703 (setq outline-mode-prior-settings rebuild)))))
705 ;;;_ - Mode-specific incidentals
706 ;;;_ = outline-during-write-cue nil
707 (defvar outline-during-write-cue nil
708 "Used to inhibit outline change-protection during file write.
710 See also `outline-post-command-business', `outline-write-file-hook',
711 `outline-before-change-protect', and `outline-post-command-business'
712 functions.")
713 ;;;_ = outline-override-protect nil
714 (defvar outline-override-protect nil
715 "Used in outline-mode for regulate of concealed-text protection mechanism.
717 Allout outline mode regulates alteration of concealed text to protect
718 against inadvertent, unnoticed changes. This is for use by specific,
719 native outline functions to temporarily override that protection.
720 It's automatically reset to nil after every buffer modification.")
721 (make-variable-buffer-local 'outline-override-protect)
722 ;;;_ > outline-unprotected (expr)
723 (defmacro outline-unprotected (expr)
724 "Evaluate EXPRESSION with `outline-override-protect' let-bound 't'."
725 (` (let ((outline-override-protect t))
726 (, expr))))
727 ;;;_ = outline-undo-aggregation
728 (defvar outline-undo-aggregation 30
729 "Amount of successive self-insert actions to bunch together per undo.
731 This is purely a kludge variable, regulating the compensation for a bug in
732 the way that before-change-function and undo interact.")
733 (make-variable-buffer-local 'outline-undo-aggregation)
734 ;;;_ = file-var-bug hack
735 (defvar outline-v18/9-file-var-hack nil
736 "Horrible hack used to prevent invalid multiple triggering of outline
737 mode from prop-line file-var activation. Used by outline-mode function
738 to track repeats.")
739 ;;;_ > outline-write-file-hook ()
740 (defun outline-write-file-hook ()
741 "In outline mode, run as a local-write-file-hooks activity.
743 Currently just sets 'outline-during-write-cue', so outline-change-
744 protection knows to keep inactive during file write."
745 (setq outline-during-write-cue t)
746 nil)
748 ;;;_ #2 Mode activation
749 ;;;_ = outline-mode
750 (defvar outline-mode () "Allout outline mode minor-mode flag.")
751 (make-variable-buffer-local 'outline-mode)
752 ;;;_ > outline-mode-p ()
753 (defmacro outline-mode-p ()
754 "Return t if outline-mode is active in current buffer."
755 'outline-mode)
756 ;;;_ = outline-explicitly-deactivated
757 (defvar outline-explicitly-deactivated nil
758 "Outline-mode was last deliberately deactivated.
759 So outline-post-command-business should not reactivate it...")
760 (make-variable-buffer-local 'outline-explicitly-deactivated)
761 ;;;_ > outline-init (&optional mode)
762 (defun outline-init (&optional mode)
763 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'.
765 MODE is one of the following symbols:
767 - nil \(or no argument) deactivate auto-activation/layou;
768 - 'activate', enable auto-activation only;
769 - 'ask', enable auto-activation, and enable auto-layout but with
770 confirmation for layout operation solicited from user each time;
771 - 'report', just report and return the current auto-activation state;
772 - anything else \(eg, t) for auto-activation and auto-layout, without
773 any confirmation check.
775 Use this function to setup your emacs session for automatic activation
776 of allout outline mode, contingent to the buffer-specific setting of
777 the `outline-layout' variable. (See `outline-layout' and
778 `outline-expose-topic' docstrings for more details on auto layout).
780 `outline-init' works by setting up (or removing) the outline-mode
781 find-file-hook, and giving `outline-auto-activation' a suitable
782 setting.
784 To prime your emacs session for full auto-outline operation, include
785 the following two lines in your emacs init file:
787 \(require 'allout)
788 \(outline-init t)"
790 (interactive)
791 (if (interactive-p)
792 (progn
793 (setq mode
794 (completing-read
795 (concat "Select outline auto setup mode "
796 "(empty for report, ? for options) ")
797 '(("nil")("full")("activate")("deactivate")
798 ("ask") ("report") (""))
801 (if (string= mode "")
802 (setq mode 'report)
803 (setq mode (intern-soft mode)))))
804 (let
805 ;; convenience aliases, for consistent ref to respective vars:
806 ((hook 'outline-find-file-hook)
807 (curr-mode 'outline-auto-activation))
809 (cond ((not mode)
810 (setq find-file-hooks (delq hook find-file-hooks))
811 (if (interactive-p)
812 (message "Allout outline mode auto-activation inhibited.")))
813 ((eq mode 'report)
814 (if (not (memq hook find-file-hooks))
815 (outline-init nil)
816 ;; Just punt and use the reports from each of the modes:
817 (outline-init (symbol-value curr-mode))))
818 (t (add-hook 'find-file-hooks hook)
819 (set curr-mode ; 'set', not 'setq'!
820 (cond ((eq mode 'activate)
821 (message
822 "Outline mode auto-activation enabled.")
823 'activate)
824 ((eq mode 'report)
825 ;; Return the current mode setting:
826 (outline-init mode))
827 ((eq mode 'ask)
828 (message
829 (concat "Outline mode auto-activation and "
830 "-layout \(upon confirmation) enabled."))
831 'ask)
832 ((message
833 "Outline mode auto-activation and -layout enabled.")
834 'full)))))))
836 ;;;_ > outline-mode (&optional toggle)
837 ;;;_ : Defun:
838 (defun outline-mode (&optional toggle)
839 ;;;_ . Doc string:
840 "Toggle minor mode for controlling exposure and editing of text outlines.
842 Optional arg forces mode reactivation iff arg is positive num or symbol.
844 Allout outline mode provides extensive outline formatting and
845 manipulation capabilities. It is specifically aimed at supporting
846 outline structuring and manipulation of syntax-sensitive text, eg
847 programming languages. \(For an example, see the allout code itself,
848 which is organized in outline structure.\)
850 It also includes such things as topic-oriented repositioning, cut, and
851 paste; integral outline exposure-layout; incremental search with
852 dynamic exposure/concealment of concealed text; automatic topic-number
853 maintenance; and many other features.
855 See the docstring of the variable `outline-init' for instructions on
856 priming your emacs session for automatic activation of outline-mode,
857 according to file-var settings of the `outline-layout' variable.
859 Below is a description of the bindings, and then explanation of
860 special outline-mode features and terminology.
862 The bindings themselves are established according to the values of
863 variables `outline-keybindings-list' and `outline-command-prefix',
864 each time the mode is invoked. Prior bindings are resurrected when
865 the mode is revoked.
867 Navigation: Exposure Control:
868 ---------- ----------------
869 C-c C-n outline-next-visible-heading | C-c C-h outline-hide-current-subtree
870 C-c C-p outline-previous-visible-heading | C-c C-i outline-show-children
871 C-c C-u outline-up-current-level | C-c C-s outline-show-current-subtree
872 C-c C-f outline-forward-current-level | C-c C-o outline-show-current-entry
873 C-c C-b outline-backward-current-level | ^U C-c C-s outline-show-all
874 C-c C-e outline-end-of-current-entry | outline-hide-current-leaves
875 C-c C-a outline-beginning-of-current-entry, alternately, goes to hot-spot
877 Topic Header Production:
878 -----------------------
879 C-c<SP> outline-open-sibtopic Create a new sibling after current topic.
880 C-c . outline-open-subtopic ... an offspring of current topic.
881 C-c , outline-open-supertopic ... a sibling of the current topic's parent.
883 Topic Level and Prefix Adjustment:
884 ---------------------------------
885 C-c > outline-shift-in Shift current topic and all offspring deeper.
886 C-c < outline-shift-out ... less deep.
887 C-c<CR> outline-rebullet-topic Reconcile bullets of topic and its' offspring
888 - distinctive bullets are not changed, others
889 alternated according to nesting depth.
890 C-c * outline-rebullet-current-heading Prompt for alternate bullet for
891 current topic.
892 C-c # outline-number-siblings Number bullets of topic and siblings - the
893 offspring are not affected. With repeat
894 count, revoke numbering.
896 Topic-oriented Killing and Yanking:
897 ----------------------------------
898 C-c C-k outline-kill-topic Kill current topic, including offspring.
899 C-k outline-kill-line Like kill-line, but reconciles numbering, etc.
900 C-y outline-yank Yank, adjusting depth of yanked topic to
901 depth of heading if yanking into bare topic
902 heading (ie, prefix sans text).
903 M-y outline-yank-pop Is to outline-yank as yank-pop is to yank
905 Misc commands:
906 -------------
907 C-c @ outline-resolve-xref pop-to-buffer named by xref (cf
908 outline-file-xref-bullet)
909 C-c c outline-copy-exposed Copy current topic outline sans concealed
910 text, to buffer with name derived from
911 current buffer - \"XXX exposed\"
912 M-x outlineify-sticky Activate outline mode for current buffer,
913 and establish a default file-var setting
914 for `outline-layout'.
915 ESC ESC (outline-init t) Setup emacs session for outline mode
916 auto-activation.
918 HOT-SPOT Operation
920 Hot-spot operation provides a means for easy, single-keystroke outline
921 navigation and exposure control.
923 \\<outline-mode-map>
924 When the text cursor is positioned directly on the bullet character of
925 a topic, regular characters (a to z) invoke the commands of the
926 corresponding outline-mode keymap control chars. For example, \"f\"
927 would invoke the command typically bound to \"C-c C-f\"
928 \(\\[outline-forward-current-level] `outline-forward-current-level').
930 Thus, by positioning the cursor on a topic bullet, you can execute
931 the outline navigation and manipulation commands with a single
932 keystroke. Non-literal chars never get this special translation, so
933 you can use them to get away from the hot-spot, and back to normal
934 operation.
936 Note that the command `outline-beginning-of-current-entry' \(\\[outline-beginning-of-current-entry]\)
937 will move to the hot-spot when the cursor is already located at the
938 beginning of the current entry, so you can simply hit \\[outline-beginning-of-current-entry]
939 twice in a row to get to the hot-spot.
941 Terminology
943 Topic hierarchy constituents - TOPICS and SUBTOPICS:
945 TOPIC: A basic, coherent component of an emacs outline. It can
946 contain other topics, and it can be subsumed by other topics,
947 CURRENT topic:
948 The visible topic most immediately containing the cursor.
949 DEPTH: The degree of nesting of a topic; it increases with
950 containment. Also called the:
951 LEVEL: The same as DEPTH.
953 ANCESTORS:
954 The topics that contain a topic.
955 PARENT: A topic's immediate ancestor. It has a depth one less than
956 the topic.
957 OFFSPRING:
958 The topics contained by a topic;
959 SUBTOPIC:
960 An immediate offspring of a topic;
961 CHILDREN:
962 The immediate offspring of a topic.
963 SIBLINGS:
964 Topics having the same parent and depth.
966 Topic text constituents:
968 HEADER: The first line of a topic, include the topic PREFIX and header
969 text.
970 PREFIX: The leading text of a topic which which distinguishes it from
971 normal text. It has a strict form, which consists of a
972 prefix-lead string, padding, and a bullet. The bullet may be
973 followed by a number, indicating the ordinal number of the
974 topic among its siblings, a space, and then the header text.
976 The relative length of the PREFIX determines the nesting depth
977 of the topic.
978 PREFIX-LEAD:
979 The string at the beginning of a topic prefix, normally a '.'.
980 It can be customized by changing the setting of
981 `outline-header-prefix' and then reinitializing outline-mode.
983 By setting the prefix-lead to the comment-string of a
984 programming language, you can embed outline-structuring in
985 program code without interfering with the language processing
986 of that code. See `outline-use-mode-specific-leader'
987 docstring for more detail.
988 PREFIX-PADDING:
989 Spaces or asterisks which separate the prefix-lead and the
990 bullet, according to the depth of the topic.
991 BULLET: A character at the end of the topic prefix, it must be one of
992 the characters listed on 'outline-plain-bullets-string' or
993 'outline-distinctive-bullets-string'. (See the documentation
994 for these variables for more details.) The default choice of
995 bullet when generating varies in a cycle with the depth of the
996 topic.
997 ENTRY: The text contained in a topic before any offspring.
998 BODY: Same as ENTRY.
1001 EXPOSURE:
1002 The state of a topic which determines the on-screen visibility
1003 of its' offspring and contained text.
1004 CONCEALED:
1005 Topics and entry text whose display is inhibited. Contiguous
1006 units of concealed text is represented by '...' ellipses.
1007 (Ref the 'selective-display' var.)
1009 Concealed topics are effectively collapsed within an ancestor.
1010 CLOSED: A topic whose immediate offspring and body-text is concealed.
1011 OPEN: A topic that is not closed, though its' offspring or body may be."
1012 ;;;_ . Code
1013 (interactive "P")
1015 (let* ((active (and (not (equal major-mode 'outline))
1016 (outline-mode-p)))
1017 ; Massage universal-arg 'toggle' val:
1018 (toggle (and toggle
1019 (or (and (listp toggle)(car toggle))
1020 toggle)))
1021 ; Activation specifically demanded?
1022 (explicit-activation (or
1024 (and toggle
1025 (or (symbolp toggle)
1026 (and (natnump toggle)
1027 (not (zerop toggle)))))))
1028 ;; outline-mode already called once during this complex command?
1029 (same-complex-command (eq outline-v18/9-file-var-hack
1030 (car command-history)))
1031 do-layout
1034 ; See comments below re v19.18,.19 bug.
1035 (setq outline-v18/9-file-var-hack (car command-history))
1037 (cond
1039 ;; Provision for v19.18, 19.19 bug -
1040 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1041 ;; modes twice when file is visited. We have to avoid toggling mode
1042 ;; off on second invocation, so we detect it as best we can, and
1043 ;; skip everything.
1044 ((and same-complex-command ; Still in same complex command
1045 ; as last time outline-mode invoked.
1046 active ; Already activated.
1047 (not explicit-activation) ; Prop-line file-vars don't have args.
1048 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1049 emacs-version)); 19.19.
1052 ;; Deactivation:
1053 ((and (not explicit-activation)
1054 (or active toggle))
1055 ; Activation not explicitly
1056 ; requested, and either in
1057 ; active state or *de*activation
1058 ; specifically requested:
1059 (setq outline-explicitly-deactivated t)
1060 (if (string-match "^18\." emacs-version)
1061 ; Revoke those keys that remain
1062 ; as we set them:
1063 (let ((curr-loc (current-local-map)))
1064 (mapcar '(lambda (cell)
1065 (if (eq (lookup-key curr-loc (car cell))
1066 (car (cdr cell)))
1067 (define-key curr-loc (car cell)
1068 (assq (car cell) outline-prior-bindings))))
1069 outline-added-bindings)
1070 (outline-resumptions 'outline-added-bindings)
1071 (outline-resumptions 'outline-prior-bindings)))
1073 (if outline-old-style-prefixes
1074 (progn
1075 (outline-resumptions 'outline-primary-bullet)
1076 (outline-resumptions 'outline-old-style-prefixes)))
1077 (outline-resumptions 'selective-display)
1078 (if (and (boundp 'before-change-function) before-change-function)
1079 (outline-resumptions 'before-change-function))
1080 (setq pre-command-hook (delq 'outline-pre-command-business
1081 pre-command-hook))
1082 (setq local-write-file-hooks
1083 (delq 'outline-write-file-hook
1084 local-write-file-hooks))
1085 (outline-resumptions 'paragraph-start)
1086 (outline-resumptions 'paragraph-separate)
1087 (outline-resumptions (if (string-match "^18" emacs-version)
1088 'auto-fill-hook
1089 'auto-fill-function))
1090 (outline-resumptions 'outline-former-auto-filler)
1091 (setq outline-mode nil))
1093 ;; Activation:
1094 ((not active)
1095 (setq outline-explicitly-deactivated nil)
1096 (if outline-old-style-prefixes
1097 (progn ; Inhibit all the fancy formatting:
1098 (outline-resumptions 'outline-primary-bullet '("*"))
1099 (outline-resumptions 'outline-old-style-prefixes '(()))))
1101 (outline-infer-header-lead)
1102 (outline-infer-body-reindent)
1104 (set-outline-regexp)
1106 ; Produce map from current version
1107 ; of outline-keybindings-list:
1108 (if (boundp 'minor-mode-map-alist)
1110 (progn ; V19, and maybe lucid and
1111 ; epoch, minor-mode key bindings:
1112 (setq outline-mode-map
1113 (produce-outline-mode-map outline-keybindings-list))
1114 (fset 'outline-mode-map outline-mode-map)
1115 ; Include on minor-mode-map-alist,
1116 ; if not already there:
1117 (if (not (member '(outline-mode . outline-mode-map)
1118 minor-mode-map-alist))
1119 (setq minor-mode-map-alist
1120 (cons '(outline-mode . outline-mode-map)
1121 minor-mode-map-alist))))
1123 ; V18 minor-mode key bindings:
1124 ; Stash record of added bindings
1125 ; for later revocation:
1126 (outline-resumptions 'outline-added-bindings
1127 (list outline-keybindings-list))
1128 (outline-resumptions 'outline-prior-bindings
1129 (list (current-local-map)))
1130 ; and add them:
1131 (use-local-map (produce-outline-mode-map outline-keybindings-list
1132 (current-local-map)))
1135 ; selective-display is the
1136 ; emacs conditional exposure
1137 ; mechanism:
1138 (outline-resumptions 'selective-display '(t))
1139 (if outline-inhibit-protection
1141 (outline-resumptions 'before-change-function
1142 '(outline-before-change-protect)))
1143 ; Temporarily set by any outline
1144 ; functions that can be trusted to
1145 ; deal properly with concealed text.
1146 (add-hook 'local-write-file-hooks 'outline-write-file-hook)
1147 ; Custom auto-fill func, to support
1148 ; respect for topic headline,
1149 ; hanging-indents, etc:
1150 (let* ((fill-func-var (if (string-match "^18" emacs-version)
1151 'auto-fill-hook
1152 'auto-fill-function))
1153 (fill-func (symbol-value fill-func-var)))
1154 ;; Register prevailing fill func for use by outline-auto-fill:
1155 (outline-resumptions 'outline-former-auto-filler (list fill-func))
1156 ;; Register outline-auto-fill to be used if filling is active:
1157 (outline-resumptions fill-func-var '(outline-auto-fill)))
1158 ;; Paragraphs are broken by topic headlines.
1159 (make-local-variable 'paragraph-start)
1160 (outline-resumptions 'paragraph-start
1161 (list (concat paragraph-start "\\|\\("
1162 outline-regexp "\\)")))
1163 (make-local-variable 'paragraph-separate)
1164 (outline-resumptions 'paragraph-separate
1165 (list (concat paragraph-separate "\\|\\("
1166 outline-regexp "\\)")))
1168 (or (assq 'outline-mode minor-mode-alist)
1169 (setq minor-mode-alist
1170 (cons '(outline-mode " Outl") minor-mode-alist)))
1172 (if outline-layout
1173 (setq do-layout t))
1175 (if outline-enwrap-isearch-mode
1176 (outline-enwrap-isearch))
1178 (run-hooks 'outline-mode-hook)
1179 (setq outline-mode t))
1181 ;; Reactivation:
1182 ((setq do-layout t)
1183 (outline-infer-body-reindent))
1184 ) ; cond
1186 (if (and do-layout
1187 outline-auto-activation
1188 (listp outline-layout)
1189 (and (not (eq outline-auto-activation 'activate))
1190 (if (eq outline-auto-activation 'ask)
1191 (if (y-or-n-p (format "Expose %s with layout '%s'? "
1192 (buffer-name)
1193 outline-layout))
1195 (message "Skipped %s layout." (buffer-name))
1196 nil)
1197 t)))
1198 (save-excursion
1199 (message "Adjusting '%s' exposure..." (buffer-name))
1200 (goto-char 0)
1201 (outline-this-or-next-heading)
1202 (condition-case err
1203 (progn
1204 (apply 'outline-expose-topic (list outline-layout))
1205 (message "Adjusting '%s' exposure... done." (buffer-name)))
1206 ;; Problem applying exposure - notify user, but don't
1207 ;; interrupt, eg, file visit:
1208 (error (message "%s" (car (cdr err)))
1209 (sit-for 1)))))
1210 outline-mode
1211 ) ; let*
1212 ) ; defun
1214 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs
1215 ;;; All the basic outline functions that directly do string matches to
1216 ;;; evaluate heading prefix location set the variables
1217 ;;; `outline-recent-prefix-beginning' and `outline-recent-prefix-end'
1218 ;;; when successful. Functions starting with `outline-recent-' all
1219 ;;; use this state, providing the means to avoid redundant searches
1220 ;;; for just-established data. This optimization can provide
1221 ;;; significant speed improvement, but it must be employed carefully.
1222 ;;;_ = outline-recent-prefix-beginning
1223 (defvar outline-recent-prefix-beginning 0
1224 "Buffer point of the start of the last topic prefix encountered.")
1225 (make-variable-buffer-local 'outline-recent-prefix-beginning)
1226 ;;;_ = outline-recent-prefix-end
1227 (defvar outline-recent-prefix-end 0
1228 "Buffer point of the end of the last topic prefix encountered.")
1229 (make-variable-buffer-local 'outline-recent-prefix-end)
1230 ;;;_ = outline-recent-end-of-subtree
1231 (defvar outline-recent-end-of-subtree 0
1232 "Buffer point last returned by outline-end-of-current-subtree.")
1233 (make-variable-buffer-local 'outline-recent-end-of-subtree)
1234 ;;;_ > outline-prefix-data (beg end)
1235 (defmacro outline-prefix-data (beg end)
1236 "Register outline-prefix state data - BEGINNING and END of prefix.
1238 For reference by 'outline-recent' funcs. Returns BEGINNING."
1239 (` (setq outline-recent-prefix-end (, end)
1240 outline-recent-prefix-beginning (, beg))))
1241 ;;;_ > outline-recent-depth ()
1242 (defmacro outline-recent-depth ()
1243 "Return depth of last heading encountered by an outline maneuvering function.
1245 All outline functions which directly do string matches to assess
1246 headings set the variables outline-recent-prefix-beginning and
1247 outline-recent-prefix-end if successful. This function uses those settings
1248 to return the current depth."
1250 '(max 1 (- outline-recent-prefix-end
1251 outline-recent-prefix-beginning
1252 outline-header-subtraction)))
1253 ;;;_ > outline-recent-prefix ()
1254 (defmacro outline-recent-prefix ()
1255 "Like outline-recent-depth, but returns text of last encountered prefix.
1257 All outline functions which directly do string matches to assess
1258 headings set the variables outline-recent-prefix-beginning and
1259 outline-recent-prefix-end if successful. This function uses those settings
1260 to return the current depth."
1261 '(buffer-substring outline-recent-prefix-beginning
1262 outline-recent-prefix-end))
1263 ;;;_ > outline-recent-bullet ()
1264 (defmacro outline-recent-bullet ()
1265 "Like outline-recent-prefix, but returns bullet of last encountered prefix.
1267 All outline functions which directly do string matches to assess
1268 headings set the variables outline-recent-prefix-beginning and
1269 outline-recent-prefix-end if successful. This function uses those settings
1270 to return the current depth of the most recently matched topic."
1271 '(buffer-substring (1- outline-recent-prefix-end)
1272 outline-recent-prefix-end))
1274 ;;;_ #4 Navigation
1276 ;;;_ - Position Assessment
1277 ;;;_ : Location Predicates
1278 ;;;_ > outline-on-current-heading-p ()
1279 (defun outline-on-current-heading-p ()
1280 "Return non-nil if point is on current visible topics' header line.
1282 Actually, returns prefix beginning point."
1283 (save-excursion
1284 (beginning-of-line)
1285 (and (looking-at outline-regexp)
1286 (outline-prefix-data (match-beginning 0) (match-end 0)))))
1287 ;;;_ > outline-e-o-prefix-p ()
1288 (defun outline-e-o-prefix-p ()
1289 "True if point is located where current topic prefix ends, heading begins."
1290 (and (save-excursion (beginning-of-line)
1291 (looking-at outline-regexp))
1292 (= (point)(save-excursion (outline-end-of-prefix)(point)))))
1293 ;;;_ > outline-hidden-p ()
1294 (defmacro outline-hidden-p ()
1295 "True if point is in hidden text."
1296 '(save-excursion
1297 (and (re-search-backward "[\n\r]" () t)
1298 (= ?\r (following-char)))))
1299 ;;;_ > outline-visible-p ()
1300 (defmacro outline-visible-p ()
1301 "True if point is not in hidden text."
1302 (interactive)
1303 '(not (outline-hidden-p)))
1304 ;;;_ : Location attributes
1305 ;;;_ > outline-depth ()
1306 (defmacro outline-depth ()
1307 "Like outline-current-depth, but respects hidden as well as visible topics."
1308 '(save-excursion
1309 (if (outline-goto-prefix)
1310 (outline-recent-depth)
1311 (progn
1312 ;; Oops, no prefix, zero prefix data:
1313 (outline-prefix-data (point)(point))
1314 ;; ... and return 0:
1315 0))))
1316 ;;;_ > outline-current-depth ()
1317 (defmacro outline-current-depth ()
1318 "Return nesting depth of visible topic most immediately containing point."
1319 '(save-excursion
1320 (if (outline-back-to-current-heading)
1321 (max 1
1322 (- outline-recent-prefix-end
1323 outline-recent-prefix-beginning
1324 outline-header-subtraction))
1325 0)))
1326 ;;;_ > outline-get-current-prefix ()
1327 (defun outline-get-current-prefix ()
1328 "Topic prefix of the current topic."
1329 (save-excursion
1330 (if (outline-goto-prefix)
1331 (outline-recent-prefix))))
1332 ;;;_ > outline-get-bullet ()
1333 (defun outline-get-bullet ()
1334 "Return bullet of containing topic (visible or not)."
1335 (save-excursion
1336 (and (outline-goto-prefix)
1337 (outline-recent-bullet))))
1338 ;;;_ > outline-current-bullet ()
1339 (defun outline-current-bullet ()
1340 "Return bullet of current (visible) topic heading, or none if none found."
1341 (condition-case err
1342 (save-excursion
1343 (outline-back-to-current-heading)
1344 (buffer-substring (- outline-recent-prefix-end 1)
1345 outline-recent-prefix-end))
1346 ;; Quick and dirty provision, ostensibly for missing bullet:
1347 (args-out-of-range nil))
1349 ;;;_ > outline-get-prefix-bullet (prefix)
1350 (defun outline-get-prefix-bullet (prefix)
1351 "Return the bullet of the header prefix string PREFIX."
1352 ;; Doesn't make sense if we're old-style prefixes, but this just
1353 ;; oughtn't be called then, so forget about it...
1354 (if (string-match outline-regexp prefix)
1355 (substring prefix (1- (match-end 0)) (match-end 0))))
1357 ;;;_ - Navigation macros
1358 ;;;_ > outline-next-heading ()
1359 (defmacro outline-next-heading ()
1360 "Move to the heading for the topic \(possibly invisible) before this one.
1362 Returns the location of the heading, or nil if none found."
1364 '(if (and (bobp) (not (eobp)))
1365 (forward-char 1))
1367 '(if (re-search-forward outline-line-boundary-regexp nil 0)
1368 (progn ; Got valid location state - set vars:
1369 (outline-prefix-data
1370 (goto-char (or (match-beginning 2)
1371 outline-recent-prefix-beginning))
1372 (or (match-end 2) outline-recent-prefix-end)))))
1373 ;;;_ : outline-this-or-next-heading
1374 (defun outline-this-or-next-heading ()
1375 "Position cursor on current or next heading."
1376 ;; A throwaway non-macro that is defined after outline-next-heading
1377 ;; and usable by outline-mode.
1378 (if (not (outline-goto-prefix)) (outline-next-heading)))
1379 ;;;_ > outline-previous-heading ()
1380 (defmacro outline-previous-heading ()
1381 "Move to the prior \(possibly invisible) heading line.
1383 Return the location of the beginning of the heading, or nil if not found."
1385 '(if (bobp)
1387 (outline-goto-prefix)
1389 ;; searches are unbounded and return nil if failed:
1390 (or (re-search-backward outline-line-boundary-regexp nil 0)
1391 (looking-at outline-bob-regexp))
1392 (progn ; Got valid location state - set vars:
1393 (outline-prefix-data
1394 (goto-char (or (match-beginning 2)
1395 outline-recent-prefix-beginning))
1396 (or (match-end 2) outline-recent-prefix-end))))))
1398 ;;;_ - Subtree Charting
1399 ;;;_ " These routines either produce or assess charts, which are
1400 ;;; nested lists of the locations of topics within a subtree.
1402 ;;; Use of charts enables efficient navigation of subtrees, by
1403 ;;; requiring only a single regexp-search based traversal, to scope
1404 ;;; out the subtopic locations. The chart then serves as the basis
1405 ;;; for whatever assessment or adjustment of the subtree that is
1406 ;;; required, without requiring redundant topic-traversal procedures.
1408 ;;;_ > outline-chart-subtree (&optional levels orig-depth prev-depth)
1409 (defun outline-chart-subtree (&optional levels orig-depth prev-depth)
1410 "Produce a location \"chart\" of subtopics of the containing topic.
1412 Optional argument LEVELS specifies the depth \(relative to start
1413 depth\) for the chart. Subsequent optional args are not for public
1414 use.
1416 Charts are used to capture outline structure, so that outline-altering
1417 routines need assess the structure only once, and then use the chart
1418 for their elaborate manipulations.
1420 Topics are entered in the chart so the last one is at the car.
1421 The entry for each topic consists of an integer indicating the point
1422 at the beginning of the topic. Charts for offspring consists of a
1423 list containing, recursively, the charts for the respective subtopics.
1424 The chart for a topics' offspring precedes the entry for the topic
1425 itself.
1427 The other function parameters are for internal recursion, and should
1428 not be specified by external callers. ORIG-DEPTH is depth of topic at
1429 starting point, and PREV-DEPTH is depth of prior topic."
1431 (let ((original (not orig-depth)) ; 'orig-depth' set only in recursion.
1432 chart curr-depth)
1434 (if original ; Just starting?
1435 ; Register initial settings and
1436 ; position to first offspring:
1437 (progn (setq orig-depth (outline-depth))
1438 (or prev-depth (setq prev-depth (1+ orig-depth)))
1439 (outline-next-heading)))
1441 ;; Loop over the current levels' siblings. Besides being more
1442 ;; efficient than tail-recursing over a level, it avoids exceeding
1443 ;; the typically quite constrained emacs max-lisp-eval-depth.
1444 ;; Probably would speed things up to implement loop-based stack
1445 ;; operation rather than recursing for lower levels. Bah.
1446 (while (and (not (eobp))
1447 ; Still within original topic?
1448 (< orig-depth (setq curr-depth (outline-recent-depth)))
1449 (cond ((= prev-depth curr-depth)
1450 ;; Register this one and move on:
1451 (setq chart (cons (point) chart))
1452 (if (and levels (<= levels 1))
1453 ;; At depth limit - skip sublevels:
1454 (or (outline-next-sibling curr-depth)
1455 ;; or no more siblings - proceed to
1456 ;; next heading at lesser depth:
1457 (while (and (<= curr-depth
1458 (outline-recent-depth))
1459 (outline-next-heading))))
1460 (outline-next-heading)))
1462 ((and (< prev-depth curr-depth)
1463 (or (not levels)
1464 (> levels 0)))
1465 ;; Recurse on deeper level of curr topic:
1466 (setq chart
1467 (cons (outline-chart-subtree (and levels
1468 (1- levels))
1469 orig-depth
1470 curr-depth)
1471 chart))
1472 ;; ... then continue with this one.
1475 ;; ... else nil if we've ascended back to prev-depth.
1479 (if original ; We're at the last sibling on
1480 ; the original level. Position
1481 ; to the end of it:
1482 (progn (and (not (eobp)) (forward-char -1))
1483 (and (memq (preceding-char) '(?\n ?\^M))
1484 (memq (aref (buffer-substring (max 1 (- (point) 3))
1485 (point))
1487 '(?\n ?\^M))
1488 (forward-char -1))
1489 (setq outline-recent-end-of-subtree (point))))
1491 chart ; (nreverse chart) not necessary,
1492 ; and maybe not preferable.
1494 ;;;_ > outline-chart-siblings (&optional start end)
1495 (defun outline-chart-siblings (&optional start end)
1496 "Produce a list of locations of this and succeeding sibling topics.
1497 Effectively a top-level chart of siblings. See 'outline-chart-subtree'
1498 for an explanation of charts."
1499 (save-excursion
1500 (if (outline-goto-prefix)
1501 (let ((chart (list (point))))
1502 (while (outline-next-sibling)
1503 (setq chart (cons (point) chart)))
1504 (if chart (setq chart (nreverse chart)))))))
1505 ;;;_ > outline-chart-to-reveal (chart depth)
1506 (defun outline-chart-to-reveal (chart depth)
1508 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
1510 Note that point can be left at any of the points on chart, or at the
1511 start point."
1513 (let (result here)
1514 (while (and (or (eq depth t) (> depth 0))
1515 chart)
1516 (setq here (car chart))
1517 (if (listp here)
1518 (let ((further (outline-chart-to-reveal here (or (eq depth t)
1519 (1- depth)))))
1520 ;; We're on the start of a subtree - recurse with it, if there's
1521 ;; more depth to go:
1522 (if further (setq result (append further result)))
1523 (setq chart (cdr chart)))
1524 (goto-char here)
1525 (if (= (preceding-char) ?\r)
1526 (setq result (cons here result)))
1527 (setq chart (cdr chart))))
1528 result))
1529 ;;;_ X outline-chart-spec (chart spec &optional exposing)
1530 (defun outline-chart-spec (chart spec &optional exposing)
1531 "Not yet \(if ever\) implemented.
1533 Produce exposure directives given topic/subtree CHART and an exposure SPEC.
1535 Exposure spec indicates the locations to be exposed and the prescribed
1536 exposure status. Optional arg EXPOSING is an integer, with 0
1537 indicating pending concealment, anything higher indicating depth to
1538 which subtopic headers should be exposed, and negative numbers
1539 indicating (negative of) the depth to which subtopic headers and
1540 bodies should be exposed.
1542 The produced list can have two types of entries. Bare numbers
1543 indicate points in the buffer where topic headers that should be
1544 exposed reside.
1546 - bare negative numbers indicates that the topic starting at the
1547 point which is the negative of the number should be opened,
1548 including their entries.
1549 - bare positive values indicate that this topic header should be
1550 opened.
1551 - Lists signify the beginning and end points of regions that should
1552 be flagged, and the flag to employ. (For concealment: '\(\?r\)', and
1553 exposure:"
1554 (while spec
1555 (cond ((listp spec)
1558 (setq spec (cdr spec)))
1561 ;;;_ - Within Topic
1562 ;;;_ > outline-goto-prefix ()
1563 (defun outline-goto-prefix ()
1564 "Put point at beginning of outline prefix for immediately containing topic.
1566 Goes to first subsequent topic if none immediately containing.
1568 Not sensitive to topic visibility.
1570 Returns a the point at the beginning of the prefix, or nil if none."
1572 (let (done)
1573 (while (and (not done)
1574 (re-search-backward "[\n\r]" nil 1))
1575 (forward-char 1)
1576 (if (looking-at outline-regexp)
1577 (setq done (outline-prefix-data (match-beginning 0)
1578 (match-end 0)))
1579 (forward-char -1)))
1580 (if (bobp)
1581 (cond ((looking-at outline-regexp)
1582 (outline-prefix-data (match-beginning 0)(match-end 0)))
1583 ((outline-next-heading)
1584 (outline-prefix-data (match-beginning 0)(match-end 0)))
1585 (done))
1586 done)))
1587 ;;;_ > outline-end-of-prefix ()
1588 (defun outline-end-of-prefix (&optional ignore-decorations)
1589 "Position cursor at beginning of header text.
1591 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
1592 otherwise skip white space between bullet and ensuing text."
1594 (if (not (outline-goto-prefix))
1596 (let ((match-data (match-data)))
1597 (goto-char (match-end 0))
1598 (if ignore-decorations
1600 (while (looking-at "[0-9]") (forward-char 1))
1601 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))
1602 (store-match-data match-data))
1603 ;; Reestablish where we are:
1604 (outline-current-depth)))
1605 ;;;_ > outline-current-bullet-pos ()
1606 (defun outline-current-bullet-pos ()
1607 "Return position of current \(visible) topic's bullet."
1609 (if (not (outline-current-depth))
1611 (1- (match-end 0))))
1612 ;;;_ > outline-back-to-current-heading ()
1613 (defun outline-back-to-current-heading ()
1614 "Move to heading line of current topic, or beginning if already on the line."
1616 (beginning-of-line)
1617 (prog1 (or (outline-on-current-heading-p)
1618 (and (re-search-backward (concat "^\\(" outline-regexp "\\)")
1620 'move)
1621 (outline-prefix-data (match-beginning 1)(match-end 1))))
1622 (if (interactive-p) (outline-end-of-prefix))))
1623 ;;;_ > outline-pre-next-preface ()
1624 (defun outline-pre-next-preface ()
1625 "Skip forward to just before the next heading line.
1627 Returns that character position."
1629 (if (re-search-forward outline-line-boundary-regexp nil 'move)
1630 (prog1 (goto-char (match-beginning 0))
1631 (outline-prefix-data (match-beginning 2)(match-end 2)))))
1632 ;;;_ > outline-end-of-current-subtree ()
1633 (defun outline-end-of-current-subtree ()
1634 "Put point at the end of the last leaf in the currently visible topic."
1635 (interactive)
1636 (outline-back-to-current-heading)
1637 (let ((level (outline-recent-depth)))
1638 (outline-next-heading)
1639 (while (and (not (eobp))
1640 (> (outline-recent-depth) level))
1641 (outline-next-heading))
1642 (and (not (eobp)) (forward-char -1))
1643 (and (memq (preceding-char) '(?\n ?\^M))
1644 (memq (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1)
1645 '(?\n ?\^M))
1646 (forward-char -1))
1647 (setq outline-recent-end-of-subtree (point))))
1648 ;;;_ > outline-beginning-of-current-entry ()
1649 (defun outline-beginning-of-current-entry ()
1650 "When not already there, position point at beginning of current topic's body.
1652 If already there, move cursor to bullet for hot-spot operation.
1653 \(See outline-mode doc string for details on hot-spot operation.)"
1654 (interactive)
1655 (let ((start-point (point)))
1656 (outline-end-of-prefix)
1657 (if (and (interactive-p)
1658 (= (point) start-point))
1659 (goto-char (outline-current-bullet-pos)))))
1660 ;;;_ > outline-end-of-current-entry ()
1661 (defun outline-end-of-current-entry ()
1662 "Position the point at the end of the current topics' entry."
1663 (interactive)
1664 (outline-show-entry)
1665 (prog1 (outline-pre-next-preface)
1666 (if (and (not (bobp))(looking-at "^$"))
1667 (forward-char -1))))
1669 ;;;_ - Depth-wise
1670 ;;;_ > outline-ascend-to-depth (depth)
1671 (defun outline-ascend-to-depth (depth)
1672 "Ascend to depth DEPTH, returning depth if successful, nil if not."
1673 (if (and (> depth 0)(<= depth (outline-depth)))
1674 (let ((last-good (point)))
1675 (while (and (< depth (outline-depth))
1676 (setq last-good (point))
1677 (outline-beginning-of-level)
1678 (outline-previous-heading)))
1679 (if (= (outline-recent-depth) depth)
1680 (progn (goto-char outline-recent-prefix-beginning)
1681 depth)
1682 (goto-char last-good)
1683 nil))
1684 (if (interactive-p) (outline-end-of-prefix))))
1685 ;;;_ > outline-descend-to-depth (depth)
1686 (defun outline-descend-to-depth (depth)
1687 "Descend to depth DEPTH within current topic.
1689 Returning depth if successful, nil if not."
1690 (let ((start-point (point))
1691 (start-depth (outline-depth)))
1692 (while
1693 (and (> (outline-depth) 0)
1694 (not (= depth (outline-recent-depth))) ; ... not there yet
1695 (outline-next-heading) ; ... go further
1696 (< start-depth (outline-recent-depth)))) ; ... still in topic
1697 (if (and (> (outline-depth) 0)
1698 (= (outline-recent-depth) depth))
1699 depth
1700 (goto-char start-point)
1701 nil))
1703 ;;;_ > outline-up-current-level (arg &optional dont-complain)
1704 (defun outline-up-current-level (arg &optional dont-complain)
1705 "Move out ARG levels from current visible topic.
1707 Positions on heading line of containing topic. Error if unable to
1708 ascend that far, or nil if unable to ascend but optional arg
1709 DONT-COMPLAIN is non-nil."
1710 (interactive "p")
1711 (outline-back-to-current-heading)
1712 (let ((present-level (outline-recent-depth))
1713 (last-good (point))
1714 failed
1715 return)
1716 ;; Loop for iterating arg:
1717 (while (and (> (outline-recent-depth) 1)
1718 (> arg 0)
1719 (not (bobp))
1720 (not failed))
1721 (setq last-good (point))
1722 ;; Loop for going back over current or greater depth:
1723 (while (and (not (< (outline-recent-depth) present-level))
1724 (or (outline-previous-visible-heading 1)
1725 (not (setq failed present-level)))))
1726 (setq present-level (outline-current-depth))
1727 (setq arg (- arg 1)))
1728 (if (or failed
1729 (> arg 0))
1730 (progn (goto-char last-good)
1731 (if (interactive-p) (outline-end-of-prefix))
1732 (if (not dont-complain)
1733 (error "Can't ascend past outermost level.")
1734 (if (interactive-p) (outline-end-of-prefix))
1735 nil))
1736 (if (interactive-p) (outline-end-of-prefix))
1737 outline-recent-prefix-beginning)))
1739 ;;;_ - Linear
1740 ;;;_ > outline-next-sibling (&optional depth backward)
1741 (defun outline-next-sibling (&optional depth backward)
1742 "Like outline-forward-current-level, but respects invisible topics.
1744 Traverse at optional DEPTH, or current depth if none specified.
1746 Go backward if optional arg BACKWARD is non-nil.
1748 Return depth if successful, nil otherwise."
1750 (if (and backward (bobp))
1752 (let ((start-depth (or depth (outline-depth)))
1753 (start-point (point))
1754 last-depth)
1755 (while (and (not (if backward (bobp) (eobp)))
1756 (if backward (outline-previous-heading)
1757 (outline-next-heading))
1758 (> (setq last-depth (outline-recent-depth)) start-depth)))
1759 (if (and (not (eobp))
1760 (and (> (or last-depth (outline-depth)) 0)
1761 (= (outline-recent-depth) start-depth)))
1762 outline-recent-prefix-beginning
1763 (goto-char start-point)
1764 (if depth (outline-depth) start-depth)
1765 nil))))
1766 ;;;_ > outline-previous-sibling (&optional depth backward)
1767 (defun outline-previous-sibling (&optional depth backward)
1768 "Like outline-forward-current-level,but backwards & respect invisible topics.
1770 Optional DEPTH specifies depth to traverse, default current depth.
1772 Optional BACKWARD reverses direction.
1774 Return depth if successful, nil otherwise."
1775 (outline-next-sibling depth (not backward))
1777 ;;;_ > outline-snug-back ()
1778 (defun outline-snug-back ()
1779 "Position cursor at end of previous topic
1781 Presumes point is at the start of a topic prefix."
1782 (if (or (bobp) (eobp))
1784 (forward-char -1))
1785 (if (or (bobp) (not (memq (preceding-char) '(?\n ?\^M))))
1787 (forward-char -1)
1788 (if (or (bobp) (not (memq (preceding-char) '(?\n ?\^M))))
1789 (forward-char -1)))
1790 (point))
1791 ;;;_ > outline-beginning-of-level ()
1792 (defun outline-beginning-of-level ()
1793 "Go back to the first sibling at this level, visible or not."
1794 (outline-end-of-level 'backward))
1795 ;;;_ > outline-end-of-level (&optional backward)
1796 (defun outline-end-of-level (&optional backward)
1797 "Go to the last sibling at this level, visible or not."
1799 (let ((depth (outline-depth)))
1800 (while (outline-previous-sibling depth nil))
1801 (prog1 (outline-recent-depth)
1802 (if (interactive-p) (outline-end-of-prefix)))))
1803 ;;;_ > outline-next-visible-heading (arg)
1804 (defun outline-next-visible-heading (arg)
1805 "Move to the next ARG'th visible heading line, backward if arg is negative.
1807 Move as far as possible in indicated direction \(beginning or end of
1808 buffer\) if headings are exhausted."
1810 (interactive "p")
1811 (let* ((backward (if (< arg 0) (setq arg (* -1 arg))))
1812 (step (if backward -1 1))
1813 (start-point (point))
1814 prev got)
1816 (while (> arg 0) ; limit condition
1817 (while (and (not (if backward (bobp)(eobp))) ; boundary condition
1818 ;; Move, skipping over all those concealed lines:
1819 (< -1 (forward-line step))
1820 (not (setq got (looking-at outline-regexp)))))
1821 ;; Register this got, it may be the last:
1822 (if got (setq prev got))
1823 (setq arg (1- arg)))
1824 (cond (got ; Last move was to a prefix:
1825 (outline-prefix-data (match-beginning 0) (match-end 0))
1826 (outline-end-of-prefix))
1827 (prev ; Last move wasn't, but prev was:
1828 (outline-prefix-data (match-beginning 0) (match-end 0)))
1829 ((not backward) (end-of-line) nil))))
1830 ;;;_ > outline-previous-visible-heading (arg)
1831 (defun outline-previous-visible-heading (arg)
1832 "Move to the previous heading line.
1834 With argument, repeats or can move forward if negative.
1835 A heading line is one that starts with a `*' (or that outline-regexp
1836 matches)."
1837 (interactive "p")
1838 (outline-next-visible-heading (- arg)))
1839 ;;;_ > outline-forward-current-level (arg)
1840 (defun outline-forward-current-level (arg)
1841 "Position point at the next heading of the same level.
1843 Takes optional repeat-count, goes backward if count is negative.
1845 Returns resulting position, else nil if none found."
1846 (interactive "p")
1847 (let ((start-depth (outline-current-depth))
1848 (start-point (point))
1849 (start-arg arg)
1850 (backward (> 0 arg))
1851 last-depth
1852 (last-good (point))
1853 at-boundary)
1854 (if (= 0 start-depth)
1855 (error "No siblings, not in a topic..."))
1856 (if backward (setq arg (* -1 arg)))
1857 (while (not (or (zerop arg)
1858 at-boundary))
1859 (while (and (not (if backward (bobp) (eobp)))
1860 (if backward (outline-previous-visible-heading 1)
1861 (outline-next-visible-heading 1))
1862 (> (setq last-depth (outline-recent-depth)) start-depth)))
1863 (if (and last-depth (= last-depth start-depth)
1864 (not (if backward (bobp) (eobp))))
1865 (setq last-good (point)
1866 arg (1- arg))
1867 (setq at-boundary t)))
1868 (if (and (not (eobp))
1869 (= arg 0)
1870 (and (> (or last-depth (outline-depth)) 0)
1871 (= (outline-recent-depth) start-depth)))
1872 outline-recent-prefix-beginning
1873 (goto-char last-good)
1874 (if (not (interactive-p))
1876 (outline-end-of-prefix)
1877 (error "Hit %s level %d topic, traversed %d of %d requested."
1878 (if backward "first" "last")
1879 (outline-recent-depth)
1880 (- (abs start-arg) arg)
1881 (abs start-arg))))))
1882 ;;;_ > outline-backward-current-level (arg)
1883 (defun outline-backward-current-level (arg)
1884 "Inverse of `outline-forward-current-level'."
1885 (interactive "p")
1886 (if (interactive-p)
1887 (let ((current-prefix-arg (* -1 arg)))
1888 (call-interactively 'outline-forward-current-level))
1889 (outline-forward-current-level (* -1 arg))))
1891 ;;;_ #5 Alteration
1893 ;;;_ - Fundamental
1894 ;;;_ > outline-before-change-protect (beg end)
1895 (defun outline-before-change-protect (beg end)
1896 "Outline before-change hook, regulates changes to concealed text.
1898 Reveal concealed text that would be changed by current command, and
1899 offer user choice to commit or forego the change. Unchanged text is
1900 reconcealed. User has option to have changed text reconcealed.
1902 Undo commands are specially treated - the user is not prompted for
1903 choice, the undoes are always committed (based on presumption that the
1904 things being undone were already subject to this regulation routine),
1905 and undoes always leave the changed stuff exposed.
1907 Changes to concealed regions are ignored while file is being written.
1908 \(This is for the sake of functions that do change the file during
1909 writes, like crypt and zip modes.)
1911 Locally bound in outline buffers to 'before-change-function', which
1912 in emacs 19 is run before any change to the buffer. (Has no effect
1913 in Emacs 18, which doesn't support before-change-function.)
1915 Any functions which set ['this-command' to 'undo', or which set]
1916 'outline-override-protect' non-nil (as does, eg, outline-flag-chars)
1917 are exempt from this restriction."
1918 (if (and (outline-mode-p)
1919 ; outline-override-protect
1920 ; set by functions that know what
1921 ; they're doing, eg outline internals:
1922 (not outline-override-protect)
1923 (not outline-during-write-cue)
1924 (save-match-data ; Preserve operation position state.
1925 ; Both beginning and end chars must
1926 ; be exposed:
1927 (save-excursion (if (memq this-command '(newline open-line))
1928 ;; Compensate for stupid emacs {new,
1929 ;; open-}line display optimization:
1930 (setq beg (1+ beg)
1931 end (1+ end)))
1932 (goto-char beg)
1933 (or (outline-hidden-p)
1934 (and (not (= beg end))
1935 (goto-char end)
1936 (outline-hidden-p))))))
1937 (save-match-data
1938 (if (equal this-command 'undo)
1939 ;; Allow undo without inhibition.
1940 ;; - Undoing new and open-line hits stupid emacs redisplay
1941 ;; optimization (em 19 cmds.c, ~ line 200).
1942 ;; - Presumably, undoing what was properly protected when
1943 ;; done.
1944 ;; - Undo may be users' only recourse in protection faults.
1945 ;; So, expose what getting changed:
1946 (progn (message "Undo! - exposing concealed target...")
1947 (if (outline-hidden-p)
1948 (outline-show-children))
1949 (message "Undo!"))
1950 (let (response
1951 (rehide-completely (save-excursion (outline-goto-prefix)
1952 (outline-hidden-p)))
1953 rehide-place)
1955 (save-excursion
1956 (if (condition-case err
1957 ;; Condition case to catch keyboard quits during reads.
1958 (progn
1959 ; Give them a peek where
1960 (save-excursion
1961 (if (eolp) (setq rehide-place
1962 (outline-goto-prefix)))
1963 (outline-show-entry))
1964 ; Present the message, but...
1965 ; leave the cursor at the location
1966 ; until they respond:
1967 ; Then interpret the response:
1968 (while
1969 (progn
1970 (message (concat "Change inside concealed"
1971 " region - do it? "
1972 "(n or 'y'/'r'eclose)"))
1973 (setq response (read-char))
1974 (not
1975 (cond ((memq response '(?r ?R))
1976 (setq response 'reclose))
1977 ((memq response '(?y ?Y ? ))
1978 (setq response t))
1979 ((memq response '(?n ?N 127))
1980 (setq response nil)
1982 ((eq response ??)
1983 (message
1984 "'r' means 'yes, then reclose")
1985 nil)
1986 (t (message "Please answer y, n, or r")
1987 (sit-for 1)
1988 nil)))))
1989 response)
1990 (quit nil))
1991 ; Continue:
1992 (if (eq response 'reclose)
1993 (save-excursion
1994 (if rehide-place (goto-char rehide-place))
1995 (if rehide-completely
1996 (outline-hide-current-entry-completely)
1997 (outline-hide-current-entry)))
1998 (if (outline-ascend-to-depth (1- (outline-recent-depth)))
1999 (outline-show-children)
2000 (outline-show-to-offshoot)))
2001 ; Prevent:
2002 (if rehide-completely
2003 (save-excursion
2004 (if rehide-place (goto-char rehide-place))
2005 (outline-hide-current-entry-completely))
2006 (outline-hide-current-entry))
2007 (error (concat
2008 "Change within concealed region prevented.")))))))
2009 ) ; if
2010 ) ; defun
2011 ;;;_ = outline-post-goto-bullet
2012 (defvar outline-post-goto-bullet nil
2013 "Outline internal var, for `outline-pre-command-business' hot-spot operation.
2015 When set, tells post-processing to reposition on topic bullet, and
2016 then unset it. Set by outline-pre-command-business when implementing
2017 hot-spot operation, where literal characters typed over a topic bullet
2018 are mapped to the command of the corresponding control-key on the
2019 outline-mode-map.")
2020 (make-variable-buffer-local 'outline-post-goto-bullet)
2021 ;;;_ > outline-post-command-business ()
2022 (defun outline-post-command-business ()
2023 "Outline post-command-hook function.
2025 - Null outline-override-protect, so it's not left open.
2027 - Implement (and clear) outline-post-goto-bullet, for hot-spot
2028 outline commands.
2030 - Massages buffer-undo-list so successive, standard character self-inserts are
2031 aggregated. This kludge compensates for lack of undo bunching when
2032 before-change-function is used."
2034 ; Apply any external change func:
2035 (if (not (outline-mode-p)) ; In outline-mode.
2037 (setq outline-override-protect nil)
2038 (if outline-during-write-cue
2039 ;; Was used by outline-before-change-protect, done with it now:
2040 (setq outline-during-write-cue nil))
2041 ;; Undo bunching business:
2042 (if (and (listp buffer-undo-list) ; Undo history being kept.
2043 (equal this-command 'self-insert-command)
2044 (equal last-command 'self-insert-command))
2045 (let* ((prev-stuff (cdr buffer-undo-list))
2046 (before-prev-stuff (cdr (cdr prev-stuff)))
2047 cur-cell cur-from cur-to
2048 prev-cell prev-from prev-to)
2049 (if (and before-prev-stuff ; Goes back far enough to bother,
2050 (not (car prev-stuff)) ; and break before current,
2051 (not (car before-prev-stuff)) ; !and break before prev!
2052 (setq prev-cell (car (cdr prev-stuff))) ; contents now,
2053 (setq cur-cell (car buffer-undo-list)) ; contents prev.
2055 ;; cur contents denote a single char insertion:
2056 (numberp (setq cur-from (car cur-cell)))
2057 (numberp (setq cur-to (cdr cur-cell)))
2058 (= 1 (- cur-to cur-from))
2060 ;; prev contents denote fewer than aggregate-limit
2061 ;; insertions:
2062 (numberp (setq prev-from (car prev-cell)))
2063 (numberp (setq prev-to (cdr prev-cell)))
2064 ; Below threshold:
2065 (> outline-undo-aggregation (- prev-to prev-from)))
2066 (setq buffer-undo-list
2067 (cons (cons prev-from cur-to)
2068 (cdr (cdr (cdr buffer-undo-list))))))))
2069 ;; Implement -post-goto-bullet, if set: (must be after undo business)
2070 (if (and outline-post-goto-bullet
2071 (outline-current-bullet-pos))
2072 (progn (goto-char (outline-current-bullet-pos))
2073 (setq outline-post-goto-bullet nil)))
2075 ;;;_ > outline-pre-command-business ()
2076 (defun outline-pre-command-business ()
2077 "Outline pre-command-hook function for outline buffers.
2079 Implements special behavior when cursor is on bullet char.
2081 Self-insert characters are reinterpreted control-character references
2082 into the outline-mode-map. The outline-mode post-command hook will
2083 position a cursor that has moved as a result of such reinterpretation,
2084 on the destination topic's bullet, when the cursor wound up in the
2086 The upshot is that you can get easy, single (unmodified) key outline
2087 maneuvering and general operations by positioning the cursor on the
2088 bullet char, and it continues until you deliberately some non-outline
2089 motion command to relocate the cursor off of a bullet char."
2091 (if (and (boundp 'outline-mode)
2092 outline-mode
2093 (eq this-command 'self-insert-command)
2094 (eq (point)(outline-current-bullet-pos)))
2096 (let* ((this-key-num (if (numberp last-command-event)
2097 last-command-event))
2098 mapped-binding)
2100 ; Map upper-register literals
2101 ; to lower register:
2102 (if (<= 96 this-key-num)
2103 (setq this-key-num (- this-key-num 32)))
2104 ; Check if we have a literal:
2105 (if (and (<= 64 this-key-num)
2106 (>= 96 this-key-num))
2107 (setq mapped-binding
2108 (lookup-key 'outline-mode-map
2109 (concat outline-command-prefix
2110 (char-to-string (- this-key-num 64))))))
2111 (if mapped-binding
2112 (setq outline-post-goto-bullet t
2113 this-command mapped-binding)))))
2114 ;;;_ > outline-find-file-hook ()
2115 (defun outline-find-file-hook ()
2116 "Activate outline-mode when `outline-auto-activation' & `outline-layout' are non-nil.
2118 See `outline-init' for setup instructions."
2119 (if (and outline-auto-activation
2120 (not (outline-mode-p))
2121 outline-layout)
2122 (outline-mode t)))
2123 ;;;_ : Establish the hooks
2124 (add-hook 'post-command-hook 'outline-post-command-business)
2125 (add-hook 'pre-command-hook 'outline-pre-command-business)
2127 ;;;_ - Topic Format Assessment
2128 ;;;_ > outline-solicit-alternate-bullet (depth &optional current-bullet)
2129 (defun outline-solicit-alternate-bullet (depth &optional current-bullet)
2131 "Prompt for and return a bullet char as an alternative to the current one.
2133 Offer one suitable for current depth DEPTH as default."
2135 (let* ((default-bullet (or current-bullet
2136 (outline-bullet-for-depth depth)))
2137 (sans-escapes (regexp-sans-escapes outline-bullets-string))
2138 (choice (solicit-char-in-string
2139 (format "Select bullet: %s ('%s' default): "
2140 sans-escapes
2141 default-bullet)
2142 sans-escapes
2143 t)))
2144 (if (string= choice "") default-bullet choice))
2146 ;;;_ > outline-sibling-index (&optional depth)
2147 (defun outline-sibling-index (&optional depth)
2148 "Item number of this prospective topic among its siblings.
2150 If optional arg depth is greater than current depth, then we're
2151 opening a new level, and return 0.
2153 If less than this depth, ascend to that depth and count..."
2155 (save-excursion
2156 (cond ((and depth (<= depth 0) 0))
2157 ((or (not depth) (= depth (outline-depth)))
2158 (let ((index 1))
2159 (while (outline-previous-sibling (outline-recent-depth) nil)
2160 (setq index (1+ index)))
2161 index))
2162 ((< depth (outline-recent-depth))
2163 (outline-ascend-to-depth depth)
2164 (outline-sibling-index))
2165 (0))))
2166 ;;;_ > outline-distinctive-bullet (bullet)
2167 (defun outline-distinctive-bullet (bullet)
2168 "True if bullet is one of those on outline-distinctive-bullets-string."
2169 (string-match (regexp-quote bullet) outline-distinctive-bullets-string))
2170 ;;;_ > outline-numbered-type-prefix (&optional prefix)
2171 (defun outline-numbered-type-prefix (&optional prefix)
2172 "True if current header prefix bullet is numbered bullet."
2173 (and outline-numbered-bullet
2174 (string= outline-numbered-bullet
2175 (if prefix
2176 (outline-get-prefix-bullet prefix)
2177 (outline-get-bullet)))))
2178 ;;;_ > outline-bullet-for-depth (&optional depth)
2179 (defun outline-bullet-for-depth (&optional depth)
2180 "Return outline topic bullet suited to optional DEPTH, or current depth."
2181 ;; Find bullet in plain-bullets-string modulo DEPTH.
2182 (if outline-stylish-prefixes
2183 (char-to-string (aref outline-plain-bullets-string
2184 (% (max 0 (- depth 2))
2185 outline-plain-bullets-string-len)))
2186 outline-primary-bullet)
2189 ;;;_ - Topic Production
2190 ;;;_ > outline-make-topic-prefix (&optional prior-bullet
2191 (defun outline-make-topic-prefix (&optional prior-bullet
2193 depth
2194 solicit
2195 number-control
2196 index)
2197 ;; Depth null means use current depth, non-null means we're either
2198 ;; opening a new topic after current topic, lower or higher, or we're
2199 ;; changing level of current topic.
2200 ;; Solicit dominates specified bullet-char.
2201 ;;;_ . Doc string:
2202 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
2204 All the arguments are optional.
2206 PRIOR-BULLET indicates the bullet of the prefix being changed, or
2207 nil if none. This bullet may be preserved (other options
2208 notwithstanding) if it is on the outline-distinctive-bullets-string,
2209 for instance.
2211 Second arg NEW indicates that a new topic is being opened after the
2212 topic at point, if non-nil. Default bullet for new topics, eg, may
2213 be set (contingent to other args) to numbered bullets if previous
2214 sibling is one. The implication otherwise is that the current topic
2215 is being adjusted - shifted or rebulleted - and we don't consider
2216 bullet or previous sibling.
2218 Third arg DEPTH forces the topic prefix to that depth, regardless of
2219 the current topics' depth.
2221 Fourth arg SOLICIT non-nil provokes solicitation from the user of a
2222 choice among the valid bullets. (This overrides other all the
2223 options, including, eg, a distinctive PRIOR-BULLET.)
2225 Fifth arg, NUMBER-CONTROL, matters only if 'outline-numbered-bullet'
2226 is non-nil *and* soliciting was not explicitly invoked. Then
2227 NUMBER-CONTROL non-nil forces prefix to either numbered or
2228 denumbered format, depending on the value of the sixth arg, INDEX.
2230 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
2232 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
2233 the prefix of the topic is forced to be numbered. Non-nil
2234 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
2235 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
2236 that the index for the numbered prefix will be derived, by counting
2237 siblings back to start of level. If INDEX is a number, then that
2238 number is used as the index for the numbered prefix (allowing, eg,
2239 sequential renumbering to not require this function counting back the
2240 index for each successive sibling)."
2241 ;;;_ . Code:
2242 ;; The options are ordered in likely frequence of use, most common
2243 ;; highest, least lowest. Ie, more likely to be doing prefix
2244 ;; adjustments than soliciting, and yet more than numbering.
2245 ;; Current prefix is least dominant, but most likely to be commonly
2246 ;; specified...
2248 (let* (body
2249 numbering
2250 denumbering
2251 (depth (or depth (outline-depth)))
2252 (header-lead outline-header-prefix)
2253 (bullet-char
2255 ;; Getting value for bullet char is practically the whole job:
2257 (cond
2258 ; Simplest situation - level 1:
2259 ((<= depth 1) (setq header-lead "") outline-primary-bullet)
2260 ; Simple, too: all asterisks:
2261 (outline-old-style-prefixes
2262 ;; Cheat - make body the whole thing, null out header-lead and
2263 ;; bullet-char:
2264 (setq body (make-string depth
2265 (string-to-char outline-primary-bullet)))
2266 (setq header-lead "")
2269 ;; (Neither level 1 nor old-style, so we're space padding.
2270 ;; Sneak it in the condition of the next case, whatever it is.)
2272 ;; Solicitation overrides numbering and other cases:
2273 ((progn (setq body (make-string (- depth 2) ?\ ))
2274 ;; The actual condition:
2275 solicit)
2276 (let* ((got (outline-solicit-alternate-bullet depth)))
2277 ;; Gotta check whether we're numbering and got a numbered bullet:
2278 (setq numbering (and outline-numbered-bullet
2279 (not (and number-control (not index)))
2280 (string= got outline-numbered-bullet)))
2281 ;; Now return what we got, regardless:
2282 got))
2284 ;; Numbering invoked through args:
2285 ((and outline-numbered-bullet number-control)
2286 (if (setq numbering (not (setq denumbering (not index))))
2287 outline-numbered-bullet
2288 (if (and prior-bullet
2289 (not (string= outline-numbered-bullet
2290 prior-bullet)))
2291 prior-bullet
2292 (outline-bullet-for-depth depth))))
2294 ;;; Neither soliciting nor controlled numbering ;;;
2295 ;;; (may be controlled denumbering, tho) ;;;
2297 ;; Check wrt previous sibling:
2298 ((and new ; only check for new prefixes
2299 (<= depth (outline-depth))
2300 outline-numbered-bullet ; ... & numbering enabled
2301 (not denumbering)
2302 (let ((sibling-bullet
2303 (save-excursion
2304 ;; Locate correct sibling:
2305 (or (>= depth (outline-depth))
2306 (outline-ascend-to-depth depth))
2307 (outline-get-bullet))))
2308 (if (and sibling-bullet
2309 (string= outline-numbered-bullet sibling-bullet))
2310 (setq numbering sibling-bullet)))))
2312 ;; Distinctive prior bullet?
2313 ((and prior-bullet
2314 (outline-distinctive-bullet prior-bullet)
2315 ;; Either non-numbered:
2316 (or (not (and outline-numbered-bullet
2317 (string= prior-bullet outline-numbered-bullet)))
2318 ;; or numbered, and not denumbering:
2319 (setq numbering (not denumbering)))
2320 ;; Here 'tis:
2321 prior-bullet))
2323 ;; Else, standard bullet per depth:
2324 ((outline-bullet-for-depth depth)))))
2326 (concat header-lead
2327 body
2328 bullet-char
2329 (if numbering
2330 (format "%d" (cond ((and index (numberp index)) index)
2331 (new (1+ (outline-sibling-index depth)))
2332 ((outline-sibling-index))))))
2335 ;;;_ > outline-open-topic (relative-depth &optional before)
2336 (defun outline-open-topic (relative-depth &optional before)
2337 "Open a new topic at depth DEPTH.
2339 New topic is situated after current one, unless optional flag BEFORE
2340 is non-nil, or unless current line is complete empty (not even
2341 whitespace), in which case open is done on current line.
2343 Nuances:
2345 - Creation of new topics is with respect to the visible topic
2346 containing the cursor, regardless of intervening concealed ones.
2348 - New headers are generally created after/before the body of a
2349 topic. However, they are created right at cursor location if the
2350 cursor is on a blank line, even if that breaks the current topic
2351 body. This is intentional, to provide a simple means for
2352 deliberately dividing topic bodies.
2354 - Double spacing of topic lists is preserved. Also, the first
2355 level two topic is created double-spaced (and so would be
2356 subsequent siblings, if that's left intact). Otherwise,
2357 single-spacing is used.
2359 - Creation of sibling or nested topics is with respect to the topic
2360 you're starting from, even when creating backwards. This way you
2361 can easily create a sibling in front of the current topic without
2362 having to go to its preceding sibling, and then open forward
2363 from there."
2365 (let* ((depth (+ (outline-current-depth) relative-depth))
2366 (opening-on-blank (if (looking-at "^\$")
2367 (not (setq before nil))))
2368 opening-numbered ; Will get while computing ref-topic, below
2369 ref-depth ; Will get while computing ref-topic, next
2370 (ref-topic (save-excursion
2371 (cond ((< relative-depth 0)
2372 (outline-ascend-to-depth depth))
2373 ((>= relative-depth 1) nil)
2374 (t (outline-back-to-current-heading)))
2375 (setq ref-depth (outline-recent-depth))
2376 (setq opening-numbered
2377 (save-excursion
2378 (and outline-numbered-bullet
2379 (or (<= relative-depth 0)
2380 (outline-descend-to-depth depth))
2381 (if (outline-numbered-type-prefix)
2382 outline-numbered-bullet))))
2383 (point)))
2384 dbl-space
2385 doing-beginning)
2387 (if (not opening-on-blank)
2388 ; Positioning and vertical
2389 ; padding - only if not
2390 ; opening-on-blank:
2391 (progn
2392 (goto-char ref-topic)
2393 (setq dbl-space ; Determine double space action:
2394 (or (and (<= relative-depth 0) ; not descending;
2395 (save-excursion
2396 ;; at b-o-b or preceded by a blank line?
2397 (or (> 0 (forward-line -1))
2398 (looking-at "^\\s-*$")
2399 (bobp)))
2400 (save-excursion
2401 ;; succeeded by a blank line?
2402 (outline-end-of-current-subtree)
2403 (bolp)))
2404 (and (= ref-depth 1)
2405 (or before
2406 (= depth 1)
2407 (save-excursion
2408 ;; Don't already have following
2409 ;; vertical padding:
2410 (not (outline-pre-next-preface)))))))
2412 ; Position to prior heading,
2413 ; if inserting backwards, and
2414 ; not going outwards:
2415 (if (and before (>= relative-depth 0))
2416 (progn (outline-back-to-current-heading)
2417 (setq doing-beginning (bobp))
2418 (if (not (bobp))
2419 (outline-previous-heading)))
2420 (if (and before (bobp))
2421 (outline-unprotected (open-line 1))))
2423 (if (<= relative-depth 0)
2424 ;; Not going inwards, don't snug up:
2425 (if doing-beginning
2426 (outline-unprotected (open-line (if dbl-space 2 1)))
2427 (if before
2428 (progn (end-of-line)
2429 (outline-pre-next-preface)
2430 (while (= ?\r (following-char))
2431 (forward-char 1))
2432 (if (not (looking-at "^$"))
2433 (outline-unprotected (open-line 1))))
2434 (outline-end-of-current-subtree)))
2435 ;; Going inwards - double-space if first offspring is,
2436 ;; otherwise snug up.
2437 (end-of-line) ; So we skip any concealed progeny.
2438 (outline-pre-next-preface)
2439 (if (bolp)
2440 ;; Blank lines between current header body and next
2441 ;; header - get to last substantive (non-white-space)
2442 ;; line in body:
2443 (re-search-backward "[^ \t\n]" nil t))
2444 (if (save-excursion
2445 (outline-next-heading)
2446 (if (> (outline-recent-depth) ref-depth)
2447 ;; This is an offspring.
2448 (progn (forward-line -1)
2449 (looking-at "^\\s-*$"))))
2450 (progn (forward-line 1)
2451 (outline-unprotected (open-line 1))))
2452 (end-of-line))
2453 ;;(if doing-beginning (goto-char doing-beginning))
2454 (if (not (bobp))
2455 (progn (if (and (not (> depth ref-depth))
2456 (not before))
2457 (outline-unprotected (open-line 1))
2458 (if (> depth ref-depth)
2459 (outline-unprotected (newline 1))
2460 (if dbl-space
2461 (outline-unprotected (open-line 1))
2462 (if (not before)
2463 (outline-unprotected (newline 1))))))
2464 (if dbl-space
2465 (outline-unprotected (newline 1)))
2466 (if (and (not (eobp))
2467 (not (bolp)))
2468 (forward-char 1))))
2470 (insert-string (concat (outline-make-topic-prefix opening-numbered
2472 depth)
2473 " "))
2475 ;;(if doing-beginning (save-excursion (newline (if dbl-space 2 1))))
2478 (outline-rebullet-heading nil ;;; solicit
2479 depth ;;; depth
2480 nil ;;; number-control
2481 nil ;;; index
2482 t) (end-of-line)
2485 ;;;_ . open-topic contingencies
2486 ;;;_ ; base topic - one from which open was issued
2487 ;;;_ , beginning char
2488 ;;;_ , amount of space before will be used, unless opening in place
2489 ;;;_ , end char will be used, unless opening before (and it still may)
2490 ;;;_ ; absolute depth of new topic
2491 ;;;_ ! insert in place - overrides most stuff
2492 ;;;_ ; relative depth of new re base
2493 ;;;_ ; before or after base topic
2494 ;;;_ ; spacing around topic, if any, prior to new topic and at same depth
2495 ;;;_ ; buffer boundaries - special provisions for beginning and end ob
2496 ;;;_ ; level 1 topics have special provisions also - double space.
2497 ;;;_ ; location of new topic
2498 ;;;_ .
2499 ;;;_ > outline-open-subtopic (arg)
2500 (defun outline-open-subtopic (arg)
2501 "Open new topic header at deeper level than the current one.
2503 Negative universal arg means to open deeper, but place the new topic
2504 prior to the current one."
2505 (interactive "p")
2506 (outline-open-topic 1 (> 0 arg)))
2507 ;;;_ > outline-open-sibtopic (arg)
2508 (defun outline-open-sibtopic (arg)
2509 "Open new topic header at same level as the current one.
2511 Negative universal arg means to place the new topic prior to the current
2512 one."
2513 (interactive "p")
2514 (outline-open-topic 0 (> 0 arg)))
2515 ;;;_ > outline-open-supertopic (arg)
2516 (defun outline-open-supertopic (arg)
2517 "Open new topic header at shallower level than the current one.
2519 Negative universal arg means to open shallower, but place the new
2520 topic prior to the current one."
2522 (interactive "p")
2523 (outline-open-topic -1 (> 0 arg)))
2525 ;;;_ - Outline Alteration
2526 ;;;_ : Topic Modification
2527 ;;;_ = outline-former-auto-filler
2528 (defvar outline-former-auto-filler nil
2529 "Name of modal fill function being wrapped by outline-auto-fill.")
2530 ;;;_ > outline-auto-fill ()
2531 (defun outline-auto-fill ()
2532 "Outline-mode autofill function.
2534 Maintains outline hanging topic indentation if
2535 `outline-use-hanging-indents' is set."
2536 (let ((fill-prefix (if outline-use-hanging-indents
2537 ;; Check for topic header indentation:
2538 (save-excursion
2539 (beginning-of-line)
2540 (if (looking-at outline-regexp)
2541 ;; ... construct indentation to account for
2542 ;; length of topic prefix:
2543 (make-string (progn (outline-end-of-prefix)
2544 (current-column))
2545 ?\ ))))))
2546 (if (or outline-former-auto-filler outline-use-hanging-indents)
2547 (do-auto-fill))))
2548 ;;;_ > outline-reindent-body (old-depth new-depth &optional number)
2549 (defun outline-reindent-body (old-depth new-depth &optional number)
2550 "Reindent body lines which were indented at old-depth to new-depth.
2552 Optional arg NUMBER indicates numbering is being added, and it must
2553 be accommodated.
2555 Note that refill of indented paragraphs is not done."
2557 (save-excursion
2558 (outline-end-of-prefix)
2559 (let* ((new-margin (current-column))
2560 excess old-indent-begin old-indent-end
2561 curr-ind
2562 ;; We want the column where the header-prefix text started
2563 ;; *before* the prefix was changed, so we infer it relative
2564 ;; to the new margin and the shift in depth:
2565 (old-margin (+ old-depth (- new-margin new-depth))))
2567 ;; Process lines up to (but excluding) next topic header:
2568 (outline-unprotected
2569 (save-match-data
2570 (while
2571 (and (re-search-forward "[\n\r]\\(\\s-*\\)"
2574 ;; Register the indent data, before we reset the
2575 ;; match data with a subsequent 'looking-at':
2576 (setq old-indent-begin (match-beginning 1)
2577 old-indent-end (match-end 1))
2578 (not (looking-at outline-regexp)))
2579 (if (> 0 (setq excess (- (current-column)
2580 old-margin)))
2581 ;; Text starts left of old margin - don't adjust:
2583 ;; Text was hanging at or right of old left margin -
2584 ;; reindent it, preserving its existing indentation
2585 ;; beyond the old margin:
2586 (delete-region old-indent-begin old-indent-end)
2587 (indent-to (+ new-margin excess)))))))))
2588 ;;;_ > outline-rebullet-current-heading (arg)
2589 (defun outline-rebullet-current-heading (arg)
2590 "Like non-interactive version 'outline-rebullet-heading'.
2592 But \(only\) affects visible heading containing point.
2594 With repeat count, solicit for bullet."
2595 (interactive "P")
2596 (save-excursion (outline-back-to-current-heading)
2597 (outline-end-of-prefix)
2598 (outline-rebullet-heading (not arg) ;;; solicit
2599 nil ;;; depth
2600 nil ;;; number-control
2601 nil ;;; index
2602 t) ;;; do-successors
2605 ;;;_ > outline-rebullet-heading (&optional solicit ...)
2606 (defun outline-rebullet-heading (&optional solicit
2607 new-depth
2608 number-control
2609 index
2610 do-successors)
2612 "Adjust bullet of current topic prefix.
2614 All args are optional.
2616 If SOLICIT is non-nil then the choice of bullet is solicited from
2617 user. Otherwise the distinctiveness of the bullet or the topic
2618 depth determines it.
2620 Second arg DEPTH forces the topic prefix to that depth, regardless
2621 of the topics current depth.
2623 Third arg NUMBER-CONTROL can force the prefix to or away from
2624 numbered form. It has effect only if 'outline-numbered-bullet' is
2625 non-nil and soliciting was not explicitly invoked (via first arg).
2626 Its effect, numbering or denumbering, then depends on the setting
2627 of the forth arg, INDEX.
2629 If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the
2630 prefix of the topic is forced to be non-numbered. Null index and
2631 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
2632 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
2633 INDEX is a number, then that number is used for the numbered
2634 prefix. Non-nil and non-number means that the index for the
2635 numbered prefix will be derived by outline-make-topic-prefix.
2637 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
2638 siblings.
2640 Cf vars 'outline-stylish-prefixes', 'outline-old-style-prefixes',
2641 and 'outline-numbered-bullet', which all affect the behavior of
2642 this function."
2644 (let* ((current-depth (outline-depth))
2645 (new-depth (or new-depth current-depth))
2646 (mb outline-recent-prefix-beginning)
2647 (me outline-recent-prefix-end)
2648 (current-bullet (buffer-substring (- me 1) me))
2649 (new-prefix (outline-make-topic-prefix current-bullet
2651 new-depth
2652 solicit
2653 number-control
2654 index)))
2656 ;; Is new one is identical to old?
2657 (if (and (= current-depth new-depth)
2658 (string= current-bullet
2659 (substring new-prefix (1- (length new-prefix)))))
2660 ;; Nothing to do:
2663 ;; New prefix probably different from old:
2664 ; get rid of old one:
2665 (outline-unprotected (delete-region mb me))
2666 (goto-char mb)
2667 ; Dispense with number if
2668 ; numbered-bullet prefix:
2669 (if (and outline-numbered-bullet
2670 (string= outline-numbered-bullet current-bullet)
2671 (looking-at "[0-9]+"))
2672 (outline-unprotected
2673 (delete-region (match-beginning 0)(match-end 0))))
2675 ; Put in new prefix:
2676 (outline-unprotected (insert-string new-prefix))
2678 ;; Reindent the body if elected and margin changed:
2679 (if (and outline-reindent-bodies
2680 (not (= new-depth current-depth)))
2681 (outline-reindent-body current-depth new-depth))
2683 ;; Recursively rectify successive siblings of orig topic if
2684 ;; caller elected for it:
2685 (if do-successors
2686 (save-excursion
2687 (while (outline-next-sibling new-depth nil)
2688 (setq index
2689 (cond ((numberp index) (1+ index))
2690 ((not number-control) (outline-sibling-index))))
2691 (if (outline-numbered-type-prefix)
2692 (outline-rebullet-heading nil ;;; solicit
2693 new-depth ;;; new-depth
2694 number-control;;; number-control
2695 index ;;; index
2696 nil))))) ;;;(dont!)do-successors
2697 ) ; (if (and (= current-depth new-depth)...))
2698 ) ; let* ((current-depth (outline-depth))...)
2699 ) ; defun
2700 ;;;_ > outline-rebullet-topic (arg)
2701 (defun outline-rebullet-topic (arg)
2702 "Like outline-rebullet-topic-grunt, but start from topic visible at point.
2704 Descends into invisible as well as visible topics, however.
2706 With repeat count, shift topic depth by that amount."
2707 (interactive "P")
2708 (let ((start-col (current-column))
2709 (was-eol (eolp)))
2710 (save-excursion
2711 ;; Normalize arg:
2712 (cond ((null arg) (setq arg 0))
2713 ((listp arg) (setq arg (car arg))))
2714 ;; Fill the user in, in case we're shifting a big topic:
2715 (if (not (zerop arg)) (message "Shifting..."))
2716 (outline-back-to-current-heading)
2717 (if (<= (+ (outline-recent-depth) arg) 0)
2718 (error "Attempt to shift topic below level 1"))
2719 (outline-rebullet-topic-grunt arg)
2720 (if (not (zerop arg)) (message "Shifting... done.")))
2721 (move-to-column (max 0 (+ start-col arg)))))
2722 ;;;_ > outline-rebullet-topic-grunt (&optional relative-depth ...)
2723 (defun outline-rebullet-topic-grunt (&optional relative-depth
2724 starting-depth
2725 starting-point
2726 index
2727 do-successors)
2729 "Rebullet the topic at point, visible or invisible, and all
2730 contained subtopics. See outline-rebullet-heading for rebulleting
2731 behavior.
2733 All arguments are optional.
2735 First arg RELATIVE-DEPTH means to shift the depth of the entire
2736 topic that amount.
2738 The rest of the args are for internal recursive use by the function
2739 itself. The are STARTING-DEPTH, STARTING-POINT, and INDEX."
2741 (let* ((relative-depth (or relative-depth 0))
2742 (new-depth (outline-depth))
2743 (starting-depth (or starting-depth new-depth))
2744 (on-starting-call (null starting-point))
2745 (index (or index
2746 ;; Leave index null on starting call, so rebullet-heading
2747 ;; calculates it at what might be new depth:
2748 (and (or (zerop relative-depth)
2749 (not on-starting-call))
2750 (outline-sibling-index))))
2751 (moving-outwards (< 0 relative-depth))
2752 (starting-point (or starting-point (point))))
2754 ;; Sanity check for excessive promotion done only on starting call:
2755 (and on-starting-call
2756 moving-outwards
2757 (> 0 (+ starting-depth relative-depth))
2758 (error "Attempt to shift topic out beyond level 1.")) ;;; ====>
2760 (cond ((= starting-depth new-depth)
2761 ;; We're at depth to work on this one:
2762 (outline-rebullet-heading nil ;;; solicit
2763 (+ starting-depth ;;; starting-depth
2764 relative-depth)
2765 nil ;;; number
2766 index ;;; index
2767 ;; Every contained topic will get hit,
2768 ;; and we have to get to outside ones
2769 ;; deliberately:
2770 nil) ;;; do-successors
2771 ;; ... and work on subsequent ones which are at greater depth:
2772 (setq index 0)
2773 (outline-next-heading)
2774 (while (and (not (eobp))
2775 (< starting-depth (outline-recent-depth)))
2776 (setq index (1+ index))
2777 (outline-rebullet-topic-grunt relative-depth ;;; relative-depth
2778 (1+ starting-depth);;;starting-depth
2779 starting-point ;;; starting-point
2780 index))) ;;; index
2782 ((< starting-depth new-depth)
2783 ;; Rare case - subtopic more than one level deeper than parent.
2784 ;; Treat this one at an even deeper level:
2785 (outline-rebullet-topic-grunt relative-depth ;;; relative-depth
2786 new-depth ;;; starting-depth
2787 starting-point ;;; starting-point
2788 index))) ;;; index
2790 (if on-starting-call
2791 (progn
2792 ;; Rectify numbering of former siblings of the adjusted topic,
2793 ;; if topic has changed depth
2794 (if (or do-successors
2795 (and (not (zerop relative-depth))
2796 (or (= (outline-recent-depth) starting-depth)
2797 (= (outline-recent-depth) (+ starting-depth
2798 relative-depth)))))
2799 (outline-rebullet-heading nil nil nil nil t))
2800 ;; Now rectify numbering of new siblings of the adjusted topic,
2801 ;; if depth has been changed:
2802 (progn (goto-char starting-point)
2803 (if (not (zerop relative-depth))
2804 (outline-rebullet-heading nil nil nil nil t)))))
2807 ;;;_ > outline-renumber-to-depth (&optional depth)
2808 (defun outline-renumber-to-depth (&optional depth)
2809 "Renumber siblings at current depth.
2811 Affects superior topics if optional arg DEPTH is less than current depth.
2813 Returns final depth."
2815 ;; Proceed by level, processing subsequent siblings on each,
2816 ;; ascending until we get shallower than the start depth:
2818 (let ((ascender (outline-depth)))
2819 (while (and (not (eobp))
2820 (outline-depth)
2821 (>= (outline-recent-depth) depth)
2822 (>= ascender depth))
2823 ; Skip over all topics at
2824 ; lesser depths, which can not
2825 ; have been disturbed:
2826 (while (and (not (eobp))
2827 (> (outline-recent-depth) ascender))
2828 (outline-next-heading))
2829 ; Prime ascender for ascension:
2830 (setq ascender (1- (outline-recent-depth)))
2831 (if (>= (outline-recent-depth) depth)
2832 (outline-rebullet-heading nil ;;; solicit
2833 nil ;;; depth
2834 nil ;;; number-control
2835 nil ;;; index
2836 t))));;; do-successors
2837 (outline-recent-depth))
2838 ;;;_ > outline-number-siblings (&optional denumber)
2839 (defun outline-number-siblings (&optional denumber)
2840 "Assign numbered topic prefix to this topic and its siblings.
2842 With universal argument, denumber - assign default bullet to this
2843 topic and its siblings.
2845 With repeated universal argument (`^U^U'), solicit bullet for each
2846 rebulleting each topic at this level."
2848 (interactive "P")
2850 (save-excursion
2851 (outline-back-to-current-heading)
2852 (outline-beginning-of-level)
2853 (let ((depth (outline-recent-depth))
2854 (index (if (not denumber) 1))
2855 (use-bullet (equal '(16) denumber))
2856 (more t))
2857 (while more
2858 (outline-rebullet-heading use-bullet ;;; solicit
2859 depth ;;; depth
2860 t ;;; number-control
2861 index ;;; index
2862 nil) ;;; do-successors
2863 (if index (setq index (1+ index)))
2864 (setq more (outline-next-sibling depth nil))))))
2865 ;;;_ > outline-shift-in (arg)
2866 (defun outline-shift-in (arg)
2867 "Increase depth of current heading and any topics collapsed within it."
2868 (interactive "p")
2869 (outline-rebullet-topic arg))
2870 ;;;_ > outline-shift-out (arg)
2871 (defun outline-shift-out (arg)
2872 "Decrease depth of current heading and any topics collapsed within it."
2873 (interactive "p")
2874 (outline-rebullet-topic (* arg -1)))
2875 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
2876 ;;;_ > outline-kill-line (&optional arg)
2877 (defun outline-kill-line (&optional arg)
2878 "Kill line, adjusting subsequent lines suitably for outline mode."
2880 (interactive "*P")
2881 (if (not (and (outline-mode-p) ; active outline mode,
2882 outline-numbered-bullet ; numbers may need adjustment,
2883 (bolp) ; may be clipping topic head,
2884 (looking-at outline-regexp))) ; are clipping topic head.
2885 ;; Above conditions do not obtain - just do a regular kill:
2886 (kill-line arg)
2887 ;; Ah, have to watch out for adjustments:
2888 (let* ((depth (outline-depth)))
2889 ; Do the kill:
2890 (kill-line arg)
2891 ; Provide some feedback:
2892 (sit-for 0)
2893 (save-excursion
2894 ; Start with the topic
2895 ; following killed line:
2896 (if (not (looking-at outline-regexp))
2897 (outline-next-heading))
2898 (outline-renumber-to-depth depth)))))
2899 ;;;_ > outline-kill-topic ()
2900 (defun outline-kill-topic ()
2901 "Kill topic together with subtopics.
2903 Leaves primary topic's trailing vertical whitespace, if any."
2905 ;; Some finagling is done to make complex topic kills appear faster
2906 ;; than they actually are. A redisplay is performed immediately
2907 ;; after the region is disposed of, though the renumbering process
2908 ;; has yet to be performed. This means that there may appear to be
2909 ;; a lag *after* the kill has been performed.
2911 (interactive)
2912 (let* ((beg (prog1 (outline-back-to-current-heading)(beginning-of-line)))
2913 (depth (outline-recent-depth)))
2914 (outline-end-of-current-subtree)
2915 (if (not (eobp))
2916 (if (or (not (looking-at "^$"))
2917 ;; A blank line - cut it with this topic *unless* this
2918 ;; is the last topic at this level, in which case
2919 ;; we'll leave the blank line as part of the
2920 ;; containing topic:
2921 (save-excursion
2922 (and (outline-next-heading)
2923 (>= (outline-recent-depth) depth))))
2924 (forward-char 1)))
2926 (kill-region beg (point))
2927 (sit-for 0)
2928 (save-excursion
2929 (outline-renumber-to-depth depth))))
2930 ;;;_ > outline-yank-processing ()
2931 (defun outline-yank-processing (&optional arg)
2933 "Incidental outline-specific business to be done just after text yanks.
2935 Does depth adjustment of yanked topics, when:
2937 1 the stuff being yanked starts with a valid outline header prefix, and
2938 2 it is being yanked at the end of a line which consists of only a valid
2939 topic prefix.
2941 Also, adjusts numbering of subsequent siblings when appropriate.
2943 Depth adjustment alters the depth of all the topics being yanked
2944 the amount it takes to make the first topic have the depth of the
2945 header into which it's being yanked.
2947 The point is left in front of yanked, adjusted topics, rather than
2948 at the end (and vice-versa with the mark). Non-adjusted yanks,
2949 however, are left exactly like normal, non-outline-specific yanks."
2951 (interactive "*P")
2952 ; Get to beginning, leaving
2953 ; region around subject:
2954 (if (< (mark-marker) (point))
2955 (exchange-point-and-mark))
2956 (let* ((subj-beg (point))
2957 (subj-end (mark-marker))
2958 ;; 'resituate' if yanking an entire topic into topic header:
2959 (resituate (and (outline-e-o-prefix-p)
2960 (looking-at (concat "\\(" outline-regexp "\\)"))
2961 (outline-prefix-data (match-beginning 1)
2962 (match-end 1))))
2963 ;; 'rectify-numbering' if resituating (where several topics may
2964 ;; be resituating) or yanking a topic into a topic slot (bol):
2965 (rectify-numbering (or resituate
2966 (and (bolp) (looking-at outline-regexp)))))
2967 (if resituate
2968 ; The yanked stuff is a topic:
2969 (let* ((prefix-len (- (match-end 1) subj-beg))
2970 (subj-depth (outline-recent-depth))
2971 (prefix-bullet (outline-recent-bullet))
2972 (adjust-to-depth
2973 ;; Nil if adjustment unnecessary, otherwise depth to which
2974 ;; adjustment should be made:
2975 (save-excursion
2976 (and (goto-char subj-end)
2977 (eolp)
2978 (goto-char subj-beg)
2979 (and (looking-at outline-regexp)
2980 (progn
2981 (beginning-of-line)
2982 (not (= (point) subj-beg)))
2983 (looking-at outline-regexp)
2984 (outline-prefix-data (match-beginning 0)
2985 (match-end 0)))
2986 (outline-recent-depth))))
2987 done
2988 (more t))
2989 (setq rectify-numbering outline-numbered-bullet)
2990 (if adjust-to-depth
2991 ; Do the adjustment:
2992 (progn
2993 (message "... yanking") (sit-for 0)
2994 (save-restriction
2995 (narrow-to-region subj-beg subj-end)
2996 ; Trim off excessive blank
2997 ; line at end, if any:
2998 (goto-char (point-max))
2999 (if (looking-at "^$")
3000 (outline-unprotected (delete-char -1)))
3001 ; Work backwards, with each
3002 ; shallowest level,
3003 ; successively excluding the
3004 ; last processed topic from
3005 ; the narrow region:
3006 (while more
3007 (outline-back-to-current-heading)
3008 ; go as high as we can in each bunch:
3009 (while (outline-ascend-to-depth (1- (outline-depth))))
3010 (save-excursion
3011 (outline-rebullet-topic-grunt (- adjust-to-depth
3012 subj-depth))
3013 (outline-depth))
3014 (if (setq more (not (bobp)))
3015 (progn (widen)
3016 (forward-char -1)
3017 (narrow-to-region subj-beg (point))))))
3018 (message "")
3019 ;; Preserve new bullet if it's a distinctive one, otherwise
3020 ;; use old one:
3021 (if (string-match (regexp-quote prefix-bullet)
3022 outline-distinctive-bullets-string)
3023 ; Delete from bullet of old to
3024 ; before bullet of new:
3025 (progn
3026 (beginning-of-line)
3027 (delete-region (point) subj-beg)
3028 (set-marker (mark-marker) subj-end)
3029 (goto-char subj-beg)
3030 (outline-end-of-prefix))
3031 ; Delete base subj prefix,
3032 ; leaving old one:
3033 (delete-region (point) (+ (point)
3034 prefix-len
3035 (- adjust-to-depth subj-depth)))
3036 ; and delete residual subj
3037 ; prefix digits and space:
3038 (while (looking-at "[0-9]") (delete-char 1))
3039 (if (looking-at " ") (delete-char 1))))
3040 (exchange-point-and-mark))))
3041 (if rectify-numbering
3042 (progn
3043 (save-excursion
3044 ; Give some preliminary feedback:
3045 (message "... reconciling numbers") (sit-for 0)
3046 ; ... and renumber, in case necessary:
3047 (goto-char subj-beg)
3048 (if (outline-goto-prefix)
3049 (outline-rebullet-heading nil ;;; solicit
3050 (outline-depth) ;;; depth
3051 nil ;;; number-control
3052 nil ;;; index
3054 (message ""))))
3055 (if (not resituate)
3056 (exchange-point-and-mark))))
3057 ;;;_ > outline-yank (&optional arg)
3058 (defun outline-yank (&optional arg)
3059 "Outline-mode yank, with depth and numbering adjustment of yanked topics.
3061 Non-topic yanks work no differently than normal yanks.
3063 If a topic is being yanked into a bare topic prefix, the depth of the
3064 yanked topic is adjusted to the depth of the topic prefix.
3066 1 we're yanking in an outline-mode buffer
3067 2 the stuff being yanked starts with a valid outline header prefix, and
3068 3 it is being yanked at the end of a line which consists of only a valid
3069 topic prefix.
3071 If these conditions hold then the depth of the yanked topics are all
3072 adjusted the amount it takes to make the first one at the depth of the
3073 header into which it's being yanked.
3075 The point is left in front of yanked, adjusted topics, rather than
3076 at the end (and vice-versa with the mark). Non-adjusted yanks,
3077 however, (ones that don't qualify for adjustment) are handled
3078 exactly like normal yanks.
3080 Numbering of yanked topics, and the successive siblings at the depth
3081 into which they're being yanked, is adjusted.
3083 Outline-yank-pop works with outline-yank just like normal yank-pop
3084 works with normal yank in non-outline buffers."
3086 (interactive "*P")
3087 (setq this-command 'yank)
3088 (yank arg)
3089 (if (outline-mode-p)
3090 (outline-yank-processing)))
3091 ;;;_ > outline-yank-pop (&optional arg)
3092 (defun outline-yank-pop (&optional arg)
3093 "Yank-pop like outline-yank when popping to bare outline prefixes.
3095 Adapts level of popped topics to level of fresh prefix.
3097 Note - prefix changes to distinctive bullets will stick, if followed
3098 by pops to non-distinctive yanks. Bug..."
3100 (interactive "*p")
3101 (setq this-command 'yank)
3102 (yank-pop arg)
3103 (if (outline-mode-p)
3104 (outline-yank-processing)))
3106 ;;;_ - Specialty bullet functions
3107 ;;;_ : File Cross references
3108 ;;;_ > outline-resolve-xref ()
3109 (defun outline-resolve-xref ()
3110 "Pop to file associated with current heading, if it has an xref bullet.
3112 \(Works according to setting of `outline-file-xref-bullet')."
3113 (interactive)
3114 (if (not outline-file-xref-bullet)
3115 (error
3116 "outline cross references disabled - no 'outline-file-xref-bullet'")
3117 (if (not (string= (outline-current-bullet) outline-file-xref-bullet))
3118 (error "current heading lacks cross-reference bullet '%s'"
3119 outline-file-xref-bullet)
3120 (let (file-name)
3121 (save-excursion
3122 (let* ((text-start outline-recent-prefix-end)
3123 (heading-end (progn (outline-pre-next-preface)
3124 (point))))
3125 (goto-char text-start)
3126 (setq file-name
3127 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t)
3128 (buffer-substring (match-beginning 1) (match-end 1))))))
3129 (setq file-name
3130 (if (not (= (aref file-name 0) ?:))
3131 (expand-file-name file-name)
3132 ; A registry-files ref, strip the ':'
3133 ; and try to follow it:
3134 (let ((reg-ref (reference-registered-file
3135 (substring file-name 1) nil t)))
3136 (if reg-ref (car (cdr reg-ref))))))
3137 (if (or (file-exists-p file-name)
3138 (if (file-writable-p file-name)
3139 (y-or-n-p (format "%s not there, create one? "
3140 file-name))
3141 (error "%s not found and can't be created" file-name)))
3142 (condition-case failure
3143 (find-file-other-window file-name)
3144 (error failure))
3145 (error "%s not found" file-name))
3151 ;;;_ #6 Exposure Control and Processing
3153 ;;;_ - Fundamental
3154 ;;;_ > outline-flag-region (from to flag)
3155 (defmacro outline-flag-region (from to flag)
3156 "Hide or show lines from FROM to TO, via emacs selective-display FLAG char.
3157 Ie, text following flag C-m \(carriage-return) is hidden until the
3158 next C-j (newline) char.
3160 Returns the endpoint of the region."
3161 (` (let ((buffer-read-only nil)
3162 (outline-override-protect t))
3163 (subst-char-in-region (, from) (, to)
3164 (if (= (, flag) ?\n) ?\r ?\n)
3165 (, flag) t))))
3166 ;;;_ > outline-flag-current-subtree (flag)
3167 (defun outline-flag-current-subtree (flag)
3168 "Hide or show subtree of currently-visible topic.
3170 See `outline-flag-region' for more details."
3172 (save-excursion
3173 (outline-back-to-current-heading)
3174 (outline-flag-region (point)
3175 (progn (outline-end-of-current-subtree) (1- (point)))
3176 flag)))
3178 ;;;_ - Mapping and processing of topics
3179 ;;;_ " See also chart functions, in navigation
3180 ;;;_ > outline-listify-exposed (&optional start end)
3181 (defun outline-listify-exposed (&optional start end)
3183 "Produce a list representing exposed topics in current region.
3185 This list can then be used by 'outline-process-exposed' to manipulate
3186 the subject region.
3188 List is composed of elements that may themselves be lists representing
3189 exposed components in subtopic.
3191 Each component list contains:
3192 - a number representing the depth of the topic,
3193 - a string representing the header-prefix (ref. 'outline-header-prefix'),
3194 - a string representing the bullet character,
3195 - and a series of strings, each containing one line of the exposed
3196 portion of the topic entry."
3198 (interactive "r")
3199 (save-excursion
3200 (let* (strings pad result depth bullet beg next done) ; State vars.
3201 (goto-char start)
3202 (beginning-of-line)
3203 (if (not (outline-goto-prefix)) ; Get initial position within a topic:
3204 (outline-next-visible-heading 1))
3205 (while (and (not done)
3206 (not (eobp)) ; Loop until we've covered the region.
3207 (not (> (point) end)))
3208 (setq depth (outline-recent-depth) ; Current topics' depth,
3209 bullet (outline-recent-bullet) ; ... bullet,
3210 beg (progn (outline-end-of-prefix t) (point))) ; and beginning.
3211 (setq done ; The boundary for the current topic:
3212 (not (outline-next-visible-heading 1)))
3213 (beginning-of-line)
3214 (setq next (point))
3215 (goto-char beg)
3216 (setq strings nil)
3217 (while (> next (point)) ; Get all the exposed text in
3218 (setq strings
3219 (cons (buffer-substring
3221 ;To hidden text or end of line:
3222 (progn
3223 (search-forward "\r"
3224 (save-excursion (end-of-line)
3225 (point))
3227 (if (= (preceding-char) ?\r)
3228 (1- (point))
3229 (point))))
3230 strings))
3231 (if (< (point) next) ; Resume from after hid text, if any.
3232 (forward-line 1))
3233 (setq beg (point)))
3234 ;; Accumulate list for this topic:
3235 (setq result
3236 (cons (append (list depth
3237 outline-header-prefix
3238 bullet)
3239 (nreverse strings))
3240 result)))
3241 ;; Put the list with first at front, to last at back:
3242 (nreverse result))))
3243 ;;;_ > outline-process-exposed (arg &optional tobuf)
3244 (defun outline-process-exposed (&optional func from to frombuf tobuf)
3245 "Map function on exposed parts of current topic; results to another buffer.
3247 Apply FUNCTION \(default 'outline-insert-listified) to exposed
3248 portions FROM position TO position \(default region, or the entire
3249 buffer if no region active) in buffer FROMBUF \(default current
3250 buffer) to buffer TOBUF \(default is buffer named like frombuf but
3251 with \"*\" prepended and \" exposed*\" appended).
3253 The function must as its arguments the elements of the list
3254 representations of topic entries produced by outline-listify-exposed."
3256 ; Resolve arguments,
3257 ; defaulting if necessary:
3258 (if (not func) (setq func 'outline-insert-listified))
3259 (if (not (and from to))
3260 (if mark-active
3261 (setq from (region-beginning) to (region-end))
3262 (setq from (point-min) to (point-max))))
3263 (if frombuf
3264 (if (not (bufferp frombuf))
3265 ;; Specified but not a buffer - get it:
3266 (let ((got (get-buffer frombuf)))
3267 (if (not got)
3268 (error "outline-process-exposed: source buffer %s not found."
3269 frombuf)
3270 (setq frombuf got))))
3271 ;; not specified - default it:
3272 (setq frombuf (current-buffer)))
3273 (if tobuf
3274 (if (not (bufferp tobuf))
3275 (setq tobuf (get-buffer-create tobuf)))
3276 ;; not specified - default it:
3277 (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
3279 (let* ((listified (progn (set-buffer frombuf)
3280 (outline-listify-exposed from to)))
3281 (prefix outline-header-prefix) ; ... as set in frombuf.
3282 curr)
3283 (set-buffer tobuf)
3284 (while listified
3285 (setq curr (car listified))
3286 (setq listified (cdr listified))
3287 (apply func (list (car curr) ; depth
3288 (car (cdr curr)) ; header-prefix
3289 (car (cdr (cdr curr))) ; bullet
3290 (cdr (cdr (cdr curr)))))) ; list of text lines
3291 (pop-to-buffer tobuf)))
3293 ;;;_ - Topic-specific
3294 ;;;_ > outline-show-entry ()
3295 ; outline-show-entry basically for isearch dynamic exposure, as is...
3296 (defun outline-show-entry ()
3297 "Like `outline-show-current-entry', reveals entries nested in hidden topics.
3299 This is a way to give restricted peek at a concealed locality without the
3300 expense of exposing its context, but can leave the outline with aberrant
3301 exposure. outline-hide-current-entry-completely or outline-show-offshoot
3302 should be used after the peek to rectify the exposure."
3304 (interactive)
3305 (save-excursion
3306 (outline-goto-prefix)
3307 (outline-flag-region (if (bobp) (point) (1- (point)))
3308 (or (outline-pre-next-preface) (point))
3309 ?\n)))
3310 ;;;_ > outline-show-children (&optional level strict)
3311 (defun outline-show-children (&optional level strict)
3313 "If point is visible, show all direct subheadings of this heading.
3315 Otherwise, do outline-show-to-offshoot, and then show subheadings.
3317 Optional LEVEL specifies how many levels below the current level
3318 should be shown, or all levels if t. Default is 1.
3320 Optional STRICT means don't resort to -show-to-offshoot, no matter
3321 what. This is basically so -show-to-offshoot, which is called by
3322 this function, can employ the pure offspring-revealing capabilities of
3325 Returns point at end of subtree that was opened, if any. (May get a
3326 point of non-opened subtree?)"
3328 (interactive "p")
3329 (let (max-pos)
3330 (if (and (not strict)
3331 (outline-hidden-p))
3333 (progn (outline-show-to-offshoot) ; Point's concealed, open to
3334 ; expose it.
3335 ;; Then recurse, but with "strict" set so we don't
3336 ;; infinite regress:
3337 (setq max-pos (outline-show-children level t)))
3339 (save-excursion
3340 (save-restriction
3341 (let* ((start-pt (point))
3342 (chart (outline-chart-subtree (or level 1)))
3343 (to-reveal (outline-chart-to-reveal chart (or level 1))))
3344 (goto-char start-pt)
3345 (if (and strict (= (preceding-char) ?\r))
3346 ;; Concealed root would already have been taken care of,
3347 ;; unless strict was set.
3348 (outline-flag-region (point) (outline-snug-back) ?\n))
3349 (while to-reveal
3350 (goto-char (car to-reveal))
3351 (outline-flag-region (point) (outline-snug-back) ?\n)
3352 (setq to-reveal (cdr to-reveal)))))))))
3353 ;;;_ x outline-show-current-children (&optional level strict)
3354 (defun outline-show-current-children (&optional level strict)
3355 "This command was misnamed, use `outline-show-children' instead.
3357 \(The \"current\" in the name is supposed to imply that it works on
3358 the visible topic containing point, while it really works with respect
3359 to the most immediate topic, concealed or not. I'll leave this old
3360 name around for a bit, but i'll soon activate an annoying message to
3361 warn people about the change, and then deprecate this alias."
3363 (interactive "p")
3364 ;;(beep)
3365 ;;(message (format "Use '%s' instead of '%s' (%s)."
3366 ;; "outline-show-children"
3367 ;; "outline-show-current-children"
3368 ;; (buffer-name (current-buffer))))
3369 (outline-show-children level strict))
3370 ;;;_ > outline-hide-point-reconcile ()
3371 (defun outline-hide-reconcile ()
3372 "Like `outline-hide-current-entry'; hides completely if within hidden region.
3374 Specifically intended for aberrant exposure states, like entries that were
3375 exposed by outline-show-entry but are within otherwise concealed regions."
3376 (interactive)
3377 (save-excursion
3378 (outline-goto-prefix)
3379 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3380 (progn (outline-pre-next-preface)
3381 (if (= ?\r (following-char))
3382 (point)
3383 (1- (point))))
3384 ?\r)))
3385 ;;;_ > outline-show-to-offshoot ()
3386 (defun outline-show-to-offshoot ()
3387 "Like outline-show-entry, but reveals opens all concealed ancestors, as well.
3389 As with outline-hide-current-entry-completely, useful for rectifying
3390 aberrant exposure states produced by outline-show-entry."
3392 (interactive)
3393 (save-excursion
3394 (let ((orig-pt (point))
3395 (orig-pref (outline-goto-prefix))
3396 (last-at (point))
3397 bag-it)
3398 (while (or bag-it (= (preceding-char) ?\r))
3399 (beginning-of-line)
3400 (if (= last-at (setq last-at (point)))
3401 ;; Oops, we're not making any progress! Show the current
3402 ;; topic completely, and bag this try.
3403 (progn (beginning-of-line)
3404 (outline-show-current-subtree)
3405 (goto-char orig-pt)
3406 (setq bag-it t)
3407 (beep)
3408 (message "%s: %s"
3409 "outline-show-to-offshoot: "
3410 "Aberrant nesting encountered.")))
3411 (outline-show-children)
3412 (goto-char orig-pref))
3413 (goto-char orig-pt)))
3414 (if (outline-hidden-p)
3415 (outline-show-entry)))
3416 ;;;_ > outline-hide-current-entry ()
3417 (defun outline-hide-current-entry ()
3418 "Hide the body directly following this heading."
3419 (interactive)
3420 (outline-back-to-current-heading)
3421 (save-excursion
3422 (outline-flag-region (point)
3423 (progn (outline-end-of-current-entry) (point))
3424 ?\^M)))
3425 ;;;_ > outline-show-current-entry (&optional arg)
3426 (defun outline-show-current-entry (&optional arg)
3428 "Show body following current heading, or hide the entry if repeat count."
3430 (interactive "P")
3431 (if arg
3432 (outline-hide-current-entry)
3433 (save-excursion
3434 (outline-flag-region (point)
3435 (progn (outline-end-of-current-entry) (point))
3436 ?\n))))
3437 ;;;_ > outline-hide-current-entry-completely ()
3438 ; ... outline-hide-current-entry-completely also for isearch dynamic exposure:
3439 (defun outline-hide-current-entry-completely ()
3440 "Like outline-hide-current-entry, but conceal topic completely.
3442 Specifically intended for aberrant exposure states, like entries that were
3443 exposed by outline-show-entry but are within otherwise concealed regions."
3444 (interactive)
3445 (save-excursion
3446 (outline-goto-prefix)
3447 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3448 (progn (outline-pre-next-preface)
3449 (if (= ?\r (following-char))
3450 (point)
3451 (1- (point))))
3452 ?\r)))
3453 ;;;_ > outline-show-current-subtree (&optional arg)
3454 (defun outline-show-current-subtree (&optional arg)
3455 "Show everything within the current topic. With a repeat-count,
3456 expose this topic and its' siblings."
3457 (interactive "P")
3458 (save-excursion
3459 (if (<= (outline-current-depth) 0)
3460 ;; Outside any topics - try to get to the first:
3461 (if (not (outline-next-heading))
3462 (error "No topics.")
3463 ;; got to first, outermost topic - set to expose it and siblings:
3464 (message "Above outermost topic - exposing all.")
3465 (outline-flag-region (point-min)(point-max) ?\n))
3466 (if (not arg)
3467 (outline-flag-current-subtree ?\n)
3468 (outline-beginning-of-level)
3469 (outline-expose-topic '(* :))))))
3470 ;;;_ > outline-hide-current-subtree (&optional just-close)
3471 (defun outline-hide-current-subtree (&optional just-close)
3472 "Close the current topic, or containing topic if this one is already closed.
3474 If this topic is closed and it's a top level topic, close this topic
3475 and its' siblings.
3477 If optional arg JUST-CLOSE is non-nil, do not treat the parent or
3478 siblings, even if the target topic is already closed."
3480 (interactive)
3481 (let ((from (point))
3482 (orig-eol (progn (end-of-line)
3483 (if (not (outline-goto-prefix))
3484 (error "No topics found.")
3485 (end-of-line)(point)))))
3486 (outline-flag-current-subtree ?\^M)
3487 (goto-char from)
3488 (if (and (= orig-eol (progn (goto-char orig-eol)
3489 (end-of-line)
3490 (point)))
3491 (not just-close)
3492 ;; Structure didn't change - try hiding current level:
3493 (goto-char from)
3494 (if (outline-up-current-level 1 t)
3496 (goto-char 0)
3497 (let ((msg
3498 "Top-level topic already closed - closing siblings..."))
3499 (message msg)
3500 (outline-expose-topic '(0 :))
3501 (message (concat msg " Done.")))
3502 nil)
3503 (/= (outline-recent-depth) 0))
3504 (outline-hide-current-subtree))
3505 (goto-char from)))
3506 ;;;_ > outline-show-current-branches ()
3507 (defun outline-show-current-branches ()
3508 "Show all subheadings of this heading, but not their bodies."
3509 (interactive)
3510 (beginning-of-line)
3511 (outline-show-children t))
3512 ;;;_ > outline-hide-current-leaves ()
3513 (defun outline-hide-current-leaves ()
3514 "Hide the bodies of the current topic and all its' offspring."
3515 (interactive)
3516 (outline-back-to-current-heading)
3517 (outline-hide-region-body (point) (progn (outline-end-of-current-subtree)
3518 (point))))
3520 ;;;_ - Region and beyond
3521 ;;;_ > outline-show-all ()
3522 (defun outline-show-all ()
3523 "Show all of the text in the buffer."
3524 (interactive)
3525 (message "Exposing entire buffer...")
3526 (outline-flag-region (point-min) (point-max) ?\n)
3527 (message "Exposing entire buffer... Done."))
3528 ;;;_ > outline-hide-bodies ()
3529 (defun outline-hide-bodies ()
3530 "Hide all of buffer except headings."
3531 (interactive)
3532 (outline-hide-region-body (point-min) (point-max)))
3533 ;;;_ > outline-hide-region-body (start end)
3534 (defun outline-hide-region-body (start end)
3535 "Hide all body lines in the region, but not headings."
3536 (save-excursion
3537 (save-restriction
3538 (narrow-to-region start end)
3539 (goto-char (point-min))
3540 (while (not (eobp))
3541 (outline-flag-region (point)
3542 (progn (outline-pre-next-preface) (point)) ?\^M)
3543 (if (not (eobp))
3544 (forward-char
3545 (if (looking-at "[\n\r][\n\r]")
3546 2 1)))))))
3548 ;;;_ > outline-expose-topic (spec)
3549 (defun outline-expose-topic (spec)
3550 "Apply exposure specs to successive outline topic items.
3552 Use the more convenient frontend, `outline-new-exposure', if you don't
3553 need evaluation of the arguments, or even better, the `outline-layout'
3554 variable-keyed mode-activation/auto-exposure feature of allout outline
3555 mode. See the respective documentation strings for more details.
3557 Cursor is left at start position.
3559 SPEC is either a number or a list.
3561 Successive specs on a list are applied to successive sibling topics.
3563 A simple spec \(either a number, one of a few symbols, or the null
3564 list) dictates the exposure for the corresponding topic.
3566 Non-null lists recursively designate exposure specs for respective
3567 subtopics of the current topic.
3569 The ':' repeat spec is used to specify exposure for any number of
3570 successive siblings, up to the trailing ones for which there are
3571 explicit specs following the ':'.
3573 Simple (numeric and null-list) specs are interpreted as follows:
3575 Numbers indicate the relative depth to open the corresponding topic.
3576 - negative numbers force the topic to be closed before opening to the
3577 absolute value of the number, so all siblings are open only to
3578 that level.
3579 - positive numbers open to the relative depth indicated by the
3580 number, but do not force already opened subtopics to be closed.
3581 - 0 means to close topic - hide all offspring.
3582 : - 'repeat'
3583 apply prior element to all siblings at current level, *up to*
3584 those siblings that would be covered by specs following the ':'
3585 on the list. Ie, apply to all topics at level but the last
3586 ones. \(Only first of multiple colons at same level is
3587 respected - subsequent ones are discarded.)
3588 * - completely opens the topic, including bodies.
3589 + - shows all the sub headers, but not the bodies
3590 - - exposes the body of the corresponding topic.
3592 Examples:
3593 \(outline-expose-topic '(-1 : 0))
3594 Close this and all following topics at current level, exposing
3595 only their immediate children, but close down the last topic
3596 at this current level completely.
3597 \(outline-expose-topic '(-1 () : 1 0))
3598 Close current topic so only the immediate subtopics are shown;
3599 show the children in the second to last topic, and completely
3600 close the last one.
3601 \(outline-expose-topic '(-2 : -1 *))
3602 Expose children and grandchildren of all topics at current
3603 level except the last two; expose children of the second to
3604 last and completely open the last one."
3606 (interactive "xExposure spec: ")
3607 (if (not (listp spec))
3609 (let ((depth (outline-depth))
3610 (max-pos 0)
3611 prev-elem curr-elem
3612 stay done
3613 snug-back
3615 (while spec
3616 (setq prev-elem curr-elem
3617 curr-elem (car spec)
3618 spec (cdr spec))
3619 (cond ; Do current element:
3620 ((null curr-elem) nil)
3621 ((symbolp curr-elem)
3622 (cond ((eq curr-elem '*) (outline-show-current-subtree)
3623 (if (> outline-recent-end-of-subtree max-pos)
3624 (setq max-pos outline-recent-end-of-subtree)))
3625 ((eq curr-elem '+) (outline-show-current-branches)
3626 (if (> outline-recent-end-of-subtree max-pos)
3627 (setq max-pos outline-recent-end-of-subtree)))
3628 ((eq curr-elem '-) (outline-show-current-entry))
3629 ((eq curr-elem ':)
3630 (setq stay t)
3631 ;; Expand the 'repeat' spec to an explicit version,
3632 ;; w.r.t. remaining siblings:
3633 (let ((residue ; = # of sibs not covered by remaining spec
3634 ;; Dang - could be nice to make use of the chart, sigh:
3635 (- (length (outline-chart-siblings))
3636 (length spec))))
3637 (if (< 0 residue)
3638 ;; Some residue - cover it with prev-elem:
3639 (setq spec (append (make-list residue prev-elem)
3640 spec)))))))
3641 ((numberp curr-elem)
3642 (if (and (>= 0 curr-elem) (outline-visible-p))
3643 (save-excursion (outline-hide-current-subtree t)
3644 (if (> 0 curr-elem)
3646 (if (> outline-recent-end-of-subtree max-pos)
3647 (setq max-pos
3648 outline-recent-end-of-subtree)))))
3649 (if (> (abs curr-elem) 0)
3650 (progn (outline-show-children (abs curr-elem))
3651 (if (> outline-recent-end-of-subtree max-pos)
3652 (setq max-pos outline-recent-end-of-subtree)))))
3653 ((listp curr-elem)
3654 (if (outline-descend-to-depth (1+ depth))
3655 (let ((got (outline-expose-topic curr-elem)))
3656 (if (and got (> got max-pos)) (setq max-pos got))))))
3657 (cond (stay (setq stay nil))
3658 ((listp (car spec)) nil)
3659 ((> max-pos (point))
3660 ;; Capitalize on max-pos state to get us nearer next sibling:
3661 (progn (goto-char (min (point-max) max-pos))
3662 (outline-next-heading)))
3663 ((outline-next-sibling depth))))
3664 max-pos)))
3665 ;;;_ > outline-old-expose-topic (spec &rest followers)
3666 (defun outline-old-expose-topic (spec &rest followers)
3668 "Deprecated. Use outline-expose-topic \(with different schema
3669 format\) instead.
3671 Dictate wholesale exposure scheme for current topic, according to SPEC.
3673 SPEC is either a number or a list. Optional successive args
3674 dictate exposure for subsequent siblings of current topic.
3676 A simple spec (either a number, a special symbol, or the null list)
3677 dictates the overall exposure for a topic. Non null lists are
3678 composite specs whose first element dictates the overall exposure for
3679 a topic, with the subsequent elements in the list interpreted as specs
3680 that dictate the exposure for the successive offspring of the topic.
3682 Simple (numeric and null-list) specs are interpreted as follows:
3684 - Numbers indicate the relative depth to open the corresponding topic:
3685 - negative numbers force the topic to be close before opening to the
3686 absolute value of the number.
3687 - positive numbers just open to the relative depth indicated by the number.
3688 - 0 just closes
3689 - '*' completely opens the topic, including bodies.
3690 - '+' shows all the sub headers, but not the bodies
3691 - '-' exposes the body and immediate offspring of the corresponding topic.
3693 If the spec is a list, the first element must be a number, which
3694 dictates the exposure depth of the topic as a whole. Subsequent
3695 elements of the list are nested SPECs, dictating the specific exposure
3696 for the corresponding offspring of the topic.
3698 Optional FOLLOWER arguments dictate exposure for succeeding siblings."
3700 (interactive "xExposure spec: ")
3701 (let ((depth (outline-current-depth))
3702 done
3703 max-pos)
3704 (cond ((null spec) nil)
3705 ((symbolp spec)
3706 (if (eq spec '*) (outline-show-current-subtree))
3707 (if (eq spec '+) (outline-show-current-branches))
3708 (if (eq spec '-) (outline-show-current-entry)))
3709 ((numberp spec)
3710 (if (>= 0 spec)
3711 (save-excursion (outline-hide-current-subtree t)
3712 (end-of-line)
3713 (if (or (not max-pos)
3714 (> (point) max-pos))
3715 (setq max-pos (point)))
3716 (if (> 0 spec)
3717 (setq spec (* -1 spec)))))
3718 (if (> spec 0)
3719 (outline-show-children spec)))
3720 ((listp spec)
3721 ;(let ((got (outline-old-expose-topic (car spec))))
3722 ; (if (and got (or (not max-pos) (> got max-pos)))
3723 ; (setq max-pos got)))
3724 (let ((new-depth (+ (outline-current-depth) 1))
3725 got)
3726 (setq max-pos (outline-old-expose-topic (car spec)))
3727 (setq spec (cdr spec))
3728 (if (and spec
3729 (outline-descend-to-depth new-depth)
3730 (not (outline-hidden-p)))
3731 (progn (setq got (apply 'outline-old-expose-topic spec))
3732 (if (and got (or (not max-pos) (> got max-pos)))
3733 (setq max-pos got)))))))
3734 (while (and followers
3735 (progn (if (and max-pos (< (point) max-pos))
3736 (progn (goto-char max-pos)
3737 (setq max-pos nil)))
3738 (end-of-line)
3739 (outline-next-sibling depth)))
3740 (outline-old-expose-topic (car followers))
3741 (setq followers (cdr followers)))
3742 max-pos))
3743 ;;;_ > outline-new-exposure '()
3744 (defmacro outline-new-exposure (&rest spec)
3745 "Literal frontend for `outline-expose-topic', doesn't evaluate arguments.
3746 Some arguments that would need to be quoted in outline-expose-topic
3747 need not be quoted in outline-new-exposure.
3749 Cursor is left at start position.
3751 Use this instead of obsolete 'outline-exposure'.
3753 Examples:
3754 \(outline-exposure (-1 () () () 1) 0)
3755 Close current topic at current level so only the immediate
3756 subtopics are shown, except also show the children of the
3757 third subtopic; and close the next topic at the current level.
3758 \(outline-exposure : -1 0)
3759 Close all topics at current level to expose only their
3760 immediate children, except for the last topic at the current
3761 level, in which even its' immediate children are hidden.
3762 \(outline-exposure -2 : -1 *)
3763 Expose children and grandchildren of first topic at current
3764 level, and expose children of subsequent topics at current
3765 level *except* for the last, which should be opened completely."
3766 (list 'save-excursion
3767 '(if (not (or (outline-goto-prefix)
3768 (outline-next-heading)))
3769 (error "outline-new-exposure: Can't find any outline topics."))
3770 (list 'outline-expose-topic (list 'quote spec))))
3771 ;;;_ > outline-exposure '()
3772 (defmacro outline-exposure (&rest spec)
3773 "Being deprecated - use more recent 'outline-new-exposure' instead.
3775 Literal frontend for `outline-old-expose-topic', doesn't evaluate arguments
3776 and retains start position."
3777 (list 'save-excursion
3778 '(if (not (or (outline-goto-prefix)
3779 (outline-next-heading)))
3780 (error "Can't find any outline topics."))
3781 (cons 'outline-old-expose-topic
3782 (mapcar '(lambda (x) (list 'quote x)) spec))))
3784 ;;;_ #7 ISearch with Dynamic Exposure
3785 ;;;_ = outline-search-reconceal
3786 (defvar outline-search-reconceal nil
3787 "Track whether current search match was concealed outside of search.
3789 The value is the location of the match, if it was concealed, regular
3790 if the entire topic was concealed, in a list if the entry was concealed.")
3791 ;;;_ = outline-search-quitting
3792 (defconst outline-search-quitting nil
3793 "Distinguishes isearch conclusion and cancellation.
3795 Used by isearch-terminate/outline-provisions and
3796 isearch-done/outline-provisions")
3799 ;;;_ > outline-enwrap-isearch ()
3800 (defun outline-enwrap-isearch ()
3801 "Impose outline-mode isearch-mode wrappers for dynamic exposure in isearch.
3803 Isearch progressively exposes and reconceals hidden topics when
3804 working in outline mode, but works normally elsewhere.
3806 The function checks to ensure that the rebindings are done only once."
3808 ; Should isearch-mode be employed,
3809 (if (or (not outline-enwrap-isearch-mode)
3810 ; or are preparations already done?
3811 (fboundp 'real-isearch-terminate))
3813 ;; ... no - skip this all:
3816 ;; ... yes:
3818 ; Ensure load of isearch-mode:
3819 (if (or (and (fboundp 'isearch-mode)
3820 (fboundp 'isearch-quote-char))
3821 (condition-case error
3822 (load-library outline-enwrap-isearch-mode)
3823 (file-error (message "Skipping isearch-mode provisions - %s '%s'"
3824 (car (cdr error))
3825 (car (cdr (cdr error))))
3826 (sit-for 1)
3827 ;; Inhibit subsequent tries and return nil:
3828 (setq outline-enwrap-isearch-mode nil))))
3829 ;; Isearch-mode loaded, encapsulate specific entry points for
3830 ;; outline dynamic-exposure business:
3831 (progn
3833 ;; stash crucial isearch-mode funcs under known, private
3834 ;; names, then register wrapper functions under the old
3835 ;; names, in their stead: 'isearch-quit' is pre isearch v 1.2.
3836 (fset 'real-isearch-terminate
3837 ; 'isearch-quit is pre v 1.2:
3838 (or (if (fboundp 'isearch-quit)
3839 (symbol-function 'isearch-quit))
3840 (if (fboundp 'isearch-abort)
3841 ; 'isearch-abort' is v 1.2 and on:
3842 (symbol-function 'isearch-abort))))
3843 (fset 'isearch-quit 'isearch-terminate/outline-provisions)
3844 (fset 'isearch-abort 'isearch-terminate/outline-provisions)
3845 (fset 'real-isearch-done (symbol-function 'isearch-done))
3846 (fset 'isearch-done 'isearch-done/outline-provisions)
3847 (fset 'real-isearch-update (symbol-function 'isearch-update))
3848 (fset 'isearch-update 'isearch-update/outline-provisions)
3849 (make-variable-buffer-local 'outline-search-reconceal)))))
3850 ;;;_ > outline-isearch-arrival-business ()
3851 (defun outline-isearch-arrival-business ()
3852 "Do outline business like exposing current point, if necessary.
3854 Registers reconcealment requirements in outline-search-reconceal
3855 accordingly.
3857 Set outline-search-reconceal to nil if current point is not
3858 concealed, to value of point if entire topic is concealed, and a
3859 list containing point if only the topic body is concealed.
3861 This will be used to determine whether outline-hide-current-entry
3862 or outline-hide-current-entry-completely will be necessary to
3863 restore the prior concealment state."
3865 (if (outline-mode-p)
3866 (setq outline-search-reconceal
3867 (if (outline-hidden-p)
3868 (save-excursion
3869 (if (re-search-backward outline-line-boundary-regexp nil 1)
3870 ;; Nil value means we got to b-o-b - wouldn't need
3871 ;; to advance.
3872 (forward-char 1))
3873 ; We'll return point or list
3874 ; containing point, depending
3875 ; on concealment state of
3876 ; topic prefix.
3877 (prog1 (if (outline-hidden-p) (point) (list (point)))
3878 ; And reveal the current
3879 ; search target:
3880 (outline-show-entry)))))))
3881 ;;;_ > outline-isearch-advancing-business ()
3882 (defun outline-isearch-advancing-business ()
3883 "Do outline business like deexposing current point, if necessary.
3885 Works according to reconceal state registration."
3886 (if (and (outline-mode-p) outline-search-reconceal)
3887 (save-excursion
3888 (if (listp outline-search-reconceal)
3889 ;; Leave the topic visible:
3890 (progn (goto-char (car outline-search-reconceal))
3891 (outline-hide-current-entry))
3892 ;; Rehide the entire topic:
3893 (goto-char outline-search-reconceal)
3894 (outline-hide-current-entry-completely)))))
3895 ;;;_ > isearch-terminate/outline-provisions ()
3896 (defun isearch-terminate/outline-provisions ()
3897 (interactive)
3898 (if (and (outline-mode-p) outline-enwrap-isearch-mode)
3899 (outline-isearch-advancing-business))
3900 (let ((outline-search-quitting t)
3901 (outline-search-reconceal nil))
3902 (real-isearch-terminate)))
3903 ;;;_ > isearch-done/outline-provisions ()
3904 (defun isearch-done/outline-provisions (&optional nopush)
3905 (interactive)
3906 (if (and (outline-mode-p) outline-enwrap-isearch-mode)
3907 (progn (if (and outline-search-reconceal
3908 (not (listp outline-search-reconceal)))
3909 ;; The topic was concealed - reveal it, its siblings,
3910 ;; and any ancestors that are still concealed:
3911 (save-excursion
3912 (message "(exposing destination)")(sit-for 0)
3913 (outline-goto-prefix)
3914 ; There may be a closed blank
3915 ; line between prior and
3916 ; current topic that would be
3917 ; missed - provide for it:
3918 (if (not (bobp))
3919 (progn (forward-char -1) ; newline
3920 (if (eq ?\r (preceding-char))
3921 (outline-flag-region (1- (point))
3922 (point)
3923 ?\n))
3924 (forward-char 1)))
3925 ; Goto parent
3926 (outline-ascend-to-depth (1- (outline-recent-depth)))
3927 (outline-show-children)))
3928 (if (and (boundp 'outline-search-quitting)
3929 outline-search-quitting)
3931 ; We're concluding abort:
3932 (outline-isearch-arrival-business)
3933 (outline-show-children))))
3934 (if nopush
3935 ;; isearch-done in newer version of isearch mode takes arg:
3936 (real-isearch-done nopush)
3937 (real-isearch-done)))
3938 ;;;_ > isearch-update/outline-provisions ()
3939 (defun isearch-update/outline-provisions ()
3940 "Wrapper dynamically adjusts isearch target exposure.
3942 Appropriately exposes and reconceals hidden outline portions, as
3943 necessary, in the course of searching."
3944 (if (not (and (outline-mode-p) outline-enwrap-isearch-mode))
3945 ;; Just do the plain business:
3946 (real-isearch-update)
3948 ;; Ah - provide for outline conditions:
3949 (outline-isearch-advancing-business)
3950 (real-isearch-update)
3951 (cond (isearch-success (outline-isearch-arrival-business))
3952 ((not isearch-success) (outline-isearch-advancing-business)))))
3954 ;;;_ #8 Copying and printing
3956 ;;;_ - Copy exposed
3957 ;;;_ > outline-insert-listified (depth prefix bullet text)
3958 (defun outline-insert-listified (depth prefix bullet text)
3959 "Insert contents of listified outline portion in current buffer."
3960 (insert-string (concat (if (> depth 1) prefix "")
3961 (make-string (1- depth) ?\ )
3962 bullet))
3963 (while text
3964 (insert-string (car text))
3965 (if (setq text (cdr text))
3966 (insert-string "\n")))
3967 (insert-string "\n"))
3968 ;;;_ > outline-copy-exposed (arg &optional tobuf)
3969 (defun outline-copy-exposed (arg &optional tobuf)
3970 "Duplicate exposed portions of current topic to another buffer.
3972 Other buffer has current buffers' name with \" exposed\" appended to it.
3974 With repeat count, copy the exposed portions of entire buffer."
3976 (interactive "P")
3977 (if (not tobuf)
3978 (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*"))))
3979 (let* ((start-pt (point))
3980 (beg (if arg (point-min) (outline-back-to-current-heading)))
3981 (end (if arg (point-max) (outline-end-of-current-subtree)))
3982 (buf (current-buffer)))
3983 (save-excursion (set-buffer tobuf)(erase-buffer))
3984 (outline-process-exposed 'outline-insert-listified
3987 (current-buffer)
3988 tobuf)
3989 (goto-char (point-min))
3990 (pop-to-buffer buf)
3991 (goto-char start-pt)))
3993 ;;;_ - LaTeX formatting
3994 ;;;_ > outline-latex-verb-quote (str &optional flow)
3995 (defun outline-latex-verb-quote (str &optional flow)
3996 "Return copy of STRING for literal reproduction across latex processing.
3997 Expresses the original characters \(including carriage returns) of the
3998 string across latex processing."
3999 (mapconcat '(lambda (char)
4000 ;;;mess: (cond ((memq char '(?"" ?$ ?% ?# ?& ?- ?" ?` ?^ ?- ?*));;;"))))
4001 (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
4002 (concat "\\char" (number-to-string char) "{}"))
4003 ((= char ?\n) "\\\\")
4004 (t (char-to-string char))))
4006 ""))
4007 ;;;_ > outline-latex-verbatim-quote-curr-line ()
4008 (defun outline-latex-verbatim-quote-curr-line ()
4009 "Express line for exact \(literal\) representation across latex processing.
4011 Adjust line contents so it is unaltered \(from the original line)
4012 across latex processing, within the context of a 'verbatim'
4013 environment. Leaves point at the end of the line."
4014 (beginning-of-line)
4015 (let ((beg (point))
4016 (end (progn (end-of-line)(point))))
4017 (goto-char beg)
4018 (while (re-search-forward "\\\\"
4019 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
4020 end ; bounded by end-of-line
4021 1) ; no matches, move to end & return nil
4022 (goto-char (match-beginning 0))
4023 (insert-string "\\")
4024 (setq end (1+ end))
4025 (goto-char (1+ (match-end 0))))))
4026 ;;;_ > outline-insert-latex-header (buf)
4027 (defun outline-insert-latex-header (buf)
4028 "Insert initial latex commands at point in BUFFER."
4029 ;; Much of this is being derived from the stuff in appendix of E in
4030 ;; the TeXBook, pg 421.
4031 (set-buffer buf)
4032 (let ((doc-style (format "\n\\documentstyle{%s}\n"
4033 "report"))
4034 (page-numbering (if outline-number-pages
4035 "\\pagestyle{empty}\n"
4036 ""))
4037 (linesdef (concat "\\def\\beginlines{"
4038 "\\par\\begingroup\\nobreak\\medskip"
4039 "\\parindent=0pt\n"
4040 " \\kern1pt\\nobreak \\obeylines \\obeyspaces "
4041 "\\everypar{\\strut}}\n"
4042 "\\def\\endlines{"
4043 "\\kern1pt\\endgroup\\medbreak\\noindent}\n"))
4044 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
4045 outline-title-style))
4046 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
4047 outline-label-style))
4048 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
4049 outline-head-line-style))
4050 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
4051 outline-body-line-style))
4052 (setlength (format "%s%s%s%s"
4053 "\\newlength{\\stepsize}\n"
4054 "\\setlength{\\stepsize}{"
4055 outline-indent
4056 "}\n"))
4057 (oneheadline (format "%s%s%s%s%s%s%s"
4058 "\\newcommand{\\OneHeadLine}[3]{%\n"
4059 "\\noindent%\n"
4060 "\\hspace*{#2\\stepsize}%\n"
4061 "\\labelcmd{#1}\\hspace*{.2cm}"
4062 "\\headlinecmd{#3}\\\\["
4063 outline-line-skip
4064 "]\n}\n"))
4065 (onebodyline (format "%s%s%s%s%s%s"
4066 "\\newcommand{\\OneBodyLine}[2]{%\n"
4067 "\\noindent%\n"
4068 "\\hspace*{#1\\stepsize}%\n"
4069 "\\bodylinecmd{#2}\\\\["
4070 outline-line-skip
4071 "]\n}\n"))
4072 (begindoc "\\begin{document}\n\\begin{center}\n")
4073 (title (format "%s%s%s%s"
4074 "\\titlecmd{"
4075 (outline-latex-verb-quote (if outline-title
4076 (condition-case err
4077 (eval outline-title)
4078 (error "<unnamed buffer>"))
4079 "Unnamed Outline"))
4080 "}\n"
4081 "\\end{center}\n\n"))
4082 (hsize "\\hsize = 7.5 true in\n")
4083 (hoffset "\\hoffset = -1.5 true in\n")
4084 (vspace "\\vspace{.1cm}\n\n"))
4085 (insert (concat doc-style
4086 page-numbering
4087 titlecmd
4088 labelcmd
4089 headlinecmd
4090 bodylinecmd
4091 setlength
4092 oneheadline
4093 onebodyline
4094 begindoc
4095 title
4096 hsize
4097 hoffset
4098 vspace)
4100 ;;;_ > outline-insert-latex-trailer (buf)
4101 (defun outline-insert-latex-trailer (buf)
4102 "Insert concluding latex commands at point in BUFFER."
4103 (set-buffer buf)
4104 (insert "\n\\end{document}\n"))
4105 ;;;_ > outline-latexify-one-item (depth prefix bullet text)
4106 (defun outline-latexify-one-item (depth prefix bullet text)
4107 "Insert LaTeX commands for formatting one outline item.
4109 Args are the topics' numeric DEPTH, the header PREFIX lead string, the
4110 BULLET string, and a list of TEXT strings for the body."
4111 (let* ((head-line (if text (car text)))
4112 (body-lines (cdr text))
4113 (curr-line)
4114 body-content bop)
4115 ; Do the head line:
4116 (insert-string (concat "\\OneHeadLine{\\verb\1 "
4117 (outline-latex-verb-quote bullet)
4118 "\1}{"
4119 depth
4120 "}{\\verb\1 "
4121 (if head-line
4122 (outline-latex-verb-quote head-line)
4124 "\1}\n"))
4125 (if (not body-lines)
4127 ;;(insert-string "\\beginlines\n")
4128 (insert-string "\\begin{verbatim}\n")
4129 (while body-lines
4130 (setq curr-line (car body-lines))
4131 (if (and (not body-content)
4132 (not (string-match "^\\s-*$" curr-line)))
4133 (setq body-content t))
4134 ; Mangle any occurrences of
4135 ; "\end{verbatim}" in text,
4136 ; it's special:
4137 (if (and body-content
4138 (setq bop (string-match "\\end{verbatim}" curr-line)))
4139 (setq curr-line (concat (substring curr-line 0 bop)
4141 (substring curr-line bop))))
4142 ;;(insert-string "|" (car body-lines) "|")
4143 (insert-string curr-line)
4144 (outline-latex-verbatim-quote-curr-line)
4145 (insert-string "\n")
4146 (setq body-lines (cdr body-lines)))
4147 (if body-content
4148 (setq body-content nil)
4149 (forward-char -1)
4150 (insert-string "\\ ")
4151 (forward-char 1))
4152 ;;(insert-string "\\endlines\n")
4153 (insert-string "\\end{verbatim}\n")
4155 ;;;_ > outline-latexify-exposed (arg &optional tobuf)
4156 (defun outline-latexify-exposed (arg &optional tobuf)
4157 "Format current topic's exposed portions to TOBUF for latex processing.
4158 TOBUF defaults to a buffer named the same as the current buffer, but
4159 with \"*\" prepended and \" latex-formed*\" appended.
4161 With repeat count, copy the exposed portions of entire buffer."
4163 (interactive "P")
4164 (if (not tobuf)
4165 (setq tobuf
4166 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
4167 (let* ((start-pt (point))
4168 (beg (if arg (point-min) (outline-back-to-current-heading)))
4169 (end (if arg (point-max) (outline-end-of-current-subtree)))
4170 (buf (current-buffer)))
4171 (set-buffer tobuf)
4172 (erase-buffer)
4173 (outline-insert-latex-header tobuf)
4174 (goto-char (point-max))
4175 (outline-process-exposed 'outline-latexify-one-item
4179 tobuf)
4180 (goto-char (point-max))
4181 (outline-insert-latex-trailer tobuf)
4182 (goto-char (point-min))
4183 (pop-to-buffer buf)
4184 (goto-char start-pt)))
4186 ;;;_ #9 miscellaneous
4187 ;;;_ > outline-mark-topic ()
4188 (defun outline-mark-topic ()
4189 "Put the region around topic currently containing point."
4190 (interactive)
4191 (beginning-of-line)
4192 (outline-goto-prefix)
4193 (push-mark (point))
4194 (outline-end-of-current-subtree)
4195 (exchange-point-and-mark))
4196 ;;;_ > outlineify-sticky ()
4197 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
4198 (defalias 'outlinify-sticky 'outlineify-sticky)
4199 (defun outlineify-sticky (&optional arg)
4200 "Activate outline mode and establish file var so it is started subsequently.
4202 See doc-string for `outline-layout' and `outline-init' for details on
4203 setup for auto-startup."
4205 (interactive "P")
4207 (outline-mode t)
4209 (save-excursion
4210 (goto-char (point-min))
4211 (if (looking-at outline-regexp)
4213 (outline-open-topic 2)
4214 (insert-string (concat "Dummy outline topic header - see"
4215 "`outline-mode' docstring for info."))
4216 (next-line 1)
4217 (goto-char (point-max))
4218 (next-line 1)
4219 (outline-open-topic 0)
4220 (insert-string "Local emacs vars.\n")
4221 (outline-open-topic 1)
4222 (insert-string "(`outline-layout' is for allout.el outline-mode)\n")
4223 (outline-open-topic 0)
4224 (insert-string "Local variables:\n")
4225 (outline-open-topic 0)
4226 (insert-string (format "outline-layout: %s\n"
4227 (or outline-layout
4228 '(1 : 0))))
4229 (outline-open-topic 0)
4230 (insert-string "End:\n"))))
4231 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
4232 (defun solicit-char-in-string (prompt string &optional do-defaulting)
4233 "Solicit (with first arg PROMPT) choice of a character from string STRING.
4235 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
4237 (let ((new-prompt prompt)
4238 got)
4240 (while (not got)
4241 (message "%s" new-prompt)
4243 ;; We do our own reading here, so we can circumvent, eg, special
4244 ;; treatment for '?' character. (Might oughta change minibuffer
4245 ;; keymap instead, oh well.)
4246 (setq got
4247 (char-to-string (let ((cursor-in-echo-area nil)) (read-char))))
4249 (if (null (string-match (regexp-quote got) string))
4250 (if (and do-defaulting (string= got "\^M"))
4251 ;; We're defaulting, return null string to indicate that:
4252 (setq got "")
4253 ;; Failed match and not defaulting,
4254 ;; set the prompt to give feedback,
4255 (setq new-prompt (concat prompt
4257 " ...pick from: "
4258 string
4259 ""))
4260 ;; and set loop to try again:
4261 (setq got nil))
4262 ;; Got a match - give feedback:
4263 (message "")))
4264 ;; got something out of loop - return it:
4265 got)
4267 ;;;_ > regexp-sans-escapes (string)
4268 (defun regexp-sans-escapes (regexp &optional successive-backslashes)
4269 "Return a copy of REGEXP with all character escapes stripped out.
4271 Representations of actual backslashes - '\\\\\\\\' - are left as a
4272 single backslash.
4274 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
4276 (if (string= regexp "")
4278 ;; Set successive-backslashes to number if current char is
4279 ;; backslash, or else to nil:
4280 (setq successive-backslashes
4281 (if (= (aref regexp 0) ?\\)
4282 (if successive-backslashes (1+ successive-backslashes) 1)
4283 nil))
4284 (if (or (not successive-backslashes) (= 2 successive-backslashes))
4285 ;; Include first char:
4286 (concat (substring regexp 0 1)
4287 (regexp-sans-escapes (substring regexp 1)))
4288 ;; Exclude first char, but maintain count:
4289 (regexp-sans-escapes (substring regexp 1) successive-backslashes))))
4290 ;;;_ - add-hook definition for divergent emacsen
4291 ;;;_ > add-hook (hook function &optional append)
4292 (if (not (fboundp 'add-hook))
4293 (defun add-hook (hook function &optional append)
4294 "Add to the value of HOOK the function FUNCTION unless already present.
4295 \(It becomes the first hook on the list unless optional APPEND is non-nil, in
4296 which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
4297 any valid function. HOOK's value should be a list of functions, not a single
4298 function. If HOOK is void, it is first set to nil."
4299 (or (boundp hook) (set hook nil))
4300 (or (if (consp function)
4301 ;; Clever way to tell whether a given lambda-expression
4302 ;; is equal to anything in the hook.
4303 (let ((tail (assoc (cdr function) (symbol-value hook))))
4304 (equal function tail))
4305 (memq function (symbol-value hook)))
4306 (set hook
4307 (if append
4308 (nconc (symbol-value hook) (list function))
4309 (cons function (symbol-value hook)))))))
4311 ;;;_ #10 Under development
4312 ;;;_ > outline-bullet-isearch (&optional bullet)
4313 (defun outline-bullet-isearch (&optional bullet)
4314 "Isearch \(regexp\) for topic with bullet BULLET."
4315 (interactive)
4316 (if (not bullet)
4317 (setq bullet (solicit-char-in-string
4318 "ISearch for topic with bullet: "
4319 (regexp-sans-escapes outline-bullets-string))))
4321 (let ((isearch-regexp t)
4322 (isearch-string (concat "^"
4323 outline-header-prefix
4324 "[ \t]*"
4325 bullet)))
4326 (isearch-repeat 'forward)
4327 (isearch-mode t)))
4328 ;;;_ ? Re hooking up with isearch - use isearch-op-fun rather than
4329 ;;; wrapping the isearch functions.
4331 ;;;_* Local emacs vars.
4332 ;;; The following `outline-layout' local variable setting:
4333 ;;; - closes all topics from the first topic to just before the third-to-last,
4334 ;;; - shows the children of the third to last (config vars)
4335 ;;; - and the second to last (code section),
4336 ;;; - and closes the last topic (this local-variables section).
4337 ;;;Local variables:
4338 ;;;outline-layout: (0 : -1 -1 0)
4339 ;;;End:
4341 ;; allout.el ends here