diff options
Diffstat (limited to 'lisp/ravi-init-navigation.el')
| -rw-r--r-- | lisp/ravi-init-navigation.el | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/lisp/ravi-init-navigation.el b/lisp/ravi-init-navigation.el index bc369f7..54c4f52 100644 --- a/lisp/ravi-init-navigation.el +++ b/lisp/ravi-init-navigation.el @@ -52,15 +52,84 @@ res)))) (use-package avy - :bind (("M-h" . avy-goto-word-1) - ("M-H" . avy-goto-word-0) + :bind (("M-H" . avy-goto-word-1) + ("M-h" . avy-goto-char-timer) ("M-g g" . avy-goto-line) ("M-g M-g" . avy-goto-line)) :config - (progn - (setq avy-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l ?r ?u ?t ?y ?w ?o ?e ?i)) - (setq avy-style 'at-full - avy-background t))) + ;; Many of these from: https://karthinks.com/software/avy-can-do-anything/ + + ;; Fix dispatch help + (defun avy-show-dispatch-help () + (let* ((len (length "avy-action-")) + (fw (frame-width)) + (raw-strings (mapcar + (lambda (x) + (format "%2s: %-19s" + (propertize + (char-to-string (car x)) + 'face 'aw-key-face) + (substring (symbol-name (cdr x)) len))) + avy-dispatch-alist)) + (max-len (1+ (apply #'max (mapcar #'length raw-strings)))) + (strings-len (length raw-strings)) + (per-row (floor fw max-len)) + display-strings) + (cl-loop for string in raw-strings + for N from 1 to strings-len do + (push (concat string " ") display-strings) + (when (= (mod N per-row) 0) (push "\n" display-strings))) + (message "%s" (apply #'concat (nreverse display-strings))))) + + ;; Kill text + (defun avy-action-kill-whole-line (pt) + (save-excursion + (goto-char pt) + (kill-whole-line)) + (select-window (cdr (ring-ref avy-ring 0))) + t) + (setf (alist-get ?k avy-dispatch-alist) 'avy-action-kill-stay + (alist-get ?k avy-dispatch-alist) 'avy-action-kill-whole-line) + + ;; Copy text + (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) + (setf (alist-get ?w avy-dispatch-alist) 'avy-action-copy + (alist-get ?W avy-dispatch-alist) 'avy-action-copy-whole-line) + + ;; Yank text + (defun avy-action-yank-whole-line (pt) + (avy-action-copy-whole-line pt) + (save-excursion (yank)) + t) + (setf (alist-get ?y avy-dispatch-alist) 'avy-action-yank + (alist-get ?Y avy-dispatch-alist) 'avy-action-yank-whole-line) + + ;; Transpose/Move text + (defun avy-action-teleport-whole-line (pt) + (avy-action-kill-whole-line pt) + (save-excursion (yank)) t) + (setf (alist-get ?t avy-dispatch-alist) 'avy-action-teleport + (alist-get ?T avy-dispatch-alist) 'avy-action-teleport-whole-line) + + ;; Mark text + (defun avy-action-mark-to-char (pt) + (activate-mark) + (goto-char pt)) + (setf (alist-get ?\s avy-dispatch-alist) 'avy-action-mark-to-char) + + ;; Any custom actions should not be preempted + (let ((key-list '(?a ?s ?d ?f ?g ?h ?j ?k ?l ?r ?u ?t ?y ?w ?o ?e ?i))) + (setq avy-keys (seq-filter (lambda (k) (not (alist-get k avy-dispatch-alist))) key-list))) + + (setq avy-style 'at-full) + (setq avy-background t)) (use-package jump-char :bind (("M-m" . jump-char-forward))) |
