209
|
1 ;;; modeline.el --- modeline hackery.
|
|
2
|
|
3 ;; Copyright (C) 1988, 1992-1994, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5
|
|
6 ;; Maintainer: XEmacs Development Team
|
|
7 ;; Keywords: extensions, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: Not in FSF.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
|
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
35 ;;; General mouse modeline stuff ;;;
|
|
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
37
|
|
38 (defgroup modeline nil
|
227
|
39 "Modeline customizations."
|
209
|
40 :group 'environment)
|
|
41
|
|
42 (defcustom drag-modeline-event-lag 150
|
|
43 "*The pause (in msecs) between drag modeline events before redisplaying.
|
|
44 If this value is too small, dragging will be choppy because redisplay cannot
|
|
45 keep up. If it is too large, dragging will be choppy because of the explicit
|
|
46 redisplay delay specified."
|
|
47 :type 'integer
|
|
48 :group 'modeline)
|
|
49
|
|
50 (defcustom modeline-click-swaps-buffers nil
|
|
51 "*If non-nil, clicking on the modeline changes the current buffer.
|
|
52 Click on the left half of the modeline cycles forward through the
|
|
53 buffer list and clicking on the right half cycles backward."
|
|
54 :type 'boolean
|
|
55 :group 'modeline)
|
|
56
|
|
57 (defun mouse-drag-modeline (event)
|
|
58 "Resize a window by dragging its modeline.
|
|
59 This command should be bound to a button-press event in modeline-map.
|
|
60 Holding down a mouse button and moving the mouse up and down will
|
|
61 make the clicked-on window taller or shorter."
|
|
62 (interactive "e")
|
|
63 (or (button-press-event-p event)
|
|
64 (error "%s must be invoked by a mouse-press" this-command))
|
|
65 (or (event-over-modeline-p event)
|
|
66 (error "not over a modeline"))
|
225
|
67 ;; Give the modeline a "pressed" look. --hniksic
|
286
|
68 (with-specifier-instance modeline-shadow-thickness
|
|
69 (- (specifier-instance modeline-shadow-thickness (event-window event)))
|
|
70 (event-window event)
|
225
|
71 (let ((done nil)
|
|
72 (depress-line (event-y event))
|
|
73 (start-event-frame (event-frame event))
|
|
74 (start-event-window (event-window event))
|
|
75 (start-nwindows (count-windows t))
|
280
|
76 ;; (hscroll-delta (face-width 'modeline))
|
265
|
77 ;; (start-hscroll (modeline-hscroll (event-window event)))
|
259
|
78 (start-x-pixel (event-x-pixel event))
|
225
|
79 (last-timestamp 0)
|
|
80 default-line-height
|
209
|
81 modeline-height
|
225
|
82 should-enlarge-minibuffer
|
|
83 event min-height minibuffer y top bot edges wconfig growth)
|
|
84 (setq minibuffer (minibuffer-window start-event-frame)
|
|
85 default-line-height (face-height 'default start-event-window)
|
|
86 min-height (+ (* window-min-height default-line-height)
|
|
87 ;; Don't let the window shrink by a
|
|
88 ;; non-multiple of the default line
|
|
89 ;; height. (enlarge-window -1) will do
|
|
90 ;; this if the difference between the
|
|
91 ;; current window height and the minimum
|
|
92 ;; window height is less than the height
|
|
93 ;; of the default font. These extra
|
|
94 ;; lost pixels of height don't come back
|
|
95 ;; if you grow the window again. This
|
|
96 ;; can make it impossible to drag back
|
|
97 ;; to the exact original size, which is
|
|
98 ;; disconcerting.
|
|
99 (% (window-pixel-height start-event-window)
|
|
100 default-line-height))
|
|
101 modeline-height
|
209
|
102 (if (specifier-instance has-modeline-p start-event-window)
|
|
103 (+ (face-height 'modeline start-event-window)
|
|
104 (* 2 (specifier-instance modeline-shadow-thickness
|
|
105 start-event-window)))
|
|
106 (* 2 (specifier-instance modeline-shadow-thickness
|
|
107 start-event-window))))
|
225
|
108 (if (not (eq (window-frame minibuffer) start-event-frame))
|
|
109 (setq minibuffer nil))
|
|
110 (if (and (null minibuffer) (one-window-p t))
|
|
111 (error "Attempt to resize sole window"))
|
|
112 ;; if this is the bottommost ordinary window, then to
|
|
113 ;; move its modeline the minibuffer must be enlarged.
|
|
114 (setq should-enlarge-minibuffer
|
|
115 (and minibuffer (window-lowest-p start-event-window)))
|
|
116 ;; loop reading events
|
|
117 (while (not done)
|
|
118 (setq event (next-event event))
|
|
119 ;; requeue event and quit if this is a misc-user, eval or
|
|
120 ;; keypress event.
|
|
121 ;; quit if this is a button press or release event, or if the event
|
|
122 ;; occurred in some other frame.
|
|
123 ;; drag if this is a mouse motion event and the time
|
|
124 ;; between this event and the last event is greater than
|
|
125 ;; drag-modeline-event-lag.
|
|
126 ;; do nothing if this is any other kind of event.
|
|
127 (cond ((or (misc-user-event-p event)
|
|
128 (key-press-event-p event))
|
|
129 (setq unread-command-events (nconc unread-command-events
|
|
130 (list event))
|
|
131 done t))
|
|
132 ((button-release-event-p event)
|
|
133 (setq done t)
|
259
|
134 ;; Consider we have a mouse click neither X pos (modeline
|
|
135 ;; scroll) nore Y pos (modeline drag) have changed.
|
|
136 (and modeline-click-swaps-buffers
|
|
137 (= depress-line (event-y event))
|
265
|
138 ;; (= start-hscroll (modeline-hscroll start-event-window))
|
259
|
139 (modeline-swap-buffers event)))
|
225
|
140 ((button-event-p event)
|
|
141 (setq done t))
|
|
142 ((not (motion-event-p event))
|
|
143 (dispatch-event event))
|
|
144 ((not (eq start-event-frame (event-frame event)))
|
|
145 (setq done t))
|
|
146 ((< (abs (- (event-timestamp event) last-timestamp))
|
|
147 drag-modeline-event-lag)
|
|
148 nil)
|
|
149 (t
|
265
|
150 ;; (set-modeline-hscroll start-event-window
|
|
151 ;; (+ (/ (- (event-x-pixel event)
|
|
152 ;; start-x-pixel)
|
|
153 ;; hscroll-delta)
|
|
154 ;; start-hscroll))
|
225
|
155 (setq last-timestamp (event-timestamp event)
|
|
156 y (event-y-pixel event)
|
|
157 edges (window-pixel-edges start-event-window)
|
|
158 top (nth 1 edges)
|
|
159 bot (nth 3 edges))
|
|
160 ;; scale back a move that would make the
|
|
161 ;; window too short.
|
|
162 (cond ((< (- y top (- modeline-height)) min-height)
|
|
163 (setq y (+ top min-height (- modeline-height)))))
|
|
164 ;; compute size change needed
|
|
165 (setq growth (- y bot (/ (- modeline-height) 2))
|
|
166 wconfig (current-window-configuration))
|
|
167 ;; grow/shrink minibuffer?
|
|
168 (if should-enlarge-minibuffer
|
|
169 (progn
|
|
170 ;; yes. scale back shrinkage if it
|
|
171 ;; would make the minibuffer less than 1
|
|
172 ;; line tall.
|
|
173 ;;
|
|
174 ;; also flip the sign of the computed growth,
|
|
175 ;; since if we want to grow the window with the
|
|
176 ;; modeline we need to shrink the minibuffer
|
|
177 ;; and vice versa.
|
|
178 (if (and (> growth 0)
|
|
179 (< (- (window-pixel-height minibuffer)
|
|
180 growth)
|
|
181 default-line-height))
|
|
182 (setq growth
|
|
183 (- (window-pixel-height minibuffer)
|
|
184 default-line-height)))
|
209
|
185 (setq growth (- growth))))
|
225
|
186 ;; window grow and shrink by lines not pixels, so
|
|
187 ;; divide the pixel height by the height of the
|
|
188 ;; default face.
|
|
189 (setq growth (/ growth default-line-height))
|
|
190 ;; grow/shrink the window
|
|
191 (enlarge-window growth nil (if should-enlarge-minibuffer
|
|
192 minibuffer
|
|
193 start-event-window))
|
|
194 ;; if this window's growth caused another
|
|
195 ;; window to be deleted because it was too
|
|
196 ;; short, rescind the change.
|
|
197 ;;
|
|
198 ;; if size change caused space to be stolen
|
|
199 ;; from a window above this one, rescind the
|
|
200 ;; change, but only if we didn't grow/shrink
|
|
201 ;; the minibuffer. minibuffer size changes
|
|
202 ;; can cause all windows to shrink... no way
|
|
203 ;; around it.
|
|
204 (if (or (/= start-nwindows (count-windows t))
|
|
205 (and (not should-enlarge-minibuffer)
|
|
206 (/= top (nth 1 (window-pixel-edges
|
|
207 start-event-window)))))
|
|
208 (set-window-configuration wconfig))))))))
|
209
|
209
|
|
210 ;; from Bob Weiner (bob_weiner@pts.mot.com)
|
259
|
211 ;; Whether this function should be called is now decided in
|
|
212 ;; mouse-drag-modeline - dverna feb. 98
|
|
213 (defun modeline-swap-buffers (event)
|
|
214 "Handle mouse clicks on modeline by switching buffers.
|
209
|
215 If click on left half of a frame's modeline, bury current buffer.
|
|
216 If click on right half of a frame's modeline, raise bottommost buffer.
|
259
|
217 Arg EVENT is the button release event that occured on the modeline."
|
|
218 (or (event-over-modeline-p event)
|
|
219 (error "not over a modeline"))
|
|
220 (or (button-release-event-p event)
|
|
221 (error "not a button release event"))
|
|
222 (if (< (event-x event) (/ (window-width (event-window event)) 2))
|
|
223 ;; On left half of modeline, bury current buffer,
|
|
224 ;; displaying second buffer on list.
|
|
225 (mouse-bury-buffer event)
|
|
226 ;; On right half of modeline, raise and display bottommost
|
|
227 ;; buffer in buffer list.
|
|
228 (mouse-unbury-buffer event)))
|
209
|
229
|
|
230 (defconst modeline-menu
|
|
231 '("Window Commands"
|
|
232 ["Delete Window Above" delete-window t]
|
|
233 ["Delete Other Windows" delete-other-windows t]
|
|
234 ["Split Window Above" split-window-vertically t]
|
|
235 ["Split Window Horizontally" split-window-horizontally t]
|
|
236 ["Balance Windows" balance-windows t]
|
|
237 ))
|
|
238
|
|
239 (defun modeline-menu (event)
|
|
240 (interactive "e")
|
|
241 (popup-menu-and-execute-in-window
|
|
242 (cons (format "Window Commands for %S:"
|
|
243 (buffer-name (event-buffer event)))
|
|
244 (cdr modeline-menu))
|
|
245 event))
|
|
246
|
|
247 (defvar modeline-map (make-sparse-keymap 'modeline-map)
|
|
248 "Keymap consulted for mouse-clicks on the modeline of a window.
|
|
249 This variable may be buffer-local; its value will be looked up in
|
|
250 the buffer of the window whose modeline was clicked upon.")
|
|
251
|
|
252 (define-key modeline-map 'button1 'mouse-drag-modeline)
|
|
253 ;; button2 selects the window without setting point
|
|
254 (define-key modeline-map 'button2 (lambda () (interactive "@")))
|
|
255 (define-key modeline-map 'button3 'modeline-menu)
|
|
256
|
|
257 (make-face 'modeline-mousable "Face for mousable portions of the modeline.")
|
263
|
258 (set-face-parent 'modeline-mousable 'modeline nil '(default))
|
284
|
259 (when (featurep 'window-system)
|
|
260 (set-face-foreground 'modeline-mousable
|
|
261 '(((default color x) . "firebrick")
|
|
262 ((default color mswindows) . "firebrick"))
|
|
263 'global))
|
209
|
264 (when (featurep 'x)
|
263
|
265 (set-face-font 'modeline-mousable [bold] nil '(default mono x))
|
|
266 (set-face-font 'modeline-mousable [bold] nil '(default grayscale x)))
|
209
|
267
|
|
268 (defmacro make-modeline-command-wrapper (command)
|
|
269 `#'(lambda (event)
|
|
270 (interactive "e")
|
|
271 (save-selected-window
|
|
272 (select-window (event-window event))
|
|
273 (call-interactively ',(eval command)))))
|
|
274
|
|
275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
276 ;;; Minor modes ;;;
|
|
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
278
|
|
279 (defvar minor-mode-alist nil
|
|
280 "Alist saying how to show minor modes in the modeline.
|
|
281 Each element looks like (VARIABLE STRING);
|
|
282 STRING is included in the modeline iff VARIABLE's value is non-nil.
|
|
283
|
|
284 Actually, STRING need not be a string; any possible modeline element
|
|
285 is okay. See `modeline-format'.")
|
|
286
|
|
287 ;; Used by C code (lookup-key and friends) but defined here.
|
|
288 (defvar minor-mode-map-alist nil
|
|
289 "Alist of keymaps to use for minor modes.
|
|
290 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read
|
|
291 key sequences and look up bindings iff VARIABLE's value is non-nil.
|
|
292 If two active keymaps bind the same key, the keymap appearing earlier
|
|
293 in the list takes precedence.")
|
|
294
|
|
295 (make-face 'modeline-mousable-minor-mode
|
|
296 "Face for mousable minor-mode strings in the modeline.")
|
263
|
297 (set-face-parent 'modeline-mousable-minor-mode 'modeline-mousable nil
|
|
298 '(default))
|
284
|
299 (when (featurep 'window-system)
|
209
|
300 (set-face-foreground 'modeline-mousable-minor-mode
|
263
|
301 '(((default color x) . "green4")
|
284
|
302 ((default color x) . "forestgreen")
|
|
303 ((default color mswindows) . "green4")
|
|
304 ((default color mswindows) . "forestgreen"))
|
|
305 'global))
|
209
|
306
|
|
307 (defvar modeline-mousable-minor-mode-extent (make-extent nil nil)
|
|
308 ;; alliteration at its finest.
|
|
309 "Extent managing the mousable minor mode modeline strings.")
|
|
310 (set-extent-face modeline-mousable-minor-mode-extent
|
|
311 'modeline-mousable-minor-mode)
|
|
312
|
|
313 ;; This replaces the idiom
|
|
314 ;;
|
|
315 ;; (or (assq 'isearch-mode minor-mode-alist)
|
|
316 ;; (setq minor-mode-alist
|
|
317 ;; (purecopy
|
|
318 ;; (append minor-mode-alist
|
|
319 ;; '((isearch-mode isearch-mode))))))
|
|
320
|
|
321 (defun add-minor-mode (toggle name &optional keymap after toggle-fun)
|
|
322 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
|
241
|
323
|
209
|
324 TOGGLE is a symbol whose value as a variable specifies whether the
|
241
|
325 minor mode is active.
|
|
326
|
|
327 NAME is the name that should appear in the modeline. It should either
|
|
328 be a string beginning with a space, or a symbol with a similar string
|
|
329 as its value.
|
|
330
|
|
331 KEYMAP is a keymap to make active when the minor mode is active.
|
|
332
|
|
333 AFTER is the toggling symbol used for another minor mode. If AFTER is
|
|
334 non-nil, then it is used to position the new mode in the minor-mode
|
|
335 alists.
|
|
336
|
|
337 TOGGLE-FUN specifies an interactive function that is called to toggle
|
|
338 the mode on and off; this affects what happens when button2 is pressed
|
|
339 on the mode, and when button3 is pressed somewhere in the list of
|
|
340 modes. If TOGGLE-FUN is nil and TOGGLE names an interactive function,
|
|
341 TOGGLE is used as the toggle function.
|
|
342
|
280
|
343 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
|
|
344 (let* ((add-elt #'(lambda (elt sym)
|
|
345 (let (place)
|
|
346 (cond ((null after) ; add to front
|
|
347 (push elt (symbol-value sym)))
|
|
348 ((and (not (eq after t))
|
|
349 (setq place (memq (assq after
|
|
350 (symbol-value sym))
|
|
351 (symbol-value sym))))
|
|
352 (push elt (cdr place)))
|
|
353 (t
|
|
354 (set sym (append (symbol-value sym)
|
|
355 (list elt))))))
|
|
356 (symbol-value sym)))
|
|
357 el toggle-keymap)
|
209
|
358 (if toggle-fun
|
280
|
359 (check-argument-type 'commandp toggle-fun)
|
|
360 (when (commandp toggle)
|
|
361 (setq toggle-fun toggle)))
|
|
362 (when (and toggle-fun name)
|
|
363 (setq toggle-keymap (make-sparse-keymap
|
|
364 (intern (concat "modeline-minor-"
|
|
365 (symbol-name toggle)
|
|
366 "-map"))))
|
|
367 (define-key toggle-keymap 'button2
|
|
368 ;; defeat the DUMB-ASS byte-compiler, which tries to
|
|
369 ;; expand the macro at compile time and fucks up.
|
|
370 (eval '(make-modeline-command-wrapper toggle-fun)))
|
|
371 (put toggle 'modeline-toggle-function toggle-fun))
|
|
372 (when name
|
|
373 (let ((hacked-name
|
|
374 (if toggle-keymap
|
|
375 (cons (let ((extent (make-extent nil nil)))
|
|
376 (set-extent-keymap extent toggle-keymap)
|
|
377 (set-extent-property
|
|
378 extent 'help-echo
|
|
379 (concat "button2 turns off "
|
|
380 (if (symbolp toggle-fun)
|
|
381 (symbol-name toggle-fun)
|
|
382 (symbol-name toggle))))
|
|
383 extent)
|
|
384 (cons modeline-mousable-minor-mode-extent name))
|
|
385 name)))
|
|
386 (if (setq el (assq toggle minor-mode-alist))
|
|
387 (setcdr el (list hacked-name))
|
|
388 (funcall add-elt
|
|
389 (list toggle hacked-name)
|
|
390 'minor-mode-alist))))
|
|
391 (when keymap
|
|
392 (if (setq el (assq toggle minor-mode-map-alist))
|
|
393 (setcdr el keymap)
|
|
394 (funcall add-elt
|
|
395 (cons toggle keymap)
|
|
396 'minor-mode-map-alist)))))
|
209
|
397
|
286
|
398 ;; #### TODO: Add `:menu-tag' keyword to add-minor-mode. Or create a
|
|
399 ;; separate function to manage the minor mode menu.
|
|
400
|
|
401 ;(put 'abbrev-mode :menu-tag "Abbreviation Expansion")
|
209
|
402 (add-minor-mode 'abbrev-mode " Abbrev")
|
241
|
403 ;; only when visiting a file...
|
209
|
404 (add-minor-mode 'overwrite-mode 'overwrite-mode)
|
286
|
405 ;(put 'auto-fill-function :menu-tag "Auto Fill")
|
209
|
406 (add-minor-mode 'auto-fill-function " Fill" nil nil 'auto-fill-mode)
|
241
|
407
|
286
|
408 ;(put 'defining-kbd-macro :menu-tag "Keyboard Macro")
|
280
|
409 (add-minor-mode 'defining-kbd-macro " Def" nil nil
|
|
410 (lambda ()
|
|
411 (interactive)
|
|
412 (if defining-kbd-macro
|
284
|
413 (progn
|
|
414 ;; #### This means to disregard the last event.
|
|
415 ;; It is needed because the last recorded
|
|
416 ;; event is usually the mouse event that
|
|
417 ;; invoked the menu item (and this function),
|
|
418 ;; and having it in the macro causes problems.
|
|
419 (zap-last-kbd-macro-event)
|
|
420 (end-kbd-macro nil))
|
280
|
421 (start-kbd-macro nil))))
|
209
|
422
|
|
423 (defun modeline-minor-mode-menu (event)
|
241
|
424 "The menu that pops up when you press `button3' inside the
|
|
425 parentheses on the modeline."
|
209
|
426 (interactive "e")
|
|
427 (save-excursion
|
|
428 (set-buffer (event-buffer event))
|
|
429 (popup-menu-and-execute-in-window
|
280
|
430 (cons
|
|
431 "Minor Mode Toggles"
|
|
432 (sort
|
|
433 (delq nil (mapcar
|
|
434 #'(lambda (x)
|
|
435 (let* ((toggle-sym (car x))
|
|
436 (toggle-fun (or (get toggle-sym
|
|
437 'modeline-toggle-function)
|
|
438 (and (commandp toggle-sym)
|
|
439 toggle-sym)))
|
286
|
440 (menu-tag (symbol-name (if (symbolp toggle-fun)
|
|
441 toggle-fun
|
|
442 toggle-sym))
|
|
443 ;; Here a function should
|
|
444 ;; maybe be invoked to
|
|
445 ;; beautify the symbol's
|
|
446 ;; menu appearance.
|
|
447 ))
|
280
|
448 (and toggle-fun
|
|
449 (vector menu-tag
|
|
450 toggle-fun
|
|
451 ;; The following two are wrong
|
|
452 ;; because of possible name
|
|
453 ;; clashes.
|
|
454 ;:active (get toggle-sym :active t)
|
|
455 ;:included (get toggle-sym :included t)
|
|
456 :style 'toggle
|
|
457 :selected (and (boundp toggle-sym)
|
|
458 toggle-sym)))))
|
|
459 minor-mode-alist))
|
|
460 (lambda (e1 e2)
|
|
461 (string< (aref e1 0) (aref e2 0)))))
|
209
|
462 event)))
|
|
463
|
|
464 (defvar modeline-minor-mode-map (make-sparse-keymap 'modeline-minor-mode-map)
|
|
465 "Keymap consulted for mouse-clicks on the minor-mode modeline list.")
|
|
466 (define-key modeline-minor-mode-map 'button3 'modeline-minor-mode-menu)
|
|
467
|
|
468 (defvar modeline-minor-mode-extent (make-extent nil nil)
|
|
469 "Extent covering the minor mode modeline strings.")
|
|
470 (set-extent-face modeline-minor-mode-extent 'modeline-mousable)
|
|
471 (set-extent-keymap modeline-minor-mode-extent modeline-minor-mode-map)
|
|
472
|
|
473
|
|
474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
475 ;;; Other ;;;
|
|
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
477
|
|
478 (defun modeline-buffers-menu (event)
|
|
479 (interactive "e")
|
|
480 (popup-menu-and-execute-in-window
|
|
481 '("Buffers Popup Menu"
|
|
482 :filter buffers-menu-filter
|
|
483 ["List All Buffers" list-buffers t]
|
|
484 "--"
|
|
485 )
|
|
486 event))
|
|
487
|
|
488 (defvar modeline-buffer-id-left-map
|
|
489 (make-sparse-keymap 'modeline-buffer-id-left-map)
|
|
490 "Keymap consulted for mouse-clicks on the left half of the buffer-id string.")
|
|
491
|
|
492 (defvar modeline-buffer-id-right-map
|
|
493 (make-sparse-keymap 'modeline-buffer-id-right-map)
|
|
494 "Keymap consulted for mouse-clicks on the right half of the buffer-id string.")
|
|
495
|
|
496 (define-key modeline-buffer-id-left-map 'button2 'mouse-unbury-buffer)
|
|
497 (define-key modeline-buffer-id-right-map 'button2 'mouse-bury-buffer)
|
|
498 (define-key modeline-buffer-id-left-map 'button3 'modeline-buffers-menu)
|
|
499 (define-key modeline-buffer-id-right-map 'button3 'modeline-buffers-menu)
|
|
500
|
|
501 (make-face 'modeline-buffer-id
|
|
502 "Face for the buffer ID string in the modeline.")
|
263
|
503 (set-face-parent 'modeline-buffer-id 'modeline nil '(default))
|
284
|
504 (when (featurep 'window-system)
|
|
505 (set-face-foreground 'modeline-buffer-id
|
|
506 '(((default color x) . "blue4")
|
|
507 ((default color mswindows) . "blue4"))
|
|
508 'global))
|
209
|
509 (when (featurep 'x)
|
263
|
510 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default mono x))
|
|
511 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default grayscale x)))
|
209
|
512 (when (featurep 'tty)
|
263
|
513 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default tty)))
|
209
|
514
|
|
515 (defvar modeline-buffer-id-extent (make-extent nil nil)
|
|
516 "Extent covering the whole of the buffer-id string.")
|
|
517 (set-extent-face modeline-buffer-id-extent 'modeline-buffer-id)
|
|
518
|
|
519 (defvar modeline-buffer-id-left-extent (make-extent nil nil)
|
|
520 "Extent covering the left half of the buffer-id string.")
|
|
521 (set-extent-keymap modeline-buffer-id-left-extent
|
|
522 modeline-buffer-id-left-map)
|
|
523 (set-extent-property modeline-buffer-id-left-extent 'help-echo
|
|
524 "button2 cycles to the previous buffer")
|
|
525
|
|
526 (defvar modeline-buffer-id-right-extent (make-extent nil nil)
|
|
527 "Extent covering the right half of the buffer-id string.")
|
|
528 (set-extent-keymap modeline-buffer-id-right-extent
|
|
529 modeline-buffer-id-right-map)
|
|
530 (set-extent-property modeline-buffer-id-right-extent 'help-echo
|
|
531 "button2 cycles to the next buffer")
|
|
532
|
|
533 (defconst modeline-buffer-identification
|
|
534 (list (cons modeline-buffer-id-left-extent (purecopy "XEmacs%N:"))
|
|
535 ; this used to be "XEmacs:"
|
|
536 (cons modeline-buffer-id-right-extent (purecopy " %17b")))
|
|
537 "Modeline control for identifying the buffer being displayed.
|
|
538 Its default value is \"XEmacs: %17b\" (NOT!). Major modes that edit things
|
|
539 other than ordinary files may change this (e.g. Info, Dired,...)")
|
|
540 (make-variable-buffer-local 'modeline-buffer-identification)
|
|
541
|
286
|
542 ;; These are for the sake of minor mode menu. #### All of this is
|
|
543 ;; kind of dirty. `add-minor-mode' started out as a simple substitute
|
|
544 ;; for (or (assq ...) ...) FSF stuff, but now is used for all kind of
|
|
545 ;; stuff. There should perhaps be a separate function to add toggles
|
|
546 ;; to the minor-mode-menu.
|
280
|
547 (add-minor-mode 'line-number-mode "")
|
|
548 (add-minor-mode 'column-number-mode "")
|
|
549
|
209
|
550 (defconst modeline-process nil
|
|
551 "Modeline control for displaying info on process status.
|
|
552 Normally nil in most modes, since there is no process to display.")
|
|
553 (make-variable-buffer-local 'modeline-process)
|
|
554
|
|
555 (defvar modeline-modified-map (make-sparse-keymap 'modeline-modified-map)
|
|
556 "Keymap consulted for mouse-clicks on the modeline-modified string.")
|
|
557 (define-key modeline-modified-map 'button2
|
|
558 (make-modeline-command-wrapper 'modeline-toggle-read-only))
|
|
559
|
|
560 (defvar modeline-modified-extent (make-extent nil nil)
|
|
561 "Extent covering the modeline-modified string.")
|
|
562 (set-extent-face modeline-modified-extent 'modeline-mousable)
|
|
563 (set-extent-keymap modeline-modified-extent modeline-modified-map)
|
|
564 (set-extent-property modeline-modified-extent 'help-echo
|
|
565 "button2 toggles the buffer's read-only status")
|
|
566
|
|
567 (defconst modeline-modified (purecopy '("--%1*%1+-"))
|
|
568 "Modeline control for displaying whether current buffer is modified.")
|
|
569 (make-variable-buffer-local 'modeline-modified)
|
|
570
|
|
571 (defvar modeline-narrowed-map (make-sparse-keymap 'modeline-narrowed-map)
|
|
572 "Keymap consulted for mouse-clicks on the modeline-narrowed string.")
|
|
573 (define-key modeline-narrowed-map 'button2
|
|
574 (make-modeline-command-wrapper 'widen))
|
|
575
|
|
576 (defvar modeline-narrowed-extent (make-extent nil nil)
|
|
577 "Extent covering the modeline-narrowed string.")
|
|
578 (set-extent-face modeline-narrowed-extent 'modeline-mousable)
|
|
579 (set-extent-keymap modeline-narrowed-extent modeline-narrowed-map)
|
|
580 (set-extent-property modeline-narrowed-extent 'help-echo
|
|
581 "button2 widens the buffer")
|
|
582
|
|
583 (setq-default
|
|
584 modeline-format
|
|
585 (list
|
|
586 (purecopy "")
|
|
587 (cons modeline-modified-extent 'modeline-modified)
|
|
588 (cons modeline-buffer-id-extent 'modeline-buffer-identification)
|
|
589 (purecopy " ")
|
|
590 'global-mode-string
|
|
591 (purecopy " %[(")
|
|
592 (cons modeline-minor-mode-extent (list "" 'mode-name 'minor-mode-alist))
|
|
593 (cons modeline-narrowed-extent "%n")
|
|
594 'modeline-process
|
|
595 (purecopy ")%]----")
|
286
|
596 (purecopy '(line-number-mode "L%l--"))
|
209
|
597 (purecopy '(column-number-mode "C%c--"))
|
|
598 (purecopy '(-3 . "%p"))
|
|
599 (purecopy "-%-")))
|
|
600
|
|
601 ;;; Added for XEmacs 20.3. Provide wrapper for vc since it may not always be
|
|
602 ;;; present, and its symbols are not visible this early in the dump if it
|
|
603 ;;; is.
|
|
604
|
|
605 (defun modeline-toggle-read-only ()
|
|
606 "Change whether this buffer is visiting its file read-only.
|
|
607 With arg, set read-only iff arg is positive.
|
|
608 This function is designed to be called when the read-only indicator on the
|
|
609 modeline is clicked. It will call `vc-toggle-read-only' if available,
|
|
610 otherwise it will call the usual `toggle-read-only'."
|
|
611 (interactive)
|
|
612 (if (fboundp 'vc-toggle-read-only)
|
|
613 (vc-toggle-read-only)
|
|
614 (toggle-read-only)))
|
|
615
|
|
616 ;;; modeline.el ends here
|