]> git.eshelyaron.com Git - emacs.git/commitdiff
* mouse.el (minor-mode-menu-from-indicator): Create a menu with a
authorDan Nicolaescu <dann@ics.uci.edu>
Thu, 21 Feb 2008 09:15:32 +0000 (09:15 +0000)
committerDan Nicolaescu <dann@ics.uci.edu>
Thu, 21 Feb 2008 09:15:32 +0000 (09:15 +0000)
"Turn off" and a "Help" entry when the minor mode has no menu.

lisp/ChangeLog
lisp/mouse.el

index 132a8cee142974a9c9b5e7fc5314fd5ece7fbe63..7645300c6aad20aa7fcf2fff3389fa1257705f45 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-21  Drew Adams  <drew.adams@oracle.com>
+
+       * mouse.el (minor-mode-menu-from-indicator): Create a menu with a
+       "Turn off" and a "Help" entry when the minor mode has no menu.
+
 2008-02-21  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * vc.el (vc-status-mark, vc-status-unmark): New functions.
index a0e823e20982e1ae3e539b740b7d921ab4b4d48a..8b3195ac01024d770a0329c80e5d3b7490d72804 100644 (file)
@@ -152,18 +152,33 @@ PREFIX is the prefix argument (if any) to pass to the command."
       (call-interactively cmd))))
 
 (defun minor-mode-menu-from-indicator (indicator)
-  "Show menu, if any, for minor mode specified by INDICATOR.
-Interactively, INDICATOR is read using completion."
-  (interactive (list (completing-read "Minor mode indicator: "
-                                      (describe-minor-mode-completion-table-for-indicator))))
+  "Show menu for minor mode specified by INDICATOR.
+Interactively, INDICATOR is read using completion.
+If there is no menu defined for the minor mode, then create one with
+items `Turn Off' and `Help'."
+  (interactive
+   (list (completing-read 
+         "Minor mode indicator: "
+         (describe-minor-mode-completion-table-for-indicator))))
   (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
-    (if minor-mode
-        (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
-               (menu (and (keymapp map) (lookup-key map [menu-bar]))))
-          (if menu
-              (popup-menu menu)
-            (message "No menu for minor mode `%s'" minor-mode)))
-      (error "Cannot find minor mode for `%s'" indicator))))
+    (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
+    (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
+           (menu (and (keymapp map) (lookup-key map [menu-bar]))))
+      (unless menu
+        (setq menu 
+             `(keymap
+               (,(intern indicator) ,indicator
+                keymap
+                (turn-off menu-item "Turn Off minor mode"
+                          (lambda ()
+                            (interactive)
+                            (,minor-mode -1)
+                            (message ,(format "`%S' turned OFF" minor-mode))))
+                (help menu-item "Help for minor mode"
+                      (lambda () (interactive) 
+                        (describe-function
+                         ',minor-mode)))))))
+      (popup-menu menu))))
 
 (defun mouse-minor-mode-menu (event)
   "Show minor-mode menu for EVENT on minor modes area of the mode line."