I'm working on capturing formatted keystrokes to a buffer related to a VimGolf minor mode that I've been working on for a few days now.
I have the capture function almost exactly where I want it except that it cannot seem to capture the kmacro-end-or-call-macro command triggered by <f4> or the calc-dispatch command triggered by C-x *. I'm not sure what else is potentially missing as my testing has only exposed these anomalies.
In case you don't want to click over to github, here's the function as it stands now:
(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))
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.
I can capture the beginning of the commands but not the end by transforming the capture functions above into:
(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))
Even when I turn off executing-kbd-macro 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 <f4> it renders an empty vector.
So how do I get those keys into my capture buffer?
For convenience, I've been testing this using Challenge ID 4d2fb20e63b08b08b0000075.
The exact keys I press are <f3> C-e M-4 M-b M-d C-b M-2 <C-S-backspace> M-2 C-y C-f <f4> M-0 <f4> C-o M-< C-x * : M-1 v r C-u y
The way those keys come into my capture buffer with the function as it stands right now is <f3> C-e M-4 M-b M-d C-b M-2 <C-S-backspace> M-2 C-y C-f <f4> C-o M-< : M-1 v r C-u y