428
|
1 ;;; gutter-items.el --- Gutter content for XEmacs.
|
|
2
|
|
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
|
442
|
4 ;; Copyright (C) 1999, 2000 Andy Piper.
|
|
5 ;; Copyright (C) 2000 Ben Wing.
|
428
|
6
|
|
7 ;; Maintainer: XEmacs Development Team
|
|
8 ;; Keywords: frames, extensions, internal, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with Xmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;; Some of this is taken from the buffer-menu stuff in menubar-items.el
|
|
28
|
|
29 ;;; The Buffers tab
|
|
30
|
|
31 (defgroup buffers-tab nil
|
|
32 "Customization of `Buffers' tab."
|
|
33 :group 'gutter)
|
|
34
|
442
|
35 (defvar gutter-buffers-tab nil
|
|
36 "A tab widget in the gutter for displaying buffers.
|
|
37 Do not set this. Use `set-glyph-image' to change the properties of the tab.")
|
|
38
|
|
39 (defcustom gutter-buffers-tab-visible-p
|
|
40 (gutter-element-visible-p default-gutter-visible-p 'buffers-tab)
|
|
41 "Whether the buffers tab is globally visible.
|
|
42 This option should be set through the options menu."
|
|
43 :group 'buffers-tab
|
|
44 :type 'boolean
|
|
45 :set #'(lambda (var val)
|
|
46 (set-gutter-element-visible-p default-gutter-visible-p
|
|
47 'buffers-tab val)
|
|
48 (setq gutter-buffers-tab-visible-p val)))
|
|
49
|
444
|
50 (defcustom gutter-buffers-tab-enabled t
|
|
51 "*Whether to enable support for buffers tab in the gutter.
|
|
52 This is different to `gutter-buffers-tab-visible-p' which still runs hooks
|
|
53 even when the gutter is invisible."
|
|
54 :group 'buffers-tab
|
|
55 :type 'boolean)
|
|
56
|
438
|
57 (defvar gutter-buffers-tab-orientation 'top
|
|
58 "Where the buffers tab currently is. Do not set this.")
|
|
59
|
428
|
60 (defcustom buffers-tab-max-size 6
|
|
61 "*Maximum number of entries which may appear on the \"Buffers\" tab.
|
|
62 If this is 10, then only the ten most-recently-selected buffers will be
|
|
63 shown. If this is nil, then all buffers will be shown. Setting this to
|
|
64 a large number or nil will slow down tab responsiveness."
|
|
65 :type '(choice (const :tag "Show all" nil)
|
|
66 (integer 6))
|
|
67 :group 'buffers-tab)
|
|
68
|
|
69 (defcustom buffers-tab-switch-to-buffer-function 'buffers-tab-switch-to-buffer
|
|
70 "*The function to call to select a buffer from the buffers tab.
|
|
71 `switch-to-buffer' is a good choice, as is `pop-to-buffer'."
|
|
72 :type '(radio (function-item switch-to-buffer)
|
|
73 (function-item pop-to-buffer)
|
|
74 (function :tag "Other"))
|
|
75 :group 'buffers-tab)
|
|
76
|
|
77 (defcustom buffers-tab-omit-function 'buffers-menu-omit-invisible-buffers
|
|
78 "*If non-nil, a function specifying the buffers to omit from the buffers tab.
|
|
79 This is passed a buffer and should return non-nil if the buffer should be
|
444
|
80 omitted. The default value `buffers-menu-omit-invisible-buffers' omits
|
428
|
81 buffers that are normally considered \"invisible\" (those whose name
|
|
82 begins with a space)."
|
|
83 :type '(choice (const :tag "None" nil)
|
|
84 function)
|
|
85 :group 'buffers-tab)
|
|
86
|
|
87 (defcustom buffers-tab-selection-function 'select-buffers-tab-buffers-by-mode
|
|
88 "*If non-nil, a function specifying the buffers to select from the
|
|
89 buffers tab. This is passed two buffers and should return non-nil if
|
|
90 the second buffer should be selected. The default value
|
|
91 `select-buffers-tab-buffers-by-mode' groups buffers by major mode and
|
|
92 by `buffers-tab-grouping-regexp'."
|
|
93
|
|
94 :type '(choice (const :tag "None" nil)
|
|
95 function)
|
|
96 :group 'buffers-tab)
|
|
97
|
444
|
98 (defcustom buffers-tab-filter-functions (list buffers-tab-selection-function)
|
|
99 "*If non-nil, a list of functions specifying the buffers to select
|
|
100 from the buffers tab.
|
|
101 Each function in the list is passed two buffers, the buffer to
|
|
102 potentially select and the context buffer, and should return non-nil
|
|
103 if the first buffer should be selected. The default value groups
|
|
104 buffers by major mode and by `buffers-tab-grouping-regexp'."
|
|
105
|
|
106 :type '(choice (const :tag "None" nil)
|
|
107 sexp)
|
|
108 :group 'buffers-tab)
|
|
109
|
442
|
110 (defcustom buffers-tab-sort-function nil
|
|
111 "*If non-nil, a function specifying the buffers to select from the
|
|
112 buffers tab. This is passed the buffer list and returns the list in the
|
|
113 order desired for the tab widget. The default value `nil' leaves the
|
|
114 list in `buffer-list' order (usual most-recently-selected-first)."
|
|
115
|
|
116 :type '(choice (const :tag "None" nil)
|
|
117 function)
|
|
118 :group 'buffers-tab)
|
|
119
|
438
|
120 (make-face 'buffers-tab "Face for displaying the buffers tab.")
|
|
121 (set-face-parent 'buffers-tab 'default)
|
|
122
|
|
123 (defcustom buffers-tab-face 'buffers-tab
|
428
|
124 "*Face to use for displaying the buffers tab."
|
|
125 :type 'face
|
|
126 :group 'buffers-tab)
|
|
127
|
|
128 (defcustom buffers-tab-grouping-regexp
|
|
129 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
|
|
130 "^\\(emacs-lisp-\\|lisp-\\)")
|
|
131 "*If non-nil, a list of regular expressions for buffer grouping.
|
|
132 Each regular expression is applied to the current major-mode symbol
|
|
133 name and mode-name, if it matches then any other buffers that match
|
|
134 the same regular expression be added to the current group."
|
|
135 :type '(choice (const :tag "None" nil)
|
|
136 sexp)
|
|
137 :group 'buffers-tab)
|
|
138
|
|
139 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-tab-line
|
|
140 "*The function to call to return a string to represent a buffer in the
|
|
141 buffers tab. The function is passed a buffer and should return a
|
|
142 string. The default value `format-buffers-tab-line' just returns the
|
|
143 name of the buffer, optionally truncated to
|
|
144 `buffers-tab-max-buffer-line-length'. Also check out
|
|
145 `slow-format-buffers-menu-line' which returns a whole bunch of info
|
|
146 about a buffer."
|
|
147 :type 'function
|
|
148 :group 'buffers-tab)
|
|
149
|
|
150 (defvar buffers-tab-default-buffer-line-length
|
|
151 (make-specifier-and-init 'generic '((global ((default) . 25))) t)
|
|
152 "*Maximum length of text which may appear in a \"Buffers\" tab.
|
|
153 This is a specifier, use set-specifier to modify it.")
|
|
154
|
|
155 (defcustom buffers-tab-max-buffer-line-length
|
|
156 (specifier-instance buffers-tab-default-buffer-line-length)
|
|
157 "*Maximum length of text which may appear in a \"Buffers\" tab.
|
|
158 Buffer names over this length will be truncated with elipses.
|
|
159 If this is 0, then the full buffer name will be shown."
|
|
160 :type '(choice (const :tag "Show all" 0)
|
|
161 (integer 25))
|
|
162 :group 'buffers-tab
|
|
163 :set #'(lambda (var val)
|
|
164 (set-specifier buffers-tab-default-buffer-line-length val)
|
|
165 (setq buffers-tab-max-buffer-line-length val)))
|
|
166
|
|
167 (defun buffers-tab-switch-to-buffer (buffer)
|
|
168 "For use as a value for `buffers-tab-switch-to-buffer-function'."
|
|
169 (unless (eq (window-buffer) buffer)
|
442
|
170 ;; this used to add the norecord flag to both calls below.
|
|
171 ;; this is bogus because it is a pervasive assumption in XEmacs
|
|
172 ;; that the current buffer is at the front of the buffers list.
|
|
173 ;; for example, select an item and then do M-C-l
|
|
174 ;; (switch-to-other-buffer). Things get way confused.
|
428
|
175 (if (> (length (windows-of-buffer buffer)) 0)
|
|
176 (select-window (car (windows-of-buffer buffer)))
|
442
|
177 (switch-to-buffer buffer))))
|
428
|
178
|
444
|
179 (defun select-buffers-tab-buffers-by-mode (buffer-to-select buf1)
|
428
|
180 "For use as a value of `buffers-tab-selection-function'.
|
|
181 This selects buffers by major mode `buffers-tab-grouping-regexp'."
|
|
182 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
|
444
|
183 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
|
|
184 buffer-to-select)))
|
428
|
185 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
|
444
|
186 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select)))
|
428
|
187 (cond ((or (eq mode1 mode2)
|
|
188 (eq modenm1 modenm2)
|
|
189 (and (string-match "^[^-]+-" mode1)
|
|
190 (string-match
|
|
191 (concat "^" (regexp-quote
|
|
192 (substring mode1 0 (match-end 0))))
|
|
193 mode2))
|
|
194 (and buffers-tab-grouping-regexp
|
|
195 (find-if #'(lambda (x)
|
|
196 (or
|
|
197 (and (string-match x mode1)
|
|
198 (string-match x mode2))
|
|
199 (and (string-match x modenm1)
|
|
200 (string-match x modenm2))))
|
|
201 buffers-tab-grouping-regexp)))
|
|
202 t)
|
|
203 (t nil))))
|
|
204
|
|
205 (defun format-buffers-tab-line (buffer)
|
|
206 "For use as a value of `buffers-tab-format-buffer-line-function'.
|
|
207 This just returns the buffer's name, optionally truncated."
|
|
208 (let ((len (specifier-instance buffers-tab-default-buffer-line-length)))
|
|
209 (if (and (> len 0)
|
|
210 (> (length (buffer-name buffer)) len))
|
440
|
211 (if (string-match ".*<.>$" (buffer-name buffer))
|
|
212 (concat (substring (buffer-name buffer)
|
|
213 0 (- len 6)) "..."
|
|
214 (substring (buffer-name buffer) -3))
|
|
215 (concat (substring (buffer-name buffer)
|
|
216 0 (- len 3)) "..."))
|
428
|
217 (buffer-name buffer))))
|
|
218
|
|
219 (defsubst build-buffers-tab-internal (buffers)
|
442
|
220 (let ((selected t))
|
428
|
221 (mapcar
|
|
222 #'(lambda (buffer)
|
442
|
223 (prog1
|
|
224 (vector
|
|
225 (funcall buffers-tab-format-buffer-line-function
|
|
226 buffer)
|
|
227 (list buffers-tab-switch-to-buffer-function
|
|
228 (buffer-name buffer))
|
|
229 :selected selected)
|
|
230 (when selected (setq selected nil))))
|
428
|
231 buffers)))
|
|
232
|
444
|
233 ;;; #### SJT would like this function to have a sort function list. I
|
|
234 ;;; don't see how this could work given that sorting is not
|
|
235 ;;; cumulative --andyp.
|
442
|
236 (defun buffers-tab-items (&optional in-deletion frame force-selection)
|
444
|
237 "Return a list of tab instantiators based on the current buffers list.
|
|
238 This function is used as the tab filter for the top-level buffers
|
|
239 \"Buffers\" tab. It dynamically creates a list of tab instantiators
|
|
240 to use as the contents of the tab. The contents and order of the list
|
|
241 is controlled by `buffers-tab-filter-functions' which by default
|
|
242 groups buffers according to major mode and removes invisible buffers.
|
|
243 You can control how many buffers will be shown by setting
|
|
244 `buffers-tab-max-size'. You can control the text of the tab items by
|
|
245 redefining the function `format-buffers-menu-line'."
|
430
|
246 (save-match-data
|
444
|
247 ;; NB it is too late if we run the omit function as part of the
|
|
248 ;; filter functions because we need to know which buffer is the
|
|
249 ;; context buffer before they get run.
|
|
250 (let* ((buffers (delete-if
|
|
251 buffers-tab-omit-function (buffer-list frame)))
|
430
|
252 (first-buf (car buffers)))
|
442
|
253 ;; maybe force the selected window
|
|
254 (when (and force-selection
|
|
255 (not in-deletion)
|
|
256 (not (eq first-buf (window-buffer (selected-window frame)))))
|
|
257 (setq buffers (cons (window-buffer (selected-window frame))
|
|
258 (delq first-buf buffers))))
|
430
|
259 ;; if we're in deletion ignore the current buffer
|
|
260 (when in-deletion
|
|
261 (setq buffers (delq (current-buffer) buffers))
|
|
262 (setq first-buf (car buffers)))
|
444
|
263 ;; filter buffers
|
|
264 (when buffers-tab-filter-functions
|
|
265 (setq buffers
|
|
266 (delete-if
|
|
267 #'null
|
|
268 (mapcar #'(lambda (buf)
|
|
269 (let ((tmp-buf buf))
|
|
270 (mapc #'(lambda (fun)
|
|
271 (unless (funcall fun buf first-buf)
|
|
272 (setq tmp-buf nil)))
|
|
273 buffers-tab-filter-functions)
|
|
274 tmp-buf))
|
|
275 buffers))))
|
442
|
276 ;; maybe shorten list of buffers
|
430
|
277 (and (integerp buffers-tab-max-size)
|
|
278 (> buffers-tab-max-size 1)
|
|
279 (> (length buffers) buffers-tab-max-size)
|
452
|
280 (setcdr (nthcdr (1- buffers-tab-max-size) buffers) nil))
|
442
|
281 ;; sort buffers in group (default is most-recently-selected)
|
|
282 (when buffers-tab-sort-function
|
|
283 (setq buffers (funcall buffers-tab-sort-function buffers)))
|
|
284 ;; convert list of buffers to list of structures used by tab widget
|
430
|
285 (setq buffers (build-buffers-tab-internal buffers))
|
|
286 buffers)))
|
428
|
287
|
|
288 (defun add-tab-to-gutter ()
|
|
289 "Put a tab control in the gutter area to hold the most recent buffers."
|
438
|
290 (setq gutter-buffers-tab-orientation (default-gutter-position))
|
444
|
291 (let* ((gutter-string (copy-sequence "\n"))
|
|
292 (gutter-buffers-tab-extent (make-extent 0 1 gutter-string)))
|
|
293 (set-extent-begin-glyph gutter-buffers-tab-extent
|
|
294 (setq gutter-buffers-tab
|
|
295 (make-glyph)))
|
442
|
296 ;; Nuke all existing tabs
|
|
297 (remove-gutter-element top-gutter 'buffers-tab)
|
|
298 (remove-gutter-element bottom-gutter 'buffers-tab)
|
|
299 (remove-gutter-element left-gutter 'buffers-tab)
|
|
300 (remove-gutter-element right-gutter 'buffers-tab)
|
|
301 ;; Put tabs into all devices that will be able to display them
|
|
302 (mapcar
|
|
303 #'(lambda (x)
|
|
304 (when (valid-image-instantiator-format-p 'tab-control x)
|
|
305 (cond ((eq gutter-buffers-tab-orientation 'top)
|
|
306 ;; This looks better than a 3d border
|
|
307 (set-specifier top-gutter-border-width 0 'global x)
|
|
308 (set-gutter-element top-gutter 'buffers-tab
|
|
309 gutter-string 'global x))
|
|
310 ((eq gutter-buffers-tab-orientation 'bottom)
|
|
311 (set-specifier bottom-gutter-border-width 0 'global x)
|
|
312 (set-gutter-element bottom-gutter 'buffers-tab
|
|
313 gutter-string 'global x))
|
|
314 ((eq gutter-buffers-tab-orientation 'left)
|
|
315 (set-specifier left-gutter-border-width 0 'global x)
|
|
316 (set-gutter-element left-gutter 'buffers-tab
|
444
|
317 gutter-string 'global x))
|
442
|
318 ((eq gutter-buffers-tab-orientation 'right)
|
|
319 (set-specifier right-gutter-border-width 0 'global x)
|
|
320 (set-gutter-element right-gutter 'buffers-tab
|
444
|
321 gutter-string 'global x))
|
442
|
322 )))
|
|
323 (console-type-list))))
|
|
324
|
|
325 (defun update-tab-in-gutter (frame &optional force-selection)
|
428
|
326 "Update the tab control in the gutter area."
|
442
|
327 ;; dedicated frames don't get tabs
|
446
|
328 (unless (or (window-dedicated-p (frame-selected-window frame))
|
|
329 (frame-property frame 'popup))
|
442
|
330 (when (specifier-instance default-gutter-visible-p frame)
|
|
331 (unless (and gutter-buffers-tab
|
438
|
332 (eq (default-gutter-position)
|
|
333 gutter-buffers-tab-orientation))
|
428
|
334 (add-tab-to-gutter))
|
442
|
335 (when (valid-image-instantiator-format-p 'tab-control frame)
|
446
|
336 (let ((items (buffers-tab-items nil frame force-selection)))
|
|
337 (when items
|
|
338 (set-glyph-image
|
|
339 gutter-buffers-tab
|
|
340 (vector 'tab-control :descriptor "Buffers" :face buffers-tab-face
|
|
341 :orientation gutter-buffers-tab-orientation
|
|
342 (if (or (eq gutter-buffers-tab-orientation 'top)
|
|
343 (eq gutter-buffers-tab-orientation 'bottom))
|
|
344 :pixel-width :pixel-height)
|
|
345 (if (or (eq gutter-buffers-tab-orientation 'top)
|
|
346 (eq gutter-buffers-tab-orientation 'bottom))
|
|
347 '(gutter-pixel-width) '(gutter-pixel-height))
|
|
348 :items items)
|
|
349 frame)
|
|
350 ;; set-glyph-image will not make the gutter dirty
|
|
351 (set-specifier-dirty-flag
|
|
352 (eval (intern (concat
|
|
353 (symbol-name gutter-buffers-tab-orientation)
|
|
354 "-gutter"))))))))))
|
428
|
355
|
442
|
356 ;; A myriad of different update hooks all doing slightly different things
|
444
|
357 (add-one-shot-hook
|
|
358 'after-init-hook
|
|
359 #'(lambda ()
|
|
360 ;; don't add the hooks if the user really doesn't want them
|
|
361 (when gutter-buffers-tab-enabled
|
|
362 (add-hook 'create-frame-hook
|
|
363 #'(lambda (frame)
|
|
364 (when gutter-buffers-tab (update-tab-in-gutter frame t))))
|
|
365 (add-hook 'buffer-list-changed-hook 'update-tab-in-gutter)
|
|
366 (add-hook 'default-gutter-position-changed-hook
|
|
367 #'(lambda ()
|
|
368 (when gutter-buffers-tab
|
|
369 (mapc #'update-tab-in-gutter (frame-list)))))
|
|
370 (add-hook 'gutter-element-visibility-changed-hook
|
|
371 #'(lambda (prop visible-p)
|
|
372 (when (and (eq prop 'buffers-tab) visible-p)
|
|
373 (mapc #'update-tab-in-gutter (frame-list)))))
|
|
374 (update-tab-in-gutter (selected-frame) t))))
|
|
375
|
428
|
376 ;;
|
|
377 ;; progress display
|
|
378 ;; ripped off from message display
|
|
379 ;;
|
442
|
380 (defcustom progress-feedback-use-echo-area nil
|
|
381 "*Whether progress gauge display should display in the echo area.
|
|
382 If NIL then progress gauges will be displayed with whatever native widgets
|
|
383 are available on the current console. If non-NIL then progress display will be
|
|
384 textual and displayed in the echo area."
|
|
385 :type 'boolean
|
|
386 :group 'gutter)
|
|
387
|
|
388 (defvar progress-glyph-height 24
|
|
389 "Height of the progress gauge glyph.")
|
|
390
|
|
391 (defvar progress-feedback-popup-period 0.5
|
|
392 "The time that the progress gauge should remain up after completion")
|
|
393
|
|
394 (defcustom progress-feedback-style 'large
|
|
395 "*Control the appearance of the progress gauge.
|
|
396 If 'large, the default, then the progress-feedback text is displayed
|
|
397 above the gauge itself. If 'small then the gauge and text are arranged
|
|
398 side-by-side."
|
|
399 :group 'gutter
|
|
400 :type '(choice (const :tag "large" large)
|
|
401 (const :tag "small" small)))
|
|
402
|
|
403 ;; private variables
|
|
404 (defvar progress-text-instantiator [string :data ""])
|
|
405 (defvar progress-layout-glyph (make-glyph))
|
|
406 (defvar progress-layout-instantiator nil)
|
|
407
|
|
408 (defvar progress-gauge-instantiator
|
|
409 [progress-gauge
|
|
410 :value 0
|
|
411 :pixel-height (eval progress-glyph-height)
|
|
412 :pixel-width 250
|
|
413 :descriptor "Progress"])
|
|
414
|
|
415 (defun set-progress-feedback-instantiator (&optional locale)
|
|
416 (cond
|
|
417 ((eq progress-feedback-style 'small)
|
|
418 (setq progress-glyph-height 16)
|
|
419 (setq progress-layout-instantiator
|
|
420 `[layout
|
|
421 :orientation horizontal
|
|
422 :margin-width 4
|
|
423 :items (,progress-gauge-instantiator
|
|
424 [button
|
|
425 :pixel-height (eval progress-glyph-height)
|
|
426 ;; 'quit is special and acts "asynchronously".
|
|
427 :descriptor "Stop" :callback 'quit]
|
|
428 ,progress-text-instantiator)])
|
|
429 (set-glyph-image progress-layout-glyph progress-layout-instantiator locale))
|
|
430 (t
|
|
431 (setq progress-glyph-height 24)
|
|
432 (setq progress-layout-instantiator
|
|
433 `[layout
|
|
434 :orientation vertical :justify left
|
|
435 :margin-width 4
|
|
436 :items (,progress-text-instantiator
|
|
437 [layout
|
|
438 :orientation horizontal
|
|
439 :items (,progress-gauge-instantiator
|
|
440 [button
|
|
441 :pixel-height (eval progress-glyph-height)
|
|
442 :descriptor " Stop "
|
|
443 ;; 'quit is special and acts "asynchronously".
|
|
444 :callback 'quit])])])
|
|
445 (set-glyph-image progress-layout-glyph progress-layout-instantiator locale))))
|
|
446
|
428
|
447 (defvar progress-stack nil
|
|
448 "An alist of label/string pairs representing active progress gauges.
|
|
449 The first element in the list is currently displayed in the gutter area.
|
442
|
450 Do not modify this directly--use the `progress-feedback' or
|
|
451 `display-progress-feedback'/`clear-progress-feedback' functions.")
|
428
|
452
|
|
453 (defvar progress-abort-glyph
|
|
454 (make-glyph
|
442
|
455 `[layout :orientation vertical :justify left
|
|
456 :items (,progress-text-instantiator
|
|
457 [layout
|
|
458 :margin-width 4
|
|
459 :pixel-height progress-glyph-height
|
|
460 :orientation horizontal])]))
|
428
|
461
|
442
|
462 (defun progress-feedback-displayed-p (&optional return-string frame)
|
428
|
463 "Return a non-nil value if a progress gauge is presently displayed in the
|
|
464 gutter area. If optional argument RETURN-STRING is non-nil,
|
|
465 return a string containing the message, otherwise just return t."
|
|
466 (let ((buffer (get-buffer-create " *Gutter Area*")))
|
|
467 (and (< (point-min buffer) (point-max buffer))
|
|
468 (if return-string
|
|
469 (buffer-substring nil nil buffer)
|
|
470 t))))
|
|
471
|
|
472 ;;; Returns the string which remains in the echo area, or nil if none.
|
|
473 ;;; If label is nil, the whole message stack is cleared.
|
442
|
474 (defun clear-progress-feedback (&optional label frame no-restore)
|
|
475 "Remove any progress gauge with LABEL from the progress gauge-stack,
|
428
|
476 erasing it from the gutter area if it's currently displayed there.
|
|
477 If a message remains at the head of the progress-stack and NO-RESTORE
|
|
478 is nil, it will be displayed. The string which remains in the gutter
|
|
479 area will be returned, or nil if the progress-stack is now empty.
|
|
480 If LABEL is nil, the entire progress-stack is cleared.
|
|
481
|
|
482 Unless you need the return value or you need to specify a label,
|
|
483 you should just use (progress nil)."
|
442
|
484 (if (or (not (valid-image-instantiator-format-p 'progress-gauge frame))
|
|
485 progress-feedback-use-echo-area)
|
|
486 (clear-message label frame nil no-restore)
|
|
487 (or frame (setq frame (selected-frame)))
|
|
488 (remove-progress-feedback label frame)
|
|
489 (let ((inhibit-read-only t)
|
|
490 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
|
|
491 (erase-buffer (get-buffer-create " *Gutter Area*")))
|
|
492 (if no-restore
|
|
493 nil ; just preparing to put another msg up
|
|
494 (if progress-stack
|
|
495 (let ((oldmsg (cdr (car progress-stack))))
|
|
496 (raw-append-progress-feedback oldmsg nil frame)
|
|
497 oldmsg)
|
|
498 ;; nothing to display so get rid of the gauge
|
|
499 (set-specifier bottom-gutter-border-width 0 frame)
|
|
500 (set-gutter-element-visible-p bottom-gutter-visible-p
|
|
501 'progress nil frame)))))
|
428
|
502
|
442
|
503 (defun progress-feedback-clear-when-idle (&optional label)
|
|
504 (add-one-shot-hook 'pre-idle-hook
|
|
505 `(lambda ()
|
|
506 (clear-progress-feedback ',label))))
|
|
507
|
|
508 (defun remove-progress-feedback (&optional label frame)
|
428
|
509 ;; If label is nil, we want to remove all matching progress gauges.
|
|
510 (while (and progress-stack
|
|
511 (or (null label) ; null label means clear whole stack
|
|
512 (eq label (car (car progress-stack)))))
|
|
513 (setq progress-stack (cdr progress-stack)))
|
|
514 (let ((s progress-stack))
|
|
515 (while (cdr s)
|
|
516 (let ((msg (car (cdr s))))
|
|
517 (if (eq label (car msg))
|
|
518 (progn
|
|
519 (setcdr s (cdr (cdr s))))
|
|
520 (setq s (cdr s)))))))
|
|
521
|
442
|
522 (defun progress-feedback-dispatch-non-command-events ()
|
|
523 ;; don't allow errors to hose things
|
|
524 (condition-case t
|
|
525 ;; (sit-for 0) is too agressive and cause more display than we
|
|
526 ;; want.
|
|
527 (dispatch-non-command-events)
|
|
528 nil))
|
|
529
|
|
530 (defun append-progress-feedback (label message &optional value frame)
|
428
|
531 (or frame (setq frame (selected-frame)))
|
|
532 ;; Add a new entry to the message-stack, or modify an existing one
|
|
533 (let* ((top (car progress-stack))
|
|
534 (tmsg (cdr top)))
|
|
535 (if (eq label (car top))
|
|
536 (progn
|
|
537 (setcdr top message)
|
442
|
538 (if (equal tmsg message)
|
|
539 (progn
|
|
540 (set-instantiator-property progress-gauge-instantiator :value value)
|
|
541 (set-progress-feedback-instantiator (frame-selected-window frame)))
|
|
542 (raw-append-progress-feedback message value frame))
|
|
543 (redisplay-gutter-area))
|
428
|
544 (push (cons label message) progress-stack)
|
442
|
545 (raw-append-progress-feedback message value frame))
|
|
546 (progress-feedback-dispatch-non-command-events)
|
|
547 ;; either get command events or sit waiting for them
|
|
548 (when (eq value 100)
|
|
549 ; (sit-for progress-feedback-popup-period nil)
|
|
550 (clear-progress-feedback label))))
|
428
|
551
|
442
|
552 (defun abort-progress-feedback (label message &optional frame)
|
|
553 (if (or (not (valid-image-instantiator-format-p 'progress-gauge frame))
|
|
554 progress-feedback-use-echo-area)
|
|
555 (display-message label (concat message "aborted.") frame)
|
|
556 (or frame (setq frame (selected-frame)))
|
|
557 ;; Add a new entry to the message-stack, or modify an existing one
|
|
558 (let* ((top (car progress-stack))
|
|
559 (inhibit-read-only t)
|
|
560 (zmacs-region-stays zmacs-region-stays))
|
|
561 (if (eq label (car top))
|
|
562 (setcdr top message)
|
|
563 (push (cons label message) progress-stack))
|
|
564 (unless (equal message "")
|
|
565 (insert-string message (get-buffer-create " *Gutter Area*"))
|
|
566 (let* ((gutter-string (copy-sequence "\n"))
|
|
567 (ext (make-extent 0 1 gutter-string)))
|
|
568 ;; do some funky display here.
|
|
569 (set-extent-begin-glyph ext progress-abort-glyph)
|
428
|
570 ;; fixup the gutter specifiers
|
442
|
571 (set-gutter-element bottom-gutter 'progress gutter-string frame)
|
428
|
572 (set-specifier bottom-gutter-border-width 2 frame)
|
442
|
573 (set-instantiator-property progress-text-instantiator :datat message)
|
|
574 (set-progress-feedback-instantiator (frame-selected-window frame))
|
428
|
575 (set-specifier bottom-gutter-height 'autodetect frame)
|
442
|
576 (set-gutter-element-visible-p bottom-gutter-visible-p
|
|
577 'progress t frame)
|
428
|
578 ;; we have to do this so redisplay is up-to-date and so
|
|
579 ;; redisplay-gutter-area performs optimally.
|
|
580 (redisplay-gutter-area)
|
442
|
581 (sit-for progress-feedback-popup-period nil)
|
|
582 (clear-progress-feedback label frame)
|
|
583 (set-extent-begin-glyph ext progress-layout-glyph)
|
|
584 (set-gutter-element bottom-gutter 'progress gutter-string frame)
|
428
|
585 )))))
|
|
586
|
442
|
587 (defun raw-append-progress-feedback (message &optional value frame)
|
428
|
588 (unless (equal message "")
|
442
|
589 (let* ((inhibit-read-only t)
|
428
|
590 (zmacs-region-stays zmacs-region-stays)
|
442
|
591 (val (or value 0))
|
|
592 (gutter-string (copy-sequence "\n"))
|
|
593 (ext (make-extent 0 1 gutter-string)))
|
428
|
594 (insert-string message (get-buffer-create " *Gutter Area*"))
|
442
|
595 ;; do some funky display here.
|
|
596 (set-extent-begin-glyph ext progress-layout-glyph)
|
|
597 ;; fixup the gutter specifiers
|
|
598 (set-gutter-element bottom-gutter 'progress gutter-string frame)
|
|
599 (set-specifier bottom-gutter-border-width 2 frame)
|
|
600 (set-instantiator-property progress-gauge-instantiator :value val)
|
|
601 (set-progress-feedback-instantiator (frame-selected-window frame))
|
|
602
|
|
603 (set-instantiator-property progress-text-instantiator :data message)
|
|
604 (set-progress-feedback-instantiator (frame-selected-window frame))
|
|
605 (if (and (eq (specifier-instance bottom-gutter-height frame)
|
|
606 'autodetect)
|
|
607 (gutter-element-visible-p bottom-gutter-visible-p
|
|
608 'progress frame))
|
|
609 ;; if the gauge is already visible then just draw the gutter
|
|
610 ;; checking for user events
|
428
|
611 (progn
|
442
|
612 (redisplay-gutter-area)
|
|
613 (progress-feedback-dispatch-non-command-events))
|
|
614 ;; otherwise make the gutter visible and redraw the frame
|
|
615 (set-specifier bottom-gutter-height 'autodetect frame)
|
|
616 (set-gutter-element-visible-p bottom-gutter-visible-p
|
|
617 'progress t frame)
|
|
618 ;; we have to do this so redisplay is up-to-date and so
|
|
619 ;; redisplay-gutter-area performs optimally. This may also
|
|
620 ;; make sure the frame geometry looks ok.
|
|
621 (progress-feedback-dispatch-non-command-events)
|
|
622 (redisplay-frame frame)
|
|
623 ))))
|
428
|
624
|
442
|
625 (defun display-progress-feedback (label message &optional value frame)
|
428
|
626 "Display a progress gauge and message in the bottom gutter area.
|
|
627 First argument LABEL is an identifier for this message. MESSAGE is
|
442
|
628 the string to display. Use `clear-progress-feedback' to remove a labelled
|
428
|
629 message."
|
442
|
630 (cond ((eq value 'abort)
|
|
631 (abort-progress-feedback label message frame))
|
|
632 ((or (not (valid-image-instantiator-format-p 'progress-gauge frame))
|
|
633 progress-feedback-use-echo-area)
|
|
634 (display-message label
|
|
635 (concat message (if (eq value 100) "done."
|
|
636 (make-string (/ value 5) ?.)))
|
|
637 frame))
|
|
638 (t
|
|
639 (append-progress-feedback label message value frame))))
|
428
|
640
|
442
|
641 (defun current-progress-feedback (&optional frame)
|
428
|
642 "Return the current progress gauge in the gutter area, or nil.
|
|
643 The FRAME argument is currently unused."
|
|
644 (cdr (car progress-stack)))
|
|
645
|
|
646 ;;; may eventually be frame-dependent
|
442
|
647 (defun current-progress-feedback-label (&optional frame)
|
428
|
648 (car (car progress-stack)))
|
|
649
|
442
|
650 (defun progress-feedback (fmt &optional value &rest args)
|
428
|
651 "Print a progress gauge and message in the bottom gutter area of the frame.
|
|
652 The arguments are the same as to `format'.
|
|
653
|
|
654 If the only argument is nil, clear any existing progress gauge."
|
442
|
655 (save-excursion
|
|
656 (if (and (null fmt) (null args))
|
|
657 (prog1 nil
|
|
658 (clear-progress-feedback nil))
|
|
659 (let ((str (apply 'format fmt args)))
|
|
660 (display-progress-feedback 'progress str value)
|
|
661 str))))
|
428
|
662
|
442
|
663 (defun progress-feedback-with-label (label fmt &optional value &rest args)
|
428
|
664 "Print a progress gauge and message in the bottom gutter area of the frame.
|
|
665 First argument LABEL is an identifier for this progress gauge. The rest of the
|
|
666 arguments are the same as to `format'."
|
442
|
667 ;; #### sometimes the buffer gets changed temporarily. I don't know
|
|
668 ;; why this is, so protect against it.
|
|
669 (save-excursion
|
|
670 (if (and (null fmt) (null args))
|
|
671 (prog1 nil
|
|
672 (clear-progress-feedback label nil))
|
|
673 (let ((str (apply 'format fmt args)))
|
|
674 (display-progress-feedback label str value)
|
|
675 str))))
|
428
|
676
|
|
677 (provide 'gutter-items)
|
|
678 ;;; gutter-items.el ends here.
|