[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: Sun, 30 Mar 2003 16:51:24 +0900 (JST)

(Two months ago, my patch is reviewd by RMS and I got comments about help 
for minor modes. I could not find time to improve. Now I do.)

This patch provides functions that:

1. you can get help for current selected major mode and minor modes
   with clicking major and minor modes string on the mode line.
2. M-x describe-minor-mode, help for a specified minor mode like 
   M-x describe-mode.

Review results(summary): 

I used popup menu to invoke describe-mode and describe-minor-mode.
RMS gave me a comment that I should use mouse-2 and help-echo instead
of popup menu. Here I did.

Masatake YAMATO

2003-03-30  Masatake YAMATO  <address@hidden>

        * bindings.el (mode-line-major-mode-keymap): New variable.
        (mode-line-minor-mode-help): New function. bound to 
        (mode-line-modes): split mode-line-mode definitions to
        mode-name, mode-line-process and minor-mode-alist.
        For mode-name, mode-line-major-mode-keymap is used.

        * help.el (describe-minor-mode): 
        (lookup-minor-mode-from-indicator): New functions.

Index: help.el
RCS file: /cvsroot/emacs/emacs/lisp/help.el,v
retrieving revision 1.257
diff -u -r1.257 help.el
--- help.el     12 Feb 2003 23:13:43 -0000      1.257
+++ help.el     30 Mar 2003 08:13:16 -0000
@@ -611,6 +611,74 @@
          (setq minor-modes (cdr minor-modes))))
+(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 
+                                          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)))
+  (when (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 Mar 2003 08:13:16 -0000
@@ -256,11 +256,19 @@
 (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.")
+(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)))
+  (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help)
   (define-key map [mode-line down-mouse-3] 'mode-line-mode-menu-1)
   (define-key map [header-line down-mouse-3] 'mode-line-mode-menu-1)
   (setq mode-line-minor-mode-keymap map))
@@ -292,8 +300,12 @@
   (setq-default mode-line-modes
      (propertize "%[(" 'help-echo help-echo)
-     `(:propertize ("" mode-name mode-line-process minor-mode-alist)
-                  help-echo "mouse-3: minor mode menu"
+     `(:propertize ("" mode-name)
+                  help-echo "mouse-2: help for current major mode"
+                  local-map ,mode-line-major-mode-keymap)
+     `(:propertize ("" mode-line-process))
+     `(:propertize ("" minor-mode-alist)
+                  help-echo "mouse-2: help for minor modes, mouse-3: minor 
mode menu"
                   local-map ,mode-line-minor-mode-keymap)
      (propertize "%n" 'help-echo "mouse-2: widen"
                 'local-map (make-mode-line-mouse-map
@@ -416,6 +428,12 @@
 (defun mode-line-mode-menu (event)
   (interactive "@e")
   (x-popup-menu event mode-line-mode-menu))
+(defun mode-line-minor-mode-help (event)
+  "Describe minor mode for EVENT occured on minor modes area of the mode line."
+  (interactive "@e")
+  (let ((indicator (car (nth 4 (car (cdr event))))))
+    (describe-minor-mode-from-indicator indicator)))
 ;; Add menu of buffer operations to the buffer identification part
 ;; of the mode line.or header line.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]