Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add button with dynamic menu to emacs's modeline?

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.

like image 494
Bad_ptr Avatar asked Jan 26 '12 14:01

Bad_ptr


1 Answers

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)
like image 184
Bad_ptr Avatar answered Nov 15 '22 20:11

Bad_ptr