1 ;;;_* allout.el - Extensive outline mode for use alone and with other modes.
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <klm@nist.gov>
6 ;; Maintainer: Ken Manheimer <klm@nist.gov>
7 ;; Created: Dec 1991 - first release to usenet
8 ;; Version: Id: allout.el,v 4.3 1994/05/12 17:43:08 klm Exp ||
9 ;; Keywords: outline mode
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
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
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;; Allout outline mode provides extensive outline formatting and
30 ;; manipulation capabilities, subsuming and well beyond that of
31 ;; standard emacs outline mode. It is specifically aimed at
32 ;; supporting outline structuring and manipulation of syntax-
33 ;; sensitive text, eg programming languages. (For an example, see the
34 ;; allout code itself, which is organized in outline structure.)
36 ;; It also includes such things as topic-oriented repositioning, cut, and
37 ;; paste; integral outline exposure-layout; incremental search with
38 ;; dynamic exposure/conceament of concealed text; automatic topic-number
39 ;; maintenance; and many other features.
41 ;; See the docstring of the variables `outline-layout' and
42 ;; `outline-auto-activation' for details on automatic activation of
43 ;; allout outline-mode as a minor mode. (It has changed since allout
44 ;; 3.x, for those of you that depend on the old method.)
46 ;; Note - the lines beginning with ';;;_' are outline topic headers.
47 ;; Just 'ESC-x eval-current-buffer' to give it a whirl.
49 ;;Ken Manheimer 301 975-3539
50 ;;ken.manheimer@nist.gov FAX: 301 963-9137
52 ;;Computer Systems and Communications Division
54 ;; Nat'l Institute of Standards and Technology
56 ;; Gaithersburg, MD 20899
62 ;;;_* USER CUSTOMIZATION VARIABLES:
64 ;;;_ + Layout, Mode, and Topic Header Configuration
66 ;;;_ = outline-auto-activation
67 (defvar outline-auto-activation nil
68 "*Regulates auto-activation modality of allout outlines - see `outline-init'.
70 Setq-default by `outline-init' to regulate whether or not allout
71 outline mode is automatically activated when the buffer-specific
72 variable `outline-layout' is non-nil, and whether or not the layout
73 dictated by `outline-layout' should be imposed on mode activation.
75 With value `t', auto-mode-activation and auto-layout are enabled.
76 \(This also depends on `outline-find-file-hooks' being installed in
77 `find-file-hooks', which is also done by `outline-init'.)
79 With value `ask', auto-mode-activation is enabled, and endorsement for
80 performing auto-layout is asked of the user each time.
82 With value `activate', only auto-mode-activation is enabled, auto-
85 With value `nil', neither auto-mode-activation nor auto-layout are
88 See the docstring for `outline-init' for the proper interface to
91 (defvar outline-layout nil
92 "*Layout specification and provisional mode trigger for allout outlines.
96 A list value specifies a default layout for the current buffer, to be
97 applied upon activation of allout outline-mode. Any non-nil value
98 will automatically trigger allout outline-mode, provided `outline-
99 init' has been called to enable it.
101 See the docstring for `outline-init' for details on setting up for
102 auto-mode-activation, and for `outline-expose-topic' for the format of
103 the layout specification.
105 You can associate a particular outline layout with a file by setting
106 this var via the file's local variables. For example, the following
107 lines at the bottom of an elisp file:
110 ;;;outline-layout: \(0 : -1 -1 0\)
113 will, modulo the above-mentioned conditions, cause the mode to be
114 activated when the file is visited, followed by the equivalent of
115 `\(outline-expose-topic 0 : -1 -1 0\)'. \(This is the layout used for
116 the allout.el, itself.)
118 Also, allout's mode-specific provisions will make topic prefixes
119 default to the comment-start string, if any, of the language of the
120 file. This is modulo the setting of `outline-use-mode-specific-
121 leader', which see.")
122 (make-variable-buffer-local 'outline-layout
)
124 ;;;_ = outline-header-prefix
125 (defvar outline-header-prefix
"."
126 "*Leading string which helps distinguish topic headers.
128 Outline topic header lines are identified by a leading topic
129 header prefix, which mostly have the value of this var at their front.
130 \(Level 1 topics are exceptions. They consist of only a single
131 character, which is typically set to the outline-primary-bullet. Many
132 outlines start at level 2 to avoid this discrepancy.")
133 (make-variable-buffer-local 'outline-header-prefix
)
134 ;;;_ = outline-primary-bullet
135 (defvar outline-primary-bullet
"*"
136 "Bullet used for top-level outline topics.
138 Outline topic header lines are identified by a leading topic header
139 prefix, which is concluded by bullets that includes the value of this
140 var and the respective outline-*-bullets-string vars.
142 The value of an asterisk ('*') provides for backwards compatability
143 with the original emacs outline mode. See outline-plain-bullets-string
144 and outline-distinctive-bullets-string for the range of available
146 (make-variable-buffer-local 'outline-primary-bullet
)
147 ;;;_ = outline-plain-bullets-string
148 (defvar outline-plain-bullets-string
(concat outline-primary-bullet
150 "*The bullets normally used in outline topic prefixes.
152 See 'outline-distinctive-bullets-string' for the other kind of
155 DO NOT include the close-square-bracket, ']', as a bullet.
157 Outline mode has to be reactivated in order for changes to the value
158 of this var to take effect.")
159 (make-variable-buffer-local 'outline-plain-bullets-string
)
160 ;;;_ = outline-distinctive-bullets-string
161 (defvar outline-distinctive-bullets-string
"=>([{}&!?#%\"X@$~\\"
162 "*Persistent outline header bullets used to distinguish special topics.
164 These bullets are not offered among the regular, level-specific
165 rotation, and are not altered by automatic rebulleting, as when
166 shifting the level of a topic. See `outline-plain-bullets-string' for
167 the selection of alternating bullets.
169 You must run 'set-outline-regexp' in order for changes
170 to the value of this var to effect outline-mode operation.
172 DO NOT include the close-square-bracket, ']', on either of the bullet
174 (make-variable-buffer-local 'outline-distinctive-bullets-string
)
176 ;;;_ = outline-use-mode-specific-leader
177 (defvar outline-use-mode-specific-leader t
178 "*When non-nil, use mode-specific topic-header prefixes.
180 Allout outline mode will use the mode-specific `outline-mode-leaders'
181 and/or comment-start string, if any, to lead the topic prefix string,
182 so topic headers look like comments in the programming language.
184 String values are used as they stand.
186 Value `t' means to first check for assoc value in `outline-mode-leaders'
187 alist, then use comment-start string, if any, then use default \(`.').
188 \(See note about use of comment-start strings, below.\)
190 Set to the symbol for either of `outline-mode-leaders' or
191 `comment-start' to use only one of them, respectively.
193 Value `nil' means to always use the default \(`.'\).
195 comment-start strings that do not end in spaces are tripled, and an
196 '_' underscore is tacked on the end, to distinguish them from regular
197 comment strings. comment-start strings that do end in spaces are not
198 tripled, but an underscore is substituted for the space. \[This
199 presumes that the space is for appearance, not comment syntax. You
200 can use `outline-mode-leaders' to override this behavior, when
202 ;;;_ = outline-mode-leaders
203 (defvar outline-mode-leaders
'()
204 "Specific outline-prefix leading strings per major modes.
206 Entries will be used in the stead (or lieu) of mode-specific
207 comment-start strings. See also `outline-use-mode-specific-leader'.
209 If you're constructing a string that will comment-out outline
210 structuring so it can be included in program code, append an extra
211 character, like an \"_\" underscore, to distinguish the lead string
212 from regular comments that start at bol.")
214 ;;;_ = outline-old-style-prefixes
215 (defvar outline-old-style-prefixes nil
216 "*When non-nil, use only old-and-crusty outline-mode '*' topic prefixes.
218 Non-nil restricts the topic creation and modification
219 functions to asterix-padded prefixes, so they look exactly
220 like the original emacs-outline style prefixes.
222 Whatever the setting of this variable, both old and new style prefixes
223 are always respected by the topic maneuvering functions.")
224 (make-variable-buffer-local 'outline-old-style-prefixes
)
225 ;;;_ = outline-stylish-prefixes - alternating bullets
226 (defvar outline-stylish-prefixes t
227 "*Do fancy stuff with topic prefix bullets according to level, etc.
229 Non-nil enables topic creation, modification, and repositioning
230 functions to vary the topic bullet char (the char that marks the topic
231 depth) just preceding the start of the topic text) according to level.
232 Otherwise, only asterisks ('*') and distinctive bullets are used.
234 This is how an outline can look (but sans indentation) with stylish
239 . + One level 3 subtopic
240 . . One level 4 subtopic
241 . . A second 4 subtopic
242 . + Another level 3 subtopic
243 . #1 A numbered level 4 subtopic
245 . ! Another level 4 subtopic with a different distinctive bullet
246 . #4 And another numbered level 4 subtopic
248 This would be an outline with stylish prefixes inhibited (but the
249 numbered and other distinctive bullets retained):
253 . * One level 3 subtopic
254 . * One level 4 subtopic
255 . * A second 4 subtopic
256 . * Another level 3 subtopic
257 . #1 A numbered level 4 subtopic
259 . ! Another level 4 subtopic with a different distinctive bullet
260 . #4 And another numbered level 4 subtopic
262 Stylish and constant prefixes (as well as old-style prefixes) are
263 always respected by the topic maneuvering functions, regardless of
264 this variable setting.
266 The setting of this var is not relevant when outline-old-style-prefixes
268 (make-variable-buffer-local 'outline-stylish-prefixes
)
270 ;;;_ = outline-numbered-bullet
271 (defvar outline-numbered-bullet
"#"
272 "*String designating bullet of topics that have auto-numbering; nil for none.
274 Topics having this bullet have automatic maintainence of a sibling
275 sequence-number tacked on, just after the bullet. Conventionally set
276 to \"#\", you can set it to a bullet of your choice. A nil value
277 disables numbering maintainence.")
278 (make-variable-buffer-local 'outline-numbered-bullet
)
279 ;;;_ = outline-file-xref-bullet
280 (defvar outline-file-xref-bullet
"@"
281 "*Bullet signifying file cross-references, for `outline-resolve-xref'.
283 Set this var to the bullet you want to use for file cross-references.
284 Set it 'nil' if you want to inhibit this capability.")
286 ;;;_ + LaTeX formatting
287 ;;;_ - outline-number-pages
288 (defvar outline-number-pages nil
289 "*Non-nil turns on page numbering for LaTeX formatting of an outline.")
290 ;;;_ - outline-label-style
291 (defvar outline-label-style
"\\large\\bf"
292 "*Font and size of labels for LaTeX formatting of an outline.")
293 ;;;_ - outline-head-line-style
294 (defvar outline-head-line-style
"\\large\\sl "
295 "*Font and size of entries for LaTeX formatting of an outline.")
296 ;;;_ - outline-body-line-style
297 (defvar outline-body-line-style
" "
298 "*Font and size of entries for LaTeX formatting of an outline.")
299 ;;;_ - outline-title-style
300 (defvar outline-title-style
"\\Large\\bf"
301 "*Font and size of titles for LaTeX formatting of an outline.")
303 (defvar outline-title
'(or buffer-file-name
(current-buffer-name))
304 "*Expression to be evaluated to determine the title for LaTeX
306 ;;;_ - outline-line-skip
307 (defvar outline-line-skip
".05cm"
308 "*Space between lines for LaTeX formatting of an outline.")
309 ;;;_ - outline-indent
310 (defvar outline-indent
".3cm"
311 "*LaTeX formatted depth-indent spacing.")
313 ;;;_ + Miscellaneous customization
315 ;;;_ = outline-keybindings-list
316 ;;; You have to reactivate outline-mode - '(outline-mode t)' - to
317 ;;; institute changes to this var.
318 (defvar outline-keybindings-list
()
319 "*List of outline-mode key / function bindings.
321 These bindings will be locally bound on the outline-mode-map. The
322 keys will be prefixed by outline-command-prefix, unless the cell
323 contains a third, no-nil element, in which case the initial string
324 will be used as is.")
325 (setq outline-keybindings-list
328 ("?t" outline-latexify-exposed
)
329 ("\C-n" outline-next-visible-heading
)
330 ("\C-p" outline-previous-visible-heading
)
331 ("\C-u" outline-up-current-level
)
332 ("\C-f" outline-forward-current-level
)
333 ("\C-b" outline-backward-current-level
)
334 ("\C-a" outline-beginning-of-current-entry
)
335 ("\C-e" outline-end-of-current-entry
)
336 ;;("\C-n" outline-next-line-or-topic)
337 ;;("\C-p" outline-previous-line-or-topic)
339 ("\C-i" outline-show-children
)
340 ("\C-s" outline-show-current-subtree
)
341 ("\C-h" outline-hide-current-subtree
)
342 ("\C-o" outline-show-current-entry
)
343 ("!" outline-show-all
)
344 ; Alteration commands:
345 (" " outline-open-sibtopic
)
346 ("." outline-open-subtopic
)
347 ("," outline-open-supertopic
)
348 ("'" outline-shift-in
)
349 (">" outline-shift-in
)
350 ("<" outline-shift-out
)
351 ("\C-m" outline-rebullet-topic
)
352 ("b" outline-rebullet-current-heading
)
353 ("#" outline-number-siblings
)
354 ("\C-k" outline-kill-line t
)
355 ("\C-y" outline-yank t
)
356 ("\M-y" outline-yank-pop t
)
357 ("\C-k" outline-kill-topic
)
358 ; Miscellaneous commands:
359 ("\C-@" outline-mark-topic
)
360 ("@" outline-resolve-xref
)
361 ("?c" outline-copy-exposed
)))
363 ;;;_ = outline-command-prefix
364 (defvar outline-command-prefix
"\C-c"
365 "*Key sequence to be used as prefix for outline mode command key bindings.")
367 ;;;_ = outline-enwrap-isearch-mode
368 (defvar outline-enwrap-isearch-mode t
369 "*Set non-nil to enable automatic exposure of concealed isearch targets.
371 If non-nil, isearch will expose hidden text encountered in the course
372 of a search, and to reconceal it if the search is continued past it.")
374 ;;;_ = outline-use-hanging-indents
375 (defvar outline-use-hanging-indents t
376 "*If non-nil, topic body text auto-indent defaults to indent of the header.
377 Ie, it is indented to be just past the header prefix. This is
378 relevant mostly for use with indented-text-mode, or other situations
379 where auto-fill occurs.
381 [This feature no longer depends in any way on the 'filladapt.el'
382 lisp-archive package.]")
383 (make-variable-buffer-local 'outline-use-hanging-indents
)
385 ;;;_ = outline-reindent-bodies
386 (defvar outline-reindent-bodies
(if outline-use-hanging-indents
388 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
390 When active, topic body lines that are indented even with or beyond
391 their topic header are reindented to correspond with depth shifts of
394 A value of `t' enables reindent in non-programming-code buffers, ie
395 those that do not have the variable `comment-start' set. A value of
396 `force' enables reindent whether or not `comment-start' is set.")
398 (make-variable-buffer-local 'outline-reindent-bodies
)
400 ;;;_ = outline-inhibit-protection
401 (defvar outline-inhibit-protection nil
402 "*Non-nil disables warnings and confirmation-checks for concealed-text edits.
404 Outline mode uses emacs change-triggered functions to detect unruly
405 changes to concealed regions. Set this var non-nil to disable the
406 protection, potentially increasing text-entry responsiveness a bit.
408 This var takes effect at outline-mode activation, so you may have to
409 deactivate and then reactivate the mode if you want to toggle the
412 ;;;_* CODE - no user customizations below.
414 ;;;_ #1 Internal Outline Formatting and Configuration
416 ;;;_ = outline-version
417 (defvar outline-version
418 (let ((rcs-rev "Revision: 4.3"))
421 (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev
)
422 (substring rcs-rev
(match-beginning 1) (match-end 1)))
424 "Revision number of currently loaded outline package. \(allout.el)")
425 ;;;_ > outline-version
426 (defun outline-version (&optional here
)
427 "Return string describing the loaded outline version."
429 (let ((msg (concat "Allout Outline Mode v " outline-version
)))
430 (if here
(insert-string msg
))
433 ;;;_ - Topic header format
434 ;;;_ = outline-regexp
435 (defvar outline-regexp
""
436 "*Regular expression to match the beginning of a heading line.
438 Any line whose beginning matches this regexp is considered a
439 heading. This var is set according to the user configuration vars
440 by set-outline-regexp.")
441 (make-variable-buffer-local 'outline-regexp
)
442 ;;;_ = outline-bullets-string
443 (defvar outline-bullets-string
""
444 "A string dictating the valid set of outline topic bullets.
446 This var should *not* be set by the user - it is set by 'set-outline-regexp',
447 and is produced from the elements of 'outline-plain-bullets-string'
448 and 'outline-distinctive-bullets-string'.")
449 (make-variable-buffer-local 'outline-bullets-string
)
450 ;;;_ = outline-bullets-string-len
451 (defvar outline-bullets-string-len
0
452 "Length of current buffers' outline-plain-bullets-string.")
453 (make-variable-buffer-local 'outline-bullets-string-len
)
454 ;;;_ = outline-line-boundary-regexp
455 (defvar outline-line-boundary-regexp
()
456 "Outline-regexp with outline-style beginning-of-line anchor.
458 \(Ie, C-j, *or* C-m, for prefixes of hidden topics). This is properly
459 set when outline-regexp is produced by 'set-outline-regexp', so
460 that (match-beginning 2) and (match-end 2) delimit the prefix.")
461 (make-variable-buffer-local 'outline-line-boundary-regexp
)
462 ;;;_ = outline-bob-regexp
463 (defvar outline-bob-regexp
()
464 "Like outline-line-boundary-regexp, for headers at beginning of buffer.
465 \(match-beginning 2) and (match-end 2) delimit the prefix.")
466 (make-variable-buffer-local 'outline-bob-regexp
)
467 ;;;_ = outline-header-subtraction
468 (defvar outline-header-subtraction
(1- (length outline-header-prefix
))
469 "Outline-header prefix length to subtract when computing topic depth.")
470 (make-variable-buffer-local 'outline-header-subtraction
)
471 ;;;_ = outline-plain-bullets-string-len
472 (defvar outline-plain-bullets-string-len
(length outline-plain-bullets-string
)
473 "Length of outline-plain-bullets-string, updated by set-outline-regexp.")
474 (make-variable-buffer-local 'outline-plain-bullets-string-len
)
477 ;;;_ X outline-reset-header-lead (header-lead)
478 (defun outline-reset-header-lead (header-lead)
479 "*Reset the leading string used to identify topic headers."
480 (interactive "sNew lead string: ")
481 (setq outline-header-prefix header-lead
)
482 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
483 (set-outline-regexp))
484 ;;;_ X outline-lead-with-comment-string (header-lead)
485 (defun outline-lead-with-comment-string (&optional header-lead
)
486 "*Set the topic-header leading string to specified string.
488 Useful when for encapsulating outline structure in programming
489 language comments. Returns the leading string."
492 (if (not (stringp header-lead
))
493 (setq header-lead
(read-string
494 "String prefix for topic headers: ")))
495 (setq outline-reindent-bodies nil
)
496 (outline-reset-header-lead header-lead
)
498 ;;;_ > outline-infer-header-lead ()
499 (defun outline-infer-header-lead ()
500 "Determine appropriate `outline-header-prefix'.
502 Works according to settings of:
505 `outline-header-prefix' (default)
506 `outline-use-mode-specific-leader'
507 and `outline-mode-leaders'.
509 Apply this via \(re\)activation of `outline-mode', rather than
510 invoking it directly."
511 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader
)
512 (if (or (stringp outline-use-mode-specific-leader
)
513 (memq outline-use-mode-specific-leader
514 '(outline-mode-leaders
517 outline-use-mode-specific-leader
518 ;; Oops - garbled value, equate with effect of 't:
522 ((not use-leader
) nil
)
523 ;; Use the explicitly designated leader:
524 ((stringp use-leader
) use-leader
)
525 (t (or (and (memq use-leader
'(t outline-mode-leaders
))
526 ;; Get it from outline mode leaders?
527 (cdr (assq major-mode outline-mode-leaders
)))
528 ;; ... didn't get from outline-mode-leaders...
529 (and (memq use-leader
'(t comment-start
))
531 ;; Use comment-start, maybe tripled, and with
535 (substring comment-start
536 (1- (length comment-start
))))
537 ;; Use comment-start, sans trailing space:
538 (substring comment-start
0 -
1)
539 (concat comment-start comment-start comment-start
))
540 ;; ... and append underscore, whichever:
544 (if (string= leader outline-header-prefix
)
545 nil
; no change, nothing to do.
546 (setq outline-header-prefix leader
)
547 outline-header-prefix
))))
548 ;;;_ > outline-infer-body-reindent ()
549 (defun outline-infer-body-reindent ()
550 "Determine proper setting for `outline-reindent-bodies'.
552 Depends on default setting of `outline-reindent-bodies' \(which see)
553 and presence of setting for `comment-start', to tell whether the
554 file is programming code."
555 (if (and outline-reindent-bodies
557 (not (eq 'force outline-reindent-bodies
)))
558 (setq outline-reindent-bodies nil
)))
559 ;;;_ > set-outline-regexp ()
560 (defun set-outline-regexp ()
561 "Generate proper topic-header regexp form for outline functions.
563 Works with respect to `outline-plain-bullets-string' and
564 `outline-distinctive-bullets-string'."
567 ;; Derive outline-bullets-string from user configured components:
568 (setq outline-bullets-string
"")
569 (let ((strings (list 'outline-plain-bullets-string
570 'outline-distinctive-bullets-string
))
578 (setq new-string
"") (setq index
0)
579 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
580 (while (< index cur-len
)
581 (setq cur-char
(aref cur-string index
))
582 (setq outline-bullets-string
583 (concat outline-bullets-string
585 ; Single dash would denote a
586 ; sequence, repeated denotes
588 ((eq cur-char ?-
) "--")
589 ; literal close-square-bracket
590 ; doesn't work right in the
592 ((eq cur-char ?\
]) "")
593 (t (regexp-quote (char-to-string cur-char
))))))
594 (setq index
(1+ index
)))
595 (setq strings
(cdr strings
)))
597 ;; Derive next for repeated use in outline-pending-bullet:
598 (setq outline-plain-bullets-string-len
(length outline-plain-bullets-string
))
599 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
600 ;; Produce the new outline-regexp:
601 (setq outline-regexp
(concat "\\(\\"
602 outline-header-prefix
604 outline-bullets-string
606 outline-primary-bullet
608 (setq outline-line-boundary-regexp
609 (concat "\\([\n\r]\\)\\(" outline-regexp
"\\)"))
610 (setq outline-bob-regexp
611 (concat "\\(\\`\\)\\(" outline-regexp
"\\)"))
614 ;;;_ = outline-mode-map
615 (defvar outline-mode-map nil
"Keybindings for (allout) outline minor mode.")
616 ;;;_ > produce-outline-mode-map (keymap-alist &optional base-map)
617 (defun produce-outline-mode-map (keymap-list &optional base-map
)
618 "Produce keymap for use as outline-mode-map, from keymap-list.
620 Built on top of optional BASE-MAP, or empty sparse map if none specified.
621 See doc string for outline-keybindings-list for format of binding list."
622 (let ((map (or base-map
(make-sparse-keymap))))
623 (mapcar (lambda (cell)
624 (apply 'define-key map
(if (null (cdr (cdr cell
)))
625 (cons (concat outline-command-prefix
628 (list (car cell
) (car (cdr cell
))))))
631 ;;;_ = outline-prior-bindings - being deprecated.
632 (defvar outline-prior-bindings nil
633 "Variable for use in V18, with outline-added-bindings, for
634 resurrecting, on mode deactivation, bindings that existed before
635 activation. Being deprecated.")
636 ;;;_ = outline-added-bindings - being deprecated
637 (defvar outline-added-bindings nil
638 "Variable for use in V18, with outline-prior-bindings, for
639 resurrecting, on mode deactivation, bindings that existed before
640 activation. Being deprecated.")
641 ;;;_ - Mode-Specific Variable Maintenance Utilities
642 ;;;_ = outline-mode-prior-settings
643 (defvar outline-mode-prior-settings nil
644 "Internal outline mode use; settings to be resumed on mode deactivation.")
645 (make-variable-buffer-local 'outline-mode-prior-settings
)
646 ;;;_ > outline-resumptions (name &optional value)
647 (defun outline-resumptions (name &optional value
)
649 "Registers or resumes settings over outline-mode activation/deactivation.
651 First arg is NAME of variable affected. Optional second arg is list
652 containing outline-mode-specific VALUE to be imposed on named
653 variable, and to be registered. (It's a list so you can specify
654 registrations of null values.) If no value is specified, the
655 registered value is returned (encapsulated in the list, so the caller
656 can distinguish nil vs no value), and the registration is popped
659 (let ((on-list (assq name outline-mode-prior-settings
))
660 prior-capsule
; By 'capsule' i mean a list
661 ; containing a value, so we can
662 ; distinguish nil from no value.
670 nil
; Already preserved prior value - don't mess with it.
671 ;; Register the old value, or nil if previously unbound:
672 (setq outline-mode-prior-settings
674 (if (boundp name
) (list (symbol-value name
))))
675 outline-mode-prior-settings
)))
676 ; And impose the new value, locally:
677 (progn (make-local-variable name
)
678 (set name
(car value
))))
683 ;; Oops, not registered - leave it be:
686 ;; Some registration:
688 (setq prior-capsule
(car (cdr on-list
)))
690 (set name
(car prior-capsule
)) ; Some prior value - reestablish it.
691 (makunbound name
)) ; Previously unbound - demolish var.
692 ; Remove registration:
694 (while outline-mode-prior-settings
695 (if (not (eq (car outline-mode-prior-settings
)
698 (cons (car outline-mode-prior-settings
)
700 (setq outline-mode-prior-settings
701 (cdr outline-mode-prior-settings
)))
702 (setq outline-mode-prior-settings rebuild
)))))
704 ;;;_ - Mode-specific incidentals
705 ;;;_ = outline-during-write-cue nil
706 (defvar outline-during-write-cue nil
707 "Used to inhibit outline change-protection during file write.
709 See also `outline-post-command-business', `outline-write-file-hook',
710 `outline-before-change-protect', and `outline-post-command-business'
712 ;;;_ = outline-override-protect nil
713 (defvar outline-override-protect nil
714 "Used in outline-mode for regulate of concealed-text protection mechanism.
716 Allout outline mode regulates alteration of concealed text to protect
717 against inadvertant, unnoticed changes. This is for use by specific,
718 native outline functions to temporarily override that protection.
719 It's automatically reset to nil after every buffer modification.")
720 (make-variable-buffer-local 'outline-override-protect
)
721 ;;;_ > outline-unprotected (expr)
722 (defmacro outline-unprotected
(expr)
723 "Evaluate EXPRESSION with `outline-override-protect' let-bound 't'."
724 (` (let ((outline-override-protect t
))
726 ;;;_ = outline-undo-aggregation
727 (defvar outline-undo-aggregation
30
728 "Amount of successive self-insert actions to bunch together per undo.
730 This is purely a kludge variable, regulating the compensation for a bug in
731 the way that before-change-function and undo interact.")
732 (make-variable-buffer-local 'outline-undo-aggregation
)
733 ;;;_ = file-var-bug hack
734 (defvar outline-v18
/9-file-var-hack nil
735 "Horrible hack used to prevent invalid multiple triggering of outline
736 mode from prop-line file-var activation. Used by outline-mode function
738 ;;;_ > outline-write-file-hook ()
739 (defun outline-write-file-hook ()
740 "In outline mode, run as a local-write-file-hooks activity.
742 Currently just sets 'outline-during-write-cue', so outline-change-
743 protection knows to keep inactive during file write."
744 (setq outline-during-write-cue t
)
747 ;;;_ #2 Mode activation
749 (defvar outline-mode
() "Allout outline mode minor-mode flag.")
750 (make-variable-buffer-local 'outline-mode
)
751 ;;;_ > outline-mode-p ()
752 (defmacro outline-mode-p
()
753 "Return t if outline-mode is active in current buffer."
755 ;;;_ = outline-explicitly-deactivated
756 (defvar outline-explicitly-deactivated nil
757 "Outline-mode was last deliberately deactived.
758 So outline-post-command-business should not reactivate it...")
759 (make-variable-buffer-local 'outline-explicitly-deactivated
)
760 ;;;_ > outline-init (&optional mode)
761 (defun outline-init (&optional mode
)
762 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'.
764 MODE is one of the following symbols:
766 - nil \(or no argument) deactivate auto-activation/layou;
767 - 'activate', enable auto-activation only;
768 - 'ask', enable auto-activation, and enable auto-layout but with
769 confirmation for layout operation solicitated from user each time;
770 - 'report', just report and return the current auto-activation state;
771 - anything else \(eg, t) for auto-activation and auto-layout, without
772 any confirmation check.
774 Use this function to setup your emacs session for automatic activation
775 of allout outline mode, contingent to the buffer-specific setting of
776 the `outline-layout' variable. (See `outline-layout' and
777 `outline-expose-topic' docstrings for more details on auto layout).
779 `outline-init' works by setting up (or removing) the outline-mode
780 find-file-hook, and giving `outline-auto-activation' a suitable
783 To prime your emacs session for full auto-outline operation, include
784 the following two lines in your emacs init file:
794 (concat "Select outline auto setup mode "
795 "(empty for report, ? for options) ")
796 '(("nil")("full")("activate")("deactivate")
797 ("ask") ("report") (""))
800 (if (string= mode
"")
802 (setq mode
(intern-soft mode
)))))
804 ;; convenience aliases, for consistent ref to respective vars:
805 ((hook 'outline-find-file-hook
)
806 (curr-mode 'outline-auto-activation
))
809 (setq find-file-hooks
(delq hook find-file-hooks
))
811 (message "Allout outline mode auto-activation inhibited.")))
813 (if (not (memq hook find-file-hooks
))
815 ;; Just punt and use the reports from each of the modes:
816 (outline-init (symbol-value curr-mode
))))
817 (t (add-hook 'find-file-hooks hook
)
818 (set curr-mode
; 'set', not 'setq'!
819 (cond ((eq mode
'activate
)
821 "Outline mode auto-activation enabled.")
824 ;; Return the current mode setting:
828 (concat "Outline mode auto-activation and "
829 "-layout \(upon confirmation) enabled."))
832 "Outline mode auto-activation and -layout enabled.")
835 ;;;_ > outline-mode (&optional toggle)
837 (defun outline-mode (&optional toggle
)
839 "Toggle minor mode for controlling exposure and editing of text outlines.
841 Optional arg forces mode reactivation iff arg is positive num or symbol.
843 Allout outline mode provides extensive outline formatting and
844 manipulation capabilities. It is specifically aimed at supporting
845 outline structuring and manipulation of syntax-sensitive text, eg
846 programming languages. \(For an example, see the allout code itself,
847 which is organized in outline structure.\)
849 It also includes such things as topic-oriented repositioning, cut, and
850 paste; integral outline exposure-layout; incremental search with
851 dynamic exposure/conceament of concealed text; automatic topic-number
852 maintenance; and many other features.
854 See the docstring of the variable `outline-init' for instructions on
855 priming your emacs session for automatic activation of outline-mode,
856 according to file-var settings of the `outline-layout' variable.
858 Below is a description of the bindings, and then explanation of
859 special outline-mode features and terminology.
861 The bindings themselves are established according to the values of
862 variables `outline-keybindings-list' and `outline-command-prefix',
863 each time the mode is invoked. Prior bindings are resurrected when
866 Navigation: Exposure Control:
867 ---------- ----------------
868 C-c C-n outline-next-visible-heading | C-c C-h outline-hide-current-subtree
869 C-c C-p outline-previous-visible-heading | C-c C-i outline-show-children
870 C-c C-u outline-up-current-level | C-c C-s outline-show-current-subtree
871 C-c C-f outline-forward-current-level | C-c C-o outline-show-current-entry
872 C-c C-b outline-backward-current-level | ^U C-c C-s outline-show-all
873 C-c C-e outline-end-of-current-entry | outline-hide-current-leaves
874 C-c C-a outline-beginning-of-current-entry, alternately, goes to hot-spot
876 Topic Header Production:
877 -----------------------
878 C-c<SP> outline-open-sibtopic Create a new sibling after current topic.
879 C-c . outline-open-subtopic ... an offspring of current topic.
880 C-c , outline-open-supertopic ... a sibling of the current topic's parent.
882 Topic Level and Prefix Adjustment:
883 ---------------------------------
884 C-c > outline-shift-in Shift current topic and all offspring deeper.
885 C-c < outline-shift-out ... less deep.
886 C-c<CR> outline-rebullet-topic Reconcile bullets of topic and its' offspring
887 - distinctive bullets are not changed, others
888 alternated according to nesting depth.
889 C-c b outline-rebullet-current-heading Prompt for alternate bullet for
891 C-c # outline-number-siblings Number bullets of topic and siblings - the
892 offspring are not affected. With repeat
893 count, revoke numbering.
895 Topic-oriented Killing and Yanking:
896 ----------------------------------
897 C-c C-k outline-kill-topic Kill current topic, including offspring.
898 C-k outline-kill-line Like kill-line, but reconciles numbering, etc.
899 C-y outline-yank Yank, adjusting depth of yanked topic to
900 depth of heading if yanking into bare topic
901 heading (ie, prefix sans text).
902 M-y outline-yank-pop Is to outline-yank as yank-pop is to yank
906 C-c @ outline-resolve-xref pop-to-buffer named by xref (cf
907 outline-file-xref-bullet)
908 C-c c outline-copy-exposed Copy current topic outline sans concealed
909 text, to buffer with name derived from
910 current buffer - \"XXX exposed\"
911 M-x outlineify-sticky Activate outline mode for current buffer,
912 and establish a default file-var setting
913 for `outline-layout'.
914 ESC ESC (outline-init t) Setup emacs session for outline mode
919 Hot-spot operation provides a means for easy, single-keystroke outline
920 navigation and exposure control.
923 When the text cursor is positioned directly on the bullet character of
924 a topic, regular characters (a to z) invoke the commands of the
925 corresponding outline-mode keymap control chars. For example, \"f\"
926 would invoke the command typically bound to \"C-c C-f\"
927 \(\\[outline-forward-current-level] `outline-forward-current-level').
929 Thus, by positioning the cursor on a topic bullet, you can execute
930 the outline navigation and manipulation commands with a single
931 keystroke. Non-literal chars never get this special translation, so
932 you can use them to get away from the hot-spot, and back to normal
935 Note that the command `outline-beginning-of-current-entry' \(\\[outline-beginning-of-current-entry]\)
936 will move to the hot-spot when the cursor is already located at the
937 beginning of the current entry, so you can simply hit \\[outline-beginning-of-current-entry]
938 twice in a row to get to the hot-spot.
942 Topic hierarchy constituents - TOPICS and SUBTOPICS:
944 TOPIC: A basic, coherent component of an emacs outline. It can
945 contain other topics, and it can be subsumed by other topics,
947 The visible topic most immediately containing the cursor.
948 DEPTH: The degree of nesting of a topic; it increases with
949 containment. Also called the:
950 LEVEL: The same as DEPTH.
953 The topics that contain a topic.
954 PARENT: A topic's immediate ancestor. It has a depth one less than
957 The topics contained by a topic;
959 An immediate offspring of a topic;
961 The immediate offspring of a topic.
963 Topics having the same parent and depth.
965 Topic text constituents:
967 HEADER: The first line of a topic, include the topic PREFIX and header
969 PREFIX: The leading text of a topic which which distinguishes it from
970 normal text. It has a strict form, which consists of a
971 prefix-lead string, padding, and a bullet. The bullet may be
972 followed by a number, indicating the ordinal number of the
973 topic among its siblings, a space, and then the header text.
975 The relative length of the PREFIX determines the nesting depth
978 The string at the beginning of a topic prefix, normally a '.'.
979 It can be customized by changing the setting of
980 `outline-header-prefix' and then reinitializing outline-mode.
982 By setting the prefix-lead to the comment-string of a
983 programming language, you can embed outline-structuring in
984 program code without interfering with the language processing
985 of that code. See `outline-use-mode-specific-leader'
986 docstring for more detail.
988 Spaces or asterisks which separate the prefix-lead and the
989 bullet, according to the depth of the topic.
990 BULLET: A character at the end of the topic prefix, it must be one of
991 the characters listed on 'outline-plain-bullets-string' or
992 'outline-distinctive-bullets-string'. (See the documentation
993 for these variables for more details.) The default choice of
994 bullet when generating varies in a cycle with the depth of the
996 ENTRY: The text contained in a topic before any offspring.
1001 The state of a topic which determines the on-screen visibility
1002 of its' offspring and contained text.
1004 Topics and entry text whose display is inhibited. Contiguous
1005 units of concealed text is represented by '...' ellipses.
1006 (Ref the 'selective-display' var.)
1008 Concealed topics are effectively collapsed within an ancestor.
1009 CLOSED: A topic whose immediate offspring and body-text is concealed.
1010 OPEN: A topic that is not closed, though its' offspring or body may be."
1014 (let* ((active (and (not (equal major-mode
'outline
))
1016 ; Massage universal-arg 'toggle' val:
1018 (or (and (listp toggle
)(car toggle
))
1020 ; Activation specficially demanded?
1021 (explicit-activation (or
1024 (or (symbolp toggle
)
1025 (and (natnump toggle
)
1026 (not (zerop toggle
)))))))
1027 ;; outline-mode already called once during this complex command?
1028 (same-complex-command (eq outline-v18
/9-file-var-hack
1029 (car command-history
)))
1033 ; See comments below re v19.18,.19 bug.
1034 (setq outline-v18
/9-file-var-hack
(car command-history
))
1038 ;; Provision for v19.18, 19.19 bug -
1039 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1040 ;; modes twice when file is visited. We have to avoid toggling mode
1041 ;; off on second invocation, so we detect it as best we can, and
1043 ((and same-complex-command
; Still in same complex command
1044 ; as last time outline-mode invoked.
1045 active
; Already activated.
1046 (not explicit-activation
) ; Prop-line file-vars don't have args.
1047 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1048 emacs-version
)); 19.19.
1052 ((and (not explicit-activation
)
1054 ; Activation not explicitly
1055 ; requested, and either in
1056 ; active state or *de*activation
1057 ; specifically requested:
1058 (setq outline-explicitly-deactivated t
)
1059 (if (string-match "^18\." emacs-version
)
1060 ; Revoke those keys that remain
1062 (let ((curr-loc (current-local-map)))
1063 (mapcar '(lambda (cell)
1064 (if (eq (lookup-key curr-loc
(car cell
))
1066 (define-key curr-loc
(car cell
)
1067 (assq (car cell
) outline-prior-bindings
))))
1068 outline-added-bindings
)
1069 (outline-resumptions 'outline-added-bindings
)
1070 (outline-resumptions 'outline-prior-bindings
)))
1072 (if outline-old-style-prefixes
1074 (outline-resumptions 'outline-primary-bullet
)
1075 (outline-resumptions 'outline-old-style-prefixes
)))
1076 (outline-resumptions 'selective-display
)
1077 (if (and (boundp 'before-change-function
) before-change-function
)
1078 (outline-resumptions 'before-change-function
))
1079 (setq pre-command-hook
(delq 'outline-pre-command-business
1081 (setq local-write-file-hooks
1082 (delq 'outline-write-file-hook
1083 local-write-file-hooks
))
1084 (outline-resumptions 'paragraph-start
)
1085 (outline-resumptions 'paragraph-separate
)
1086 (outline-resumptions (if (string-match "^18" emacs-version
)
1088 'auto-fill-function
))
1089 (outline-resumptions 'outline-former-auto-filler
)
1090 (setq outline-mode nil
))
1094 (setq outline-explicitly-deactivated nil
)
1095 (if outline-old-style-prefixes
1096 (progn ; Inhibit all the fancy formatting:
1097 (outline-resumptions 'outline-primary-bullet
'("*"))
1098 (outline-resumptions 'outline-old-style-prefixes
'(()))))
1100 (outline-infer-header-lead)
1101 (outline-infer-body-reindent)
1103 (set-outline-regexp)
1105 ; Produce map from current version
1106 ; of outline-keybindings-list:
1107 (if (boundp 'minor-mode-map-alist
)
1109 (progn ; V19, and maybe lucid and
1110 ; epoch, minor-mode key bindings:
1111 (setq outline-mode-map
1112 (produce-outline-mode-map outline-keybindings-list
))
1113 (fset 'outline-mode-map outline-mode-map
)
1114 ; Include on minor-mode-map-alist,
1115 ; if not already there:
1116 (if (not (member '(outline-mode . outline-mode-map
)
1117 minor-mode-map-alist
))
1118 (setq minor-mode-map-alist
1119 (cons '(outline-mode . outline-mode-map
)
1120 minor-mode-map-alist
))))
1122 ; V18 minor-mode key bindings:
1123 ; Stash record of added bindings
1124 ; for later revocation:
1125 (outline-resumptions 'outline-added-bindings
1126 (list outline-keybindings-list
))
1127 (outline-resumptions 'outline-prior-bindings
1128 (list (current-local-map)))
1130 (use-local-map (produce-outline-mode-map outline-keybindings-list
1131 (current-local-map)))
1134 ; selective-display is the
1135 ; emacs conditional exposure
1137 (outline-resumptions 'selective-display
'(t))
1138 (if outline-inhibit-protection
1140 (outline-resumptions 'before-change-function
1141 '(outline-before-change-protect)))
1142 ; Temporarily set by any outline
1143 ; functions that can be trusted to
1144 ; deal properly with concealed text.
1145 (add-hook 'local-write-file-hooks
'outline-write-file-hook
)
1146 ; Custom auto-fill func, to support
1147 ; respect for topic headline,
1148 ; hanging-indents, etc:
1149 (let* ((fill-func-var (if (string-match "^18" emacs-version
)
1151 'auto-fill-function
))
1152 (fill-func (symbol-value fill-func-var
)))
1153 ;; Register prevailing fill func for use by outline-auto-fill:
1154 (outline-resumptions 'outline-former-auto-filler
(list fill-func
))
1155 ;; Register outline-auto-fill to be used if filling is active:
1156 (outline-resumptions fill-func-var
'(outline-auto-fill)))
1157 ;; Paragraphs are broken by topic headlines.
1158 (make-local-variable 'paragraph-start
)
1159 (outline-resumptions 'paragraph-start
1160 (list (concat paragraph-start
"\\|^\\("
1161 outline-regexp
"\\)")))
1162 (make-local-variable 'paragraph-separate
)
1163 (outline-resumptions 'paragraph-separate
1164 (list (concat paragraph-separate
"\\|^\\("
1165 outline-regexp
"\\)")))
1167 (or (assq 'outline-mode minor-mode-alist
)
1168 (setq minor-mode-alist
1169 (cons '(outline-mode " Outl") minor-mode-alist
)))
1174 (if outline-enwrap-isearch-mode
1175 (outline-enwrap-isearch))
1177 (run-hooks 'outline-mode-hook
)
1178 (setq outline-mode t
))
1182 (outline-infer-body-reindent))
1186 outline-auto-activation
1187 (listp outline-layout
)
1188 (and (not (eq outline-auto-activation
'activate
))
1189 (if (eq outline-auto-activation
'ask
)
1190 (if (y-or-n-p (format "Expose %s with layout '%s'? "
1194 (message "Skipped %s layout." (buffer-name))
1198 (message "Adjusting '%s' exposure..." (buffer-name))
1200 (outline-this-or-next-heading)
1203 (apply 'outline-expose-topic
(list outline-layout
))
1204 (message "Adjusting '%s' exposure... done." (buffer-name)))
1205 ;; Problem applying exposure - notify user, but don't
1206 ;; interrupt, eg, file visit:
1207 (error (message "%s" (car (cdr err
)))
1213 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs
1214 ;;; All the basic outline functions that directly do string matches to
1215 ;;; evaluate heading prefix location set the variables
1216 ;;; `outline-recent-prefix-beginning' and `outline-recent-prefix-end'
1217 ;;; when successful. Functions starting with `outline-recent-' all
1218 ;;; use this state, providing the means to avoid redundant searches
1219 ;;; for just-established data. This optimization can provide
1220 ;;; significant speed improvement, but it must be employed carefully.
1221 ;;;_ = outline-recent-prefix-beginning
1222 (defvar outline-recent-prefix-beginning
0
1223 "Buffer point of the start of the last topic prefix encountered.")
1224 (make-variable-buffer-local 'outline-recent-prefix-beginning
)
1225 ;;;_ = outline-recent-prefix-end
1226 (defvar outline-recent-prefix-end
0
1227 "Buffer point of the end of the last topic prefix encountered.")
1228 (make-variable-buffer-local 'outline-recent-prefix-end
)
1229 ;;;_ = outline-recent-end-of-subtree
1230 (defvar outline-recent-end-of-subtree
0
1231 "Buffer point last returned by outline-end-of-current-subtree.")
1232 (make-variable-buffer-local 'outline-recent-end-of-subtree
)
1233 ;;;_ > outline-prefix-data (beg end)
1234 (defmacro outline-prefix-data
(beg end
)
1235 "Register outline-prefix state data - BEGINNING and END of prefix.
1237 For reference by 'outline-recent' funcs. Returns BEGINNING."
1238 (` (setq outline-recent-prefix-end
(, end
)
1239 outline-recent-prefix-beginning
(, beg
))))
1240 ;;;_ > outline-recent-depth ()
1241 (defmacro outline-recent-depth
()
1242 "Return depth of last heading encountered by an outline maneuvering function.
1244 All outline functions which directly do string matches to assess
1245 headings set the variables outline-recent-prefix-beginning and
1246 outline-recent-prefix-end if successful. This function uses those settings
1247 to return the current depth."
1249 '(max 1 (- outline-recent-prefix-end
1250 outline-recent-prefix-beginning
1251 outline-header-subtraction
)))
1252 ;;;_ > outline-recent-prefix ()
1253 (defmacro outline-recent-prefix
()
1254 "Like outline-recent-depth, but returns text of last encountered prefix.
1256 All outline functions which directly do string matches to assess
1257 headings set the variables outline-recent-prefix-beginning and
1258 outline-recent-prefix-end if successful. This function uses those settings
1259 to return the current depth."
1260 '(buffer-substring outline-recent-prefix-beginning
1261 outline-recent-prefix-end
))
1262 ;;;_ > outline-recent-bullet ()
1263 (defmacro outline-recent-bullet
()
1264 "Like outline-recent-prefix, but returns bullet of last encountered prefix.
1266 All outline functions which directly do string matches to assess
1267 headings set the variables outline-recent-prefix-beginning and
1268 outline-recent-prefix-end if successful. This function uses those settings
1269 to return the current depth of the most recently matched topic."
1270 '(buffer-substring (1- outline-recent-prefix-end
)
1271 outline-recent-prefix-end
))
1275 ;;;_ - Position Assessment
1276 ;;;_ : Location Predicates
1277 ;;;_ > outline-on-current-heading-p ()
1278 (defun outline-on-current-heading-p ()
1279 "Return non-nil if point is on current visible topics' header line.
1281 Actually, returns prefix beginning point."
1284 (and (looking-at outline-regexp
)
1285 (outline-prefix-data (match-beginning 0) (match-end 0)))))
1286 ;;;_ > outline-e-o-prefix-p ()
1287 (defun outline-e-o-prefix-p ()
1288 "True if point is located where current topic prefix ends, heading begins."
1289 (and (save-excursion (beginning-of-line)
1290 (looking-at outline-regexp
))
1291 (= (point)(save-excursion (outline-end-of-prefix)(point)))))
1292 ;;;_ > outline-hidden-p ()
1293 (defmacro outline-hidden-p
()
1294 "True if point is in hidden text."
1296 (and (re-search-backward "[\n\r]" () t
)
1297 (= ?
\r (following-char)))))
1298 ;;;_ > outline-visible-p ()
1299 (defmacro outline-visible-p
()
1300 "True if point is not in hidden text."
1302 '(not (outline-hidden-p)))
1303 ;;;_ : Location attributes
1304 ;;;_ > outline-depth ()
1305 (defmacro outline-depth
()
1306 "Like outline-current-depth, but respects hidden as well as visible topics."
1308 (if (outline-goto-prefix)
1309 (outline-recent-depth)
1311 ;; Oops, no prefix, zero prefix data:
1312 (outline-prefix-data (point)(point))
1313 ;; ... and return 0:
1315 ;;;_ > outline-current-depth ()
1316 (defmacro outline-current-depth
()
1317 "Return nesting depth of visible topic most immediately containing point."
1319 (if (outline-back-to-current-heading)
1321 (- outline-recent-prefix-end
1322 outline-recent-prefix-beginning
1323 outline-header-subtraction
))
1325 ;;;_ > outline-get-current-prefix ()
1326 (defun outline-get-current-prefix ()
1327 "Topic prefix of the current topic."
1329 (if (outline-goto-prefix)
1330 (outline-recent-prefix))))
1331 ;;;_ > outline-get-bullet ()
1332 (defun outline-get-bullet ()
1333 "Return bullet of containing topic (visible or not)."
1335 (and (outline-goto-prefix)
1336 (outline-recent-bullet))))
1337 ;;;_ > outline-current-bullet ()
1338 (defun outline-current-bullet ()
1339 "Return bullet of current (visible) topic heading, or none if none found."
1342 (outline-back-to-current-heading)
1343 (buffer-substring (- outline-recent-prefix-end
1)
1344 outline-recent-prefix-end
))
1345 ;; Quick and dirty provision, ostensibly for missing bullet:
1346 (args-out-of-range nil
))
1348 ;;;_ > outline-get-prefix-bullet (prefix)
1349 (defun outline-get-prefix-bullet (prefix)
1350 "Return the bullet of the header prefix string PREFIX."
1351 ;; Doesn't make sense if we're old-style prefixes, but this just
1352 ;; oughtn't be called then, so forget about it...
1353 (if (string-match outline-regexp prefix
)
1354 (substring prefix
(1- (match-end 0)) (match-end 0))))
1356 ;;;_ - Navigation macros
1357 ;;;_ > outline-next-heading ()
1358 (defmacro outline-next-heading
()
1359 "Move to the heading for the topic \(possibly invisible) before this one.
1361 Returns the location of the heading, or nil if none found."
1363 '(if (and (bobp) (not (eobp)))
1366 '(if (re-search-forward outline-line-boundary-regexp nil
0)
1367 (progn ; Got valid location state - set vars:
1368 (outline-prefix-data
1369 (goto-char (or (match-beginning 2)
1370 outline-recent-prefix-beginning
))
1371 (or (match-end 2) outline-recent-prefix-end
)))))
1372 ;;;_ : outline-this-or-next-heading
1373 (defun outline-this-or-next-heading ()
1374 "Position cursor on current or next heading."
1375 ;; A throwaway non-macro that is defined after outline-next-heading
1376 ;; and usable by outline-mode.
1377 (if (not (outline-goto-prefix)) (outline-next-heading)))
1378 ;;;_ > outline-previous-heading ()
1379 (defmacro outline-previous-heading
()
1380 "Move to the prior \(possibly invisible) heading line.
1382 Return the location of the beginning of the heading, or nil if not found."
1386 (outline-goto-prefix)
1388 ;; searches are unbounded and return nil if failed:
1389 (or (re-search-backward outline-line-boundary-regexp nil
0)
1390 (looking-at outline-bob-regexp
))
1391 (progn ; Got valid location state - set vars:
1392 (outline-prefix-data
1393 (goto-char (or (match-beginning 2)
1394 outline-recent-prefix-beginning
))
1395 (or (match-end 2) outline-recent-prefix-end
))))))
1397 ;;;_ - Subtree Charting
1398 ;;;_ " These routines either produce or assess charts, which are
1399 ;;; nested lists of the locations of topics within a subtree.
1401 ;;; Use of charts enables efficient navigation of subtrees, by
1402 ;;; requiring only a single regexp-search based traversal, to scope
1403 ;;; out the subtopic locations. The chart then serves as the basis
1404 ;;; for whatever assessment or adjustment of the subtree that is
1405 ;;; required, without requiring redundant topic-traversal procedures.
1407 ;;;_ > outline-chart-subtree (&optional levels orig-depth prev-depth)
1408 (defun outline-chart-subtree (&optional levels orig-depth prev-depth
)
1409 "Produce a location \"chart\" of subtopics of the containing topic.
1411 Optional argument LEVELS specifies the depth \(releative to start
1412 depth\) for the chart. Subsequent optional args are not for public
1415 Charts are used to capture outline structure, so that outline-altering
1416 routines need assess the structure only once, and then use the chart
1417 for their elaborate manipulations.
1419 Topics are entered in the chart so the last one is at the car.
1420 The entry for each topic consists of an integer indicating the point
1421 at the beginning of the topic. Charts for offspring consists of a
1422 list containing, recursively, the charts for the respective subtopics.
1423 The chart for a topics' offspring precedes the entry for the topic
1426 The other function parameters are for internal recursion, and should
1427 not be specified by external callers. ORIG-DEPTH is depth of topic at
1428 starting point, and PREV-DEPTH is depth of prior topic."
1430 (let ((original (not orig-depth
)) ; 'orig-depth' set only in recursion.
1433 (if original
; Just starting?
1434 ; Register initial settings and
1435 ; position to first offspring:
1436 (progn (setq orig-depth
(outline-depth))
1437 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
1438 (outline-next-heading)))
1440 ;; Loop over the current levels' siblings. Besides being more
1441 ;; efficient than tail-recursing over a level, it avoids exceeding
1442 ;; the typically quite constrained emacs max-lisp-eval-depth.
1443 ;; Probably would speed things up to implement loop-based stack
1444 ;; operation rather than recursing for lower levels. Bah.
1445 (while (and (not (eobp))
1446 ; Still within original topic?
1447 (< orig-depth
(setq curr-depth
(outline-recent-depth)))
1448 (cond ((= prev-depth curr-depth
)
1449 ;; Register this one and move on:
1450 (setq chart
(cons (point) chart
))
1451 (if (and levels
(<= levels
1))
1452 ;; At depth limit - skip sublevels:
1453 (or (outline-next-sibling curr-depth
)
1454 ;; or no more siblings - proceed to
1455 ;; next heading at lesser depth:
1456 (while (and (<= curr-depth
1457 (outline-recent-depth))
1458 (outline-next-heading))))
1459 (outline-next-heading)))
1461 ((and (< prev-depth curr-depth
)
1464 ;; Recurse on deeper level of curr topic:
1466 (cons (outline-chart-subtree (and levels
1471 ;; ... then continue with this one.
1474 ;; ... else nil if we've ascended back to prev-depth.
1478 (if original
; We're at the last sibling on
1479 ; the original level. Position
1481 (progn (and (not (eobp)) (forward-char -
1))
1482 (and (memq (preceding-char) '(?
\n ?\^M
))
1483 (memq (aref (buffer-substring (max 1 (- (point) 3))
1488 (setq outline-recent-end-of-subtree
(point))))
1490 chart
; (nreverse chart) not necessary,
1491 ; and maybe not preferable.
1493 ;;;_ > outline-chart-siblings (&optional start end)
1494 (defun outline-chart-siblings (&optional start end
)
1495 "Produce a list of locations of this and succeeding sibling topics.
1496 Effectively a top-level chart of siblings. See 'outline-chart-subtree'
1497 for an explanation of charts."
1499 (if (outline-goto-prefix)
1500 (let ((chart (list (point))))
1501 (while (outline-next-sibling)
1502 (setq chart
(cons (point) chart
)))
1503 (if chart
(setq chart
(nreverse chart
)))))))
1504 ;;;_ > outline-chart-to-reveal (chart depth)
1505 (defun outline-chart-to-reveal (chart depth
)
1507 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
1509 Note that point can be left at any of the points on chart, or at the
1513 (while (and (or (eq depth t
) (> depth
0))
1515 (setq here
(car chart
))
1517 (let ((further (outline-chart-to-reveal here
(or (eq depth t
)
1519 ;; We're on the start of a subtree - recurse with it, if there's
1520 ;; more depth to go:
1521 (if further
(setq result
(append further result
)))
1522 (setq chart
(cdr chart
)))
1524 (if (= (preceding-char) ?
\r)
1525 (setq result
(cons here result
)))
1526 (setq chart
(cdr chart
))))
1528 ;;;_ X outline-chart-spec (chart spec &optional exposing)
1529 (defun outline-chart-spec (chart spec
&optional exposing
)
1530 "Not yet \(if ever\) implemented.
1532 Produce exposure directives given topic/subtree CHART and an exposure SPEC.
1534 Exposure spec indicates the locations to be exposed and the prescribed
1535 exposure status. Optional arg EXPOSING is an integer, with 0
1536 indicating pending concealment, anything higher indicating depth to
1537 which subtopic headers should be exposed, and negative numbers
1538 indicating (negative of) the depth to which subtopic headers and
1539 bodies should be exposed.
1541 The produced list can have two types of entries. Bare numbers
1542 indicate points in the buffer where topic headers that should be
1545 - bare negative numbers indicates that the topic starting at the
1546 point which is the negative of the number should be opened,
1547 including their entries.
1548 - bare positive values indicate that this topic header should be
1550 - Lists signify the beginning and end points of regions that should
1551 be flagged, and the flag to employ. (For concealment: '\(\?r\)', and
1557 (setq spec
(cdr spec
)))
1561 ;;;_ > outline-goto-prefix ()
1562 (defun outline-goto-prefix ()
1563 "Put point at beginning of outline prefix for immediately containing topic.
1565 Goes to first subsequent topic if none immediately containing.
1567 Not sensitive to topic visibility.
1569 Returns a the point at the beginning of the prefix, or nil if none."
1572 (while (and (not done
)
1573 (re-search-backward "[\n\r]" nil
1))
1575 (if (looking-at outline-regexp
)
1576 (setq done
(outline-prefix-data (match-beginning 0)
1580 (cond ((looking-at outline-regexp
)
1581 (outline-prefix-data (match-beginning 0)(match-end 0)))
1582 ((outline-next-heading)
1583 (outline-prefix-data (match-beginning 0)(match-end 0)))
1586 ;;;_ > outline-end-of-prefix ()
1587 (defun outline-end-of-prefix (&optional ignore-decorations
)
1588 "Position cursor at beginning of header text.
1590 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
1591 otherwise skip white space between bullet and ensuing text."
1593 (if (not (outline-goto-prefix))
1595 (let ((match-data (match-data)))
1596 (goto-char (match-end 0))
1597 (if ignore-decorations
1599 (while (looking-at "[0-9]") (forward-char 1))
1600 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))
1601 (store-match-data match-data
))
1602 ;; Reestablish where we are:
1603 (outline-current-depth)))
1604 ;;;_ > outline-current-bullet-pos ()
1605 (defun outline-current-bullet-pos ()
1606 "Return position of current \(visible) topic's bullet."
1608 (if (not (outline-current-depth))
1610 (1- (match-end 0))))
1611 ;;;_ > outline-back-to-current-heading ()
1612 (defun outline-back-to-current-heading ()
1613 "Move to heading line of current topic, or beginning if already on the line."
1616 (prog1 (or (outline-on-current-heading-p)
1617 (and (re-search-backward (concat "^\\(" outline-regexp
"\\)")
1620 (outline-prefix-data (match-beginning 1)(match-end 1))))
1621 (if (interactive-p) (outline-end-of-prefix))))
1622 ;;;_ > outline-pre-next-preface ()
1623 (defun outline-pre-next-preface ()
1624 "Skip forward to just before the next heading line.
1626 Returns that character position."
1628 (if (re-search-forward outline-line-boundary-regexp nil
'move
)
1629 (prog1 (goto-char (match-beginning 0))
1630 (outline-prefix-data (match-beginning 2)(match-end 2)))))
1631 ;;;_ > outline-end-of-current-subtree ()
1632 (defun outline-end-of-current-subtree ()
1633 "Put point at the end of the last leaf in the currently visible topic."
1635 (outline-back-to-current-heading)
1636 (let ((level (outline-recent-depth)))
1637 (outline-next-heading)
1638 (while (and (not (eobp))
1639 (> (outline-recent-depth) level
))
1640 (outline-next-heading))
1641 (and (not (eobp)) (forward-char -
1))
1642 (and (memq (preceding-char) '(?
\n ?\^M
))
1643 (memq (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1)
1646 (setq outline-recent-end-of-subtree
(point))))
1647 ;;;_ > outline-beginning-of-current-entry ()
1648 (defun outline-beginning-of-current-entry ()
1649 "When not already there, position point at beginning of current topic's body.
1651 If already there, move cursor to bullet for hot-spot operation.
1652 \(See outline-mode doc string for details on hot-spot operation.)"
1654 (let ((start-point (point)))
1655 (outline-end-of-prefix)
1656 (if (and (interactive-p)
1657 (= (point) start-point
))
1658 (goto-char (outline-current-bullet-pos)))))
1659 ;;;_ > outline-end-of-current-entry ()
1660 (defun outline-end-of-current-entry ()
1661 "Position the point at the end of the current topics' entry."
1663 (outline-show-entry)
1664 (prog1 (outline-pre-next-preface)
1665 (if (and (not (bobp))(looking-at "^$"))
1666 (forward-char -
1))))
1669 ;;;_ > outline-ascend-to-depth (depth)
1670 (defun outline-ascend-to-depth (depth)
1671 "Ascend to depth DEPTH, returning depth if successful, nil if not."
1672 (if (and (> depth
0)(<= depth
(outline-depth)))
1673 (let ((last-good (point)))
1674 (while (and (< depth
(outline-depth))
1675 (setq last-good
(point))
1676 (outline-beginning-of-level)
1677 (outline-previous-heading)))
1678 (if (= (outline-recent-depth) depth
)
1679 (progn (goto-char outline-recent-prefix-beginning
)
1681 (goto-char last-good
)
1683 (if (interactive-p) (outline-end-of-prefix))))
1684 ;;;_ > outline-descend-to-depth (depth)
1685 (defun outline-descend-to-depth (depth)
1686 "Descend to depth DEPTH within current topic.
1688 Returning depth if successful, nil if not."
1689 (let ((start-point (point))
1690 (start-depth (outline-depth)))
1692 (and (> (outline-depth) 0)
1693 (not (= depth
(outline-recent-depth))) ; ... not there yet
1694 (outline-next-heading) ; ... go further
1695 (< start-depth
(outline-recent-depth)))) ; ... still in topic
1696 (if (and (> (outline-depth) 0)
1697 (= (outline-recent-depth) depth
))
1699 (goto-char start-point
)
1702 ;;;_ > outline-up-current-level (arg &optional dont-complain)
1703 (defun outline-up-current-level (arg &optional dont-complain
)
1704 "Move out ARG levels from current visible topic.
1706 Positions on heading line of containing topic. Error if unable to
1707 ascend that far, or nil if unable to ascend but optional arg
1708 DONT-COMPLAIN is non-nil."
1710 (outline-back-to-current-heading)
1711 (let ((present-level (outline-recent-depth))
1715 ;; Loop for iterating arg:
1716 (while (and (> (outline-recent-depth) 1)
1720 (setq last-good
(point))
1721 ;; Loop for going back over current or greater depth:
1722 (while (and (not (< (outline-recent-depth) present-level
))
1723 (or (outline-previous-visible-heading 1)
1724 (not (setq failed present-level
)))))
1725 (setq present-level
(outline-current-depth))
1726 (setq arg
(- arg
1)))
1729 (progn (goto-char last-good
)
1730 (if (interactive-p) (outline-end-of-prefix))
1731 (if (not dont-complain
)
1732 (error "Can't ascend past outermost level.")
1733 (if (interactive-p) (outline-end-of-prefix))
1735 (if (interactive-p) (outline-end-of-prefix))
1736 outline-recent-prefix-beginning
)))
1739 ;;;_ > outline-next-sibling (&optional depth backward)
1740 (defun outline-next-sibling (&optional depth backward
)
1741 "Like outline-forward-current-level, but respects invisible topics.
1743 Traverse at optional DEPTH, or current depth if none specified.
1745 Go backward if optional arg BACKWARD is non-nil.
1747 Return depth if successful, nil otherwise."
1749 (if (and backward
(bobp))
1751 (let ((start-depth (or depth
(outline-depth)))
1752 (start-point (point))
1754 (while (and (not (if backward
(bobp) (eobp)))
1755 (if backward
(outline-previous-heading)
1756 (outline-next-heading))
1757 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
1758 (if (and (not (eobp))
1759 (and (> (or last-depth
(outline-depth)) 0)
1760 (= (outline-recent-depth) start-depth
)))
1761 outline-recent-prefix-beginning
1762 (goto-char start-point
)
1763 (if depth
(outline-depth) start-depth
)
1765 ;;;_ > outline-previous-sibling (&optional depth backward)
1766 (defun outline-previous-sibling (&optional depth backward
)
1767 "Like outline-forward-current-level,but backwards & respect invisible topics.
1769 Optional DEPTH specifies depth to traverse, default current depth.
1771 Optional BACKWARD reverses direction.
1773 Return depth if successful, nil otherwise."
1774 (outline-next-sibling depth
(not backward
))
1776 ;;;_ > outline-snug-back ()
1777 (defun outline-snug-back ()
1778 "Position cursor at end of previous topic
1780 Presumes point is at the start of a topic prefix."
1781 (if (or (bobp) (eobp))
1784 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?\^M
))))
1787 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?\^M
))))
1790 ;;;_ > outline-beginning-of-level ()
1791 (defun outline-beginning-of-level ()
1792 "Go back to the first sibling at this level, visible or not."
1793 (outline-end-of-level 'backward
))
1794 ;;;_ > outline-end-of-level (&optional backward)
1795 (defun outline-end-of-level (&optional backward
)
1796 "Go to the last sibling at this level, visible or not."
1798 (let ((depth (outline-depth)))
1799 (while (outline-previous-sibling depth nil
))
1800 (prog1 (outline-recent-depth)
1801 (if (interactive-p) (outline-end-of-prefix)))))
1802 ;;;_ > outline-next-visible-heading (arg)
1803 (defun outline-next-visible-heading (arg)
1804 "Move to the next ARG'th visible heading line, backward if arg is negative.
1806 Move as far as possible in indicated direction \(beginning or end of
1807 buffer\) if headings are exhausted."
1810 (let* ((backward (if (< arg
0) (setq arg
(* -
1 arg
))))
1811 (step (if backward -
1 1))
1812 (start-point (point))
1815 (while (> arg
0) ; limit condition
1816 (while (and (not (if backward
(bobp)(eobp))) ; boundary condition
1817 ;; Move, skipping over all those concealed lines:
1818 (< -
1 (forward-line step
))
1819 (not (setq got
(looking-at outline-regexp
)))))
1820 ;; Register this got, it may be the last:
1821 (if got
(setq prev got
))
1822 (setq arg
(1- arg
)))
1823 (cond (got ; Last move was to a prefix:
1824 (outline-prefix-data (match-beginning 0) (match-end 0))
1825 (outline-end-of-prefix))
1826 (prev ; Last move wasn't, but prev was:
1827 (outline-prefix-data (match-beginning 0) (match-end 0)))
1828 ((not backward
) (end-of-line) nil
))))
1829 ;;;_ > outline-previous-visible-heading (arg)
1830 (defun outline-previous-visible-heading (arg)
1831 "Move to the previous heading line.
1833 With argument, repeats or can move forward if negative.
1834 A heading line is one that starts with a `*' (or that outline-regexp
1837 (outline-next-visible-heading (- arg
)))
1838 ;;;_ > outline-forward-current-level (arg)
1839 (defun outline-forward-current-level (arg)
1840 "Position point at the next heading of the same level.
1842 Takes optional repeat-count, goes backward if count is negative.
1844 Returns resulting position, else nil if none found."
1846 (let ((start-depth (outline-current-depth))
1847 (start-point (point))
1849 (backward (> 0 arg
))
1853 (if (= 0 start-depth
)
1854 (error "No siblings, not in a topic..."))
1855 (if backward
(setq arg
(* -
1 arg
)))
1856 (while (not (or (zerop arg
)
1858 (while (and (not (if backward
(bobp) (eobp)))
1859 (if backward
(outline-previous-visible-heading 1)
1860 (outline-next-visible-heading 1))
1861 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
1862 (if (and last-depth
(= last-depth start-depth
)
1863 (not (if backward
(bobp) (eobp))))
1864 (setq last-good
(point)
1866 (setq at-boundary t
)))
1867 (if (and (not (eobp))
1869 (and (> (or last-depth
(outline-depth)) 0)
1870 (= (outline-recent-depth) start-depth
)))
1871 outline-recent-prefix-beginning
1872 (goto-char last-good
)
1873 (if (not (interactive-p))
1875 (outline-end-of-prefix)
1876 (error "Hit %s level %d topic, traversed %d of %d requested."
1877 (if backward
"first" "last")
1878 (outline-recent-depth)
1879 (- (abs start-arg
) arg
)
1880 (abs start-arg
))))))
1881 ;;;_ > outline-backward-current-level (arg)
1882 (defun outline-backward-current-level (arg)
1883 "Inverse of `outline-forward-current-level'."
1886 (let ((current-prefix-arg (* -
1 arg
)))
1887 (call-interactively 'outline-forward-current-level
))
1888 (outline-forward-current-level (* -
1 arg
))))
1893 ;;;_ > outline-before-change-protect (beg end)
1894 (defun outline-before-change-protect (beg end
)
1895 "Outline before-change hook, regulates changes to concealed text.
1897 Reveal concealed text that would be changed by current command, and
1898 offer user choice to commit or forego the change. Unchanged text is
1899 reconcealed. User has option to have changed text reconcealed.
1901 Undo commands are specially treated - the user is not prompted for
1902 choice, the undoes are always committed (based on presumption that the
1903 things being undone were already subject to this regulation routine),
1904 and undoes always leave the changed stuff exposed.
1906 Changes to concealed regions are ignored while file is being written.
1907 \(This is for the sake of functions that do change the file during
1908 writes, like crypt and zip modes.)
1910 Locally bound in outline buffers to 'before-change-function', which
1911 in emacs 19 is run before any change to the buffer. (Has no effect
1912 in Emacs 18, which doesn't support before-change-function.)
1914 Any functions which set ['this-command' to 'undo', or which set]
1915 'outline-override-protect' non-nil (as does, eg, outline-flag-chars)
1916 are exempt from this restriction."
1917 (if (and (outline-mode-p)
1918 ; outline-override-protect
1919 ; set by functions that know what
1920 ; they're doing, eg outline internals:
1921 (not outline-override-protect
)
1922 (not outline-during-write-cue
)
1923 (save-match-data ; Preserve operation position state.
1924 ; Both beginning and end chars must
1926 (save-excursion (if (memq this-command
'(newline open-line
))
1927 ;; Compensate for stupid emacs {new,
1928 ;; open-}line display optimization:
1932 (or (outline-hidden-p)
1933 (and (not (= beg end
))
1935 (outline-hidden-p))))))
1937 (if (equal this-command
'undo
)
1938 ;; Allow undo without inhibition.
1939 ;; - Undoing new and open-line hits stupid emacs redisplay
1940 ;; optimization (em 19 cmds.c, ~ line 200).
1941 ;; - Presumably, undoing what was properly protected when
1943 ;; - Undo may be users' only recourse in protection faults.
1944 ;; So, expose what getting changed:
1945 (progn (message "Undo! - exposing concealed target...")
1946 (if (outline-hidden-p)
1947 (outline-show-children))
1950 (rehide-completely (save-excursion (outline-goto-prefix)
1951 (outline-hidden-p)))
1955 (if (condition-case err
1956 ;; Condition case to catch keyboard quits during reads.
1958 ; Give them a peek where
1960 (if (eolp) (setq rehide-place
1961 (outline-goto-prefix)))
1962 (outline-show-entry))
1963 ; Present the message, but...
1964 ; leave the cursor at the location
1965 ; until they respond:
1966 ; Then interpret the response:
1969 (message (concat "Change inside concealed"
1971 "(n or 'y'/'r'eclose)"))
1972 (setq response
(read-char))
1974 (cond ((memq response
'(?r ?R
))
1975 (setq response
'reclose
))
1976 ((memq response
'(?y ?Y ?
))
1978 ((memq response
'(?n ?N
127))
1983 "'r' means 'yes, then reclose")
1985 (t (message "Please answer y, n, or r")
1991 (if (eq response
'reclose
)
1993 (if rehide-place
(goto-char rehide-place
))
1994 (if rehide-completely
1995 (outline-hide-current-entry-completely)
1996 (outline-hide-current-entry)))
1997 (if (outline-ascend-to-depth (1- (outline-recent-depth)))
1998 (outline-show-children)
1999 (outline-show-to-offshoot)))
2001 (if rehide-completely
2003 (if rehide-place
(goto-char rehide-place
))
2004 (outline-hide-current-entry-completely))
2005 (outline-hide-current-entry))
2007 "Change within concealed region prevented.")))))))
2010 ;;;_ = outline-post-goto-bullet
2011 (defvar outline-post-goto-bullet nil
2012 "Outline internal var, for `outline-pre-command-business' hot-spot operation.
2014 When set, tells post-processing to reposition on topic bullet, and
2015 then unset it. Set by outline-pre-command-business when implementing
2016 hot-spot operation, where literal characters typed over a topic bullet
2017 are mapped to the command of the corresponding control-key on the
2019 (make-variable-buffer-local 'outline-post-goto-bullet
)
2020 ;;;_ > outline-post-command-business ()
2021 (defun outline-post-command-business ()
2022 "Outline post-command-hook function.
2024 - Null outline-override-protect, so it's not left open.
2026 - Implement (and clear) outline-post-goto-bullet, for hot-spot
2029 - Massages buffer-undo-list so successive, standard character self-inserts are
2030 aggregated. This kludge compensates for lack of undo bunching when
2031 before-change-function is used."
2033 ; Apply any external change func:
2034 (if (not (outline-mode-p)) ; In outline-mode.
2036 (setq outline-override-protect nil
)
2037 (if outline-during-write-cue
2038 ;; Was used by outline-before-change-protect, done with it now:
2039 (setq outline-during-write-cue nil
))
2040 ;; Undo bunching business:
2041 (if (and (listp buffer-undo-list
) ; Undo history being kept.
2042 (equal this-command
'self-insert-command
)
2043 (equal last-command
'self-insert-command
))
2044 (let* ((prev-stuff (cdr buffer-undo-list
))
2045 (before-prev-stuff (cdr (cdr prev-stuff
)))
2046 cur-cell cur-from cur-to
2047 prev-cell prev-from prev-to
)
2048 (if (and before-prev-stuff
; Goes back far enough to bother,
2049 (not (car prev-stuff
)) ; and break before current,
2050 (not (car before-prev-stuff
)) ; !and break before prev!
2051 (setq prev-cell
(car (cdr prev-stuff
))) ; contents now,
2052 (setq cur-cell
(car buffer-undo-list
)) ; contents prev.
2054 ;; cur contents denote a single char insertion:
2055 (numberp (setq cur-from
(car cur-cell
)))
2056 (numberp (setq cur-to
(cdr cur-cell
)))
2057 (= 1 (- cur-to cur-from
))
2059 ;; prev contents denote fewer than aggregate-limit
2061 (numberp (setq prev-from
(car prev-cell
)))
2062 (numberp (setq prev-to
(cdr prev-cell
)))
2064 (> outline-undo-aggregation
(- prev-to prev-from
)))
2065 (setq buffer-undo-list
2066 (cons (cons prev-from cur-to
)
2067 (cdr (cdr (cdr buffer-undo-list
))))))))
2068 ;; Implement -post-goto-bullet, if set: (must be after undo business)
2069 (if (and outline-post-goto-bullet
2070 (outline-current-bullet-pos))
2071 (progn (goto-char (outline-current-bullet-pos))
2072 (setq outline-post-goto-bullet nil
)))
2074 ;;;_ > outline-pre-command-business ()
2075 (defun outline-pre-command-business ()
2076 "Outline pre-command-hook function for outline buffers.
2078 Implements special behavior when cursor is on bullet char.
2080 Self-insert characters are reinterpreted control-character references
2081 into the outline-mode-map. The outline-mode post-command hook will
2082 position a cursor that has moved as a result of such reinterpretation,
2083 on the destination topic's bullet, when the cursor wound up in the
2085 The upshot is that you can get easy, single (unmodified) key outline
2086 maneuvering and general operations by positioning the cursor on the
2087 bullet char, and it continues until you deliberately some non-outline
2088 motion command to relocate the cursor off of a bullet char."
2090 (if (and (boundp 'outline-mode
)
2092 (eq this-command
'self-insert-command
)
2093 (eq (point)(outline-current-bullet-pos)))
2095 (let* ((this-key-num (if (numberp last-command-event
)
2096 last-command-event
))
2099 ; Map upper-register literals
2100 ; to lower register:
2101 (if (<= 96 this-key-num
)
2102 (setq this-key-num
(- this-key-num
32)))
2103 ; Check if we have a literal:
2104 (if (and (<= 64 this-key-num
)
2105 (>= 96 this-key-num
))
2106 (setq mapped-binding
2107 (lookup-key 'outline-mode-map
2108 (concat outline-command-prefix
2109 (char-to-string (- this-key-num
64))))))
2111 (setq outline-post-goto-bullet t
2112 this-command mapped-binding
)))))
2113 ;;;_ > outline-find-file-hook ()
2114 (defun outline-find-file-hook ()
2115 "Activate outline-mode when `outline-auto-activation' & `outline-layout' are non-nil.
2117 See `outline-init' for setup instructions."
2118 (if (and outline-auto-activation
2119 (not (outline-mode-p))
2122 ;;;_ : Establish the hooks
2123 (add-hook 'post-command-hook
'outline-post-command-business
)
2124 (add-hook 'pre-command-hook
'outline-pre-command-business
)
2126 ;;;_ - Topic Format Assessment
2127 ;;;_ > outline-solicit-alternate-bullet (depth &optional current-bullet)
2128 (defun outline-solicit-alternate-bullet (depth &optional current-bullet
)
2130 "Prompt for and return a bullet char as an alternative to the current one.
2132 Offer one suitable for current depth DEPTH as default."
2134 (let* ((default-bullet (or current-bullet
2135 (outline-bullet-for-depth depth
)))
2136 (sans-escapes (regexp-sans-escapes outline-bullets-string
))
2137 (choice (solicit-char-in-string
2138 (format "Select bullet: %s ('%s' default): "
2143 (if (string= choice
"") default-bullet choice
))
2145 ;;;_ > outline-sibling-index (&optional depth)
2146 (defun outline-sibling-index (&optional depth
)
2147 "Item number of this prospective topic among its siblings.
2149 If optional arg depth is greater than current depth, then we're
2150 opening a new level, and return 0.
2152 If less than this depth, ascend to that depth and count..."
2155 (cond ((and depth
(<= depth
0) 0))
2156 ((or (not depth
) (= depth
(outline-depth)))
2158 (while (outline-previous-sibling (outline-recent-depth) nil
)
2159 (setq index
(1+ index
)))
2161 ((< depth
(outline-recent-depth))
2162 (outline-ascend-to-depth depth
)
2163 (outline-sibling-index))
2165 ;;;_ > outline-distinctive-bullet (bullet)
2166 (defun outline-distinctive-bullet (bullet)
2167 "True if bullet is one of those on outline-distinctive-bullets-string."
2168 (string-match (regexp-quote bullet
) outline-distinctive-bullets-string
))
2169 ;;;_ > outline-numbered-type-prefix (&optional prefix)
2170 (defun outline-numbered-type-prefix (&optional prefix
)
2171 "True if current header prefix bullet is numbered bullet."
2172 (and outline-numbered-bullet
2173 (string= outline-numbered-bullet
2175 (outline-get-prefix-bullet prefix
)
2176 (outline-get-bullet)))))
2177 ;;;_ > outline-bullet-for-depth (&optional depth)
2178 (defun outline-bullet-for-depth (&optional depth
)
2179 "Return outline topic bullet suited to optional DEPTH, or current depth."
2180 ;; Find bullet in plain-bullets-string modulo DEPTH.
2181 (if outline-stylish-prefixes
2182 (char-to-string (aref outline-plain-bullets-string
2183 (%
(max 0 (- depth
2))
2184 outline-plain-bullets-string-len
)))
2185 outline-primary-bullet
)
2188 ;;;_ - Topic Production
2189 ;;;_ > outline-make-topic-prefix (&optional prior-bullet
2190 (defun outline-make-topic-prefix (&optional prior-bullet
2196 ;; Depth null means use current depth, non-null means we're either
2197 ;; opening a new topic after current topic, lower or higher, or we're
2198 ;; changing level of current topic.
2199 ;; Solicit dominates specified bullet-char.
2201 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
2203 All the arguments are optional.
2205 PRIOR-BULLET indicates the bullet of the prefix being changed, or
2206 nil if none. This bullet may be preserved (other options
2207 notwithstanding) if it is on the outline-distinctive-bullets-string,
2210 Second arg NEW indicates that a new topic is being opened after the
2211 topic at point, if non-nil. Default bullet for new topics, eg, may
2212 be set (contingent to other args) to numbered bullets if previous
2213 sibling is one. The implication otherwise is that the current topic
2214 is being adjusted - shifted or rebulleted - and we don't consider
2215 bullet or previous sibling.
2217 Third arg DEPTH forces the topic prefix to that depth, regardless of
2218 the current topics' depth.
2220 Fourth arg SOLICIT non-nil provokes solicitation from the user of a
2221 choice among the valid bullets. (This overrides other all the
2222 options, including, eg, a distinctive PRIOR-BULLET.)
2224 Fifth arg, NUMBER-CONTROL, matters only if 'outline-numbered-bullet'
2225 is non-nil *and* soliciting was not explicitly invoked. Then
2226 NUMBER-CONTROL non-nil forces prefix to either numbered or
2227 denumbered format, depending on the value of the sixth arg, INDEX.
2229 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
2231 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
2232 the prefix of the topic is forced to be numbered. Non-nil
2233 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
2234 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
2235 that the index for the numbered prefix will be derived, by counting
2236 siblings back to start of level. If INDEX is a number, then that
2237 number is used as the index for the numbered prefix (allowing, eg,
2238 sequential renumbering to not requre this function counting back the
2239 index for each successive sibling)."
2241 ;; The options are ordered in likely frequence of use, most common
2242 ;; highest, least lowest. Ie, more likely to be doing prefix
2243 ;; adjustments than soliciting, and yet more than numbering.
2244 ;; Current prefix is least dominant, but most likely to be commonly
2250 (depth (or depth
(outline-depth)))
2251 (header-lead outline-header-prefix
)
2254 ;; Getting value for bullet char is practically the whole job:
2257 ; Simplest situation - level 1:
2258 ((<= depth
1) (setq header-lead
"") outline-primary-bullet
)
2259 ; Simple, too: all asterisks:
2260 (outline-old-style-prefixes
2261 ;; Cheat - make body the whole thing, null out header-lead and
2263 (setq body
(make-string depth
2264 (string-to-char outline-primary-bullet
)))
2265 (setq header-lead
"")
2268 ;; (Neither level 1 nor old-style, so we're space padding.
2269 ;; Sneak it in the condition of the next case, whatever it is.)
2271 ;; Solicitation overrides numbering and other cases:
2272 ((progn (setq body
(make-string (- depth
2) ?\
))
2273 ;; The actual condition:
2275 (let* ((got (outline-solicit-alternate-bullet depth
)))
2276 ;; Gotta check whether we're numbering and got a numbered bullet:
2277 (setq numbering
(and outline-numbered-bullet
2278 (not (and number-control
(not index
)))
2279 (string= got outline-numbered-bullet
)))
2280 ;; Now return what we got, regardless:
2283 ;; Numbering invoked through args:
2284 ((and outline-numbered-bullet number-control
)
2285 (if (setq numbering
(not (setq denumbering
(not index
))))
2286 outline-numbered-bullet
2287 (if (and prior-bullet
2288 (not (string= outline-numbered-bullet
2291 (outline-bullet-for-depth depth
))))
2293 ;;; Neither soliciting nor controlled numbering ;;;
2294 ;;; (may be controlled denumbering, tho) ;;;
2296 ;; Check wrt previous sibling:
2297 ((and new
; only check for new prefixes
2298 (<= depth
(outline-depth))
2299 outline-numbered-bullet
; ... & numbering enabled
2301 (let ((sibling-bullet
2303 ;; Locate correct sibling:
2304 (or (>= depth
(outline-depth))
2305 (outline-ascend-to-depth depth
))
2306 (outline-get-bullet))))
2307 (if (and sibling-bullet
2308 (string= outline-numbered-bullet sibling-bullet
))
2309 (setq numbering sibling-bullet
)))))
2311 ;; Distinctive prior bullet?
2313 (outline-distinctive-bullet prior-bullet
)
2314 ;; Either non-numbered:
2315 (or (not (and outline-numbered-bullet
2316 (string= prior-bullet outline-numbered-bullet
)))
2317 ;; or numbered, and not denumbering:
2318 (setq numbering
(not denumbering
)))
2322 ;; Else, standard bullet per depth:
2323 ((outline-bullet-for-depth depth
)))))
2329 (format "%d" (cond ((and index
(numberp index
)) index
)
2330 (new (1+ (outline-sibling-index depth
)))
2331 ((outline-sibling-index))))))
2334 ;;;_ > outline-open-topic (relative-depth &optional before)
2335 (defun outline-open-topic (relative-depth &optional before
)
2336 "Open a new topic at depth DEPTH.
2338 New topic is situated after current one, unless optional flag BEFORE
2339 is non-nil, or unless current line is complete empty (not even
2340 whitespace), in which case open is done on current line.
2344 - Creation of new topics is with respect to the visible topic
2345 containing the cursor, regardless of intervening concealed ones.
2347 - New headers are generally created after/before the body of a
2348 topic. However, they are created right at cursor location if the
2349 cursor is on a blank line, even if that breaks the current topic
2350 body. This is intentional, to provide a simple means for
2351 deliberately dividing topic bodies.
2353 - Double spacing of topic lists is preserved. Also, the first
2354 level two topic is created double-spaced (and so would be
2355 subsequent siblings, if that's left intact). Otherwise,
2356 single-spacing is used.
2358 - Creation of sibling or nested topics is with respect to the topic
2359 you're starting from, even when creating backwards. This way you
2360 can easily create a sibling in front of the current topic without
2361 having to go to its preceeding sibling, and then open forward
2364 (let* ((depth (+ (outline-current-depth) relative-depth
))
2365 (opening-on-blank (if (looking-at "^\$")
2366 (not (setq before nil
))))
2367 opening-numbered
; Will get while computing ref-topic, below
2368 ref-depth
; Will get while computing ref-topic, next
2369 (ref-topic (save-excursion
2370 (cond ((< relative-depth
0)
2371 (outline-ascend-to-depth depth
))
2372 ((>= relative-depth
1) nil
)
2373 (t (outline-back-to-current-heading)))
2374 (setq ref-depth
(outline-recent-depth))
2375 (setq opening-numbered
2377 (and outline-numbered-bullet
2378 (or (<= relative-depth
0)
2379 (outline-descend-to-depth depth
))
2380 (if (outline-numbered-type-prefix)
2381 outline-numbered-bullet
))))
2386 (if (not opening-on-blank
)
2387 ; Positioning and vertical
2388 ; padding - only if not
2391 (goto-char ref-topic
)
2392 (setq dbl-space
; Determine double space action:
2393 (or (and (<= relative-depth
0) ; not descending;
2395 ;; at b-o-b or preceeded by a blank line?
2396 (or (> 0 (forward-line -
1))
2397 (looking-at "^\\s-*$")
2400 ;; succeeded by a blank line?
2401 (outline-end-of-current-subtree)
2403 (and (= ref-depth
1)
2407 ;; Don't already have following
2408 ;; vertical padding:
2409 (not (outline-pre-next-preface)))))))
2411 ; Position to prior heading,
2412 ; if inserting backwards, and
2413 ; not going outwards:
2414 (if (and before
(>= relative-depth
0))
2415 (progn (outline-back-to-current-heading)
2416 (setq doing-beginning
(bobp))
2418 (outline-previous-heading)))
2419 (if (and before
(bobp))
2420 (outline-unprotected (open-line 1))))
2422 (if (<= relative-depth
0)
2423 ;; Not going inwards, don't snug up:
2425 (outline-unprotected (open-line (if dbl-space
2 1)))
2427 (progn (end-of-line)
2428 (outline-pre-next-preface)
2429 (while (= ?
\r (following-char))
2431 (if (not (looking-at "^$"))
2432 (outline-unprotected (open-line 1))))
2433 (outline-end-of-current-subtree)))
2434 ;; Going inwards - double-space if first offspring is,
2435 ;; otherwise snug up.
2436 (end-of-line) ; So we skip any concealed progeny.
2437 (outline-pre-next-preface)
2439 ;; Blank lines between current header body and next
2440 ;; header - get to last substantive (non-white-space)
2442 (re-search-backward "[^ \t\n]" nil t
))
2444 (outline-next-heading)
2445 (if (> (outline-recent-depth) ref-depth
)
2446 ;; This is an offspring.
2447 (progn (forward-line -
1)
2448 (looking-at "^\\s-*$"))))
2449 (progn (forward-line 1)
2450 (outline-unprotected (open-line 1))))
2452 ;;(if doing-beginning (goto-char doing-beginning))
2454 (progn (if (and (not (> depth ref-depth
))
2456 (outline-unprotected (open-line 1))
2457 (if (> depth ref-depth
)
2458 (outline-unprotected (newline 1))
2460 (outline-unprotected (open-line 1))
2462 (outline-unprotected (newline 1))))))
2464 (outline-unprotected (newline 1)))
2465 (if (and (not (eobp))
2469 (insert-string (concat (outline-make-topic-prefix opening-numbered
2474 ;;(if doing-beginning (save-excursion (newline (if dbl-space 2 1))))
2477 (outline-rebullet-heading nil
;;; solicit
2479 nil
;;; number-control
2484 ;;;_ . open-topic contingencies
2485 ;;;_ ; base topic - one from which open was issued
2486 ;;;_ , beginning char
2487 ;;;_ , amount of space before will be used, unless openning in place
2488 ;;;_ , end char will be used, unless opening before (and it still may)
2489 ;;;_ ; absolute depth of new topic
2490 ;;;_ ! insert in place - overrides most stuff
2491 ;;;_ ; relative depth of new re base
2492 ;;;_ ; before or after base topic
2493 ;;;_ ; spacing around topic, if any, prior to new topic and at same depth
2494 ;;;_ ; buffer boundaries - special provisions for beginning and end ob
2495 ;;;_ ; level 1 topics have special provisions also - double space.
2496 ;;;_ ; location of new topic
2498 ;;;_ > outline-open-subtopic (arg)
2499 (defun outline-open-subtopic (arg)
2500 "Open new topic header at deeper level than the current one.
2502 Negative universal arg means to open deeper, but place the new topic
2503 prior to the current one."
2505 (outline-open-topic 1 (> 0 arg
)))
2506 ;;;_ > outline-open-sibtopic (arg)
2507 (defun outline-open-sibtopic (arg)
2508 "Open new topic header at same level as the current one.
2510 Negative universal arg means to place the new topic prior to the current
2513 (outline-open-topic 0 (> 0 arg
)))
2514 ;;;_ > outline-open-supertopic (arg)
2515 (defun outline-open-supertopic (arg)
2516 "Open new topic header at shallower level than the current one.
2518 Negative universal arg means to open shallower, but place the new
2519 topic prior to the current one."
2522 (outline-open-topic -
1 (> 0 arg
)))
2524 ;;;_ - Outline Alteration
2525 ;;;_ : Topic Modification
2526 ;;;_ = outline-former-auto-filler
2527 (defvar outline-former-auto-filler nil
2528 "Name of modal fill function being wrapped by outline-auto-fill.")
2529 ;;;_ > outline-auto-fill ()
2530 (defun outline-auto-fill ()
2531 "Outline-mode autofill function.
2533 Maintains outline hanging topic indentation if
2534 `outline-use-hanging-indents' is set."
2535 (let ((fill-prefix (if outline-use-hanging-indents
2536 ;; Check for topic header indentation:
2539 (if (looking-at outline-regexp
)
2540 ;; ... construct indentation to account for
2541 ;; length of topic prefix:
2542 (make-string (progn (outline-end-of-prefix)
2545 (if (or outline-former-auto-filler outline-use-hanging-indents
)
2547 ;;;_ > outline-reindent-body (old-depth new-depth &optional number)
2548 (defun outline-reindent-body (old-depth new-depth
&optional number
)
2549 "Reindent body lines which were indented at old-depth to new-depth.
2551 Optional arg NUMBER indicates numbering is being added, and it must
2554 Note that refill of indented paragraphs is not done."
2557 (outline-end-of-prefix)
2558 (let* ((new-margin (current-column))
2559 excess old-indent-begin old-indent-end
2561 ;; We want the column where the header-prefix text started
2562 ;; *before* the prefix was changed, so we infer it relative
2563 ;; to the new margin and the shift in depth:
2564 (old-margin (+ old-depth
(- new-margin new-depth
))))
2566 ;; Process lines up to (but excluding) next topic header:
2567 (outline-unprotected
2570 (and (re-search-forward "[\n\r]\\(\\s-*\\)"
2573 ;; Register the indent data, before we reset the
2574 ;; match data with a subsequent 'looking-at':
2575 (setq old-indent-begin
(match-beginning 1)
2576 old-indent-end
(match-end 1))
2577 (not (looking-at outline-regexp
)))
2578 (if (> 0 (setq excess
(- (current-column)
2580 ;; Text starts left of old margin - don't adjust:
2582 ;; Text was hanging at or right of old left margin -
2583 ;; reindent it, preserving its existing indentation
2584 ;; beyond the old margin:
2585 (delete-region old-indent-begin old-indent-end
)
2586 (indent-to (+ new-margin excess
)))))))))
2587 ;;;_ > outline-rebullet-current-heading (arg)
2588 (defun outline-rebullet-current-heading (arg)
2589 "Like non-interactive version 'outline-rebullet-heading'.
2591 But \(only\) affects visible heading containing point.
2593 With repeat count, solicit for bullet."
2595 (save-excursion (outline-back-to-current-heading)
2596 (outline-end-of-prefix)
2597 (outline-rebullet-heading (not arg
) ;;; solicit
2599 nil
;;; number-control
2601 t
) ;;; do-successors
2604 ;;;_ > outline-rebullet-heading (&optional solicit ...)
2605 (defun outline-rebullet-heading (&optional solicit
2611 "Adjust bullet of current topic prefix.
2613 All args are optional.
2615 If SOLICIT is non-nil then the choice of bullet is solicited from
2616 user. Otherwise the distinctiveness of the bullet or the topic
2617 depth determines it.
2619 Second arg DEPTH forces the topic prefix to that depth, regardless
2620 of the topics current depth.
2622 Third arg NUMBER-CONTROL can force the prefix to or away from
2623 numbered form. It has effect only if 'outline-numbered-bullet' is
2624 non-nil and soliciting was not explicitly invoked (via first arg).
2625 Its effect, numbering or denumbering, then depends on the setting
2626 of the forth arg, INDEX.
2628 If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the
2629 prefix of the topic is forced to be non-numbered. Null index and
2630 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
2631 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
2632 INDEX is a number, then that number is used for the numbered
2633 prefix. Non-nil and non-number means that the index for the
2634 numbered prefix will be derived by outline-make-topic-prefix.
2636 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
2639 Cf vars 'outline-stylish-prefixes', 'outline-old-style-prefixes',
2640 and 'outline-numbered-bullet', which all affect the behavior of
2643 (let* ((current-depth (outline-depth))
2644 (new-depth (or new-depth current-depth
))
2645 (mb outline-recent-prefix-beginning
)
2646 (me outline-recent-prefix-end
)
2647 (current-bullet (buffer-substring (- me
1) me
))
2648 (new-prefix (outline-make-topic-prefix current-bullet
2655 ;; Is new one is identical to old?
2656 (if (and (= current-depth new-depth
)
2657 (string= current-bullet
2658 (substring new-prefix
(1- (length new-prefix
)))))
2662 ;; New prefix probably different from old:
2663 ; get rid of old one:
2664 (outline-unprotected (delete-region mb me
))
2666 ; Dispense with number if
2667 ; numbered-bullet prefix:
2668 (if (and outline-numbered-bullet
2669 (string= outline-numbered-bullet current-bullet
)
2670 (looking-at "[0-9]+"))
2671 (outline-unprotected
2672 (delete-region (match-beginning 0)(match-end 0))))
2674 ; Put in new prefix:
2675 (outline-unprotected (insert-string new-prefix
))
2677 ;; Reindent the body if elected and margin changed:
2678 (if (and outline-reindent-bodies
2679 (not (= new-depth current-depth
)))
2680 (outline-reindent-body current-depth new-depth
))
2682 ;; Recursively rectify successive siblings of orig topic if
2683 ;; caller elected for it:
2686 (while (outline-next-sibling new-depth nil
)
2688 (cond ((numberp index
) (1+ index
))
2689 ((not number-control
) (outline-sibling-index))))
2690 (if (outline-numbered-type-prefix)
2691 (outline-rebullet-heading nil
;;; solicit
2692 new-depth
;;; new-depth
2693 number-control
;;; number-control
2695 nil
))))) ;;;(dont!)do-successors
2696 ) ; (if (and (= current-depth new-depth)...))
2697 ) ; let* ((current-depth (outline-depth))...)
2699 ;;;_ > outline-rebullet-topic (arg)
2700 (defun outline-rebullet-topic (arg)
2701 "Like outline-rebullet-topic-grunt, but start from topic visible at point.
2703 Descends into invisible as well as visible topics, however.
2705 With repeat count, shift topic depth by that amount."
2707 (let ((start-col (current-column))
2711 (cond ((null arg
) (setq arg
0))
2712 ((listp arg
) (setq arg
(car arg
))))
2713 ;; Fill the user in, in case we're shifting a big topic:
2714 (if (not (zerop arg
)) (message "Shifting..."))
2715 (outline-back-to-current-heading)
2716 (if (<= (+ (outline-recent-depth) arg
) 0)
2717 (error "Attempt to shift topic below level 1"))
2718 (outline-rebullet-topic-grunt arg
)
2719 (if (not (zerop arg
)) (message "Shifting... done.")))
2720 (move-to-column (max 0 (+ start-col arg
)))))
2721 ;;;_ > outline-rebullet-topic-grunt (&optional relative-depth ...)
2722 (defun outline-rebullet-topic-grunt (&optional relative-depth
2728 "Rebullet the topic at point, visible or invisible, and all
2729 contained subtopics. See outline-rebullet-heading for rebulleting
2732 All arguments are optional.
2734 First arg RELATIVE-DEPTH means to shift the depth of the entire
2737 The rest of the args are for internal recursive use by the function
2738 itself. The are STARTING-DEPTH, STARTING-POINT, and INDEX."
2740 (let* ((relative-depth (or relative-depth
0))
2741 (new-depth (outline-depth))
2742 (starting-depth (or starting-depth new-depth
))
2743 (on-starting-call (null starting-point
))
2745 ;; Leave index null on starting call, so rebullet-heading
2746 ;; calculates it at what might be new depth:
2747 (and (or (zerop relative-depth
)
2748 (not on-starting-call
))
2749 (outline-sibling-index))))
2750 (moving-outwards (< 0 relative-depth
))
2751 (starting-point (or starting-point
(point))))
2753 ;; Sanity check for excessive promotion done only on starting call:
2754 (and on-starting-call
2756 (> 0 (+ starting-depth relative-depth
))
2757 (error "Attempt to shift topic out beyond level 1.")) ;;; ====>
2759 (cond ((= starting-depth new-depth
)
2760 ;; We're at depth to work on this one:
2761 (outline-rebullet-heading nil
;;; solicit
2762 (+ starting-depth
;;; starting-depth
2766 ;; Every contained topic will get hit,
2767 ;; and we have to get to outside ones
2769 nil
) ;;; do-successors
2770 ;; ... and work on subsequent ones which are at greater depth:
2772 (outline-next-heading)
2773 (while (and (not (eobp))
2774 (< starting-depth
(outline-recent-depth)))
2775 (setq index
(1+ index
))
2776 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
2777 (1+ starting-depth
);;;starting-depth
2778 starting-point
;;; starting-point
2781 ((< starting-depth new-depth
)
2782 ;; Rare case - subtopic more than one level deeper than parent.
2783 ;; Treat this one at an even deeper level:
2784 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
2785 new-depth
;;; starting-depth
2786 starting-point
;;; starting-point
2789 (if on-starting-call
2791 ;; Rectify numbering of former siblings of the adjusted topic,
2792 ;; if topic has changed depth
2793 (if (or do-successors
2794 (and (not (zerop relative-depth
))
2795 (or (= (outline-recent-depth) starting-depth
)
2796 (= (outline-recent-depth) (+ starting-depth
2798 (outline-rebullet-heading nil nil nil nil t
))
2799 ;; Now rectify numbering of new siblings of the adjusted topic,
2800 ;; if depth has been changed:
2801 (progn (goto-char starting-point
)
2802 (if (not (zerop relative-depth
))
2803 (outline-rebullet-heading nil nil nil nil t
)))))
2806 ;;;_ > outline-renumber-to-depth (&optional depth)
2807 (defun outline-renumber-to-depth (&optional depth
)
2808 "Renumber siblings at current depth.
2810 Affects superior topics if optional arg DEPTH is less than current depth.
2812 Returns final depth."
2814 ;; Proceed by level, processing subsequent siblings on each,
2815 ;; ascending until we get shallower than the start depth:
2817 (let ((ascender (outline-depth)))
2818 (while (and (not (eobp))
2820 (>= (outline-recent-depth) depth
)
2821 (>= ascender depth
))
2822 ; Skip over all topics at
2823 ; lesser depths, which can not
2824 ; have been disturbed:
2825 (while (and (not (eobp))
2826 (> (outline-recent-depth) ascender
))
2827 (outline-next-heading))
2828 ; Prime ascender for ascension:
2829 (setq ascender
(1- (outline-recent-depth)))
2830 (if (>= (outline-recent-depth) depth
)
2831 (outline-rebullet-heading nil
;;; solicit
2833 nil
;;; number-control
2835 t
))));;; do-successors
2836 (outline-recent-depth))
2837 ;;;_ > outline-number-siblings (&optional denumber)
2838 (defun outline-number-siblings (&optional denumber
)
2839 "Assign numbered topic prefix to this topic and its siblings.
2841 With universal argument, denumber - assign default bullet to this
2842 topic and its siblings.
2844 With repeated universal argument (`^U^U'), solicit bullet for each
2845 rebulleting each topic at this level."
2850 (outline-back-to-current-heading)
2851 (outline-beginning-of-level)
2852 (let ((depth (outline-recent-depth))
2853 (index (if (not denumber
) 1))
2854 (use-bullet (equal '(16) denumber
))
2857 (outline-rebullet-heading use-bullet
;;; solicit
2859 t
;;; number-control
2861 nil
) ;;; do-successors
2862 (if index
(setq index
(1+ index
)))
2863 (setq more
(outline-next-sibling depth nil
))))))
2864 ;;;_ > outline-shift-in (arg)
2865 (defun outline-shift-in (arg)
2866 "Increase depth of current heading and any topics collapsed within it."
2868 (outline-rebullet-topic arg
))
2869 ;;;_ > outline-shift-out (arg)
2870 (defun outline-shift-out (arg)
2871 "Decrease depth of current heading and any topics collapsed within it."
2873 (outline-rebullet-topic (* arg -
1)))
2874 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
2875 ;;;_ > outline-kill-line (&optional arg)
2876 (defun outline-kill-line (&optional arg
)
2877 "Kill line, adjusting subsequent lines suitably for outline mode."
2880 (if (not (and (outline-mode-p) ; active outline mode,
2881 outline-numbered-bullet
; numbers may need adjustment,
2882 (bolp) ; may be clipping topic head,
2883 (looking-at outline-regexp
))) ; are clipping topic head.
2884 ;; Above conditions do not obtain - just do a regular kill:
2886 ;; Ah, have to watch out for adjustments:
2887 (let* ((depth (outline-depth)))
2890 ; Provide some feedback:
2893 ; Start with the topic
2894 ; following killed line:
2895 (if (not (looking-at outline-regexp
))
2896 (outline-next-heading))
2897 (outline-renumber-to-depth depth
)))))
2898 ;;;_ > outline-kill-topic ()
2899 (defun outline-kill-topic ()
2900 "Kill topic together with subtopics.
2902 Leaves primary topic's trailing vertical whitespace, if any."
2904 ;; Some finagling is done to make complex topic kills appear faster
2905 ;; than they actually are. A redisplay is performed immediately
2906 ;; after the region is disposed of, though the renumbering process
2907 ;; has yet to be performed. This means that there may appear to be
2908 ;; a lag *after* the kill has been performed.
2911 (let* ((beg (prog1 (outline-back-to-current-heading)(beginning-of-line)))
2912 (depth (outline-recent-depth)))
2913 (outline-end-of-current-subtree)
2915 (if (or (not (looking-at "^$"))
2916 ;; A blank line - cut it with this topic *unless* this
2917 ;; is the last topic at this level, in which case
2918 ;; we'll leave the blank line as part of the
2919 ;; containing topic:
2921 (and (outline-next-heading)
2922 (>= (outline-recent-depth) depth
))))
2925 (kill-region beg
(point))
2928 (outline-renumber-to-depth depth
))))
2929 ;;;_ > outline-yank-processing ()
2930 (defun outline-yank-processing (&optional arg
)
2932 "Incidental outline-specific business to be done just after text yanks.
2934 Does depth adjustment of yanked topics, when:
2936 1 the stuff being yanked starts with a valid outline header prefix, and
2937 2 it is being yanked at the end of a line which consists of only a valid
2940 Also, adjusts numbering of subsequent siblings when appropropriate.
2942 Depth adjustment alters the depth of all the topics being yanked
2943 the amount it takes to make the first topic have the depth of the
2944 header into which it's being yanked.
2946 The point is left in front of yanked, adjusted topics, rather than
2947 at the end (and vice-versa with the mark). Non-adjusted yanks,
2948 however, are left exactly like normal, non-outline-specific yanks."
2951 ; Get to beginning, leaving
2952 ; region around subject:
2953 (if (< (mark-marker) (point))
2954 (exchange-point-and-mark))
2955 (let* ((subj-beg (point))
2956 (subj-end (mark-marker))
2957 ;; 'resituate' if yanking an entire topic into topic header:
2958 (resituate (and (outline-e-o-prefix-p)
2959 (looking-at (concat "\\(" outline-regexp
"\\)"))
2960 (outline-prefix-data (match-beginning 1)
2962 ;; 'rectify-numbering' if resituating (where several topics may
2963 ;; be resituating) or yanking a topic into a topic slot (bol):
2964 (rectify-numbering (or resituate
2965 (and (bolp) (looking-at outline-regexp
)))))
2967 ; The yanked stuff is a topic:
2968 (let* ((prefix-len (- (match-end 1) subj-beg
))
2969 (subj-depth (outline-recent-depth))
2970 (prefix-bullet (outline-recent-bullet))
2972 ;; Nil if adjustment unnecessary, otherwise depth to which
2973 ;; adjustment should be made:
2975 (and (goto-char subj-end
)
2977 (goto-char subj-beg
)
2978 (and (looking-at outline-regexp
)
2981 (not (= (point) subj-beg
)))
2982 (looking-at outline-regexp
)
2983 (outline-prefix-data (match-beginning 0)
2985 (outline-recent-depth))))
2988 (setq rectify-numbering outline-numbered-bullet
)
2990 ; Do the adjustment:
2992 (message "... yanking") (sit-for 0)
2994 (narrow-to-region subj-beg subj-end
)
2995 ; Trim off excessive blank
2996 ; line at end, if any:
2997 (goto-char (point-max))
2998 (if (looking-at "^$")
2999 (outline-unprotected (delete-char -
1)))
3000 ; Work backwards, with each
3002 ; successively excluding the
3003 ; last processed topic from
3004 ; the narrow region:
3006 (outline-back-to-current-heading)
3007 ; go as high as we can in each bunch:
3008 (while (outline-ascend-to-depth (1- (outline-depth))))
3010 (outline-rebullet-topic-grunt (- adjust-to-depth
3013 (if (setq more
(not (bobp)))
3016 (narrow-to-region subj-beg
(point))))))
3018 ;; Preserve new bullet if it's a distinctive one, otherwise
3020 (if (string-match (regexp-quote prefix-bullet
)
3021 outline-distinctive-bullets-string
)
3022 ; Delete from bullet of old to
3023 ; before bullet of new:
3026 (delete-region (point) subj-beg
)
3027 (set-marker (mark-marker) subj-end
)
3028 (goto-char subj-beg
)
3029 (outline-end-of-prefix))
3030 ; Delete base subj prefix,
3032 (delete-region (point) (+ (point)
3034 (- adjust-to-depth subj-depth
)))
3035 ; and delete residual subj
3036 ; prefix digits and space:
3037 (while (looking-at "[0-9]") (delete-char 1))
3038 (if (looking-at " ") (delete-char 1))))
3039 (exchange-point-and-mark))))
3040 (if rectify-numbering
3043 ; Give some preliminary feedback:
3044 (message "... reconciling numbers") (sit-for 0)
3045 ; ... and renumber, in case necessary:
3046 (goto-char subj-beg
)
3047 (if (outline-goto-prefix)
3048 (outline-rebullet-heading nil
;;; solicit
3049 (outline-depth) ;;; depth
3050 nil
;;; number-control
3055 (exchange-point-and-mark))))
3056 ;;;_ > outline-yank (&optional arg)
3057 (defun outline-yank (&optional arg
)
3058 "Outline-mode yank, with depth and numbering adjustment of yanked topics.
3060 Non-topic yanks work no differntly than normal yanks.
3062 If a topic is being yanked into a bare topic prefix, the depth of the
3063 yanked topic is adjusted to the depth of the topic prefix.
3065 1 we're yanking in an outline-mode buffer
3066 2 the stuff being yanked starts with a valid outline header prefix, and
3067 3 it is being yanked at the end of a line which consists of only a valid
3070 If these conditions hold then the depth of the yanked topics are all
3071 adjusted the amount it takes to make the first one at the depth of the
3072 header into which it's being yanked.
3074 The point is left in front of yanked, adjusted topics, rather than
3075 at the end (and vice-versa with the mark). Non-adjusted yanks,
3076 however, (ones that don't qualify for adjustment) are handled
3077 exactly like normal yanks.
3079 Numbering of yanked topics, and the succesive siblings at the depth
3080 into which they're being yanked, is adjusted.
3082 Outline-yank-pop works with outline-yank just like normal yank-pop
3083 works with normal yank in non-outline buffers."
3086 (setq this-command
'yank
)
3088 (if (outline-mode-p)
3089 (outline-yank-processing)))
3090 ;;;_ > outline-yank-pop (&optional arg)
3091 (defun outline-yank-pop (&optional arg
)
3092 "Yank-pop like outline-yank when popping to bare outline prefixes.
3094 Adapts level of popped topics to level of fresh prefix.
3096 Note - prefix changes to distinctive bullets will stick, if followed
3097 by pops to non-distinctive yanks. Bug..."
3100 (setq this-command
'yank
)
3102 (if (outline-mode-p)
3103 (outline-yank-processing)))
3105 ;;;_ - Specialty bullet functions
3106 ;;;_ : File Cross references
3107 ;;;_ > outline-resolve-xref ()
3108 (defun outline-resolve-xref ()
3109 "Pop to file associated with current heading, if it has an xref bullet.
3111 \(Works according to setting of `outline-file-xref-bullet')."
3113 (if (not outline-file-xref-bullet
)
3115 "outline cross references disabled - no 'outline-file-xref-bullet'")
3116 (if (not (string= (outline-current-bullet) outline-file-xref-bullet
))
3117 (error "current heading lacks cross-reference bullet '%s'"
3118 outline-file-xref-bullet
)
3121 (let* ((text-start outline-recent-prefix-end
)
3122 (heading-end (progn (outline-pre-next-preface)
3124 (goto-char text-start
)
3126 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
3127 (buffer-substring (match-beginning 1) (match-end 1))))))
3129 (if (not (= (aref file-name
0) ?
:))
3130 (expand-file-name file-name
)
3131 ; A registry-files ref, strip the ':'
3132 ; and try to follow it:
3133 (let ((reg-ref (reference-registered-file
3134 (substring file-name
1) nil t
)))
3135 (if reg-ref
(car (cdr reg-ref
))))))
3136 (if (or (file-exists-p file-name
)
3137 (if (file-writable-p file-name
)
3138 (y-or-n-p (format "%s not there, create one? "
3140 (error "%s not found and can't be created" file-name
)))
3141 (condition-case failure
3142 (find-file-other-window file-name
)
3144 (error "%s not found" file-name
))
3150 ;;;_ #6 Exposure Control and Processing
3153 ;;;_ > outline-flag-region (from to flag)
3154 (defmacro outline-flag-region
(from to flag
)
3155 "Hide or show lines from FROM to TO, via emacs selective-display FLAG char.
3156 Ie, text following flag C-m \(carriage-return) is hidden until the
3157 next C-j (newline) char.
3159 Returns the endpoint of the region."
3160 (` (let ((buffer-read-only nil
)
3161 (outline-override-protect t
))
3162 (subst-char-in-region (, from
) (, to
)
3163 (if (= (, flag
) ?
\n) ?
\r ?
\n)
3165 ;;;_ > outline-flag-current-subtree (flag)
3166 (defun outline-flag-current-subtree (flag)
3167 "Hide or show subtree of currently-visible topic.
3169 See `outline-flag-region' for more details."
3172 (outline-back-to-current-heading)
3173 (outline-flag-region (point)
3174 (progn (outline-end-of-current-subtree) (1- (point)))
3177 ;;;_ - Mapping and processing of topics
3178 ;;;_ " See also chart functions, in navigation
3179 ;;;_ > outline-listify-exposed (&optional start end)
3180 (defun outline-listify-exposed (&optional start end
)
3182 "Produce a list representing exposed topics in current region.
3184 This list can then be used by 'outline-process-exposed' to manipulate
3187 List is composed of elements that may themselves be lists representing
3188 exposed components in subtopic.
3190 Each component list contains:
3191 - a number representing the depth of the topic,
3192 - a string representing the header-prefix (ref. 'outline-header-prefix'),
3193 - a string representing the bullet character,
3194 - and a series of strings, each containing one line of the exposed
3195 portion of the topic entry."
3199 (let* (strings pad result depth bullet beg next done
) ; State vars.
3202 (if (not (outline-goto-prefix)) ; Get initial position within a topic:
3203 (outline-next-visible-heading 1))
3204 (while (and (not done
)
3205 (not (eobp)) ; Loop until we've covered the region.
3206 (not (> (point) end
)))
3207 (setq depth
(outline-recent-depth) ; Current topics' depth,
3208 bullet
(outline-recent-bullet) ; ... bullet,
3209 beg
(progn (outline-end-of-prefix t
) (point))) ; and beginning.
3210 (setq done
; The boundary for the current topic:
3211 (not (outline-next-visible-heading 1)))
3216 (while (> next
(point)) ; Get all the exposed text in
3218 (cons (buffer-substring
3220 ;To hidden text or end of line:
3222 (search-forward "\r"
3223 (save-excursion (end-of-line)
3226 (if (= (preceding-char) ?
\r)
3230 (if (< (point) next
) ; Resume from after hid text, if any.
3233 ;; Accumulate list for this topic:
3235 (cons (append (list depth
3236 outline-header-prefix
3240 ;; Put the list with first at front, to last at back:
3241 (nreverse result
))))
3242 ;;;_ > outline-process-exposed (arg &optional tobuf)
3243 (defun outline-process-exposed (&optional func from to frombuf tobuf
)
3244 "Map function on exposed parts of current topic; results to another buffer.
3246 Apply FUNCTION \(default 'outline-insert-listified) to exposed
3247 portions FROM position TO position \(default region, or the entire
3248 buffer if no region active) in buffer FROMBUF \(default current
3249 buffer) to buffer TOBUF \(default is buffer named like frombuf but
3250 with \"*\" prepended and \" exposed*\" appended).
3252 The function must as its arguments the elements of the list
3253 representations of topic entries produced by outline-listify-exposed."
3255 ; Resolve arguments,
3256 ; defaulting if necessary:
3257 (if (not func
) (setq func
'outline-insert-listified
))
3258 (if (not (and from to
))
3260 (setq from
(region-beginning) to
(region-end))
3261 (setq from
(point-min) to
(point-max))))
3263 (if (not (bufferp frombuf
))
3264 ;; Specified but not a buffer - get it:
3265 (let ((got (get-buffer frombuf
)))
3267 (error (concat "outline-process-exposed: source buffer "
3270 (setq frombuf got
))))
3271 ;; not specified - default it:
3272 (setq frombuf
(current-buffer)))
3274 (if (not (bufferp tobuf
))
3275 (setq tobuf
(get-buffer-create tobuf
)))
3276 ;; not specified - default it:
3277 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
3279 (let* ((listified (progn (set-buffer frombuf
)
3280 (outline-listify-exposed from to
)))
3281 (prefix outline-header-prefix
) ; ... as set in frombuf.
3285 (setq curr
(car listified
))
3286 (setq listified
(cdr listified
))
3287 (apply func
(list (car curr
) ; depth
3288 (car (cdr curr
)) ; header-prefix
3289 (car (cdr (cdr curr
))) ; bullet
3290 (cdr (cdr (cdr curr
)))))) ; list of text lines
3291 (pop-to-buffer tobuf
)))
3293 ;;;_ - Topic-specific
3294 ;;;_ > outline-show-entry ()
3295 ; outline-show-entry basically for isearch dynamic exposure, as is...
3296 (defun outline-show-entry ()
3297 "Like `outline-show-current-entry', reveals entries nested in hidden topics.
3299 This is a way to give restricted peek at a concealed locality without the
3300 expense of exposing its context, but can leave the outline with aberrant
3301 exposure. outline-hide-current-entry-completely or outline-show-offshoot
3302 should be used after the peek to rectify the exposure."
3306 (outline-goto-prefix)
3307 (outline-flag-region (if (bobp) (point) (1- (point)))
3308 (or (outline-pre-next-preface) (point))
3310 ;;;_ > outline-show-children (&optional level strict)
3311 (defun outline-show-children (&optional level strict
)
3313 "If point is visible, show all direct subheadings of this heading.
3315 Otherwise, do outline-show-to-offshoot, and then show subheadings.
3317 Optional LEVEL specifies how many levels below the current level
3318 should be shown, or all levels if t. Default is 1.
3320 Optional STRICT means don't resort to -show-to-offshoot, no matter
3321 what. This is basically so -show-to-offshoot, which is called by
3322 this function, can employ the pure offspring-revealing capabilities of
3325 Returns point at end of subtree that was opened, if any. (May get a
3326 point of non-opened subtree?)"
3330 (if (and (not strict
)
3333 (progn (outline-show-to-offshoot) ; Point's concealed, open to
3335 ;; Then recurse, but with "strict" set so we don't
3336 ;; infinite regress:
3337 (setq max-pos
(outline-show-children level t
)))
3341 (let* ((start-pt (point))
3342 (chart (outline-chart-subtree (or level
1)))
3343 (to-reveal (outline-chart-to-reveal chart
(or level
1))))
3344 (goto-char start-pt
)
3345 (if (and strict
(= (preceding-char) ?
\r))
3346 ;; Concealed root would already have been taken care of,
3347 ;; unless strict was set.
3348 (outline-flag-region (point) (outline-snug-back) ?
\n))
3350 (goto-char (car to-reveal
))
3351 (outline-flag-region (point) (outline-snug-back) ?
\n)
3352 (setq to-reveal
(cdr to-reveal
)))))))))
3353 ;;;_ x outline-show-current-children (&optional level strict)
3354 (defun outline-show-current-children (&optional level strict
)
3355 "This command was misnamed, use `outline-show-children' instead.
3357 \(The \"current\" in the name is supposed to imply that it works on
3358 the visible topic containing point, while it really works with respect
3359 to the most immediate topic, concealed or not. I'll leave this old
3360 name around for a bit, but i'll soon activate an annoying message to
3361 warn people about the change, and then deprecate this alias."
3365 ;;(message (format "Use '%s' instead of '%s' (%s)."
3366 ;; "outline-show-children"
3367 ;; "outline-show-current-children"
3368 ;; (buffer-name (current-buffer))))
3369 (outline-show-children level strict
))
3370 ;;;_ > outline-hide-point-reconcile ()
3371 (defun outline-hide-reconcile ()
3372 "Like `outline-hide-current-entry'; hides completely if within hidden region.
3374 Specifically intended for aberrant exposure states, like entries that were
3375 exposed by outline-show-entry but are within otherwise concealed regions."
3378 (outline-goto-prefix)
3379 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3380 (progn (outline-pre-next-preface)
3381 (if (= ?
\r (following-char))
3385 ;;;_ > outline-show-to-offshoot ()
3386 (defun outline-show-to-offshoot ()
3387 "Like outline-show-entry, but reveals opens all concealed ancestors, as well.
3389 As with outline-hide-current-entry-completely, useful for rectifying
3390 aberrant exposure states produced by outline-show-entry."
3394 (let ((orig-pt (point))
3395 (orig-pref (outline-goto-prefix))
3398 (while (or bag-it
(= (preceding-char) ?
\r))
3400 (if (= last-at
(setq last-at
(point)))
3401 ;; Oops, we're not making any progress! Show the current
3402 ;; topic completely, and bag this try.
3403 (progn (beginning-of-line)
3404 (outline-show-current-subtree)
3409 "outline-show-to-offshoot: "
3410 "Aberrant nesting encountered.")))
3411 (outline-show-children)
3412 (goto-char orig-pref
))
3413 (goto-char orig-pt
)))
3414 (if (outline-hidden-p)
3415 (outline-show-entry)))
3416 ;;;_ > outline-hide-current-entry ()
3417 (defun outline-hide-current-entry ()
3418 "Hide the body directly following this heading."
3420 (outline-back-to-current-heading)
3422 (outline-flag-region (point)
3423 (progn (outline-end-of-current-entry) (point))
3425 ;;;_ > outline-show-current-entry (&optional arg)
3426 (defun outline-show-current-entry (&optional arg
)
3428 "Show body following current heading, or hide the entry if repeat count."
3432 (outline-hide-current-entry)
3434 (outline-flag-region (point)
3435 (progn (outline-end-of-current-entry) (point))
3437 ;;;_ > outline-hide-current-entry-completely ()
3438 ; ... outline-hide-current-entry-completely also for isearch dynamic exposure:
3439 (defun outline-hide-current-entry-completely ()
3440 "Like outline-hide-current-entry, but conceal topic completely.
3442 Specifically intended for aberrant exposure states, like entries that were
3443 exposed by outline-show-entry but are within otherwise concealed regions."
3446 (outline-goto-prefix)
3447 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3448 (progn (outline-pre-next-preface)
3449 (if (= ?
\r (following-char))
3453 ;;;_ > outline-show-current-subtree (&optional arg)
3454 (defun outline-show-current-subtree (&optional arg
)
3455 "Show everything within the current topic. With a repeat-count,
3456 expose this topic and its' siblings."
3459 (if (<= (outline-current-depth) 0)
3460 ;; Outside any topics - try to get to the first:
3461 (if (not (outline-next-heading))
3462 (error "No topics.")
3463 ;; got to first, outermost topic - set to expose it and siblings:
3464 (message "Above outermost topic - exposing all.")
3465 (outline-flag-region (point-min)(point-max) ?
\n))
3467 (outline-flag-current-subtree ?
\n)
3468 (outline-beginning-of-level)
3469 (outline-expose-topic '(* :))))))
3470 ;;;_ > outline-hide-current-subtree (&optional just-close)
3471 (defun outline-hide-current-subtree (&optional just-close
)
3472 "Close the current topic, or containing topic if this one is already closed.
3474 If this topic is closed and it's a top level topic, close this topic
3477 If optional arg JUST-CLOSE is non-nil, do not treat the parent or
3478 siblings, even if the target topic is already closed."
3481 (let ((from (point))
3482 (orig-eol (progn (end-of-line)
3483 (if (not (outline-goto-prefix))
3484 (error "No topics found.")
3485 (end-of-line)(point)))))
3486 (outline-flag-current-subtree ?\^M
)
3488 (if (and (= orig-eol
(progn (goto-char orig-eol
)
3492 ;; Structure didn't change - try hiding current level:
3494 (if (outline-up-current-level 1 t
)
3498 "Top-level topic already closed - closing siblings..."))
3500 (outline-expose-topic '(0 :))
3501 (message (concat msg
" Done.")))
3503 (/= (outline-recent-depth) 0))
3504 (outline-hide-current-subtree))
3506 ;;;_ > outline-show-current-branches ()
3507 (defun outline-show-current-branches ()
3508 "Show all subheadings of this heading, but not their bodies."
3511 (outline-show-children t
))
3512 ;;;_ > outline-hide-current-leaves ()
3513 (defun outline-hide-current-leaves ()
3514 "Hide the bodies of the current topic and all its' offspring."
3516 (outline-back-to-current-heading)
3517 (outline-hide-region-body (point) (progn (outline-end-of-current-subtree)
3520 ;;;_ - Region and beyond
3521 ;;;_ > outline-show-all ()
3522 (defun outline-show-all ()
3523 "Show all of the text in the buffer."
3525 (message "Exposing entire buffer...")
3526 (outline-flag-region (point-min) (point-max) ?
\n)
3527 (message "Exposing entire buffer... Done."))
3528 ;;;_ > outline-hide-bodies ()
3529 (defun outline-hide-bodies ()
3530 "Hide all of buffer except headings."
3532 (outline-hide-region-body (point-min) (point-max)))
3533 ;;;_ > outline-hide-region-body (start end)
3534 (defun outline-hide-region-body (start end
)
3535 "Hide all body lines in the region, but not headings."
3538 (narrow-to-region start end
)
3539 (goto-char (point-min))
3541 (outline-flag-region (point)
3542 (progn (outline-pre-next-preface) (point)) ?\^M
)
3545 (if (looking-at "[\n\r][\n\r]")
3548 ;;;_ > outline-expose-topic (spec)
3549 (defun outline-expose-topic (spec)
3550 "Apply exposure specs to successive outline topic items.
3552 Use the more convenient frontend, `outline-new-exposure', if you don't
3553 need evaluation of the arguments, or even better, the `outline-layout'
3554 variable-keyed mode-activation/auto-exposure feature of allout outline
3555 mode. See the respective documentation strings for more details.
3557 Cursor is left at start position.
3559 SPEC is either a number or a list.
3561 Successive specs on a list are applied to successive sibling topics.
3563 A simple spec \(either a number, one of a few symbols, or the null
3564 list) dictates the exposure for the corresponding topic.
3566 Non-null lists recursively designate exposure specs for respective
3567 subtopics of the current topic.
3569 The ':' repeat spec is used to specify exposure for any number of
3570 successive siblings, up to the trailing ones for which there are
3571 explicit specs following the ':'.
3573 Simple (numeric and null-list) specs are interpreted as follows:
3575 Numbers indicate the relative depth to open the corresponding topic.
3576 - negative numbers force the topic to be closed before opening to the
3577 absolute value of the number, so all siblings are open only to
3579 - positive numbers open to the relative depth indicated by the
3580 number, but do not force already opened subtopics to be closed.
3581 - 0 means to close topic - hide all offspring.
3583 apply prior element to all siblings at current level, *up to*
3584 those siblings that would be covered by specs following the ':'
3585 on the list. Ie, apply to all topics at level but the last
3586 ones. \(Only first of multiple colons at same level is
3587 respected - subsequent ones are discarded.)
3588 * - completely opens the topic, including bodies.
3589 + - shows all the sub headers, but not the bodies
3590 - - exposes the body of the corresponding topic.
3593 \(outline-expose-topic '(-1 : 0))
3594 Close this and all following topics at current level, exposing
3595 only their immediate children, but close down the last topic
3596 at this current level completely.
3597 \(outline-expose-topic '(-1 () : 1 0))
3598 Close current topic so only the immediate subtopics are shown;
3599 show the children in the second to last topic, and completely
3601 \(outline-expose-topic '(-2 : -1 *))
3602 Expose children and grandchildren of all topics at current
3603 level except the last two; expose children of the second to
3604 last and completely open the last one."
3606 (interactive "xExposure spec: ")
3607 (if (not (listp spec
))
3609 (let ((depth (outline-depth))
3616 (setq prev-elem curr-elem
3617 curr-elem
(car spec
)
3619 (cond ; Do current element:
3620 ((null curr-elem
) nil
)
3621 ((symbolp curr-elem
)
3622 (cond ((eq curr-elem
'*) (outline-show-current-subtree)
3623 (if (> outline-recent-end-of-subtree max-pos
)
3624 (setq max-pos outline-recent-end-of-subtree
)))
3625 ((eq curr-elem
'+) (outline-show-current-branches)
3626 (if (> outline-recent-end-of-subtree max-pos
)
3627 (setq max-pos outline-recent-end-of-subtree
)))
3628 ((eq curr-elem
'-
) (outline-show-current-entry))
3631 ;; Expand the 'repeat' spec to an explicit version,
3632 ;; w.r.t. remaining siblings:
3633 (let ((residue ; = # of sibs not covered by remaining spec
3634 ;; Dang - could be nice to make use of the chart, sigh:
3635 (- (length (outline-chart-siblings))
3638 ;; Some residue - cover it with prev-elem:
3639 (setq spec
(append (make-list residue prev-elem
)
3641 ((numberp curr-elem
)
3642 (if (and (>= 0 curr-elem
) (outline-visible-p))
3643 (save-excursion (outline-hide-current-subtree t
)
3646 (if (> outline-recent-end-of-subtree max-pos
)
3648 outline-recent-end-of-subtree
)))))
3649 (if (> (abs curr-elem
) 0)
3650 (progn (outline-show-children (abs curr-elem
))
3651 (if (> outline-recent-end-of-subtree max-pos
)
3652 (setq max-pos outline-recent-end-of-subtree
)))))
3654 (if (outline-descend-to-depth (1+ depth
))
3655 (let ((got (outline-expose-topic curr-elem
)))
3656 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
3657 (cond (stay (setq stay nil
))
3658 ((listp (car spec
)) nil
)
3659 ((> max-pos
(point))
3660 ;; Capitalize on max-pos state to get us nearer next sibling:
3661 (progn (goto-char (min (point-max) max-pos
))
3662 (outline-next-heading)))
3663 ((outline-next-sibling depth
))))
3665 ;;;_ > outline-old-expose-topic (spec &rest followers)
3666 (defun outline-old-expose-topic (spec &rest followers
)
3668 "Deprecated. Use outline-expose-topic \(with different schema
3671 Dictate wholesale exposure scheme for current topic, according to SPEC.
3673 SPEC is either a number or a list. Optional successive args
3674 dictate exposure for subsequent siblings of current topic.
3676 A simple spec (either a number, a special symbol, or the null list)
3677 dictates the overall exposure for a topic. Non null lists are
3678 composite specs whose first element dictates the overall exposure for
3679 a topic, with the subsequent elements in the list interpreted as specs
3680 that dictate the exposure for the successive offspring of the topic.
3682 Simple (numeric and null-list) specs are interpreted as follows:
3684 - Numbers indicate the relative depth to open the corresponding topic:
3685 - negative numbers force the topic to be close before opening to the
3686 absolute value of the number.
3687 - positive numbers just open to the relative depth indicated by the number.
3689 - '*' completely opens the topic, including bodies.
3690 - '+' shows all the sub headers, but not the bodies
3691 - '-' exposes the body and immediate offspring of the corresponding topic.
3693 If the spec is a list, the first element must be a number, which
3694 dictates the exposure depth of the topic as a whole. Subsequent
3695 elements of the list are nested SPECs, dictating the specific exposure
3696 for the corresponding offspring of the topic.
3698 Optional FOLLOWER arguments dictate exposure for succeeding siblings."
3700 (interactive "xExposure spec: ")
3701 (let ((depth (outline-current-depth))
3704 (cond ((null spec
) nil
)
3706 (if (eq spec
'*) (outline-show-current-subtree))
3707 (if (eq spec
'+) (outline-show-current-branches))
3708 (if (eq spec
'-
) (outline-show-current-entry)))
3711 (save-excursion (outline-hide-current-subtree t
)
3713 (if (or (not max-pos
)
3714 (> (point) max-pos
))
3715 (setq max-pos
(point)))
3717 (setq spec
(* -
1 spec
)))))
3719 (outline-show-children spec
)))
3721 ;(let ((got (outline-old-expose-topic (car spec))))
3722 ; (if (and got (or (not max-pos) (> got max-pos)))
3723 ; (setq max-pos got)))
3724 (let ((new-depth (+ (outline-current-depth) 1))
3726 (setq max-pos
(outline-old-expose-topic (car spec
)))
3727 (setq spec
(cdr spec
))
3729 (outline-descend-to-depth new-depth
)
3730 (not (outline-hidden-p)))
3731 (progn (setq got
(apply 'outline-old-expose-topic spec
))
3732 (if (and got
(or (not max-pos
) (> got max-pos
)))
3733 (setq max-pos got
)))))))
3734 (while (and followers
3735 (progn (if (and max-pos
(< (point) max-pos
))
3736 (progn (goto-char max-pos
)
3737 (setq max-pos nil
)))
3739 (outline-next-sibling depth
)))
3740 (outline-old-expose-topic (car followers
))
3741 (setq followers
(cdr followers
)))
3743 ;;;_ > outline-new-exposure '()
3744 (defmacro outline-new-exposure
(&rest spec
)
3745 "Literal frontend for `outline-expose-topic', doesn't evaluate arguments.
3746 Some arguments that would need to be quoted in outline-expose-topic
3747 need not be quoted in outline-new-exposure.
3749 Cursor is left at start position.
3751 Use this instead of obsolete 'outline-exposure'.
3754 \(outline-exposure (-1 () () () 1) 0)
3755 Close current topic at current level so only the immediate
3756 subtopics are shown, except also show the children of the
3757 third subtopic; and close the next topic at the current level.
3758 \(outline-exposure : -1 0)
3759 Close all topics at current level to expose only their
3760 immediate children, except for the last topic at the current
3761 level, in which even its' immediate children are hidden.
3762 \(outline-exposure -2 : -1 *)
3763 Expose children and grandchildren of first topic at current
3764 level, and expose children of subsequent topics at current
3765 level *except* for the last, which should be opened completely."
3766 (list 'save-excursion
3767 '(if (not (or (outline-goto-prefix)
3768 (outline-next-heading)))
3769 (error "outline-new-exposure: Can't find any outline topics."))
3770 (list 'outline-expose-topic
(list 'quote spec
))))
3771 ;;;_ > outline-exposure '()
3772 (defmacro outline-exposure
(&rest spec
)
3773 "Being deprecated - use more recent 'outline-new-exposure' instead.
3775 Literal frontend for `outline-old-expose-topic', doesn't evaluate arguments
3776 and retains start position."
3777 (list 'save-excursion
3778 '(if (not (or (outline-goto-prefix)
3779 (outline-next-heading)))
3780 (error "Can't find any outline topics."))
3781 (cons 'outline-old-expose-topic
3782 (mapcar '(lambda (x) (list 'quote x
)) spec
))))
3784 ;;;_ #7 ISearch with Dynamic Exposure
3785 ;;;_ = outline-search-reconceal
3786 (defvar outline-search-reconceal nil
3787 "Track whether current search match was concealed outside of search.
3789 The value is the location of the match, if it was concealed, regular
3790 if the entire topic was concealed, in a list if the entry was concealed.")
3791 ;;;_ = outline-search-quitting
3792 (defconst outline-search-quitting nil
3793 "Distinguishes isearch conclusion and cancellation.
3795 Used by isearch-terminate/outline-provisions and
3796 isearch-done/outline-provisions")
3799 ;;;_ > outline-enwrap-isearch ()
3800 (defun outline-enwrap-isearch ()
3801 "Impose outline-mode isearch-mode wrappers for dynamic exposure in isearch.
3803 Isearch progressively exposes and reconceals hidden topics when
3804 working in outline mode, but works normally elsewhere.
3806 The function checks to ensure that the rebindings are done only once."
3808 ; Should isearch-mode be employed,
3809 (if (or (not outline-enwrap-isearch-mode
)
3810 ; or are preparations already done?
3811 (fboundp 'real-isearch-terminate
))
3813 ;; ... no - skip this all:
3818 ; Ensure load of isearch-mode:
3819 (if (or (and (fboundp 'isearch-mode
)
3820 (fboundp 'isearch-quote-char
))
3821 (condition-case error
3822 (load-library outline-enwrap-isearch-mode
)
3823 (file-error (message "Skipping isearch-mode provisions - %s '%s'"
3825 (car (cdr (cdr error
))))
3827 ;; Inhibit subsequent tries and return nil:
3828 (setq outline-enwrap-isearch-mode nil
))))
3829 ;; Isearch-mode loaded, encapsulate specific entry points for
3830 ;; outline dynamic-exposure business:
3833 ;; stash crucial isearch-mode funcs under known, private
3834 ;; names, then register wrapper functions under the old
3835 ;; names, in their stead: 'isearch-quit' is pre isearch v 1.2.
3836 (fset 'real-isearch-terminate
3837 ; 'isearch-quit is pre v 1.2:
3838 (or (if (fboundp 'isearch-quit
)
3839 (symbol-function 'isearch-quit
))
3840 (if (fboundp 'isearch-abort
)
3841 ; 'isearch-abort' is v 1.2 and on:
3842 (symbol-function 'isearch-abort
))))
3843 (fset 'isearch-quit
'isearch-terminate
/outline-provisions
)
3844 (fset 'isearch-abort
'isearch-terminate
/outline-provisions
)
3845 (fset 'real-isearch-done
(symbol-function 'isearch-done
))
3846 (fset 'isearch-done
'isearch-done
/outline-provisions
)
3847 (fset 'real-isearch-update
(symbol-function 'isearch-update
))
3848 (fset 'isearch-update
'isearch-update
/outline-provisions
)
3849 (make-variable-buffer-local 'outline-search-reconceal
)))))
3850 ;;;_ > outline-isearch-arrival-business ()
3851 (defun outline-isearch-arrival-business ()
3852 "Do outline business like exposing current point, if necessary.
3854 Registers reconcealment requirements in outline-search-reconceal
3857 Set outline-search-reconceal to nil if current point is not
3858 concealed, to value of point if entire topic is concealed, and a
3859 list containing point if only the topic body is concealed.
3861 This will be used to determine whether outline-hide-current-entry
3862 or outline-hide-current-entry-completely will be necessary to
3863 restore the prior concealment state."
3865 (if (outline-mode-p)
3866 (setq outline-search-reconceal
3867 (if (outline-hidden-p)
3869 (if (re-search-backward outline-line-boundary-regexp nil
1)
3870 ;; Nil value means we got to b-o-b - wouldn't need
3873 ; We'll return point or list
3874 ; containing point, depending
3875 ; on concealment state of
3877 (prog1 (if (outline-hidden-p) (point) (list (point)))
3878 ; And reveal the current
3880 (outline-show-entry)))))))
3881 ;;;_ > outline-isearch-advancing-business ()
3882 (defun outline-isearch-advancing-business ()
3883 "Do outline business like deexposing current point, if necessary.
3885 Works according to reconceal state registration."
3886 (if (and (outline-mode-p) outline-search-reconceal
)
3888 (if (listp outline-search-reconceal
)
3889 ;; Leave the topic visible:
3890 (progn (goto-char (car outline-search-reconceal
))
3891 (outline-hide-current-entry))
3892 ;; Rehide the entire topic:
3893 (goto-char outline-search-reconceal
)
3894 (outline-hide-current-entry-completely)))))
3895 ;;;_ > isearch-terminate/outline-provisions ()
3896 (defun isearch-terminate/outline-provisions
()
3898 (if (and (outline-mode-p) outline-enwrap-isearch-mode
)
3899 (outline-isearch-advancing-business))
3900 (let ((outline-search-quitting t
)
3901 (outline-search-reconceal nil
))
3902 (real-isearch-terminate)))
3903 ;;;_ > isearch-done/outline-provisions ()
3904 (defun isearch-done/outline-provisions
(&optional nopush
)
3906 (if (and (outline-mode-p) outline-enwrap-isearch-mode
)
3907 (progn (if (and outline-search-reconceal
3908 (not (listp outline-search-reconceal
)))
3909 ;; The topic was concealed - reveal it, its siblings,
3910 ;; and any ancestors that are still concealed:
3912 (message "(exposing destination)")(sit-for 0)
3913 (outline-goto-prefix)
3914 ; There may be a closed blank
3915 ; line between prior and
3916 ; current topic that would be
3917 ; missed - provide for it:
3919 (progn (forward-char -
1) ; newline
3920 (if (eq ?
\r (preceding-char))
3921 (outline-flag-region (1- (point))
3926 (outline-ascend-to-depth (1- (outline-recent-depth)))
3927 (outline-show-children)))
3928 (if (and (boundp 'outline-search-quitting
)
3929 outline-search-quitting
)
3931 ; We're concluding abort:
3932 (outline-isearch-arrival-business)
3933 (outline-show-children))))
3935 ;; isearch-done in newer version of isearch mode takes arg:
3936 (real-isearch-done nopush
)
3937 (real-isearch-done)))
3938 ;;;_ > isearch-update/outline-provisions ()
3939 (defun isearch-update/outline-provisions
()
3940 "Wrapper dynamically adjusts isearch target exposure.
3942 Appropriately exposes and reconceals hidden outline portions, as
3943 necessary, in the course of searching."
3944 (if (not (and (outline-mode-p) outline-enwrap-isearch-mode
))
3945 ;; Just do the plain business:
3946 (real-isearch-update)
3948 ;; Ah - provide for outline conditions:
3949 (outline-isearch-advancing-business)
3950 (real-isearch-update)
3951 (cond (isearch-success (outline-isearch-arrival-business))
3952 ((not isearch-success
) (outline-isearch-advancing-business)))))
3954 ;;;_ #8 Copying and printing
3957 ;;;_ > outline-insert-listified (depth prefix bullet text)
3958 (defun outline-insert-listified (depth prefix bullet text
)
3959 "Insert contents of listified outline portion in current buffer."
3960 (insert-string (concat (if (> depth
1) prefix
"")
3961 (make-string (1- depth
) ?\
)
3964 (insert-string (car text
))
3965 (if (setq text
(cdr text
))
3966 (insert-string "\n")))
3967 (insert-string "\n"))
3968 ;;;_ > outline-copy-exposed (arg &optional tobuf)
3969 (defun outline-copy-exposed (arg &optional tobuf
)
3970 "Duplicate exposed portions of current topic to another buffer.
3972 Other buffer has current buffers' name with \" exposed\" appended to it.
3974 With repeat count, copy the exposed portions of entire buffer."
3978 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
3979 (let* ((start-pt (point))
3980 (beg (if arg
(point-min) (outline-back-to-current-heading)))
3981 (end (if arg
(point-max) (outline-end-of-current-subtree)))
3982 (buf (current-buffer)))
3983 (save-excursion (set-buffer tobuf
)(erase-buffer))
3984 (outline-process-exposed 'outline-insert-listified
3989 (goto-char (point-min))
3991 (goto-char start-pt
)))
3993 ;;;_ - LaTeX formatting
3994 ;;;_ > outline-latex-verb-quote (str &optional flow)
3995 (defun outline-latex-verb-quote (str &optional flow
)
3996 "Return copy of STRING for literal reproduction across latex processing.
3997 Expresses the original characters \(including carriage returns) of the
3998 string across latex processing."
3999 (mapconcat '(lambda (char)
4000 ;;;mess: (cond ((memq char '(?"" ?$ ?% ?# ?& ?- ?" ?` ?^ ?- ?*));;;"))))
4001 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
4002 (concat "\\char" (number-to-string char
) "{}"))
4003 ((= char ?
\n) "\\\\")
4004 (t (char-to-string char
))))
4007 ;;;_ > outline-latex-verbatim-quote-curr-line ()
4008 (defun outline-latex-verbatim-quote-curr-line ()
4009 "Express line for exact \(literal\) representation across latex processing.
4011 Adjust line contents so it is unaltered \(from the original line)
4012 across latex processing, within the context of a 'verbatim'
4013 environment. Leaves point at the end of the line."
4016 (end (progn (end-of-line)(point))))
4018 (while (re-search-forward "\\\\"
4019 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
4020 end
; bounded by end-of-line
4021 1) ; no matches, move to end & return nil
4022 (goto-char (match-beginning 0))
4023 (insert-string "\\")
4025 (goto-char (1+ (match-end 0))))))
4026 ;;;_ > outline-insert-latex-header (buf)
4027 (defun outline-insert-latex-header (buf)
4028 "Insert initial latex commands at point in BUFFER."
4029 ;; Much of this is being derived from the stuff in appendix of E in
4030 ;; the TeXBook, pg 421.
4032 (let ((doc-style (format "\n\\documentstyle{%s}\n"
4034 (page-numbering (if outline-number-pages
4035 "\\pagestyle{empty}\n"
4037 (linesdef (concat "\\def\\beginlines{"
4038 "\\par\\begingroup\\nobreak\\medskip"
4040 " \\kern1pt\\nobreak \\obeylines \\obeyspaces "
4041 "\\everypar{\\strut}}\n"
4043 "\\kern1pt\\endgroup\\medbreak\\noindent}\n"))
4044 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
4045 outline-title-style
))
4046 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
4047 outline-label-style
))
4048 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
4049 outline-head-line-style
))
4050 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
4051 outline-body-line-style
))
4052 (setlength (format "%s%s%s%s"
4053 "\\newlength{\\stepsize}\n"
4054 "\\setlength{\\stepsize}{"
4057 (oneheadline (format "%s%s%s%s%s%s%s"
4058 "\\newcommand{\\OneHeadLine}[3]{%\n"
4060 "\\hspace*{#2\\stepsize}%\n"
4061 "\\labelcmd{#1}\\hspace*{.2cm}"
4062 "\\headlinecmd{#3}\\\\["
4065 (onebodyline (format "%s%s%s%s%s%s"
4066 "\\newcommand{\\OneBodyLine}[2]{%\n"
4068 "\\hspace*{#1\\stepsize}%\n"
4069 "\\bodylinecmd{#2}\\\\["
4072 (begindoc "\\begin{document}\n\\begin{center}\n")
4073 (title (format "%s%s%s%s"
4075 (outline-latex-verb-quote (if outline-title
4077 (eval outline-title
)
4078 (error "<unnamed buffer>"))
4081 "\\end{center}\n\n"))
4082 (hsize "\\hsize = 7.5 true in\n")
4083 (hoffset "\\hoffset = -1.5 true in\n")
4084 (vspace "\\vspace{.1cm}\n\n"))
4085 (insert (concat doc-style
4100 ;;;_ > outline-insert-latex-trailer (buf)
4101 (defun outline-insert-latex-trailer (buf)
4102 "Insert concluding latex commands at point in BUFFER."
4104 (insert "\n\\end{document}\n"))
4105 ;;;_ > outline-latexify-one-item (depth prefix bullet text)
4106 (defun outline-latexify-one-item (depth prefix bullet text
)
4107 "Insert LaTeX commands for formatting one outline item.
4109 Args are the topics' numeric DEPTH, the header PREFIX lead string, the
4110 BULLET string, and a list of TEXT strings for the body."
4111 (let* ((head-line (if text
(car text
)))
4112 (body-lines (cdr text
))
4116 (insert-string (concat "\\OneHeadLine{\\verb\1 "
4117 (outline-latex-verb-quote bullet
)
4122 (outline-latex-verb-quote head-line
)
4125 (if (not body-lines
)
4127 ;;(insert-string "\\beginlines\n")
4128 (insert-string "\\begin{verbatim}\n")
4130 (setq curr-line
(car body-lines
))
4131 (if (and (not body-content
)
4132 (not (string-match "^\\s-*$" curr-line
)))
4133 (setq body-content t
))
4134 ; Mangle any occurrences of
4135 ; "\end{verbatim}" in text,
4137 (if (and body-content
4138 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
4139 (setq curr-line
(concat (substring curr-line
0 bop
)
4141 (substring curr-line bop
))))
4142 ;;(insert-string "|" (car body-lines) "|")
4143 (insert-string curr-line
)
4144 (outline-latex-verbatim-quote-curr-line)
4145 (insert-string "\n")
4146 (setq body-lines
(cdr body-lines
)))
4148 (setq body-content nil
)
4150 (insert-string "\\ ")
4152 ;;(insert-string "\\endlines\n")
4153 (insert-string "\\end{verbatim}\n")
4155 ;;;_ > outline-latexify-exposed (arg &optional tobuf)
4156 (defun outline-latexify-exposed (arg &optional tobuf
)
4157 "Format current topic's exposed portions to TOBUF for latex processing.
4158 TOBUF defaults to a buffer named the same as the current buffer, but
4159 with \"*\" prepended and \" latex-formed*\" appended.
4161 With repeat count, copy the exposed portions of entire buffer."
4166 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
4167 (let* ((start-pt (point))
4168 (beg (if arg
(point-min) (outline-back-to-current-heading)))
4169 (end (if arg
(point-max) (outline-end-of-current-subtree)))
4170 (buf (current-buffer)))
4173 (outline-insert-latex-header tobuf
)
4174 (goto-char (point-max))
4175 (outline-process-exposed 'outline-latexify-one-item
4180 (goto-char (point-max))
4181 (outline-insert-latex-trailer tobuf
)
4182 (goto-char (point-min))
4184 (goto-char start-pt
)))
4186 ;;;_ #9 miscellaneous
4187 ;;;_ > outline-mark-topic ()
4188 (defun outline-mark-topic ()
4189 "Put the region around topic currently containing point."
4192 (outline-goto-prefix)
4194 (outline-end-of-current-subtree)
4195 (exchange-point-and-mark))
4196 ;;;_ > outlineify-sticky ()
4197 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
4198 (defalias 'outlinify-sticky
'outlineify-sticky
)
4199 (defun outlineify-sticky (&optional arg
)
4200 "Activate outline mode and establish file var so it is started subseqently.
4202 See doc-string for `outline-layout' and `outline-init' for details on
4203 setup for auto-startup."
4210 (goto-char (point-min))
4211 (if (looking-at outline-regexp
)
4213 (outline-open-topic 2)
4214 (insert-string (concat "Dummy outline topic header - see"
4215 "`outline-mode' docstring for info."))
4217 (goto-char (point-max))
4219 (outline-open-topic 0)
4220 (insert-string "Local emacs vars.\n")
4221 (outline-open-topic 1)
4222 (insert-string "(`outline-layout' is for allout.el outline-mode)\n")
4223 (outline-open-topic 0)
4224 (insert-string "Local variables:\n")
4225 (outline-open-topic 0)
4226 (insert-string (format "outline-layout: %s\n"
4229 (outline-open-topic 0)
4230 (insert-string "End:\n"))))
4231 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
4232 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
4233 "Solicit (with first arg PROMPT) choice of a character from string STRING.
4235 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
4237 (let ((new-prompt prompt
)
4241 (message "%s" new-prompt
)
4243 ;; We do our own reading here, so we can circumvent, eg, special
4244 ;; treatment for '?' character. (Might oughta change minibuffer
4245 ;; keymap instead, oh well.)
4247 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
4249 (if (null (string-match (regexp-quote got
) string
))
4250 (if (and do-defaulting
(string= got
"\^M"))
4251 ;; We're defaulting, return null string to indicate that:
4253 ;; Failed match and not defaulting,
4254 ;; set the prompt to give feedback,
4255 (setq new-prompt
(concat prompt
4260 ;; and set loop to try again:
4262 ;; Got a match - give feedback:
4264 ;; got something out of loop - return it:
4267 ;;;_ > regexp-sans-escapes (string)
4268 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
4269 "Return a copy of REGEXP with all character escapes stripped out.
4271 Representations of actual backslashes - '\\\\\\\\' - are left as a
4274 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
4276 (if (string= regexp
"")
4278 ;; Set successive-backslashes to number if current char is
4279 ;; backslash, or else to nil:
4280 (setq successive-backslashes
4281 (if (= (aref regexp
0) ?
\\)
4282 (if successive-backslashes
(1+ successive-backslashes
) 1)
4284 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
4285 ;; Include first char:
4286 (concat (substring regexp
0 1)
4287 (regexp-sans-escapes (substring regexp
1)))
4288 ;; Exclude first char, but maintain count:
4289 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
4290 ;;;_ - add-hook definition for divergent emacsen
4291 ;;;_ > add-hook (hook function &optional append)
4292 (if (not (fboundp 'add-hook
))
4293 (defun add-hook (hook function
&optional append
)
4294 "Add to the value of HOOK the function FUNCTION unless already present.
4295 \(It becomes the first hook on the list unless optional APPEND is non-nil, in
4296 which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
4297 any valid function. HOOK's value should be a list of functions, not a single
4298 function. If HOOK is void, it is first set to nil."
4299 (or (boundp hook
) (set hook nil
))
4300 (or (if (consp function
)
4301 ;; Clever way to tell whether a given lambda-expression
4302 ;; is equal to anything in the hook.
4303 (let ((tail (assoc (cdr function
) (symbol-value hook
))))
4304 (equal function tail
))
4305 (memq function
(symbol-value hook
)))
4308 (nconc (symbol-value hook
) (list function
))
4309 (cons function
(symbol-value hook
)))))))
4311 ;;;_ #10 Under development
4312 ;;;_ > outline-bullet-isearch (&optional bullet)
4313 (defun outline-bullet-isearch (&optional bullet
)
4314 "Isearch \(regexp\) for topic with bullet BULLET."
4317 (setq bullet
(solicit-char-in-string
4318 "ISearch for topic with bullet: "
4319 (regexp-sans-escapes outline-bullets-string
))))
4321 (let ((isearch-regexp t
)
4322 (isearch-string (concat "^"
4323 outline-header-prefix
4326 (isearch-repeat 'forward
)
4328 ;;;_ ? Re hooking up with isearch - use isearch-op-fun rather than
4329 ;;; wrapping the isearch functions.
4331 ;;;_* Local emacs vars.
4332 ;;; The following `outline-layout' local variable setting:
4333 ;;; - closes all topics from the first topic to just before the third-to-last,
4334 ;;; - shows the children of the third to last (config vars)
4335 ;;; - and the second to last (code section),
4336 ;;; - and closes the last topic (this local-variables section).
4338 ;;;outline-layout: (0 : -1 -1 0)
4341 ;; allout.el ends here