[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: |PATCH| describe-minor-mode and describe-minor-mode-from-indicator
From: |
Masatake YAMATO |
Subject: |
Re: |PATCH| describe-minor-mode and describe-minor-mode-from-indicator |
Date: |
Fri, 31 Jan 2003 01:04:27 +0900 (JST) |
> There is trade-off in two methods: just-one-click or choosing-from-menu.
>
> If you are familiar with Emacs, you will do not hesitate to click the
> mode line because you might know what happens next. You might be satisfied
> with quick operation. Further more, you might think GUI menu is a toy that
> make computer operation slow down.
>
> The tooltip says what the clicks do. If it says "Mouse-1: mode help",
> people won't be scared.
>
> Please put it on mouse-2 and update the tooltip string.
I did. Please try the attached patch.
You don't need to apply patches for ruler-mode.el and subr.el I posted here.
Because some symbols in the new patch are reverted.
Masatake YAMATO
Index: help.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help.el,v
retrieving revision 1.255
diff -u -r1.255 help.el
--- help.el 13 Jan 2003 08:04:46 -0000 1.255
+++ help.el 30 Jan 2003 17:19:07 -0000
@@ -611,6 +611,75 @@
(setq minor-modes (cdr minor-modes))))
(print-help-return-message))))
+(defun describe-minor-mode (minor-mode)
+ "Display documentation of a minor mode given as MINOR-MODE."
+ (interactive (list (intern (completing-read
+ "Minor mode: "
+ (delete nil (mapcar
+ (function (lambda (x)
+ (if (eval (car x))
+ (symbol-name (car
x)))))
+ minor-mode-alist))))))
+ (if (fboundp minor-mode)
+ (describe-function minor-mode)
+ (describe-variable minor-mode)))
+
+(defun describe-minor-mode-from-indicator (indicator)
+ "Display documentation of a minor mode specified by INDICATOR."
+ (interactive (list
+ (completing-read
+ "Minor mode indicator: "
+ (delete nil
+ (mapcar
+ #'(lambda (x)
+ (if (eval (car x))
+ (let ((i (expand-minor-mode-indicator-object
(cadr x))))
+ (if (and (< 0 (length i))
+ (string= " " (substring i 0 1)))
+ (substring i 1)
+ i))))
+ minor-mode-alist)))))
+ (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
+ (if minor-mode
+ (describe-minor-mode minor-mode)
+ (error "Cannot find minor mode for `%s'" indicator))))
+
+(defun lookup-minor-mode-from-indicator (indicator)
+ "Return a minor mode symbol from its indicator on the modeline."
+ (if (and (< 0 (length indicator))
+ (not (string= " " (substring indicator 0 1))))
+ (setq indicator (concat " " indicator)))
+ (let ((minor-modes minor-mode-alist)
+ result)
+ (while minor-modes
+ (let* ((minor-mode (car (car minor-modes)))
+ (anindicator (car (cdr (car minor-modes)))))
+ (setq anindicator (expand-minor-mode-indicator-object anindicator))
+ (if (and (stringp anindicator)
+ (string= anindicator indicator))
+ (setq result minor-mode
+ minor-modes nil)
+ (setq minor-modes (cdr minor-modes)))))
+ result))
+
+(defun expand-minor-mode-indicator-object (obj)
+ "Expand OBJ that represents a minor-mode indicator.
+cdr part of a `minor-mode-alist' element(indicator object) is the
+indicator of minor mode that is in car part. Normally indicator
+object is a string. However, in some case it is more compound object
+like cons cell. This function tries to make the compound object a string."
+ ;; copied from describe-mode
+ (while (and obj (symbolp obj)
+ (boundp obj)
+ (not (eq obj (symbol-value obj))))
+ (setq obj (symbol-value obj)))
+ ;; eval :eval
+ (if (and (consp obj)
+ (keywordp (car obj))
+ (eq :eval (car obj)))
+ (setq obj (eval (cadr obj))))
+ obj)
+
;;; Automatic resizing of temporary buffers.
Index: bindings.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.112
diff -u -r1.112 bindings.el
--- bindings.el 21 Dec 2002 20:19:37 -0000 1.112
+++ bindings.el 30 Jan 2003 17:19:08 -0000
@@ -256,8 +256,16 @@
(defvar mode-line-modes nil
"Mode-line control for displaying major and minor modes.")
+(defvar mode-line-major-mode-keymap nil "\
+Keymap to display on major mode.")
+
(defvar mode-line-minor-mode-keymap nil "\
-Keymap to display on major and minor modes.")
+Keymap to display on minor modes.")
+
+;; Menu of major mode.
+(let ((map (make-sparse-keymap)))
+ (define-key map [mode-line mouse-2] 'describe-mode)
+ (setq mode-line-major-mode-keymap map))
;; Menu of minor modes.
(let ((map (make-sparse-keymap)))
@@ -292,8 +300,15 @@
(setq-default mode-line-modes
(list
(propertize "%[(" 'help-echo help-echo)
- `(:propertize ("" mode-name mode-line-process minor-mode-alist)
- help-echo "mouse-3: minor mode menu"
+ ;; major mode
+ `(:propertize ("" mode-name)
+ help-echo ,#'(lambda (window object point)
+ (format "mouse-2: help for \"%s\""
+ object))
+ local-map ,mode-line-major-mode-keymap)
+ ;; minor modes
+ `(:propertize ("" mode-line-process minor-mode-alist)
+ help-echo "mouse-3: minor modes menu"
local-map ,mode-line-minor-mode-keymap)
(propertize "%n" 'help-echo "mouse-2: widen"
'local-map (make-mode-line-mouse-map
@@ -413,9 +428,23 @@
`(menu-item ,(purecopy "Abbrev (Abbrev)") abbrev-mode
:button (:toggle . abbrev-mode)))
+(defvar mode-line-mode-menu-grab-mode-indicator nil)
+(autoload 'describe-minor-mode-from-indicator "help"
+ "Display documentation of a minor mode given as MINOR-MODE." t)
+(define-key mode-line-mode-menu [describe-minor-mode]
+ `(menu-item ,'(format "Describe `%s'"
+ (substring mode-line-mode-menu-grab-mode-indicator 1))
+ (lambda ()
+ (interactive)
+ (describe-minor-mode-from-indicator
+ mode-line-mode-menu-grab-mode-indicator))
+ :visible (and mode-line-mode-menu-grab-mode-indicator
+ (string= " " (substring
mode-line-mode-menu-grab-mode-indicator 0 1)))))
(defun mode-line-mode-menu (event)
(interactive "@e")
- (x-popup-menu event mode-line-mode-menu))
+ (let ((get-mode-indicator-from-event #'(lambda (e) (car (nth 4 (car (cdr
e)))))))
+ (setq mode-line-mode-menu-grab-mode-indicator (funcall
get-mode-indicator-from-event event))
+ (x-popup-menu event mode-line-mode-menu)))
;; Add menu of buffer operations to the buffer identification part
;; of the mode line.or header line.