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@python.org>
6 ;; Maintainer: Ken Manheimer <klm@python.org>
7 ;; Created: Dec 1991 - first release to usenet
8 ;; Version: Id: allout.el,v 4.3 1994/05/12 17:43:08 klm Exp ||
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)
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.
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.)
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.
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
57 ;; Gaithersburg, MD 20899
63 ;;;_* USER CUSTOMIZATION VARIABLES:
65 "Extensive outline mode for use alone and with other modes."
69 ;;;_ + Layout, Mode, and Topic Header Configuration
71 ;;;_ = outline-auto-activation
72 (defvar outline-auto-activation nil
73 "*Regulates auto-activation modality of allout outlines - see `outline-init'.
75 Setq-default by `outline-init' to regulate whether or not allout
76 outline mode is automatically activated when the buffer-specific
77 variable `outline-layout' is non-nil, and whether or not the layout
78 dictated by `outline-layout' should be imposed on mode activation.
80 With value `t', auto-mode-activation and auto-layout are enabled.
81 \(This also depends on `outline-find-file-hooks' being installed in
82 `find-file-hooks', which is also done by `outline-init'.)
84 With value `ask', auto-mode-activation is enabled, and endorsement for
85 performing auto-layout is asked of the user each time.
87 With value `activate', only auto-mode-activation is enabled,
90 With value `nil', neither auto-mode-activation nor auto-layout are
93 See the docstring for `outline-init' for the proper interface to
96 (defvar outline-layout nil
97 "*Layout specification and provisional mode trigger for allout outlines.
101 A list value specifies a default layout for the current buffer, to be
102 applied upon activation of allout outline-mode. Any non-nil value will
103 automatically trigger allout outline-mode, provided `outline-init'
104 has been called to enable it.
106 See the docstring for `outline-init' for details on setting up for
107 auto-mode-activation, and for `outline-expose-topic' for the format of
108 the layout specification.
110 You can associate a particular outline layout with a file by setting
111 this var via the file's local variables. For example, the following
112 lines at the bottom of an Emacs Lisp file:
115 ;;;outline-layout: \(0 : -1 -1 0\)
118 will, modulo the above-mentioned conditions, cause the mode to be
119 activated when the file is visited, followed by the equivalent of
120 `\(outline-expose-topic 0 : -1 -1 0\)'. \(This is the layout used for
121 the allout.el, itself.)
123 Also, allout's mode-specific provisions will make topic prefixes default
124 to the comment-start string, if any, of the language of the file. This
125 is modulo the setting of `outline-use-mode-specific-leader', which see.")
126 (make-variable-buffer-local 'outline-layout
)
128 ;;;_ = outline-header-prefix
129 (defcustom outline-header-prefix
"."
130 "*Leading string which helps distinguish topic headers.
132 Outline topic header lines are identified by a leading topic
133 header prefix, which mostly have the value of this var at their front.
134 \(Level 1 topics are exceptions. They consist of only a single
135 character, which is typically set to the outline-primary-bullet. Many
136 outlines start at level 2 to avoid this discrepancy."
139 (make-variable-buffer-local 'outline-header-prefix
)
140 ;;;_ = outline-primary-bullet
141 (defcustom outline-primary-bullet
"*"
142 "Bullet used for top-level outline topics.
144 Outline topic header lines are identified by a leading topic header
145 prefix, which is concluded by bullets that includes the value of this
146 var and the respective outline-*-bullets-string vars.
148 The value of an asterisk (`*') provides for backwards compatibility
149 with the original emacs outline mode. See outline-plain-bullets-string
150 and outline-distinctive-bullets-string for the range of available
154 (make-variable-buffer-local 'outline-primary-bullet
)
155 ;;;_ = outline-plain-bullets-string
156 (defcustom outline-plain-bullets-string
(concat outline-primary-bullet
158 "*The bullets normally used in outline topic prefixes.
160 See `outline-distinctive-bullets-string' for the other kind of
163 DO NOT include the close-square-bracket, `]', as a bullet.
165 Outline mode has to be reactivated in order for changes to the value
166 of this var to take effect."
169 (make-variable-buffer-local 'outline-plain-bullets-string
)
170 ;;;_ = outline-distinctive-bullets-string
171 (defcustom outline-distinctive-bullets-string
"=>([{}&!?#%\"X@$~\\"
172 "*Persistent outline header bullets used to distinguish special topics.
174 These bullets are not offered among the regular, level-specific
175 rotation, and are not altered by automatic rebulleting, as when
176 shifting the level of a topic. See `outline-plain-bullets-string' for
177 the selection of alternating bullets.
179 You must run `set-outline-regexp' in order for changes
180 to the value of this var to effect outline-mode operation.
182 DO NOT include the close-square-bracket, `]', on either of the bullet
186 (make-variable-buffer-local 'outline-distinctive-bullets-string
)
188 ;;;_ = outline-use-mode-specific-leader
189 (defcustom outline-use-mode-specific-leader t
190 "*When non-nil, use mode-specific topic-header prefixes.
192 Allout outline mode will use the mode-specific `outline-mode-leaders'
193 and/or comment-start string, if any, to lead the topic prefix string,
194 so topic headers look like comments in the programming language.
196 String values are used as they stand.
198 Value `t' means to first check for assoc value in `outline-mode-leaders'
199 alist, then use comment-start string, if any, then use default \(`.').
200 \(See note about use of comment-start strings, below.\)
202 Set to the symbol for either of `outline-mode-leaders' or
203 `comment-start' to use only one of them, respectively.
205 Value `nil' means to always use the default \(`.'\).
207 comment-start strings that do not end in spaces are tripled, and an
208 `_' underscore is tacked on the end, to distinguish them from regular
209 comment strings. comment-start strings that do end in spaces are not
210 tripled, but an underscore is substituted for the space. [This
211 presumes that the space is for appearance, not comment syntax. You
212 can use `outline-mode-leaders' to override this behavior, when
214 :type
'(choice (const t
) (const nil
) string
215 (const outline-mode-leaders
)
216 (const comment-start
))
218 ;;;_ = outline-mode-leaders
219 (defvar outline-mode-leaders
'()
220 "Specific outline-prefix leading strings per major modes.
222 Entries will be used in the stead (or lieu) of mode-specific
223 comment-start strings. See also `outline-use-mode-specific-leader'.
225 If you're constructing a string that will comment-out outline
226 structuring so it can be included in program code, append an extra
227 character, like an \"_\" underscore, to distinguish the lead string
228 from regular comments that start at bol.")
230 ;;;_ = outline-old-style-prefixes
231 (defcustom outline-old-style-prefixes nil
232 "*When non-nil, use only old-and-crusty outline-mode `*' topic prefixes.
234 Non-nil restricts the topic creation and modification
235 functions to asterix-padded prefixes, so they look exactly
236 like the original emacs-outline style prefixes.
238 Whatever the setting of this variable, both old and new style prefixes
239 are always respected by the topic maneuvering functions."
242 (make-variable-buffer-local 'outline-old-style-prefixes
)
243 ;;;_ = outline-stylish-prefixes - alternating bullets
244 (defcustom outline-stylish-prefixes t
245 "*Do fancy stuff with topic prefix bullets according to level, etc.
247 Non-nil enables topic creation, modification, and repositioning
248 functions to vary the topic bullet char (the char that marks the topic
249 depth) just preceding the start of the topic text) according to level.
250 Otherwise, only asterisks (`*') and distinctive bullets are used.
252 This is how an outline can look (but sans indentation) with stylish
257 . + One level 3 subtopic
258 . . One level 4 subtopic
259 . . A second 4 subtopic
260 . + Another level 3 subtopic
261 . #1 A numbered level 4 subtopic
263 . ! Another level 4 subtopic with a different distinctive bullet
264 . #4 And another numbered level 4 subtopic
266 This would be an outline with stylish prefixes inhibited (but the
267 numbered and other distinctive bullets retained):
271 . * One level 3 subtopic
272 . * One level 4 subtopic
273 . * A second 4 subtopic
274 . * Another level 3 subtopic
275 . #1 A numbered level 4 subtopic
277 . ! Another level 4 subtopic with a different distinctive bullet
278 . #4 And another numbered level 4 subtopic
280 Stylish and constant prefixes (as well as old-style prefixes) are
281 always respected by the topic maneuvering functions, regardless of
282 this variable setting.
284 The setting of this var is not relevant when outline-old-style-prefixes
288 (make-variable-buffer-local 'outline-stylish-prefixes
)
290 ;;;_ = outline-numbered-bullet
291 (defcustom outline-numbered-bullet
"#"
292 "*String designating bullet of topics that have auto-numbering; nil for none.
294 Topics having this bullet have automatic maintenance of a sibling
295 sequence-number tacked on, just after the bullet. Conventionally set
296 to \"#\", you can set it to a bullet of your choice. A nil value
297 disables numbering maintenance."
298 :type
'(choice (const nil
) string
)
300 (make-variable-buffer-local 'outline-numbered-bullet
)
301 ;;;_ = outline-file-xref-bullet
302 (defcustom outline-file-xref-bullet
"@"
303 "*Bullet signifying file cross-references, for `outline-resolve-xref'.
305 Set this var to the bullet you want to use for file cross-references.
306 Set it to nil if you want to inhibit this capability."
307 :type
'(choice (const nil
) string
)
310 ;;;_ + LaTeX formatting
311 ;;;_ - outline-number-pages
312 (defcustom outline-number-pages nil
313 "*Non-nil turns on page numbering for LaTeX formatting of an outline."
316 ;;;_ - outline-label-style
317 (defcustom outline-label-style
"\\large\\bf"
318 "*Font and size of labels for LaTeX formatting of an outline."
321 ;;;_ - outline-head-line-style
322 (defcustom outline-head-line-style
"\\large\\sl "
323 "*Font and size of entries for LaTeX formatting of an outline."
326 ;;;_ - outline-body-line-style
327 (defcustom outline-body-line-style
" "
328 "*Font and size of entries for LaTeX formatting of an outline."
331 ;;;_ - outline-title-style
332 (defcustom outline-title-style
"\\Large\\bf"
333 "*Font and size of titles for LaTeX formatting of an outline."
337 (defcustom outline-title
'(or buffer-file-name
(current-buffer-name))
338 "*Expression to be evaluated to determine the title for LaTeX
342 ;;;_ - outline-line-skip
343 (defcustom outline-line-skip
".05cm"
344 "*Space between lines for LaTeX formatting of an outline."
347 ;;;_ - outline-indent
348 (defcustom outline-indent
".3cm"
349 "*LaTeX formatted depth-indent spacing."
353 ;;;_ + Miscellaneous customization
355 ;;;_ = outline-keybindings-list
356 ;;; You have to reactivate outline-mode - `(outline-mode t)' - to
357 ;;; institute changes to this var.
358 (defvar outline-keybindings-list
()
359 "*List of outline-mode key / function bindings.
361 These bindings will be locally bound on the outline-mode-map. The
362 keys will be prefixed by outline-command-prefix, unless the cell
363 contains a third, no-nil element, in which case the initial string
364 will be used as is.")
365 (setq outline-keybindings-list
368 ("?t" outline-latexify-exposed
)
369 ("\C-n" outline-next-visible-heading
)
370 ("\C-p" outline-previous-visible-heading
)
371 ("\C-u" outline-up-current-level
)
372 ("\C-f" outline-forward-current-level
)
373 ("\C-b" outline-backward-current-level
)
374 ("\C-a" outline-beginning-of-current-entry
)
375 ("\C-e" outline-end-of-current-entry
)
376 ;;("\C-n" outline-next-line-or-topic)
377 ;;("\C-p" outline-previous-line-or-topic)
379 ("\C-i" outline-show-children
)
380 ("\C-s" outline-show-current-subtree
)
381 ("\C-h" outline-hide-current-subtree
)
382 ("\C-o" outline-show-current-entry
)
383 ("!" outline-show-all
)
384 ; Alteration commands:
385 (" " outline-open-sibtopic
)
386 ("." outline-open-subtopic
)
387 ("," outline-open-supertopic
)
388 ("'" outline-shift-in
)
389 (">" outline-shift-in
)
390 ("<" outline-shift-out
)
391 ("\C-m" outline-rebullet-topic
)
392 ("*" outline-rebullet-current-heading
)
393 ("#" outline-number-siblings
)
394 ("\C-k" outline-kill-line t
)
395 ("\C-y" outline-yank t
)
396 ("\M-y" outline-yank-pop t
)
397 ("\C-k" outline-kill-topic
)
398 ; Miscellaneous commands:
399 ("\C-@" outline-mark-topic
)
400 ("@" outline-resolve-xref
)
401 ("?c" outline-copy-exposed
)))
403 ;;;_ = outline-command-prefix
404 (defcustom outline-command-prefix
"\C-c"
405 "*Key sequence to be used as prefix for outline mode command key bindings."
409 ;;;_ = outline-enwrap-isearch-mode
410 (defcustom outline-enwrap-isearch-mode t
411 "*Set non-nil to enable automatic exposure of concealed isearch targets.
413 If non-nil, isearch will expose hidden text encountered in the course
414 of a search, and to reconceal it if the search is continued past it."
418 ;;;_ = outline-use-hanging-indents
419 (defcustom outline-use-hanging-indents t
420 "*If non-nil, topic body text auto-indent defaults to indent of the header.
421 Ie, it is indented to be just past the header prefix. This is
422 relevant mostly for use with indented-text-mode, or other situations
423 where auto-fill occurs.
425 \[This feature no longer depends in any way on the `filladapt.el'
426 lisp-archive package.\]"
429 (make-variable-buffer-local 'outline-use-hanging-indents
)
431 ;;;_ = outline-reindent-bodies
432 (defcustom outline-reindent-bodies
(if outline-use-hanging-indents
434 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
436 When active, topic body lines that are indented even with or beyond
437 their topic header are reindented to correspond with depth shifts of
440 A value of `t' enables reindent in non-programming-code buffers, ie
441 those that do not have the variable `comment-start' set. A value of
442 `force' enables reindent whether or not `comment-start' is set."
443 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
446 (make-variable-buffer-local 'outline-reindent-bodies
)
448 ;;;_ = outline-inhibit-protection
449 (defcustom outline-inhibit-protection nil
450 "*Non-nil disables warnings and confirmation-checks for concealed-text edits.
452 Outline mode uses emacs change-triggered functions to detect unruly
453 changes to concealed regions. Set this var non-nil to disable the
454 protection, potentially increasing text-entry responsiveness a bit.
456 This var takes effect at outline-mode activation, so you may have to
457 deactivate and then reactivate the mode if you want to toggle the
462 ;;;_* CODE - no user customizations below.
464 ;;;_ #1 Internal Outline Formatting and Configuration
466 ;;;_ = outline-version
467 (defvar outline-version
468 (let ((rcs-rev "Revision: 4.3"))
471 (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev
)
472 (substring rcs-rev
(match-beginning 1) (match-end 1)))
474 "Revision number of currently loaded outline package. \(allout.el)")
475 ;;;_ > outline-version
476 (defun outline-version (&optional here
)
477 "Return string describing the loaded outline version."
479 (let ((msg (concat "Allout Outline Mode v " outline-version
)))
480 (if here
(insert-string msg
))
483 ;;;_ - Topic header format
484 ;;;_ = outline-regexp
485 (defvar outline-regexp
""
486 "*Regular expression to match the beginning of a heading line.
488 Any line whose beginning matches this regexp is considered a
489 heading. This var is set according to the user configuration vars
490 by set-outline-regexp.")
491 (make-variable-buffer-local 'outline-regexp
)
492 ;;;_ = outline-bullets-string
493 (defvar outline-bullets-string
""
494 "A string dictating the valid set of outline topic bullets.
496 This var should *not* be set by the user - it is set by `set-outline-regexp',
497 and is produced from the elements of `outline-plain-bullets-string'
498 and `outline-distinctive-bullets-string'.")
499 (make-variable-buffer-local 'outline-bullets-string
)
500 ;;;_ = outline-bullets-string-len
501 (defvar outline-bullets-string-len
0
502 "Length of current buffers' outline-plain-bullets-string.")
503 (make-variable-buffer-local 'outline-bullets-string-len
)
504 ;;;_ = outline-line-boundary-regexp
505 (defvar outline-line-boundary-regexp
()
506 "Outline-regexp with outline-style beginning-of-line anchor.
508 \(Ie, C-j, *or* C-m, for prefixes of hidden topics). This is properly
509 set when outline-regexp is produced by `set-outline-regexp', so
510 that (match-beginning 2) and (match-end 2) delimit the prefix.")
511 (make-variable-buffer-local 'outline-line-boundary-regexp
)
512 ;;;_ = outline-bob-regexp
513 (defvar outline-bob-regexp
()
514 "Like outline-line-boundary-regexp, for headers at beginning of buffer.
515 \(match-beginning 2) and (match-end 2) delimit the prefix.")
516 (make-variable-buffer-local 'outline-bob-regexp
)
517 ;;;_ = outline-header-subtraction
518 (defvar outline-header-subtraction
(1- (length outline-header-prefix
))
519 "Outline-header prefix length to subtract when computing topic depth.")
520 (make-variable-buffer-local 'outline-header-subtraction
)
521 ;;;_ = outline-plain-bullets-string-len
522 (defvar outline-plain-bullets-string-len
(length outline-plain-bullets-string
)
523 "Length of outline-plain-bullets-string, updated by set-outline-regexp.")
524 (make-variable-buffer-local 'outline-plain-bullets-string-len
)
527 ;;;_ X outline-reset-header-lead (header-lead)
528 (defun outline-reset-header-lead (header-lead)
529 "*Reset the leading string used to identify topic headers."
530 (interactive "sNew lead string: ")
531 (setq outline-header-prefix header-lead
)
532 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
533 (set-outline-regexp))
534 ;;;_ X outline-lead-with-comment-string (header-lead)
535 (defun outline-lead-with-comment-string (&optional header-lead
)
536 "*Set the topic-header leading string to specified string.
538 Useful when for encapsulating outline structure in programming
539 language comments. Returns the leading string."
542 (if (not (stringp header-lead
))
543 (setq header-lead
(read-string
544 "String prefix for topic headers: ")))
545 (setq outline-reindent-bodies nil
)
546 (outline-reset-header-lead header-lead
)
548 ;;;_ > outline-infer-header-lead ()
549 (defun outline-infer-header-lead ()
550 "Determine appropriate `outline-header-prefix'.
552 Works according to settings of:
555 `outline-header-prefix' (default)
556 `outline-use-mode-specific-leader'
557 and `outline-mode-leaders'.
559 Apply this via \(re\)activation of `outline-mode', rather than
560 invoking it directly."
561 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader
)
562 (if (or (stringp outline-use-mode-specific-leader
)
563 (memq outline-use-mode-specific-leader
564 '(outline-mode-leaders
567 outline-use-mode-specific-leader
568 ;; Oops - garbled value, equate with effect of 't:
572 ((not use-leader
) nil
)
573 ;; Use the explicitly designated leader:
574 ((stringp use-leader
) use-leader
)
575 (t (or (and (memq use-leader
'(t outline-mode-leaders
))
576 ;; Get it from outline mode leaders?
577 (cdr (assq major-mode outline-mode-leaders
)))
578 ;; ... didn't get from outline-mode-leaders...
579 (and (memq use-leader
'(t comment-start
))
581 ;; Use comment-start, maybe tripled, and with
585 (substring comment-start
586 (1- (length comment-start
))))
587 ;; Use comment-start, sans trailing space:
588 (substring comment-start
0 -
1)
589 (concat comment-start comment-start comment-start
))
590 ;; ... and append underscore, whichever:
594 (if (string= leader outline-header-prefix
)
595 nil
; no change, nothing to do.
596 (setq outline-header-prefix leader
)
597 outline-header-prefix
))))
598 ;;;_ > outline-infer-body-reindent ()
599 (defun outline-infer-body-reindent ()
600 "Determine proper setting for `outline-reindent-bodies'.
602 Depends on default setting of `outline-reindent-bodies' \(which see)
603 and presence of setting for `comment-start', to tell whether the
604 file is programming code."
605 (if (and outline-reindent-bodies
607 (not (eq 'force outline-reindent-bodies
)))
608 (setq outline-reindent-bodies nil
)))
609 ;;;_ > set-outline-regexp ()
610 (defun set-outline-regexp ()
611 "Generate proper topic-header regexp form for outline functions.
613 Works with respect to `outline-plain-bullets-string' and
614 `outline-distinctive-bullets-string'."
617 ;; Derive outline-bullets-string from user configured components:
618 (setq outline-bullets-string
"")
619 (let ((strings (list 'outline-plain-bullets-string
620 'outline-distinctive-bullets-string
))
628 (setq new-string
"") (setq index
0)
629 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
630 (while (< index cur-len
)
631 (setq cur-char
(aref cur-string index
))
632 (setq outline-bullets-string
633 (concat outline-bullets-string
635 ; Single dash would denote a
636 ; sequence, repeated denotes
638 ((eq cur-char ?-
) "--")
639 ; literal close-square-bracket
640 ; doesn't work right in the
642 ((eq cur-char ?\
]) "")
643 (t (regexp-quote (char-to-string cur-char
))))))
644 (setq index
(1+ index
)))
645 (setq strings
(cdr strings
)))
647 ;; Derive next for repeated use in outline-pending-bullet:
648 (setq outline-plain-bullets-string-len
(length outline-plain-bullets-string
))
649 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
650 ;; Produce the new outline-regexp:
651 (setq outline-regexp
(concat "\\(\\"
652 outline-header-prefix
654 outline-bullets-string
656 outline-primary-bullet
658 (setq outline-line-boundary-regexp
659 (concat "\\([\n\r]\\)\\(" outline-regexp
"\\)"))
660 (setq outline-bob-regexp
661 (concat "\\(\\`\\)\\(" outline-regexp
"\\)"))
664 ;;;_ = outline-mode-map
665 (defvar outline-mode-map nil
"Keybindings for (allout) outline minor mode.")
666 ;;;_ > produce-outline-mode-map (keymap-alist &optional base-map)
667 (defun produce-outline-mode-map (keymap-list &optional base-map
)
668 "Produce keymap for use as outline-mode-map, from keymap-list.
670 Built on top of optional BASE-MAP, or empty sparse map if none specified.
671 See doc string for outline-keybindings-list for format of binding list."
672 (let ((map (or base-map
(make-sparse-keymap))))
673 (mapcar (lambda (cell)
674 (apply 'define-key map
(if (null (cdr (cdr cell
)))
675 (cons (concat outline-command-prefix
678 (list (car cell
) (car (cdr cell
))))))
681 ;;;_ = outline-prior-bindings - being deprecated.
682 (defvar outline-prior-bindings nil
683 "Variable for use in V18, with outline-added-bindings, for
684 resurrecting, on mode deactivation, bindings that existed before
685 activation. Being deprecated.")
686 ;;;_ = outline-added-bindings - being deprecated
687 (defvar outline-added-bindings nil
688 "Variable for use in V18, with outline-prior-bindings, for
689 resurrecting, on mode deactivation, bindings that existed before
690 activation. Being deprecated.")
691 ;;;_ - Mode-Specific Variable Maintenance Utilities
692 ;;;_ = outline-mode-prior-settings
693 (defvar outline-mode-prior-settings nil
694 "Internal outline mode use; settings to be resumed on mode deactivation.")
695 (make-variable-buffer-local 'outline-mode-prior-settings
)
696 ;;;_ > outline-resumptions (name &optional value)
697 (defun outline-resumptions (name &optional value
)
699 "Registers or resumes settings over outline-mode activation/deactivation.
701 First arg is NAME of variable affected. Optional second arg is list
702 containing outline-mode-specific VALUE to be imposed on named
703 variable, and to be registered. (It's a list so you can specify
704 registrations of null values.) If no value is specified, the
705 registered value is returned (encapsulated in the list, so the caller
706 can distinguish nil vs no value), and the registration is popped
709 (let ((on-list (assq name outline-mode-prior-settings
))
710 prior-capsule
; By `capsule' i mean a list
711 ; containing a value, so we can
712 ; distinguish nil from no value.
720 nil
; Already preserved prior value - don't mess with it.
721 ;; Register the old value, or nil if previously unbound:
722 (setq outline-mode-prior-settings
724 (if (boundp name
) (list (symbol-value name
))))
725 outline-mode-prior-settings
)))
726 ; And impose the new value, locally:
727 (progn (make-local-variable name
)
728 (set name
(car value
))))
733 ;; Oops, not registered - leave it be:
736 ;; Some registration:
738 (setq prior-capsule
(car (cdr on-list
)))
740 (set name
(car prior-capsule
)) ; Some prior value - reestablish it.
741 (makunbound name
)) ; Previously unbound - demolish var.
742 ; Remove registration:
744 (while outline-mode-prior-settings
745 (if (not (eq (car outline-mode-prior-settings
)
748 (cons (car outline-mode-prior-settings
)
750 (setq outline-mode-prior-settings
751 (cdr outline-mode-prior-settings
)))
752 (setq outline-mode-prior-settings rebuild
)))))
754 ;;;_ - Mode-specific incidentals
755 ;;;_ = outline-during-write-cue nil
756 (defvar outline-during-write-cue nil
757 "Used to inhibit outline change-protection during file write.
759 See also `outline-post-command-business', `outline-write-file-hook',
760 `outline-before-change-protect', and `outline-post-command-business'
762 ;;;_ = outline-override-protect nil
763 (defvar outline-override-protect nil
764 "Used in outline-mode for regulate of concealed-text protection mechanism.
766 Allout outline mode regulates alteration of concealed text to protect
767 against inadvertent, unnoticed changes. This is for use by specific,
768 native outline functions to temporarily override that protection.
769 It's automatically reset to nil after every buffer modification.")
770 (make-variable-buffer-local 'outline-override-protect
)
771 ;;;_ > outline-unprotected (expr)
772 (defmacro outline-unprotected
(expr)
773 "Evaluate EXPRESSION with `outline-override-protect' let-bound to t."
774 (` (let ((outline-override-protect t
))
776 ;;;_ = outline-undo-aggregation
777 (defvar outline-undo-aggregation
30
778 "Amount of successive self-insert actions to bunch together per undo.
780 This is purely a kludge variable, regulating the compensation for a bug in
781 the way that before-change-function and undo interact.")
782 (make-variable-buffer-local 'outline-undo-aggregation
)
783 ;;;_ = file-var-bug hack
784 (defvar outline-v18
/9-file-var-hack nil
785 "Horrible hack used to prevent invalid multiple triggering of outline
786 mode from prop-line file-var activation. Used by outline-mode function
788 ;;;_ > outline-write-file-hook ()
789 (defun outline-write-file-hook ()
790 "In outline mode, run as a local-write-file-hooks activity.
792 Currently just sets `outline-during-write-cue', so outline-change-protection
793 knows to keep inactive during file write."
794 (setq outline-during-write-cue t
)
797 ;;;_ #2 Mode activation
799 (defvar outline-mode
() "Allout outline mode minor-mode flag.")
800 (make-variable-buffer-local 'outline-mode
)
801 ;;;_ > outline-mode-p ()
802 (defmacro outline-mode-p
()
803 "Return t if outline-mode is active in current buffer."
805 ;;;_ = outline-explicitly-deactivated
806 (defvar outline-explicitly-deactivated nil
807 "Outline-mode was last deliberately deactivated.
808 So outline-post-command-business should not reactivate it...")
809 (make-variable-buffer-local 'outline-explicitly-deactivated
)
810 ;;;_ > outline-init (&optional mode)
811 (defun outline-init (&optional mode
)
812 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'.
814 MODE is one of the following symbols:
816 - nil \(or no argument) deactivate auto-activation/layout;
817 - `activate', enable auto-activation only;
818 - `ask', enable auto-activation, and enable auto-layout but with
819 confirmation for layout operation solicited from user each time;
820 - `report', just report and return the current auto-activation state;
821 - anything else \(eg, t) for auto-activation and auto-layout, without
822 any confirmation check.
824 Use this function to setup your emacs session for automatic activation
825 of allout outline mode, contingent to the buffer-specific setting of
826 the `outline-layout' variable. (See `outline-layout' and
827 `outline-expose-topic' docstrings for more details on auto layout).
829 `outline-init' works by setting up (or removing) the outline-mode
830 find-file-hook, and giving `outline-auto-activation' a suitable
833 To prime your emacs session for full auto-outline operation, include
834 the following two lines in your emacs init file:
844 (concat "Select outline auto setup mode "
845 "(empty for report, ? for options) ")
846 '(("nil")("full")("activate")("deactivate")
847 ("ask") ("report") (""))
850 (if (string= mode
"")
852 (setq mode
(intern-soft mode
)))))
854 ;; convenience aliases, for consistent ref to respective vars:
855 ((hook 'outline-find-file-hook
)
856 (curr-mode 'outline-auto-activation
))
859 (setq find-file-hooks
(delq hook find-file-hooks
))
861 (message "Allout outline mode auto-activation inhibited.")))
863 (if (not (memq hook find-file-hooks
))
865 ;; Just punt and use the reports from each of the modes:
866 (outline-init (symbol-value curr-mode
))))
867 (t (add-hook 'find-file-hooks hook
)
868 (set curr-mode
; `set', not `setq'!
869 (cond ((eq mode
'activate
)
871 "Outline mode auto-activation enabled.")
874 ;; Return the current mode setting:
878 (concat "Outline mode auto-activation and "
879 "-layout \(upon confirmation) enabled."))
882 "Outline mode auto-activation and -layout enabled.")
885 ;;;_ > outline-mode (&optional toggle)
887 (defun outline-mode (&optional toggle
)
889 "Toggle minor mode for controlling exposure and editing of text outlines.
891 Optional arg forces mode reactivation iff arg is positive num or symbol.
893 Allout outline mode provides extensive outline formatting and
894 manipulation capabilities. It is specifically aimed at supporting
895 outline structuring and manipulation of syntax-sensitive text, eg
896 programming languages. \(For an example, see the allout code itself,
897 which is organized in outline structure.\)
899 It also includes such things as topic-oriented repositioning, cut, and
900 paste; integral outline exposure-layout; incremental search with
901 dynamic exposure/concealment of concealed text; automatic topic-number
902 maintenance; and many other features.
904 See the docstring of the variable `outline-init' for instructions on
905 priming your emacs session for automatic activation of outline-mode,
906 according to file-var settings of the `outline-layout' variable.
908 Below is a description of the bindings, and then explanation of
909 special outline-mode features and terminology.
911 The bindings themselves are established according to the values of
912 variables `outline-keybindings-list' and `outline-command-prefix',
913 each time the mode is invoked. Prior bindings are resurrected when
916 Navigation: Exposure Control:
917 ---------- ----------------
918 C-c C-n outline-next-visible-heading | C-c C-h outline-hide-current-subtree
919 C-c C-p outline-previous-visible-heading | C-c C-i outline-show-children
920 C-c C-u outline-up-current-level | C-c C-s outline-show-current-subtree
921 C-c C-f outline-forward-current-level | C-c C-o outline-show-current-entry
922 C-c C-b outline-backward-current-level | ^U C-c C-s outline-show-all
923 C-c C-e outline-end-of-current-entry | outline-hide-current-leaves
924 C-c C-a outline-beginning-of-current-entry, alternately, goes to hot-spot
926 Topic Header Production:
927 -----------------------
928 C-c<SP> outline-open-sibtopic Create a new sibling after current topic.
929 C-c . outline-open-subtopic ... an offspring of current topic.
930 C-c , outline-open-supertopic ... a sibling of the current topic's parent.
932 Topic Level and Prefix Adjustment:
933 ---------------------------------
934 C-c > outline-shift-in Shift current topic and all offspring deeper.
935 C-c < outline-shift-out ... less deep.
936 C-c<CR> outline-rebullet-topic Reconcile bullets of topic and its offspring
937 - distinctive bullets are not changed, others
938 alternated according to nesting depth.
939 C-c * outline-rebullet-current-heading Prompt for alternate bullet for
941 C-c # outline-number-siblings Number bullets of topic and siblings - the
942 offspring are not affected. With repeat
943 count, revoke numbering.
945 Topic-oriented Killing and Yanking:
946 ----------------------------------
947 C-c C-k outline-kill-topic Kill current topic, including offspring.
948 C-k outline-kill-line Like kill-line, but reconciles numbering, etc.
949 C-y outline-yank Yank, adjusting depth of yanked topic to
950 depth of heading if yanking into bare topic
951 heading (ie, prefix sans text).
952 M-y outline-yank-pop Is to outline-yank as yank-pop is to yank
956 C-c @ outline-resolve-xref pop-to-buffer named by xref (cf
957 outline-file-xref-bullet)
958 C-c c outline-copy-exposed Copy current topic outline sans concealed
959 text, to buffer with name derived from
960 current buffer - \"XXX exposed\"
961 M-x outlineify-sticky Activate outline mode for current buffer,
962 and establish a default file-var setting
963 for `outline-layout'.
964 ESC ESC (outline-init t) Setup emacs session for outline mode
969 Hot-spot operation provides a means for easy, single-keystroke outline
970 navigation and exposure control.
973 When the text cursor is positioned directly on the bullet character of
974 a topic, regular characters (a to z) invoke the commands of the
975 corresponding outline-mode keymap control chars. For example, \"f\"
976 would invoke the command typically bound to \"C-c C-f\"
977 \(\\[outline-forward-current-level] `outline-forward-current-level').
979 Thus, by positioning the cursor on a topic bullet, you can execute
980 the outline navigation and manipulation commands with a single
981 keystroke. Non-literal chars never get this special translation, so
982 you can use them to get away from the hot-spot, and back to normal
985 Note that the command `outline-beginning-of-current-entry' \(\\[outline-beginning-of-current-entry]\)
986 will move to the hot-spot when the cursor is already located at the
987 beginning of the current entry, so you can simply hit \\[outline-beginning-of-current-entry]
988 twice in a row to get to the hot-spot.
992 Topic hierarchy constituents - TOPICS and SUBTOPICS:
994 TOPIC: A basic, coherent component of an emacs outline. It can
995 contain other topics, and it can be subsumed by other topics,
997 The visible topic most immediately containing the cursor.
998 DEPTH: The degree of nesting of a topic; it increases with
999 containment. Also called the:
1000 LEVEL: The same as DEPTH.
1003 The topics that contain a topic.
1004 PARENT: A topic's immediate ancestor. It has a depth one less than
1007 The topics contained by a topic;
1009 An immediate offspring of a topic;
1011 The immediate offspring of a topic.
1013 Topics having the same parent and depth.
1015 Topic text constituents:
1017 HEADER: The first line of a topic, include the topic PREFIX and header
1019 PREFIX: The leading text of a topic which which distinguishes it from
1020 normal text. It has a strict form, which consists of a
1021 prefix-lead string, padding, and a bullet. The bullet may be
1022 followed by a number, indicating the ordinal number of the
1023 topic among its siblings, a space, and then the header text.
1025 The relative length of the PREFIX determines the nesting depth
1028 The string at the beginning of a topic prefix, normally a `.'.
1029 It can be customized by changing the setting of
1030 `outline-header-prefix' and then reinitializing outline-mode.
1032 By setting the prefix-lead to the comment-string of a
1033 programming language, you can embed outline-structuring in
1034 program code without interfering with the language processing
1035 of that code. See `outline-use-mode-specific-leader'
1036 docstring for more detail.
1038 Spaces or asterisks which separate the prefix-lead and the
1039 bullet, according to the depth of the topic.
1040 BULLET: A character at the end of the topic prefix, it must be one of
1041 the characters listed on `outline-plain-bullets-string' or
1042 `outline-distinctive-bullets-string'. (See the documentation
1043 for these variables for more details.) The default choice of
1044 bullet when generating varies in a cycle with the depth of the
1046 ENTRY: The text contained in a topic before any offspring.
1047 BODY: Same as ENTRY.
1051 The state of a topic which determines the on-screen visibility
1052 of its offspring and contained text.
1054 Topics and entry text whose display is inhibited. Contiguous
1055 units of concealed text is represented by `...' ellipses.
1056 (Ref the `selective-display' var.)
1058 Concealed topics are effectively collapsed within an ancestor.
1059 CLOSED: A topic whose immediate offspring and body-text is concealed.
1060 OPEN: A topic that is not closed, though its offspring or body may be."
1064 (let* ((active (and (not (equal major-mode
'outline
))
1066 ; Massage universal-arg `toggle' val:
1068 (or (and (listp toggle
)(car toggle
))
1070 ; Activation specifically demanded?
1071 (explicit-activation (or
1074 (or (symbolp toggle
)
1075 (and (natnump toggle
)
1076 (not (zerop toggle
)))))))
1077 ;; outline-mode already called once during this complex command?
1078 (same-complex-command (eq outline-v18
/9-file-var-hack
1079 (car command-history
)))
1083 ; See comments below re v19.18,.19 bug.
1084 (setq outline-v18
/9-file-var-hack
(car command-history
))
1088 ;; Provision for v19.18, 19.19 bug -
1089 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1090 ;; modes twice when file is visited. We have to avoid toggling mode
1091 ;; off on second invocation, so we detect it as best we can, and
1093 ((and same-complex-command
; Still in same complex command
1094 ; as last time outline-mode invoked.
1095 active
; Already activated.
1096 (not explicit-activation
) ; Prop-line file-vars don't have args.
1097 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1098 emacs-version
)); 19.19.
1102 ((and (not explicit-activation
)
1104 ; Activation not explicitly
1105 ; requested, and either in
1106 ; active state or *de*activation
1107 ; specifically requested:
1108 (setq outline-explicitly-deactivated t
)
1109 (if (string-match "^18\." emacs-version
)
1110 ; Revoke those keys that remain
1112 (let ((curr-loc (current-local-map)))
1113 (mapcar '(lambda (cell)
1114 (if (eq (lookup-key curr-loc
(car cell
))
1116 (define-key curr-loc
(car cell
)
1117 (assq (car cell
) outline-prior-bindings
))))
1118 outline-added-bindings
)
1119 (outline-resumptions 'outline-added-bindings
)
1120 (outline-resumptions 'outline-prior-bindings
)))
1122 (if outline-old-style-prefixes
1124 (outline-resumptions 'outline-primary-bullet
)
1125 (outline-resumptions 'outline-old-style-prefixes
)))
1126 (outline-resumptions 'selective-display
)
1127 (if (and (boundp 'before-change-function
) before-change-function
)
1128 (outline-resumptions 'before-change-function
))
1129 (setq pre-command-hook
(delq 'outline-pre-command-business
1131 (setq local-write-file-hooks
1132 (delq 'outline-write-file-hook
1133 local-write-file-hooks
))
1134 (outline-resumptions 'paragraph-start
)
1135 (outline-resumptions 'paragraph-separate
)
1136 (outline-resumptions (if (string-match "^18" emacs-version
)
1138 'auto-fill-function
))
1139 (outline-resumptions 'outline-former-auto-filler
)
1140 (setq outline-mode nil
))
1144 (setq outline-explicitly-deactivated nil
)
1145 (if outline-old-style-prefixes
1146 (progn ; Inhibit all the fancy formatting:
1147 (outline-resumptions 'outline-primary-bullet
'("*"))
1148 (outline-resumptions 'outline-old-style-prefixes
'(()))))
1150 (outline-infer-header-lead)
1151 (outline-infer-body-reindent)
1153 (set-outline-regexp)
1155 ; Produce map from current version
1156 ; of outline-keybindings-list:
1157 (if (boundp 'minor-mode-map-alist
)
1159 (progn ; V19, and maybe lucid and
1160 ; epoch, minor-mode key bindings:
1161 (setq outline-mode-map
1162 (produce-outline-mode-map outline-keybindings-list
))
1163 (fset 'outline-mode-map outline-mode-map
)
1164 ; Include on minor-mode-map-alist,
1165 ; if not already there:
1166 (if (not (member '(outline-mode . outline-mode-map
)
1167 minor-mode-map-alist
))
1168 (setq minor-mode-map-alist
1169 (cons '(outline-mode . outline-mode-map
)
1170 minor-mode-map-alist
))))
1172 ; V18 minor-mode key bindings:
1173 ; Stash record of added bindings
1174 ; for later revocation:
1175 (outline-resumptions 'outline-added-bindings
1176 (list outline-keybindings-list
))
1177 (outline-resumptions 'outline-prior-bindings
1178 (list (current-local-map)))
1180 (use-local-map (produce-outline-mode-map outline-keybindings-list
1181 (current-local-map)))
1184 ; selective-display is the
1185 ; emacs conditional exposure
1187 (outline-resumptions 'selective-display
'(t))
1188 (if outline-inhibit-protection
1190 (outline-resumptions 'before-change-function
1191 '(outline-before-change-protect)))
1192 ; Temporarily set by any outline
1193 ; functions that can be trusted to
1194 ; deal properly with concealed text.
1195 (add-hook 'local-write-file-hooks
'outline-write-file-hook
)
1196 ; Custom auto-fill func, to support
1197 ; respect for topic headline,
1198 ; hanging-indents, etc:
1199 (let* ((fill-func-var (if (string-match "^18" emacs-version
)
1201 'auto-fill-function
))
1202 (fill-func (symbol-value fill-func-var
)))
1203 ;; Register prevailing fill func for use by outline-auto-fill:
1204 (outline-resumptions 'outline-former-auto-filler
(list fill-func
))
1205 ;; Register outline-auto-fill to be used if filling is active:
1206 (outline-resumptions fill-func-var
'(outline-auto-fill)))
1207 ;; Paragraphs are broken by topic headlines.
1208 (make-local-variable 'paragraph-start
)
1209 (outline-resumptions 'paragraph-start
1210 (list (concat paragraph-start
"\\|\\("
1211 outline-regexp
"\\)")))
1212 (make-local-variable 'paragraph-separate
)
1213 (outline-resumptions 'paragraph-separate
1214 (list (concat paragraph-separate
"\\|\\("
1215 outline-regexp
"\\)")))
1217 (or (assq 'outline-mode minor-mode-alist
)
1218 (setq minor-mode-alist
1219 (cons '(outline-mode " Outl") minor-mode-alist
)))
1224 (if outline-enwrap-isearch-mode
1225 (outline-enwrap-isearch))
1227 (run-hooks 'outline-mode-hook
)
1228 (setq outline-mode t
))
1232 (outline-infer-body-reindent))
1236 outline-auto-activation
1237 (listp outline-layout
)
1238 (and (not (eq outline-auto-activation
'activate
))
1239 (if (eq outline-auto-activation
'ask
)
1240 (if (y-or-n-p (format "Expose %s with layout '%s'? "
1244 (message "Skipped %s layout." (buffer-name))
1248 (message "Adjusting '%s' exposure..." (buffer-name))
1250 (outline-this-or-next-heading)
1253 (apply 'outline-expose-topic
(list outline-layout
))
1254 (message "Adjusting '%s' exposure... done." (buffer-name)))
1255 ;; Problem applying exposure - notify user, but don't
1256 ;; interrupt, eg, file visit:
1257 (error (message "%s" (car (cdr err
)))
1263 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs
1264 ;;; All the basic outline functions that directly do string matches to
1265 ;;; evaluate heading prefix location set the variables
1266 ;;; `outline-recent-prefix-beginning' and `outline-recent-prefix-end'
1267 ;;; when successful. Functions starting with `outline-recent-' all
1268 ;;; use this state, providing the means to avoid redundant searches
1269 ;;; for just-established data. This optimization can provide
1270 ;;; significant speed improvement, but it must be employed carefully.
1271 ;;;_ = outline-recent-prefix-beginning
1272 (defvar outline-recent-prefix-beginning
0
1273 "Buffer point of the start of the last topic prefix encountered.")
1274 (make-variable-buffer-local 'outline-recent-prefix-beginning
)
1275 ;;;_ = outline-recent-prefix-end
1276 (defvar outline-recent-prefix-end
0
1277 "Buffer point of the end of the last topic prefix encountered.")
1278 (make-variable-buffer-local 'outline-recent-prefix-end
)
1279 ;;;_ = outline-recent-end-of-subtree
1280 (defvar outline-recent-end-of-subtree
0
1281 "Buffer point last returned by outline-end-of-current-subtree.")
1282 (make-variable-buffer-local 'outline-recent-end-of-subtree
)
1283 ;;;_ > outline-prefix-data (beg end)
1284 (defmacro outline-prefix-data
(beg end
)
1285 "Register outline-prefix state data - BEGINNING and END of prefix.
1287 For reference by `outline-recent' funcs. Returns BEGINNING."
1288 (` (setq outline-recent-prefix-end
(, end
)
1289 outline-recent-prefix-beginning
(, beg
))))
1290 ;;;_ > outline-recent-depth ()
1291 (defmacro outline-recent-depth
()
1292 "Return depth of last heading encountered by an outline maneuvering function.
1294 All outline functions which directly do string matches to assess
1295 headings set the variables outline-recent-prefix-beginning and
1296 outline-recent-prefix-end if successful. This function uses those settings
1297 to return the current depth."
1299 '(max 1 (- outline-recent-prefix-end
1300 outline-recent-prefix-beginning
1301 outline-header-subtraction
)))
1302 ;;;_ > outline-recent-prefix ()
1303 (defmacro outline-recent-prefix
()
1304 "Like outline-recent-depth, but returns text of last encountered prefix.
1306 All outline functions which directly do string matches to assess
1307 headings set the variables outline-recent-prefix-beginning and
1308 outline-recent-prefix-end if successful. This function uses those settings
1309 to return the current depth."
1310 '(buffer-substring outline-recent-prefix-beginning
1311 outline-recent-prefix-end
))
1312 ;;;_ > outline-recent-bullet ()
1313 (defmacro outline-recent-bullet
()
1314 "Like outline-recent-prefix, but returns bullet of last encountered prefix.
1316 All outline functions which directly do string matches to assess
1317 headings set the variables outline-recent-prefix-beginning and
1318 outline-recent-prefix-end if successful. This function uses those settings
1319 to return the current depth of the most recently matched topic."
1320 '(buffer-substring (1- outline-recent-prefix-end
)
1321 outline-recent-prefix-end
))
1325 ;;;_ - Position Assessment
1326 ;;;_ : Location Predicates
1327 ;;;_ > outline-on-current-heading-p ()
1328 (defun outline-on-current-heading-p ()
1329 "Return non-nil if point is on current visible topics' header line.
1331 Actually, returns prefix beginning point."
1334 (and (looking-at outline-regexp
)
1335 (outline-prefix-data (match-beginning 0) (match-end 0)))))
1336 ;;;_ > outline-e-o-prefix-p ()
1337 (defun outline-e-o-prefix-p ()
1338 "True if point is located where current topic prefix ends, heading begins."
1339 (and (save-excursion (beginning-of-line)
1340 (looking-at outline-regexp
))
1341 (= (point)(save-excursion (outline-end-of-prefix)(point)))))
1342 ;;;_ > outline-hidden-p ()
1343 (defmacro outline-hidden-p
()
1344 "True if point is in hidden text."
1346 (and (re-search-backward "[\n\r]" () t
)
1347 (= ?
\r (following-char)))))
1348 ;;;_ > outline-visible-p ()
1349 (defmacro outline-visible-p
()
1350 "True if point is not in hidden text."
1352 '(not (outline-hidden-p)))
1353 ;;;_ : Location attributes
1354 ;;;_ > outline-depth ()
1355 (defmacro outline-depth
()
1356 "Like outline-current-depth, but respects hidden as well as visible topics."
1358 (if (outline-goto-prefix)
1359 (outline-recent-depth)
1361 ;; Oops, no prefix, zero prefix data:
1362 (outline-prefix-data (point)(point))
1363 ;; ... and return 0:
1365 ;;;_ > outline-current-depth ()
1366 (defmacro outline-current-depth
()
1367 "Return nesting depth of visible topic most immediately containing point."
1369 (if (outline-back-to-current-heading)
1371 (- outline-recent-prefix-end
1372 outline-recent-prefix-beginning
1373 outline-header-subtraction
))
1375 ;;;_ > outline-get-current-prefix ()
1376 (defun outline-get-current-prefix ()
1377 "Topic prefix of the current topic."
1379 (if (outline-goto-prefix)
1380 (outline-recent-prefix))))
1381 ;;;_ > outline-get-bullet ()
1382 (defun outline-get-bullet ()
1383 "Return bullet of containing topic (visible or not)."
1385 (and (outline-goto-prefix)
1386 (outline-recent-bullet))))
1387 ;;;_ > outline-current-bullet ()
1388 (defun outline-current-bullet ()
1389 "Return bullet of current (visible) topic heading, or none if none found."
1392 (outline-back-to-current-heading)
1393 (buffer-substring (- outline-recent-prefix-end
1)
1394 outline-recent-prefix-end
))
1395 ;; Quick and dirty provision, ostensibly for missing bullet:
1396 (args-out-of-range nil
))
1398 ;;;_ > outline-get-prefix-bullet (prefix)
1399 (defun outline-get-prefix-bullet (prefix)
1400 "Return the bullet of the header prefix string PREFIX."
1401 ;; Doesn't make sense if we're old-style prefixes, but this just
1402 ;; oughtn't be called then, so forget about it...
1403 (if (string-match outline-regexp prefix
)
1404 (substring prefix
(1- (match-end 0)) (match-end 0))))
1406 ;;;_ - Navigation macros
1407 ;;;_ > outline-next-heading ()
1408 (defmacro outline-next-heading
()
1409 "Move to the heading for the topic \(possibly invisible) before this one.
1411 Returns the location of the heading, or nil if none found."
1413 '(if (and (bobp) (not (eobp)))
1416 '(if (re-search-forward outline-line-boundary-regexp nil
0)
1417 (progn ; Got valid location state - set vars:
1418 (outline-prefix-data
1419 (goto-char (or (match-beginning 2)
1420 outline-recent-prefix-beginning
))
1421 (or (match-end 2) outline-recent-prefix-end
)))))
1422 ;;;_ : outline-this-or-next-heading
1423 (defun outline-this-or-next-heading ()
1424 "Position cursor on current or next heading."
1425 ;; A throwaway non-macro that is defined after outline-next-heading
1426 ;; and usable by outline-mode.
1427 (if (not (outline-goto-prefix)) (outline-next-heading)))
1428 ;;;_ > outline-previous-heading ()
1429 (defmacro outline-previous-heading
()
1430 "Move to the prior \(possibly invisible) heading line.
1432 Return the location of the beginning of the heading, or nil if not found."
1436 (outline-goto-prefix)
1438 ;; searches are unbounded and return nil if failed:
1439 (or (re-search-backward outline-line-boundary-regexp nil
0)
1440 (looking-at outline-bob-regexp
))
1441 (progn ; Got valid location state - set vars:
1442 (outline-prefix-data
1443 (goto-char (or (match-beginning 2)
1444 outline-recent-prefix-beginning
))
1445 (or (match-end 2) outline-recent-prefix-end
))))))
1447 ;;;_ - Subtree Charting
1448 ;;;_ " These routines either produce or assess charts, which are
1449 ;;; nested lists of the locations of topics within a subtree.
1451 ;;; Use of charts enables efficient navigation of subtrees, by
1452 ;;; requiring only a single regexp-search based traversal, to scope
1453 ;;; out the subtopic locations. The chart then serves as the basis
1454 ;;; for whatever assessment or adjustment of the subtree that is
1455 ;;; required, without requiring redundant topic-traversal procedures.
1457 ;;;_ > outline-chart-subtree (&optional levels orig-depth prev-depth)
1458 (defun outline-chart-subtree (&optional levels orig-depth prev-depth
)
1459 "Produce a location \"chart\" of subtopics of the containing topic.
1461 Optional argument LEVELS specifies the depth \(relative to start
1462 depth\) for the chart. Subsequent optional args are not for public
1465 Charts are used to capture outline structure, so that outline-altering
1466 routines need assess the structure only once, and then use the chart
1467 for their elaborate manipulations.
1469 Topics are entered in the chart so the last one is at the car.
1470 The entry for each topic consists of an integer indicating the point
1471 at the beginning of the topic. Charts for offspring consists of a
1472 list containing, recursively, the charts for the respective subtopics.
1473 The chart for a topics' offspring precedes the entry for the topic
1476 The other function parameters are for internal recursion, and should
1477 not be specified by external callers. ORIG-DEPTH is depth of topic at
1478 starting point, and PREV-DEPTH is depth of prior topic."
1480 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
1483 (if original
; Just starting?
1484 ; Register initial settings and
1485 ; position to first offspring:
1486 (progn (setq orig-depth
(outline-depth))
1487 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
1488 (outline-next-heading)))
1490 ;; Loop over the current levels' siblings. Besides being more
1491 ;; efficient than tail-recursing over a level, it avoids exceeding
1492 ;; the typically quite constrained emacs max-lisp-eval-depth.
1493 ;; Probably would speed things up to implement loop-based stack
1494 ;; operation rather than recursing for lower levels. Bah.
1495 (while (and (not (eobp))
1496 ; Still within original topic?
1497 (< orig-depth
(setq curr-depth
(outline-recent-depth)))
1498 (cond ((= prev-depth curr-depth
)
1499 ;; Register this one and move on:
1500 (setq chart
(cons (point) chart
))
1501 (if (and levels
(<= levels
1))
1502 ;; At depth limit - skip sublevels:
1503 (or (outline-next-sibling curr-depth
)
1504 ;; or no more siblings - proceed to
1505 ;; next heading at lesser depth:
1506 (while (and (<= curr-depth
1507 (outline-recent-depth))
1508 (outline-next-heading))))
1509 (outline-next-heading)))
1511 ((and (< prev-depth curr-depth
)
1514 ;; Recurse on deeper level of curr topic:
1516 (cons (outline-chart-subtree (and levels
1521 ;; ... then continue with this one.
1524 ;; ... else nil if we've ascended back to prev-depth.
1528 (if original
; We're at the last sibling on
1529 ; the original level. Position
1531 (progn (and (not (eobp)) (forward-char -
1))
1532 (and (memq (preceding-char) '(?
\n ?\^M
))
1533 (memq (aref (buffer-substring (max 1 (- (point) 3))
1538 (setq outline-recent-end-of-subtree
(point))))
1540 chart
; (nreverse chart) not necessary,
1541 ; and maybe not preferable.
1543 ;;;_ > outline-chart-siblings (&optional start end)
1544 (defun outline-chart-siblings (&optional start end
)
1545 "Produce a list of locations of this and succeeding sibling topics.
1546 Effectively a top-level chart of siblings. See `outline-chart-subtree'
1547 for an explanation of charts."
1549 (if (outline-goto-prefix)
1550 (let ((chart (list (point))))
1551 (while (outline-next-sibling)
1552 (setq chart
(cons (point) chart
)))
1553 (if chart
(setq chart
(nreverse chart
)))))))
1554 ;;;_ > outline-chart-to-reveal (chart depth)
1555 (defun outline-chart-to-reveal (chart depth
)
1557 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
1559 Note that point can be left at any of the points on chart, or at the
1563 (while (and (or (eq depth t
) (> depth
0))
1565 (setq here
(car chart
))
1567 (let ((further (outline-chart-to-reveal here
(or (eq depth t
)
1569 ;; We're on the start of a subtree - recurse with it, if there's
1570 ;; more depth to go:
1571 (if further
(setq result
(append further result
)))
1572 (setq chart
(cdr chart
)))
1574 (if (= (preceding-char) ?
\r)
1575 (setq result
(cons here result
)))
1576 (setq chart
(cdr chart
))))
1578 ;;;_ X outline-chart-spec (chart spec &optional exposing)
1579 (defun outline-chart-spec (chart spec
&optional exposing
)
1580 "Not yet \(if ever\) implemented.
1582 Produce exposure directives given topic/subtree CHART and an exposure SPEC.
1584 Exposure spec indicates the locations to be exposed and the prescribed
1585 exposure status. Optional arg EXPOSING is an integer, with 0
1586 indicating pending concealment, anything higher indicating depth to
1587 which subtopic headers should be exposed, and negative numbers
1588 indicating (negative of) the depth to which subtopic headers and
1589 bodies should be exposed.
1591 The produced list can have two types of entries. Bare numbers
1592 indicate points in the buffer where topic headers that should be
1595 - bare negative numbers indicates that the topic starting at the
1596 point which is the negative of the number should be opened,
1597 including their entries.
1598 - bare positive values indicate that this topic header should be
1600 - Lists signify the beginning and end points of regions that should
1601 be flagged, and the flag to employ. (For concealment: `\(\?r\)', and
1607 (setq spec
(cdr spec
)))
1611 ;;;_ > outline-goto-prefix ()
1612 (defun outline-goto-prefix ()
1613 "Put point at beginning of outline prefix for immediately containing topic.
1615 Goes to first subsequent topic if none immediately containing.
1617 Not sensitive to topic visibility.
1619 Returns a the point at the beginning of the prefix, or nil if none."
1622 (while (and (not done
)
1623 (re-search-backward "[\n\r]" nil
1))
1625 (if (looking-at outline-regexp
)
1626 (setq done
(outline-prefix-data (match-beginning 0)
1630 (cond ((looking-at outline-regexp
)
1631 (outline-prefix-data (match-beginning 0)(match-end 0)))
1632 ((outline-next-heading)
1633 (outline-prefix-data (match-beginning 0)(match-end 0)))
1636 ;;;_ > outline-end-of-prefix ()
1637 (defun outline-end-of-prefix (&optional ignore-decorations
)
1638 "Position cursor at beginning of header text.
1640 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
1641 otherwise skip white space between bullet and ensuing text."
1643 (if (not (outline-goto-prefix))
1645 (let ((match-data (match-data)))
1646 (goto-char (match-end 0))
1647 (if ignore-decorations
1649 (while (looking-at "[0-9]") (forward-char 1))
1650 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))
1651 (set-match-data match-data
))
1652 ;; Reestablish where we are:
1653 (outline-current-depth)))
1654 ;;;_ > outline-current-bullet-pos ()
1655 (defun outline-current-bullet-pos ()
1656 "Return position of current \(visible) topic's bullet."
1658 (if (not (outline-current-depth))
1660 (1- (match-end 0))))
1661 ;;;_ > outline-back-to-current-heading ()
1662 (defun outline-back-to-current-heading ()
1663 "Move to heading line of current topic, or beginning if already on the line."
1666 (prog1 (or (outline-on-current-heading-p)
1667 (and (re-search-backward (concat "^\\(" outline-regexp
"\\)")
1670 (outline-prefix-data (match-beginning 1)(match-end 1))))
1671 (if (interactive-p) (outline-end-of-prefix))))
1672 ;;;_ > outline-pre-next-preface ()
1673 (defun outline-pre-next-preface ()
1674 "Skip forward to just before the next heading line.
1676 Returns that character position."
1678 (if (re-search-forward outline-line-boundary-regexp nil
'move
)
1679 (prog1 (goto-char (match-beginning 0))
1680 (outline-prefix-data (match-beginning 2)(match-end 2)))))
1681 ;;;_ > outline-end-of-current-subtree ()
1682 (defun outline-end-of-current-subtree ()
1683 "Put point at the end of the last leaf in the currently visible topic."
1685 (outline-back-to-current-heading)
1686 (let ((level (outline-recent-depth)))
1687 (outline-next-heading)
1688 (while (and (not (eobp))
1689 (> (outline-recent-depth) level
))
1690 (outline-next-heading))
1691 (and (not (eobp)) (forward-char -
1))
1692 (and (memq (preceding-char) '(?
\n ?\^M
))
1693 (memq (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1)
1696 (setq outline-recent-end-of-subtree
(point))))
1697 ;;;_ > outline-beginning-of-current-entry ()
1698 (defun outline-beginning-of-current-entry ()
1699 "When not already there, position point at beginning of current topic's body.
1701 If already there, move cursor to bullet for hot-spot operation.
1702 \(See outline-mode doc string for details on hot-spot operation.)"
1704 (let ((start-point (point)))
1705 (outline-end-of-prefix)
1706 (if (and (interactive-p)
1707 (= (point) start-point
))
1708 (goto-char (outline-current-bullet-pos)))))
1709 ;;;_ > outline-end-of-current-entry ()
1710 (defun outline-end-of-current-entry ()
1711 "Position the point at the end of the current topics' entry."
1713 (outline-show-entry)
1714 (prog1 (outline-pre-next-preface)
1715 (if (and (not (bobp))(looking-at "^$"))
1716 (forward-char -
1))))
1719 ;;;_ > outline-ascend-to-depth (depth)
1720 (defun outline-ascend-to-depth (depth)
1721 "Ascend to depth DEPTH, returning depth if successful, nil if not."
1722 (if (and (> depth
0)(<= depth
(outline-depth)))
1723 (let ((last-good (point)))
1724 (while (and (< depth
(outline-depth))
1725 (setq last-good
(point))
1726 (outline-beginning-of-level)
1727 (outline-previous-heading)))
1728 (if (= (outline-recent-depth) depth
)
1729 (progn (goto-char outline-recent-prefix-beginning
)
1731 (goto-char last-good
)
1733 (if (interactive-p) (outline-end-of-prefix))))
1734 ;;;_ > outline-descend-to-depth (depth)
1735 (defun outline-descend-to-depth (depth)
1736 "Descend to depth DEPTH within current topic.
1738 Returning depth if successful, nil if not."
1739 (let ((start-point (point))
1740 (start-depth (outline-depth)))
1742 (and (> (outline-depth) 0)
1743 (not (= depth
(outline-recent-depth))) ; ... not there yet
1744 (outline-next-heading) ; ... go further
1745 (< start-depth
(outline-recent-depth)))) ; ... still in topic
1746 (if (and (> (outline-depth) 0)
1747 (= (outline-recent-depth) depth
))
1749 (goto-char start-point
)
1752 ;;;_ > outline-up-current-level (arg &optional dont-complain)
1753 (defun outline-up-current-level (arg &optional dont-complain
)
1754 "Move out ARG levels from current visible topic.
1756 Positions on heading line of containing topic. Error if unable to
1757 ascend that far, or nil if unable to ascend but optional arg
1758 DONT-COMPLAIN is non-nil."
1760 (outline-back-to-current-heading)
1761 (let ((present-level (outline-recent-depth))
1765 ;; Loop for iterating arg:
1766 (while (and (> (outline-recent-depth) 1)
1770 (setq last-good
(point))
1771 ;; Loop for going back over current or greater depth:
1772 (while (and (not (< (outline-recent-depth) present-level
))
1773 (or (outline-previous-visible-heading 1)
1774 (not (setq failed present-level
)))))
1775 (setq present-level
(outline-current-depth))
1776 (setq arg
(- arg
1)))
1779 (progn (goto-char last-good
)
1780 (if (interactive-p) (outline-end-of-prefix))
1781 (if (not dont-complain
)
1782 (error "Can't ascend past outermost level.")
1783 (if (interactive-p) (outline-end-of-prefix))
1785 (if (interactive-p) (outline-end-of-prefix))
1786 outline-recent-prefix-beginning
)))
1789 ;;;_ > outline-next-sibling (&optional depth backward)
1790 (defun outline-next-sibling (&optional depth backward
)
1791 "Like outline-forward-current-level, but respects invisible topics.
1793 Traverse at optional DEPTH, or current depth if none specified.
1795 Go backward if optional arg BACKWARD is non-nil.
1797 Return depth if successful, nil otherwise."
1799 (if (and backward
(bobp))
1801 (let ((start-depth (or depth
(outline-depth)))
1802 (start-point (point))
1804 (while (and (not (if backward
(bobp) (eobp)))
1805 (if backward
(outline-previous-heading)
1806 (outline-next-heading))
1807 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
1808 (if (and (not (eobp))
1809 (and (> (or last-depth
(outline-depth)) 0)
1810 (= (outline-recent-depth) start-depth
)))
1811 outline-recent-prefix-beginning
1812 (goto-char start-point
)
1813 (if depth
(outline-depth) start-depth
)
1815 ;;;_ > outline-previous-sibling (&optional depth backward)
1816 (defun outline-previous-sibling (&optional depth backward
)
1817 "Like outline-forward-current-level,but backwards & respect invisible topics.
1819 Optional DEPTH specifies depth to traverse, default current depth.
1821 Optional BACKWARD reverses direction.
1823 Return depth if successful, nil otherwise."
1824 (outline-next-sibling depth
(not backward
))
1826 ;;;_ > outline-snug-back ()
1827 (defun outline-snug-back ()
1828 "Position cursor at end of previous topic
1830 Presumes point is at the start of a topic prefix."
1831 (if (or (bobp) (eobp))
1834 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?\^M
))))
1837 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?\^M
))))
1840 ;;;_ > outline-beginning-of-level ()
1841 (defun outline-beginning-of-level ()
1842 "Go back to the first sibling at this level, visible or not."
1843 (outline-end-of-level 'backward
))
1844 ;;;_ > outline-end-of-level (&optional backward)
1845 (defun outline-end-of-level (&optional backward
)
1846 "Go to the last sibling at this level, visible or not."
1848 (let ((depth (outline-depth)))
1849 (while (outline-previous-sibling depth nil
))
1850 (prog1 (outline-recent-depth)
1851 (if (interactive-p) (outline-end-of-prefix)))))
1852 ;;;_ > outline-next-visible-heading (arg)
1853 (defun outline-next-visible-heading (arg)
1854 "Move to the next ARG'th visible heading line, backward if arg is negative.
1856 Move as far as possible in indicated direction \(beginning or end of
1857 buffer\) if headings are exhausted."
1860 (let* ((backward (if (< arg
0) (setq arg
(* -
1 arg
))))
1861 (step (if backward -
1 1))
1862 (start-point (point))
1865 (while (> arg
0) ; limit condition
1866 (while (and (not (if backward
(bobp)(eobp))) ; boundary condition
1867 ;; Move, skipping over all those concealed lines:
1868 (< -
1 (forward-line step
))
1869 (not (setq got
(looking-at outline-regexp
)))))
1870 ;; Register this got, it may be the last:
1871 (if got
(setq prev got
))
1872 (setq arg
(1- arg
)))
1873 (cond (got ; Last move was to a prefix:
1874 (outline-prefix-data (match-beginning 0) (match-end 0))
1875 (outline-end-of-prefix))
1876 (prev ; Last move wasn't, but prev was:
1877 (outline-prefix-data (match-beginning 0) (match-end 0)))
1878 ((not backward
) (end-of-line) nil
))))
1879 ;;;_ > outline-previous-visible-heading (arg)
1880 (defun outline-previous-visible-heading (arg)
1881 "Move to the previous heading line.
1883 With argument, repeats or can move forward if negative.
1884 A heading line is one that starts with a `*' (or that outline-regexp
1887 (outline-next-visible-heading (- arg
)))
1888 ;;;_ > outline-forward-current-level (arg)
1889 (defun outline-forward-current-level (arg)
1890 "Position point at the next heading of the same level.
1892 Takes optional repeat-count, goes backward if count is negative.
1894 Returns resulting position, else nil if none found."
1896 (let ((start-depth (outline-current-depth))
1897 (start-point (point))
1899 (backward (> 0 arg
))
1903 (if (= 0 start-depth
)
1904 (error "No siblings, not in a topic..."))
1905 (if backward
(setq arg
(* -
1 arg
)))
1906 (while (not (or (zerop arg
)
1908 (while (and (not (if backward
(bobp) (eobp)))
1909 (if backward
(outline-previous-visible-heading 1)
1910 (outline-next-visible-heading 1))
1911 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
1912 (if (and last-depth
(= last-depth start-depth
)
1913 (not (if backward
(bobp) (eobp))))
1914 (setq last-good
(point)
1916 (setq at-boundary t
)))
1917 (if (and (not (eobp))
1919 (and (> (or last-depth
(outline-depth)) 0)
1920 (= (outline-recent-depth) start-depth
)))
1921 outline-recent-prefix-beginning
1922 (goto-char last-good
)
1923 (if (not (interactive-p))
1925 (outline-end-of-prefix)
1926 (error "Hit %s level %d topic, traversed %d of %d requested."
1927 (if backward
"first" "last")
1928 (outline-recent-depth)
1929 (- (abs start-arg
) arg
)
1930 (abs start-arg
))))))
1931 ;;;_ > outline-backward-current-level (arg)
1932 (defun outline-backward-current-level (arg)
1933 "Inverse of `outline-forward-current-level'."
1936 (let ((current-prefix-arg (* -
1 arg
)))
1937 (call-interactively 'outline-forward-current-level
))
1938 (outline-forward-current-level (* -
1 arg
))))
1943 ;;;_ > outline-before-change-protect (beg end)
1944 (defun outline-before-change-protect (beg end
)
1945 "Outline before-change hook, regulates changes to concealed text.
1947 Reveal concealed text that would be changed by current command, and
1948 offer user choice to commit or forego the change. Unchanged text is
1949 reconcealed. User has option to have changed text reconcealed.
1951 Undo commands are specially treated - the user is not prompted for
1952 choice, the undoes are always committed (based on presumption that the
1953 things being undone were already subject to this regulation routine),
1954 and undoes always leave the changed stuff exposed.
1956 Changes to concealed regions are ignored while file is being written.
1957 \(This is for the sake of functions that do change the file during
1958 writes, like crypt and zip modes.)
1960 Locally bound in outline buffers to `before-change-function', which
1961 in emacs 19 is run before any change to the buffer. (Has no effect
1962 in Emacs 18, which doesn't support before-change-function.)
1964 Any functions which set [`this-command' to `undo', or which set]
1965 `outline-override-protect' non-nil (as does, eg, outline-flag-chars)
1966 are exempt from this restriction."
1967 (if (and (outline-mode-p)
1968 ; outline-override-protect
1969 ; set by functions that know what
1970 ; they're doing, eg outline internals:
1971 (not outline-override-protect
)
1972 (not outline-during-write-cue
)
1973 (save-match-data ; Preserve operation position state.
1974 ; Both beginning and end chars must
1976 (save-excursion (if (memq this-command
'(newline open-line
))
1977 ;; Compensate for stupid emacs {new,
1978 ;; open-}line display optimization:
1982 (or (outline-hidden-p)
1983 (and (not (= beg end
))
1985 (outline-hidden-p))))))
1987 (if (equal this-command
'undo
)
1988 ;; Allow undo without inhibition.
1989 ;; - Undoing new and open-line hits stupid emacs redisplay
1990 ;; optimization (em 19 cmds.c, ~ line 200).
1991 ;; - Presumably, undoing what was properly protected when
1993 ;; - Undo may be users' only recourse in protection faults.
1994 ;; So, expose what getting changed:
1995 (progn (message "Undo! - exposing concealed target...")
1996 (if (outline-hidden-p)
1997 (outline-show-children))
2000 (rehide-completely (save-excursion (outline-goto-prefix)
2001 (outline-hidden-p)))
2005 (if (condition-case err
2006 ;; Condition case to catch keyboard quits during reads.
2008 ; Give them a peek where
2010 (if (eolp) (setq rehide-place
2011 (outline-goto-prefix)))
2012 (outline-show-entry))
2013 ; Present the message, but...
2014 ; leave the cursor at the location
2015 ; until they respond:
2016 ; Then interpret the response:
2019 (message (concat "Change inside concealed"
2021 "(n or 'y'/'r'eclose)"))
2022 (setq response
(read-char))
2024 (cond ((memq response
'(?r ?R
))
2025 (setq response
'reclose
))
2026 ((memq response
'(?y ?Y ?
))
2028 ((memq response
'(?n ?N
127))
2033 "`r' means `yes, then reclose'")
2035 (t (message "Please answer y, n, or r")
2041 (if (eq response
'reclose
)
2043 (if rehide-place
(goto-char rehide-place
))
2044 (if rehide-completely
2045 (outline-hide-current-entry-completely)
2046 (outline-hide-current-entry)))
2047 (if (outline-ascend-to-depth (1- (outline-recent-depth)))
2048 (outline-show-children)
2049 (outline-show-to-offshoot)))
2051 (if rehide-completely
2053 (if rehide-place
(goto-char rehide-place
))
2054 (outline-hide-current-entry-completely))
2055 (outline-hide-current-entry))
2057 "Change within concealed region prevented.")))))))
2060 ;;;_ = outline-post-goto-bullet
2061 (defvar outline-post-goto-bullet nil
2062 "Outline internal var, for `outline-pre-command-business' hot-spot operation.
2064 When set, tells post-processing to reposition on topic bullet, and
2065 then unset it. Set by outline-pre-command-business when implementing
2066 hot-spot operation, where literal characters typed over a topic bullet
2067 are mapped to the command of the corresponding control-key on the
2069 (make-variable-buffer-local 'outline-post-goto-bullet
)
2070 ;;;_ > outline-post-command-business ()
2071 (defun outline-post-command-business ()
2072 "Outline post-command-hook function.
2074 - Null outline-override-protect, so it's not left open.
2076 - Implement (and clear) outline-post-goto-bullet, for hot-spot
2079 - Massages buffer-undo-list so successive, standard character self-inserts are
2080 aggregated. This kludge compensates for lack of undo bunching when
2081 before-change-function is used."
2083 ; Apply any external change func:
2084 (if (not (outline-mode-p)) ; In outline-mode.
2086 (setq outline-override-protect nil
)
2087 (if outline-during-write-cue
2088 ;; Was used by outline-before-change-protect, done with it now:
2089 (setq outline-during-write-cue nil
))
2090 ;; Undo bunching business:
2091 (if (and (listp buffer-undo-list
) ; Undo history being kept.
2092 (equal this-command
'self-insert-command
)
2093 (equal last-command
'self-insert-command
))
2094 (let* ((prev-stuff (cdr buffer-undo-list
))
2095 (before-prev-stuff (cdr (cdr prev-stuff
)))
2096 cur-cell cur-from cur-to
2097 prev-cell prev-from prev-to
)
2098 (if (and before-prev-stuff
; Goes back far enough to bother,
2099 (not (car prev-stuff
)) ; and break before current,
2100 (not (car before-prev-stuff
)) ; !and break before prev!
2101 (setq prev-cell
(car (cdr prev-stuff
))) ; contents now,
2102 (setq cur-cell
(car buffer-undo-list
)) ; contents prev.
2104 ;; cur contents denote a single char insertion:
2105 (numberp (setq cur-from
(car cur-cell
)))
2106 (numberp (setq cur-to
(cdr cur-cell
)))
2107 (= 1 (- cur-to cur-from
))
2109 ;; prev contents denote fewer than aggregate-limit
2111 (numberp (setq prev-from
(car prev-cell
)))
2112 (numberp (setq prev-to
(cdr prev-cell
)))
2114 (> outline-undo-aggregation
(- prev-to prev-from
)))
2115 (setq buffer-undo-list
2116 (cons (cons prev-from cur-to
)
2117 (cdr (cdr (cdr buffer-undo-list
))))))))
2118 ;; Implement -post-goto-bullet, if set: (must be after undo business)
2119 (if (and outline-post-goto-bullet
2120 (outline-current-bullet-pos))
2121 (progn (goto-char (outline-current-bullet-pos))
2122 (setq outline-post-goto-bullet nil
)))
2124 ;;;_ > outline-pre-command-business ()
2125 (defun outline-pre-command-business ()
2126 "Outline pre-command-hook function for outline buffers.
2128 Implements special behavior when cursor is on bullet char.
2130 Self-insert characters are reinterpreted control-character references
2131 into the outline-mode-map. The outline-mode post-command hook will
2132 position a cursor that has moved as a result of such reinterpretation,
2133 on the destination topic's bullet, when the cursor wound up in the
2135 The upshot is that you can get easy, single (unmodified) key outline
2136 maneuvering and general operations by positioning the cursor on the
2137 bullet char, and it continues until you deliberately some non-outline
2138 motion command to relocate the cursor off of a bullet char."
2140 (if (and (boundp 'outline-mode
)
2142 (eq this-command
'self-insert-command
)
2143 (eq (point)(outline-current-bullet-pos)))
2145 (let* ((this-key-num (if (numberp last-command-event
)
2146 last-command-event
))
2149 ; Map upper-register literals
2150 ; to lower register:
2151 (if (<= 96 this-key-num
)
2152 (setq this-key-num
(- this-key-num
32)))
2153 ; Check if we have a literal:
2154 (if (and (<= 64 this-key-num
)
2155 (>= 96 this-key-num
))
2156 (setq mapped-binding
2157 (lookup-key 'outline-mode-map
2158 (concat outline-command-prefix
2159 (char-to-string (- this-key-num
64))))))
2161 (setq outline-post-goto-bullet t
2162 this-command mapped-binding
)))))
2163 ;;;_ > outline-find-file-hook ()
2164 (defun outline-find-file-hook ()
2165 "Activate outline-mode when `outline-auto-activation' & `outline-layout' are non-nil.
2167 See `outline-init' for setup instructions."
2168 (if (and outline-auto-activation
2169 (not (outline-mode-p))
2172 ;;;_ : Establish the hooks
2173 (add-hook 'post-command-hook
'outline-post-command-business
)
2174 (add-hook 'pre-command-hook
'outline-pre-command-business
)
2176 ;;;_ - Topic Format Assessment
2177 ;;;_ > outline-solicit-alternate-bullet (depth &optional current-bullet)
2178 (defun outline-solicit-alternate-bullet (depth &optional current-bullet
)
2180 "Prompt for and return a bullet char as an alternative to the current one.
2182 Offer one suitable for current depth DEPTH as default."
2184 (let* ((default-bullet (or current-bullet
2185 (outline-bullet-for-depth depth
)))
2186 (sans-escapes (regexp-sans-escapes outline-bullets-string
))
2187 (choice (solicit-char-in-string
2188 (format "Select bullet: %s ('%s' default): "
2193 (if (string= choice
"") default-bullet choice
))
2195 ;;;_ > outline-sibling-index (&optional depth)
2196 (defun outline-sibling-index (&optional depth
)
2197 "Item number of this prospective topic among its siblings.
2199 If optional arg depth is greater than current depth, then we're
2200 opening a new level, and return 0.
2202 If less than this depth, ascend to that depth and count..."
2205 (cond ((and depth
(<= depth
0) 0))
2206 ((or (not depth
) (= depth
(outline-depth)))
2208 (while (outline-previous-sibling (outline-recent-depth) nil
)
2209 (setq index
(1+ index
)))
2211 ((< depth
(outline-recent-depth))
2212 (outline-ascend-to-depth depth
)
2213 (outline-sibling-index))
2215 ;;;_ > outline-distinctive-bullet (bullet)
2216 (defun outline-distinctive-bullet (bullet)
2217 "True if bullet is one of those on outline-distinctive-bullets-string."
2218 (string-match (regexp-quote bullet
) outline-distinctive-bullets-string
))
2219 ;;;_ > outline-numbered-type-prefix (&optional prefix)
2220 (defun outline-numbered-type-prefix (&optional prefix
)
2221 "True if current header prefix bullet is numbered bullet."
2222 (and outline-numbered-bullet
2223 (string= outline-numbered-bullet
2225 (outline-get-prefix-bullet prefix
)
2226 (outline-get-bullet)))))
2227 ;;;_ > outline-bullet-for-depth (&optional depth)
2228 (defun outline-bullet-for-depth (&optional depth
)
2229 "Return outline topic bullet suited to optional DEPTH, or current depth."
2230 ;; Find bullet in plain-bullets-string modulo DEPTH.
2231 (if outline-stylish-prefixes
2232 (char-to-string (aref outline-plain-bullets-string
2233 (%
(max 0 (- depth
2))
2234 outline-plain-bullets-string-len
)))
2235 outline-primary-bullet
)
2238 ;;;_ - Topic Production
2239 ;;;_ > outline-make-topic-prefix (&optional prior-bullet
2240 (defun outline-make-topic-prefix (&optional prior-bullet
2246 ;; Depth null means use current depth, non-null means we're either
2247 ;; opening a new topic after current topic, lower or higher, or we're
2248 ;; changing level of current topic.
2249 ;; Solicit dominates specified bullet-char.
2251 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
2253 All the arguments are optional.
2255 PRIOR-BULLET indicates the bullet of the prefix being changed, or
2256 nil if none. This bullet may be preserved (other options
2257 notwithstanding) if it is on the outline-distinctive-bullets-string,
2260 Second arg NEW indicates that a new topic is being opened after the
2261 topic at point, if non-nil. Default bullet for new topics, eg, may
2262 be set (contingent to other args) to numbered bullets if previous
2263 sibling is one. The implication otherwise is that the current topic
2264 is being adjusted - shifted or rebulleted - and we don't consider
2265 bullet or previous sibling.
2267 Third arg DEPTH forces the topic prefix to that depth, regardless of
2268 the current topics' depth.
2270 Fourth arg SOLICIT non-nil provokes solicitation from the user of a
2271 choice among the valid bullets. (This overrides other all the
2272 options, including, eg, a distinctive PRIOR-BULLET.)
2274 Fifth arg, NUMBER-CONTROL, matters only if `outline-numbered-bullet'
2275 is non-nil *and* soliciting was not explicitly invoked. Then
2276 NUMBER-CONTROL non-nil forces prefix to either numbered or
2277 denumbered format, depending on the value of the sixth arg, INDEX.
2279 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
2281 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
2282 the prefix of the topic is forced to be numbered. Non-nil
2283 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
2284 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
2285 that the index for the numbered prefix will be derived, by counting
2286 siblings back to start of level. If INDEX is a number, then that
2287 number is used as the index for the numbered prefix (allowing, eg,
2288 sequential renumbering to not require this function counting back the
2289 index for each successive sibling)."
2291 ;; The options are ordered in likely frequence of use, most common
2292 ;; highest, least lowest. Ie, more likely to be doing prefix
2293 ;; adjustments than soliciting, and yet more than numbering.
2294 ;; Current prefix is least dominant, but most likely to be commonly
2300 (depth (or depth
(outline-depth)))
2301 (header-lead outline-header-prefix
)
2304 ;; Getting value for bullet char is practically the whole job:
2307 ; Simplest situation - level 1:
2308 ((<= depth
1) (setq header-lead
"") outline-primary-bullet
)
2309 ; Simple, too: all asterisks:
2310 (outline-old-style-prefixes
2311 ;; Cheat - make body the whole thing, null out header-lead and
2313 (setq body
(make-string depth
2314 (string-to-char outline-primary-bullet
)))
2315 (setq header-lead
"")
2318 ;; (Neither level 1 nor old-style, so we're space padding.
2319 ;; Sneak it in the condition of the next case, whatever it is.)
2321 ;; Solicitation overrides numbering and other cases:
2322 ((progn (setq body
(make-string (- depth
2) ?\
))
2323 ;; The actual condition:
2325 (let* ((got (outline-solicit-alternate-bullet depth
)))
2326 ;; Gotta check whether we're numbering and got a numbered bullet:
2327 (setq numbering
(and outline-numbered-bullet
2328 (not (and number-control
(not index
)))
2329 (string= got outline-numbered-bullet
)))
2330 ;; Now return what we got, regardless:
2333 ;; Numbering invoked through args:
2334 ((and outline-numbered-bullet number-control
)
2335 (if (setq numbering
(not (setq denumbering
(not index
))))
2336 outline-numbered-bullet
2337 (if (and prior-bullet
2338 (not (string= outline-numbered-bullet
2341 (outline-bullet-for-depth depth
))))
2343 ;;; Neither soliciting nor controlled numbering ;;;
2344 ;;; (may be controlled denumbering, tho) ;;;
2346 ;; Check wrt previous sibling:
2347 ((and new
; only check for new prefixes
2348 (<= depth
(outline-depth))
2349 outline-numbered-bullet
; ... & numbering enabled
2351 (let ((sibling-bullet
2353 ;; Locate correct sibling:
2354 (or (>= depth
(outline-depth))
2355 (outline-ascend-to-depth depth
))
2356 (outline-get-bullet))))
2357 (if (and sibling-bullet
2358 (string= outline-numbered-bullet sibling-bullet
))
2359 (setq numbering sibling-bullet
)))))
2361 ;; Distinctive prior bullet?
2363 (outline-distinctive-bullet prior-bullet
)
2364 ;; Either non-numbered:
2365 (or (not (and outline-numbered-bullet
2366 (string= prior-bullet outline-numbered-bullet
)))
2367 ;; or numbered, and not denumbering:
2368 (setq numbering
(not denumbering
)))
2372 ;; Else, standard bullet per depth:
2373 ((outline-bullet-for-depth depth
)))))
2379 (format "%d" (cond ((and index
(numberp index
)) index
)
2380 (new (1+ (outline-sibling-index depth
)))
2381 ((outline-sibling-index))))))
2384 ;;;_ > outline-open-topic (relative-depth &optional before)
2385 (defun outline-open-topic (relative-depth &optional before
)
2386 "Open a new topic at depth DEPTH.
2388 New topic is situated after current one, unless optional flag BEFORE
2389 is non-nil, or unless current line is complete empty (not even
2390 whitespace), in which case open is done on current line.
2394 - Creation of new topics is with respect to the visible topic
2395 containing the cursor, regardless of intervening concealed ones.
2397 - New headers are generally created after/before the body of a
2398 topic. However, they are created right at cursor location if the
2399 cursor is on a blank line, even if that breaks the current topic
2400 body. This is intentional, to provide a simple means for
2401 deliberately dividing topic bodies.
2403 - Double spacing of topic lists is preserved. Also, the first
2404 level two topic is created double-spaced (and so would be
2405 subsequent siblings, if that's left intact). Otherwise,
2406 single-spacing is used.
2408 - Creation of sibling or nested topics is with respect to the topic
2409 you're starting from, even when creating backwards. This way you
2410 can easily create a sibling in front of the current topic without
2411 having to go to its preceding sibling, and then open forward
2414 (let* ((depth (+ (outline-current-depth) relative-depth
))
2415 (opening-on-blank (if (looking-at "^\$")
2416 (not (setq before nil
))))
2417 opening-numbered
; Will get while computing ref-topic, below
2418 ref-depth
; Will get while computing ref-topic, next
2419 (ref-topic (save-excursion
2420 (cond ((< relative-depth
0)
2421 (outline-ascend-to-depth depth
))
2422 ((>= relative-depth
1) nil
)
2423 (t (outline-back-to-current-heading)))
2424 (setq ref-depth
(outline-recent-depth))
2425 (setq opening-numbered
2427 (and outline-numbered-bullet
2428 (or (<= relative-depth
0)
2429 (outline-descend-to-depth depth
))
2430 (if (outline-numbered-type-prefix)
2431 outline-numbered-bullet
))))
2436 (if (not opening-on-blank
)
2437 ; Positioning and vertical
2438 ; padding - only if not
2441 (goto-char ref-topic
)
2442 (setq dbl-space
; Determine double space action:
2443 (or (and (<= relative-depth
0) ; not descending;
2445 ;; at b-o-b or preceded by a blank line?
2446 (or (> 0 (forward-line -
1))
2447 (looking-at "^\\s-*$")
2450 ;; succeeded by a blank line?
2451 (outline-end-of-current-subtree)
2453 (and (= ref-depth
1)
2457 ;; Don't already have following
2458 ;; vertical padding:
2459 (not (outline-pre-next-preface)))))))
2461 ; Position to prior heading,
2462 ; if inserting backwards, and
2463 ; not going outwards:
2464 (if (and before
(>= relative-depth
0))
2465 (progn (outline-back-to-current-heading)
2466 (setq doing-beginning
(bobp))
2468 (outline-previous-heading)))
2469 (if (and before
(bobp))
2470 (outline-unprotected (open-line 1))))
2472 (if (<= relative-depth
0)
2473 ;; Not going inwards, don't snug up:
2475 (outline-unprotected (open-line (if dbl-space
2 1)))
2477 (progn (end-of-line)
2478 (outline-pre-next-preface)
2479 (while (= ?
\r (following-char))
2481 (if (not (looking-at "^$"))
2482 (outline-unprotected (open-line 1))))
2483 (outline-end-of-current-subtree)))
2484 ;; Going inwards - double-space if first offspring is,
2485 ;; otherwise snug up.
2486 (end-of-line) ; So we skip any concealed progeny.
2487 (outline-pre-next-preface)
2489 ;; Blank lines between current header body and next
2490 ;; header - get to last substantive (non-white-space)
2492 (re-search-backward "[^ \t\n]" nil t
))
2494 (outline-next-heading)
2495 (if (> (outline-recent-depth) ref-depth
)
2496 ;; This is an offspring.
2497 (progn (forward-line -
1)
2498 (looking-at "^\\s-*$"))))
2499 (progn (forward-line 1)
2500 (outline-unprotected (open-line 1))))
2502 ;;(if doing-beginning (goto-char doing-beginning))
2504 (progn (if (and (not (> depth ref-depth
))
2506 (outline-unprotected (open-line 1))
2507 (if (> depth ref-depth
)
2508 (outline-unprotected (newline 1))
2510 (outline-unprotected (open-line 1))
2512 (outline-unprotected (newline 1))))))
2514 (outline-unprotected (newline 1)))
2515 (if (and (not (eobp))
2519 (insert-string (concat (outline-make-topic-prefix opening-numbered
2524 ;;(if doing-beginning (save-excursion (newline (if dbl-space 2 1))))
2527 (outline-rebullet-heading nil
;;; solicit
2529 nil
;;; number-control
2534 ;;;_ . open-topic contingencies
2535 ;;;_ ; base topic - one from which open was issued
2536 ;;;_ , beginning char
2537 ;;;_ , amount of space before will be used, unless opening in place
2538 ;;;_ , end char will be used, unless opening before (and it still may)
2539 ;;;_ ; absolute depth of new topic
2540 ;;;_ ! insert in place - overrides most stuff
2541 ;;;_ ; relative depth of new re base
2542 ;;;_ ; before or after base topic
2543 ;;;_ ; spacing around topic, if any, prior to new topic and at same depth
2544 ;;;_ ; buffer boundaries - special provisions for beginning and end ob
2545 ;;;_ ; level 1 topics have special provisions also - double space.
2546 ;;;_ ; location of new topic
2548 ;;;_ > outline-open-subtopic (arg)
2549 (defun outline-open-subtopic (arg)
2550 "Open new topic header at deeper level than the current one.
2552 Negative universal arg means to open deeper, but place the new topic
2553 prior to the current one."
2555 (outline-open-topic 1 (> 0 arg
)))
2556 ;;;_ > outline-open-sibtopic (arg)
2557 (defun outline-open-sibtopic (arg)
2558 "Open new topic header at same level as the current one.
2560 Negative universal arg means to place the new topic prior to the current
2563 (outline-open-topic 0 (> 0 arg
)))
2564 ;;;_ > outline-open-supertopic (arg)
2565 (defun outline-open-supertopic (arg)
2566 "Open new topic header at shallower level than the current one.
2568 Negative universal arg means to open shallower, but place the new
2569 topic prior to the current one."
2572 (outline-open-topic -
1 (> 0 arg
)))
2574 ;;;_ - Outline Alteration
2575 ;;;_ : Topic Modification
2576 ;;;_ = outline-former-auto-filler
2577 (defvar outline-former-auto-filler nil
2578 "Name of modal fill function being wrapped by outline-auto-fill.")
2579 ;;;_ > outline-auto-fill ()
2580 (defun outline-auto-fill ()
2581 "Outline-mode autofill function.
2583 Maintains outline hanging topic indentation if
2584 `outline-use-hanging-indents' is set."
2585 (let ((fill-prefix (if outline-use-hanging-indents
2586 ;; Check for topic header indentation:
2589 (if (looking-at outline-regexp
)
2590 ;; ... construct indentation to account for
2591 ;; length of topic prefix:
2592 (make-string (progn (outline-end-of-prefix)
2595 (if (or outline-former-auto-filler outline-use-hanging-indents
)
2597 ;;;_ > outline-reindent-body (old-depth new-depth &optional number)
2598 (defun outline-reindent-body (old-depth new-depth
&optional number
)
2599 "Reindent body lines which were indented at old-depth to new-depth.
2601 Optional arg NUMBER indicates numbering is being added, and it must
2604 Note that refill of indented paragraphs is not done."
2607 (outline-end-of-prefix)
2608 (let* ((new-margin (current-column))
2609 excess old-indent-begin old-indent-end
2611 ;; We want the column where the header-prefix text started
2612 ;; *before* the prefix was changed, so we infer it relative
2613 ;; to the new margin and the shift in depth:
2614 (old-margin (+ old-depth
(- new-margin new-depth
))))
2616 ;; Process lines up to (but excluding) next topic header:
2617 (outline-unprotected
2620 (and (re-search-forward "[\n\r]\\(\\s-*\\)"
2623 ;; Register the indent data, before we reset the
2624 ;; match data with a subsequent `looking-at':
2625 (setq old-indent-begin
(match-beginning 1)
2626 old-indent-end
(match-end 1))
2627 (not (looking-at outline-regexp
)))
2628 (if (> 0 (setq excess
(- (current-column)
2630 ;; Text starts left of old margin - don't adjust:
2632 ;; Text was hanging at or right of old left margin -
2633 ;; reindent it, preserving its existing indentation
2634 ;; beyond the old margin:
2635 (delete-region old-indent-begin old-indent-end
)
2636 (indent-to (+ new-margin excess
)))))))))
2637 ;;;_ > outline-rebullet-current-heading (arg)
2638 (defun outline-rebullet-current-heading (arg)
2639 "Like non-interactive version `outline-rebullet-heading'.
2641 But \(only\) affects visible heading containing point.
2643 With repeat count, solicit for bullet."
2645 (save-excursion (outline-back-to-current-heading)
2646 (outline-end-of-prefix)
2647 (outline-rebullet-heading (not arg
) ;;; solicit
2649 nil
;;; number-control
2651 t
) ;;; do-successors
2654 ;;;_ > outline-rebullet-heading (&optional solicit ...)
2655 (defun outline-rebullet-heading (&optional solicit
2661 "Adjust bullet of current topic prefix.
2663 All args are optional.
2665 If SOLICIT is non-nil then the choice of bullet is solicited from
2666 user. Otherwise the distinctiveness of the bullet or the topic
2667 depth determines it.
2669 Second arg DEPTH forces the topic prefix to that depth, regardless
2670 of the topics current depth.
2672 Third arg NUMBER-CONTROL can force the prefix to or away from
2673 numbered form. It has effect only if `outline-numbered-bullet' is
2674 non-nil and soliciting was not explicitly invoked (via first arg).
2675 Its effect, numbering or denumbering, then depends on the setting
2676 of the forth arg, INDEX.
2678 If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the
2679 prefix of the topic is forced to be non-numbered. Null index and
2680 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
2681 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
2682 INDEX is a number, then that number is used for the numbered
2683 prefix. Non-nil and non-number means that the index for the
2684 numbered prefix will be derived by outline-make-topic-prefix.
2686 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
2689 Cf vars `outline-stylish-prefixes', `outline-old-style-prefixes',
2690 and `outline-numbered-bullet', which all affect the behavior of
2693 (let* ((current-depth (outline-depth))
2694 (new-depth (or new-depth current-depth
))
2695 (mb outline-recent-prefix-beginning
)
2696 (me outline-recent-prefix-end
)
2697 (current-bullet (buffer-substring (- me
1) me
))
2698 (new-prefix (outline-make-topic-prefix current-bullet
2705 ;; Is new one is identical to old?
2706 (if (and (= current-depth new-depth
)
2707 (string= current-bullet
2708 (substring new-prefix
(1- (length new-prefix
)))))
2712 ;; New prefix probably different from old:
2713 ; get rid of old one:
2714 (outline-unprotected (delete-region mb me
))
2716 ; Dispense with number if
2717 ; numbered-bullet prefix:
2718 (if (and outline-numbered-bullet
2719 (string= outline-numbered-bullet current-bullet
)
2720 (looking-at "[0-9]+"))
2721 (outline-unprotected
2722 (delete-region (match-beginning 0)(match-end 0))))
2724 ; Put in new prefix:
2725 (outline-unprotected (insert-string new-prefix
))
2727 ;; Reindent the body if elected and margin changed:
2728 (if (and outline-reindent-bodies
2729 (not (= new-depth current-depth
)))
2730 (outline-reindent-body current-depth new-depth
))
2732 ;; Recursively rectify successive siblings of orig topic if
2733 ;; caller elected for it:
2736 (while (outline-next-sibling new-depth nil
)
2738 (cond ((numberp index
) (1+ index
))
2739 ((not number-control
) (outline-sibling-index))))
2740 (if (outline-numbered-type-prefix)
2741 (outline-rebullet-heading nil
;;; solicit
2742 new-depth
;;; new-depth
2743 number-control
;;; number-control
2745 nil
))))) ;;;(dont!)do-successors
2746 ) ; (if (and (= current-depth new-depth)...))
2747 ) ; let* ((current-depth (outline-depth))...)
2749 ;;;_ > outline-rebullet-topic (arg)
2750 (defun outline-rebullet-topic (arg)
2751 "Like outline-rebullet-topic-grunt, but start from topic visible at point.
2753 Descends into invisible as well as visible topics, however.
2755 With repeat count, shift topic depth by that amount."
2757 (let ((start-col (current-column))
2761 (cond ((null arg
) (setq arg
0))
2762 ((listp arg
) (setq arg
(car arg
))))
2763 ;; Fill the user in, in case we're shifting a big topic:
2764 (if (not (zerop arg
)) (message "Shifting..."))
2765 (outline-back-to-current-heading)
2766 (if (<= (+ (outline-recent-depth) arg
) 0)
2767 (error "Attempt to shift topic below level 1"))
2768 (outline-rebullet-topic-grunt arg
)
2769 (if (not (zerop arg
)) (message "Shifting... done.")))
2770 (move-to-column (max 0 (+ start-col arg
)))))
2771 ;;;_ > outline-rebullet-topic-grunt (&optional relative-depth ...)
2772 (defun outline-rebullet-topic-grunt (&optional relative-depth
2778 "Rebullet the topic at point, visible or invisible, and all
2779 contained subtopics. See outline-rebullet-heading for rebulleting
2782 All arguments are optional.
2784 First arg RELATIVE-DEPTH means to shift the depth of the entire
2787 The rest of the args are for internal recursive use by the function
2788 itself. The are STARTING-DEPTH, STARTING-POINT, and INDEX."
2790 (let* ((relative-depth (or relative-depth
0))
2791 (new-depth (outline-depth))
2792 (starting-depth (or starting-depth new-depth
))
2793 (on-starting-call (null starting-point
))
2795 ;; Leave index null on starting call, so rebullet-heading
2796 ;; calculates it at what might be new depth:
2797 (and (or (zerop relative-depth
)
2798 (not on-starting-call
))
2799 (outline-sibling-index))))
2800 (moving-outwards (< 0 relative-depth
))
2801 (starting-point (or starting-point
(point))))
2803 ;; Sanity check for excessive promotion done only on starting call:
2804 (and on-starting-call
2806 (> 0 (+ starting-depth relative-depth
))
2807 (error "Attempt to shift topic out beyond level 1.")) ;;; ====>
2809 (cond ((= starting-depth new-depth
)
2810 ;; We're at depth to work on this one:
2811 (outline-rebullet-heading nil
;;; solicit
2812 (+ starting-depth
;;; starting-depth
2816 ;; Every contained topic will get hit,
2817 ;; and we have to get to outside ones
2819 nil
) ;;; do-successors
2820 ;; ... and work on subsequent ones which are at greater depth:
2822 (outline-next-heading)
2823 (while (and (not (eobp))
2824 (< starting-depth
(outline-recent-depth)))
2825 (setq index
(1+ index
))
2826 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
2827 (1+ starting-depth
);;;starting-depth
2828 starting-point
;;; starting-point
2831 ((< starting-depth new-depth
)
2832 ;; Rare case - subtopic more than one level deeper than parent.
2833 ;; Treat this one at an even deeper level:
2834 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
2835 new-depth
;;; starting-depth
2836 starting-point
;;; starting-point
2839 (if on-starting-call
2841 ;; Rectify numbering of former siblings of the adjusted topic,
2842 ;; if topic has changed depth
2843 (if (or do-successors
2844 (and (not (zerop relative-depth
))
2845 (or (= (outline-recent-depth) starting-depth
)
2846 (= (outline-recent-depth) (+ starting-depth
2848 (outline-rebullet-heading nil nil nil nil t
))
2849 ;; Now rectify numbering of new siblings of the adjusted topic,
2850 ;; if depth has been changed:
2851 (progn (goto-char starting-point
)
2852 (if (not (zerop relative-depth
))
2853 (outline-rebullet-heading nil nil nil nil t
)))))
2856 ;;;_ > outline-renumber-to-depth (&optional depth)
2857 (defun outline-renumber-to-depth (&optional depth
)
2858 "Renumber siblings at current depth.
2860 Affects superior topics if optional arg DEPTH is less than current depth.
2862 Returns final depth."
2864 ;; Proceed by level, processing subsequent siblings on each,
2865 ;; ascending until we get shallower than the start depth:
2867 (let ((ascender (outline-depth)))
2868 (while (and (not (eobp))
2870 (>= (outline-recent-depth) depth
)
2871 (>= ascender depth
))
2872 ; Skip over all topics at
2873 ; lesser depths, which can not
2874 ; have been disturbed:
2875 (while (and (not (eobp))
2876 (> (outline-recent-depth) ascender
))
2877 (outline-next-heading))
2878 ; Prime ascender for ascension:
2879 (setq ascender
(1- (outline-recent-depth)))
2880 (if (>= (outline-recent-depth) depth
)
2881 (outline-rebullet-heading nil
;;; solicit
2883 nil
;;; number-control
2885 t
))));;; do-successors
2886 (outline-recent-depth))
2887 ;;;_ > outline-number-siblings (&optional denumber)
2888 (defun outline-number-siblings (&optional denumber
)
2889 "Assign numbered topic prefix to this topic and its siblings.
2891 With universal argument, denumber - assign default bullet to this
2892 topic and its siblings.
2894 With repeated universal argument (`^U^U'), solicit bullet for each
2895 rebulleting each topic at this level."
2900 (outline-back-to-current-heading)
2901 (outline-beginning-of-level)
2902 (let ((depth (outline-recent-depth))
2903 (index (if (not denumber
) 1))
2904 (use-bullet (equal '(16) denumber
))
2907 (outline-rebullet-heading use-bullet
;;; solicit
2909 t
;;; number-control
2911 nil
) ;;; do-successors
2912 (if index
(setq index
(1+ index
)))
2913 (setq more
(outline-next-sibling depth nil
))))))
2914 ;;;_ > outline-shift-in (arg)
2915 (defun outline-shift-in (arg)
2916 "Increase depth of current heading and any topics collapsed within it."
2918 (outline-rebullet-topic arg
))
2919 ;;;_ > outline-shift-out (arg)
2920 (defun outline-shift-out (arg)
2921 "Decrease depth of current heading and any topics collapsed within it."
2923 (outline-rebullet-topic (* arg -
1)))
2924 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
2925 ;;;_ > outline-kill-line (&optional arg)
2926 (defun outline-kill-line (&optional arg
)
2927 "Kill line, adjusting subsequent lines suitably for outline mode."
2930 (if (not (and (outline-mode-p) ; active outline mode,
2931 outline-numbered-bullet
; numbers may need adjustment,
2932 (bolp) ; may be clipping topic head,
2933 (looking-at outline-regexp
))) ; are clipping topic head.
2934 ;; Above conditions do not obtain - just do a regular kill:
2936 ;; Ah, have to watch out for adjustments:
2937 (let* ((depth (outline-depth)))
2940 ; Provide some feedback:
2943 ; Start with the topic
2944 ; following killed line:
2945 (if (not (looking-at outline-regexp
))
2946 (outline-next-heading))
2947 (outline-renumber-to-depth depth
)))))
2948 ;;;_ > outline-kill-topic ()
2949 (defun outline-kill-topic ()
2950 "Kill topic together with subtopics.
2952 Leaves primary topic's trailing vertical whitespace, if any."
2954 ;; Some finagling is done to make complex topic kills appear faster
2955 ;; than they actually are. A redisplay is performed immediately
2956 ;; after the region is disposed of, though the renumbering process
2957 ;; has yet to be performed. This means that there may appear to be
2958 ;; a lag *after* the kill has been performed.
2961 (let* ((beg (prog1 (outline-back-to-current-heading)(beginning-of-line)))
2962 (depth (outline-recent-depth)))
2963 (outline-end-of-current-subtree)
2965 (if (or (not (looking-at "^$"))
2966 ;; A blank line - cut it with this topic *unless* this
2967 ;; is the last topic at this level, in which case
2968 ;; we'll leave the blank line as part of the
2969 ;; containing topic:
2971 (and (outline-next-heading)
2972 (>= (outline-recent-depth) depth
))))
2975 (kill-region beg
(point))
2978 (outline-renumber-to-depth depth
))))
2979 ;;;_ > outline-yank-processing ()
2980 (defun outline-yank-processing (&optional arg
)
2982 "Incidental outline-specific business to be done just after text yanks.
2984 Does depth adjustment of yanked topics, when:
2986 1 the stuff being yanked starts with a valid outline header prefix, and
2987 2 it is being yanked at the end of a line which consists of only a valid
2990 Also, adjusts numbering of subsequent siblings when appropriate.
2992 Depth adjustment alters the depth of all the topics being yanked
2993 the amount it takes to make the first topic have the depth of the
2994 header into which it's being yanked.
2996 The point is left in front of yanked, adjusted topics, rather than
2997 at the end (and vice-versa with the mark). Non-adjusted yanks,
2998 however, are left exactly like normal, non-outline-specific yanks."
3001 ; Get to beginning, leaving
3002 ; region around subject:
3003 (if (< (mark-marker) (point))
3004 (exchange-point-and-mark))
3005 (let* ((subj-beg (point))
3006 (subj-end (mark-marker))
3007 ;; `resituate' if yanking an entire topic into topic header:
3008 (resituate (and (outline-e-o-prefix-p)
3009 (looking-at (concat "\\(" outline-regexp
"\\)"))
3010 (outline-prefix-data (match-beginning 1)
3012 ;; `rectify-numbering' if resituating (where several topics may
3013 ;; be resituating) or yanking a topic into a topic slot (bol):
3014 (rectify-numbering (or resituate
3015 (and (bolp) (looking-at outline-regexp
)))))
3017 ; The yanked stuff is a topic:
3018 (let* ((prefix-len (- (match-end 1) subj-beg
))
3019 (subj-depth (outline-recent-depth))
3020 (prefix-bullet (outline-recent-bullet))
3022 ;; Nil if adjustment unnecessary, otherwise depth to which
3023 ;; adjustment should be made:
3025 (and (goto-char subj-end
)
3027 (goto-char subj-beg
)
3028 (and (looking-at outline-regexp
)
3031 (not (= (point) subj-beg
)))
3032 (looking-at outline-regexp
)
3033 (outline-prefix-data (match-beginning 0)
3035 (outline-recent-depth))))
3038 (setq rectify-numbering outline-numbered-bullet
)
3040 ; Do the adjustment:
3042 (message "... yanking") (sit-for 0)
3044 (narrow-to-region subj-beg subj-end
)
3045 ; Trim off excessive blank
3046 ; line at end, if any:
3047 (goto-char (point-max))
3048 (if (looking-at "^$")
3049 (outline-unprotected (delete-char -
1)))
3050 ; Work backwards, with each
3052 ; successively excluding the
3053 ; last processed topic from
3054 ; the narrow region:
3056 (outline-back-to-current-heading)
3057 ; go as high as we can in each bunch:
3058 (while (outline-ascend-to-depth (1- (outline-depth))))
3060 (outline-rebullet-topic-grunt (- adjust-to-depth
3063 (if (setq more
(not (bobp)))
3066 (narrow-to-region subj-beg
(point))))))
3068 ;; Preserve new bullet if it's a distinctive one, otherwise
3070 (if (string-match (regexp-quote prefix-bullet
)
3071 outline-distinctive-bullets-string
)
3072 ; Delete from bullet of old to
3073 ; before bullet of new:
3076 (delete-region (point) subj-beg
)
3077 (set-marker (mark-marker) subj-end
)
3078 (goto-char subj-beg
)
3079 (outline-end-of-prefix))
3080 ; Delete base subj prefix,
3082 (delete-region (point) (+ (point)
3084 (- adjust-to-depth subj-depth
)))
3085 ; and delete residual subj
3086 ; prefix digits and space:
3087 (while (looking-at "[0-9]") (delete-char 1))
3088 (if (looking-at " ") (delete-char 1))))
3089 (exchange-point-and-mark))))
3090 (if rectify-numbering
3093 ; Give some preliminary feedback:
3094 (message "... reconciling numbers") (sit-for 0)
3095 ; ... and renumber, in case necessary:
3096 (goto-char subj-beg
)
3097 (if (outline-goto-prefix)
3098 (outline-rebullet-heading nil
;;; solicit
3099 (outline-depth) ;;; depth
3100 nil
;;; number-control
3105 (exchange-point-and-mark))))
3106 ;;;_ > outline-yank (&optional arg)
3107 (defun outline-yank (&optional arg
)
3108 "Outline-mode yank, with depth and numbering adjustment of yanked topics.
3110 Non-topic yanks work no differently than normal yanks.
3112 If a topic is being yanked into a bare topic prefix, the depth of the
3113 yanked topic is adjusted to the depth of the topic prefix.
3115 1 we're yanking in an outline-mode buffer
3116 2 the stuff being yanked starts with a valid outline header prefix, and
3117 3 it is being yanked at the end of a line which consists of only a valid
3120 If these conditions hold then the depth of the yanked topics are all
3121 adjusted the amount it takes to make the first one at the depth of the
3122 header into which it's being yanked.
3124 The point is left in front of yanked, adjusted topics, rather than
3125 at the end (and vice-versa with the mark). Non-adjusted yanks,
3126 however, (ones that don't qualify for adjustment) are handled
3127 exactly like normal yanks.
3129 Numbering of yanked topics, and the successive siblings at the depth
3130 into which they're being yanked, is adjusted.
3132 Outline-yank-pop works with outline-yank just like normal yank-pop
3133 works with normal yank in non-outline buffers."
3136 (setq this-command
'yank
)
3138 (if (outline-mode-p)
3139 (outline-yank-processing)))
3140 ;;;_ > outline-yank-pop (&optional arg)
3141 (defun outline-yank-pop (&optional arg
)
3142 "Yank-pop like outline-yank when popping to bare outline prefixes.
3144 Adapts level of popped topics to level of fresh prefix.
3146 Note - prefix changes to distinctive bullets will stick, if followed
3147 by pops to non-distinctive yanks. Bug..."
3150 (setq this-command
'yank
)
3152 (if (outline-mode-p)
3153 (outline-yank-processing)))
3155 ;;;_ - Specialty bullet functions
3156 ;;;_ : File Cross references
3157 ;;;_ > outline-resolve-xref ()
3158 (defun outline-resolve-xref ()
3159 "Pop to file associated with current heading, if it has an xref bullet.
3161 \(Works according to setting of `outline-file-xref-bullet')."
3163 (if (not outline-file-xref-bullet
)
3165 "outline cross references disabled - no `outline-file-xref-bullet'")
3166 (if (not (string= (outline-current-bullet) outline-file-xref-bullet
))
3167 (error "current heading lacks cross-reference bullet `%s'"
3168 outline-file-xref-bullet
)
3171 (let* ((text-start outline-recent-prefix-end
)
3172 (heading-end (progn (end-of-line) (point))))
3173 (goto-char text-start
)
3175 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
3176 (buffer-substring (match-beginning 1) (match-end 1))))))
3178 (if (not (= (aref file-name
0) ?
:))
3179 (expand-file-name file-name
)
3180 ; A registry-files ref, strip the `:'
3181 ; and try to follow it:
3182 (let ((reg-ref (reference-registered-file
3183 (substring file-name
1) nil t
)))
3184 (if reg-ref
(car (cdr reg-ref
))))))
3185 (if (or (file-exists-p file-name
)
3186 (if (file-writable-p file-name
)
3187 (y-or-n-p (format "%s not there, create one? "
3189 (error "%s not found and can't be created" file-name
)))
3190 (condition-case failure
3191 (find-file-other-window file-name
)
3193 (error "%s not found" file-name
))
3199 ;;;_ #6 Exposure Control and Processing
3202 ;;;_ > outline-flag-region (from to flag)
3203 (defmacro outline-flag-region
(from to flag
)
3204 "Hide or show lines from FROM to TO, via emacs selective-display FLAG char.
3205 Ie, text following flag C-m \(carriage-return) is hidden until the
3206 next C-j (newline) char.
3208 Returns the endpoint of the region."
3209 (` (let ((buffer-read-only nil
)
3210 (outline-override-protect t
))
3211 (subst-char-in-region (, from
) (, to
)
3212 (if (= (, flag
) ?
\n) ?
\r ?
\n)
3214 ;;;_ > outline-flag-current-subtree (flag)
3215 (defun outline-flag-current-subtree (flag)
3216 "Hide or show subtree of currently-visible topic.
3218 See `outline-flag-region' for more details."
3221 (outline-back-to-current-heading)
3222 (outline-flag-region (point)
3223 (progn (outline-end-of-current-subtree) (1- (point)))
3226 ;;;_ - Mapping and processing of topics
3227 ;;;_ " See also chart functions, in navigation
3228 ;;;_ > outline-listify-exposed (&optional start end)
3229 (defun outline-listify-exposed (&optional start end
)
3231 "Produce a list representing exposed topics in current region.
3233 This list can then be used by `outline-process-exposed' to manipulate
3236 List is composed of elements that may themselves be lists representing
3237 exposed components in subtopic.
3239 Each component list contains:
3240 - a number representing the depth of the topic,
3241 - a string representing the header-prefix (ref. `outline-header-prefix'),
3242 - a string representing the bullet character,
3243 - and a series of strings, each containing one line of the exposed
3244 portion of the topic entry."
3248 (let* (strings pad result depth bullet beg next done
) ; State vars.
3251 (if (not (outline-goto-prefix)) ; Get initial position within a topic:
3252 (outline-next-visible-heading 1))
3253 (while (and (not done
)
3254 (not (eobp)) ; Loop until we've covered the region.
3255 (not (> (point) end
)))
3256 (setq depth
(outline-recent-depth) ; Current topics' depth,
3257 bullet
(outline-recent-bullet) ; ... bullet,
3258 beg
(progn (outline-end-of-prefix t
) (point))) ; and beginning.
3259 (setq done
; The boundary for the current topic:
3260 (not (outline-next-visible-heading 1)))
3265 (while (> next
(point)) ; Get all the exposed text in
3267 (cons (buffer-substring
3269 ;To hidden text or end of line:
3271 (search-forward "\r"
3272 (save-excursion (end-of-line)
3275 (if (= (preceding-char) ?
\r)
3279 (if (< (point) next
) ; Resume from after hid text, if any.
3282 ;; Accumulate list for this topic:
3284 (cons (append (list depth
3285 outline-header-prefix
3289 ;; Put the list with first at front, to last at back:
3290 (nreverse result
))))
3291 ;;;_ > outline-process-exposed (arg &optional tobuf)
3292 (defun outline-process-exposed (&optional func from to frombuf tobuf
)
3293 "Map function on exposed parts of current topic; results to another buffer.
3295 Apply FUNCTION \(default 'outline-insert-listified) to exposed
3296 portions FROM position TO position \(default region, or the entire
3297 buffer if no region active) in buffer FROMBUF \(default current
3298 buffer) to buffer TOBUF \(default is buffer named like frombuf but
3299 with \"*\" prepended and \" exposed*\" appended).
3301 The function must as its arguments the elements of the list
3302 representations of topic entries produced by outline-listify-exposed."
3304 ; Resolve arguments,
3305 ; defaulting if necessary:
3306 (if (not func
) (setq func
'outline-insert-listified
))
3307 (if (not (and from to
))
3309 (setq from
(region-beginning) to
(region-end))
3310 (setq from
(point-min) to
(point-max))))
3312 (if (not (bufferp frombuf
))
3313 ;; Specified but not a buffer - get it:
3314 (let ((got (get-buffer frombuf
)))
3316 (error "outline-process-exposed: source buffer %s not found."
3318 (setq frombuf got
))))
3319 ;; not specified - default it:
3320 (setq frombuf
(current-buffer)))
3322 (if (not (bufferp tobuf
))
3323 (setq tobuf
(get-buffer-create tobuf
)))
3324 ;; not specified - default it:
3325 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
3327 (let* ((listified (progn (set-buffer frombuf
)
3328 (outline-listify-exposed from to
)))
3329 (prefix outline-header-prefix
) ; ... as set in frombuf.
3333 (setq curr
(car listified
))
3334 (setq listified
(cdr listified
))
3335 (apply func
(list (car curr
) ; depth
3336 (car (cdr curr
)) ; header-prefix
3337 (car (cdr (cdr curr
))) ; bullet
3338 (cdr (cdr (cdr curr
)))))) ; list of text lines
3339 (pop-to-buffer tobuf
)))
3341 ;;;_ - Topic-specific
3342 ;;;_ > outline-show-entry ()
3343 ; outline-show-entry basically for isearch dynamic exposure, as is...
3344 (defun outline-show-entry ()
3345 "Like `outline-show-current-entry', reveals entries nested in hidden topics.
3347 This is a way to give restricted peek at a concealed locality without the
3348 expense of exposing its context, but can leave the outline with aberrant
3349 exposure. outline-hide-current-entry-completely or outline-show-offshoot
3350 should be used after the peek to rectify the exposure."
3354 (outline-goto-prefix)
3355 (outline-flag-region (if (bobp) (point) (1- (point)))
3356 (or (outline-pre-next-preface) (point))
3358 ;;;_ > outline-show-children (&optional level strict)
3359 (defun outline-show-children (&optional level strict
)
3361 "If point is visible, show all direct subheadings of this heading.
3363 Otherwise, do outline-show-to-offshoot, and then show subheadings.
3365 Optional LEVEL specifies how many levels below the current level
3366 should be shown, or all levels if t. Default is 1.
3368 Optional STRICT means don't resort to -show-to-offshoot, no matter
3369 what. This is basically so -show-to-offshoot, which is called by
3370 this function, can employ the pure offspring-revealing capabilities of
3373 Returns point at end of subtree that was opened, if any. (May get a
3374 point of non-opened subtree?)"
3378 (if (and (not strict
)
3381 (progn (outline-show-to-offshoot) ; Point's concealed, open to
3383 ;; Then recurse, but with "strict" set so we don't
3384 ;; infinite regress:
3385 (setq max-pos
(outline-show-children level t
)))
3389 (let* ((start-pt (point))
3390 (chart (outline-chart-subtree (or level
1)))
3391 (to-reveal (outline-chart-to-reveal chart
(or level
1))))
3392 (goto-char start-pt
)
3393 (if (and strict
(= (preceding-char) ?
\r))
3394 ;; Concealed root would already have been taken care of,
3395 ;; unless strict was set.
3396 (outline-flag-region (point) (outline-snug-back) ?
\n))
3398 (goto-char (car to-reveal
))
3399 (outline-flag-region (point) (outline-snug-back) ?
\n)
3400 (setq to-reveal
(cdr to-reveal
)))))))))
3401 ;;;_ x outline-show-current-children (&optional level strict)
3402 (defun outline-show-current-children (&optional level strict
)
3403 "This command was misnamed, use `outline-show-children' instead.
3405 \(The \"current\" in the name is supposed to imply that it works on
3406 the visible topic containing point, while it really works with respect
3407 to the most immediate topic, concealed or not. I'll leave this old
3408 name around for a bit, but i'll soon activate an annoying message to
3409 warn people about the change, and then deprecate this alias."
3413 ;;(message (format "Use `%s' instead of `%s' (%s)."
3414 ;; "outline-show-children"
3415 ;; "outline-show-current-children"
3416 ;; (buffer-name (current-buffer))))
3417 (outline-show-children level strict
))
3418 ;;;_ > outline-hide-point-reconcile ()
3419 (defun outline-hide-reconcile ()
3420 "Like `outline-hide-current-entry'; hides completely if within hidden region.
3422 Specifically intended for aberrant exposure states, like entries that were
3423 exposed by outline-show-entry but are within otherwise concealed regions."
3426 (outline-goto-prefix)
3427 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3428 (progn (outline-pre-next-preface)
3429 (if (= ?
\r (following-char))
3433 ;;;_ > outline-show-to-offshoot ()
3434 (defun outline-show-to-offshoot ()
3435 "Like outline-show-entry, but reveals opens all concealed ancestors, as well.
3437 As with outline-hide-current-entry-completely, useful for rectifying
3438 aberrant exposure states produced by outline-show-entry."
3442 (let ((orig-pt (point))
3443 (orig-pref (outline-goto-prefix))
3446 (while (or bag-it
(= (preceding-char) ?
\r))
3448 (if (= last-at
(setq last-at
(point)))
3449 ;; Oops, we're not making any progress! Show the current
3450 ;; topic completely, and bag this try.
3451 (progn (beginning-of-line)
3452 (outline-show-current-subtree)
3457 "outline-show-to-offshoot: "
3458 "Aberrant nesting encountered.")))
3459 (outline-show-children)
3460 (goto-char orig-pref
))
3461 (goto-char orig-pt
)))
3462 (if (outline-hidden-p)
3463 (outline-show-entry)))
3464 ;;;_ > outline-hide-current-entry ()
3465 (defun outline-hide-current-entry ()
3466 "Hide the body directly following this heading."
3468 (outline-back-to-current-heading)
3470 (outline-flag-region (point)
3471 (progn (outline-end-of-current-entry) (point))
3473 ;;;_ > outline-show-current-entry (&optional arg)
3474 (defun outline-show-current-entry (&optional arg
)
3476 "Show body following current heading, or hide the entry if repeat count."
3480 (outline-hide-current-entry)
3482 (outline-flag-region (point)
3483 (progn (outline-end-of-current-entry) (point))
3485 ;;;_ > outline-hide-current-entry-completely ()
3486 ; ... outline-hide-current-entry-completely also for isearch dynamic exposure:
3487 (defun outline-hide-current-entry-completely ()
3488 "Like outline-hide-current-entry, but conceal topic completely.
3490 Specifically intended for aberrant exposure states, like entries that were
3491 exposed by outline-show-entry but are within otherwise concealed regions."
3494 (outline-goto-prefix)
3495 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3496 (progn (outline-pre-next-preface)
3497 (if (= ?
\r (following-char))
3501 ;;;_ > outline-show-current-subtree (&optional arg)
3502 (defun outline-show-current-subtree (&optional arg
)
3503 "Show everything within the current topic. With a repeat-count,
3504 expose this topic and its siblings."
3507 (if (<= (outline-current-depth) 0)
3508 ;; Outside any topics - try to get to the first:
3509 (if (not (outline-next-heading))
3510 (error "No topics.")
3511 ;; got to first, outermost topic - set to expose it and siblings:
3512 (message "Above outermost topic - exposing all.")
3513 (outline-flag-region (point-min)(point-max) ?
\n))
3515 (outline-flag-current-subtree ?
\n)
3516 (outline-beginning-of-level)
3517 (outline-expose-topic '(* :))))))
3518 ;;;_ > outline-hide-current-subtree (&optional just-close)
3519 (defun outline-hide-current-subtree (&optional just-close
)
3520 "Close the current topic, or containing topic if this one is already closed.
3522 If this topic is closed and it's a top level topic, close this topic
3525 If optional arg JUST-CLOSE is non-nil, do not treat the parent or
3526 siblings, even if the target topic is already closed."
3529 (let ((from (point))
3530 (orig-eol (progn (end-of-line)
3531 (if (not (outline-goto-prefix))
3532 (error "No topics found.")
3533 (end-of-line)(point)))))
3534 (outline-flag-current-subtree ?\^M
)
3536 (if (and (= orig-eol
(progn (goto-char orig-eol
)
3540 ;; Structure didn't change - try hiding current level:
3542 (if (outline-up-current-level 1 t
)
3546 "Top-level topic already closed - closing siblings..."))
3548 (outline-expose-topic '(0 :))
3549 (message (concat msg
" Done.")))
3551 (/= (outline-recent-depth) 0))
3552 (outline-hide-current-subtree))
3554 ;;;_ > outline-show-current-branches ()
3555 (defun outline-show-current-branches ()
3556 "Show all subheadings of this heading, but not their bodies."
3559 (outline-show-children t
))
3560 ;;;_ > outline-hide-current-leaves ()
3561 (defun outline-hide-current-leaves ()
3562 "Hide the bodies of the current topic and all its offspring."
3564 (outline-back-to-current-heading)
3565 (outline-hide-region-body (point) (progn (outline-end-of-current-subtree)
3568 ;;;_ - Region and beyond
3569 ;;;_ > outline-show-all ()
3570 (defun outline-show-all ()
3571 "Show all of the text in the buffer."
3573 (message "Exposing entire buffer...")
3574 (outline-flag-region (point-min) (point-max) ?
\n)
3575 (message "Exposing entire buffer... Done."))
3576 ;;;_ > outline-hide-bodies ()
3577 (defun outline-hide-bodies ()
3578 "Hide all of buffer except headings."
3580 (outline-hide-region-body (point-min) (point-max)))
3581 ;;;_ > outline-hide-region-body (start end)
3582 (defun outline-hide-region-body (start end
)
3583 "Hide all body lines in the region, but not headings."
3586 (narrow-to-region start end
)
3587 (goto-char (point-min))
3589 (outline-flag-region (point)
3590 (progn (outline-pre-next-preface) (point)) ?\^M
)
3593 (if (looking-at "[\n\r][\n\r]")
3596 ;;;_ > outline-expose-topic (spec)
3597 (defun outline-expose-topic (spec)
3598 "Apply exposure specs to successive outline topic items.
3600 Use the more convenient frontend, `outline-new-exposure', if you don't
3601 need evaluation of the arguments, or even better, the `outline-layout'
3602 variable-keyed mode-activation/auto-exposure feature of allout outline
3603 mode. See the respective documentation strings for more details.
3605 Cursor is left at start position.
3607 SPEC is either a number or a list.
3609 Successive specs on a list are applied to successive sibling topics.
3611 A simple spec \(either a number, one of a few symbols, or the null
3612 list) dictates the exposure for the corresponding topic.
3614 Non-null lists recursively designate exposure specs for respective
3615 subtopics of the current topic.
3617 The `:' repeat spec is used to specify exposure for any number of
3618 successive siblings, up to the trailing ones for which there are
3619 explicit specs following the `:'.
3621 Simple (numeric and null-list) specs are interpreted as follows:
3623 Numbers indicate the relative depth to open the corresponding topic.
3624 - negative numbers force the topic to be closed before opening to the
3625 absolute value of the number, so all siblings are open only to
3627 - positive numbers open to the relative depth indicated by the
3628 number, but do not force already opened subtopics to be closed.
3629 - 0 means to close topic - hide all offspring.
3631 apply prior element to all siblings at current level, *up to*
3632 those siblings that would be covered by specs following the `:'
3633 on the list. Ie, apply to all topics at level but the last
3634 ones. \(Only first of multiple colons at same level is
3635 respected - subsequent ones are discarded.)
3636 * - completely opens the topic, including bodies.
3637 + - shows all the sub headers, but not the bodies
3638 - - exposes the body of the corresponding topic.
3641 \(outline-expose-topic '(-1 : 0))
3642 Close this and all following topics at current level, exposing
3643 only their immediate children, but close down the last topic
3644 at this current level completely.
3645 \(outline-expose-topic '(-1 () : 1 0))
3646 Close current topic so only the immediate subtopics are shown;
3647 show the children in the second to last topic, and completely
3649 \(outline-expose-topic '(-2 : -1 *))
3650 Expose children and grandchildren of all topics at current
3651 level except the last two; expose children of the second to
3652 last and completely open the last one."
3654 (interactive "xExposure spec: ")
3655 (if (not (listp spec
))
3657 (let ((depth (outline-depth))
3664 (setq prev-elem curr-elem
3665 curr-elem
(car spec
)
3667 (cond ; Do current element:
3668 ((null curr-elem
) nil
)
3669 ((symbolp curr-elem
)
3670 (cond ((eq curr-elem
'*) (outline-show-current-subtree)
3671 (if (> outline-recent-end-of-subtree max-pos
)
3672 (setq max-pos outline-recent-end-of-subtree
)))
3673 ((eq curr-elem
'+) (outline-show-current-branches)
3674 (if (> outline-recent-end-of-subtree max-pos
)
3675 (setq max-pos outline-recent-end-of-subtree
)))
3676 ((eq curr-elem
'-
) (outline-show-current-entry))
3679 ;; Expand the `repeat' spec to an explicit version,
3680 ;; w.r.t. remaining siblings:
3681 (let ((residue ; = # of sibs not covered by remaining spec
3682 ;; Dang - could be nice to make use of the chart, sigh:
3683 (- (length (outline-chart-siblings))
3686 ;; Some residue - cover it with prev-elem:
3687 (setq spec
(append (make-list residue prev-elem
)
3689 ((numberp curr-elem
)
3690 (if (and (>= 0 curr-elem
) (outline-visible-p))
3691 (save-excursion (outline-hide-current-subtree t
)
3694 (if (> outline-recent-end-of-subtree max-pos
)
3696 outline-recent-end-of-subtree
)))))
3697 (if (> (abs curr-elem
) 0)
3698 (progn (outline-show-children (abs curr-elem
))
3699 (if (> outline-recent-end-of-subtree max-pos
)
3700 (setq max-pos outline-recent-end-of-subtree
)))))
3702 (if (outline-descend-to-depth (1+ depth
))
3703 (let ((got (outline-expose-topic curr-elem
)))
3704 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
3705 (cond (stay (setq stay nil
))
3706 ((listp (car spec
)) nil
)
3707 ((> max-pos
(point))
3708 ;; Capitalize on max-pos state to get us nearer next sibling:
3709 (progn (goto-char (min (point-max) max-pos
))
3710 (outline-next-heading)))
3711 ((outline-next-sibling depth
))))
3713 ;;;_ > outline-old-expose-topic (spec &rest followers)
3714 (defun outline-old-expose-topic (spec &rest followers
)
3716 "Deprecated. Use outline-expose-topic \(with different schema
3719 Dictate wholesale exposure scheme for current topic, according to SPEC.
3721 SPEC is either a number or a list. Optional successive args
3722 dictate exposure for subsequent siblings of current topic.
3724 A simple spec (either a number, a special symbol, or the null list)
3725 dictates the overall exposure for a topic. Non null lists are
3726 composite specs whose first element dictates the overall exposure for
3727 a topic, with the subsequent elements in the list interpreted as specs
3728 that dictate the exposure for the successive offspring of the topic.
3730 Simple (numeric and null-list) specs are interpreted as follows:
3732 - Numbers indicate the relative depth to open the corresponding topic:
3733 - negative numbers force the topic to be close before opening to the
3734 absolute value of the number.
3735 - positive numbers just open to the relative depth indicated by the number.
3737 - `*' completely opens the topic, including bodies.
3738 - `+' shows all the sub headers, but not the bodies
3739 - `-' exposes the body and immediate offspring of the corresponding topic.
3741 If the spec is a list, the first element must be a number, which
3742 dictates the exposure depth of the topic as a whole. Subsequent
3743 elements of the list are nested SPECs, dictating the specific exposure
3744 for the corresponding offspring of the topic.
3746 Optional FOLLOWER arguments dictate exposure for succeeding siblings."
3748 (interactive "xExposure spec: ")
3749 (let ((depth (outline-current-depth))
3752 (cond ((null spec
) nil
)
3754 (if (eq spec
'*) (outline-show-current-subtree))
3755 (if (eq spec
'+) (outline-show-current-branches))
3756 (if (eq spec
'-
) (outline-show-current-entry)))
3759 (save-excursion (outline-hide-current-subtree t
)
3761 (if (or (not max-pos
)
3762 (> (point) max-pos
))
3763 (setq max-pos
(point)))
3765 (setq spec
(* -
1 spec
)))))
3767 (outline-show-children spec
)))
3769 ;(let ((got (outline-old-expose-topic (car spec))))
3770 ; (if (and got (or (not max-pos) (> got max-pos)))
3771 ; (setq max-pos got)))
3772 (let ((new-depth (+ (outline-current-depth) 1))
3774 (setq max-pos
(outline-old-expose-topic (car spec
)))
3775 (setq spec
(cdr spec
))
3777 (outline-descend-to-depth new-depth
)
3778 (not (outline-hidden-p)))
3779 (progn (setq got
(apply 'outline-old-expose-topic spec
))
3780 (if (and got
(or (not max-pos
) (> got max-pos
)))
3781 (setq max-pos got
)))))))
3782 (while (and followers
3783 (progn (if (and max-pos
(< (point) max-pos
))
3784 (progn (goto-char max-pos
)
3785 (setq max-pos nil
)))
3787 (outline-next-sibling depth
)))
3788 (outline-old-expose-topic (car followers
))
3789 (setq followers
(cdr followers
)))
3791 ;;;_ > outline-new-exposure '()
3792 (defmacro outline-new-exposure
(&rest spec
)
3793 "Literal frontend for `outline-expose-topic', doesn't evaluate arguments.
3794 Some arguments that would need to be quoted in outline-expose-topic
3795 need not be quoted in outline-new-exposure.
3797 Cursor is left at start position.
3799 Use this instead of obsolete `outline-exposure'.
3802 \(outline-exposure (-1 () () () 1) 0)
3803 Close current topic at current level so only the immediate
3804 subtopics are shown, except also show the children of the
3805 third subtopic; and close the next topic at the current level.
3806 \(outline-exposure : -1 0)
3807 Close all topics at current level to expose only their
3808 immediate children, except for the last topic at the current
3809 level, in which even its immediate children are hidden.
3810 \(outline-exposure -2 : -1 *)
3811 Expose children and grandchildren of first topic at current
3812 level, and expose children of subsequent topics at current
3813 level *except* for the last, which should be opened completely."
3814 (list 'save-excursion
3815 '(if (not (or (outline-goto-prefix)
3816 (outline-next-heading)))
3817 (error "outline-new-exposure: Can't find any outline topics."))
3818 (list 'outline-expose-topic
(list 'quote spec
))))
3819 ;;;_ > outline-exposure '()
3820 (defmacro outline-exposure
(&rest spec
)
3821 "Being deprecated - use more recent `outline-new-exposure' instead.
3823 Literal frontend for `outline-old-expose-topic', doesn't evaluate arguments
3824 and retains start position."
3825 (list 'save-excursion
3826 '(if (not (or (outline-goto-prefix)
3827 (outline-next-heading)))
3828 (error "Can't find any outline topics."))
3829 (cons 'outline-old-expose-topic
3830 (mapcar '(lambda (x) (list 'quote x
)) spec
))))
3832 ;;;_ #7 ISearch with Dynamic Exposure
3833 ;;;_ = outline-search-reconceal
3834 (defvar outline-search-reconceal nil
3835 "Track whether current search match was concealed outside of search.
3837 The value is the location of the match, if it was concealed, regular
3838 if the entire topic was concealed, in a list if the entry was concealed.")
3839 ;;;_ = outline-search-quitting
3840 (defconst outline-search-quitting nil
3841 "Distinguishes isearch conclusion and cancellation.
3843 Used by isearch-terminate/outline-provisions and
3844 isearch-done/outline-provisions")
3847 ;;;_ > outline-enwrap-isearch ()
3848 (defun outline-enwrap-isearch ()
3849 "Impose outline-mode isearch-mode wrappers for dynamic exposure in isearch.
3851 Isearch progressively exposes and reconceals hidden topics when
3852 working in outline mode, but works normally elsewhere.
3854 The function checks to ensure that the rebindings are done only once."
3856 ; Should isearch-mode be employed,
3857 (if (or (not outline-enwrap-isearch-mode
)
3858 ; or are preparations already done?
3859 (fboundp 'real-isearch-terminate
))
3861 ;; ... no - skip this all:
3866 ; Ensure load of isearch-mode:
3867 (if (or (and (fboundp 'isearch-mode
)
3868 (fboundp 'isearch-quote-char
))
3869 (condition-case error
3870 (load-library outline-enwrap-isearch-mode
)
3871 (file-error (message "Skipping isearch-mode provisions - %s '%s'"
3873 (car (cdr (cdr error
))))
3875 ;; Inhibit subsequent tries and return nil:
3876 (setq outline-enwrap-isearch-mode nil
))))
3877 ;; Isearch-mode loaded, encapsulate specific entry points for
3878 ;; outline dynamic-exposure business:
3881 ;; stash crucial isearch-mode funcs under known, private
3882 ;; names, then register wrapper functions under the old
3883 ;; names, in their stead: `isearch-quit' is pre isearch v 1.2.
3884 (fset 'real-isearch-terminate
3885 ; `isearch-quit' is pre v 1.2:
3886 (or (if (fboundp 'isearch-quit
)
3887 (symbol-function 'isearch-quit
))
3888 (if (fboundp 'isearch-abort
)
3889 ; `isearch-abort' is v 1.2 and on:
3890 (symbol-function 'isearch-abort
))))
3891 (fset 'isearch-quit
'isearch-terminate
/outline-provisions
)
3892 (fset 'isearch-abort
'isearch-terminate
/outline-provisions
)
3893 (fset 'real-isearch-done
(symbol-function 'isearch-done
))
3894 (fset 'isearch-done
'isearch-done
/outline-provisions
)
3895 (fset 'real-isearch-update
(symbol-function 'isearch-update
))
3896 (fset 'isearch-update
'isearch-update
/outline-provisions
)
3897 (make-variable-buffer-local 'outline-search-reconceal
)))))
3898 ;;;_ > outline-isearch-arrival-business ()
3899 (defun outline-isearch-arrival-business ()
3900 "Do outline business like exposing current point, if necessary.
3902 Registers reconcealment requirements in outline-search-reconceal
3905 Set outline-search-reconceal to nil if current point is not
3906 concealed, to value of point if entire topic is concealed, and a
3907 list containing point if only the topic body is concealed.
3909 This will be used to determine whether outline-hide-current-entry
3910 or outline-hide-current-entry-completely will be necessary to
3911 restore the prior concealment state."
3913 (if (outline-mode-p)
3914 (setq outline-search-reconceal
3915 (if (outline-hidden-p)
3917 (if (re-search-backward outline-line-boundary-regexp nil
1)
3918 ;; Nil value means we got to b-o-b - wouldn't need
3921 ; We'll return point or list
3922 ; containing point, depending
3923 ; on concealment state of
3925 (prog1 (if (outline-hidden-p) (point) (list (point)))
3926 ; And reveal the current
3928 (outline-show-entry)))))))
3929 ;;;_ > outline-isearch-advancing-business ()
3930 (defun outline-isearch-advancing-business ()
3931 "Do outline business like deexposing current point, if necessary.
3933 Works according to reconceal state registration."
3934 (if (and (outline-mode-p) outline-search-reconceal
)
3936 (if (listp outline-search-reconceal
)
3937 ;; Leave the topic visible:
3938 (progn (goto-char (car outline-search-reconceal
))
3939 (outline-hide-current-entry))
3940 ;; Rehide the entire topic:
3941 (goto-char outline-search-reconceal
)
3942 (outline-hide-current-entry-completely)))))
3943 ;;;_ > isearch-terminate/outline-provisions ()
3944 (defun isearch-terminate/outline-provisions
()
3946 (if (and (outline-mode-p) outline-enwrap-isearch-mode
)
3947 (outline-isearch-advancing-business))
3948 (let ((outline-search-quitting t
)
3949 (outline-search-reconceal nil
))
3950 (real-isearch-terminate)))
3951 ;;;_ > isearch-done/outline-provisions ()
3952 (defun isearch-done/outline-provisions
(&optional nopush
)
3954 (if (and (outline-mode-p) outline-enwrap-isearch-mode
)
3955 (progn (if (and outline-search-reconceal
3956 (not (listp outline-search-reconceal
)))
3957 ;; The topic was concealed - reveal it, its siblings,
3958 ;; and any ancestors that are still concealed:
3960 (message "(exposing destination)")(sit-for 0)
3961 (outline-goto-prefix)
3962 ; There may be a closed blank
3963 ; line between prior and
3964 ; current topic that would be
3965 ; missed - provide for it:
3967 (progn (forward-char -
1) ; newline
3968 (if (eq ?
\r (preceding-char))
3969 (outline-flag-region (1- (point))
3974 (outline-ascend-to-depth (1- (outline-recent-depth)))
3975 (outline-show-children)))
3976 (if (and (boundp 'outline-search-quitting
)
3977 outline-search-quitting
)
3979 ; We're concluding abort:
3980 (outline-isearch-arrival-business)
3981 (outline-show-children))))
3983 ;; isearch-done in newer version of isearch mode takes arg:
3984 (real-isearch-done nopush
)
3985 (real-isearch-done)))
3986 ;;;_ > isearch-update/outline-provisions ()
3987 (defun isearch-update/outline-provisions
()
3988 "Wrapper dynamically adjusts isearch target exposure.
3990 Appropriately exposes and reconceals hidden outline portions, as
3991 necessary, in the course of searching."
3992 (if (not (and (outline-mode-p) outline-enwrap-isearch-mode
))
3993 ;; Just do the plain business:
3994 (real-isearch-update)
3996 ;; Ah - provide for outline conditions:
3997 (outline-isearch-advancing-business)
3998 (real-isearch-update)
3999 (cond (isearch-success (outline-isearch-arrival-business))
4000 ((not isearch-success
) (outline-isearch-advancing-business)))))
4002 ;;;_ #8 Copying and printing
4005 ;;;_ > outline-insert-listified (depth prefix bullet text)
4006 (defun outline-insert-listified (depth prefix bullet text
)
4007 "Insert contents of listified outline portion in current buffer."
4008 (insert-string (concat (if (> depth
1) prefix
"")
4009 (make-string (1- depth
) ?\
)
4012 (insert-string (car text
))
4013 (if (setq text
(cdr text
))
4014 (insert-string "\n")))
4015 (insert-string "\n"))
4016 ;;;_ > outline-copy-exposed (arg &optional tobuf)
4017 (defun outline-copy-exposed (arg &optional tobuf
)
4018 "Duplicate exposed portions of current topic to another buffer.
4020 Other buffer has current buffers' name with \" exposed\" appended to it.
4022 With repeat count, copy the exposed portions of entire buffer."
4026 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
4027 (let* ((start-pt (point))
4028 (beg (if arg
(point-min) (outline-back-to-current-heading)))
4029 (end (if arg
(point-max) (outline-end-of-current-subtree)))
4030 (buf (current-buffer)))
4031 (save-excursion (set-buffer tobuf
)(erase-buffer))
4032 (outline-process-exposed 'outline-insert-listified
4037 (goto-char (point-min))
4039 (goto-char start-pt
)))
4041 ;;;_ - LaTeX formatting
4042 ;;;_ > outline-latex-verb-quote (str &optional flow)
4043 (defun outline-latex-verb-quote (str &optional flow
)
4044 "Return copy of STRING for literal reproduction across latex processing.
4045 Expresses the original characters \(including carriage returns) of the
4046 string across latex processing."
4047 (mapconcat '(lambda (char)
4048 ;;;mess: (cond ((memq char '(?"" ?$ ?% ?# ?& ?- ?" ?` ?^ ?- ?*));;;"))))
4049 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
4050 (concat "\\char" (number-to-string char
) "{}"))
4051 ((= char ?
\n) "\\\\")
4052 (t (char-to-string char
))))
4055 ;;;_ > outline-latex-verbatim-quote-curr-line ()
4056 (defun outline-latex-verbatim-quote-curr-line ()
4057 "Express line for exact \(literal\) representation across latex processing.
4059 Adjust line contents so it is unaltered \(from the original line)
4060 across latex processing, within the context of a `verbatim'
4061 environment. Leaves point at the end of the line."
4064 (end (progn (end-of-line)(point))))
4066 (while (re-search-forward "\\\\"
4067 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
4068 end
; bounded by end-of-line
4069 1) ; no matches, move to end & return nil
4070 (goto-char (match-beginning 0))
4071 (insert-string "\\")
4073 (goto-char (1+ (match-end 0))))))
4074 ;;;_ > outline-insert-latex-header (buf)
4075 (defun outline-insert-latex-header (buf)
4076 "Insert initial latex commands at point in BUFFER."
4077 ;; Much of this is being derived from the stuff in appendix of E in
4078 ;; the TeXBook, pg 421.
4080 (let ((doc-style (format "\n\\documentstyle{%s}\n"
4082 (page-numbering (if outline-number-pages
4083 "\\pagestyle{empty}\n"
4085 (linesdef (concat "\\def\\beginlines{"
4086 "\\par\\begingroup\\nobreak\\medskip"
4088 " \\kern1pt\\nobreak \\obeylines \\obeyspaces "
4089 "\\everypar{\\strut}}\n"
4091 "\\kern1pt\\endgroup\\medbreak\\noindent}\n"))
4092 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
4093 outline-title-style
))
4094 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
4095 outline-label-style
))
4096 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
4097 outline-head-line-style
))
4098 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
4099 outline-body-line-style
))
4100 (setlength (format "%s%s%s%s"
4101 "\\newlength{\\stepsize}\n"
4102 "\\setlength{\\stepsize}{"
4105 (oneheadline (format "%s%s%s%s%s%s%s"
4106 "\\newcommand{\\OneHeadLine}[3]{%\n"
4108 "\\hspace*{#2\\stepsize}%\n"
4109 "\\labelcmd{#1}\\hspace*{.2cm}"
4110 "\\headlinecmd{#3}\\\\["
4113 (onebodyline (format "%s%s%s%s%s%s"
4114 "\\newcommand{\\OneBodyLine}[2]{%\n"
4116 "\\hspace*{#1\\stepsize}%\n"
4117 "\\bodylinecmd{#2}\\\\["
4120 (begindoc "\\begin{document}\n\\begin{center}\n")
4121 (title (format "%s%s%s%s"
4123 (outline-latex-verb-quote (if outline-title
4125 (eval outline-title
)
4126 (error "<unnamed buffer>"))
4129 "\\end{center}\n\n"))
4130 (hsize "\\hsize = 7.5 true in\n")
4131 (hoffset "\\hoffset = -1.5 true in\n")
4132 (vspace "\\vspace{.1cm}\n\n"))
4133 (insert (concat doc-style
4148 ;;;_ > outline-insert-latex-trailer (buf)
4149 (defun outline-insert-latex-trailer (buf)
4150 "Insert concluding latex commands at point in BUFFER."
4152 (insert "\n\\end{document}\n"))
4153 ;;;_ > outline-latexify-one-item (depth prefix bullet text)
4154 (defun outline-latexify-one-item (depth prefix bullet text
)
4155 "Insert LaTeX commands for formatting one outline item.
4157 Args are the topics' numeric DEPTH, the header PREFIX lead string, the
4158 BULLET string, and a list of TEXT strings for the body."
4159 (let* ((head-line (if text
(car text
)))
4160 (body-lines (cdr text
))
4164 (insert-string (concat "\\OneHeadLine{\\verb\1 "
4165 (outline-latex-verb-quote bullet
)
4170 (outline-latex-verb-quote head-line
)
4173 (if (not body-lines
)
4175 ;;(insert-string "\\beginlines\n")
4176 (insert-string "\\begin{verbatim}\n")
4178 (setq curr-line
(car body-lines
))
4179 (if (and (not body-content
)
4180 (not (string-match "^\\s-*$" curr-line
)))
4181 (setq body-content t
))
4182 ; Mangle any occurrences of
4183 ; "\end{verbatim}" in text,
4185 (if (and body-content
4186 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
4187 (setq curr-line
(concat (substring curr-line
0 bop
)
4189 (substring curr-line bop
))))
4190 ;;(insert-string "|" (car body-lines) "|")
4191 (insert-string curr-line
)
4192 (outline-latex-verbatim-quote-curr-line)
4193 (insert-string "\n")
4194 (setq body-lines
(cdr body-lines
)))
4196 (setq body-content nil
)
4198 (insert-string "\\ ")
4200 ;;(insert-string "\\endlines\n")
4201 (insert-string "\\end{verbatim}\n")
4203 ;;;_ > outline-latexify-exposed (arg &optional tobuf)
4204 (defun outline-latexify-exposed (arg &optional tobuf
)
4205 "Format current topic's exposed portions to TOBUF for latex processing.
4206 TOBUF defaults to a buffer named the same as the current buffer, but
4207 with \"*\" prepended and \" latex-formed*\" appended.
4209 With repeat count, copy the exposed portions of entire buffer."
4214 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
4215 (let* ((start-pt (point))
4216 (beg (if arg
(point-min) (outline-back-to-current-heading)))
4217 (end (if arg
(point-max) (outline-end-of-current-subtree)))
4218 (buf (current-buffer)))
4221 (outline-insert-latex-header tobuf
)
4222 (goto-char (point-max))
4223 (outline-process-exposed 'outline-latexify-one-item
4228 (goto-char (point-max))
4229 (outline-insert-latex-trailer tobuf
)
4230 (goto-char (point-min))
4232 (goto-char start-pt
)))
4234 ;;;_ #9 miscellaneous
4235 ;;;_ > outline-mark-topic ()
4236 (defun outline-mark-topic ()
4237 "Put the region around topic currently containing point."
4240 (outline-goto-prefix)
4242 (outline-end-of-current-subtree)
4243 (exchange-point-and-mark))
4244 ;;;_ > outlineify-sticky ()
4245 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
4246 (defalias 'outlinify-sticky
'outlineify-sticky
)
4247 (defun outlineify-sticky (&optional arg
)
4248 "Activate outline mode and establish file var so it is started subsequently.
4250 See doc-string for `outline-layout' and `outline-init' for details on
4251 setup for auto-startup."
4258 (goto-char (point-min))
4259 (if (looking-at outline-regexp
)
4261 (outline-open-topic 2)
4262 (insert-string (concat "Dummy outline topic header - see"
4263 "`outline-mode' docstring for info."))
4265 (goto-char (point-max))
4267 (outline-open-topic 0)
4268 (insert-string "Local emacs vars.\n")
4269 (outline-open-topic 1)
4270 (insert-string "(`outline-layout' is for allout.el outline-mode)\n")
4271 (outline-open-topic 0)
4272 (insert-string "Local variables:\n")
4273 (outline-open-topic 0)
4274 (insert-string (format "outline-layout: %s\n"
4277 (outline-open-topic 0)
4278 (insert-string "End:\n"))))
4279 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
4280 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
4281 "Solicit (with first arg PROMPT) choice of a character from string STRING.
4283 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
4285 (let ((new-prompt prompt
)
4289 (message "%s" new-prompt
)
4291 ;; We do our own reading here, so we can circumvent, eg, special
4292 ;; treatment for `?' character. (Might oughta change minibuffer
4293 ;; keymap instead, oh well.)
4295 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
4297 (if (null (string-match (regexp-quote got
) string
))
4298 (if (and do-defaulting
(string= got
"\^M"))
4299 ;; We're defaulting, return null string to indicate that:
4301 ;; Failed match and not defaulting,
4302 ;; set the prompt to give feedback,
4303 (setq new-prompt
(concat prompt
4308 ;; and set loop to try again:
4310 ;; Got a match - give feedback:
4312 ;; got something out of loop - return it:
4315 ;;;_ > regexp-sans-escapes (string)
4316 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
4317 "Return a copy of REGEXP with all character escapes stripped out.
4319 Representations of actual backslashes - '\\\\\\\\' - are left as a
4322 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
4324 (if (string= regexp
"")
4326 ;; Set successive-backslashes to number if current char is
4327 ;; backslash, or else to nil:
4328 (setq successive-backslashes
4329 (if (= (aref regexp
0) ?
\\)
4330 (if successive-backslashes
(1+ successive-backslashes
) 1)
4332 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
4333 ;; Include first char:
4334 (concat (substring regexp
0 1)
4335 (regexp-sans-escapes (substring regexp
1)))
4336 ;; Exclude first char, but maintain count:
4337 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
4338 ;;;_ - add-hook definition for divergent emacsen
4339 ;;;_ > add-hook (hook function &optional append)
4340 (if (not (fboundp 'add-hook
))
4341 (defun add-hook (hook function
&optional append
)
4342 "Add to the value of HOOK the function FUNCTION unless already present.
4343 \(It becomes the first hook on the list unless optional APPEND is non-nil, in
4344 which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
4345 any valid function. HOOK's value should be a list of functions, not a single
4346 function. If HOOK is void, it is first set to nil."
4347 (or (boundp hook
) (set hook nil
))
4348 (or (if (consp function
)
4349 ;; Clever way to tell whether a given lambda-expression
4350 ;; is equal to anything in the hook.
4351 (let ((tail (assoc (cdr function
) (symbol-value hook
))))
4352 (equal function tail
))
4353 (memq function
(symbol-value hook
)))
4356 (nconc (symbol-value hook
) (list function
))
4357 (cons function
(symbol-value hook
)))))))
4359 ;;;_ #10 Under development
4360 ;;;_ > outline-bullet-isearch (&optional bullet)
4361 (defun outline-bullet-isearch (&optional bullet
)
4362 "Isearch \(regexp\) for topic with bullet BULLET."
4365 (setq bullet
(solicit-char-in-string
4366 "ISearch for topic with bullet: "
4367 (regexp-sans-escapes outline-bullets-string
))))
4369 (let ((isearch-regexp t
)
4370 (isearch-string (concat "^"
4371 outline-header-prefix
4374 (isearch-repeat 'forward
)
4376 ;;;_ ? Re hooking up with isearch - use isearch-op-fun rather than
4377 ;;; wrapping the isearch functions.
4379 ;;;_* Local emacs vars.
4380 ;;; The following `outline-layout' local variable setting:
4381 ;;; - closes all topics from the first topic to just before the third-to-last,
4382 ;;; - shows the children of the third to last (config vars)
4383 ;;; - and the second to last (code section),
4384 ;;; - and closes the last topic (this local-variables section).
4386 ;;;outline-layout: (0 : -1 -1 0)
4389 ;; allout.el ends here