comparison lisp/modeline.el @ 241:f955c73f5258 r20-5b19

Import from CVS: tag r20-5b19
author cvs
date Mon, 13 Aug 2007 10:16:16 +0200
parents 0e522484dd2a
children 65c19d2020f7
comparison
equal deleted inserted replaced
240:835e739f3c17 241:f955c73f5258
298 ;; '((isearch-mode isearch-mode)))))) 298 ;; '((isearch-mode isearch-mode))))))
299 299
300 (defvar place) 300 (defvar place)
301 (defun add-minor-mode (toggle name &optional keymap after toggle-fun) 301 (defun add-minor-mode (toggle name &optional keymap after toggle-fun)
302 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'. 302 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
303
303 TOGGLE is a symbol whose value as a variable specifies whether the 304 TOGGLE is a symbol whose value as a variable specifies whether the
304 minor mode is active. NAME is the name that should appear in the 305 minor mode is active.
305 modeline (it should either be a string beginning with a space or a 306
306 symbol). KEYMAP is a keymap to make active when the minor mode is 307 If TOGGLE has the `:menu-tag' property set to a string, that string
307 active. AFTER is the toggling symbol used for another minor mode. If 308 will be used as the label on the `modeline-minor-mode-menu' instead
308 AFTER is non-nil, then it is used to position the new mode in the 309 of TOGGLE's symbol-name.
309 minor-mode alists. TOGGLE-FUN specifies an interactive function that 310
310 is called to toggle the mode on and off; this affects what happens 311 TOGGLE may have an `:included' property, which determines whether a
311 when button2 is pressed on the mode, and when button3 is pressed 312 menu button will be shown for this minor mode in the
312 somewhere in the list of modes. If TOGGLE-FUN is nil and TOGGLE names 313 `modeline-minor-mode-menu'. This should be either a boolean
313 an interactive function, TOGGLE is used as the toggle function. 314 variable, or an expression evaluating to t or nil. \(See the
314 315 documentation of `current-menubar' for more information.)
315 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)" 316
317 It may have an `:active' property also, as documented in
318 `current-menubar'.
319
320 NAME is the name that should appear in the modeline. It should either
321 be a string beginning with a space, or a symbol with a similar string
322 as its value.
323
324 KEYMAP is a keymap to make active when the minor mode is active.
325
326 AFTER is the toggling symbol used for another minor mode. If AFTER is
327 non-nil, then it is used to position the new mode in the minor-mode
328 alists.
329
330 TOGGLE-FUN specifies an interactive function that is called to toggle
331 the mode on and off; this affects what happens when button2 is pressed
332 on the mode, and when button3 is pressed somewhere in the list of
333 modes. If TOGGLE-FUN is nil and TOGGLE names an interactive function,
334 TOGGLE is used as the toggle function.
335
336 Example: (put 'view-minor-mode :menu-tag \"View (minor)\")
337 (put 'view-minor-mode :included '(buffer-file-name))
338 (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
316 (let (el place 339 (let (el place
317 (add-elt #'(lambda (elt sym) 340 (add-elt #'(lambda (elt sym)
318 (cond ((null after) ; add to front 341 (cond ((null after) ; add to front
319 (set sym (cons elt (symbol-value sym)))) 342 (set sym (cons elt (symbol-value sym))))
320 ((and (not (eq after t)) 343 ((and (not (eq after t))
371 (funcall add-elt 394 (funcall add-elt
372 (cons toggle keymap) 395 (cons toggle keymap)
373 'minor-mode-map-alist))) 396 'minor-mode-map-alist)))
374 )) 397 ))
375 398
399 ;; gettext anyone?
400 (put 'abbrev-mode :menu-tag "Abbreviation Expansion")
376 (add-minor-mode 'abbrev-mode " Abbrev") 401 (add-minor-mode 'abbrev-mode " Abbrev")
402 ;; only when visiting a file...
377 (add-minor-mode 'overwrite-mode 'overwrite-mode) 403 (add-minor-mode 'overwrite-mode 'overwrite-mode)
404 (put 'auto-fill-function :menu-tag "Auto Fill")
378 (add-minor-mode 'auto-fill-function " Fill" nil nil 'auto-fill-mode) 405 (add-minor-mode 'auto-fill-function " Fill" nil nil 'auto-fill-mode)
379 ;; not really a minor mode... 406
380 (add-minor-mode 'defining-kbd-macro " Def") 407 ;; what's the meaning of `####' vs `FIXME' or ...?
408 ;; not really a minor mode... and it doesn't work right anyway.
409 ;;(put 'defining-kbd-macro :menu-tag "Defining kbd macro")
410 ;;(add-minor-mode 'defining-kbd-macro " Def") FIXME
381 411
382 (defun modeline-minor-mode-menu (event) 412 (defun modeline-minor-mode-menu (event)
413 "The menu that pops up when you press `button3' inside the
414 parentheses on the modeline."
383 (interactive "e") 415 (interactive "e")
384 (save-excursion 416 (save-excursion
385 (set-buffer (event-buffer event)) 417 (set-buffer (event-buffer event))
386 (popup-menu-and-execute-in-window 418 (popup-menu-and-execute-in-window
387 (cons (format "Minor Mode Commands for %S:" 419 (cons "Minor Mode Toggles"
388 (buffer-name (event-buffer event)))
389 (apply 'nconc 420 (apply 'nconc
390 (mapcar 421 (mapcar
391 #'(lambda (x) 422 #'(lambda (x)
392 (let* ((toggle-sym (car x)) 423 (let* ((toggle-sym (car x))
424 (menu-tag (get toggle-sym :menu-tag nil))
393 (toggle-fun 425 (toggle-fun
394 (or (get toggle-sym 426 (or (get toggle-sym
395 'modeline-toggle-function) 427 'modeline-toggle-function)
396 (and (fboundp toggle-sym) 428 (and (fboundp toggle-sym)
397 (commandp toggle-sym) 429 (commandp toggle-sym)
398 toggle-sym)))) 430 toggle-sym))))
399 (if (not toggle-fun) nil 431 (if (not toggle-fun) nil
400 (list (vector 432 (list (vector
401 (concat (if (and (boundp toggle-sym) 433 (or (and (stringp menu-tag)
402 (symbol-value toggle-sym)) 434 menu-tag)
403 "turn off " "turn on ") 435 (setq menu-tag (capitalize
404 (if (symbolp toggle-fun) 436 (replace-in-string
405 (symbol-name toggle-fun) 437 (replace-in-string
406 (symbol-name toggle-sym))) 438 (replace-in-string (if (symbolp toggle-fun)
407 439 (symbol-name toggle-fun)
440 (symbol-name toggle-sym))
441 "-" " ")
442 "minor" " (minor)")
443 " mode" ""))))
408 toggle-fun 444 toggle-fun
409 t))))) 445 :active (get toggle-sym :active t)
446 :included (get toggle-sym :included t)
447 :style 'toggle
448 :selected (and (boundp toggle-sym)
449 toggle-sym))))))
410 minor-mode-alist))) 450 minor-mode-alist)))
411 event))) 451 event)))
412 452
413 (defvar modeline-minor-mode-map (make-sparse-keymap 'modeline-minor-mode-map) 453 (defvar modeline-minor-mode-map (make-sparse-keymap 'modeline-minor-mode-map)
414 "Keymap consulted for mouse-clicks on the minor-mode modeline list.") 454 "Keymap consulted for mouse-clicks on the minor-mode modeline list.")