all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* echo-area-keystroke-hook
@ 2015-12-14 22:35 Christian Dietrich
  2015-12-14 22:38 ` echo-area-keystroke-hook John Wiegley
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Dietrich @ 2015-12-14 22:35 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1634 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-echo-area-keystroke-hook.patch --]
[-- Type: text/x-diff, Size: 2023 bytes --]

From f3e1bd52c57e536cd8b61568e1d0cc8de9c1d6ba Mon Sep 17 00:00:00 2001
From: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-15  3:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-14 22:35 echo-area-keystroke-hook Christian Dietrich
2015-12-14 22:38 ` echo-area-keystroke-hook John Wiegley
2015-12-14 22:42   ` echo-area-keystroke-hook Christian Dietrich
2015-12-14 23:21     ` echo-area-keystroke-hook Artur Malabarba
2015-12-15  3:40   ` echo-area-keystroke-hook Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.