From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.help Subject: Re: I'd like to advise a /keybinding/, how do I do it? Date: Wed, 28 Apr 2021 09:21:17 +0000 Message-ID: <877dkm3gtu.fsf@posteo.net> References: <87lf930ymd.fsf@mbork.pl> <87im466g3y.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11203"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Omar Polo Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 28 11:22:44 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbgP5-0002nl-JE for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 28 Apr 2021 11:22:43 +0200 Original-Received: from localhost ([::1]:42836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbgP4-0005qr-Kb for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 28 Apr 2021 05:22:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbgNp-0005q6-Fw for help-gnu-emacs@gnu.org; Wed, 28 Apr 2021 05:21:25 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:48919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbgNm-0004hx-A2 for help-gnu-emacs@gnu.org; Wed, 28 Apr 2021 05:21:25 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 1414A240028 for ; Wed, 28 Apr 2021 11:21:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1619601679; bh=rIL04usdT743pemT5RDvUwYLvIJAGhMLDtdfAeAANjU=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=ikRnxpNDAoTRhUeIny0YN0F816jZjnlbXDJNyn6Fmhf+agtRb8XZz86LeVLSvMAn0 COvUITaKpljPtLO4YZzKIcGJ46HGi+TxF7Nv8DjacsDUBq+yjZT0U06HfeWxF1C+HE dpPAzPVrjiNdDRXmwGnWNk7akPrGJ7iXATCNDO88BLge7ONGGZLiTLFTfTMx6KV0v3 Z/hl+wioDv6EJE3sxFbLn5TUgEprK4+npQD7TpX9jYhWX78dzffW5IfkihsUQFNqz7 kIfUcRnnTy78EsY9qz0P2q8aAp5rWvTPfH3fQ1XaCAHaWTja6Btnk2F1Pw8JODa3V4 mxq9h71Y9jUzA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FVY662Qrrz6tmP; Wed, 28 Apr 2021 11:21:18 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=mutual; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <87im466g3y.fsf@omarpolo.com> (Omar Polo's message of "Wed, 28 Apr 2021 09:08:33 +0200") Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129186 Archived-At: Omar Polo writes: > Marcin Borkowski 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.