Skip to content

Instantly share code, notes, and snippets.

@mjkramer
Created November 27, 2021 18:24
Show Gist options
  • Save mjkramer/39307cbf4fb0b7a15ca2045d72039162 to your computer and use it in GitHub Desktop.
Save mjkramer/39307cbf4fb0b7a15ca2045d72039162 to your computer and use it in GitHub Desktop.
;;; keypeat.el -*- lexical-binding: t; -*-
(defvar ++keypeat-last-keys nil)
(defun ++keypeat-save-h ()
(setq ++keypeat-last-keys (this-command-keys)))
(add-hook 'post-command-hook #'++keypeat-save-h)
(defun ++keypeat-push-prefix (keyseq)
(setq unread-command-events
(mapcar (lambda (k) `(t . ,k))
(listify-key-sequence (seq-subseq keyseq 0 -1)))))
(defun ++keypeat-repeat ()
(unless (memq this-command '(++keypeat/next ++keypeat/last))
(if (not this-command)
(remove-hook 'post-command-hook #'++keypeat-repeat)
(++keypeat-push-prefix (this-command-keys)))))
(defun ++keypeat/next ()
(interactive)
(add-hook 'post-command-hook #'++keypeat-repeat))
(defun ++keypeat/last ()
(interactive)
(++keypeat/next)
(++keypeat-push-prefix ++keypeat-last-keys))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment