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