[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: mode-line menu for minor modes

From: Drew Adams
Subject: RE: mode-line menu for minor modes
Date: Wed, 20 Feb 2008 16:11:44 -0800

>   > > The new feature to pop a menu when clicking on the mode-line 
>   > > :lighter for
>   > > minor modes is great.
>   > > 
>   > > But for minor modes that don't provide a menu, just an error 
>   > > message is
>   > > displayed: "No menu for minor mode `BLAH'".  This is 
>   > > not very helpful
>   > > for the user, it would be nicer to pop up a menu that 
>   > > has (at least) 2
>   > > entries: - one to turn off the minor mode
>   > >          - one to show the help for that minor mode.
>   > > 
>   > > Yes, these are available elsewhere, but it's better to 
>   > > provide something
>   > > useful and consistent for mouse-1 instead of just 
>   > > complaining that a menu is not available.
>   > 
>   > Good idea.
> Given that you wrote the rest of the minor mode menu popup 
> code, do you
> want to implement this too?

OK - see below. I wanted to make a patch, but apparently I don't know how to
find the latest CVS version. When I look at what I think would be the latest
version, namely the first download link at
http://cvs.savannah.gnu.org/viewvc/emacs/emacs/lisp/bindings.el?view=log, it
shows a version of bindings.el that does not have the changes I submitted.
But you are apparently seeing some version that does include that patch.

If you tell me how to find the right version to patch, I'll send a patch. If
not, here is the updated function definition - just substitute this for the
definition I sent in my September patch.

Note: I added (sleep-for 1) because the turned-off message is otherwise
erased immediately, at least in my environment. If it works for you without
the sleep-for, then go ahead and remove it.

(defun minor-mode-menu-from-indicator (indicator) ; e.g. " Icy"
  "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: "
  (let ((minor-mode (lookup-minor-mode-from-indicator 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]))))
      (if menu
          (popup-menu menu)
        (read-event)                    ; Swallow the mouse up event.
        (setq menu `(keymap
                     (,(intern indicator) ,indicator
                       (turn-off menu-item "Turn Off"
                                 (lambda ()
                                   (,minor-mode -1)
                                   (message ,(format "`%S' turned OFF"
                                   (sleep-for 1)))
                       (help menu-item "Help"
                             (lambda () (interactive) (describe-function
        (popup-menu menu)))))

reply via email to

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