diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2022-04-16 00:49:35 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2022-04-16 00:49:35 (GMT) |
| commit | 7815878ed8b47e8c12e9a88560097ce750cc3d5b (patch) | |
| tree | 63e4837d37bf1f46dc3ed672711a85dff1c850d5 | |
| parent | 4eadb62c312979a73f3729bed0c3410f08a8d330 (diff) | |
| download | dotemacs-7815878ed8b47e8c12e9a88560097ce750cc3d5b.zip dotemacs-7815878ed8b47e8c12e9a88560097ce750cc3d5b.tar.gz dotemacs-7815878ed8b47e8c12e9a88560097ce750cc3d5b.tar.bz2 | |
Hint when easy-kill is used
| -rw-r--r-- | lisp/ravi-init-navigation.el | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/lisp/ravi-init-navigation.el b/lisp/ravi-init-navigation.el index 610b0a7..1f1770b 100644 --- a/lisp/ravi-init-navigation.el +++ b/lisp/ravi-init-navigation.el @@ -263,7 +263,66 @@ ([remap mark-sexp] . easy-mark)) :init (with-eval-after-load "whole-line-or-region" - (bind-key [remap kill-ring-save] 'easy-kill whole-line-or-region-local-mode-map))) + (bind-key [remap kill-ring-save] 'easy-kill whole-line-or-region-local-mode-map)) + :config + + ;; Copied easy-kill-activate-keymap from easy-kill.el to add on-exit and on-enter + (defun ravi/easy-kill-activate-keymap-with-hooks (&optional on-enter-with-map on-exit-with-map) + (let ((map (easy-kill-map))) + (when on-enter-with-map (funcall on-enter-with-map map)) + (set-transient-map + map + (lambda () + ;; Prevent any error from activating the keymap forever. + (condition-case err + (or (and (not (easy-kill-exit-p this-command)) + (or (eq this-command + (lookup-key map (this-single-command-keys))) + (let ((cmd (key-binding + (this-single-command-keys) nil t))) + (command-remapping cmd nil (list map))))) + (ignore + (easy-kill-destroy-candidate) + (unless (or (easy-kill-get mark) (easy-kill-exit-p this-command)) + (easy-kill-save-candidate)))) + (error (message "%s:%s" this-command (error-message-string err)) + nil))) + (when on-exit-with-map (lambda () (funcall on-exit-with-map map)))))) + + (defun ravi/easy-kill-make-hint-message () + (let ((basic "+=:expand -:shrink SPC:cycle @:append 0:original 1-9:more ?:help") + (remapped-basic (mapconcat 'identity + (delq nil (mapcar + (lambda (c) + (when-let ((binding (where-is-internal (car c) nil t))) + (concat (key-description binding) ":" (symbol-name (car c))))) + (cdr (alist-get 'remap easy-kill-base-map)))) + " ")) + (configurable (mapconcat (lambda (item) + (concat (char-to-string (car item)) ":" (symbol-name (cadr item)))) + easy-kill-alist " "))) + (concat basic "\n" remapped-basic "\n" configurable))) + + (defvar ravi/easy-kill-hint-delay 2.0 + "Delay before easy-kill hints are shown") + (defun ravi/easy-kill-activate-keymap () + (let* ((help-timer)) + (ravi/easy-kill-activate-keymap-with-hooks + ;; Set up a help message display on a timer before the transient keymap + (lambda (map) + (setq help-timer + (run-with-timer + ravi/easy-kill-hint-delay nil + (lambda () + (let ((message-log-max nil)) + (message (ravi/easy-kill-make-hint-message))))))) + ;; Cancel the timer on exitng the transient keymap + (lambda (map) + (when help-timer (cancel-timer help-timer))) + ))) + + (advice-add 'easy-kill-activate-keymap :override #'ravi/easy-kill-activate-keymap) + ) ;; grep and friends |
