annotate lisp/reveal.el @ 66454:9082bf778ad8

Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621 Merge from gnus--rel--5.10 Patches applied: * gnus--rel--5.10 (patch 147-148) - Update from CVS 2005-10-25 Reiner Steib <Reiner.Steib@gmx.de> * lisp/gnus/gnus-score.el (gnus-default-adaptive-score-alist): Set defaults depending on gnus-score-decay-constant. 2005-10-25 Lars Magne Ingebrigtsen <larsi@gnus.org> * lisp/gnus/nnslashdot.el (nnslashdot-request-article) (nnslashdot-retrieve-headers-1): Update to new HTML. 2005-10-23 Simon Josefsson <jas@extundo.com> * lisp/gnus/imap.el (imap-gssapi-program): Align command line parameters with latest GNU SASL. (imap-gssapi-open): Ignore 'Trying ...' messages from GNU SASL.
author Miles Bader <miles@gnu.org>
date Tue, 25 Oct 2005 23:34:40 +0000
parents 41bb365f41c4
children 3fbf09f9769f 2d92f5c9d6ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; reveal.el --- Automatically reveal hidden text at point
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
4 ;; 2005 Free Software Foundation, Inc.
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Keywords: outlines
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8
42320
44b4a14ae7fc Fix Lisp headers.
Pavel Janík <Pavel@Janik.cz>
parents: 41778
diff changeset
9 ;; This file is part of GNU Emacs.
44b4a14ae7fc Fix Lisp headers.
Pavel Janík <Pavel@Janik.cz>
parents: 41778
diff changeset
10
45340
a0cc96a3bf71 Fix the preamble comments.
Eli Zaretskii <eliz@gnu.org>
parents: 42320
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; any later version.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15
45341
1471d94c6f8a More preamble fixes.
Eli Zaretskii <eliz@gnu.org>
parents: 45340
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; GNU General Public License for more details.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
23 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
24 ;; Boston, MA 02110-1301, USA.
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26 ;;; Commentary:
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 ;; Reveal mode is a minor mode that makes sure that text around point
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;; is always visible. When point enters a region of hidden text,
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 ;; `reveal-mode' temporarily makes it visible.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 ;;
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;; This is normally used in conjunction with `outline-minor-mode',
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33 ;; `hs-minor-mode', `hide-ifdef-mode', ...
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;;
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 ;; It only works with packages that hide text using overlays.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; Packages can provide special support for it by placing
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;; a function in the `reveal-toggle-invisible' property on the symbol
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; used as the value of the `invisible' overlay property.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 ;; The function is called right after revealing (or re-hiding) the
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 ;; text with two arguments: the overlay and a boolean that's non-nil
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 ;; if we have just revealed the text. When revealing, that function
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42 ;; may re-hide some of the text.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 ;;; Todo:
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 ;; - find other hysteresis features.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 ;;; Code:
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 (require 'pcvs-util)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 (defgroup reveal nil
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 "Reveal hidden text on the fly."
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 :group 'editing)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 (defcustom reveal-around-mark t
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 "Reveal text around the mark, if active."
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61275
diff changeset
58 :type 'boolean
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61275
diff changeset
59 :group 'reveal)
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 (defvar reveal-open-spots nil)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 (make-variable-buffer-local 'reveal-open-spots)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63
57816
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
64 (defvar reveal-last-tick nil)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
65 (make-variable-buffer-local 'reveal-last-tick)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
66
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 ;; Actual code
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 (defun reveal-post-command ()
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 ;; Refresh the spots that might have changed.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 ;; `Refreshing' here means to try and re-hide the corresponding text.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 ;; We don't refresh everything correctly:
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 ;; - we only refresh spots in the current window.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 ;; FIXME: do we actually know that (current-buffer) = (window-buffer) ?
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 (with-local-quit
45428
ac7e0cc03aed (reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45341
diff changeset
76 (condition-case err
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 (let* ((spots (cvs-partition
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 (lambda (x)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 ;; We refresh any spot in the current window as well
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 ;; as any spots associated with a dead window or a window
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 ;; which does not show this buffer any more.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (or (eq (car x) (selected-window))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 (not (window-live-p (car x)))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 (not (eq (window-buffer (car x))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 (current-buffer)))))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 reveal-open-spots))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87 (old-ols (mapcar 'cdr (car spots)))
45428
ac7e0cc03aed (reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45341
diff changeset
88 (repeat t))
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 (setq reveal-open-spots (cdr spots))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 ;; Open new overlays.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (while repeat
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (setq repeat nil)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (dolist (ol (nconc (when (and reveal-around-mark mark-active)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 (overlays-at (mark)))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 (overlays-at (point))))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (push (cons (selected-window) ol) reveal-open-spots)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 (setq old-ols (delq ol old-ols))
60301
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
98 (let ((inv (overlay-get ol 'invisible)) open)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
99 (when (and inv
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
100 ;; There's an `invisible' property. Make sure it's
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
101 ;; actually invisible.
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
102 (or (not (listp buffer-invisibility-spec))
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
103 (memq inv buffer-invisibility-spec)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
104 (assq inv buffer-invisibility-spec))
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
105 (or (setq open
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
106 (or (overlay-get ol 'reveal-toggle-invisible)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
107 (and (symbolp inv)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
108 (get inv 'reveal-toggle-invisible))
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
109 (overlay-get ol 'isearch-open-invisible-temporary)))
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
110 (overlay-get ol 'isearch-open-invisible)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
111 (and (consp buffer-invisibility-spec)
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
112 (cdr (assq inv buffer-invisibility-spec))))
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
113 (overlay-put ol 'reveal-invisible inv))
45428
ac7e0cc03aed (reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45341
diff changeset
114 (if (null open)
ac7e0cc03aed (reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45341
diff changeset
115 (overlay-put ol 'invisible nil)
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 ;; Use the provided opening function and repeat (since the
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 ;; opening function might have hidden a subpart around point).
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 (setq repeat t)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 (condition-case err
45428
ac7e0cc03aed (reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45341
diff changeset
120 (funcall open ol nil)
60301
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
121 (error (message "!!Reveal-show (funcall %s %s nil): %s !!"
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
122 open ol err)
50374
73660951a233 (reveal-post-command): Better error handling and debugging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 48399
diff changeset
123 ;; Let's default to a meaningful behavior to avoid
73660951a233 (reveal-post-command): Better error handling and debugging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 48399
diff changeset
124 ;; getting stuck in an infinite loop.
50384
09ec24acd6a5 (reveal-post-command): Remove buggy debugging code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50374
diff changeset
125 (setq repeat nil)
50374
73660951a233 (reveal-post-command): Better error handling and debugging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 48399
diff changeset
126 (overlay-put ol 'invisible nil))))))))
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 ;; Close old overlays.
57816
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
128 (if (not (eq reveal-last-tick
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
129 (setq reveal-last-tick (buffer-modified-tick))))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
130 ;; The buffer was modified since last command: let's refrain from
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
131 ;; closing any overlay because it tends to behave poorly when
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
132 ;; inserting text at the end of an overlay (basically the overlay
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
133 ;; should be rear-advance when it's open, but things like
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
134 ;; outline-minor-mode make it non-rear-advance because it's
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
135 ;; a better choice when it's closed).
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
136 (dolist (ol old-ols)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
137 (push (cons (selected-window) ol) reveal-open-spots))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
138 ;; The last command was only a point motion or some such
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
139 ;; non-buffer-modifying command. Let's close whatever can be closed.
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
140 (dolist (ol old-ols)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
141 (when (and (eq (current-buffer) (overlay-buffer ol))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
142 (not (rassq ol reveal-open-spots)))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
143 (if (and (>= (point) (save-excursion
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
144 (goto-char (overlay-start ol))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
145 (line-beginning-position 1)))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
146 (<= (point) (save-excursion
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
147 (goto-char (overlay-end ol))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
148 (line-beginning-position 2))))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
149 ;; Still near the overlay: keep it open.
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
150 (push (cons (selected-window) ol) reveal-open-spots)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
151 ;; Really close it.
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
152 (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
153 (if (or open
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
154 (and (setq inv (overlay-get ol 'reveal-invisible))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
155 (setq open (or (get inv 'reveal-toggle-invisible)
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
156 (overlay-get ol 'isearch-open-invisible-temporary)))))
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
157 (condition-case err
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
158 (funcall open ol t)
60301
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
159 (error (message "!!Reveal-hide (funcall %s %s t): %s !!"
f3c5c717aa02 (reveal-post-command): Don't try to reveal overlays which
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58435
diff changeset
160 open ol err)))
57816
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
161 (overlay-put ol 'invisible inv))))))))
50384
09ec24acd6a5 (reveal-post-command): Remove buggy debugging code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50374
diff changeset
162 (error (message "Reveal: %s" err)))))
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163
58435
180297c18beb (reveal-mode-map): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57816
diff changeset
164 (defvar reveal-mode-map
180297c18beb (reveal-mode-map): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57816
diff changeset
165 (let ((map (make-sparse-keymap)))
60487
bf372b4b92e9 (reveal-mode-map): Bind C-a to beginning-of-line.
Kim F. Storm <storm@cua.dk>
parents: 60301
diff changeset
166 ;; Override the default move-beginning-of-line and move-end-of-line
bf372b4b92e9 (reveal-mode-map): Bind C-a to beginning-of-line.
Kim F. Storm <storm@cua.dk>
parents: 60301
diff changeset
167 ;; which skips valuable invisible text.
61087
386a445c2ae9 (reveal-mode-map): Don't override C-a and C-e.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 60487
diff changeset
168 (define-key map [remap move-beginning-of-line] 'beginning-of-line)
386a445c2ae9 (reveal-mode-map): Don't override C-a and C-e.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 60487
diff changeset
169 (define-key map [remap move-end-of-line] 'end-of-line)
58435
180297c18beb (reveal-mode-map): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57816
diff changeset
170 map))
180297c18beb (reveal-mode-map): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57816
diff changeset
171
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ;;;###autoload
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (define-minor-mode reveal-mode
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 "Toggle Reveal mode on or off.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 Reveal mode renders invisible text around point visible again.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 Interactively, with no prefix argument, toggle the mode.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 With universal prefix ARG (or if ARG is nil) turn mode on.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 With zero or negative ARG turn mode off."
61275
4e273c06e466 (reveal-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 61087
diff changeset
180 :group 'reveal
41778
19e76eadbf86 (reveal-mode): Fix reveal-mode's lighter.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41621
diff changeset
181 :lighter (global-reveal-mode nil " Reveal")
58435
180297c18beb (reveal-mode-map): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57816
diff changeset
182 :keymap reveal-mode-map
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 (if reveal-mode
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 (progn
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 (set (make-local-variable 'search-invisible) t)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 (add-hook 'post-command-hook 'reveal-post-command nil t))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (kill-local-variable 'search-invisible)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 (remove-hook 'post-command-hook 'reveal-post-command t)))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 ;;;###autoload
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 (define-minor-mode global-reveal-mode
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 "Toggle Reveal mode in all buffers on or off.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 Reveal mode renders invisible text around point visible again.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 Interactively, with no prefix argument, toggle the mode.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 With universal prefix ARG (or if ARG is nil) turn mode on.
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 With zero or negative ARG turn mode off."
48399
59fc5f077731 (global-reveal-mode): Add group.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45428
diff changeset
198 :global t :group 'reveal
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 (setq-default reveal-mode global-reveal-mode)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 (if global-reveal-mode
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201 (progn
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 (setq search-invisible t)
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 (add-hook 'post-command-hook 'reveal-post-command))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 (setq search-invisible 'open) ;FIXME
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 (remove-hook 'post-command-hook 'reveal-post-command)))
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 (provide 'reveal)
48399
59fc5f077731 (global-reveal-mode): Add group.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45428
diff changeset
208
57816
af6e1f8dd9e0 (reveal-last-tick): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
209 ;; arch-tag: 96ba0242-2274-4ed7-8e10-26bc0707b4d8
41621
8835d207e12a Initial commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 ;;; reveal.el ends here