[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Context menus and mouse-3
From: |
Tak Kunihiro |
Subject: |
Re: Context menus and mouse-3 |
Date: |
Sun, 18 Jul 2021 14:13:11 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) |
>> IMO, when mouse-3 is clocked on a misspelled word, it makes much more
>> sense to assume the user wants to fix that word than that the user
>> wants to paste.
>>
>> But here's an idea: how about merging the two menus into one in these
>> cases? We could add a top-level menu with the two alternatives, each
>> one would then drop down one of the two possible menus.
>> Alternatively, just make a long menu by concatenating the contents of
>> the two original ones.
>>
>> WDYT?
>
> Tak Kunihiro had a very good idea of using a hook-like variable
> that contains a list of functions that return parts of the whole
> context-menu, then these parts will be collected into the final menu.
The idea is to define a variable (something like below;
poplife-menu-candidates) with list of functions that returns nil or
keymap (something like below; poplife-mouse-word-menu). A function
(something like below; poplife-context-menu) will test each of them
until it gets keymap.
In this way, to revise context menu is easy.
(defvar poplife-menu-candidates
'(poplife-mouse-help-menu ; HELP menu
poplife-mouse-info-menu ; INFO menu
poplife-mouse-file-menu ; FILE menu
poplife-mouse-dir-menu ; DIR menu
poplife-mouse-word-menu ; WORD menu
poplife-mouse-url-menu ; URL menu
;; menu-bar-edit-menu ; EDIT menu (default)
poplife-mouse-edit-menu) ; EDIT menu
"List of candidates for context menu.
Candidates are function or keymap. They will be evaluated in the
order of the list. A function should accept mouse EVENT, and
return keymap or nil. The last candidate should return valid
keymap.")
(defun poplife-mouse-word-menu (event)
"Return 'flyspell-correct-word when word under mouse cursor on EVENT is
incorrect."
(and
(not (region-active-p))
;; Check face by (what-cursor-position t) or C-u C-x =.
(let ((faces-at-point (mapcar (lambda (xxx) (overlay-get xxx 'face))
(overlays-at (posn-point (event-start
event))))))
(when (or (member 'flyspell-incorrect faces-at-point)
(member 'flyspell-duplicate faces-at-point))
#'flyspell-correct-word))))
(defun poplife-context-menu (event)
"Return key's definition depending on thing under mouse click EVENT.
Items in `poplife-menu-candidates' are examined sequentially.
See `define-key' for the key's definition"
;; ~/.emacs.d/init.el ~/.emacs.d/ https://www.gnu.org/software/emacs/
(when (fboundp 'secondary-selection-to-region) ; 26.1
(secondary-selection-to-region)) ; When there is only secondary, turn it to
region.
(let ((candidates poplife-menu-candidates)
context-menu)
(while (not context-menu)
(let ((item (car candidates)))
(setq candidates (cdr candidates))
;; See how dired-guess-shell-alist-user is used in dired-guess-default.
(setq context-menu (cond ((fboundp item)
(funcall item event))
((and (symbolp item)
(keymapp (symbol-value item)))
(symbol-value item))
(t ; else
nil)))))
context-menu))
- RE: [External] : Re: Context menus and mouse-3, (continued)
- RE: [External] : Re: Context menus and mouse-3, Drew Adams, 2021/07/12
- Re: Context menus and mouse-3, Eli Zaretskii, 2021/07/13
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/13
- Re: Context menus and mouse-3, Eli Zaretskii, 2021/07/14
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/14
- Re: Context menus and mouse-3, Eli Zaretskii, 2021/07/15
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/15
- Re: Context menus and mouse-3, Eli Zaretskii, 2021/07/16
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/16
- RE: [External] : Re: Context menus and mouse-3, Drew Adams, 2021/07/16
- Re: Context menus and mouse-3,
Tak Kunihiro <=
- Re: Context menus and mouse-3, Stefan Monnier, 2021/07/18
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/19
- Re: Context menus and mouse-3, Stefan Monnier, 2021/07/19
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/20
- Re: Context menus and mouse-3, Stefan Monnier, 2021/07/20
- Re: Context menus and mouse-3, Juri Linkov, 2021/07/20
- Re: Context menus and mouse-3, Tak Kunihiro, 2021/07/21
- RE: [External] : Re: Context menus and mouse-3, Drew Adams, 2021/07/21
- Re: Context menus and mouse-3, Stefan Monnier, 2021/07/21
- RE: [External] : Re: Context menus and mouse-3, Drew Adams, 2021/07/21