[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Christian Dietrich
Subject: echo-area-keystroke-hook
Date: Mon, 14 Dec 2015 23:35:17 +0100
User-agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/ (x86_64-pc-linux-gnu)

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))))
        (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?


[1] https://github.com/abo-abo/hydra

>From f3e1bd52c57e536cd8b61568e1d0cc8de9c1d6ba Mon Sep 17 00:00:00 2001
From: Christian Dietrich <address@hidden>
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;

reply via email to

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