annotate lisp/utils/foldout.el @ 98:0d2f883870bc r20-1b1

Import from CVS: tag r20-1b1
author cvs
date Mon, 13 Aug 2007 09:13:56 +0200
parents ac2d302a0011
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; foldout.el --- Folding extensions for outline-mode and outline-minor-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Kevin Broadey <KevinB@bartley.demon.co.uk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Created: 27 Jan 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Version: foldout.el 1.10 dated 94/05/19 at 17:09:12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Keywords: folding, outline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
27 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; This file provides folding editor extensions for outline-mode and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; outline-minor-mode buffers. What's a "folding editor"? Read on...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Imagine you're in an outline-mode buffer and you've hidden all the text and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; subheadings under your level-1 headings. You now want to look at the stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; hidden under one of these headings. Normally you'd do C-c C-e (show-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; to expose the body or C-c C-i to expose the child (level-2) headings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; With foldout, you do C-c C-z (foldout-zoom-subtree). This exposes the body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; and child subheadings and narrows the buffer so that only the level-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; heading, the body and the level-2 headings are visible. If you now want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; look under one of the level-2 headings, position the cursor on it and do C-c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; C-z again. This exposes the level-2 body and its level-3 child subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; and narrows the buffer again. You can keep on zooming in on successive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; subheadings as much as you like. A string in the modeline tells you how
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; deep you've gone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; When zooming in on a heading you might only want to see the child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; subheadings. You do this by specifying a numeric argument: C-u C-c C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; You can specify the number of levels of children too (c.f. show-children):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; e.g. M-2 C-c C-z exposes two levels of child subheadings. Alternatively,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; you might only be interested in the body. You do this by specifying a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; negative argument: M-- C-c C-z. You can also cause the whole subtree to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; expanded, similar to C-c C-s (show-subtree), by specifying a zero argument:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; M-0 C-c C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; While you're zoomed in you can still use outline-mode's exposure and hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; functions. It won't upset foldout at all. Also, since the buffer is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; narrowed, "global" editing actions will only affect the stuff under the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; zoomed-in heading. This is useful for restricting changes to a particular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; chapter or section of your document.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; You unzoom (exit) a fold by doing C-c C-x (foldout-exit-fold). This hides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; all the text and subheadings under the top-level heading and returns you to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; the previous view of the buffer. Specifying a numeric argument exits that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; many folds. Specifying a zero argument exits *all* folds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; You might want to exit a fold *without* hiding the text and subheadings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; You do this by specifying a negative argument. For example, M--2 C-c C-x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; exits two folds and leaves the text and subheadings exposed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Foldout also provides mouse bindings for entering and exiting folds and for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; showing and hiding text. Hold down Meta and Control, then click a mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; button as follows:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; mouse-1 (foldout-mouse-zoom) zooms in on the heading clicked on:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; single click expose body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; double click expose subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; triple click expose body and subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; quad click expose entire subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; mouse-2 (foldout-mouse-show) exposes text under the heading clicked on:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; single click expose body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; double click expose subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; triple click expose body and subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; quad click expose entire subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; mouse-3 (foldout-mouse-hide-or-exit) hides text under the heading clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; on or exits the fold:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; single click hide subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; double click exit fold and hide text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; triple click exit fold without hiding text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; quad click exit all folds and hide text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; You can change the modifier keys used by setting `foldout-mouse-modifiers'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; To use foldout, put this in your .emacs:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; (require 'foldout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; If you don't want it loaded until you need it, try this instead:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; (eval-after-load "outline" '(require 'foldout))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; Advertisements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; Get out-xtra.el by Per Abrahamsen <abraham@iesd.auc.dk> for more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; outline-mode goodies. In particular, `outline-hide-sublevels' makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; setup a lot easier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; folding.el by Jamie Lokier <u90jl@ecs.ox.ac.uk> supports folding by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; recognising special marker text in you file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; c-outline.el (by me) provides outline-mode support to recognise `C'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; statements as outline headings, so with foldout you can have a folding `C'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; code editor without having to put in start- and end-of-fold markers. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; is a real winner!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;; ChangeLog:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; 1.10 21-Mar-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; foldout.el is now part of the GNU Emacs distribution!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; Put in changes made by RMS to version 1.8 to keep the diffs to a minimum.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; bugfix: numeric arg to foldout-exit-fold wasn't working - looks like I don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; know how to use the Common LISP `loop' macro after all, so use `while'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; 1.9 15-Mar-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Didn't test that very well, did I? The change to foldout-zoom-subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; affected foldout-mouse-zoom: if the heading under the `level n' one clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; on was at `level n+2' then it didn't get exposed. Sorry about that!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; 1.8 15-Mar-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; Changed meaning of prefix arg to foldout-zoom-subtree. arg > 0 now means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; "expose that many children" instead of just "expose children" so it is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; like `show-children' (C-c C-i). Arg of C-u on its own only shows one level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; of children, though, so you can still zoom by doing C-u C-c C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; I can't think of a good meaning for the value of a negative prefix. Any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; suggestions?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; Added advertisement for my c-outline.el package. Now you can have a folding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; editor for c-mode without any effort!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; 1.7 7-Mar-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; I got fed up trying to work out how many blank lines there were outside the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; narrowed region when inside a fold. Now *all* newlines before the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; heading are *in* the narrowed region. Thus, if the cursor is at point-max,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; the number of blank lines above it is the number you'll get above the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; heading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Since all newlines are now inside the narrowed region, when exiting a fold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; add a newline at the end of the region if there isn't one so that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; following heading doesn't accidentally get joined to the body text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; Bugfix: `foldout-mouse-modifiers' should be `defvar', not `defconst'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Use "cond" instead of "case" so that lemacs-19.9 users can use the mouse.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; Improve "Commentary" entry on using the mouse.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; Add "Installation" keyword.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; 1.6 3-Mar-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; Add mouse support functions foldout-mouse-zoom, foldout-mouse-show,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; foldout-mouse-hide-or-exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; 1.5 11-Feb-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; Rename `foldout-enter-subtree' to `foldout-zoom-subtree' and change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; keystroke from C-g to C-z. This is more mnemonic and leaves C-g alone, as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; users expect this to cancel the current key sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Added better commentary at the request of RMS. Added stuff to comply with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; the lisp-mnt.el conventions. Added instructions on how best to load the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; 1.4 2-Feb-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; Bugfix: end-of-fold marking was wrong:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; End of narrowed region should be one character on from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; (outline-end-of-subtree) so it includes the end-of-line at the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; last line of the subtree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; End-of-fold marker should be outside the narrowed region so text inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; at the end of the region goes before the marker. Need to make a special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; case for end-of-buffer because it is impossible to set a marker that will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; follow eob. Bummer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; 1.3 28-Jan-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; Changed `foldout-zoom-subtree'. A zero arg now makes it expose the entire
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; subtree on entering the fold. As before, < 0 shows only the body and > 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; shows only the subheadings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; 1.2 28-Jan-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Fixed a dumb bug - didn't make `foldout-modeline-string' buffer-local :-(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Changed `foldout-exit-fold' to use prefix arg to say how many folds to exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Negative arg means exit but don't hide text. Zero arg means exit all folds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Added `foldout-inhibit-key-bindings' to inhibit key bindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; 1.1 27-Jan-94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; Released to the net. Inspired by a question in gnu.emacs.help from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Jason D Lohn <jlohn@eng.umd.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (require 'outline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; something has gone very wrong if outline-minor-mode isn't bound now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if (not (boundp 'outline-minor-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (error "Can't find outline-minor-mode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defconst foldout-fold-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 "List of start and end markers for the folds currently entered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 An end marker of NIL means the fold ends after (point-max).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (make-variable-buffer-local 'foldout-fold-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defconst foldout-modeline-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "Modeline string announcing that we are in an outline fold.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (make-variable-buffer-local 'foldout-modeline-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; put our minor mode string immediately following outline-minor-mode's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (or (assq 'foldout-modeline-string minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (let ((outl-entry (memq (assq 'outline-minor-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 minor-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (foldout-entry '((foldout-modeline-string foldout-modeline-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; something's wrong with outline if we can't find it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if (null outl-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (error "Can't find outline-minor-mode in minor-mode-alist"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; slip our fold announcement into the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setcdr outl-entry (nconc foldout-entry (cdr outl-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun foldout-zoom-subtree (&optional exposure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "Open the subtree under the current heading and narrow to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Normally the body and the immediate subheadings are exposed, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 optional arg EXPOSURE \(interactively with prefix arg\) changes this:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 EXPOSURE > 0 exposes n levels of subheadings (c.f. show-children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 EXPOSURE < 0 exposes only the body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 EXPOSURE = 0 exposes the entire subtree"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (outline-back-to-heading)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (let* ((exposure-value (prefix-numeric-value exposure))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (start-marker (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (end (progn (outline-end-of-subtree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (skip-chars-forward "\n\^M")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; I need a marker that will follow the end of the region even when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; text is inserted right at the end. Text gets inserted *after*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; markers, so I need it at end+1. Unfortunately I can't set a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; marker at (point-max)+1, so I use NIL to mean the region ends at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; (point-max).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (end-marker (if (eobp) nil (set-marker (make-marker) (1+ end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; narrow to this subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; show the body and/or subheadings for this heading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ((null exposure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (show-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (show-children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ((< exposure-value 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (show-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ((consp exposure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (show-children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ((> exposure-value 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (show-children exposure-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (show-subtree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;; save the location of the fold we are entering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq foldout-fold-list (cons (cons start-marker end-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 foldout-fold-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; update the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (foldout-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defun foldout-exit-fold (&optional num-folds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "Return to the ARG'th enclosing fold view. With ARG = 0 exit all folds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 Normally causes exited folds to be hidden, but with ARG < 0, -ARG folds are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 exited and text is left visible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (let (start-marker end-marker (hide-fold t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; check there are some folds to leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (null foldout-fold-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (error "Not in a fold!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; catch a request to leave all folds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ((zerop num-folds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (setq num-folds (length foldout-fold-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; have we been told not to hide the fold?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ((< num-folds 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq hide-fold nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 num-folds (- num-folds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; limit the number of folds if we've been told to exit too many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (setq num-folds (min num-folds (length foldout-fold-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;; exit the folds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (while (not (zerop num-folds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; get the fold at the top of the stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq start-marker (car (car foldout-fold-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 end-marker (cdr (car foldout-fold-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 foldout-fold-list (cdr foldout-fold-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 num-folds (1- num-folds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; Make sure there is a newline at the end of this fold,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;; otherwise the following heading will get joined to the body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if end-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (goto-char end-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (or (memq (preceding-char) '(?\n ?\^M))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (insert ?\n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; If this is the last fold to exit, hide the text unless we've
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; been told not to. Note that at the moment point is at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; beginning of the following heading if there is one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; Also, make sure that the newline before the following heading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; is \n otherwise it will be hidden. If there is a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; before this one, make it visible too so we do the same as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; outline.el and leave a blank line before the heading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (if (zerop num-folds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (let ((beginning-of-heading (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (end-of-subtree (if end-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (if (memq (preceding-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 '(?\n ?\^M))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; hide the subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (if hide-fold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (outline-flag-region start-marker end-of-subtree ?\^M))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; make sure the next heading is exposed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if end-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (outline-flag-region end-of-subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 beginning-of-heading ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; zap the markers so they don't slow down editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (set-marker start-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (if end-marker (set-marker end-marker nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;; narrow to the enclosing fold if there is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (if foldout-fold-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq start-marker (car (car foldout-fold-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 end-marker (cdr (car foldout-fold-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (narrow-to-region start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (if end-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (1- (marker-position end-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (recenter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; update the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (foldout-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defun foldout-update-modeline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "Set the modeline string to indicate our fold depth."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (let ((depth (length foldout-fold-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq foldout-modeline-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;; if we're not in a fold, keep quiet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ((zerop depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;; in outline-minor-mode we're after "Outl:xx" in the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (outline-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (format ":%d" depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;; otherwise just announce the depth (I guess we're in outline-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ((= depth 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 " Inside 1 fold")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (format " Inside %d folds" depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun foldout-mouse-zoom (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 "Zoom in on the heading clicked on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 How much is exposed by the zoom depends on the number of mouse clicks:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 1 expose body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 2 expose subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 3 expose body and subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 4 expose entire subtree"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; swallow intervening mouse events so we only get the final click-count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq event (foldout-mouse-swallow-events event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;; go to the heading clicked on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (foldout-mouse-goto-heading event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ;; zoom away
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (foldout-zoom-subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((nclicks (event-click-count event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ((= nclicks 1) -1) ; body only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ((= nclicks 2) '(1)) ; subheadings only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ((= nclicks 3) nil) ; body and subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (t 0))))) ; entire subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (defun foldout-mouse-show (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 "Show what is hidden under the heading clicked on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 What gets exposed depends on the number of mouse clicks:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 1 expose body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 2 expose subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 3 expose body and subheadings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 4 expose entire subtree"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; swallow intervening mouse events so we only get the final click-count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq event (foldout-mouse-swallow-events event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; expose the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (foldout-mouse-goto-heading event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (let ((nclicks (event-click-count event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ((= nclicks 1) (show-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ((= nclicks 2) (show-children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ((= nclicks 3) (show-entry) (show-children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (t (show-subtree)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (defun foldout-mouse-hide-or-exit (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 "Hide the subtree under the heading clicked on, or exit a fold.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 What happens depends on the number of mouse clicks:-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 1 hide subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 2 exit fold and hide text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 3 exit fold without hiding text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 4 exit all folds and hide text"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; swallow intervening mouse events so we only get the final click-count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (setq event (foldout-mouse-swallow-events event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; hide or exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (let ((nclicks (event-click-count event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (= nclicks 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (foldout-mouse-goto-heading event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (hide-subtree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (foldout-exit-fold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ((= nclicks 2) 1) ; exit and hide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ((= nclicks 3) -1) ; exit don't hide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (t 0)))))) ; exit all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (defun foldout-mouse-swallow-events (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "Swallow intervening mouse events so we only get the final click-count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 Signal an error if the final event isn't the same type as the first one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (let ((initial-event-type (event-basic-type event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (while (null (sit-for 0 double-click-time 'nodisplay))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (setq event (read-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (or (eq initial-event-type (event-basic-type event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (defun foldout-mouse-goto-heading (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Go to the heading where the mouse event started. Signal an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 if the event didn't occur on a heading."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (goto-char (posn-point (event-start event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (or (outline-on-heading-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;; outline.el sometimes treats beginning-of-buffer as a heading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; even though outline-on-heading returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (save-excursion (beginning-of-line) (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (error "Not a heading line")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;;; Keymaps:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (defvar foldout-inhibit-key-bindings nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Set non-NIL before loading foldout to inhibit key bindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defvar foldout-mouse-modifiers '(meta control)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 "List of modifier keys to apply to foldout's mouse events.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 The default (meta control) makes foldout bind its functions to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 M-C-down-mouse-{1,2,3}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 Valid modifiers are shift, control, meta, alt, hyper and super.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (if foldout-inhibit-key-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (define-key outline-mode-map "\C-c\C-z" 'foldout-zoom-subtree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (define-key outline-mode-map "\C-c\C-x" 'foldout-exit-fold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (define-key outline-minor-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (concat outline-minor-mode-prefix "\C-z") 'foldout-zoom-subtree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (define-key outline-minor-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (concat outline-minor-mode-prefix "\C-x") 'foldout-exit-fold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (let* ((modifiers (apply 'concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (lambda (modifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ((eq modifier 'shift) ?S)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ((eq modifier 'control) ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ((eq modifier 'meta) ?M)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ((eq modifier 'alt) ?A)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ((eq modifier 'hyper) ?H)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ((eq modifier 'super) ?s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (t (error "invalid mouse modifier %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 modifier)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ?-)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 foldout-mouse-modifiers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (mouse-1 (vector (intern (concat modifiers "down-mouse-1"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (mouse-2 (vector (intern (concat modifiers "down-mouse-2"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (mouse-3 (vector (intern (concat modifiers "down-mouse-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (define-key outline-mode-map mouse-1 'foldout-mouse-zoom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (define-key outline-mode-map mouse-2 'foldout-mouse-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (define-key outline-mode-map mouse-3 'foldout-mouse-hide-or-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (define-key outline-minor-mode-map mouse-1 'foldout-mouse-zoom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (define-key outline-minor-mode-map mouse-2 'foldout-mouse-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (define-key outline-minor-mode-map mouse-3 'foldout-mouse-hide-or-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (provide 'foldout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ;;; foldout.el ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562