avy-region.el 968 B

1234567891011121314151617181920212223242526272829
  1. ;;; ../../lyfi/configs/apps/doom/custom/avy-region.el -*- lexical-binding: t; -*-
  2. (defun my/avy-region (jump-fn &optional inclusive)
  3. "Select region between two points chosen with JUMP-FN.
  4. JUMP-FN is a command like `avy-goto-char-timer' or `avy-goto-line'.
  5. When INCLUSIVE is non-nil, include the character at the end point."
  6. (interactive)
  7. (let (p1 p2)
  8. (cl-labels ((do-jump () (call-interactively jump-fn) (point)))
  9. (setq p1 (do-jump))
  10. (setq p2 (do-jump)))
  11. (when (and p1 p2)
  12. (let ((beg (min p1 p2))
  13. (end (max p1 p2)))
  14. (push-mark beg nil t)
  15. (goto-char end)
  16. (when inclusive
  17. (unless (eobp) (forward-char 1)))))))
  18. (defun my/avy-char-region ()
  19. "mark region between 2 chars using avy-char"
  20. (interactive)
  21. (my/avy-region 'avy-goto-char-timer t))
  22. (defun my/avy-line-region ()
  23. "mark region between 2 lines using avy-line"
  24. (interactive)
  25. (my/avy-region 'avy-goto-line)
  26. (forward-line 1))