From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christian Dietrich Newsgroups: gmane.emacs.devel Subject: echo-area-keystroke-hook Date: Mon, 14 Dec 2015 23:35:17 +0100 Message-ID: <87zixc1wwq.fsf@dokucode.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1450132559 24440 80.91.229.3 (14 Dec 2015 22:35:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Dec 2015 22:35:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 14 23:35:51 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a8bih-0003Bk-D8 for ged-emacs-devel@m.gmane.org; Mon, 14 Dec 2015 23:35:51 +0100 Original-Received: from localhost ([::1]:34217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8big-00087a-SN for ged-emacs-devel@m.gmane.org; Mon, 14 Dec 2015 17:35:50 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8biH-00087M-BG for emacs-devel@gnu.org; Mon, 14 Dec 2015 17:35:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8biC-00059C-BN for emacs-devel@gnu.org; Mon, 14 Dec 2015 17:35:25 -0500 Original-Received: from mailgate.zerties.org ([176.9.118.134]:51545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8biC-00058c-4G for emacs-devel@gnu.org; Mon, 14 Dec 2015 17:35:20 -0500 Original-Received: from ppp-46-244-229-127.dynamic.mnet-online.de ([46.244.229.127] helo=faui49cd) by mailgate.zerties.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1a8biA-0007E4-BI; Mon, 14 Dec 2015 22:35:18 +0000 Original-Received: from stettberger by faui49cd with local (Exim 4.86) (envelope-from ) id 1a8bi9-00026p-Nx; Mon, 14 Dec 2015 23:35:17 +0100 User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/25.0.50.2 (x86_64-pc-linux-gnu) X-SA-Exim-Connect-IP: 46.244.229.127 X-SA-Exim-Mail-From: stettberger@dokucode.de X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 176.9.118.134 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:196272 Archived-At: --=-=-= Content-Type: text/plain Hi, I was fiddling around with the hydra package[1]. Hydra, which provides easily defined popups. And I had the following idea: Normally, I know my keybindings, so I type them in very fast. But sometimes I just don't know what the next character of a prefix command should be. So, when I wait long enough, a pre-defined hydra should be spawned. And there is already something that does does something when a partial keystroke sits there long enough: the echo-keystrokes timeout. So, I searched for a hook to call my hydra there. But I didn't found one (so please give me a hint, if i missed something). So I took a look into keyboard.c and inserted a hook there that is called when the dash of an partial keystroke is echoed. Together with the following lisp code I can easily define general echo-keystroke timeouts: (defvar echo-area-keystroke-keymap (make-sparse-keymap)) (define-key echo-area-keystroke-keymap (kbd "C-c p") 'hydra-projectile/body) (defun echo-area-keystroke-echoed (&optional key) (let ((keystroke (or key (this-command-keys)))) (when-let ((command (lookup-key echo-area-keystroke-keymap keystroke)) (command-found (not (integer-or-marker-p command)))) (ignore-errors (funcall command) (setq quit-flag t))))) (add-hook 'echo-area-keystroke-hook 'echo-area-keystroke-echoed) I don't know if this is useful, but I actually was really buffled that at that point there is no hook. And I don't know if added the hook correctly, since this is the very first time I touched a line of emacs C source code. What do you think? chris [1] https://github.com/abo-abo/hydra --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-New-echo-area-keystroke-hook.patch >From f3e1bd52c57e536cd8b61568e1d0cc8de9c1d6ba Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Mon, 14 Dec 2015 23:18:08 +0100 Subject: [PATCH] New 'echo-area-keystroke-hook' The echo-area-keystroke-hook is called when a keystroke is inserted partially and the keystroke is printed to the echo area. * src/keyboard.c: New hook is called when dash is printed to the echo area. --- src/keyboard.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/keyboard.c b/src/keyboard.c index 02bc7d2..1a2b621 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -530,6 +530,11 @@ echo_dash (void) kset_echo_string (current_kboard, concat2 (KVAR (current_kboard, echo_string), dash)); echo_now (); + + /* Call the hook indicating that a keystroke was printed to the echo + area */ + safe_run_hooks (Qecho_area_keystroke_hook); + } static void @@ -11008,6 +11013,7 @@ syms_of_keyboard (void) DEFSYM (Qhelp_form_show, "help-form-show"); DEFSYM (Qecho_keystrokes, "echo-keystrokes"); + DEFSYM (Qecho_area_keystroke_hook, "echo-area-keystroke-hook"); Fset (Qinput_method_exit_on_first_char, Qnil); Fset (Qinput_method_use_echo_area, Qnil); @@ -11396,6 +11402,14 @@ See also `pre-command-hook'. */); DEFSYM (Qecho_area_clear_hook, "echo-area-clear-hook"); Fset (Qecho_area_clear_hook, Qnil); + DEFVAR_LISP ("echo-area-keystroke-hook", Vecho_area_keystroke_hook, + doc: /* Normal hook run after a partial key input is +printed to the echo area. If an unhandled error happens in this hook, +the function in which the error occured is unconditionally removed, +since otherwise the error might happen repeatedly and make Emacs +nonfunctional. */); + Vecho_area_keystroke_hook = Qnil; + DEFVAR_LISP ("lucid-menu-bar-dirty-flag", Vlucid_menu_bar_dirty_flag, doc: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */); Vlucid_menu_bar_dirty_flag = Qnil; -- 2.6.2 --=-=-=--