annotate lisp/gutter-items.el @ 422:95016f13131a r21-2-19

Import from CVS: tag r21-2-19
author cvs
date Mon, 13 Aug 2007 11:25:01 +0200
parents
children 11054d720c21
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)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
73 (integer 10))
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
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
94 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-menu-line
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
95 "*The function to call to return a string to represent a buffer in the
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
96 buffers tab. The function is passed a buffer and should return a string.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
97 The default value `format-buffers-menu-line' just returns the name of
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
98 the buffer. Also check out `slow-format-buffers-menu-line' which
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
99 returns a whole bunch of info about a buffer."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
100 :type 'function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
101 :group 'buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
102
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
103 (defun buffers-tab-switch-to-buffer (buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
104 "For use as a value for `buffers-tab-switch-to-buffer-function'."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
105 (switch-to-buffer buffer t))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
106
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
107 (defsubst build-buffers-tab-internal (buffers)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
108 (let (line)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
109 (mapcar
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
110 #'(lambda (buffer)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
111 (setq line (funcall buffers-tab-format-buffer-line-function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
112 buffer))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
113 (vector line (list buffers-tab-switch-to-buffer-function
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
114 (buffer-name buffer))))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
115 buffers)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
116
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
117 (defun buffers-tab-items ()
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
118 "This is the tab filter for the top-level buffers \"Buffers\" tab.
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
119 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
120 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
121 efficiency reasons. You can control how many buffers will be shown by
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
122 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
123 items by redefining the function `format-buffers-menu-line'."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
124 (let ((buffers (delete-if buffers-tab-omit-function (buffer-list))))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
125 (and (integerp buffers-tab-max-size)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
126 (> buffers-tab-max-size 1)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
127 (> (length buffers) buffers-tab-max-size)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
128 ;; shorten list of buffers
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
129 (setcdr (nthcdr buffers-tab-max-size buffers) nil))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
130 (setq buffers (build-buffers-tab-internal buffers))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
131 buffers))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
132
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
133 (defun add-tab-to-gutter ()
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
134 "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
135 (let ((gutter-string ""))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
136 (set-extent-begin-glyph
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
137 (make-extent 0 0 gutter-string)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
138 (setq gutter-buffers-tab
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
139 (make-glyph
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
140 (vector 'tab-control :descriptor "Buffers"
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
141 :properties (list :items (buffers-tab-items))))))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
142 ;; This looks better than a 3d border
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
143 (set-specifier default-gutter-border-width 0 'global 'mswindows)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
144 (set-specifier default-gutter gutter-string 'global 'mswindows)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
145
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
146 (defun update-tab-in-gutter (&optional notused)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
147 "Update the tab control in the gutter area."
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
148 (when (valid-image-instantiator-format-p 'tab-control)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
149 (set-image-instance-property (glyph-image-instance gutter-buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
150 :items
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
151 (buffers-tab-items))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
152 (resize-subwindow (glyph-image-instance gutter-buffers-tab)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
153 (gutter-pixel-width) nil)))
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
154
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
155 (add-tab-to-gutter)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
156 (add-hook 'switch-to-buffer-hooks 'update-tab-in-gutter)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
157 (add-hook 'create-frame-hook 'update-tab-in-gutter)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
158
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
159 (provide 'gutter-items)
95016f13131a Import from CVS: tag r21-2-19
cvs
parents:
diff changeset
160 ;;; gutter-items.el ends here.