diff options
| author | Sakamoto <me@sakamoto.network> | 2026-08-16 15:34:00 -0500 |
|---|---|---|
| committer | Sakamoto <me@sakamoto.network> | 2026-08-16 15:34:00 -0500 |
| commit | d51beea88d300cb5066bb92a8148cad52fa1091d (patch) | |
| tree | 4357b4958c19dddd304a0d6ee77994fb9f12c118 /dot_config/emacs/lisp/avy-config.el | |
| parent | a623fed63460d6d810605ce1ce858a58a5b222f7 (diff) | |
| download | dotfiles-d51beea88d300cb5066bb92a8148cad52fa1091d.tar.xz dotfiles-d51beea88d300cb5066bb92a8148cad52fa1091d.zip | |
update
Diffstat (limited to 'dot_config/emacs/lisp/avy-config.el')
| -rw-r--r-- | dot_config/emacs/lisp/avy-config.el | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/dot_config/emacs/lisp/avy-config.el b/dot_config/emacs/lisp/avy-config.el new file mode 100644 index 0000000..50c14ce --- /dev/null +++ b/dot_config/emacs/lisp/avy-config.el @@ -0,0 +1,176 @@ +;;; tweaked from karthink's .emacs.d + +(use-package avy + :ensure t + :commands (avy-goto-word-1 avy-goto-char-2 avy-goto-char-timer) + :config + (setq avy-timeout-seconds 0.4) + (setq avy-keys '(?a ?r ?s ?t ?g ?m ?n ?e ?i ?o ?' + ?q ?w ?f ?p ?b ?j ?l ?u ?y ?\; ?- + ?z ?x ?c ?d ?v ?k ?h ?, ?. ?/)) + + (setq avy-single-candidate-jump nil) + (setq avy-dispatch-alist '((?m . avy-action-mark) + (?$ . avy-action-ispell) + (?z . avy-action-zap-to-char) + (? . avy-action-embark) + (?= . avy-action-define) + (23 . avy-action-zap-to-char) + (?c . avy-action-mark-to-char) + (?h . avy-action-helpful) + (?x . avy-action-exchange) + + (11 . avy-action-kill-line) + (25 . avy-action-yank-line) + + (?w . avy-action-easy-kill) + (?k . avy-action-kill-stay) + (?y . avy-action-yank) + (?t . avy-action-teleport) + + (?W . avy-action-copy-whole-line) + (?K . avy-action-kill-whole-line) + (?Y . avy-action-yank-whole-line) + (?T . avy-action-teleport-whole-line))) + + ;; Improved to include transposition by hylophile + (defun avy-action-easy-kill (pt) + (unless (require 'easy-kill nil t) + (user-error "Easy Kill not found, please install.")) + (cl-letf* ((bounds (cond + ((use-region-p) + (prog1 (cons (region-beginning) (region-end)) + (deactivate-mark))) + ((bounds-of-thing-at-point 'sexp)) + (t (cons (point) (point))))) + (transpose-map + (define-keymap + "M-t" (lambda () (interactive "*") + (pcase-let ((`(,beg . ,end) (easy-kill--bounds))) + (transpose-regions (car bounds) (cdr bounds) beg end + 'leave-markers))))) + ((symbol-function 'easy-kill-activate-keymap) + (lambda () + (let ((map (easy-kill-map))) + (set-transient-map + (make-composed-keymap transpose-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))) + (lambda () + (let ((dat (ring-ref avy-ring 0))) + (select-frame-set-input-focus + (window-frame (cdr dat))) + (select-window (cdr dat)) + (goto-char (car dat))))))))) + (goto-char pt) + (easy-kill))) + + (defun avy-action-exchange (pt) + "Exchange sexp at PT with the one at point." + (set-mark pt) + (transpose-sexps 0)) + + (defun avy-action-helpful (pt) + (save-excursion + (goto-char pt) + (call-interactively #'display-local-help)) + (select-window + (cdr (ring-ref avy-ring 0))) + t) + + (defun avy-action-define (pt) + (cl-letf (((symbol-function 'keyboard-quit) + #'abort-recursive-edit)) + (save-excursion + (goto-char pt) + (dictionary-search-dwim)) + (select-window + (cdr (ring-ref avy-ring 0)))) + t) + + (defun avy-action-embark (pt) + (unwind-protect + (save-excursion + (goto-char pt) + (embark-act)) + (select-window + (cdr (ring-ref avy-ring 0)))) + t) + + (defun avy-action-kill-line (pt) + (unwind-protect + (save-excursion + (goto-char pt) + (kill-line)) + (avy-resume)) + (select-window + (cdr (ring-ref avy-ring 0))) + t) + + (defun avy-action-copy-whole-line (pt) + (save-excursion + (goto-char pt) + (cl-destructuring-bind (start . end) + (bounds-of-thing-at-point 'line) + (copy-region-as-kill start end))) + (select-window + (cdr + (ring-ref avy-ring 0))) + t) + + (defun avy-action-kill-whole-line (pt) + (unwind-protect + (save-excursion + (goto-char pt) + (kill-whole-line) + (avy-resume))) + (select-window + (cdr + (ring-ref avy-ring 0))) + t) + + (defun avy-action-yank-whole-line (pt) + (avy-action-copy-whole-line pt) + (save-excursion (yank)) + t) + + (defun avy-action-teleport-whole-line (pt) + (avy-action-kill-whole-line pt) + (save-excursion (yank)) t) + + (defun avy-action-mark-to-char (pt) + (activate-mark) + (goto-char pt)) + + :bind (("C-M-'" . avy-resume) + ("C-'" . avy-goto-char-this-window) + ("M-j" . avy-goto-char-timer) + ("M-s y" . avy-copy-line) + ("M-s M-y" . avy-copy-region) + ("M-s M-k" . avy-kill-whole-line) + ("M-s j" . avy-goto-char-2) + ("M-s M-p" . avy-goto-line-above) + ("M-s M-n" . avy-goto-line-below) + ("M-s M-l" . avy-goto-end-of-line) + ("M-s C-w" . avy-kill-region) + ("M-s M-w" . avy-kill-ring-save-region) + ("M-s t" . avy-move-line) + ("M-s M-t" . avy-move-region) + :map isearch-mode-map + ("C-'" . avy-isearch) + ("M-j" . avy-isearch))) + +(provide 'avy-config) |
