0
|
1 ;;; outl-mouse.el --- outline mode mouse commands for Emacs
|
|
2
|
|
3 ;; Copyright 1994 (C) Andy Piper <ajp@eng.cam.ac.uk>
|
|
4 ;; Keywords: outlines, mouse
|
|
5
|
|
6 ;; This file is part of XEmacs.
|
|
7
|
|
8 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
9 ;; under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 ;; General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
|
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
21 ;;
|
|
22 ;; outl-mouse.el v1.3.8:
|
|
23 ;;
|
|
24 ;; Defines button one to hide blocks when clicked on outline-up-arrow
|
|
25 ;; and expand blocks when clicked on outline-down-arrow. Features are
|
|
26 ;; activated when outline-minor-mode or outline-mode are turned
|
|
27 ;; on. There is also a menu for each glyph on button 3.
|
|
28 ;;
|
|
29 ;; To use put:
|
|
30 ;; (require 'outl-mouse)
|
|
31 ;; in your .emacs file.
|
|
32 ;;
|
|
33 ;; If you use func-menu all the time and want outl-mouse on all the
|
|
34 ;; time as well then put:
|
|
35 ;; (setq outline-sync-with-func-menu t)
|
|
36 ;; outlining will then be turned on when func-menu is. Note that this
|
|
37 ;; requires a patch to func-menu 2.16 (in 19.10) to work:
|
|
38 ;;
|
|
39 ;RCS file: func-menu.el,v
|
|
40 ;retrieving revision 1.1
|
|
41 ;diff -r1.1 func-menu.el
|
|
42 ;180a181,183
|
|
43 ;> (defvar fume-found-function-hook nil
|
|
44 ;> "*Hook to call after every function match.")
|
|
45 ;>
|
|
46 ;1137,1138c1140,1142
|
|
47 ;< (if (listp funcname)
|
|
48 ;< (setq funclist (cons funcname funclist)))
|
|
49 ;---
|
|
50 ;> (cond ((listp funcname)
|
|
51 ;> (setq funclist (cons funcname funclist))
|
|
52 ;> (save-excursion (run-hooks 'fume-found-function-hook))))
|
|
53 ;;
|
|
54 ;; If you want mac-style outlining then set outline-mac-style to t.
|
|
55 ;; If you want the outline arrows on the left then set
|
|
56 ;; outline-glyphs-on-left to t. If you have xpm then arrows are much
|
|
57 ;; better defined.
|
|
58 ;;
|
|
59 ;; This package uses func-menu to define outline regexps if they are
|
|
60 ;; not already defined. You should no longer need to use out-xtra.
|
|
61 ;;
|
|
62 ;; You can define the package to do something other than outlining by
|
|
63 ;; setting outline-fold-in-function and outline-fold-out-function.
|
|
64 ;;
|
|
65 ;; You can define the color of outline arrows, but only in your .emacs.
|
|
66 ;;
|
|
67 ;; Only works in XEmacs 19.10 and onwards.
|
|
68 ;;
|
|
69 ;; User definable variables.
|
|
70 ;;
|
|
71 (defvar outline-mac-style nil
|
|
72 "*If t then outline glyphs will be right and down arrows.")
|
|
73
|
|
74 (defvar outline-glyphs-on-left nil
|
|
75 "*The position of outline glyphs on a line.")
|
|
76
|
|
77 (defvar outline-glyph-colour "Gray75"
|
|
78 "*The colour of outlining arrows.")
|
|
79
|
|
80 (defvar outline-glyph-shade-colour "Gray40"
|
|
81 "*The shadow colour of outlining arrows.")
|
|
82
|
|
83 (defvar outline-glyph-lit-colour "Gray90"
|
|
84 "*The lit colour of outlining arrows.")
|
|
85
|
|
86 (defvar outline-fold-in-function 'outline-fold-in
|
|
87 "Function to call for folding in.
|
|
88 The function should take an annotation argument.")
|
|
89 (make-variable-buffer-local 'outline-fold-in-function)
|
|
90
|
|
91 (defvar outline-fold-out-function 'outline-fold-out
|
|
92 "Function to call for folding out.
|
|
93 The function should take an annotation argument.")
|
|
94 (make-variable-buffer-local 'outline-fold-out-function)
|
|
95
|
|
96 (defvar outline-sync-with-func-menu nil
|
|
97 "*If t then outline glyphs are permanently added by func-menu scans.
|
|
98 If outline-minor-mode is turned off then turing it back on will have
|
|
99 no effect. Instead the buffer should be rescanned from the function
|
|
100 menu.")
|
|
101
|
|
102 (defvar outline-move-point-after-click t
|
|
103 "*If t then point is moved to the current heading when clicked.")
|
|
104
|
|
105 (defvar outline-scanning-message "Adding glyphs... (%3d%%)"
|
|
106 "*Progress message during the scanning of the buffer.
|
|
107 Set this to nil to inhibit progress messages.")
|
|
108
|
|
109 ;;
|
|
110 ;; No user definable variables beyond this point.
|
|
111 ;;
|
48
|
112
|
|
113 ;; I'll bet there's a neat way to do this with specifiers -- a pity the
|
|
114 ;; sucks so badly on it. -sb
|
|
115 (defconst outline-up-arrow ; XEmacs
|
|
116 (make-glyph ; an up-arrow
|
|
117 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
118 static char * arrow[] = {
|
|
119 \"10 10 5 1\",
|
|
120 \" c none\",
|
|
121 \". c " outline-glyph-lit-colour "\",
|
|
122 \"X c " outline-glyph-shade-colour "\",
|
|
123 \"o c " outline-glyph-colour "\",
|
|
124 \"O c " outline-glyph-shade-colour "\",
|
|
125 \" .X \",
|
|
126 \" .X \",
|
|
127 \" ..XX \",
|
|
128 \" ..XX \",
|
|
129 \" ..ooXX \",
|
|
130 \" ..ooXX \",
|
|
131 \" ..ooooXX \",
|
|
132 \" ..ooooXX \",
|
|
133 \"..OOOOOOXX\",
|
48
|
134 \"OOOOOOOOOO\"};")))
|
|
135 ((featurep 'x)
|
|
136 (vector 'xbm
|
|
137 :data
|
|
138 (list 10 10
|
|
139 (concat "\000\000\000\000\060\000\060\000\150\000"
|
|
140 "\150\000\324\000\324\000\376\001\376\001"))))
|
|
141 (t "^")))
|
0
|
142 "Bitmap object for outline up glyph.")
|
|
143
|
48
|
144 (defconst outline-up-arrow-mask ; XEmacs
|
|
145 (make-glyph ; an up-arrow
|
|
146 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
147 static char * arrow[] = {
|
|
148 \"10 10 5 1\",
|
|
149 \" c none\",
|
|
150 \". c " outline-glyph-shade-colour "\",
|
|
151 \"X c " outline-glyph-lit-colour "\",
|
|
152 \"o c " outline-glyph-colour "\",
|
|
153 \"O c " outline-glyph-lit-colour "\",
|
|
154 \" .X \",
|
|
155 \" .X \",
|
|
156 \" ..XX \",
|
|
157 \" ..XX \",
|
|
158 \" ..ooXX \",
|
|
159 \" ..ooXX \",
|
|
160 \" ..ooooXX \",
|
|
161 \" ..ooooXX \",
|
|
162 \"..OOOOOOXX\",
|
48
|
163 \"OOOOOOOOOO\"};")))
|
|
164 ((featurep 'x)
|
|
165 (vector 'xbm
|
|
166 :data
|
|
167 (list 10 10
|
|
168 (concat "\000\000\000\000\060\000\060\000\130\000"
|
|
169 "\130\000\254\000\274\000\006\001\376\001"))))
|
|
170 (t "+")))
|
0
|
171 "Bitmap object for outline depressed up glyph.")
|
|
172
|
48
|
173 (defconst outline-down-arrow ; XEmacs
|
|
174 (make-glyph ; a down-arrow
|
|
175 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
176 static char * down[] = {
|
|
177 \"10 10 5 1\",
|
|
178 \" c " outline-glyph-lit-colour "\",
|
|
179 \". c " outline-glyph-lit-colour "\",
|
|
180 \"X c " outline-glyph-shade-colour "\",
|
|
181 \"o c none\",
|
|
182 \"O c " outline-glyph-colour "\",
|
|
183 \" \",
|
|
184 \".. XX\",
|
|
185 \"o..OOOOXXo\",
|
|
186 \"o..OOOOXXo\",
|
|
187 \"oo..OOXXoo\",
|
|
188 \"oo..OOXXoo\",
|
|
189 \"ooo..XXooo\",
|
|
190 \"ooo..XXooo\",
|
|
191 \"oooo.Xoooo\",
|
48
|
192 \"oooo.Xoooo\"};")))
|
|
193 ((featurep 'x)
|
|
194 (vector 'xbm
|
|
195 :data
|
|
196 (list 10 10
|
|
197 (concat "\000\000\000\000\376\001\202\001\364\000"
|
|
198 "\324\000\150\000\150\000\060\000\060\000"))))
|
|
199 (t "v")))
|
0
|
200 "Bitmap object for outline down glyph.")
|
|
201
|
48
|
202 (defconst outline-down-arrow-mask ; XEmacs
|
|
203 (make-glyph ; a down-arrow
|
|
204 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
205 static char * down[] = {
|
|
206 \"10 10 5 1\",
|
|
207 \" c " outline-glyph-shade-colour "\",
|
|
208 \". c " outline-glyph-shade-colour "\",
|
|
209 \"X c " outline-glyph-lit-colour "\",
|
|
210 \"o c none\",
|
|
211 \"O c " outline-glyph-colour "\",
|
|
212 \" \",
|
|
213 \".. XX\",
|
|
214 \"o..OOOOXXo\",
|
|
215 \"o..OOOOXXo\",
|
|
216 \"oo..OOXXoo\",
|
|
217 \"oo..OOXXoo\",
|
|
218 \"ooo..XXooo\",
|
|
219 \"ooo..XXooo\",
|
|
220 \"oooo.Xoooo\",
|
48
|
221 \"oooo.Xoooo\"};")))
|
|
222 ((featurep 'x)
|
|
223 (vector 'xbm
|
|
224 :data
|
|
225 (list 10 10
|
|
226 (concat "\000\000\000\000\376\001\376\001\254\000"
|
|
227 "\254\000\130\000\130\000\060\000\060\000"))))
|
|
228 (t "+")))
|
0
|
229 "Bitmap object for outline depressed down glyph.")
|
|
230
|
|
231 (defconst outline-right-arrow
|
48
|
232 (make-glyph ; a right-arrow
|
|
233 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
234 static char * right[] = {
|
|
235 \"10 10 5 1\",
|
|
236 \" c " outline-glyph-lit-colour "\",
|
|
237 \". c " outline-glyph-lit-colour "\",
|
|
238 \"X c none\",
|
|
239 \"o c " outline-glyph-colour "\",
|
|
240 \"O c " outline-glyph-shade-colour "\",
|
|
241 \" .XXXXXXXX\",
|
|
242 \" ...XXXXXX\",
|
|
243 \" ....XXXX\",
|
|
244 \" oo....XX\",
|
|
245 \" oooo....\",
|
|
246 \" ooooOOOO\",
|
|
247 \" ooOOOOXX\",
|
|
248 \" OOOOXXXX\",
|
|
249 \" OOOXXXXXX\",
|
48
|
250 \" OXXXXXXXX\"};")))
|
|
251 ((featurep 'x)
|
|
252 (vector 'xbm
|
|
253 :data
|
|
254 (list 10 10
|
|
255 (concat "\000\000\006\000\032\000\142\000\232\001"
|
|
256 "\352\001\172\000\036\000\006\000\000\000"))))
|
|
257 (t ">")))
|
0
|
258 "Bitmap object for outline right glyph.")
|
|
259
|
|
260 (defconst outline-right-arrow-mask
|
48
|
261 (make-glyph ; a right-arrow
|
|
262 (cond ((featurep 'xpm) (vector 'xpm :data (concat "/* XPM */
|
0
|
263 static char * right[] = {
|
|
264 \"10 10 5 1\",
|
|
265 \" c " outline-glyph-shade-colour "\",
|
|
266 \". c " outline-glyph-shade-colour "\",
|
|
267 \"X c none\",
|
|
268 \"o c " outline-glyph-colour "\",
|
|
269 \"O c " outline-glyph-lit-colour "\",
|
|
270 \" .XXXXXXXX\",
|
|
271 \" ...XXXXXX\",
|
|
272 \" ....XXXX\",
|
|
273 \" oo....XX\",
|
|
274 \" oooo....\",
|
|
275 \" ooooOOOO\",
|
|
276 \" ooOOOOXX\",
|
|
277 \" OOOOXXXX\",
|
|
278 \" OOOXXXXXX\",
|
48
|
279 \" OXXXXXXXX\"};")))
|
|
280 ((featurep 'x)
|
|
281 (vector 'xbm
|
|
282 :data
|
|
283 (list 10 10
|
|
284 (concat "\000\000\006\000\036\000\176\000\346\001"
|
|
285 "\236\001\146\000\036\000\006\000\000\000"))))
|
|
286 (t "+")))
|
0
|
287 "Bitmap object for outline depressed right glyph.")
|
|
288
|
|
289 (defvar outline-glyph-menu
|
|
290 '("Outline Commands"
|
|
291 ["Hide all" hide-body t]
|
|
292 ["Hide all subtrees" hide-subtrees-same-level t]
|
8
|
293 ["Hide subtree" hide-subtree t]
|
|
294 ; ["Hide body" hide-body t]
|
0
|
295 "---"
|
8
|
296 ["Show all" show-all t]
|
0
|
297 ["Show subtree" show-subtree t]
|
|
298 ["Show body" show-entry t]
|
|
299 "---"
|
|
300 ["Update buffer" outline-add-glyphs t]
|
|
301 ["Rescan buffer" outline-rescan-buffer t])
|
|
302 "Menu of commands for outline glyphs.")
|
|
303
|
|
304 (set-pixmap-contributes-to-line-height outline-down-arrow nil)
|
|
305 (set-pixmap-contributes-to-line-height outline-up-arrow nil)
|
|
306 (set-pixmap-contributes-to-line-height outline-down-arrow-mask nil)
|
|
307 (set-pixmap-contributes-to-line-height outline-up-arrow-mask nil)
|
|
308 (set-pixmap-contributes-to-line-height outline-right-arrow nil)
|
|
309 (set-pixmap-contributes-to-line-height outline-right-arrow-mask nil)
|
|
310
|
|
311 (require 'annotations)
|
|
312 (require 'advice) ; help me doctor !
|
|
313 (require 'outline)
|
|
314 (require 'func-menu) ; for those most excellent regexps.
|
|
315
|
|
316 (add-hook 'outline-mode-hook 'outline-mouse-hooks)
|
|
317 (add-hook 'outline-minor-mode-hook 'outline-mouse-hooks)
|
|
318 ;; I thought this was done already ...
|
|
319 (make-variable-buffer-local 'outline-regexp)
|
|
320 (make-variable-buffer-local 'outline-level)
|
|
321
|
|
322 (cond (outline-sync-with-func-menu
|
|
323 (add-hook 'fume-found-function-hook 'outline-heading-add-glyph-1)
|
|
324 (setq-default fume-rescan-buffer-hook '(lambda ()
|
|
325 (outline-minor-mode 1)))))
|
|
326
|
|
327 (defadvice fume-set-defaults (after fume-set-defaults-ad activate)
|
|
328 "Advise fume-set-defaults to setup outline regexps."
|
|
329 (if (and (not (assq 'outline-regexp (buffer-local-variables)))
|
|
330 fume-function-name-regexp)
|
|
331 (progn
|
|
332 (setq outline-regexp (if (listp fume-function-name-regexp)
|
|
333 (car fume-function-name-regexp)
|
|
334 fume-function-name-regexp))
|
|
335 (setq outline-level '(lambda () 1)))))
|
|
336
|
|
337 (defadvice outline-minor-mode (after outline-mode-mouse activate)
|
|
338 "Advise outline-minor-mode to delete glyphs when switched off."
|
|
339 (if (not outline-minor-mode)
|
|
340 (progn
|
|
341 (outline-delete-glyphs)
|
|
342 (show-all))))
|
|
343
|
|
344 ;; advise all outline commands so that glyphs are synced after use
|
|
345 (defadvice show-all (after show-all-ad activate)
|
|
346 "Advise show-all to sync headings."
|
|
347 (outline-sync-visible-sub-headings-in-region (point-min) (point-max)))
|
|
348
|
|
349 (defadvice hide-subtree (after hide-subtree-ad activate)
|
|
350 "Advise hide-subtree to sync headings."
|
|
351 (outline-sync-visible-sub-headings))
|
|
352
|
|
353 (defadvice hide-entry (after hide-entry-ad activate)
|
|
354 "Advise hide-entry to sync headings."
|
|
355 (outline-sync-visible-sub-headings))
|
|
356
|
|
357 (defadvice hide-body (after hide-body-ad activate)
|
|
358 "Advise hide-body to sync headings."
|
|
359 (outline-sync-visible-sub-headings-in-region (point-min) (point-max)))
|
|
360
|
|
361 (defadvice show-subtree (after show-subtree-ad activate)
|
|
362 "Advise show-subtree to sync headings."
|
|
363 (outline-sync-visible-sub-headings))
|
|
364
|
|
365 (defadvice show-entry (after show-entry-ad activate)
|
|
366 "Advise shown-entry to sync headings."
|
|
367 (outline-sync-visible-sub-headings))
|
|
368
|
|
369 ;;;###autoload
|
|
370 (defun outl-mouse-mode ()
|
|
371 "Calls outline-mode, with outl-mouse extensions"
|
|
372 (interactive)
|
|
373 (outline-mode))
|
|
374
|
|
375 ;;;###autoload
|
|
376 (defun outl-mouse-minor-mode (&optional arg)
|
|
377 "Toggles outline-minor-mode, with outl-mouse extensions"
|
|
378 (interactive "P")
|
|
379 (outline-minor-mode arg))
|
|
380
|
|
381 (defun hide-subtrees-same-level ()
|
|
382 "Hide all subtrees below the current level."
|
|
383 (interactive)
|
|
384 (save-excursion
|
|
385 (while (progn
|
|
386 (hide-subtree)
|
|
387 (condition-case nil
|
|
388 (progn
|
|
389 (outline-forward-same-level 1)
|
|
390 t)
|
|
391 (error nil))))))
|
|
392
|
|
393 (defun outline-mouse-hooks ()
|
|
394 "Hook for installing outlining with the mouse."
|
|
395 ;; use function menu regexps if not set
|
|
396 (fume-set-defaults)
|
|
397 ;; only add glyphs when we're not synced.
|
|
398 (if (not outline-sync-with-func-menu) (outline-add-glyphs))
|
|
399 ;; add C-a to local keymap
|
|
400 (let ((outline (cond ((keymapp (lookup-key (current-local-map)
|
|
401 outline-minor-mode-prefix))
|
|
402 (lookup-key (current-local-map)
|
|
403 outline-minor-mode-prefix))
|
|
404 (t
|
|
405 (define-key (current-local-map)
|
|
406 outline-minor-mode-prefix (make-sparse-keymap))
|
|
407 (lookup-key (current-local-map)
|
|
408 outline-minor-mode-prefix)))))
|
|
409 (define-key outline "\C-a" 'outline-heading-add-glyph)
|
|
410 (define-key outline-mode-map "\C-c\C-a" 'outline-heading-add-glyph)))
|
|
411
|
|
412 (defun outline-add-glyphs ()
|
|
413 "Add annotations and glyphs to all heading lines that don't have them."
|
|
414 (interactive)
|
|
415 (save-excursion
|
|
416 (and outline-scanning-message (message outline-scanning-message 0))
|
|
417 (goto-char (point-min))
|
|
418 (if (not (outline-on-heading-p)) (outline-next-visible-heading-safe))
|
|
419 (while
|
|
420 (progn
|
|
421 (outline-heading-add-glyph-1)
|
|
422 (and outline-scanning-message
|
|
423 (message outline-scanning-message (fume-relative-position)))
|
|
424 (outline-next-visible-heading-safe)))
|
|
425 (and outline-scanning-message
|
|
426 (message "%s done" (format outline-scanning-message 100)))))
|
|
427
|
|
428 (defun outline-delete-glyphs ()
|
|
429 "Remove annotations and glyphs from heading lines."
|
|
430 (save-excursion
|
|
431 (mapcar 'outline-heading-delete-glyph (annotation-list))))
|
|
432
|
|
433 (defun outline-rescan-buffer ()
|
|
434 "Remove and insert all annotations."
|
|
435 (interactive)
|
|
436 (outline-delete-glyphs)
|
|
437 (outline-add-glyphs)
|
|
438 (save-excursion
|
|
439 (outline-sync-visible-sub-headings-in-region (point-min) (point-max))))
|
|
440
|
|
441 (defun outline-heading-delete-glyph (ext)
|
|
442 "Delete annotation and glyph from a heading with annotation EXT."
|
|
443 (if (and
|
|
444 (progn
|
|
445 (goto-char (extent-start-position ext))
|
|
446 (beginning-of-line)
|
|
447 (outline-on-heading-p))
|
|
448 (extent-property ext 'outline))
|
|
449 (delete-annotation ext))
|
|
450 nil)
|
|
451
|
|
452 (defun outline-heading-add-glyph ()
|
|
453 "Interactive version of outline-heading-add-glyph-1."
|
|
454 (interactive)
|
|
455 (save-excursion
|
|
456 (outline-heading-add-glyph-1)))
|
|
457
|
|
458 (defun outline-heading-add-glyph-1 ()
|
|
459 "Add glyph to the end of heading line which point is on.
|
|
460 Returns nil if point is not on a heading or glyph already exists."
|
|
461 (if (or (not (outline-on-heading-p))
|
|
462 (outline-heading-has-glyph-p)
|
|
463 (save-excursion (forward-line) (outline-on-heading-p)))
|
|
464 nil
|
|
465 (outline-back-to-heading)
|
|
466 (let ((anot2
|
|
467 (make-annotation (if outline-mac-style
|
|
468 outline-right-arrow
|
|
469 outline-down-arrow)
|
|
470 (save-excursion (if outline-glyphs-on-left nil
|
|
471 (outline-end-of-heading))
|
|
472 (point))
|
|
473 'text nil t
|
|
474 (if outline-mac-style
|
|
475 outline-right-arrow-mask
|
|
476 outline-down-arrow-mask)))
|
|
477 (anot1
|
|
478 (make-annotation (if outline-mac-style
|
|
479 outline-down-arrow
|
|
480 outline-up-arrow)
|
|
481 (save-excursion (if outline-glyphs-on-left nil
|
|
482 (outline-end-of-heading))
|
|
483 (point))
|
|
484 'text nil t
|
|
485 (if outline-mac-style
|
|
486 outline-down-arrow-mask
|
|
487 outline-up-arrow-mask))))
|
|
488 ;; we cunningly make the annotation data point to its twin.
|
|
489 (set-annotation-data anot1 anot2)
|
|
490 (set-extent-property anot1 'outline 'up)
|
|
491 (set-annotation-action anot1 'outline-up-click)
|
|
492 (set-annotation-menu anot1 outline-glyph-menu)
|
|
493 (set-extent-priority anot1 1)
|
|
494 (set-annotation-data anot2 anot1)
|
|
495 (set-extent-property anot2 'outline 'down)
|
|
496 (set-annotation-menu anot2 outline-glyph-menu)
|
|
497 (set-annotation-action anot2 'outline-down-click)
|
|
498 (annotation-hide anot2))
|
|
499 t))
|
|
500
|
|
501 (defun outline-heading-has-glyph-p ()
|
|
502 "Return t if heading has an outline glyph."
|
|
503 (catch 'found
|
|
504 (mapcar
|
|
505 '(lambda(a)
|
|
506 (if (extent-property a 'outline)
|
|
507 (throw 'found t)))
|
|
508 (annotations-in-region (save-excursion (outline-back-to-heading) (point))
|
|
509 (save-excursion (outline-end-of-heading)
|
|
510 (+ 1 (point)))
|
|
511 (current-buffer)))
|
|
512 nil))
|
|
513
|
|
514 (defun outline-sync-visible-sub-headings-in-region (pmin pmax)
|
|
515 "Make sure all anotations on headings in region PMIN PMAX are
|
|
516 displayed correctly."
|
|
517 (mapcar '(lambda (x)
|
|
518 (goto-char (extent-start-position x))
|
|
519 (beginning-of-line)
|
|
520 (cond ((and (eq (extent-property x 'outline) 'down)
|
|
521 ;; skip things we can't see
|
|
522 (not (eq (preceding-char) ?\^M)))
|
|
523 (if (outline-more-to-hide)
|
|
524 ;; reveal my twin
|
|
525 (annotation-reveal (annotation-data x))
|
|
526 (annotation-hide (annotation-data x)))
|
|
527 (if (not (outline-hidden-p))
|
|
528 ;; hide my self
|
|
529 (annotation-hide x)
|
|
530 (annotation-reveal x)))))
|
|
531 (annotations-in-region pmin pmax (current-buffer))))
|
|
532
|
|
533 (defun outline-sync-visible-sub-headings ()
|
|
534 "Make sure all anotations on sub-headings below the one point is on are
|
|
535 displayed correctly."
|
|
536 (outline-sync-visible-sub-headings-in-region
|
|
537 (point)
|
|
538 (progn (outline-end-of-subtree) (point))))
|
|
539
|
|
540 (defun outline-fold-out (annotation)
|
|
541 "Fold out the current heading."
|
|
542 (beginning-of-line)
|
|
543 ; (if (not (equal (condition-case nil
|
|
544 ; (save-excursion (outline-next-visible-heading 1)
|
|
545 ; (point))
|
|
546 ; (error nil))
|
|
547 ; (save-excursion (outline-next-heading)
|
|
548 ; (if (eobp) nil (point)))))
|
|
549 (if (save-excursion (outline-next-heading)
|
|
550 (eq (preceding-char) ?\^M))
|
|
551 (progn
|
|
552 (save-excursion (show-children))
|
|
553 (outline-sync-visible-sub-headings))
|
|
554 ;; mess with single entry
|
|
555 (if (outline-hidden-p)
|
|
556 (progn
|
|
557 (save-excursion (show-entry))
|
|
558 ;; reveal my twin and hide me
|
|
559 (annotation-hide annotation)
|
|
560 (annotation-reveal (annotation-data annotation))))))
|
|
561
|
|
562 (defun outline-fold-in (annotation)
|
|
563 "Fold in the current heading."
|
|
564 (beginning-of-line)
|
|
565 ;; mess with single entries
|
|
566 (if (not (outline-hidden-p))
|
|
567 (progn
|
|
568 (save-excursion (hide-entry))
|
|
569 (if (not (outline-more-to-hide))
|
|
570 (annotation-hide annotation))
|
|
571 (annotation-reveal (annotation-data annotation)))
|
|
572 ;; otherwise look for more leaves
|
|
573 (save-excursion
|
|
574 (if (outline-more-to-hide t)
|
|
575 (hide-subtree)
|
|
576 (hide-leaves)))
|
|
577 ;; sync everything
|
|
578 (outline-sync-visible-sub-headings)))
|
|
579
|
|
580 (defun outline-more-to-hide (&optional arg)
|
|
581 "Return t if there are more visible sub-headings or text.
|
|
582 With ARG return t only if visible sub-headings have no visible text."
|
|
583 (if (not (outline-hidden-p))
|
|
584 (if arg nil t)
|
|
585 (save-excursion
|
|
586 (and (< (funcall outline-level) (condition-case nil
|
|
587 (progn
|
|
588 (outline-next-visible-heading 1)
|
|
589 (funcall outline-level))
|
|
590 (error 0)))
|
|
591 (if (and (not (outline-hidden-p)) arg)
|
|
592 nil t)))))
|
|
593
|
|
594 (defun outline-hidden-p ()
|
|
595 "Return t if point is on the header of a hidden subtree."
|
|
596 (save-excursion
|
|
597 (let ((end-of-entry (save-excursion (outline-next-heading))))
|
|
598 ;; Make sure that the end of the entry really exists.
|
|
599 (if (not end-of-entry)
|
|
600 (setq end-of-entry (point-max)))
|
|
601 (outline-back-to-heading)
|
|
602 ;; If there are ANY ^M's, the entry is hidden.
|
|
603 (search-forward "\^M" end-of-entry t))))
|
|
604
|
|
605 (defun outline-next-visible-heading-safe ()
|
|
606 "Safely go to the next visible heading.
|
|
607 nil is returned if there is none."
|
|
608 (condition-case nil
|
|
609 (progn
|
|
610 (outline-next-visible-heading 1)
|
|
611 t)
|
|
612 (error nil)))
|
|
613
|
|
614 (defun outline-up-click (data ev)
|
|
615 "Annotation action for clicking on an up arrow.
|
|
616 DATA is the annotation data. EV is the mouse click event."
|
|
617 (save-excursion
|
|
618 (goto-char (extent-end-position (event-glyph-extent ev)))
|
|
619 (funcall outline-fold-in-function (event-glyph-extent ev)))
|
|
620 (if outline-move-point-after-click
|
|
621 (progn
|
|
622 (goto-char (extent-end-position (event-glyph-extent ev)))
|
|
623 (beginning-of-line))))
|
|
624 ; This line demonstrates a bug in redisplay
|
|
625 (defun outline-down-click (data ev)
|
|
626 "Annotation action for clicking on a down arrow.
|
|
627 DATA is the annotation data. EV is the mouse click event."
|
|
628 (save-excursion
|
|
629 (goto-char (extent-end-position (event-glyph-extent ev)))
|
|
630 (funcall outline-fold-out-function (event-glyph-extent ev)))
|
|
631 (if outline-move-point-after-click
|
|
632 (progn
|
|
633 (goto-char (extent-end-position (event-glyph-extent ev)))
|
|
634 (beginning-of-line))))
|
|
635
|
|
636
|
|
637 (provide 'outl-mouse)
|
|
638 (provide 'outln-18) ; fool auctex - outline is ok now.
|
|
639
|
|
640 ;; Local Variables:
|
|
641 ;; outline-regexp: ";;; \\|(def.."
|
|
642 ;; End:
|
|
643
|
|
644
|
|
645
|