0
|
1 ;;; modeline.el --- modeline hackery.
|
|
2
|
|
3 ;; Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5
|
|
6 ;; This file is part of XEmacs.
|
|
7
|
|
8 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
9 ;; under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 ;; General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
16
|
19 ;; along with XEmacs; see the file COPYING. If not, write to the
|
70
|
20 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
16
|
21 ;; Boston, MA 02111-1307, USA.
|
0
|
22
|
|
23 ;;; Synched up with: Not in FSF.
|
|
24
|
|
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
26 ;;; General mouse modeline stuff ;;;
|
|
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
28
|
120
|
29 (defgroup modeline nil
|
|
30 "Modeline customizations"
|
|
31 :group 'environment)
|
0
|
32
|
120
|
33 (defcustom drag-modeline-event-lag 150
|
|
34 "*The pause (in msecs) between drag modeline events before redisplaying.
|
|
35 If this value is too small, dragging will be choppy because redisplay cannot
|
|
36 keep up. If it is too large, dragging will be choppy because of the explicit
|
|
37 redisplay delay specified."
|
|
38 :type 'integer
|
|
39 :group 'modeline)
|
|
40
|
|
41 (defcustom modeline-click-swaps-buffers nil
|
0
|
42 "*If non-nil, clicking on the modeline changes the current buffer.
|
|
43 Click on the left half of the modeline cycles forward through the
|
120
|
44 buffer list and clicking on the right half cycles backward."
|
|
45 :type 'boolean
|
|
46 :group 'modeline)
|
0
|
47
|
|
48 (defun mouse-drag-modeline (event)
|
|
49 "Resize the window by dragging the modeline.
|
|
50 This should be bound to a mouse button in `modeline-map'."
|
|
51 (interactive "e")
|
|
52 (or (button-press-event-p event)
|
|
53 (error "%s must be invoked by a mouse-press" this-command))
|
|
54 (or (event-over-modeline-p event)
|
|
55 (error "not over a modeline"))
|
|
56 (let ((depress-line (event-y event))
|
|
57 (mouse-down t)
|
|
58 (window (event-window event))
|
|
59 (old-window (selected-window))
|
|
60 (def-line-height (face-height 'default))
|
|
61 (prior-drag-modeline-event-time 0)
|
|
62 delta)
|
|
63 (while mouse-down
|
|
64 (setq event (next-event event))
|
|
65 (cond ((motion-event-p event)
|
|
66 (if (window-lowest-p window)
|
|
67 (error "can't drag bottommost modeline"))
|
|
68 (cond ((> (- (event-timestamp event)
|
|
69 prior-drag-modeline-event-time)
|
|
70 drag-modeline-event-lag)
|
|
71
|
|
72 (setq prior-drag-modeline-event-time (event-timestamp event))
|
|
73
|
|
74 (if (event-over-modeline-p event)
|
|
75 (setq delta 0)
|
|
76 (setq delta (- (event-y-pixel event)
|
|
77 (nth 3 (window-pixel-edges window))))
|
|
78 (if (> delta 0)
|
|
79 (setq delta (+ delta def-line-height)))
|
|
80 (setq delta (/ delta def-line-height)))
|
|
81
|
|
82 ;; cough sputter hack kludge. It shouldn't be possible
|
|
83 ;; to get in here when we are over the minibuffer. But
|
|
84 ;; it is happening and that cause next-vertical-window to
|
|
85 ;; return nil which does not lead to window-height returning
|
|
86 ;; anything remotely resembling a sensible value. So catch
|
|
87 ;; the situation and die a happy death.
|
|
88 ;;
|
|
89 ;; Oh, and the BLAT FOOP error messages suck as well but
|
|
90 ;; I don't know what should be there. This should be
|
|
91 ;; looked at again when the new redisplay is done.
|
|
92 (if (not (next-vertical-window window))
|
|
93 (error "Try again: dragging in minibuffer does nothing"))
|
|
94 (cond ((and (> delta 0)
|
|
95 (<= (- (window-height (next-vertical-window window))
|
|
96 delta)
|
|
97 window-min-height))
|
|
98 (setq delta (- (window-height
|
|
99 (next-vertical-window window))
|
|
100 window-min-height))
|
|
101 (if (< delta 0) (error "BLAT")))
|
|
102 ((and (< delta 0)
|
|
103 (< (+ (window-height window) delta)
|
|
104 window-min-height))
|
|
105 (setq delta (- window-min-height
|
|
106 (window-height window)))
|
|
107 (if (> delta 0) (error "FOOP"))))
|
|
108 (if (= delta 0)
|
|
109 nil
|
|
110 (select-window window)
|
|
111 (enlarge-window delta)
|
|
112 ;; The call to enlarge-window may have caused the old
|
|
113 ;; window to disappear. Don't try and select it in
|
|
114 ;; that case.
|
|
115 (if (window-live-p old-window)
|
|
116 (select-window old-window))
|
|
117 (sit-for 0)
|
|
118 ))))
|
|
119 ((button-release-event-p event)
|
|
120 (setq mouse-down nil)
|
|
121 (if modeline-click-swaps-buffers
|
|
122 (mouse-release-modeline event depress-line)))
|
|
123 ((or (button-press-event-p event)
|
|
124 (key-press-event-p event))
|
|
125 (error ""))
|
|
126 (t
|
|
127 (dispatch-event event)))
|
|
128 )))
|
|
129
|
|
130 ;; from Bob Weiner (bob_weiner@pts.mot.com)
|
|
131 (defun mouse-release-modeline (event line-num)
|
|
132 "Handle modeline click EVENT on LINE-NUM by switching buffers.
|
|
133 If click on left half of a frame's modeline, bury current buffer.
|
|
134 If click on right half of a frame's modeline, raise bottommost buffer.
|
|
135 Args are: EVENT, the mouse release event, and LINE-NUM, the line number
|
|
136 within the frame at which the mouse was first depressed."
|
|
137 (if (= line-num (event-y event))
|
|
138 ;; Button press and release are at same line, treat this as
|
|
139 ;; a click and switch buffers.
|
|
140 (if (< (event-x event) (/ (window-width (event-window event)) 2))
|
|
141 ;; On left half of modeline, bury current buffer,
|
|
142 ;; displaying second buffer on list.
|
|
143 (mouse-bury-buffer event)
|
|
144 ;; On right half of modeline, raise and display bottommost
|
|
145 ;; buffer in buffer list.
|
|
146 (mouse-unbury-buffer event))))
|
|
147
|
|
148 (defconst modeline-menu
|
|
149 '("Window Commands"
|
|
150 ["Delete Window Above" delete-window t]
|
|
151 ["Delete Other Windows" delete-other-windows t]
|
|
152 ["Split Window Above" split-window-vertically t]
|
|
153 ["Split Window Horizontally" split-window-horizontally t]
|
|
154 ["Balance Windows" balance-windows t]
|
|
155 ))
|
|
156
|
|
157 (defun modeline-menu (event)
|
|
158 (interactive "e")
|
|
159 (popup-menu-and-execute-in-window
|
|
160 (cons (format "Window Commands for %S:"
|
|
161 (buffer-name (event-buffer event)))
|
|
162 (cdr modeline-menu))
|
|
163 event))
|
|
164
|
|
165 (defvar modeline-map (make-sparse-keymap 'modeline-map)
|
|
166 "Keymap consulted for mouse-clicks on the modeline of a window.
|
|
167 This variable may be buffer-local; its value will be looked up in
|
|
168 the buffer of the window whose modeline was clicked upon.")
|
|
169
|
|
170 (define-key modeline-map 'button1 'mouse-drag-modeline)
|
|
171 ;; button2 selects the window without setting point
|
|
172 (define-key modeline-map 'button2 (lambda () (interactive "@")))
|
|
173 (define-key modeline-map 'button3 'modeline-menu)
|
|
174
|
|
175 (make-face 'modeline-mousable "Face for mousable portions of the modeline.")
|
|
176
|
|
177 (defmacro make-modeline-command-wrapper (command)
|
|
178 `#'(lambda (event)
|
|
179 (interactive "e")
|
|
180 (save-selected-window
|
|
181 (select-window (event-window event))
|
|
182 (call-interactively ',(eval command)))))
|
|
183
|
|
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
185 ;;; Minor modes ;;;
|
|
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
187
|
|
188 (defvar minor-mode-alist nil
|
|
189 "Alist saying how to show minor modes in the modeline.
|
|
190 Each element looks like (VARIABLE STRING);
|
|
191 STRING is included in the modeline iff VARIABLE's value is non-nil.
|
|
192
|
|
193 Actually, STRING need not be a string; any possible modeline element
|
|
194 is okay. See `modeline-format'.")
|
|
195
|
|
196 ;; Used by C code (lookup-key and friends) but defined here.
|
|
197 (defvar minor-mode-map-alist nil
|
|
198 "Alist of keymaps to use for minor modes.
|
|
199 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read
|
|
200 key sequences and look up bindings iff VARIABLE's value is non-nil.
|
|
201 If two active keymaps bind the same key, the keymap appearing earlier
|
|
202 in the list takes precedence.")
|
|
203
|
|
204 (make-face 'modeline-mousable-minor-mode
|
|
205 "Face for mousable minor-mode strings in the modeline.")
|
|
206
|
|
207 (defvar modeline-mousable-minor-mode-extent (make-extent nil nil)
|
|
208 ;; alliteration at its finest.
|
|
209 "Extent managing the mousable minor mode modeline strings.")
|
|
210 (set-extent-face modeline-mousable-minor-mode-extent
|
|
211 'modeline-mousable-minor-mode)
|
|
212
|
|
213 ;; This replaces the idiom
|
|
214 ;;
|
|
215 ;; (or (assq 'isearch-mode minor-mode-alist)
|
|
216 ;; (setq minor-mode-alist
|
|
217 ;; (purecopy
|
|
218 ;; (append minor-mode-alist
|
|
219 ;; '((isearch-mode isearch-mode))))))
|
|
220
|
|
221 (defun add-minor-mode (toggle name &optional keymap after toggle-fun)
|
|
222 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
|
|
223 TOGGLE is a symbol whose value as a variable specifies whether the
|
|
224 minor mode is active. NAME is the name that should appear in the
|
|
225 modeline (it should be a string beginning with a space). KEYMAP is a
|
|
226 keymap to make active when the minor mode is active. AFTER is the
|
|
227 toggling symbol used for another minor mode. If AFTER is non-nil,
|
|
228 then it is used to position the new mode in the minor-mode alists.
|
|
229 TOGGLE-FUN specifies an interactive function that is called to toggle
|
|
230 the mode on and off; this affects what happens when button2 is pressed
|
|
231 on the mode, and when button3 is pressed somewhere in the list of
|
|
232 modes. If TOGGLE-FUN is nil and TOGGLE names an interactive function,
|
|
233 TOGGLE is used as the toggle function.
|
|
234
|
|
235 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
|
|
236 (let (el place
|
|
237 (add-elt #'(lambda (elt sym)
|
|
238 (cond ((null after) ; add to front
|
|
239 (set sym (cons elt (symbol-value sym))))
|
|
240 ((and (not (eq after t))
|
|
241 (setq place (memq (assq after
|
|
242 (symbol-value sym))
|
|
243 (symbol-value sym))))
|
|
244 (setq elt (cons elt (cdr place)))
|
|
245 (setcdr place elt))
|
|
246 (t
|
|
247 (set sym (append (symbol-value sym) (list elt))))
|
|
248 )
|
|
249 (symbol-value sym)))
|
|
250 toggle-keymap)
|
|
251 (if toggle-fun
|
|
252 (if (not (commandp toggle-fun))
|
|
253 (error "not an interactive function: %S" toggle-fun))
|
|
254 (if (commandp toggle)
|
|
255 (setq toggle-fun toggle)))
|
|
256 (if (and toggle-fun name)
|
|
257 (progn
|
|
258 (setq toggle-keymap (make-sparse-keymap
|
|
259 (intern (concat "modeline-minor-"
|
|
260 (symbol-name toggle)
|
|
261 "-map"))))
|
|
262 (define-key toggle-keymap 'button2
|
|
263 ;; defeat the DUMB-ASS byte-compiler, which tries to
|
|
264 ;; expand the macro at compile time and fucks up.
|
|
265 (eval '(make-modeline-command-wrapper toggle-fun)))
|
|
266 (put toggle 'modeline-toggle-function toggle-fun)))
|
|
267 (and name
|
|
268 (let ((hacked-name
|
|
269 (if toggle-keymap
|
|
270 (cons (let ((extent (make-extent nil nil)))
|
|
271 (set-extent-keymap extent toggle-keymap)
|
|
272 (set-extent-property
|
|
273 extent 'help-echo
|
|
274 (concat "button2 turns off "
|
|
275 (if (symbolp toggle-fun)
|
|
276 (symbol-name toggle-fun)
|
|
277 (symbol-name toggle))))
|
|
278 extent)
|
|
279 (cons
|
|
280 modeline-mousable-minor-mode-extent
|
|
281 name))
|
|
282 name)))
|
|
283 (if (setq el (assq toggle minor-mode-alist))
|
|
284 (setcdr el (list hacked-name))
|
|
285 (funcall add-elt
|
|
286 (list toggle hacked-name)
|
|
287 'minor-mode-alist))))
|
|
288 (and keymap
|
|
289 (if (setq el (assq toggle minor-mode-map-alist))
|
|
290 (setcdr el keymap)
|
|
291 (funcall add-elt
|
|
292 (cons toggle keymap)
|
|
293 'minor-mode-map-alist)))
|
|
294 ))
|
|
295
|
|
296 (add-minor-mode 'abbrev-mode " Abbrev")
|
|
297 (add-minor-mode 'overwrite-mode 'overwrite-mode)
|
|
298 (add-minor-mode 'auto-fill-function " Fill" nil nil 'auto-fill-mode)
|
|
299 ;; not really a minor mode...
|
|
300 (add-minor-mode 'defining-kbd-macro " Def")
|
|
301
|
|
302 (defun modeline-minor-mode-menu (event)
|
|
303 (interactive "e")
|
110
|
304 (save-excursion
|
|
305 (set-buffer (event-buffer event))
|
|
306 (popup-menu-and-execute-in-window
|
|
307 (cons (format "Minor Mode Commands for %S:"
|
|
308 (buffer-name (event-buffer event)))
|
|
309 (apply 'nconc
|
|
310 (mapcar
|
|
311 #'(lambda (x)
|
|
312 (let* ((toggle-sym (car x))
|
|
313 (toggle-fun
|
|
314 (or (get toggle-sym
|
|
315 'modeline-toggle-function)
|
|
316 (and (fboundp toggle-sym)
|
|
317 (commandp toggle-sym)
|
|
318 toggle-sym))))
|
|
319 (if (not toggle-fun) nil
|
|
320 (list (vector
|
|
321 (concat (if (and (boundp toggle-sym)
|
|
322 (symbol-value toggle-sym))
|
|
323 "turn off " "turn on ")
|
|
324 (if (symbolp toggle-fun)
|
|
325 (symbol-name toggle-fun)
|
|
326 (symbol-name toggle-sym)))
|
|
327
|
|
328 toggle-fun
|
|
329 t)))))
|
|
330 minor-mode-alist)))
|
|
331 event)))
|
0
|
332
|
|
333 (defvar modeline-minor-mode-map (make-sparse-keymap 'modeline-minor-mode-map)
|
|
334 "Keymap consulted for mouse-clicks on the minor-mode modeline list.")
|
|
335 (define-key modeline-minor-mode-map 'button3 'modeline-minor-mode-menu)
|
|
336
|
|
337 (defvar modeline-minor-mode-extent (make-extent nil nil)
|
|
338 "Extent covering the minor mode modeline strings.")
|
|
339 (set-extent-face modeline-minor-mode-extent 'modeline-mousable)
|
|
340 (set-extent-keymap modeline-minor-mode-extent modeline-minor-mode-map)
|
|
341
|
|
342
|
|
343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
344 ;;; Other ;;;
|
|
345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
346
|
|
347 (defun modeline-buffers-menu (event)
|
|
348 (interactive "e")
|
|
349 (popup-menu-and-execute-in-window
|
|
350 '("Buffers Popup Menu"
|
|
351 :filter buffers-menu-filter
|
|
352 ["List All Buffers" list-buffers t]
|
|
353 "--"
|
|
354 )
|
|
355 event))
|
|
356
|
|
357 (defvar modeline-buffer-id-left-map
|
|
358 (make-sparse-keymap 'modeline-buffer-id-left-map)
|
|
359 "Keymap consulted for mouse-clicks on the left half of the buffer-id string.")
|
|
360
|
|
361 (defvar modeline-buffer-id-right-map
|
|
362 (make-sparse-keymap 'modeline-buffer-id-right-map)
|
|
363 "Keymap consulted for mouse-clicks on the right half of the buffer-id string.")
|
|
364
|
|
365 (define-key modeline-buffer-id-left-map 'button2 'mouse-unbury-buffer)
|
|
366 (define-key modeline-buffer-id-right-map 'button2 'mouse-bury-buffer)
|
|
367 (define-key modeline-buffer-id-left-map 'button3 'modeline-buffers-menu)
|
|
368 (define-key modeline-buffer-id-right-map 'button3 'modeline-buffers-menu)
|
|
369
|
|
370 (make-face 'modeline-buffer-id
|
|
371 "Face for the buffer ID string in the modeline.")
|
|
372
|
|
373 (defvar modeline-buffer-id-extent (make-extent nil nil)
|
|
374 "Extent covering the whole of the buffer-id string.")
|
|
375 (set-extent-face modeline-buffer-id-extent 'modeline-buffer-id)
|
|
376
|
|
377 (defvar modeline-buffer-id-left-extent (make-extent nil nil)
|
|
378 "Extent covering the left half of the buffer-id string.")
|
|
379 (set-extent-keymap modeline-buffer-id-left-extent
|
|
380 modeline-buffer-id-left-map)
|
|
381 (set-extent-property modeline-buffer-id-left-extent 'help-echo
|
|
382 "button2 cycles to the previous buffer")
|
|
383
|
|
384 (defvar modeline-buffer-id-right-extent (make-extent nil nil)
|
|
385 "Extent covering the right half of the buffer-id string.")
|
|
386 (set-extent-keymap modeline-buffer-id-right-extent
|
|
387 modeline-buffer-id-right-map)
|
|
388 (set-extent-property modeline-buffer-id-right-extent 'help-echo
|
|
389 "button2 cycles to the next buffer")
|
|
390
|
|
391 (defconst modeline-buffer-identification
|
|
392 (list (cons modeline-buffer-id-left-extent (purecopy "XEmacs:"))
|
|
393 (cons modeline-buffer-id-right-extent (purecopy " %17b")))
|
|
394 "Modeline control for identifying the buffer being displayed.
|
|
395 Its default value is \"XEmacs: %17b\" (NOT!). Major modes that edit things
|
|
396 other than ordinary files may change this (e.g. Info, Dired,...)")
|
|
397 (make-variable-buffer-local 'modeline-buffer-identification)
|
|
398
|
|
399 (defconst modeline-process nil
|
|
400 "Modeline control for displaying info on process status.
|
|
401 Normally nil in most modes, since there is no process to display.")
|
|
402 (make-variable-buffer-local 'modeline-process)
|
|
403
|
|
404 (defvar modeline-modified-map (make-sparse-keymap 'modeline-modified-map)
|
|
405 "Keymap consulted for mouse-clicks on the modeline-modified string.")
|
|
406 (define-key modeline-modified-map 'button2
|
98
|
407 (make-modeline-command-wrapper 'vc-toggle-read-only))
|
0
|
408
|
|
409 (defvar modeline-modified-extent (make-extent nil nil)
|
|
410 "Extent covering the modeline-modified string.")
|
|
411 (set-extent-face modeline-modified-extent 'modeline-mousable)
|
|
412 (set-extent-keymap modeline-modified-extent modeline-modified-map)
|
|
413 (set-extent-property modeline-modified-extent 'help-echo
|
|
414 "button2 toggles the buffer's read-only status")
|
|
415
|
|
416 (defconst modeline-modified (purecopy '("--%1*%1+-"))
|
|
417 "Modeline control for displaying whether current buffer is modified.")
|
|
418 (make-variable-buffer-local 'modeline-modified)
|
|
419
|
|
420 (defvar modeline-narrowed-map (make-sparse-keymap 'modeline-narrowed-map)
|
|
421 "Keymap consulted for mouse-clicks on the modeline-narrowed string.")
|
|
422 (define-key modeline-narrowed-map 'button2
|
|
423 (make-modeline-command-wrapper 'widen))
|
|
424
|
|
425 (defvar modeline-narrowed-extent (make-extent nil nil)
|
|
426 "Extent covering the modeline-narrowed string.")
|
|
427 (set-extent-face modeline-narrowed-extent 'modeline-mousable)
|
|
428 (set-extent-keymap modeline-narrowed-extent modeline-narrowed-map)
|
|
429 (set-extent-property modeline-narrowed-extent 'help-echo
|
|
430 "button2 widens the buffer")
|
|
431
|
70
|
432 (setq-default
|
|
433 modeline-format
|
|
434 (list
|
|
435 (purecopy "")
|
|
436 (cons modeline-modified-extent 'modeline-modified)
|
|
437 (cons modeline-buffer-id-extent 'modeline-buffer-identification)
|
|
438 (purecopy " ")
|
|
439 'global-mode-string
|
|
440 (purecopy " %[(")
|
|
441 (cons modeline-minor-mode-extent (list "" 'mode-name 'minor-mode-alist))
|
|
442 (cons modeline-narrowed-extent "%n")
|
|
443 'modeline-process
|
|
444 (purecopy ")%]----")
|
|
445 (purecopy '(line-number-mode "L%l--"))
|
|
446 (purecopy '(column-number-mode "C%c--"))
|
|
447 (purecopy '(-3 . "%p"))
|
|
448 (purecopy "-%-")))
|