doomemacs/modules/editor/evil/autoload/textobjects.el
Samuel Tschiedel 488ad07cc5 fix(evil): define *-any-quote directly
Defining `*-any-quote` objects via the exiting `*-block` helpers leads
to incorrect behaviour, where the trailing boundary is also included as
part of the selection (cursor on `|`, selection between `|`):

```
start: "te|st"
v i q: "|test"|
```

The expected behaviour is the same as `v i "`:
```
start: "te|st"
v i q: "|test|"
```

Fix: #5698
2022-04-25 16:38:40 +02:00

68 lines
2.6 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; editor/evil/autoload/textobjects.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+evil:whole-buffer-txtobj "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:whole-buffer-txtobj (count &optional _beg _end type)
"Text object to select the whole buffer."
(evil-range (point-min) (point-max) type))
;;;###autoload (autoload '+evil:defun-txtobj "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:defun-txtobj (count &optional _beg _end type)
"Text object to select the top-level Lisp form or function definition at
point."
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'defun)
(evil-range beg end type)))
;;;###autoload (autoload '+evil:inner-url-txtobj "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:inner-url-txtobj (count &optional _beg _end type)
"Text object to select the inner url at point.
This excludes the protocol and querystring."
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'url)
(evil-range
(save-excursion
(goto-char beg)
(re-search-forward "://" end t))
(save-excursion
(goto-char end)
(- (if-let (pos (re-search-backward "[?#]" beg t))
pos
end)
(if (evil-visual-state-p)
1
0)))
type)))
;;;###autoload (autoload '+evil:outer-url-txtobj "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:outer-url-txtobj (count &optional _beg _end type)
"Text object to select the whole url at point."
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'url)
(evil-range
beg (- end (if (evil-visual-state-p) 1 0))
type)))
;;;###autoload (autoload '+evil:inner-any-quote "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:inner-any-quote (count &optional beg end type)
"Select the closest inner quote."
(require 'evil-textobj-anyblock)
(let ((evil-textobj-anyblock-blocks
'(("'" . "'")
("\"" . "\"")
("`" . "`")
("" . "")
("" . ""))))
(evil-textobj-anyblock--make-textobj beg end type count nil)))
;;;###autoload (autoload '+evil:outer-any-quote "editor/evil/autoload/textobjects" nil nil)
(evil-define-text-object +evil:outer-any-quote (count &optional beg end type)
"Select the closest outer quote."
(require 'evil-textobj-anyblock)
(let ((evil-textobj-anyblock-blocks
'(("'" . "'")
("\"" . "\"")
("`" . "`")
("" . "")
("" . ""))))
(evil-textobj-anyblock--make-textobj beg end type count t)))