all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Omar Polo <op@omarpolo.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: I'd like to advise a /keybinding/, how do I do it?
Date: Wed, 28 Apr 2021 09:21:17 +0000	[thread overview]
Message-ID: <877dkm3gtu.fsf@posteo.net> (raw)
In-Reply-To: <87im466g3y.fsf@omarpolo.com> (Omar Polo's message of "Wed, 28 Apr 2021 09:08:33 +0200")

Omar Polo <op@omarpolo.com> writes:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> Hello everyone,
>>
>> what I'd like to do is to "advise a keybinding", IOW, advise whatever
>> command a given key is bound to.  How do I get the name of the command
>> given a key, and taking into account the current major mode, minor modes
>> etc.?
>>
>> I tried to look at the source code of `describe-key-briefly', but it is
>> pretty dense, and maybe there's a better way than diving into that
>> rabbit hole.
>>
>> 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.
>>
>> Of course, a more robust way would be to have a list of various major
>> modes and their "finishing" commands, but I think the idea with just
>> looking up C-c C-c is cute (even if not very robust), and I was
>> wondering if it can be done in a simple way, even as a toy.
>>
>> Any ideas?
>
> Probably post-command-hook?  I don't know how to read the current
> keybinding, but if it's possible then you can run code in the
> post-command-hook and check there

Do you mean something like (this-command-keys)? But yes, an advice
system could be built that checks an alist or hash-table in
pre/post-command-hook on what to execute.

> HTH
>
>

-- 
	Philip K.



  reply	other threads:[~2021-04-28  9:21 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 [this message]
2021-04-28 11:44 ` Eli Zaretskii
2021-04-28 14:33 ` Stefan Monnier
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877dkm3gtu.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=op@omarpolo.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.