Files
lypacamacs/custom/avy-region.el
T

40 lines
1.3 KiB
EmacsLisp

;;; ../../lyfi/configs/apps/doom/custom/avy-region.el -*- lexical-binding: t; -*-
(defun my/avy-region (jump-fn &optional inclusive)
"Select region between two points chosen with JUMP-FN.
JUMP-FN is a command like `avy-goto-char-timer' or `avy-goto-line'.
When INCLUSIVE is non-nil, include the character at the end point."
(interactive)
(let (p1 p2)
(cl-labels ((do-jump () (call-interactively jump-fn) (point)))
(setq p1 (do-jump))
(setq p2 (do-jump)))
(when (and p1 p2)
(let ((beg (min p1 p2))
(end (max p1 p2)))
(push-mark beg nil t)
(goto-char end)
(when inclusive
(unless (eobp) (forward-char 1)))))))
(defun my/avy-char-region ()
"mark region between 2 chars using avy-char"
(interactive)
(my/avy-region 'avy-goto-char-timer t))
(defun my/avy-line-region ()
"mark region between 2 lines using avy-line"
(interactive)
(my/avy-region 'avy-goto-line)
(forward-line 1))
(defun my/another-select-exact-string (str)
"Prompt for a string and select its exact match using avy."
(interactive "sSelect target: ")
(avy-with my/select-exact-string
(avy-jump (regexp-quote str)
:action (lambda (pt)
(goto-char pt)
(set-mark pt)
(forward-char (length str))))))