I'm making my own minor mode for emacs. Now I want to add button to modeline. Click on this button must сause pop-up menu appear. The items of this menu depend on user's actions. I know that there is a way to add a function button to modeline with `minor-mode-alist', but I have no idea how to make dynamic menu.
Add button with dynamic menu to emacs's modeline?
1.1k views Asked by Bad_ptr At
2
There are 2 answers
0
On
Ok. Solution founded.:)
First: define some keymap:
(defconst my-mode-line-map
(let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1]
(make-sparse-keymap))
map))
Second: append list with propertized string to modeline:
(setq global-mode-string
(append global-mode-string
(list
(propertize string-name
'local-map my-mode-line-map
'mouse-face 'mode-line-highlight))))
Third: Now you can add items with
(define-key my-mode-line-map
(vconcat [mode-line down-mouse-1]
(list some_generated_id_for_future_use))
(cons name function))
...and remove with
(define-key my-mode-line-map
(vconcat [mode-line down-mouse-1]
(list id_of_button_that_u_gave_when_add))
nil)
I found more proper way: When you define minor mode, you can specify :lighter param
then you can use easymenu:
This menu will be added to global menu-bar and it will pop up if you click on auto added(cause you specified :lighter param) minor-mode button on modeline.