all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Menu on minor mode lighter
@ 2014-08-01 16:09 Sebastian Wiesner
  2014-08-01 17:18 ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Wiesner @ 2014-08-01 16:09 UTC (permalink / raw
  To: help-gnu-emacs

Hello,

how can I add a menu to the mode line lighter of a minor mode, similar to the menu that appears when you click on the mode line lighter of Dired?  However, the menu should *not* appear in the global menu bar, if the minor mode is enabled.

I’d prefer a solution with easy-menu, but if I need to create a keymap explicitly, it’s ok as well.  

Thanks


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

* Re: Menu on minor mode lighter
  2014-08-01 16:09 Menu on minor mode lighter Sebastian Wiesner
@ 2014-08-01 17:18 ` Michael Heerdegen
  2014-08-02 13:12   ` Sebastian Wiesner
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-08-01 17:18 UTC (permalink / raw
  To: help-gnu-emacs

Sebastian Wiesner <swiesner@lunaryorn.com> writes:

> how can I add a menu to the mode line lighter of a minor mode, similar
> to the menu that appears when you click on the mode line lighter of
> Dired?  However, the menu should *not* appear in the global menu bar,
> if the minor mode is enabled.

In the mode-line, down-mouse-1 is bound to `mouse-minor-mode-menu'.
`mouse-minor-mode-menu' determines the indicator string you clicked on
and calls `minor-mode-menu-from-indicator' on it.

So the presumably easiest way to do what you want is to advice
`minor-mode-menu-from-indicator' to pop up a different menu for certain
indicators.


Michael.




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

* Re: Menu on minor mode lighter
  2014-08-01 17:18 ` Michael Heerdegen
@ 2014-08-02 13:12   ` Sebastian Wiesner
  2014-08-02 13:42     ` Sebastian Wiesner
  2014-08-03 17:57     ` Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Sebastian Wiesner @ 2014-08-02 13:12 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: help-gnu-emacs


Am 01.08.2014 um 19:18 schrieb Michael Heerdegen <michael_heerdegen@web.de>:

> Sebastian Wiesner <swiesner@lunaryorn.com> writes:
> 
>> how can I add a menu to the mode line lighter of a minor mode, similar
>> to the menu that appears when you click on the mode line lighter of
>> Dired?  However, the menu should *not* appear in the global menu bar,
>> if the minor mode is enabled.
> 
> In the mode-line, down-mouse-1 is bound to `mouse-minor-mode-menu'.
> `mouse-minor-mode-menu' determines the indicator string you clicked on
> and calls `minor-mode-menu-from-indicator' on it.
> 
> So the presumably easiest way to do what you want is to advice
> `minor-mode-menu-from-indicator' to pop up a different menu for certain
> indicators.

Mh, the doctoring of `minor-mode-menu-from-indicator' says (emphasis mine):

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’.

So how do I do that?  How do I “define a menu for a minor mode”?


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

* Re: Menu on minor mode lighter
  2014-08-02 13:12   ` Sebastian Wiesner
@ 2014-08-02 13:42     ` Sebastian Wiesner
  2014-08-03 17:57     ` Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastian Wiesner @ 2014-08-02 13:42 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: help-gnu-emacs


Am 02.08.2014 um 15:12 schrieb Sebastian Wiesner <swiesner@lunaryorn.com>:

> 
> Am 01.08.2014 um 19:18 schrieb Michael Heerdegen <michael_heerdegen@web.de>:
> 
>> Sebastian Wiesner <swiesner@lunaryorn.com> writes:
>> 
>>> how can I add a menu to the mode line lighter of a minor mode, similar
>>> to the menu that appears when you click on the mode line lighter of
>>> Dired?  However, the menu should *not* appear in the global menu bar,
>>> if the minor mode is enabled.
>> 
>> In the mode-line, down-mouse-1 is bound to `mouse-minor-mode-menu'.
>> `mouse-minor-mode-menu' determines the indicator string you clicked on
>> and calls `minor-mode-menu-from-indicator' on it.
>> 
>> So the presumably easiest way to do what you want is to advice
>> `minor-mode-menu-from-indicator' to pop up a different menu for certain
>> indicators.
> 
> Mh, the doctoring of `minor-mode-menu-from-indicator' says (emphasis mine):

It’s the _docstring_ of course… sorry about that.



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

* Re: Menu on minor mode lighter
  2014-08-02 13:12   ` Sebastian Wiesner
  2014-08-02 13:42     ` Sebastian Wiesner
@ 2014-08-03 17:57     ` Michael Heerdegen
  2014-08-04  6:54       ` Sebastian Wiesner
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-08-03 17:57 UTC (permalink / raw
  To: help-gnu-emacs

Sebastian Wiesner <swiesner@lunaryorn.com> writes:

> So how do I do that?  How do I “define a menu for a minor mode”?

As you like, e.g. with "easymenu".  Here is an example of how you could
do it:

--8<---------------cut here---------------start------------->8---
(require 'easymenu)

(defvar my-mode-line-menus '()
  "My alist of menus for the mode-line.")

(defun my-add-menu-to-mode-line (mode menu)
  "Add MENU as mode-line indicator menu for MODE."
  (unless (assoc mode my-mode-line-menus)
    (push (cons mode menu)
          my-mode-line-menus)))

(defadvice minor-mode-menu-from-indicator
           (around add-my-stuff activate)
  (let* ((mode (lookup-minor-mode-from-indicator (ad-get-arg 0)))
         (my-menu (cdr (assoc mode my-mode-line-menus))))
    (if my-menu
        (popup-menu my-menu)
      ad-do-it)))


;; Example: add menu for ispell

(my-add-menu-to-mode-line
 'ispell-minor-mode
 (easy-menu-create-menu
  "Ispell"
  '(["Spell word"   ispell-word]
    ["Spell buffer" ispell-buffer])))
--8<---------------cut here---------------end--------------->8---

Does that do what you want?


Regards,

Michael.




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

* Re: Menu on minor mode lighter
  2014-08-03 17:57     ` Michael Heerdegen
@ 2014-08-04  6:54       ` Sebastian Wiesner
  2014-08-04 13:52         ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Wiesner @ 2014-08-04  6:54 UTC (permalink / raw
  To: help-gnu-emacs; +Cc: Michael Heerdegen

Am Sonntag, 3. August 2014, 19:57:35 schrieb Michael Heerdegen:
> Sebastian Wiesner <swiesner@lunaryorn.com> writes:
> > So how do I do that?  How do I “define a menu for a minor mode”?
> 
> As you like, e.g. with "easymenu".  Here is an example of how you could
> do it:
> 
> --8<---------------cut here---------------start------------->8---
> (require 'easymenu)
> 
> (defvar my-mode-line-menus '()
>   "My alist of menus for the mode-line.")
> 
> (defun my-add-menu-to-mode-line (mode menu)
>   "Add MENU as mode-line indicator menu for MODE."
>   (unless (assoc mode my-mode-line-menus)
>     (push (cons mode menu)
>           my-mode-line-menus)))
> 
> (defadvice minor-mode-menu-from-indicator
>            (around add-my-stuff activate)
>   (let* ((mode (lookup-minor-mode-from-indicator (ad-get-arg 0)))
>          (my-menu (cdr (assoc mode my-mode-line-menus))))
>     (if my-menu
>         (popup-menu my-menu)
>       ad-do-it)))
> 
> 
> ;; Example: add menu for ispell
> 
> (my-add-menu-to-mode-line
>  'ispell-minor-mode
>  (easy-menu-create-menu
>   "Ispell"
>   '(["Spell word"   ispell-word]
>     ["Spell buffer" ispell-buffer])))
> --8<---------------cut here---------------end--------------->8---
> 
> Does that do what you want?

Yes, it looks like it, but I'd rather go without an advice.  This feature 
isn't intended for my own customization, but rather for a package that I 
maintain (see [1]), and I am under the impression that advices in packages are 
really bad style.

Couldn't I just add my own menu to the 'local-map property of the mode line 
lighter text?

[1]: https://github.com/flycheck/flycheck/issues/365



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

* Re: Menu on minor mode lighter
  2014-08-04  6:54       ` Sebastian Wiesner
@ 2014-08-04 13:52         ` Michael Heerdegen
  2014-08-07 11:11           ` Sebastian Wiesner
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-08-04 13:52 UTC (permalink / raw
  To: help-gnu-emacs

Sebastian Wiesner <swiesner@lunaryorn.com> writes:

> Yes, it looks like it, but I'd rather go without an advice.  This
> feature isn't intended for my own customization, but rather for a
> package that I maintain (see [1]), and I am under the impression that
> advices in packages are really bad style.

Indeed.

> Couldn't I just add my own menu to the 'local-map property of the mode
> line lighter text?

That could work, but i'm not sure if that would be of better style.  You
would circumvent built in code and hardcode a certain (generally
configurable) mouse key.

> [1]: https://github.com/flycheck/flycheck/issues/365

I see.  Note that the situation for ispell is similar: It has a menu bar
menu under Tools, but this menu isn't present in the mode-line, because
the code doesn't capture that case.

There's probably no nice solution for your problem.


Regards,

Michael.




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

* Re: Menu on minor mode lighter
  2014-08-04 13:52         ` Michael Heerdegen
@ 2014-08-07 11:11           ` Sebastian Wiesner
  0 siblings, 0 replies; 8+ messages in thread
From: Sebastian Wiesner @ 2014-08-07 11:11 UTC (permalink / raw
  To: help-gnu-emacs; +Cc: Michael Heerdegen

Am Montag, 4. August 2014, 15:52:38 schrieb Michael Heerdegen:
> Sebastian Wiesner <swiesner@lunaryorn.com> writes:
> > Yes, it looks like it, but I'd rather go without an advice.  This
> > feature isn't intended for my own customization, but rather for a
> > package that I maintain (see [1]), and I am under the impression that
> > advices in packages are really bad style.
> 
> Indeed.
> 
> > Couldn't I just add my own menu to the 'local-map property of the mode
> > line lighter text?
> 
> That could work, but i'm not sure if that would be of better style.  You
> would circumvent built in code and hardcode a certain (generally
> configurable) mouse key.
> 
> > [1]: https://github.com/flycheck/flycheck/issues/365
> 
> I see.  Note that the situation for ispell is similar: It has a menu bar
> menu under Tools, but this menu isn't present in the mode-line, because
> the code doesn't capture that case.
> 
> There's probably no nice solution for your problem.

Turns out that there is.  After careful reading of the Elisp reference and 
"mouse.el", and some experiments, I figured out that it's just a matter of 
defining the menu in a special way.

The top menu bar will only show items that have no special key attached to the 
"[menu-bar]" binding, whereas the minor mode lighter simply shows the entire 
menu in the minor mode map.

Hence, creating a menu with "easy-menu-create-menu", and binding it as "[menu-
bar flycheck]" in the mode map does the job.

https://github.com/flycheck/flycheck/commit/b727e98fcbdfd27f4dc2ebe0777ec888192973d0 
has the corresponding change, for reference.

Many many thanks for your help.  Without your pointer to "mouse-minor-mode-
menu" and "minor-mode-menu-from-indicator" I'd never have been able to figure 
it out.



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

end of thread, other threads:[~2014-08-07 11:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-01 16:09 Menu on minor mode lighter Sebastian Wiesner
2014-08-01 17:18 ` Michael Heerdegen
2014-08-02 13:12   ` Sebastian Wiesner
2014-08-02 13:42     ` Sebastian Wiesner
2014-08-03 17:57     ` Michael Heerdegen
2014-08-04  6:54       ` Sebastian Wiesner
2014-08-04 13:52         ` Michael Heerdegen
2014-08-07 11:11           ` Sebastian Wiesner

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.