aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorChong Yidong2012-06-03 17:03:23 +0800
committerChong Yidong2012-06-03 17:03:23 +0800
commit5f2c76c6cee2b5d2d84ffd409839fd58d2ad16fa (patch)
treeccab5d66cbd6666671d529849c174c5701508d1e /lisp
parent773d47f6b23a2294baaf577f5cb783338232008c (diff)
downloademacs-5f2c76c6cee2b5d2d84ffd409839fd58d2ad16fa.tar.gz
emacs-5f2c76c6cee2b5d2d84ffd409839fd58d2ad16fa.zip
Implement default help-echo for mode line.
* lisp/bindings.el: Remove explicit help-echo from format-mode-line. (mode-line-front-space, mode-line-end-spaces) (mode-line-misc-info): New variables. (mode-line-modes, mode-line-position): Move the default value to the variable definition. (mode-line-default-help-echo): New defcustom. * src/buffer.c (buffer_local_value_1): New function, split from Fbuffer_local_value; can return Qunbound. (Fbuffer_local_value): Use it. (Vmode_line_format): Docstring tweaks. * src/xdisp.c (calc_pixel_width_or_height): Use Fbuffer_local_value. (note_mode_line_or_margin_highlight): If there is no help echo, use mode-line-default-help-echo. Handle the case where the mouse position is past the end of the mode line string. * doc/lispref/modes.texi (Mode Line Data): Use "mode line construct" terminology for consistency.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/bindings.el313
2 files changed, 165 insertions, 158 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e39b8a64205..5a3b1d3926d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12012-06-03 Chong Yidong <cyd@gnu.org>
2
3 * bindings.el: Remove explicit help text from format-mode-line.
4 It is now supplied by mode-line-default-help-echo.
5 (mode-line-front-space, mode-line-end-spaces)
6 (mode-line-misc-info): New variables.
7 (mode-line-modes, mode-line-position): Move the default value to
8 the variable definition.
9 (mode-line-default-help-echo): New defcustom.
10
12012-06-02 Stefan Monnier <monnier@iro.umontreal.ca> 112012-06-02 Stefan Monnier <monnier@iro.umontreal.ca>
2 12
3 * simple.el (execute-extended-command): Set real-this-command 13 * simple.el (execute-extended-command): Set real-this-command
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 69d96ab6889..65dd68a4447 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -43,7 +43,6 @@ corresponding to the mode line clicked."
43 (with-no-warnings (toggle-read-only)) 43 (with-no-warnings (toggle-read-only))
44 (force-mode-line-update))) 44 (force-mode-line-update)))
45 45
46
47(defun mode-line-toggle-modified (event) 46(defun mode-line-toggle-modified (event)
48 "Toggle the buffer-modified flag from the mode-line." 47 "Toggle the buffer-modified flag from the mode-line."
49 (interactive "e") 48 (interactive "e")
@@ -52,7 +51,6 @@ corresponding to the mode line clicked."
52 (set-buffer-modified-p (not (buffer-modified-p))) 51 (set-buffer-modified-p (not (buffer-modified-p)))
53 (force-mode-line-update))) 52 (force-mode-line-update)))
54 53
55
56(defun mode-line-widen (event) 54(defun mode-line-widen (event)
57 "Widen a buffer from the mode-line." 55 "Widen a buffer from the mode-line."
58 (interactive "e") 56 (interactive "e")
@@ -61,7 +59,6 @@ corresponding to the mode line clicked."
61 (widen) 59 (widen)
62 (force-mode-line-update))) 60 (force-mode-line-update)))
63 61
64
65(defvar mode-line-input-method-map 62(defvar mode-line-input-method-map
66 (let ((map (make-sparse-keymap))) 63 (let ((map (make-sparse-keymap)))
67 (define-key map [mode-line mouse-2] 64 (define-key map [mode-line mouse-2]
@@ -81,7 +78,6 @@ corresponding to the mode line clicked."
81 (describe-current-input-method)))) 78 (describe-current-input-method))))
82 (purecopy map))) 79 (purecopy map)))
83 80
84
85(defvar mode-line-coding-system-map 81(defvar mode-line-coding-system-map
86 (let ((map (make-sparse-keymap))) 82 (let ((map (make-sparse-keymap)))
87 (define-key map [mode-line mouse-1] 83 (define-key map [mode-line mouse-1]
@@ -95,7 +91,6 @@ corresponding to the mode line clicked."
95 (purecopy map)) 91 (purecopy map))
96 "Local keymap for the coding-system part of the mode line.") 92 "Local keymap for the coding-system part of the mode line.")
97 93
98
99(defun mode-line-change-eol (event) 94(defun mode-line-change-eol (event)
100 "Cycle through the various possible kinds of end-of-line styles." 95 "Cycle through the various possible kinds of end-of-line styles."
101 (interactive "e") 96 (interactive "e")
@@ -130,13 +125,28 @@ corresponding to the mode line clicked."
130 (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache) 125 (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
131 desc))) 126 desc)))
132 127
133(defvar mode-line-client 128
134 `("" 129;;; Mode line contents
135 (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" ""))) 130
136 help-echo ,(purecopy "emacsclient frame"))) 131(defcustom mode-line-default-help-echo
137 "Mode-line control for identifying emacsclient frames.") 132 "mouse-1: Select (drag to resize)\n\
138;;;###autoload 133mouse-2: Make current window occupy the whole frame\n\
139(put 'mode-line-client 'risky-local-variable t) 134mouse-3: Remove current window from display"
135 "Default help text for the mode line.
136If the value is a string, it specifies the tooltip or echo area
137message to display when the mouse is moved over the mode line.
138If the text at the mouse position has a `help-echo' text
139property, that overrides this variable."
140 :type '(choice (const :tag "No help" :value nil) string)
141 :version "24.2"
142 :group 'mode-line)
143
144(defvar mode-line-front-space '(:eval (if (display-graphic-p) " " "-"))
145 "Mode line construct to put at the front of the mode line.
146By default, this construct is displayed right at the beginning of
147the mode line, except that if there is a memory-full message, it
148is displayed first.")
149(put 'mode-line-front-space 'risky-local-variable t)
140 150
141(defvar mode-line-mule-info 151(defvar mode-line-mule-info
142 `("" 152 `(""
@@ -167,7 +177,7 @@ mouse-3: Describe current input method"))
167 'mouse-face 'mode-line-highlight 177 'mouse-face 'mode-line-highlight
168 'local-map mode-line-coding-system-map) 178 'local-map mode-line-coding-system-map)
169 (:eval (mode-line-eol-desc))) 179 (:eval (mode-line-eol-desc)))
170 "Mode-line control for displaying information of multilingual environment. 180 "Mode line construct for displaying information of multilingual environment.
171Normally it displays current input method (if any activated) and 181Normally it displays current input method (if any activated) and
172mnemonics of the following coding systems: 182mnemonics of the following coding systems:
173 coding system for saving or writing the current buffer 183 coding system for saving or writing the current buffer
@@ -177,34 +187,17 @@ mnemonics of the following coding systems:
177 ;; coding system for decoding output of buffer process (if any) 187 ;; coding system for decoding output of buffer process (if any)
178 ;; coding system for encoding text to send to buffer process (if any)." 188 ;; coding system for encoding text to send to buffer process (if any)."
179) 189)
180
181;;;###autoload 190;;;###autoload
182(put 'mode-line-mule-info 'risky-local-variable t) 191(put 'mode-line-mule-info 'risky-local-variable t)
183(make-variable-buffer-local 'mode-line-mule-info) 192(make-variable-buffer-local 'mode-line-mule-info)
184 193
185;; MSDOS frames have window-system, but want the Fn identification. 194(defvar mode-line-client
186(defun mode-line-frame-control () 195 `(""
187 "Compute mode-line control for frame identification. 196 (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" "")))
188Value is used for `mode-line-frame-identification', which see." 197 help-echo ,(purecopy "emacsclient frame")))
189 (if (or (null window-system) 198 "Mode line construct for identifying emacsclient frames.")
190 (eq window-system 'pc))
191 "-%F "
192 " "))
193
194;; We need to defer the call to mode-line-frame-control to the time
195;; the mode line is actually displayed.
196(defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
197 "Mode-line control to describe the current frame.")
198;;;###autoload
199(put 'mode-line-frame-identification 'risky-local-variable t)
200
201(defvar mode-line-process nil "\
202Mode-line control for displaying info on process status.
203Normally nil in most modes, since there is no process to display.")
204
205;;;###autoload 199;;;###autoload
206(put 'mode-line-process 'risky-local-variable t) 200(put 'mode-line-client 'risky-local-variable t)
207(make-variable-buffer-local 'mode-line-process)
208 201
209(defvar mode-line-modified 202(defvar mode-line-modified
210 (list (propertize 203 (list (propertize
@@ -232,8 +225,7 @@ Normally nil in most modes, since there is no process to display.")
232 'local-map (purecopy (make-mode-line-mouse-map 225 'local-map (purecopy (make-mode-line-mouse-map
233 'mouse-1 #'mode-line-toggle-modified)) 226 'mouse-1 #'mode-line-toggle-modified))
234 'mouse-face 'mode-line-highlight)) 227 'mouse-face 'mode-line-highlight))
235 "Mode-line control for displaying whether current buffer is modified.") 228 "Mode line construct for displaying whether current buffer is modified.")
236
237;;;###autoload 229;;;###autoload
238(put 'mode-line-modified 'risky-local-variable t) 230(put 'mode-line-modified 'risky-local-variable t)
239(make-variable-buffer-local 'mode-line-modified) 231(make-variable-buffer-local 'mode-line-modified)
@@ -251,24 +243,33 @@ Normally nil in most modes, since there is no process to display.")
251 "Current directory is remote: " 243 "Current directory is remote: "
252 "Current directory is local: ") 244 "Current directory is local: ")
253 default-directory))))))) 245 default-directory)))))))
254 "Mode-line flag to show if default-directory for current buffer is remote.") 246 "Mode line construct to indicate a remote buffer.")
255;;;###autoload 247;;;###autoload
256(put 'mode-line-remote 'risky-local-variable t) 248(put 'mode-line-remote 'risky-local-variable t)
257
258(make-variable-buffer-local 'mode-line-remote) 249(make-variable-buffer-local 'mode-line-remote)
259 250
260;; Actual initialization is below. 251;; MSDOS frames have window-system, but want the Fn identification.
261(defvar mode-line-position nil 252(defun mode-line-frame-control ()
262 "Mode-line control for displaying the position in the buffer. 253 "Compute mode line construct for frame identification.
263Normally displays the buffer percentage and, optionally, the 254Value is used for `mode-line-frame-identification', which see."
264buffer size, the line number and the column number.") 255 (if (or (null window-system)
256 (eq window-system 'pc))
257 "-%F "
258 " "))
259
260;; We need to defer the call to mode-line-frame-control to the time
261;; the mode line is actually displayed.
262(defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
263 "Mode line construct to describe the current frame.")
265;;;###autoload 264;;;###autoload
266(put 'mode-line-position 'risky-local-variable t) 265(put 'mode-line-frame-identification 'risky-local-variable t)
267 266
268(defvar mode-line-modes nil 267(defvar mode-line-process nil
269 "Mode-line control for displaying major and minor modes.") 268 "Mode line construct for displaying info on process status.
269Normally nil in most modes, since there is no process to display.")
270;;;###autoload 270;;;###autoload
271(put 'mode-line-modes 'risky-local-variable t) 271(put 'mode-line-process 'risky-local-variable t)
272(make-variable-buffer-local 'mode-line-process)
272 273
273(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\ 274(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
274Menu of mode operations in the mode line.") 275Menu of mode operations in the mode line.")
@@ -292,6 +293,35 @@ Keymap to display on major mode.")
292 map) "\ 293 map) "\
293Keymap to display on minor modes.") 294Keymap to display on minor modes.")
294 295
296(defvar mode-line-modes
297 (let ((recursive-edit-help-echo "Recursive edit, type C-M-c to get out"))
298 (list (propertize "%[" 'help-echo recursive-edit-help-echo)
299 "("
300 `(:propertize ("" mode-name)
301 help-echo "Major mode\n\
302mouse-1: Display major mode menu\n\
303mouse-2: Show help for major mode\n\
304mouse-3: Toggle minor modes"
305 mouse-face mode-line-highlight
306 local-map ,mode-line-major-mode-keymap)
307 '("" mode-line-process)
308 `(:propertize ("" minor-mode-alist)
309 mouse-face mode-line-highlight
310 help-echo "Minor mode\n\
311mouse-1: Display minor mode menu\n\
312mouse-2: Show help for minor mode\n\
313mouse-3: Toggle minor modes"
314 local-map ,mode-line-minor-mode-keymap)
315 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from the current buffer"
316 'mouse-face 'mode-line-highlight
317 'local-map (make-mode-line-mouse-map
318 'mouse-2 #'mode-line-widen))
319 ")"
320 (propertize "%]" 'help-echo recursive-edit-help-echo)
321 " "))
322 "Mode line construct for displaying major and minor modes.")
323(put 'mode-line-modes 'risky-local-variable t)
324
295(defvar mode-line-column-line-number-mode-map 325(defvar mode-line-column-line-number-mode-map
296 (let ((map (make-sparse-keymap)) 326 (let ((map (make-sparse-keymap))
297 (menu-map (make-sparse-keymap "Toggle Line and Column Number Display"))) 327 (menu-map (make-sparse-keymap "Toggle Line and Column Number Display")))
@@ -307,114 +337,47 @@ Keymap to display on minor modes.")
307 map) "\ 337 map) "\
308Keymap to display on column and line numbers.") 338Keymap to display on column and line numbers.")
309 339
310(let* ((help-echo 340(defvar mode-line-position
311 ;; The multi-line message doesn't work terribly well on the 341 `((-3 ,(propertize
312 ;; bottom mode line... Better ideas? 342 "%p"
313 ;; "\ 343 'local-map mode-line-column-line-number-mode-map
314 ;; mouse-1: select window, mouse-2: delete others, mouse-3: delete, 344 'mouse-face 'mode-line-highlight
315 ;; drag-mouse-1: resize, C-mouse-2: split horizontally" 345 ;; XXX needs better description
316 "mouse-1: Select (drag to resize)\n\ 346 'help-echo "Size indication mode\n\
317mouse-2: Make current window occupy the whole frame\n\
318mouse-3: Remove current window from display")
319 (recursive-edit-help-echo "Recursive edit, type C-M-c to get out")
320 (spaces (propertize " " 'help-echo help-echo))
321 (standard-mode-line-format
322 (list
323 "%e"
324 `(:eval (if (display-graphic-p)
325 ,(propertize " " 'help-echo help-echo)
326 ,(propertize "-" 'help-echo help-echo)))
327 'mode-line-mule-info
328 'mode-line-client
329 'mode-line-modified
330 'mode-line-remote
331 'mode-line-frame-identification
332 'mode-line-buffer-identification
333 (propertize " " 'help-echo help-echo)
334 'mode-line-position
335 '(vc-mode vc-mode)
336 (propertize " " 'help-echo help-echo)
337 'mode-line-modes
338 `(which-func-mode ("" which-func-format ,spaces))
339 `(global-mode-string ("" global-mode-string ,spaces))
340 `(:eval (unless (display-graphic-p)
341 ,(propertize "-%-" 'help-echo help-echo)))))
342 (standard-mode-line-modes
343 (list
344 (propertize "%[" 'help-echo recursive-edit-help-echo)
345 (propertize "(" 'help-echo help-echo)
346 `(:propertize ("" mode-name)
347 help-echo "Major mode\n\
348mouse-1: Display major mode menu\n\
349mouse-2: Show help for major mode\n\
350mouse-3: Toggle minor modes"
351 mouse-face mode-line-highlight
352 local-map ,mode-line-major-mode-keymap)
353 '("" mode-line-process)
354 `(:propertize ("" minor-mode-alist)
355 mouse-face mode-line-highlight
356 help-echo "Minor mode\n\
357mouse-1: Display minor mode menu\n\
358mouse-2: Show help for minor mode\n\
359mouse-3: Toggle minor modes"
360 local-map ,mode-line-minor-mode-keymap)
361 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from the current buffer"
362 'mouse-face 'mode-line-highlight
363 'local-map (make-mode-line-mouse-map
364 'mouse-2 #'mode-line-widen))
365 (propertize ")" 'help-echo help-echo)
366 (propertize "%]" 'help-echo recursive-edit-help-echo)
367 spaces))
368
369 (standard-mode-line-position
370 `((-3 ,(propertize
371 "%p"
372 'local-map mode-line-column-line-number-mode-map
373 'mouse-face 'mode-line-highlight
374 ;; XXX needs better description
375 'help-echo "Size indication mode\n\
376mouse-1: Display Line and Column Mode Menu")) 347mouse-1: Display Line and Column Mode Menu"))
377 (size-indication-mode 348 (size-indication-mode
378 (8 ,(propertize 349 (8 ,(propertize
379 " of %I" 350 " of %I"
380 'local-map mode-line-column-line-number-mode-map 351 'local-map mode-line-column-line-number-mode-map
381 'mouse-face 'mode-line-highlight 352 'mouse-face 'mode-line-highlight
382 ;; XXX needs better description 353 ;; XXX needs better description
383 'help-echo "Size indication mode\n\ 354 'help-echo "Size indication mode\n\
384mouse-1: Display Line and Column Mode Menu"))) 355mouse-1: Display Line and Column Mode Menu")))
385 (line-number-mode 356 (line-number-mode
386 ((column-number-mode 357 ((column-number-mode
387 (10 ,(propertize 358 (10 ,(propertize
388 " (%l,%c)" 359 " (%l,%c)"
389 'local-map mode-line-column-line-number-mode-map 360 'local-map mode-line-column-line-number-mode-map
390 'mouse-face 'mode-line-highlight 361 'mouse-face 'mode-line-highlight
391 'help-echo "Line number and Column number\n\ 362 'help-echo "Line number and Column number\n\
392mouse-1: Display Line and Column Mode Menu")) 363mouse-1: Display Line and Column Mode Menu"))
393 (6 ,(propertize 364 (6 ,(propertize
394 " L%l" 365 " L%l"
395 'local-map mode-line-column-line-number-mode-map 366 'local-map mode-line-column-line-number-mode-map
396 'mouse-face 'mode-line-highlight 367 'mouse-face 'mode-line-highlight
397 'help-echo "Line Number\n\ 368 'help-echo "Line Number\n\
398mouse-1: Display Line and Column Mode Menu")))) 369mouse-1: Display Line and Column Mode Menu"))))
399 ((column-number-mode 370 ((column-number-mode
400 (5 ,(propertize 371 (5 ,(propertize
401 " C%c" 372 " C%c"
402 'local-map mode-line-column-line-number-mode-map 373 'local-map mode-line-column-line-number-mode-map
403 'mouse-face 'mode-line-highlight 374 'mouse-face 'mode-line-highlight
404 'help-echo "Column number\n\ 375 'help-echo "Column number\n\
405mouse-1: Display Line and Column Mode Menu")))))))) 376mouse-1: Display Line and Column Mode Menu"))))))
406 377 "Mode line construct for displaying the position in the buffer.
407 (setq-default mode-line-format standard-mode-line-format) 378Normally displays the buffer percentage and, optionally, the
408 (put 'mode-line-format 'standard-value 379buffer size, the line number and the column number.")
409 (list `(quote ,standard-mode-line-format))) 380(put 'mode-line-position 'risky-local-variable t)
410
411 (setq-default mode-line-modes standard-mode-line-modes)
412 (put 'mode-line-modes 'standard-value
413 (list `(quote ,standard-mode-line-modes)))
414
415 (setq-default mode-line-position standard-mode-line-position)
416 (put 'mode-line-position 'standard-value
417 (list `(quote ,standard-mode-line-position))))
418 381
419(defvar mode-line-buffer-identification-keymap 382(defvar mode-line-buffer-identification-keymap
420 ;; Add menu of buffer operations to the buffer identification part 383 ;; Add menu of buffer operations to the buffer identification part
@@ -444,16 +407,50 @@ mouse-3: next buffer")
444 'mouse-face 'mode-line-highlight 407 'mouse-face 'mode-line-highlight
445 'local-map mode-line-buffer-identification-keymap))) 408 'local-map mode-line-buffer-identification-keymap)))
446 409
447(defvar mode-line-buffer-identification (propertized-buffer-identification "%12b") "\ 410(defvar mode-line-buffer-identification
448Mode-line control for identifying the buffer being displayed. 411 (propertized-buffer-identification "%12b")
412 "Mode line construct for identifying the buffer being displayed.
449Its default value is (\"%12b\") with some text properties added. 413Its default value is (\"%12b\") with some text properties added.
450Major modes that edit things other than ordinary files may change this 414Major modes that edit things other than ordinary files may change this
451\(e.g. Info, Dired,...)") 415\(e.g. Info, Dired,...)")
452
453;;;###autoload 416;;;###autoload
454(put 'mode-line-buffer-identification 'risky-local-variable t) 417(put 'mode-line-buffer-identification 'risky-local-variable t)
455(make-variable-buffer-local 'mode-line-buffer-identification) 418(make-variable-buffer-local 'mode-line-buffer-identification)
456 419
420(defvar mode-line-misc-info
421 '((which-func-mode ("" which-func-format " "))
422 (global-mode-string ("" global-mode-string " ")))
423 "Mode line construct for miscellaneous information.
424By default, this shows the information specified by
425`which-func-mode' and `global-mode-string'.")
426(put 'mode-line-misc-info 'risky-local-variable t)
427
428(defvar mode-line-end-spaces '(:eval (unless (display-graphic-p) "-%-"))
429 "Mode line construct to put at the end of the mode line.")
430(put 'mode-line-end-spaces 'risky-local-variable t)
431
432;; Default value of the top-level `mode-line-format' variable:
433(let ((standard-mode-line-format
434 (list "%e"
435 'mode-line-front-space
436 'mode-line-mule-info
437 'mode-line-client
438 'mode-line-modified
439 'mode-line-remote
440 'mode-line-frame-identification
441 'mode-line-buffer-identification
442 " "
443 'mode-line-position
444 '(vc-mode vc-mode)
445 " "
446 'mode-line-modes
447 'mode-line-misc-info
448 'mode-line-end-spaces)))
449 (setq-default mode-line-format standard-mode-line-format)
450 (put 'mode-line-format 'standard-value
451 (list `(quote ,standard-mode-line-format))))
452
453
457(defun mode-line-unbury-buffer (event) "\ 454(defun mode-line-unbury-buffer (event) "\
458Call `unbury-buffer' in this window." 455Call `unbury-buffer' in this window."
459 (interactive "e") 456 (interactive "e")
@@ -551,8 +548,8 @@ Alist saying how to show minor modes in the mode line.
551Each element looks like (VARIABLE STRING); 548Each element looks like (VARIABLE STRING);
552STRING is included in the mode line if VARIABLE's value is non-nil. 549STRING is included in the mode line if VARIABLE's value is non-nil.
553 550
554Actually, STRING need not be a string; any possible mode-line element 551Actually, STRING need not be a string; any mode-line construct is
555is okay. See `mode-line-format'.") 552okay. See `mode-line-format'.")
556;;;###autoload 553;;;###autoload
557(put 'minor-mode-alist 'risky-local-variable t) 554(put 'minor-mode-alist 'risky-local-variable t)
558;; Don't use purecopy here--some people want to change these strings. 555;; Don't use purecopy here--some people want to change these strings.