Mercurial > emacs
annotate lisp/reveal.el @ 49914:b4b6ede28a6f
(x_face_list_fonts): Fix int/Lisp_Object mixup.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 22 Feb 2003 22:20:00 +0000 |
parents | 59fc5f077731 |
children | 73660951a233 d7ddb3e565de |
rev | line source |
---|---|
41621 | 1 ;;; reveal.el --- Automatically reveal hidden text at point |
2 | |
3 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu> | |
6 ;; Keywords: outlines | |
7 | |
42320 | 8 ;; This file is part of GNU Emacs. |
9 | |
45340 | 10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
41621 | 11 ;; it under the terms of the GNU General Public License as published by |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
45341 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
41621 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Reveal mode is a minor mode that makes sure that text around point | |
28 ;; is always visible. When point enters a region of hidden text, | |
29 ;; `reveal-mode' temporarily makes it visible. | |
30 ;; | |
31 ;; This is normally used in conjunction with `outline-minor-mode', | |
32 ;; `hs-minor-mode', `hide-ifdef-mode', ... | |
33 ;; | |
34 ;; It only works with packages that hide text using overlays. | |
35 ;; Packages can provide special support for it by placing | |
36 ;; a function in the `reveal-toggle-invisible' property on the symbol | |
37 ;; used as the value of the `invisible' overlay property. | |
38 ;; The function is called right after revealing (or re-hiding) the | |
39 ;; text with two arguments: the overlay and a boolean that's non-nil | |
40 ;; if we have just revealed the text. When revealing, that function | |
41 ;; may re-hide some of the text. | |
42 | |
43 ;;; Todo: | |
44 | |
45 ;; - find other hysteresis features. | |
46 | |
47 ;;; Code: | |
48 | |
49 (require 'pcvs-util) | |
50 | |
51 (defgroup reveal nil | |
52 "Reveal hidden text on the fly." | |
53 :group 'editing) | |
54 | |
55 (defcustom reveal-around-mark t | |
56 "Reveal text around the mark, if active." | |
57 :type 'boolean) | |
58 | |
59 (defvar reveal-open-spots nil) | |
60 (make-variable-buffer-local 'reveal-open-spots) | |
61 | |
62 ;; Actual code | |
63 | |
64 (defun reveal-post-command () | |
65 ;; Refresh the spots that might have changed. | |
66 ;; `Refreshing' here means to try and re-hide the corresponding text. | |
67 ;; We don't refresh everything correctly: | |
68 ;; - we only refresh spots in the current window. | |
69 ;; FIXME: do we actually know that (current-buffer) = (window-buffer) ? | |
70 (with-local-quit | |
45428
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
71 (condition-case err |
41621 | 72 (let* ((spots (cvs-partition |
73 (lambda (x) | |
74 ;; We refresh any spot in the current window as well | |
75 ;; as any spots associated with a dead window or a window | |
76 ;; which does not show this buffer any more. | |
77 (or (eq (car x) (selected-window)) | |
78 (not (window-live-p (car x))) | |
79 (not (eq (window-buffer (car x)) | |
80 (current-buffer))))) | |
81 reveal-open-spots)) | |
82 (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
|
83 (repeat t)) |
41621 | 84 (setq reveal-open-spots (cdr spots)) |
85 ;; Open new overlays. | |
86 (while repeat | |
87 (setq repeat nil) | |
88 (dolist (ol (nconc (when (and reveal-around-mark mark-active) | |
89 (overlays-at (mark))) | |
90 (overlays-at (point)))) | |
91 (push (cons (selected-window) ol) reveal-open-spots) | |
92 (setq old-ols (delq ol old-ols)) | |
45428
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
93 (let ((open (overlay-get ol 'reveal-toggle-invisible))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
94 (when (or open |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
95 (let ((inv (overlay-get ol 'invisible))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
96 (and inv (symbolp inv) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
97 (or (setq open (or (get inv 'reveal-toggle-invisible) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
98 (get ol 'isearch-open-invisible-temporary))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
99 (overlay-get ol 'isearch-open-invisible) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
100 (and (consp buffer-invisibility-spec) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
101 (assq inv buffer-invisibility-spec))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
102 (overlay-put ol 'reveal-invisible inv)))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
103 (if (null open) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
104 (overlay-put ol 'invisible nil) |
41621 | 105 ;; Use the provided opening function and repeat (since the |
106 ;; opening function might have hidden a subpart around point). | |
107 (setq repeat t) | |
108 (condition-case err | |
45428
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
109 (funcall open ol nil) |
41621 | 110 (error (message "!!Reveal-show: %s !!" err)))))))) |
111 ;; Close old overlays. | |
112 (dolist (ol old-ols) | |
45428
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
113 (when (and (eq (current-buffer) (overlay-buffer ol)) |
41621 | 114 (not (rassq ol reveal-open-spots))) |
115 (if (and (>= (point) (save-excursion | |
116 (goto-char (overlay-start ol)) | |
117 (line-beginning-position 1))) | |
118 (<= (point) (save-excursion | |
119 (goto-char (overlay-end ol)) | |
120 (line-beginning-position 2)))) | |
121 ;; Still near the overlay: keep it open. | |
122 (push (cons (selected-window) ol) reveal-open-spots) | |
123 ;; Really close it. | |
45428
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
124 (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
125 (if (or open |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
126 (and (setq inv (overlay-get ol 'reveal-invisible)) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
127 (setq open (or (get inv 'reveal-toggle-invisible) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
128 (get ol 'isearch-open-invisible-temporary))))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
129 (condition-case err |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
130 (funcall open ol t) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
131 (error (message "!!Reveal-hide: %s !!" err))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
132 (overlay-put ol 'invisible inv))))))) |
ac7e0cc03aed
(reveal-post-command): Reverse the semantics of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45341
diff
changeset
|
133 (error (message "Reveal: %s" err))))) |
41621 | 134 |
135 ;;;###autoload | |
136 (define-minor-mode reveal-mode | |
137 "Toggle Reveal mode on or off. | |
138 Reveal mode renders invisible text around point visible again. | |
139 | |
140 Interactively, with no prefix argument, toggle the mode. | |
141 With universal prefix ARG (or if ARG is nil) turn mode on. | |
142 With zero or negative ARG turn mode off." | |
41778
19e76eadbf86
(reveal-mode): Fix reveal-mode's lighter.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41621
diff
changeset
|
143 :lighter (global-reveal-mode nil " Reveal") |
41621 | 144 (if reveal-mode |
145 (progn | |
146 (set (make-local-variable 'search-invisible) t) | |
147 (add-hook 'post-command-hook 'reveal-post-command nil t)) | |
148 (kill-local-variable 'search-invisible) | |
149 (remove-hook 'post-command-hook 'reveal-post-command t))) | |
150 | |
151 ;;;###autoload | |
152 (define-minor-mode global-reveal-mode | |
153 "Toggle Reveal mode in all buffers on or off. | |
154 Reveal mode renders invisible text around point visible again. | |
155 | |
156 Interactively, with no prefix argument, toggle the mode. | |
157 With universal prefix ARG (or if ARG is nil) turn mode on. | |
158 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
|
159 :global t :group 'reveal |
41621 | 160 (setq-default reveal-mode global-reveal-mode) |
161 (if global-reveal-mode | |
162 (progn | |
163 (setq search-invisible t) | |
164 (add-hook 'post-command-hook 'reveal-post-command)) | |
165 (setq search-invisible 'open) ;FIXME | |
166 (remove-hook 'post-command-hook 'reveal-post-command))) | |
167 | |
168 (provide 'reveal) | |
48399
59fc5f077731
(global-reveal-mode): Add group.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
45428
diff
changeset
|
169 |
41621 | 170 ;;; reveal.el ends here |