annotate lisp/gutter-items.el @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 95016f13131a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
1 ;;; gutter-items.el --- Gutter content for XEmacs.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
2
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
4 ;; Copyright (C) 1999 Andy Piper.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
5
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
7 ;; Keywords: frames, extensions, internal, dumped
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
8
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
10
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
14 ;; any later version.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
15
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
19 ;; General Public License for more details.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
20
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
22 ;; along with Xmacs; see the file COPYING. If not, write to the
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
25
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
26 ;; Some of this is taken from the buffer-menu stuff in menubar-items.el
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
27 ;; and the custom specs in toolbar.el.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
28
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
29 (defgroup gutter nil
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
30 "Input from the gutters."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
31 :group 'environment)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
32
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
33 (defcustom gutter-visible-p
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
34 (specifier-instance default-gutter-visible-p)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
35 "Whether the default gutter is globally visible. This option can be
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
36 customized through the options menu."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
37 :group 'display
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
38 :type 'boolean
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
39 :set #'(lambda (var val)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
40 (set-specifier default-gutter-visible-p val)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
41 (setq gutter-visible-p val)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
42
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
43 (defcustom default-gutter-position
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
44 (default-gutter-position)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
45 "The location of the default gutter. It can be 'top, 'bottom, 'left or
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
46 'right. This option can be customized through the options menu."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
47 :group 'display
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
48 :type '(choice (const :tag "top" 'top)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
49 (const :tag "bottom" 'bottom)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
50 (const :tag "left" 'left)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
51 (const :tag "right" 'right))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
52 :set #'(lambda (var val)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
53 (set-default-gutter-position val)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
54 (setq default-gutter-position val)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
55
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
56 ;;; The Buffers tab
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
57
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
58 (defgroup buffers-tab nil
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
59 "Customization of `Buffers' tab."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
60 :group 'gutter)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
61
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
62 (defvar gutter-buffers-tab nil
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
63 "A tab widget in the gutter for displaying buffers.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
64 Do not set this. Use `glyph-image-instance' and
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
65 `set-image-instance-property' to change the properties of the tab.")
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
66
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
67 (defcustom buffers-tab-max-size 6
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
68 "*Maximum number of entries which may appear on the \"Buffers\" tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
69 If this is 10, then only the ten most-recently-selected buffers will be
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
70 shown. If this is nil, then all buffers will be shown. Setting this to
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
71 a large number or nil will slow down tab responsiveness."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
72 :type '(choice (const :tag "Show all" nil)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
73 (integer 6))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
74 :group 'buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
75
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
76 (defcustom buffers-tab-switch-to-buffer-function 'buffers-tab-switch-to-buffer
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
77 "*The function to call to select a buffer from the buffers tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
78 `switch-to-buffer' is a good choice, as is `pop-to-buffer'."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
79 :type '(radio (function-item switch-to-buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
80 (function-item pop-to-buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
81 (function :tag "Other"))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
82 :group 'buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
83
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
84 (defcustom buffers-tab-omit-function 'buffers-menu-omit-invisible-buffers
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
85 "*If non-nil, a function specifying the buffers to omit from the buffers tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
86 This is passed a buffer and should return non-nil if the buffer should be
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
87 omitted. The default value `buffers-tab-omit-invisible-buffers' omits
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
88 buffers that are normally considered \"invisible\" (those whose name
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
89 begins with a space)."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
90 :type '(choice (const :tag "None" nil)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
91 function)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
92 :group 'buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
93
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
94 (defcustom buffers-tab-selection-function 'select-buffers-tab-buffers-by-mode
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
95 "*If non-nil, a function specifying the buffers to select from the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
96 buffers tab. This is passed two buffers and should return non-nil if
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
97 the second buffer should be selected. The default value
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
98 `select-buffers-tab-buffers-by-mode' groups buffers by major mode and
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
99 by `buffers-tab-grouping-regexp'."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
100
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
101 :type '(choice (const :tag "None" nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
102 function)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
103 :group 'buffers-tab)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
104
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
105 (defcustom buffers-tab-face 'default
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
106 "*Face to use for displaying the buffers tab."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
107 :type 'face
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
108 :group 'buffers-tab)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
109
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
110 (defcustom buffers-tab-grouping-regexp
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
111 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
112 "^\\(emacs-lisp-\\|lisp-\\)")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
113 "*If non-nil, a list of regular expressions for buffer grouping.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
114 Each regular expression is applied to the current major-mode symbol
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
115 name and mode-name, if it matches then any other buffers that match
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
116 the same regular expression be added to the current group."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
117 :type '(choice (const :tag "None" nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
118 sexp)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
119 :group 'buffers-tab)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
120
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
121 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-tab-line
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
122 "*The function to call to return a string to represent a buffer in the
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
123 buffers tab. The function is passed a buffer and should return a
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
124 string. The default value `format-buffers-tab-line' just returns the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
125 name of the buffer, optionally truncated to
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
126 `buffers-tab-max-buffer-line-length'. Also check out
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
127 `slow-format-buffers-menu-line' which returns a whole bunch of info
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
128 about a buffer."
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
129 :type 'function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
130 :group 'buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
131
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
132 (defvar buffers-tab-default-buffer-line-length
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
133 (make-specifier-and-init 'generic '((global ((default) . 25))) t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
134 "*Maximum length of text which may appear in a \"Buffers\" tab.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
135 This is a specifier, use set-specifier to modify it.")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
136
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
137 (defcustom buffers-tab-max-buffer-line-length
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
138 (specifier-instance buffers-tab-default-buffer-line-length)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
139 "*Maximum length of text which may appear in a \"Buffers\" tab.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
140 Buffer names over this length will be truncated with elipses.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
141 If this is 0, then the full buffer name will be shown."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
142 :type '(choice (const :tag "Show all" 0)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
143 (integer 25))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
144 :group 'buffers-tab
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
145 :set #'(lambda (var val)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
146 (set-specifier buffers-tab-default-buffer-line-length val)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
147 (setq buffers-tab-max-buffer-line-length val)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
148
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
149 (defun buffers-tab-switch-to-buffer (buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
150 "For use as a value for `buffers-tab-switch-to-buffer-function'."
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
151 (unless (eq (window-buffer) buffer)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
152 (if (> (length (windows-of-buffer buffer)) 0)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
153 (select-window (car (windows-of-buffer buffer)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
154 (switch-to-buffer buffer t))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
155
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
156 (defun select-buffers-tab-buffers-by-mode (buf1 buf2)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
157 "For use as a value of `buffers-tab-selection-function'.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
158 This selects buffers by major mode `buffers-tab-grouping-regexp'."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
159 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
160 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode buf2)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
161 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
162 (modenm2 (symbol-value-in-buffer 'mode-name buf2)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
163 (cond ((or (eq mode1 mode2)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
164 (eq modenm1 modenm2)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
165 (and (string-match "^[^-]+-" mode1)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
166 (string-match
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
167 (concat "^" (regexp-quote
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
168 (substring mode1 0 (match-end 0))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
169 mode2))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
170 (and buffers-tab-grouping-regexp
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
171 (find-if #'(lambda (x)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
172 (or
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
173 (and (string-match x mode1)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
174 (string-match x mode2))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
175 (and (string-match x modenm1)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
176 (string-match x modenm2))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
177 buffers-tab-grouping-regexp)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
178 t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
179 (t nil))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
180
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
181 (defun format-buffers-tab-line (buffer)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
182 "For use as a value of `buffers-tab-format-buffer-line-function'.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
183 This just returns the buffer's name, optionally truncated."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
184 (let ((len (specifier-instance buffers-tab-default-buffer-line-length)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
185 (if (and (> len 0)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
186 (> (length (buffer-name buffer)) len))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
187 (concat (substring (buffer-name buffer)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
188 0 (- len 3)) "...")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
189 (buffer-name buffer))))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
190
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
191 (defsubst build-buffers-tab-internal (buffers)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
192 (let (line)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
193 (mapcar
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
194 #'(lambda (buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
195 (setq line (funcall buffers-tab-format-buffer-line-function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
196 buffer))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
197 (vector line (list buffers-tab-switch-to-buffer-function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
198 (buffer-name buffer))))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
199 buffers)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
200
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
201 (defun buffers-tab-items (&optional in-deletion frame)
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
202 "This is the tab filter for the top-level buffers \"Buffers\" tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
203 It dynamically creates a list of buffers to use as the contents of the tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
204 Only the most-recently-used few buffers will be listed on the tab, for
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
205 efficiency reasons. You can control how many buffers will be shown by
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
206 setting `buffers-tab-max-size'. You can control the text of the tab
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
207 items by redefining the function `format-buffers-menu-line'."
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
208 (let* ((buffers (delete-if buffers-tab-omit-function (buffer-list frame)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
209 (first-buf (car buffers)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
210 ;; if we're in deletion ignore the current buffer
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
211 (when in-deletion
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
212 (setq buffers (delq (current-buffer) buffers))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
213 (setq first-buf (car buffers)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
214 ;; group buffers by mode
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
215 (when buffers-tab-selection-function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
216 (delete-if-not #'(lambda (buf)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
217 (funcall buffers-tab-selection-function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
218 first-buf buf)) buffers))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
219 (and (integerp buffers-tab-max-size)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
220 (> buffers-tab-max-size 1)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
221 (> (length buffers) buffers-tab-max-size)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
222 ;; shorten list of buffers
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
223 (setcdr (nthcdr buffers-tab-max-size buffers) nil))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
224 (setq buffers (build-buffers-tab-internal buffers))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
225 buffers))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
226
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
227 (defun add-tab-to-gutter ()
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
228 "Put a tab control in the gutter area to hold the most recent buffers."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
229 (let ((gutter-string ""))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
230 (set-extent-begin-glyph
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
231 (make-extent 0 0 gutter-string)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
232 (setq gutter-buffers-tab
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
233 (make-glyph
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
234 (vector 'tab-control :descriptor "Buffers" :face buffers-tab-face
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
235 :properties (list :items (buffers-tab-items))))))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
236 ;; This looks better than a 3d border
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
237 (mapcar '(lambda (x)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
238 (when (valid-image-instantiator-format-p 'tab-control x)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
239 (set-specifier default-gutter-border-width 0 'global x)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
240 (set-specifier default-gutter gutter-string 'global x)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
241 (console-type-list))))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
242
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
243 (defun update-tab-in-gutter (&optional frame-or-buffer)
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
244 "Update the tab control in the gutter area."
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
245 (let ((locale (if (framep frame-or-buffer) frame-or-buffer)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
246 (when (specifier-instance default-gutter-visible-p locale)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
247 (unless gutter-buffers-tab
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
248 (add-tab-to-gutter))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
249 (when (valid-image-instantiator-format-p 'tab-control)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
250 (let ((inst (glyph-image-instance
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
251 gutter-buffers-tab
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
252 (when (framep frame-or-buffer)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
253 (last-nonminibuf-window frame-or-buffer)))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
254 (set-image-instance-property inst :items
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
255 (buffers-tab-items
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
256 nil locale))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
257 (resize-subwindow inst (gutter-pixel-width) nil))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
258 ))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
259
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
260 (defun remove-buffer-from-gutter-tab ()
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
261 "Remove the current buffer from the tab control in the gutter area."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
262 (when (and (valid-image-instantiator-format-p 'tab-control)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
263 (specifier-instance default-gutter-visible-p))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
264 (let ((inst (glyph-image-instance gutter-buffers-tab))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
265 (buffers (buffers-tab-items t)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
266 (unless buffers
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
267 (setq buffers (build-buffers-tab-internal
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
268 (list
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
269 (get-buffer-create "*scratch*")))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
270 (set-image-instance-property inst :items buffers)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
271 (resize-subwindow inst (gutter-pixel-width) nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
272 )))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
273
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
274 (add-hook 'kill-buffer-hook 'remove-buffer-from-gutter-tab)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
275 (add-hook 'create-frame-hook 'update-tab-in-gutter)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
276 (add-hook 'record-buffer-hook 'update-tab-in-gutter)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
277
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
278 ;;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
279 ;; progress display
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
280 ;; ripped off from message display
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
281 ;;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
282 (defvar progress-stack nil
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
283 "An alist of label/string pairs representing active progress gauges.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
284 The first element in the list is currently displayed in the gutter area.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
285 Do not modify this directly--use the `progress' or
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
286 `display-progress'/`clear-progress' functions.")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
287
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
288 (defvar progress-glyph-height 32
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
289 "Height of the gutter area for progress messages.")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
290
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
291 (defvar progress-stop-callback 'progress-quit-function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
292 "Function to call to stop the progress operation.")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
293
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
294 (defun progress-quit-function ()
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
295 "Default function to call for the stop button in a progress gauge.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
296 This just removes the progress gauge and calls quit."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
297 (interactive)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
298 (clear-progress)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
299 (keyboard-quit))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
300
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
301 ;; private variables
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
302 (defvar progress-gauge-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
303 (make-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
304 (vector 'progress-gauge
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
305 :pixel-height (- progress-glyph-height 8)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
306 :pixel-width 250
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
307 :descriptor "Progress")))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
308
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
309 (defvar progress-text-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
310 (make-glyph [string :data ""]))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
311
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
312 (defvar progress-layout-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
313 (make-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
314 (vector
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
315 'layout :orientation 'vertical :justify 'left
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
316 :items (list
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
317 progress-text-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
318 (make-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
319 (vector
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
320 'layout :pixel-height progress-glyph-height
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
321 :orientation 'horizontal
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
322 :items (list
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
323 progress-gauge-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
324 (vector
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
325 'button :pixel-height (- progress-glyph-height 8)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
326 :descriptor " Stop "
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
327 :callback '(funcall progress-stop-callback)))))))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
328
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
329 (defvar progress-abort-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
330 (make-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
331 (vector 'layout :orientation 'vertical :justify 'left
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
332 :items (list progress-text-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
333 (make-glyph
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
334 (vector 'layout
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
335 :pixel-height progress-glyph-height
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
336 :orientation 'horizontal))))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
337
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
338 (defvar progress-extent-text "")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
339 (defvar progress-extent nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
340
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
341 (defun progress-displayed-p (&optional return-string frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
342 "Return a non-nil value if a progress gauge is presently displayed in the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
343 gutter area. If optional argument RETURN-STRING is non-nil,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
344 return a string containing the message, otherwise just return t."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
345 (let ((buffer (get-buffer-create " *Gutter Area*")))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
346 (and (< (point-min buffer) (point-max buffer))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
347 (if return-string
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
348 (buffer-substring nil nil buffer)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
349 t))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
350
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
351 ;;; Returns the string which remains in the echo area, or nil if none.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
352 ;;; If label is nil, the whole message stack is cleared.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
353 (defun clear-progress (&optional label frame no-restore)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
354 "Remove any progress gauge with the given LABEL from the progress gauge-stack,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
355 erasing it from the gutter area if it's currently displayed there.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
356 If a message remains at the head of the progress-stack and NO-RESTORE
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
357 is nil, it will be displayed. The string which remains in the gutter
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
358 area will be returned, or nil if the progress-stack is now empty.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
359 If LABEL is nil, the entire progress-stack is cleared.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
360
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
361 Unless you need the return value or you need to specify a label,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
362 you should just use (progress nil)."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
363 (or frame (setq frame (selected-frame)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
364 (remove-progress label frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
365 (let ((inhibit-read-only t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
366 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
367 (erase-buffer " *Echo Area*")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
368 (erase-buffer (get-buffer-create " *Gutter Area*")))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
369 (if no-restore
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
370 nil ; just preparing to put another msg up
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
371 (if progress-stack
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
372 (let ((oldmsg (cdr (car progress-stack))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
373 (raw-append-progress oldmsg frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
374 oldmsg)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
375 ;; nothing to display so get rid of the gauge
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
376 (set-specifier bottom-gutter-border-width 0 frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
377 (set-specifier bottom-gutter-visible-p nil frame))))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
378
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
379 (defun remove-progress (&optional label frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
380 ;; If label is nil, we want to remove all matching progress gauges.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
381 (while (and progress-stack
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
382 (or (null label) ; null label means clear whole stack
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
383 (eq label (car (car progress-stack)))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
384 (setq progress-stack (cdr progress-stack)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
385 (let ((s progress-stack))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
386 (while (cdr s)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
387 (let ((msg (car (cdr s))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
388 (if (eq label (car msg))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
389 (progn
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
390 (setcdr s (cdr (cdr s))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
391 (setq s (cdr s)))))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
392
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
393 (defun append-progress (label message &optional value frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
394 (or frame (setq frame (selected-frame)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
395 ;; Add a new entry to the message-stack, or modify an existing one
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
396 (let* ((top (car progress-stack))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
397 (tmsg (cdr top)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
398 (if (eq label (car top))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
399 (progn
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
400 (setcdr top message)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
401 (if (eq tmsg message)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
402 (set-image-instance-property
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
403 (glyph-image-instance progress-gauge-glyph)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
404 :percent value)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
405 (raw-append-progress message value frame))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
406 (redisplay-gutter-area)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
407 (when (input-pending-p)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
408 (dispatch-event (next-command-event))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
409 (push (cons label message) progress-stack)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
410 (raw-append-progress message value frame))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
411 (when (eq value 100)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
412 (sit-for 0.5 nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
413 (clear-progress label))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
414
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
415 (defun abort-progress (label message &optional frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
416 (or frame (setq frame (selected-frame)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
417 ;; Add a new entry to the message-stack, or modify an existing one
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
418 (let* ((top (car progress-stack))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
419 (inhibit-read-only t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
420 (zmacs-region-stays zmacs-region-stays))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
421 (if (eq label (car top))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
422 (setcdr top message)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
423 (push (cons label message) progress-stack))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
424 (unless (equal message "")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
425 (insert-string message (get-buffer-create " *Gutter Area*"))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
426 ;; Do what the device is able to cope with.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
427 (if (not (valid-image-instantiator-format-p 'progress-gauge frame))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
428 (progn
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
429 (insert-string message " *Echo Area*")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
430 (if (not executing-kbd-macro)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
431 (redisplay-echo-area)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
432 ;; do some funky display here.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
433 (unless progress-extent
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
434 (setq progress-extent (make-extent 0 0 progress-extent-text)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
435 (let ((bglyph (extent-begin-glyph progress-extent)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
436 (set-extent-begin-glyph progress-extent progress-abort-glyph)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
437 ;; fixup the gutter specifiers
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
438 (set-specifier bottom-gutter progress-extent-text frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
439 (set-specifier bottom-gutter-border-width 2 frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
440 (set-image-instance-property
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
441 (glyph-image-instance progress-text-glyph) :data message)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
442 (set-specifier bottom-gutter-height 'autodetect frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
443 (set-specifier bottom-gutter-visible-p t frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
444 ;; we have to do this so redisplay is up-to-date and so
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
445 ;; redisplay-gutter-area performs optimally.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
446 (redisplay-gutter-area)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
447 (sit-for 0.5 nil)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
448 (clear-progress label)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
449 (set-extent-begin-glyph progress-extent bglyph)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
450 )))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
451
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
452 (defun raw-append-progress (message &optional value frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
453 (unless (equal message "")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
454 (let ((inhibit-read-only t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
455 (zmacs-region-stays zmacs-region-stays)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
456 (val (or value 0))) ; preserve from change
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
457 (insert-string message (get-buffer-create " *Gutter Area*"))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
458 ;; Do what the device is able to cope with.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
459 (if (not (valid-image-instantiator-format-p 'progress-gauge frame))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
460 (progn
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
461 (insert-string
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
462 (concat message (if (eq val 100) "done.")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
463 (make-string (/ val 5) ?.))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
464 " *Echo Area*")
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
465 (if (not executing-kbd-macro)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
466 (redisplay-echo-area)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
467 ;; do some funky display here.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
468 (unless progress-extent
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
469 (setq progress-extent (make-extent 0 0 progress-extent-text))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
470 (set-extent-begin-glyph progress-extent progress-layout-glyph))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
471 ;; fixup the gutter specifiers
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
472 (set-specifier bottom-gutter progress-extent-text frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
473 (set-specifier bottom-gutter-border-width 2 frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
474 (set-image-instance-property
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
475 (glyph-image-instance progress-gauge-glyph) :percent val)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
476 (set-image-instance-property
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
477 (glyph-image-instance progress-text-glyph) :data message)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
478 (if (and (eq (specifier-instance bottom-gutter-height frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
479 'autodetect)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
480 (specifier-instance bottom-gutter-visible-p frame))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
481 (progn
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
482 ;; if the gauge is already visible then just draw the gutter
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
483 ;; checking for user events
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
484 (redisplay-gutter-area)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
485 (when (input-pending-p)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
486 (dispatch-event (next-command-event))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
487 ;; otherwise make the gutter visible and redraw the frame
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
488 (set-specifier bottom-gutter-height 'autodetect frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
489 (set-specifier bottom-gutter-visible-p t frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
490 ;; we have to do this so redisplay is up-to-date and so
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
491 ;; redisplay-gutter-area performs optimally.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
492 (redisplay-frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
493 )))))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
494
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
495 (defun display-progress (label message &optional value frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
496 "Display a progress gauge and message in the bottom gutter area.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
497 First argument LABEL is an identifier for this message. MESSAGE is
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
498 the string to display. Use `clear-progress' to remove a labelled
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
499 message."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
500 (clear-progress label frame t)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
501 (if (eq value 'abort)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
502 (abort-progress label message frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
503 (append-progress label message value frame)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
504
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
505 (defun current-progress (&optional frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
506 "Return the current progress gauge in the gutter area, or nil.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
507 The FRAME argument is currently unused."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
508 (cdr (car progress-stack)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
509
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
510 ;;; may eventually be frame-dependent
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
511 (defun current-progress-label (&optional frame)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
512 (car (car progress-stack)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
513
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
514 (defun progress (fmt &optional value &rest args)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
515 "Print a progress gauge and message in the bottom gutter area of the frame.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
516 The arguments are the same as to `format'.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
517
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
518 If the only argument is nil, clear any existing progress gauge."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
519 (if (and (null fmt) (null args))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
520 (prog1 nil
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
521 (clear-progress nil))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
522 (let ((str (apply 'format fmt args)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
523 (display-progress 'progress str value)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
524 str)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
525
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
526 (defun lprogress (label fmt &optional value &rest args)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
527 "Print a progress gauge and message in the bottom gutter area of the frame.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
528 First argument LABEL is an identifier for this progress gauge. The rest of the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
529 arguments are the same as to `format'."
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
530 (if (and (null fmt) (null args))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
531 (prog1 nil
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
532 (clear-progress label nil))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
533 (let ((str (apply 'format fmt args)))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
534 (display-progress label str value)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 422
diff changeset
535 str)))
422
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
536
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
537 (provide 'gutter-items)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
538 ;;; gutter-items.el ends here.