branch: externals/avy commit 27d1af3fa6b7622a36452cddca1710e9d5245cf9 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
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 --- avy.el | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/avy.el b/avy.el index 7c33b983c9..b83fb29b1e 100644 --- a/avy.el +++ b/avy.el @@ -960,9 +960,12 @@ When GROUP is non-nil, (BEG . END) should delimit that regex group." (when (avy--visible-p (1- (point))) (when (or (null pred) (funcall pred)) - (push (cons (cons (match-beginning group) - (match-end group)) - wnd) candidates))))))) + (push (cons + (if (numberp group) + (cons (match-beginning group) + (match-end group)) + (funcall group)) + wnd) candidates))))))) (nreverse candidates))) (defvar avy--overlay-offset 0 @@ -1233,20 +1236,22 @@ exist." (ignore #'ignore) (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. The window scope is determined by `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. 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)) (let ((avy-all-windows (if window-flip (not avy-all-windows) avy-all-windows))) (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) "Jump to REGEX. @@ -1361,6 +1366,20 @@ BEG and END narrow the scope where candidates are searched." :beg beg :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) "Jump to a word start between window start and point. The window scope is determined by `avy-all-windows'.