Skip to content

Instantly share code, notes, and snippets.

@karthink
Created July 3, 2022 10:59
Show Gist options
  • Save karthink/9f054dc8fba07fd117738bec31652a90 to your computer and use it in GitHub Desktop.
Save karthink/9f054dc8fba07fd117738bec31652a90 to your computer and use it in GitHub Desktop.
repeat-mode configuration with which-key for Emacs 28
(use-package repeat
:if (version< "28.0" emacs-version)
:bind ("H-z" . repeat)
:hook (after-init . my/repeat-mode)
:config
(defun my/repeat-mode ()
(let ((inhibit-message t)
(message-log-max nil))
(repeat-mode)))
(use-package which-key
:after which-key
:config
(advice-add 'repeat-post-hook :after
(defun my/which-key-repeat ()
(when-let ((cmd (or this-command real-this-command))
(keymap (repeat--command-property 'repeat-map)))
(run-at-time
which-key-idle-delay nil
(lambda ()
(which-key--create-buffer-and-show
nil (symbol-value keymap)))))))
(defun my/which-key-repeat-mode-dispatch ()
(interactive)
(setq this-command last-command)
(when-let (keymap (repeat--command-property 'repeat-map))
(which-key--create-buffer-and-show
nil (symbol-value keymap))))
(defun my/which-key-repeat-mode-binding ()
(when repeat-mode
(when-let* ((rep-map-sym (or repeat-map (repeat--command-property 'repeat-map)))
(keymap (and (symbolp rep-map-sym) (symbol-value rep-map-sym))))
(set-transient-map
(make-composed-keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-h") #'my/which-key-repeat-mode-dispatch)
map)
keymap)))))
(advice-add 'repeat-post-hook :after #'my/which-key-repeat-mode-binding)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment