unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
@ 2012-01-26 17:27 Gideon Stupp
  2012-01-26 18:36 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Gideon Stupp @ 2012-01-26 17:27 UTC (permalink / raw)
  To: 10614, emacs-devel, juri

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

Package: emacs
Tags: patch
Severity: wishlist

This experimental patch implements a suggestion by Juri Linkov to extend
isearch-repeat-forward/backward to support a prefix argument. Instead of
pressing C-s / C-r multiple times it is possible with this patch to
enter a prefix argument
which runs the command multiple times for you. If a negative argument
is given for
isearch-repeat-forward then isearch-repeat-backward is run and visa
versa. Visual hints
are added to the matched strings to help figure out what argument
should be given.

Please try it out.

Thanks, Gideon.

[-- Attachment #2: isearchnavjuri.patch --]
[-- Type: text/x-patch, Size: 7354 bytes --]

This experimental patch implements a suggestion by Juri Linkov to extend
isearch-repeat-forward/backward to support a prefix argument. Instead of 
pressing C-s / C-r multiple times it is now possible to enter a prefix argument
which runs the command multiple times for you. If a negative argument is given for
isearch-repeat-forward than isearch-repeat-backward is run and visa versa. Visual hints
are added to the matched strings to help figure out what argument should be given.


diff --git a/lisp/isearch.el b/lisp/isearch.el
index ce75911..fce6fd5 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -333,6 +333,21 @@ A value of nil means highlight all matches."
                                 'lazy-highlight-face
                                 "22.1")
 (defvar lazy-highlight-face 'lazy-highlight)
+
+(defface lazy-highlight-hint
+  '((((class color) (min-colors 88) (background light))
+     (:background "paleturquoise" :bold t))
+    (((class color) (min-colors 88) (background dark))
+     (:background "paleturquoise4" :bold t))
+    (((class color) (min-colors 16))
+     (:background "turquoise3" :bold t))
+    (((class color) (min-colors 8))
+     (:background "turquoise3" :bold t))
+    (t (:underline t)))
+  "Face for lazy highlighting hints."
+  :group 'lazy-highlight
+  :group 'basic-faces)
+
 \f
 ;; Define isearch help map.
 
@@ -417,10 +432,25 @@ This is like `describe-bindings', but displays only Isearch keys."
     ;; We need these explicit definitions because, in a dense keymap,
     ;; the binding for t does not affect characters.
     ;; We use a dense keymap to save space.
+
     (while (< i ?\s)
       (define-key map (make-string 1 i) 'isearch-other-control-char)
       (setq i (1+ i)))
 
+    ;; Bring universal-argument and friends back in
+    (define-key map "\C-u" 'universal-argument)
+    (define-key map (kbd "C--") 'negative-argument)
+    (define-key map (kbd "C-0") 'digit-argument)
+    (define-key map (kbd "C-1") 'digit-argument)
+    (define-key map (kbd "C-2") 'digit-argument)
+    (define-key map (kbd "C-3") 'digit-argument)
+    (define-key map (kbd "C-4") 'digit-argument)
+    (define-key map (kbd "C-5") 'digit-argument)
+    (define-key map (kbd "C-6") 'digit-argument)
+    (define-key map (kbd "C-7") 'digit-argument)
+    (define-key map (kbd "C-8") 'digit-argument)
+    (define-key map (kbd "C-9") 'digit-argument)
+
     ;; Single-byte printing chars extend the search string by default.
     (setq i ?\s)
     (while (< i 256)
@@ -434,7 +464,20 @@ This is like `describe-bindings', but displays only Isearch keys."
     ;; default local key binding for any key not otherwise bound.
     (let ((meta-map (make-sparse-keymap)))
       (define-key map (char-to-string meta-prefix-char) meta-map)
-      (define-key map [escape] meta-map))
+      (define-key map [escape] meta-map)
+    (define-key meta-map (kbd "-") 'negative-argument)
+    (define-key meta-map (kbd "C--") 'negative-argument)
+    (define-key meta-map (kbd "C-0") 'digit-argument)
+    (define-key meta-map (kbd "C-1") 'digit-argument)
+    (define-key meta-map (kbd "C-2") 'digit-argument)
+    (define-key meta-map (kbd "C-3") 'digit-argument)
+    (define-key meta-map (kbd "C-4") 'digit-argument)
+    (define-key meta-map (kbd "C-5") 'digit-argument)
+    (define-key meta-map (kbd "C-6") 'digit-argument)
+    (define-key meta-map (kbd "C-7") 'digit-argument)
+    (define-key meta-map (kbd "C-8") 'digit-argument)
+    (define-key meta-map (kbd "C-9") 'digit-argument))
+
     (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
 
     ;; Several non-printing chars change the searching behavior.
@@ -528,6 +571,7 @@ This is like `describe-bindings', but displays only Isearch keys."
 ;; These are all set with setq while isearching
 ;; and bound locally while editing the search string.
 
+(defvar isearch-hint-count 0)
 (defvar isearch-forward nil)	; Searching in the forward direction.
 (defvar isearch-regexp nil)	; Searching for a regexp.
 (defvar isearch-word nil)	; Searching for words.
@@ -1340,15 +1384,30 @@ Use `isearch-exit' to quit without signaling."
   (isearch-push-state)
   (isearch-update))
 
-(defun isearch-repeat-forward ()
+(defun isearch-repeat-forward (arg)
   "Repeat incremental search forwards."
-  (interactive)
-  (isearch-repeat 'forward))
+  (interactive "p")
+  (while (> arg 0)
+    (isearch-repeat 'forward)
+    (setq arg (1- arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (while (< arg 0)
+    (isearch-repeat 'backward)
+    (setq arg (1+ arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (isearch-update))
 
-(defun isearch-repeat-backward ()
+(defun isearch-repeat-backward (arg)
   "Repeat incremental search backwards."
-  (interactive)
-  (isearch-repeat 'backward))
+  (interactive "p")
+  (while (> arg 0)
+    (isearch-repeat 'backward)
+    (setq arg (1- arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (while (< arg 0)
+    (isearch-repeat 'forward)
+    (setq arg (1+ arg)))
+  (setq isearch-hint-count (1+ isearch-hint-count)))
 
 (defun isearch-toggle-regexp ()
   "Toggle regexp searching on or off."
@@ -2627,6 +2686,7 @@ since they have special meaning in a regexp."
 (defvar isearch-lazy-highlight-word nil)
 (defvar isearch-lazy-highlight-forward nil)
 (defvar isearch-lazy-highlight-error nil)
+(defvar isearch-lazy-highlight-hint-count nil)
 
 (defun lazy-highlight-cleanup (&optional force)
   "Stop lazy highlighting and remove extra highlighting from current buffer.
@@ -2671,6 +2731,9 @@ by other Emacs features."
 			 isearch-lazy-highlight-window-end))
 		 (not (eq isearch-forward
 			  isearch-lazy-highlight-forward))
+		 (not (eq isearch-lazy-highlight-hint-count
+			  isearch-hint-count))
+
 		 ;; In case we are recovering from an error.
 		 (not (equal isearch-error
 			     isearch-lazy-highlight-error))))
@@ -2693,6 +2756,7 @@ by other Emacs features."
 	  isearch-lazy-highlight-regexp       isearch-regexp
 	  isearch-lazy-highlight-space-regexp search-whitespace-regexp
 	  isearch-lazy-highlight-word         isearch-word
+	  isearch-lazy-highlight-hint-count   isearch-hint-count
 	  isearch-lazy-highlight-forward      isearch-forward)
       (unless (equal isearch-string "")
 	(setq isearch-lazy-highlight-timer
@@ -2739,7 +2803,8 @@ Attempt to do the search exactly the way the pending Isearch would."
   "Update highlighting of other matches for current search."
   (let ((max lazy-highlight-max-at-a-time)
         (looping t)
-        nomore)
+        nomore
+	(count 1))
     (with-local-quit
       (save-selected-window
 	(if (and (window-live-p isearch-lazy-highlight-window)
@@ -2773,8 +2838,14 @@ Attempt to do the search exactly the way the pending Isearch would."
 			      (forward-char -1)))
 
 			;; non-zero-length match
-			(let ((ov (make-overlay mb me)))
+			(let ((ov (make-overlay mb me)) hint)
 			  (push ov isearch-lazy-highlight-overlays)
+			  (if (not isearch-lazy-highlight-wrapped)
+			      (progn
+				(setq hint (number-to-string count))
+				(setq count (1+ count))
+				(set-text-properties 0 (length hint) '(face lazy-highlight-hint) hint)
+				(overlay-put ov 'before-string hint)))
 			  ;; 1000 is higher than ediff's 100+,
 			  ;; but lower than isearch main overlay's 1001
 			  (overlay-put ov 'priority 1000)

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 17:27 bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
@ 2012-01-26 18:36 ` Tassilo Horn
  2012-01-26 18:46   ` Tassilo Horn
                     ` (3 more replies)
  2012-01-27  1:44 ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following " Juri Linkov
  2016-02-25  6:06 ` bug#10614: " Lars Ingebrigtsen
  2 siblings, 4 replies; 24+ messages in thread
From: Tassilo Horn @ 2012-01-26 18:36 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: juri, bug-gnu-emacs, emacs-devel

Gideon Stupp <gideon.stupp@gmail.com> writes:

Hi Gideon,

> This experimental patch implements a suggestion by Juri Linkov to extend
> isearch-repeat-forward/backward to support a prefix argument.

I like it.  I adapted it a bit to show the hints at the position where
point would be if that one's selected, and I added also a bit
superscript magic, which suits me better, visually.  (Well, that should
be customizable, of course.)

But how the heck is the usage of the prefix arg supposed to work?  When
I do C-s foo C-3, isearch is exited...

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 18:36 ` Tassilo Horn
@ 2012-01-26 18:46   ` Tassilo Horn
  2012-01-26 19:00   ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 24+ messages in thread
From: Tassilo Horn @ 2012-01-26 18:46 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: juri, bug-gnu-emacs, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Tassilo Horn <tassilo@member.fsf.org> writes:

>> This experimental patch implements a suggestion by Juri Linkov to
>> extend isearch-repeat-forward/backward to support a prefix argument.
>
> I like it.  I adapted it a bit to show the hints at the position where
> point would be if that one's selected, and I added also a bit
> superscript magic, which suits me better, visually.  (Well, that should
> be customizable, of course.)

Ups, I forgot to attach the patch.

Bye,
Tassilo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: isearchnavjuri.patch --]
[-- Type: text/x-patch, Size: 6509 bytes --]

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2012-01-19 07:21:25 +0000
+++ lisp/isearch.el	2012-01-26 18:32:18 +0000
@@ -333,6 +333,21 @@
                                 'lazy-highlight-face
                                 "22.1")
 (defvar lazy-highlight-face 'lazy-highlight)
+
+(defface lazy-highlight-hint
+  '((((class color) (min-colors 88) (background light))
+     (:background "paleturquoise" :bold t))
+    (((class color) (min-colors 88) (background dark))
+     (:background "paleturquoise4" :bold t))
+    (((class color) (min-colors 16))
+     (:background "turquoise3" :bold t))
+    (((class color) (min-colors 8))
+     (:background "turquoise3" :bold t))
+    (t (:underline t)))
+  "Face for lazy highlighting hints."
+  :group 'lazy-highlight
+  :group 'basic-faces)
+
 \f
 ;; Define isearch help map.
 
@@ -417,10 +432,25 @@
     ;; We need these explicit definitions because, in a dense keymap,
     ;; the binding for t does not affect characters.
     ;; We use a dense keymap to save space.
+
     (while (< i ?\s)
       (define-key map (make-string 1 i) 'isearch-other-control-char)
       (setq i (1+ i)))
 
+    ;; Bring universal-argument and friends back in
+    (define-key map "\C-u" 'universal-argument)
+    (define-key map (kbd "C--") 'negative-argument)
+    (define-key map (kbd "C-0") 'digit-argument)
+    (define-key map (kbd "C-1") 'digit-argument)
+    (define-key map (kbd "C-2") 'digit-argument)
+    (define-key map (kbd "C-3") 'digit-argument)
+    (define-key map (kbd "C-4") 'digit-argument)
+    (define-key map (kbd "C-5") 'digit-argument)
+    (define-key map (kbd "C-6") 'digit-argument)
+    (define-key map (kbd "C-7") 'digit-argument)
+    (define-key map (kbd "C-8") 'digit-argument)
+    (define-key map (kbd "C-9") 'digit-argument)
+
     ;; Single-byte printing chars extend the search string by default.
     (setq i ?\s)
     (while (< i 256)
@@ -434,7 +464,20 @@
     ;; default local key binding for any key not otherwise bound.
     (let ((meta-map (make-sparse-keymap)))
       (define-key map (char-to-string meta-prefix-char) meta-map)
-      (define-key map [escape] meta-map))
+      (define-key map [escape] meta-map)
+    (define-key meta-map (kbd "-") 'negative-argument)
+    (define-key meta-map (kbd "C--") 'negative-argument)
+    (define-key meta-map (kbd "C-0") 'digit-argument)
+    (define-key meta-map (kbd "C-1") 'digit-argument)
+    (define-key meta-map (kbd "C-2") 'digit-argument)
+    (define-key meta-map (kbd "C-3") 'digit-argument)
+    (define-key meta-map (kbd "C-4") 'digit-argument)
+    (define-key meta-map (kbd "C-5") 'digit-argument)
+    (define-key meta-map (kbd "C-6") 'digit-argument)
+    (define-key meta-map (kbd "C-7") 'digit-argument)
+    (define-key meta-map (kbd "C-8") 'digit-argument)
+    (define-key meta-map (kbd "C-9") 'digit-argument))
+
     (define-key map (vector meta-prefix-char t) 'isearch-other-meta-char)
 
     ;; Several non-printing chars change the searching behavior.
@@ -528,6 +571,7 @@
 ;; These are all set with setq while isearching
 ;; and bound locally while editing the search string.
 
+(defvar isearch-hint-count 0)
 (defvar isearch-forward nil)	; Searching in the forward direction.
 (defvar isearch-regexp nil)	; Searching for a regexp.
 (defvar isearch-word nil)	; Searching for words.
@@ -1340,15 +1384,30 @@
   (isearch-push-state)
   (isearch-update))
 
-(defun isearch-repeat-forward ()
+(defun isearch-repeat-forward (arg)
   "Repeat incremental search forwards."
-  (interactive)
-  (isearch-repeat 'forward))
+  (interactive "p")
+  (while (> arg 0)
+    (isearch-repeat 'forward)
+    (setq arg (1- arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (while (< arg 0)
+    (isearch-repeat 'backward)
+    (setq arg (1+ arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (isearch-update))
 
-(defun isearch-repeat-backward ()
+(defun isearch-repeat-backward (arg)
   "Repeat incremental search backwards."
-  (interactive)
-  (isearch-repeat 'backward))
+  (interactive "p")
+  (while (> arg 0)
+    (isearch-repeat 'backward)
+    (setq arg (1- arg))
+    (setq isearch-hint-count (1+ isearch-hint-count)))
+  (while (< arg 0)
+    (isearch-repeat 'forward)
+    (setq arg (1+ arg)))
+  (setq isearch-hint-count (1+ isearch-hint-count)))
 
 (defun isearch-toggle-regexp ()
   "Toggle regexp searching on or off."
@@ -2627,6 +2686,7 @@
 (defvar isearch-lazy-highlight-word nil)
 (defvar isearch-lazy-highlight-forward nil)
 (defvar isearch-lazy-highlight-error nil)
+(defvar isearch-lazy-highlight-hint-count nil)
 
 (defun lazy-highlight-cleanup (&optional force)
   "Stop lazy highlighting and remove extra highlighting from current buffer.
@@ -2671,6 +2731,9 @@
 			 isearch-lazy-highlight-window-end))
 		 (not (eq isearch-forward
 			  isearch-lazy-highlight-forward))
+		 (not (eq isearch-lazy-highlight-hint-count
+			  isearch-hint-count))
+
 		 ;; In case we are recovering from an error.
 		 (not (equal isearch-error
 			     isearch-lazy-highlight-error))))
@@ -2693,6 +2756,7 @@
 	  isearch-lazy-highlight-regexp       isearch-regexp
 	  isearch-lazy-highlight-space-regexp search-whitespace-regexp
 	  isearch-lazy-highlight-word         isearch-word
+	  isearch-lazy-highlight-hint-count   isearch-hint-count
 	  isearch-lazy-highlight-forward      isearch-forward)
       (unless (equal isearch-string "")
 	(setq isearch-lazy-highlight-timer
@@ -2739,7 +2803,8 @@
   "Update highlighting of other matches for current search."
   (let ((max lazy-highlight-max-at-a-time)
         (looping t)
-        nomore)
+        nomore
+	(count 1))
     (with-local-quit
       (save-selected-window
 	(if (and (window-live-p isearch-lazy-highlight-window)
@@ -2773,8 +2838,19 @@
 			      (forward-char -1)))
 
 			;; non-zero-length match
-			(let ((ov (make-overlay mb me)))
+			(let ((ov (make-overlay mb me)) hint)
 			  (push ov isearch-lazy-highlight-overlays)
+			  (if (not isearch-lazy-highlight-wrapped)
+			      (progn
+				(setq hint (number-to-string count))
+				(setq count (1+ count))
+				(set-text-properties 0 (length hint)
+						     '(face lazy-highlight-hint
+							    display ((height 0.7) (raise 0.3)))
+						     hint)
+				(if isearch-lazy-highlight-forward
+				    (overlay-put ov 'after-string hint)
+				  (overlay-put ov 'before-string hint))))
 			  ;; 1000 is higher than ediff's 100+,
 			  ;; but lower than isearch main overlay's 1001
 			  (overlay-put ov 'priority 1000)


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument
  2012-01-26 18:36 ` Tassilo Horn
  2012-01-26 18:46   ` Tassilo Horn
@ 2012-01-26 19:00   ` gideon.stupp
  2012-01-26 19:10     ` Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argum gideon.stupp
  2012-01-26 19:11   ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Tassilo Horn
  2012-01-26 21:43   ` bug#10614: [EXPERIMENTAL PATCH] ExtendingIsearch-repeat-forward/backward to support a prefix argumentfollowing " Drew Adams
  3 siblings, 1 reply; 24+ messages in thread
From: gideon.stupp @ 2012-01-26 19:00 UTC (permalink / raw)
  To: Tassilo Horn, Gideon Stupp; +Cc: juri, bug-gnu-emacs, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

hmm. It shouldn't exit. I probably have a bug in the patch (that's the  
problem with experimental patches ;)). I will look at it again in (my)  
morning.

Thanks, Gideon.

On , Tassilo Horn <tassilo@member.fsf.org> wrote:
> Gideon Stupp gideon.stupp@gmail.com> writes:



> Hi Gideon,



> > This experimental patch implements a suggestion by Juri Linkov to extend

> > isearch-repeat-forward/backward to support a prefix argument.



> I like it. I adapted it a bit to show the hints at the position where

> point would be if that one's selected, and I added also a bit

> superscript magic, which suits me better, visually. (Well, that should

> be customizable, of course.)



> But how the heck is the usage of the prefix arg supposed to work? When

> I do Cs foo C-3, isearch is exited...



> Bye,

> Tassilo


[-- Attachment #2: Type: text/html, Size: 1179 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argum
  2012-01-26 19:00   ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
@ 2012-01-26 19:10     ` gideon.stupp
  2012-01-26 19:32       ` Glenn Morris
  0 siblings, 1 reply; 24+ messages in thread
From: gideon.stupp @ 2012-01-26 19:10 UTC (permalink / raw)
  To: Tassilo Horn, Gideon Stupp; +Cc: juri, bug-gnu-emacs, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]

Oh, I just thought of something. If you try to patch isearch.el and then  
load-file it the new keybindings won't take place (the map is defvar'ed). I  
think you have to compile isearch.el to isearch.elc and then run with  
temacs.

Hope this helps,

Gideon.

On , gideon.stupp@gmail.com wrote:
> hmm. It shouldn't exit. I probably have a bug in the patch (that's the  
> problem with experimental patches ;)). I will look at it again in (my)  
> morning.

> Thanks, Gideon.

> On , Tassilo Horn tassilo@member.fsf.org> wrote:
> > Gideon Stupp gideon.stupp@gmail.com> writes:
> >
> >
> >
> > Hi Gideon,
> >
> >
> >
> > > This experimental patch implements a suggestion by Juri Linkov to  
> extend
> >
> > > isearch-repeat-forward/backward to support a prefix argument.
> >
> >
> >
> > I like it. I adapted it a bit to show the hints at the position where
> >
> > point would be if that one's selected, and I added also a bit
> >
> > superscript magic, which suits me better, visually. (Well, that should
> >
> > be customizable, of course.)
> >
> >
> >
> > But how the heck is the usage of the prefix arg supposed to work? When
> >
> > I do Cs foo C-3, isearch is exited...
> >
> >
> >
> > Bye,
> >
> > Tassilo
> >

[-- Attachment #2: Type: text/html, Size: 1703 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 18:36 ` Tassilo Horn
  2012-01-26 18:46   ` Tassilo Horn
  2012-01-26 19:00   ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
@ 2012-01-26 19:11   ` Tassilo Horn
  2012-01-26 19:28     ` bug#10614: " Jérémy Compostella
  2012-01-26 21:43   ` bug#10614: [EXPERIMENTAL PATCH] ExtendingIsearch-repeat-forward/backward to support a prefix argumentfollowing " Drew Adams
  3 siblings, 1 reply; 24+ messages in thread
From: Tassilo Horn @ 2012-01-26 19:11 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: juri, bug-gnu-emacs, emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> But how the heck is the usage of the prefix arg supposed to work?
> When I do C-s foo C-3, isearch is exited...

That was my fault.  Of course, loading the patched isearch.el didn't
make the changed isearch-mode-map active (defvar).  It works fine, now.

Usability-wise, C-s foo C-<number> C-s makes only sense if that
keystroke is shorter to type than C-s multiple times.  So maybe the
numbering should start with some offset, say, with the 5th next match?

And the typing of C-s after the number is a bit inconvenient, so maybe,
C-7 could jump directly to the match hinted with 7, and only for
two-digit matches C-s was needed, i.e., C-u 1 2 C-s to jump to the 12th
match?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 19:11   ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Tassilo Horn
@ 2012-01-26 19:28     ` Jérémy Compostella
  0 siblings, 0 replies; 24+ messages in thread
From: Jérémy Compostella @ 2012-01-26 19:28 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: 10614, Gideon Stupp, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]

2012/1/26 Tassilo Horn <tassilo@member.fsf.org>

> Tassilo Horn <tassilo@member.fsf.org> writes:
>
> > But how the heck is the usage of the prefix arg supposed to work?
> > When I do C-s foo C-3, isearch is exited...
>
> That was my fault.  Of course, loading the patched isearch.el didn't
> make the changed isearch-mode-map active (defvar).  It works fine, now.
>
> Usability-wise, C-s foo C-<number> C-s makes only sense if that
> keystroke is shorter to type than C-s multiple times.  So maybe the
> numbering should start with some offset, say, with the 5th next match?
>
> And the typing of C-s after the number is a bit inconvenient, so maybe,
> C-7 could jump directly to the match hinted with 7, and only for
> two-digit matches C-s was needed, i.e., C-u 1 2 C-s to jump to the 12th
> match?
>
>
I just played play with it too and I really like it. Here my notes:
- I do agree with Tassilo, C-7 should directly jump to match hinted 7.
- When more than lazy-highlight-max-at-a-time are visible in the window,
  the prefix number is restarted from 1 on the next match hinted. It's
confusing
  and I think it should not appear on these items.
- A defcustom variable should be added to enable/disable the match hinted
prefix
  number.

Anyway, it's an very interesting improvement.

Jérémy

[-- Attachment #2: Type: text/html, Size: 1815 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argum
  2012-01-26 19:10     ` Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argum gideon.stupp
@ 2012-01-26 19:32       ` Glenn Morris
  0 siblings, 0 replies; 24+ messages in thread
From: Glenn Morris @ 2012-01-26 19:32 UTC (permalink / raw)
  To: gideon.stupp; +Cc: emacs-devel


Hi - please could you either:

1) start cc'ing 10614@debbugs.gnu.org instead of bug-gnu-emacs
2) stop having this discussion on two mailing lists

because otherwise you will end up creating multiple bug reports every
time you change the subject header.

Personally I think very few things need to be discussed on multiple
Emacs mailing lists at the same time, and this is not one of them. So I
suggest you pick one list and stick with it.

Note that if you want to cc someone on a new bug report, the right way
is to use an x-debbugs-cc header when you make the initial report (see
debbugs docs).

Thanks.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* RE: bug#10614: [EXPERIMENTAL PATCH] ExtendingIsearch-repeat-forward/backward to support a prefix argumentfollowing suggesion by Juri Linkov
  2012-01-26 18:36 ` Tassilo Horn
                     ` (2 preceding siblings ...)
  2012-01-26 19:11   ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Tassilo Horn
@ 2012-01-26 21:43   ` Drew Adams
  3 siblings, 0 replies; 24+ messages in thread
From: Drew Adams @ 2012-01-26 21:43 UTC (permalink / raw)
  To: 'Tassilo Horn', 'Gideon Stupp'; +Cc: 10614, emacs-devel

Please do not send stuff to both emacs-devel and the bug list.




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 17:27 bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
  2012-01-26 18:36 ` Tassilo Horn
@ 2012-01-27  1:44 ` Juri Linkov
  2012-01-27  6:17   ` Gideon Stupp
  2016-02-25  6:06 ` bug#10614: " Lars Ingebrigtsen
  2 siblings, 1 reply; 24+ messages in thread
From: Juri Linkov @ 2012-01-27  1:44 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: emacs-devel

> Please try it out.

Thanks.  A few comments below:

> +    ;; Bring universal-argument and friends back in
> +    (define-key map "\C-u" 'universal-argument)
> +    (define-key map (kbd "C--") 'negative-argument)
> +    (define-key map (kbd "C-0") 'digit-argument)
> +    (define-key map (kbd "C-1") 'digit-argument)
> +    (define-key map (kbd "C-2") 'digit-argument)
> +    (define-key map (kbd "C-3") 'digit-argument)
> +    (define-key map (kbd "C-4") 'digit-argument)
> +    (define-key map (kbd "C-5") 'digit-argument)
> +    (define-key map (kbd "C-6") 'digit-argument)
> +    (define-key map (kbd "C-7") 'digit-argument)
> +    (define-key map (kbd "C-8") 'digit-argument)
> +    (define-key map (kbd "C-9") 'digit-argument)

> +    (define-key meta-map (kbd "-") 'negative-argument)
> +    (define-key meta-map (kbd "C--") 'negative-argument)
> +    (define-key meta-map (kbd "C-0") 'digit-argument)
> +    (define-key meta-map (kbd "C-1") 'digit-argument)
> +    (define-key meta-map (kbd "C-2") 'digit-argument)
> +    (define-key meta-map (kbd "C-3") 'digit-argument)
> +    (define-key meta-map (kbd "C-4") 'digit-argument)
> +    (define-key meta-map (kbd "C-5") 'digit-argument)
> +    (define-key meta-map (kbd "C-6") 'digit-argument)
> +    (define-key meta-map (kbd "C-7") 'digit-argument)
> +    (define-key meta-map (kbd "C-8") 'digit-argument)
> +    (define-key meta-map (kbd "C-9") 'digit-argument))

Instead of adding these keybindings, you can just set
`isearch-allow-scroll' to t.

Also there are plans to add a better variable `isearch-enable-prefix'
in 24.2, you can see more information at this link -
http://thread.gmane.org/gmane.emacs.devel/143829

> -(defun isearch-repeat-forward ()
> +(defun isearch-repeat-forward (arg)

> -(defun isearch-repeat-backward ()
> +(defun isearch-repeat-backward (arg)

Please use (&optional arg) for backward-compatibility.

> +				(setq hint (number-to-string count))
> +				(setq count (1+ count))
> +				(set-text-properties 0 (length hint) '(face lazy-highlight-hint) hint)
> +				(overlay-put ov 'before-string hint)))

A suggestion by Tassilo to use superscripts looks good too,
but then these hints look like references to footnotes :-)



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-27  1:44 ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following " Juri Linkov
@ 2012-01-27  6:17   ` Gideon Stupp
  2012-01-27 12:07     ` Juri Linkov
  0 siblings, 1 reply; 24+ messages in thread
From: Gideon Stupp @ 2012-01-27  6:17 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 3256 bytes --]

Thank you for your comments Juri.  Do you have a thought on how to
implement this functionality as a package the way Stefan asked for?
Negative arguments in particular seem to be challenging. Right now I
implemented negative argument navigation by calling isearch-repeat with the
opposite functionality but that has all kinds of odd effects. For example
the search message changes,  C-- C-1 isearch-forward does not go back one
matched string but rather just switches to isearch-backward and so on.  I
did  implement visual hints for the negative arguments because that would
require changing the way lazy highlight works significantly (lazy-highlight
loop wraps around back to the first line and at that point you can't know
the negative argument for the current match).


On Fri, Jan 27, 2012 at 3:44 AM, Juri Linkov <juri@jurta.org> wrote:

> > Please try it out.
>
> Thanks.  A few comments below:
>
> > +    ;; Bring universal-argument and friends back in
> > +    (define-key map "\C-u" 'universal-argument)
> > +    (define-key map (kbd "C--") 'negative-argument)
> > +    (define-key map (kbd "C-0") 'digit-argument)
> > +    (define-key map (kbd "C-1") 'digit-argument)
> > +    (define-key map (kbd "C-2") 'digit-argument)
> > +    (define-key map (kbd "C-3") 'digit-argument)
> > +    (define-key map (kbd "C-4") 'digit-argument)
> > +    (define-key map (kbd "C-5") 'digit-argument)
> > +    (define-key map (kbd "C-6") 'digit-argument)
> > +    (define-key map (kbd "C-7") 'digit-argument)
> > +    (define-key map (kbd "C-8") 'digit-argument)
> > +    (define-key map (kbd "C-9") 'digit-argument)
>
> > +    (define-key meta-map (kbd "-") 'negative-argument)
> > +    (define-key meta-map (kbd "C--") 'negative-argument)
> > +    (define-key meta-map (kbd "C-0") 'digit-argument)
> > +    (define-key meta-map (kbd "C-1") 'digit-argument)
> > +    (define-key meta-map (kbd "C-2") 'digit-argument)
> > +    (define-key meta-map (kbd "C-3") 'digit-argument)
> > +    (define-key meta-map (kbd "C-4") 'digit-argument)
> > +    (define-key meta-map (kbd "C-5") 'digit-argument)
> > +    (define-key meta-map (kbd "C-6") 'digit-argument)
> > +    (define-key meta-map (kbd "C-7") 'digit-argument)
> > +    (define-key meta-map (kbd "C-8") 'digit-argument)
> > +    (define-key meta-map (kbd "C-9") 'digit-argument))
>
> Instead of adding these keybindings, you can just set
> `isearch-allow-scroll' to t.
>
> Also there are plans to add a better variable `isearch-enable-prefix'
> in 24.2, you can see more information at this link -
> http://thread.gmane.org/gmane.emacs.devel/143829
>
> > -(defun isearch-repeat-forward ()
> > +(defun isearch-repeat-forward (arg)
>
> > -(defun isearch-repeat-backward ()
> > +(defun isearch-repeat-backward (arg)
>
> Please use (&optional arg) for backward-compatibility.
>
> > +                             (setq hint (number-to-string count))
> > +                             (setq count (1+ count))
> > +                             (set-text-properties 0 (length hint)
> '(face lazy-highlight-hint) hint)
> > +                             (overlay-put ov 'before-string hint)))
>
> A suggestion by Tassilo to use superscripts looks good too,
> but then these hints look like references to footnotes :-)
>

[-- Attachment #2: Type: text/html, Size: 4234 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-27  6:17   ` Gideon Stupp
@ 2012-01-27 12:07     ` Juri Linkov
  2012-01-27 17:05       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport " Drew Adams
                         ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Juri Linkov @ 2012-01-27 12:07 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: emacs-devel

> Thank you for your comments Juri.  Do you have a thought on how to
> implement this functionality as a package the way Stefan asked for?

Adding a new count argument to `isearch-repeat-forward' is a pretty
unobtrusive change and is standard Emacs practice.  But if you want
to do fancy stuff with hint display then you could add a hook to
`isearch-lazy-highlight-update' and implement fancy features in a separate
package whose functionality is added by the hook.

> Negative arguments in particular seem to be challenging. Right now I
> implemented negative argument navigation by calling isearch-repeat with the
> opposite functionality but that has all kinds of odd effects.
> For example the search message changes, C-- C-1 isearch-forward does
> not go back one matched string but rather just switches to
> isearch-backward and so on.

Then you need to take into account this situation and to add 1 to the
counter when isearch-forward switches to isearch-backward with C-- C-1.

> I did implement visual hints for the negative arguments because that
> would require changing the way lazy highlight works significantly
> (lazy-highlight loop wraps around back to the first line and at that
> point you can't know the negative argument for the current match).

There are other problems with negative arguments: sometimes backward
regexp search finds more matches than forward regexp search.
For instance, trying to search a regexp like "a+" forward on a string
like "aaa" finds all occurrences of "aaa" as one match, but backward
regexp search matches every "a" individually.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* RE: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport a prefix argument following suggesion by Juri Linkov
  2012-01-27 12:07     ` Juri Linkov
@ 2012-01-27 17:05       ` Drew Adams
  2012-01-28 12:40         ` RE: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport a prefix argument f gideon.stupp
  2012-01-28 12:31       ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
  2012-01-29 16:11       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
  2 siblings, 1 reply; 24+ messages in thread
From: Drew Adams @ 2012-01-27 17:05 UTC (permalink / raw)
  To: 'Juri Linkov', 'Gideon Stupp'; +Cc: emacs-devel

> Adding a new count argument to `isearch-repeat-forward' is a pretty
> unobtrusive change and is standard Emacs practice.

Not really following this thread, so I don't have an opinion on the proposed
change (not even sure what it is).

I'd just point out that the use of a prefix arg for the count does change the
current UI, where the prefix arg has a different meaning.  (Not a big deal,
IMO.)




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument
  2012-01-27 12:07     ` Juri Linkov
  2012-01-27 17:05       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport " Drew Adams
@ 2012-01-28 12:31       ` gideon.stupp
  2012-01-29 16:11       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
  2 siblings, 0 replies; 24+ messages in thread
From: gideon.stupp @ 2012-01-28 12:31 UTC (permalink / raw)
  To: Juri Linkov, Gideon Stupp; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2105 bytes --]

So it seems that the support for negative arguments will be best effort  
anyway.
Ok, I will make sure the counting is done right. Also I believe that
when C-- C-1 isearch-forward is pressed the user expects to stay in  
isearch-forward and not switch to isearch-backward so I will add another  
call to isearch-forward just to change the direction. Not pretty but should  
do the job.

Thanks, gideon.

On , Juri Linkov <juri@jurta.org> wrote:
> > Thank you for your comments Juri. Do you have a thought on how to

> > implement this functionality as a package the way Stefan asked for?



> Adding a new count argument to `isearch-repeat-forward' is a pretty

> unobtrusive change and is standard Emacs practice. But if you want

> to do fancy stuff with hint display then you could add a hook to

> `isearch-lazy-highlight-update' and implement fancy features in a separate

> package whose functionality is added by the hook.



> > Negative arguments in particular seem to be challenging. Right now I

> > implemented negative argument navigation by calling isearch-repeat with  
> the

> > opposite functionality but that has all kinds of odd effects.

> > For example the search message changes, C-- C-1 isearch-forward does

> > not go back one matched string but rather just switches to

> > isearch-backward and so on.



> Then you need to take into account this situation and to add 1 to the

> counter when isearch-forward switches to isearch-backward with C-- C-1.



> > I did implement visual hints for the negative arguments because that

> > would require changing the way lazy highlight works significantly

> > (lazy-highlight loop wraps around back to the first line and at that

> > point you can't know the negative argument for the current match).



> There are other problems with negative arguments: sometimes backward

> regexp search finds more matches than forward regexp search.

> For instance, trying to search a regexp like "a+" forward on a string

> like "aaa" finds all occurrences of "aaa" as one match, but backward

> regexp search matches every "a" individually.


[-- Attachment #2: Type: text/html, Size: 2750 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: RE: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport a prefix argument f
  2012-01-27 17:05       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport " Drew Adams
@ 2012-01-28 12:40         ` gideon.stupp
  0 siblings, 0 replies; 24+ messages in thread
From: gideon.stupp @ 2012-01-28 12:40 UTC (permalink / raw)
  To: Drew Adams, Gideon Stupp; +Cc: Juri Linkov, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

Thanks for pointing that out Drew. I think that if I follow Juri's  
suggestion and rely on isearch-allow-scroll instead of changing the key  
mapping it should be ok.

Gideon.

On , Drew Adams <drew.adams@oracle.com> wrote:
> > Adding a new count argument to `isearch-repeat-forward' is a pretty

> > unobtrusive change and is standard Emacs practice.



> Not really following this thread, so I don't have an opinion on the  
> proposed

> change (not even sure what it is).



> I'd just point out that the use of a prefix arg for the count does change  
> the

> current UI, where the prefix arg has a different meaning. (Not a big deal,

> IMO.)




[-- Attachment #2: Type: text/html, Size: 875 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-27 12:07     ` Juri Linkov
  2012-01-27 17:05       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport " Drew Adams
  2012-01-28 12:31       ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
@ 2012-01-29 16:11       ` Gideon Stupp
  2012-01-30  0:38         ` Juri Linkov
  2 siblings, 1 reply; 24+ messages in thread
From: Gideon Stupp @ 2012-01-29 16:11 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 2236 bytes --]

Hi Juri,

I am attaching a short patch which implements prefix arg support for
'isearch-repeat-forward' and 'isearch-repeat-backward'. It does not contain
any visual hints or even hooks for visual support because it seems
worthwhile to test this functionality for a while before adding anything
"fancy" as you say.  Negative arguments are supported in what seems to me a
reasonable way, though clearly not ideal for regex searches as point out.

Please let me know if you think any more changes are required.

Thanks, Gideon.


On Fri, Jan 27, 2012 at 2:07 PM, Juri Linkov <juri@jurta.org> wrote:

> > Thank you for your comments Juri.  Do you have a thought on how to
> > implement this functionality as a package the way Stefan asked for?
>
> Adding a new count argument to `isearch-repeat-forward' is a pretty
> unobtrusive change and is standard Emacs practice.  But if you want
> to do fancy stuff with hint display then you could add a hook to
> `isearch-lazy-highlight-update' and implement fancy features in a separate
> package whose functionality is added by the hook.
>
> > Negative arguments in particular seem to be challenging. Right now I
> > implemented negative argument navigation by calling isearch-repeat with
> the
> > opposite functionality but that has all kinds of odd effects.
> > For example the search message changes, C-- C-1 isearch-forward does
> > not go back one matched string but rather just switches to
> > isearch-backward and so on.
>
> Then you need to take into account this situation and to add 1 to the
> counter when isearch-forward switches to isearch-backward with C-- C-1.
>
> > I did implement visual hints for the negative arguments because that
> > would require changing the way lazy highlight works significantly
> > (lazy-highlight loop wraps around back to the first line and at that
> > point you can't know the negative argument for the current match).
>
> There are other problems with negative arguments: sometimes backward
> regexp search finds more matches than forward regexp search.
> For instance, trying to search a regexp like "a+" forward on a string
> like "aaa" finds all occurrences of "aaa" as one match, but backward
> regexp search matches every "a" individually.
>

[-- Attachment #1.2: Type: text/html, Size: 2775 bytes --]

[-- Attachment #2: isearch_repeat_prefix_arg_support.patch --]
[-- Type: application/octet-stream, Size: 1400 bytes --]

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."

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-29 16:11       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
@ 2012-01-30  0:38         ` Juri Linkov
  2012-01-30  9:53           ` Gideon Stupp
  0 siblings, 1 reply; 24+ messages in thread
From: Juri Linkov @ 2012-01-30  0:38 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: emacs-devel

> I am attaching a short patch which implements prefix arg support for
> 'isearch-repeat-forward' and 'isearch-repeat-backward'. It does not contain
> any visual hints or even hooks for visual support because it seems
> worthwhile to test this functionality for a while before adding anything
> "fancy" as you say.  Negative arguments are supported in what seems to me a
> reasonable way, though clearly not ideal for regex searches as point out.
>
> Please let me know if you think any more changes are required.

It's not yet clear what is the most expected behavior.

With your patch, typing `C-s a C-3 C-s C- C-3 C-s' returns the isearch point
to the original position - this is good, thanks.

But its behavior is not deterministic: it depends on the current search
direction before calling these commands with a numeric argument.
So e.g. `C-s a C-3 C-s C-r C- C-3 C-s' (where `C-r' just switches
the search direction) doesn't return it to the original position.
Perhaps you need to check the current direction defined in the variable
`isearch-forward' and take it into account.

Another question is why e.g. `C-s a C-3 C-s C-3 C-r' doesn't handle
switching of search direction and does not return to the original position?
In terms of implementation, the question is: why in
`isearch-repeat-forward' and `isearch-repeat-backward' you don't add code
that switches the current direction to the `(> arg 0)' code branch?



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-30  0:38         ` Juri Linkov
@ 2012-01-30  9:53           ` Gideon Stupp
  2012-01-30 22:53             ` Juri Linkov
  0 siblings, 1 reply; 24+ messages in thread
From: Gideon Stupp @ 2012-01-30  9:53 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2707 bytes --]

On Mon, Jan 30, 2012 at 2:38 AM, Juri Linkov <juri@jurta.org> wrote:

> > I am attaching a short patch which implements prefix arg support for
> > 'isearch-repeat-forward' and 'isearch-repeat-backward'. It does not
> contain
> > any visual hints or even hooks for visual support because it seems
> > worthwhile to test this functionality for a while before adding anything
> > "fancy" as you say.  Negative arguments are supported in what seems to
> me a
> > reasonable way, though clearly not ideal for regex searches as point out.
> >
> > Please let me know if you think any more changes are required.
>
> It's not yet clear what is the most expected behavior.
>
> With your patch, typing `C-s a C-3 C-s C- C-3 C-s' returns the isearch
> point
> to the original position - this is good, thanks.
>
> But its behavior is not deterministic: it depends on the current search
> direction before calling these commands with a numeric argument.
> So e.g. `C-s a C-3 C-s C-r C- C-3 C-s' (where `C-r' just switches
> the search direction) doesn't return it to the original position.
> Perhaps you need to check the current direction defined in the variable
> `isearch-forward' and take it into account.
>
> This is bug; I did not think of this scenario. Thanks for pointing it out.


> Another question is why e.g. `C-s a C-3 C-s C-3 C-r' doesn't handle
> switching of search direction and does not return to the original position?
> In terms of implementation, the question is: why in
> `isearch-repeat-forward' and `isearch-repeat-backward' you don't add code
> that switches the current direction to the `(> arg 0)' code branch?
>

I did not add code that switches the current direction in the (> arg 0)
case for compatibility reasons; I wanted C-3 C-s to behave exactly like C-s
C-s C-s.
But I do see your point. So how about the following behavior (for brevity I
will describe only isearch-repeat-forward):  (1) if you use
isearch-repeat-forward then at the end of the operation you must be in a
search-forward state; (2) the numerical value decides how many searches are
done and (3) the sign defines the direction. More specifically

isearch-repeat-forward   -|  the usual "interactive" mode.

C-0 isearch-repeat-forward -|  if in backward search switch to forward
search but don't do any actual search, otherwise don't do anything.
C-<number> isearch-repeat-forward -| switch to forward search (if
necessary) and search <number> times forward.
C-u isearch-repeat-forward              -| like C-4

C-- C-<number> isearch-repreat-forward -| go back <number> times of search
but make sure to finish in forward-search state.
C-- isearch-repeat-forward  -|  like C- C-1 isearch-repeat-forward.

Thanks, Gideon.

[-- Attachment #2: Type: text/html, Size: 3414 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-30  9:53           ` Gideon Stupp
@ 2012-01-30 22:53             ` Juri Linkov
  2012-01-31 11:52               ` Gideon Stupp
  0 siblings, 1 reply; 24+ messages in thread
From: Juri Linkov @ 2012-01-30 22:53 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: emacs-devel

> So how about the following behavior (for brevity I will describe only
> isearch-repeat-forward): (1) if you use isearch-repeat-forward then at
> the end of the operation you must be in a search-forward state; (2)
> the numerical value decides how many searches are done and (3) the
> sign defines the direction.

Thanks.  I agree that these rules are reasonable.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-30 22:53             ` Juri Linkov
@ 2012-01-31 11:52               ` Gideon Stupp
  2012-01-31 20:18                 ` Juri Linkov
  0 siblings, 1 reply; 24+ messages in thread
From: Gideon Stupp @ 2012-01-31 11:52 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 605 bytes --]

On 1/31/12, Juri Linkov <juri@jurta.org> wrote:
>> So how about the following behavior (for brevity I will describe only
>> isearch-repeat-forward): (1) if you use isearch-repeat-forward then at
>> the end of the operation you must be in a search-forward state; (2)
>> the numerical value decides how many searches are done and (3) the
>> sign defines the direction.
>
> Thanks.  I agree that these rules are reasonable.
>
Hi Juri,
Please see attached patch. Note that I decided to stop the repeated
search at wraparound and any other case where the search fails (eq
isearch-sucess nil).

Thanks, Gideon.

[-- Attachment #2: isearch_repeat_prefix_arg_support.patch --]
[-- Type: text/x-patch, Size: 2157 bytes --]

diff --git a/lisp/isearch.el b/lisp/isearch.el
index ce75911..04f29ba 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1340,15 +1340,60 @@ 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
+      (let ((narg (prefix-numeric-value arg)))
+	(if (< narg 0)
+	    ;; Go backward.
+	    (progn
+	      ;; Switch direction if necessary
+	      (if isearch-forward (isearch-repeat 'backward))
+	      ;; Go back narg times
+	      (while (and isearch-success (< narg 0))
+		(isearch-repeat 'backward)
+		(setq narg (1+ narg)))
+	      ;; Switch back to forward search
+	      (isearch-repeat 'forward))
+	  ;; Go forward
+	  (progn
+	    ;; Switch direction if necessary
+	    (or isearch-forward (isearch-repeat 'forward))
+	    ;; Go forward narg times
+	    (while (and isearch-success (> narg 0))
+	      (isearch-repeat 'forward)
+	      (setq narg (1- narg))))))
+    ;; No argument
+    (isearch-repeat 'forward)))
+
+(defun isearch-repeat-backward (&optional arg)
   "Repeat incremental search backwards."
-  (interactive)
-  (isearch-repeat 'backward))
+  (interactive "P")
+  (if arg
+    (let ((narg (prefix-numeric-value arg)))
+     (if (< narg 0)
+	 ;; Go forward.
+	 (progn
+	   ;; Switch direction if necessary
+	   (or isearch-forward (isearch-repeat 'forward))
+	   ;; Go back narg times
+	   (while (and isearch-success(< narg 0))
+	     (isearch-repeat 'forward)
+	     (setq narg (1+ narg)))
+	   ;; Switch back to backward search
+	   (isearch-repeat 'backward))
+       ;; Go backward
+       (progn
+	 ;; Switch direction if necessary
+	 (if isearch-forward (isearch-repeat 'backward))
+	 ;; Go backward narg times
+	 (while (and isearch-success (> narg 0))
+	   (isearch-repeat 'backward)
+	   (setq narg (1- narg))))))
+    ;; No argument
+    (isearch-repeat 'backward)))
+
 
 (defun isearch-toggle-regexp ()
   "Toggle regexp searching on or off."

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-31 11:52               ` Gideon Stupp
@ 2012-01-31 20:18                 ` Juri Linkov
  0 siblings, 0 replies; 24+ messages in thread
From: Juri Linkov @ 2012-01-31 20:18 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: emacs-devel

> Please see attached patch. Note that I decided to stop the repeated
> search at wraparound and any other case where the search fails (eq
> isearch-sucess nil).

I think you are right that repeated Isearch should stop at wraparound
and other search errors.  Thanks.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2012-01-26 17:27 bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
  2012-01-26 18:36 ` Tassilo Horn
  2012-01-27  1:44 ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following " Juri Linkov
@ 2016-02-25  6:06 ` Lars Ingebrigtsen
  2016-02-29 23:44   ` Juri Linkov
  2 siblings, 1 reply; 24+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-25  6:06 UTC (permalink / raw)
  To: Gideon Stupp; +Cc: juri, emacs-devel, 10614

Gideon Stupp <gideon.stupp@gmail.com> writes:

> This experimental patch implements a suggestion by Juri Linkov to
> extend isearch-repeat-forward/backward to support a prefix
> argument. Instead of pressing C-s / C-r multiple times it is possible
> with this patch to enter a prefix argument which runs the command
> multiple times for you. If a negative argument is given for
> isearch-repeat-forward then isearch-repeat-backward is run and visa
> versa. Visual hints are added to the matched strings to help figure
> out what argument should be given.

Hm...  I guess I can see why this would be attractive, but I'm a bit
sceptical.  Numeric prefixes make sense in many instances, but I would
myself never this "hm, I must repeat the search three times"...  I would
just hit `C-s' four times instead.  That seems faster and more
convenient...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2016-02-25  6:06 ` bug#10614: " Lars Ingebrigtsen
@ 2016-02-29 23:44   ` Juri Linkov
  2016-03-01  0:43     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 24+ messages in thread
From: Juri Linkov @ 2016-02-29 23:44 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Gideon Stupp, emacs-devel, 10614

>> This experimental patch implements a suggestion by Juri Linkov to
>> extend isearch-repeat-forward/backward to support a prefix
>> argument. Instead of pressing C-s / C-r multiple times it is possible
>> with this patch to enter a prefix argument which runs the command
>> multiple times for you. If a negative argument is given for
>> isearch-repeat-forward then isearch-repeat-backward is run and visa
>> versa. Visual hints are added to the matched strings to help figure
>> out what argument should be given.
>
> Hm...  I guess I can see why this would be attractive, but I'm a bit
> sceptical.  Numeric prefixes make sense in many instances, but I would
> myself never this "hm, I must repeat the search three times"...  I would
> just hit `C-s' four times instead.  That seems faster and more
> convenient...

What if you need to visit a Nth occurrence where N is larger
than the number of keystrokes with numeric prefixes
(while using isearch for navigation)?



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
  2016-02-29 23:44   ` Juri Linkov
@ 2016-03-01  0:43     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 24+ messages in thread
From: Lars Ingebrigtsen @ 2016-03-01  0:43 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Gideon Stupp, emacs-devel, 10614

Juri Linkov <juri@jurta.org> writes:

> What if you need to visit a Nth occurrence where N is larger
> than the number of keystrokes with numeric prefixes
> (while using isearch for navigation)?

I still don't think I'd want to enter a number.  I'd either stop doing
isearch if it was too far away (and just move the cursor where I wanted
it to be), or I'd hit `C-s' a lot.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2016-03-01  0:43 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-26 17:27 bug#10614: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
2012-01-26 18:36 ` Tassilo Horn
2012-01-26 18:46   ` Tassilo Horn
2012-01-26 19:00   ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
2012-01-26 19:10     ` Re: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argum gideon.stupp
2012-01-26 19:32       ` Glenn Morris
2012-01-26 19:11   ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Tassilo Horn
2012-01-26 19:28     ` bug#10614: " Jérémy Compostella
2012-01-26 21:43   ` bug#10614: [EXPERIMENTAL PATCH] ExtendingIsearch-repeat-forward/backward to support a prefix argumentfollowing " Drew Adams
2012-01-27  1:44 ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following " Juri Linkov
2012-01-27  6:17   ` Gideon Stupp
2012-01-27 12:07     ` Juri Linkov
2012-01-27 17:05       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport " Drew Adams
2012-01-28 12:40         ` RE: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward tosupport a prefix argument f gideon.stupp
2012-01-28 12:31       ` Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument gideon.stupp
2012-01-29 16:11       ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov Gideon Stupp
2012-01-30  0:38         ` Juri Linkov
2012-01-30  9:53           ` Gideon Stupp
2012-01-30 22:53             ` Juri Linkov
2012-01-31 11:52               ` Gideon Stupp
2012-01-31 20:18                 ` Juri Linkov
2016-02-25  6:06 ` bug#10614: " Lars Ingebrigtsen
2016-02-29 23:44   ` Juri Linkov
2016-03-01  0:43     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).