annotate lisp/gutter-items.el @ 442:abe6d1db359e r21-2-36

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