configuring avy

This commit is contained in:
Dibyashanu Pati 2025-02-10 23:49:12 +05:30
parent 4863dd103b
commit f4d3ddd875
8 changed files with 187 additions and 15 deletions

129
AVY.org Normal file
View file

@ -0,0 +1,129 @@
:PROPERTIES:
:ID: d9246843-e229-4f53-b75d-0cac546f353b
:END:
#+title: AVY
AVY is a powerful Emacs library that allows you to jump to any visible character in a buffer with efficient tree searches.
The core idea that makes Avy a powerful tool is [[id:65391d4b-e2b4-4a71-9d98-100cbc9772b4][the filter - select - act paradigm]].
*Usage :*
1. call avy-goto-char-time - I have bound it to SPC a a
2. /filter/ by typing the characters of stings you want to go to
3. A decision tree appears at all matching points in the frame
4. Now before typing the decision /select/ the action
default (do nothing) - will go to position
? - display all possible actions, runs avy-show-dispatch-help
5. /act/ by entering your decision
#+begin_src elisp
(use-package avy
:config
(setq avy-timeout-seconds 0.3)
(setq avy-keys '(?q ?e ?r ?y ?u ?o ?p
?a ?s ?d ?f ?g ?h ?j
?k ?l ?' ?x ?c ?v ?b
?n ?, ?/))
;; overrides the function in avy.el, type ? before the decesion phase to call
(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 ? avy-dispatch-alist) 'avy-action-mark-to-char)
;; Flyspell words --------------------------------------------------
(defun avy-action-flyspell (pt)
(save-excursion
(goto-char pt)
(when (require 'flyspell nil t)
(flyspell-auto-correct-word)))
(select-window
(cdr (ring-ref avy-ring 0)))
t)
;; Bind to semicolon (flyspell uses C-;)
(setf (alist-get ?\; avy-dispatch-alist) 'avy-action-flyspell)
)
#+end_src
** References
+ https://karthinks.com/software/avy-can-do-anything/index.html
+ https://github.com/abo-abo/avy
+ https://github.com/abo-abo/avy/wiki/defcustom
+ https://gist.github.com/karthink/af013ffd77fe09e67360f040b57b4c7b

View file

@ -1,6 +0,0 @@
:PROPERTIES:
:ID: 1245040a-0412-45cd-b4de-81026f06422a
:END:
#+title: Emacs
Emacs is much more than just a text editor.

14
Index.org Normal file
View file

@ -0,0 +1,14 @@
:PROPERTIES:
:ID: 020c5410-998b-46fb-8c5e-59013dd30db4
:END:
#+title: Index
#+hugo_section: ./
These are my thoughts.
I use org-roam to manage these thoughts and ox-hugo along with quartz to publish them.
For more details see
* Topics
Here are some topics I think about
** [[id:0a87430b-6616-4f92-8ecc-22ceeebf43c6][Emacs]]

10
My_Emacs_Config.org Normal file
View file

@ -0,0 +1,10 @@
:PROPERTIES:
:ID: 43f5a7d2-4e8c-4d61-b333-8993d2aefbf6
:END:
#+title: My_Emacs_Config
Here is my emacs config with commentary.
TODO This is a work in progress - I am adding packages one by one after cleaning some of the code and fixing bugs
* [[id:d9246843-e229-4f53-b75d-0cac546f353b][AVY]]

View file

@ -1,9 +1 @@
:PROPERTIES:
:ID: 020c5410-998b-46fb-8c5e-59013dd30db4
:END:
#+title: Notes
These will be some notes on various topics I like.
* Topics
** [[file:Emacs/README.org][Emacs]]
These are my thoughts in the form of a [[https://www.orgroam.com/][org roam]] database.

8
emacs.org Normal file
View file

@ -0,0 +1,8 @@
:PROPERTIES:
:ID: 0a87430b-6616-4f92-8ecc-22ceeebf43c6
:END:
#+title: Emacs
Emacs is much more than just a text editor.
Here is my [[id:43f5a7d2-4e8c-4d61-b333-8993d2aefbf6][My Emacs Config]]

14
index.org Normal file
View file

@ -0,0 +1,14 @@
:PROPERTIES:
:ID: 020c5410-998b-46fb-8c5e-59013dd30db4
:END:
#+title: index
#+hugo_section: ./
These are my thoughts.
I use org-roam to manage these thoughts and ox-hugo along with quartz to publish them.
For more details see
* Topics
Here are some topics I think about
** [[id:0a87430b-6616-4f92-8ecc-22ceeebf43c6][Emacs]]

View file

@ -0,0 +1,11 @@
:PROPERTIES:
:ID: 65391d4b-e2b4-4a71-9d98-100cbc9772b4
:END:
#+title: the_filter-select-act_paradigm
The filter - select - act paradigm/pattern is powerful abstraction used in [[id:0a87430b-6616-4f92-8ecc-22ceeebf43c6][Emacs]] and many of its packages like [[id:d9246843-e229-4f53-b75d-0cac546f353b][AVY]].
It is a philosophy that not only makes string manipulation efficient but allows one to really utilize emacs the way it is ment to be used, like a single mutable state, not just some willy nilly text editor.
* References
+ https://karthinks.com/software/avy-can-do-anything/index.html