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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With