all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Gideon Stupp <gideon.stupp@gmail.com>
To: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov
Date: Sun, 29 Jan 2012 18:11:43 +0200	[thread overview]
Message-ID: <CAJzWQ4d4LPrG29=e2Rq19AZ2T-JJ+3gbWmZ-KvT8oRjPS0X1Lg@mail.gmail.com> (raw)
In-Reply-To: <87ty3h2uvp.fsf@mail.jurta.org>


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

  parent reply	other threads:[~2012-01-29 16:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 19:28     ` 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-26 21:43   ` 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       ` Gideon Stupp [this message]
2012-01-30  0:38         ` [EXPERIMENTAL PATCH] Extending Isearch-repeat-forward/backward to support a prefix argument following suggesion by Juri Linkov 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
2019-06-27 15:36       ` Lars Ingebrigtsen
2016-03-01  0:43     ` Lars Ingebrigtsen
2016-02-29 23:44   ` Juri Linkov
2016-02-25  6:06 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJzWQ4d4LPrG29=e2Rq19AZ2T-JJ+3gbWmZ-KvT8oRjPS0X1Lg@mail.gmail.com' \
    --to=gideon.stupp@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.