avy.el (avy-goto-whitespace-end): New command

* avy.el (avy--regex-candidates): Allow `group' to be a function.
(avy-jump): Pass `group' to `avy--regex-candidates'.

Fixes #278
This commit is contained in:
Oleh Krehel 2019-08-27 20:07:10 +02:00
parent 01a311ca6a
commit 27d1af3fa6

27
avy.el
View File

@ -960,8 +960,11 @@ When GROUP is non-nil, (BEG . END) should delimit that regex group."
(when (avy--visible-p (1- (point))) (when (avy--visible-p (1- (point)))
(when (or (null pred) (when (or (null pred)
(funcall pred)) (funcall pred))
(push (cons (cons (match-beginning group) (push (cons
(if (numberp group)
(cons (match-beginning group)
(match-end group)) (match-end group))
(funcall group))
wnd) candidates))))))) wnd) candidates)))))))
(nreverse candidates))) (nreverse candidates)))
@ -1233,20 +1236,22 @@ exist."
(ignore #'ignore) (ignore #'ignore)
(t (error "Unexpected style %S" style)))) (t (error "Unexpected style %S" style))))
(cl-defun avy-jump (regex &key window-flip beg end action pred) (cl-defun avy-jump (regex &key window-flip beg end action pred group)
"Jump to REGEX. "Jump to REGEX.
The window scope is determined by `avy-all-windows'. The window scope is determined by `avy-all-windows'.
When WINDOW-FLIP is non-nil, do the opposite of `avy-all-windows'. When WINDOW-FLIP is non-nil, do the opposite of `avy-all-windows'.
BEG and END narrow the scope where candidates are searched. BEG and END narrow the scope where candidates are searched.
ACTION is a function that takes point position as an argument. ACTION is a function that takes point position as an argument.
When PRED is non-nil, it's a filter for matching point positions." When PRED is non-nil, it's a filter for matching point positions.
When GROUP is non-nil, it's either a match group in REGEX, or a function
that returns a cons of match beginning and end."
(setq avy-action (or action avy-action)) (setq avy-action (or action avy-action))
(let ((avy-all-windows (let ((avy-all-windows
(if window-flip (if window-flip
(not avy-all-windows) (not avy-all-windows)
avy-all-windows))) avy-all-windows)))
(avy-process (avy-process
(avy--regex-candidates regex beg end pred)))) (avy--regex-candidates regex beg end pred group))))
(defun avy--generic-jump (regex window-flip &optional beg end) (defun avy--generic-jump (regex window-flip &optional beg end)
"Jump to REGEX. "Jump to REGEX.
@ -1361,6 +1366,20 @@ BEG and END narrow the scope where candidates are searched."
:beg beg :beg beg
:end end))) :end end)))
;;;###autoload
(defun avy-goto-whitespace-end (arg &optional beg end)
"Jump to the end of a whitespace sequence.
The window scope is determined by `avy-all-windows'.
When ARG is non-nil, do the opposite of `avy-all-windows'.
BEG and END narrow the scope where candidates are searched."
(interactive "P")
(avy-with avy-goto-whitespace-end
(avy-jump "[ \t]+\\|\n[ \t]*"
:window-flip arg
:beg beg
:end end
:group (lambda () (cons (point) (1+ (point)))))))
(defun avy-goto-word-0-above (arg) (defun avy-goto-word-0-above (arg)
"Jump to a word start between window start and point. "Jump to a word start between window start and point.
The window scope is determined by `avy-all-windows'. The window scope is determined by `avy-all-windows'.