help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I'd like to advise a /keybinding/, how do I do it?


From: Stefan Monnier
Subject: Re: I'd like to advise a /keybinding/, how do I do it?
Date: Wed, 28 Apr 2021 10:33:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> The rationale is that I'm thinking about writing a minor mode which
> could prevent a "finishing" action until the buffer is ready.
> A "finishing" action is often bound to C-c C-c (sending an email and
> commiting something to Git come to mind), so I'd like to advise whatever
> C-c C-c calls to check the buffer for occurrences of a string like TODO.

"advising the key-binding" would imply changing by side-effect the
underlying major mode's keymap (BTW: yes, it can be done, by defining
`lookup-key` as an lvalue (e.g. with gv-define-setter) after which you
can use `add-function` to modify a key binding).

Or you could do it by advising the command bound to the particular key
(in which case it'll also affect invocations of that command that don't
go through this key binding, e.g. via `M-x`).

Or you could do it with a minor-mode map (i.e. without modifying any
major mode keymap or command), where you bind `C-c C-c` to a command
that either beeps or delegates to the command that it hid (e.g. which
you could find for example with (let ((my-new-minor-mode nil))
(key-binding (this-command-keys))))

Or you could do it with a `pre-command-hook` which checks
`this-command-keys`.

Or the minor-mode map could use a "filtered menu-item" conditional
key-binding.

Or ...


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]