[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29321: Isearch hit count

From: Juri Linkov
Subject: bug#29321: Isearch hit count
Date: Wed, 21 Nov 2018 01:52:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

> Do you think adding similar behavior to
> "isearch-forward"/"isearch-backward" would be feasible?  For example,
> C-6 C-s foo could move point forward to the sixth next occurrence of
> "foo".

Now that isearch-repeat-forward supports a prefix arg, it's easy to do
this for isearch-forward-symbol-at-point with a small patch below.

This allows a trivial implementation of corresponding
Vi-like keybindings.  I don't like Vi-keybindings, but here's
the implementation for anyone who likes Vi-keybindings:

(defun isearch-forward-search-symbol-at-point (&optional count)
  (interactive "p")
  (isearch-forward-symbol-at-point (or count 1)))
(define-key search-map "*" 'isearch-forward-search-symbol-at-point)
(defun isearch-backward-search-symbol-at-point (&optional count)
  (interactive "p")
  (isearch-forward-symbol-at-point (- (or count 1))))
(define-key search-map "#" 'isearch-backward-search-symbol-at-point)

Here's the patch that adds a prefix arg:

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 6d94ef6693..78c4d7b275 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -887,21 +887,26 @@ isearch-backward-regexp
   (interactive "P\np")
   (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
-(defun isearch-forward-symbol-at-point ()
+(defun isearch-forward-symbol-at-point (&optional arg)
   "Do incremental search forward for a symbol found near point.
 Like ordinary incremental search except that the symbol found at point
 is added to the search string initially as a regexp surrounded
 by symbol boundary constructs \\_< and \\_>.
-See the command `isearch-forward-symbol' for more information."
-  (interactive)
+See the command `isearch-forward-symbol' for more information.
+With a prefix argument, search for ARGth symbol forward if ARG is
+positive, or search for ARGth symbol backward if ARG is negative."
+  (interactive "P")
   (isearch-forward-symbol nil 1)
-  (let ((bounds (find-tag-default-bounds)))
+  (let ((bounds (find-tag-default-bounds))
+        (count (and arg (prefix-numeric-value arg))))
       (when (< (car bounds) (point))
        (goto-char (car bounds)))
-       (buffer-substring-no-properties (car bounds) (cdr bounds))))
+       (buffer-substring-no-properties (car bounds) (cdr bounds)))
+      (when count
+        (isearch-repeat-forward count)))
       (setq isearch-error "No symbol at point")

reply via email to

[Prev in Thread] Current Thread [Next in Thread]