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: Philip Kaludercic
Subject: Re: I'd like to advise a /keybinding/, how do I do it?
Date: Wed, 28 Apr 2021 09:21:17 +0000

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 via email to

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