comparison lisp/gutter-items.el @ 903:4a27df428c73

[xemacs-hg @ 2002-07-06 05:48:14 by andyp] sync with 21.4
author andyp
date Sat, 06 Jul 2002 05:48:22 +0000
parents 42375619fa45
children 3508e2f71814
comparison
equal deleted inserted replaced
902:2fd2239ea63a 903:4a27df428c73
46 :group 'buffers-tab 46 :group 'buffers-tab
47 :type 'boolean) 47 :type 'boolean)
48 48
49 (defvar gutter-buffers-tab-orientation 'top 49 (defvar gutter-buffers-tab-orientation 'top
50 "Where the buffers tab currently is. Do not set this.") 50 "Where the buffers tab currently is. Do not set this.")
51
52 (defcustom buffers-tab-max-size 6
53 "*Maximum number of entries which may appear on the \"Buffers\" tab.
54 If this is 10, then only the ten most-recently-selected buffers will be
55 shown. If this is nil, then all buffers will be shown. Setting this to
56 a large number or nil will slow down tab responsiveness."
57 :type '(choice (const :tag "Show all" nil)
58 (integer 6))
59 :group 'buffers-tab)
60
61 (defcustom buffers-tab-switch-to-buffer-function 'buffers-tab-switch-to-buffer
62 "*The function to call to select a buffer from the buffers tab.
63 `switch-to-buffer' is a good choice, as is `pop-to-buffer'."
64 :type '(radio (function-item switch-to-buffer)
65 (function-item pop-to-buffer)
66 (function :tag "Other"))
67 :group 'buffers-tab)
68
69 (defcustom buffers-tab-omit-function 'buffers-menu-omit-invisible-buffers
70 "*If non-nil, a function specifying the buffers to omit from the buffers tab.
71 This is passed a buffer and should return non-nil if the buffer should be
72 omitted. The default value `buffers-menu-omit-invisible-buffers' omits
73 buffers that are normally considered \"invisible\" (those whose name
74 begins with a space)."
75 :type '(choice (const :tag "None" nil)
76 function)
77 :group 'buffers-tab)
78
79 (defvar buffers-tab-selection-function 'select-buffers-tab-buffers-by-mode
80 "*If non-nil, a function specifying the buffers to select in the
81 buffers tab. This is passed two buffers and should return non-nil if
82 the first buffer should be selected. The default value
83 `select-buffers-tab-buffers-by-mode' groups buffers by major mode and
84 by `buffers-tab-grouping-regexp'.")
85
86 (make-obsolete-variable buffers-tab-selection-function
87 "Set `buffers-tab-filter-functions' instead.")
88
89 (defcustom buffers-tab-filter-functions (list 'select-buffers-tab-buffers-by-mode)
90 "*If non-nil, a list of functions specifying the buffers to include
91 in the buffers tab, depending on the context.
92 Each function in the list is passed two buffers, the buffer to
93 potentially select and the context buffer, and should return non-nil
94 if the first buffer should be selected. The default value groups
95 buffers by major mode and by `buffers-tab-grouping-regexp'."
96
97 :type '(repeat function)
98 :group 'buffers-tab)
99
100 (defcustom buffers-tab-sort-function nil
101 "*If non-nil, a function specifying the buffers to select from the
102 buffers tab. This is passed the buffer list and returns the list in the
103 order desired for the tab widget. The default value `nil' leaves the
104 list in `buffer-list' order (usual most-recently-selected-first)."
105
106 :type '(choice (const :tag "None" nil)
107 function)
108 :group 'buffers-tab)
109
110 (make-face 'buffers-tab "Face for displaying the buffers tab.")
111 (set-face-parent 'buffers-tab 'modeline)
112
113 (defcustom buffers-tab-face 'buffers-tab
114 "*Face to use for displaying the buffers tab."
115 :type 'face
116 :group 'buffers-tab)
117
118 (defcustom buffers-tab-grouping-regexp
119 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
120 "^\\(emacs-lisp-\\|lisp-\\)")
121 "*If non-nil, a list of regular expressions for buffer grouping.
122 Each regular expression is applied to the current major-mode symbol
123 name and mode-name, if it matches then any other buffers that match
124 the same regular expression be added to the current group."
125 :type '(choice (const :tag "None" nil)
126 sexp)
127 :group 'buffers-tab)
128
129 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-tab-line
130 "*The function to call to return a string to represent a buffer in the
131 buffers tab. The function is passed a buffer and should return a
132 string. The default value `format-buffers-tab-line' just returns the
133 name of the buffer, optionally truncated to
134 `buffers-tab-max-buffer-line-length'. Also check out
135 `slow-format-buffers-menu-line' which returns a whole bunch of info
136 about a buffer."
137 :type 'function
138 :group 'buffers-tab)
139
140 (defvar buffers-tab-default-buffer-line-length
141 (make-specifier-and-init 'generic '((global ((default) . 25))) t)
142 "*Maximum length of text which may appear in a \"Buffers\" tab.
143 This is a specifier, use set-specifier to modify it.")
144
145 (defcustom buffers-tab-max-buffer-line-length
146 (specifier-instance buffers-tab-default-buffer-line-length)
147 "*Maximum length of text which may appear in a \"Buffers\" tab.
148 Buffer names over this length will be truncated with elipses.
149 If this is 0, then the full buffer name will be shown."
150 :type '(choice (const :tag "Show all" 0)
151 (integer 25))
152 :group 'buffers-tab
153 :set #'(lambda (var val)
154 (set-specifier buffers-tab-default-buffer-line-length val)
155 (setq buffers-tab-max-buffer-line-length val)))
156
157 (defun buffers-tab-switch-to-buffer (buffer)
158 "For use as a value for `buffers-tab-switch-to-buffer-function'."
159 (unless (eq (window-buffer) buffer)
160 ;; this used to add the norecord flag to both calls below.
161 ;; this is bogus because it is a pervasive assumption in XEmacs
162 ;; that the current buffer is at the front of the buffers list.
163 ;; for example, select an item and then do M-C-l
164 ;; (switch-to-other-buffer). Things get way confused.
165 (if (> (length (windows-of-buffer buffer)) 0)
166 (select-window (car (windows-of-buffer buffer)))
167 (switch-to-buffer buffer))))
168
169 (defun select-buffers-tab-buffers-by-mode (buffer-to-select buf1)
170 "For use as a value of `buffers-tab-selection-function'.
171 This selects buffers by major mode `buffers-tab-grouping-regexp'."
172 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
173 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
174 buffer-to-select)))
175 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
176 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select)))
177 (cond ((or (eq mode1 mode2)
178 (eq modenm1 modenm2)
179 (and (string-match "^[^-]+-" mode1)
180 (string-match
181 (concat "^" (regexp-quote
182 (substring mode1 0 (match-end 0))))
183 mode2))
184 (and buffers-tab-grouping-regexp
185 (find-if #'(lambda (x)
186 (or
187 (and (string-match x mode1)
188 (string-match x mode2))
189 (and (string-match x modenm1)
190 (string-match x modenm2))))
191 buffers-tab-grouping-regexp)))
192 t)
193 (t nil))))
194
195 (defun format-buffers-tab-line (buffer)
196 "For use as a value of `buffers-tab-format-buffer-line-function'.
197 This just returns the buffer's name, optionally truncated."
198 (let ((len (specifier-instance buffers-tab-default-buffer-line-length)))
199 (if (and (> len 0)
200 (> (length (buffer-name buffer)) len))
201 (if (string-match ".*<.>$" (buffer-name buffer))
202 (concat (substring (buffer-name buffer)
203 0 (- len 6)) "..."
204 (substring (buffer-name buffer) -3))
205 (concat (substring (buffer-name buffer)
206 0 (- len 3)) "..."))
207 (buffer-name buffer))))
208
209 (defsubst build-buffers-tab-internal (buffers)
210 (let ((selected t))
211 (mapcar
212 #'(lambda (buffer)
213 (prog1
214 (vector
215 (funcall buffers-tab-format-buffer-line-function
216 buffer)
217 (list buffers-tab-switch-to-buffer-function
218 (buffer-name buffer))
219 :selected selected)
220 (when selected (setq selected nil))))
221 buffers)))
222
223 ;;; #### SJT would like this function to have a sort function list. I
224 ;;; don't see how this could work given that sorting is not
225 ;;; cumulative --andyp.
226 (defun buffers-tab-items (&optional in-deletion frame force-selection)
227 "Return a list of tab instantiators based on the current buffers list.
228 This function is used as the tab filter for the top-level buffers
229 \"Buffers\" tab. It dynamically creates a list of tab instantiators
230 to use as the contents of the tab. The contents and order of the list
231 is controlled by `buffers-tab-filter-functions' which by default
232 groups buffers according to major mode and removes invisible buffers.
233 You can control how many buffers will be shown by setting
234 `buffers-tab-max-size'. You can control the text of the tab items by
235 redefining the function `format-buffers-menu-line'."
236 (save-match-data
237 ;; NB it is too late if we run the omit function as part of the
238 ;; filter functions because we need to know which buffer is the
239 ;; context buffer before they get run.
240 (let* ((buffers (delete-if
241 buffers-tab-omit-function (buffer-list frame)))
242 (first-buf (car buffers)))
243 ;; maybe force the selected window
244 (when (and force-selection
245 (not in-deletion)
246 (not (eq first-buf (window-buffer (selected-window frame)))))
247 (setq buffers (cons (window-buffer (selected-window frame))
248 (delq first-buf buffers))))
249 ;; if we're in deletion ignore the current buffer
250 (when in-deletion
251 (setq buffers (delq (current-buffer) buffers))
252 (setq first-buf (car buffers)))
253 ;; filter buffers
254 (when buffers-tab-filter-functions
255 (setq buffers
256 (delete-if
257 #'null
258 (mapcar #'(lambda (buf)
259 (let ((tmp-buf buf))
260 (mapc #'(lambda (fun)
261 (unless (funcall fun buf first-buf)
262 (setq tmp-buf nil)))
263 buffers-tab-filter-functions)
264 tmp-buf))
265 buffers))))
266 ;; maybe shorten list of buffers
267 (and (integerp buffers-tab-max-size)
268 (> buffers-tab-max-size 1)
269 (> (length buffers) buffers-tab-max-size)
270 (setcdr (nthcdr (1- buffers-tab-max-size) buffers) nil))
271 ;; sort buffers in group (default is most-recently-selected)
272 (when buffers-tab-sort-function
273 (setq buffers (funcall buffers-tab-sort-function buffers)))
274 ;; convert list of buffers to list of structures used by tab widget
275 (setq buffers (build-buffers-tab-internal buffers))
276 buffers)))
51 277
52 (defun add-tab-to-gutter () 278 (defun add-tab-to-gutter ()
53 "Put a tab control in the gutter area to hold the most recent buffers." 279 "Put a tab control in the gutter area to hold the most recent buffers."
54 (setq gutter-buffers-tab-orientation (default-gutter-position)) 280 (setq gutter-buffers-tab-orientation (default-gutter-position))
55 (let* ((gutter-string (copy-sequence "\n")) 281 (let* ((gutter-string (copy-sequence "\n"))