The flaw with my original patch is that it is too specific. Even on my own computer, the ascii sequences generated will differ in length when using emacs differently (eg. emacs-nox in gui frame versus in a tty session without X). The SOLUTION (thank you, Stefan Monnier) was to not use function `recall-keys', which was meant to be a debug tool only, and instead, to use variables `this-command' and `last-command'
(defvar home-end-marker) (defvar my-command-state 0) (global-set-key [home] 'home-quadruple-play) (global-set-key [end] 'end-quadruple-play) (defun home-quadruple-play (&optional arg) "React uniquely to repeated presses of the `home' key. A first key-press moves the point to the beginning of the current line; a second key-press mo\ ves the point to the beginning of the current visible window, and; a third key-press moves the point to the beginning of the buffer. Additionally, with numeric `arg' N, this command calls function `beginning-of-buffer' to move the point to the (N*10)% position of the buffer. Recommended usage is to bind this function to the `home' key by, for instance, placing the following in the .emacs file: `(global-set-key [home] \'home-quadruple-play)'" (interactive "P") (if arg (beginning-of-buffer arg) (keypress-triple-play (lambda() (setq home-end-marker (copy-marker (point))) (beginning-of-line)) (lambda() (push-mark home-end-marker) (move-to-window-line 0)) (lambda() (goto-char (point-min)))))) (defun end-quadruple-play (&optional arg) "React uniquely to repeated presses of the `end' key. A first key-press moves the point to the end of the current line; a second key-press moves the\ point to the end of the current visible window, and; a third key-press moves the point to the end of the buffer. Additionally, with numeric `arg' N, this command calls function `end-of-buffer' to move the point to the (100-N*10)% position of the buffer. Recommended usage is to bind this function to the `end' key by, for instance, placing the following in the .emacs file: `(global-set-key [end] \'end-quadruple-play)'" (interactive "P") (if arg (end-of-buffer arg) (keypress-triple-play (lambda() (setq home-end-marker (copy-marker (point))) (end-of-line)) (lambda() (push-mark home-end-marker) (move-to-window-line -1) (end-of-line)) (lambda() (goto-char (point-max)))))) (defun keypress-triple-play (react_1 react_2 react_3) "Respond to a repeated keyboard-event (key-press) based upon the number of its repetitions. When the key-press has been performed once, reactby call\ ing function `react_1'; When the key-press is repeated once, react by calling function `react_2'; When the key-press is repeated more often, reactby c\ alling function `react_3'. This function was originally written to support functions `home-quadruple-play' and `end-quadruple-play'. See there as example usages. These three \ functions replace functions `home-end-home' and `home-end-end' in file `home-end.el' of Debian\'s `emacs-goodies-el' package." (interactive) (if (or executing-kbd-macro defining-kbd-macro) (funcall react_1)) (setq my-command-state (if (eq this-command last-command) (1+ my-command-state) 0)) (pcase my-command-state (`0 (funcall react_1)) (`1 (funcall react_2)) (`2 (funcall react_3)))) -- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
signature.asc
Description: OpenPGP digital signature