From fbcfee3ae492922abc34e62381354c7d8b989fea Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 6 Nov 2019 01:35:47 +0200 Subject: [PATCH] Add prefix arg to more isearch commands (bug#14563) * lisp/isearch.el (isearch--yank-char-or-syntax) (isearch-yank-word-or-char, isearch-yank-symbol-or-char) (isearch-yank-until-char): Add optional prefix arg. --- etc/NEWS | 2 ++ lisp/isearch.el | 38 +++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index db3434f55b0..a5b9dbdebd0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1458,6 +1458,8 @@ commands repeat the search for the specified occurrence of the search string. A negative argument repeats the search in the opposite direction. This makes possible also to use a prefix argument for 'M-s .' ('isearch-forward-symbol-at-point') to find the next Nth symbol. +Also a prefix argument is supported for 'isearch-yank-until-char', +'isearch-yank-word-or-char', 'isearch-yank-symbol-or-char'. *** To go to the first/last occurrence of the current search string is possible now with new commands 'isearch-beginning-of-buffer' and diff --git a/lisp/isearch.el b/lisp/isearch.el index 1e4a87ff481..a46f4fc3eee 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2541,25 +2541,28 @@ If optional ARG is non-nil, pull in the next ARG characters." (interactive "p") (isearch-yank-internal (lambda () (forward-char arg) (point)))) -(defun isearch--yank-char-or-syntax (syntax-list fn) +(defun isearch--yank-char-or-syntax (syntax-list fn &optional arg) (isearch-yank-internal (lambda () - (if (or (memq (char-syntax (or (char-after) 0)) syntax-list) - (memq (char-syntax (or (char-after (1+ (point))) 0)) - syntax-list)) - (funcall fn 1) - (forward-char 1)) + (dotimes (_ arg) + (if (or (memq (char-syntax (or (char-after) 0)) syntax-list) + (memq (char-syntax (or (char-after (1+ (point))) 0)) + syntax-list)) + (funcall fn 1) + (forward-char 1))) (point)))) -(defun isearch-yank-word-or-char () - "Pull next character or word from buffer into search string." - (interactive) - (isearch--yank-char-or-syntax '(?w) 'forward-word)) +(defun isearch-yank-word-or-char (&optional arg) + "Pull next character or word from buffer into search string. +If optional ARG is non-nil, pull in the next ARG characters/words." + (interactive "p") + (isearch--yank-char-or-syntax '(?w) 'forward-word arg)) -(defun isearch-yank-symbol-or-char () - "Pull next character or symbol from buffer into search string." - (interactive) - (isearch--yank-char-or-syntax '(?w ?_) 'forward-symbol)) +(defun isearch-yank-symbol-or-char (&optional arg) + "Pull next character or symbol from buffer into search string. +If optional ARG is non-nil, pull in the next ARG characters/symbols." + (interactive "p") + (isearch--yank-char-or-syntax '(?w ?_) 'forward-symbol arg)) (defun isearch-yank-word (&optional arg) "Pull next word from buffer into search string. @@ -2567,17 +2570,18 @@ If optional ARG is non-nil, pull in the next ARG words." (interactive "p") (isearch-yank-internal (lambda () (forward-word arg) (point)))) -(defun isearch-yank-until-char (char) +(defun isearch-yank-until-char (char &optional arg) "Pull everything until next instance of CHAR from buffer into search string. Interactively, prompt for CHAR. +If optional ARG is non-nil, pull until next ARGth instance of CHAR. This is often useful for keyboard macros, for example in programming languages or markup languages in which CHAR marks a token boundary." - (interactive "cYank until character: ") + (interactive "cYank until character: \np") (isearch-yank-internal (lambda () (let ((inhibit-field-text-motion t)) (condition-case nil (progn - (search-forward (char-to-string char)) + (search-forward (char-to-string char) nil nil arg) (forward-char -1)) (search-failed (message "`%c' not found" char) -- 2.39.5