Tor-björn Claesson <[email protected]> writes:
>> 3. If we can make toggles work as well, even better. Although, I am not
>> sure if it is going to be easy. If not, no need to bother.
>>
>> Basically, we can accept that some menus will not support all the
>> features of transient, but we can implement a bare minimum.
I just played a little with this and got the following demo:
(defvar my-toggle-menu-pos nil
"Stored mouse event for re-opening the toggle menu.")
(defvar my-toggle-state
'((auto-fill . nil)
(visual-line . nil)
(display-line-numbers . nil))
"Checkbox state alist.")
(easy-menu-define my-toggle-menu nil
"Persistent toggle menu."
'("Options"
["Auto-Fill" (my-toggle 'auto-fill)
:style toggle :selected (cdr (assq 'auto-fill my-toggle-state))]
["Visual Line" (my-toggle 'visual-line)
:style toggle :selected (cdr (assq 'visual-line my-toggle-state))]
["Line Numbers" (my-toggle 'display-line-numbers)
:style toggle :selected (cdr (assq 'display-line-numbers
my-toggle-state))]))
(defun my-toggle (feature)
"Toggle FEATURE and re-open the menu."
(let ((new (not (cdr (assq feature my-toggle-state)))))
(setcdr (assq feature my-toggle-state) new)
(pcase feature
('auto-fill (auto-fill-mode (if new 1 -1)))
('visual-line (visual-line-mode (if new 1 -1)))
('display-line-numbers (display-line-numbers-mode (if new 1 -1)))))
;; Re-open at the stored position
(when my-toggle-menu-pos
(run-with-idle-timer
0 nil
(lambda () (popup-menu my-toggle-menu my-toggle-menu-pos)))))
(defun my-toggle-menu-show (event)
"Show the toggle menu at mouse EVENT."
(interactive "e")
(setq my-toggle-menu-pos event)
(popup-menu my-toggle-menu event))
(global-set-key [mouse-3] #'my-toggle-menu-show)
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>