annotate lisp/modeline.el @ 444:576fb035e263 r21-2-37

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