From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.help Subject: Re: I'd like to advise a /keybinding/, how do I do it? Date: Wed, 28 Apr 2021 09:08:33 +0200 Message-ID: <87im466g3y.fsf@omarpolo.com> References: <87lf930ymd.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14194"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 28 09:09:10 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 1lbeJp-0003UD-W3 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 28 Apr 2021 09:09:09 +0200 Original-Received: from localhost ([::1]:51450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbeJp-0002HY-3B for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 28 Apr 2021 03:09:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbeJU-0002HM-HU for help-gnu-emacs@gnu.org; Wed, 28 Apr 2021 03:08:48 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:51840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbeJS-0000lK-7H for help-gnu-emacs@gnu.org; Wed, 28 Apr 2021 03:08:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1619593715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EvGPTHSrRgEGPtI0CVqWH41LXxnbhdaB3noI4H2AYtQ=; b=UKIaojQ9WXTgFOKzVxzM9F57xM2Ux5Zta6bEMi49/cFy3XJ66xJzTwUYAXgc3kWHSWB+GN iAnCAYZPhY+RZkF7jsen688SWibbXqwIuUjEAe7V20rxnd3PD1a4v0olNI9TVvP/1mYVaN +WHCfixg0geAQRdHgV1KpilSQpOh5X0= Original-Received: from localhost ( [87.13.101.227]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 78cafa20 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 28 Apr 2021 09:08:35 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id b821477d; Wed, 28 Apr 2021 09:08:33 +0200 (CEST) In-reply-to: <87lf930ymd.fsf@mbork.pl> Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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:129184 Archived-At: 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 HTH