unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* |PATCH| describe-minor-mode and describe-minor-mode-from-indicator
@ 2003-01-18  7:35 Masatake YAMATO
  2003-01-18 14:12 ` Masatake YAMATO
  2003-01-20  0:49 ` Richard Stallman
  0 siblings, 2 replies; 25+ messages in thread
From: Masatake YAMATO @ 2003-01-18  7:35 UTC (permalink / raw)
  Cc: emacs-devel

Dear, Stefan Monnier

(I found your name on the MAINTAINERS file as a developer 
who has interests on minor-mode/major-mode infrastructure.
So I've put your name to To: field of this mail.)

I've created a prototype of describe-minor-mode.

Background: Few days ago, I found a strange string
on mode-line: "doe". I wonder what is "doe". However,
I cannot find a way to know what is doe. M-x describe-mode
tells me nothing about doe. Finally I have to do 
"grep doe emacs/lisp/*.el".

What I did: 
I think we need something help
functions for minor mode. I wrote 3 things:

1. M-x describe-minor-mode
   The user of describe-minor-mode can give its argument
   with completion. The completion table is built from the
   name of minor modes activated on the current buffer.

2. M-x describe-minor-mode-from-indicator
   Almost the same as describe-minor-mode but the user 
   can pass an indicator instead of minor mode name to
   get help. I could not implment completion.
   (You will be not satisfied with "without completion".)

3. I added "Describe `MinorMode'" menu item to "Minor Modes" 
   popup menu. The user can get help about a minor mode with mouse-3.

I believe these functions helps beginner of Emacs. In other word
the user might be confused with strange minor mode strings. 

Regards,
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	18 Jan 2003 08:19:27 -0000
@@ -611,6 +611,20 @@
 	  (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))
+							   (list (symbol-name (car x))))))
+					   minor-mode-alist))))))
+  (if (fboundp minor-mode)
+      (describe-function minor-mode)
+    (describe-variable minor-mode)))
+
+
 \f
 ;;; 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	18 Jan 2003 08:19:28 -0000
@@ -376,6 +376,14 @@
   "Return the value of symbol VAR if it is bound, else nil."
   `(and (boundp (quote ,var)) ,var))
 
+
+(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))
+	      :visible (and mode-line-mode-menu-grab-mode-indicator
+			    (string= " " (substring mode-line-mode-menu-grab-mode-indicator 0 1)))))
+
 (define-key mode-line-mode-menu [overwrite-mode]
   `(menu-item ,(purecopy "Overwrite (Ovwrt)") overwrite-mode
 	      :button (:toggle . overwrite-mode)))
@@ -413,9 +421,49 @@
   `(menu-item ,(purecopy "Abbrev (Abbrev)") abbrev-mode
 	      :button (:toggle . abbrev-mode)))
 
+(defun get-mode-indicator-from-event (event)
+  (car (nth 4 (car (cdr event)))))
+(defvar mode-line-mode-menu-grab-mode-indicator nil)
+
 (defun mode-line-mode-menu (event)
   (interactive "@e")
+  (setq mode-line-mode-menu-grab-mode-indicator (get-mode-indicator-from-event event))
   (x-popup-menu event mode-line-mode-menu))
+
+(defun describe-minor-mode-from-indicator (&optional indicator)
+  "Display documentation of a minor mode specified by INDICATOR."
+  (interactive "sIndicator: ")
+  (unless indicator
+    (setq indicator mode-line-mode-menu-grab-mode-indicator))
+  (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
+    (if minor-mode
+	(describe-minor-mode minor-mode)
+      (message "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)))))
+	(while (and anindicator (symbolp anindicator)
+		    (boundp anindicator)
+		    (not (eq anindicator (symbol-value anindicator))))
+	  (setq anindicator (symbol-value anindicator)))
+	(if (and (consp anindicator) 
+		 (keywordp (car anindicator))
+		 (eq :eval (car anindicator)))
+	    (setq anindicator (eval (cadr anindicator))))
+	(if (and (stringp anindicator) 
+		 (string= anindicator indicator))
+	    (setq result minor-mode
+		  minor-modes nil)
+	  (setq minor-modes (cdr minor-modes)))))
+    result))
 
 ;; Add menu of buffer operations to the buffer identification part
 ;; of the mode line.or header line.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2003-04-12 17:08 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-18  7:35 |PATCH| describe-minor-mode and describe-minor-mode-from-indicator Masatake YAMATO
2003-01-18 14:12 ` Masatake YAMATO
2003-01-20  0:49 ` Richard Stallman
2003-01-20 16:06   ` Masatake YAMATO
2003-01-21  6:00     ` Masatake YAMATO
2003-01-22  9:59     ` Richard Stallman
2003-01-23 17:40       ` Masatake YAMATO
2003-01-25 19:23         ` Richard Stallman
2003-01-30 16:04           ` Masatake YAMATO
     [not found]             ` <E18eghV-0000MM-00@fencepost.gnu.org>
2003-03-30  7:51               ` Masatake YAMATO
2003-03-31 15:51                 ` Stefan Monnier
2003-03-31 16:35                   ` Masatake YAMATO
2003-03-31 17:14                     ` Stefan Monnier
2003-04-01  9:38                   ` Richard Stallman
2003-04-01 12:27                     ` Masatake YAMATO
2003-04-01 12:58                       ` Masatake YAMATO
2003-04-02  9:19                         ` Richard Stallman
2003-04-07 15:46                           ` Masatake YAMATO
2003-04-08  2:30                             ` Richard Stallman
2003-04-10  8:36                               ` Masatake YAMATO
2003-04-10 13:21                                 ` Stefan Monnier
2003-04-11  8:51                                 ` Richard Stallman
2003-04-11 19:30                                   ` Masatake YAMATO
2003-04-12 17:08                                     ` Richard Stallman
2003-04-02  9:18                       ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).