Subject: bug#10638: [PATCH] Prefix Arg support for 'isearch-repeat-forward' and 'isearch-repeat-backward'

From: Gideon Stupp <[email-masked]>
Date: Sun, 29 Jan 2012 17:59:06 +0200

Package: emacs
Tags: patch

This patch extends 'isearch-repeat-forward' and 'isearch-repeat-backward'
to support a prefix argument so that during search it is possible to press
C-3 C-s for example to repeat the last search three times.   Notice that
you need to set `isearch-allow-scroll' to t for the patch to take effect.

Gideon.
diff --git a/lisp/isearch.el b/lisp/isearch.el
index ce75911..ce12552 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1340,15 +1340,37 @@ Use `isearch-exit' to quit without signaling."
   (isearch-push-state)
   (isearch-update))
 
-(defun isearch-repeat-forward ()
+(defun isearch-repeat-forward (&optional arg)
   "Repeat incremental search forwards."
-  (interactive)
-  (isearch-repeat 'forward))
-
-(defun isearch-repeat-backward ()
+  (interactive "p")
+  (if (< arg 0)
+      (progn
+	;; Doesn't do any search, just switches to backward search
+	(isearch-repeat 'backward)
+	(while (< arg 0)
+	  (isearch-repeat 'backward)
+	  (setq arg (1+ arg)))
+	;; Now switch back to forward search
+	(isearch-repeat 'forward))
+    (while (> arg 0)
+      (isearch-repeat 'forward)
+      (setq arg (1- arg)))))
+
+(defun isearch-repeat-backward (&optional arg)
   "Repeat incremental search backwards."
-  (interactive)
-  (isearch-repeat 'backward))
+  (interactive "p")
+  (if (< arg 0)
+      (progn
+	;; Doesn't do any search, just switches to forward search
+	(isearch-repeat 'forward)
+	(while (< arg 0)
+	  (isearch-repeat 'forward)
+	  (setq arg (1+ arg)))
+	;; Now switch back to backward search
+	(isearch-repeat 'backward))
+    (while (> arg 0)
+      (isearch-repeat 'backward)
+      (setq arg (1- arg)))))
 
 (defun isearch-toggle-regexp ()
   "Toggle regexp searching on or off."