annotate lisp/foldout.el @ 14753:cf8ad47dc610

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