Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I capture the `M-0 <f4>` event and write it to a buffer in that format in Emacs?
    primarykey
    data
    text
    <p>I'm working on capturing formatted keystrokes to a buffer related to a <a href="http://vimgolf.com/" rel="nofollow">VimGolf</a> <a href="https://github.com/timvisher/vimgolf/blob/keystrokes-parse/emacs/vimgolf.el" rel="nofollow">minor mode</a> that I've been working on for a few days now.</p> <p>I have the <a href="https://github.com/timvisher/vimgolf/blob/keystrokes-parse/emacs/vimgolf.el#L116" rel="nofollow">capture function</a> almost exactly where I want it except that it cannot seem to capture the <code>kmacro-end-or-call-macro</code> command triggered by <code>&lt;f4&gt;</code> or the <code>calc-dispatch</code> command triggered by <code>C-x *</code>. I'm not sure what else is potentially missing as my testing has only exposed these anomalies.</p> <p>In case you don't want to <a href="https://github.com/timvisher/vimgolf/blob/keystrokes-parse/emacs/vimgolf.el#L116" rel="nofollow">click over to github</a>, here's the function as it stands now:</p> <pre> (defun vimgolf-capture-keystroke () (with-current-buffer (get-buffer-create vimgolf-keystrokes-buffer-name) (end-of-buffer) (if (not (or executing-kbd-macro prefix-arg)) (progn (insert (key-description (this-command-keys))) (insert " "))))) (defun vimgolf-capture-keystrokes () (add-hook 'post-command-hook 'vimgolf-capture-keystroke)) (defun vimgolf-stop-capture-keystrokes () (remove-hook 'post-command-hook 'vimgolf-capture-keystroke)) </pre> <p>The only connection I can see between the two problem functions that I know about is that they both recurse into executing other commands prior to finishing the command that they actually execute.</p> <p>I can capture the beginning of the commands but not the end by transforming the capture functions above into:</p> <pre> (defun vimgolf-capture-keystrokes () (add-hook 'pre-command-hook 'vimgolf-capture-keystroke)) (defun vimgolf-stop-capture-keystrokes () (remove-hook 'pre-command-hook 'vimgolf-capture-keystroke)) </pre> <p>Even when I turn off <code>executing-kbd-macro</code> from the restriction on appending to the buffer, it still does not capture that event. I tried to examine the actual vector that comes down from the post-command-hook and in all cases it's exactly what I would expect but for <code>&lt;f4&gt;</code> it renders an empty vector.</p> <p>So how do I get those keys into my capture buffer?</p> <hr> <p>For convenience, I've been testing this using Challenge ID <code>4d2fb20e63b08b08b0000075</code>.</p> <p>The exact keys I press are <code>&lt;f3&gt; C-e M-4 M-b M-d C-b M-2 &lt;C-S-backspace&gt; M-2 C-y C-f &lt;f4&gt; M-0 &lt;f4&gt; C-o M-&lt; C-x * : M-1 v r C-u y</code></p> <p>The way those keys come into my capture buffer with the function as it stands right now is <code>&lt;f3&gt; C-e M-4 M-b M-d C-b M-2 &lt;C-S-backspace&gt; M-2 C-y C-f &lt;f4&gt; C-o M-&lt; : M-1 v r C-u y</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload