help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Menu on minor mode lighter


From: Sebastian Wiesner
Subject: Re: Menu on minor mode lighter
Date: Mon, 04 Aug 2014 08:54:15 +0200
User-agent: KMail/4.13.3 (Linux/3.15.7-1-ARCH; KDE/4.13.3; x86_64; ; )

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



reply via email to

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