From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: I'd like to advise a /keybinding/, how do I do it?
Date: Wed, 28 Apr 2021 10:33:31 -0400 [thread overview]
Message-ID: <jwv8s52ij0b.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87lf930ymd.fsf@mbork.pl
> 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
next prev parent reply other threads:[~2021-04-28 14:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 5:25 I'd like to advise a /keybinding/, how do I do it? Marcin Borkowski
2021-04-28 7:08 ` Omar Polo
2021-04-28 9:21 ` Philip Kaludercic
2021-04-28 11:44 ` Eli Zaretskii
2021-04-28 14:33 ` Stefan Monnier [this message]
2021-04-29 0:29 ` Bob Newell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv8s52ij0b.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).