emacs-devel
[Top][All Lists]
Advanced

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

Re: isearch-query-replace-regexp and stuff


From: Juri Linkov
Subject: Re: isearch-query-replace-regexp and stuff
Date: Sat, 03 Jul 2004 09:59:14 +0300
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

David Kastrup <address@hidden> writes:
> The other thing that might make sense is to just define M-% and use it
> to start regexp replacements in regexp searches, and non-regexp
> replaced in normal isearch.  It might be confusing.  OTOH, the C-s
> binding during searches already has this sort of split personality.

Yes, it makes sense to use M-% to start regexp replacements in regexp
search.  I often mistakenly type M-% even if I want to start regexp
replacements, and then cancel it and retype C-M-%.  Using M-% to start
regexp replacements in regexp isearch will reduce such mistakes.  If
users have switched to regexp search mode there is a high probability
than they want regexp replacements and mistyped M-% instead of C-M-%.

>> We could use a prefix argument of M-r to implement these things
>> instead of adding a new key binding.
>
> No, we couldn't.  Prefix arguments exit the search.

Prefix arguments don't exit the search.  IIRC, this is a relatively
recent change in isearch.el.

> It might make sense when switching to use the respective search
> history's last entry _if_ it happens to match at point.

This is useless.  It's possible to type M-p just after switching
the search mode to use the respective search history's last entry.
But the current non-intrusive behavior of M-r is much better
for users who use it to switch the search type invoked by mistake
(`C-s' instead of `C-M-s') or by other reasons (e.g. want to add
regexp constructs to the current search string).

BTW, M-p currently does not work right.  When typing it after starting
isearch mode (i.e. `C-s M-p') it uses not the most recent item in the
search ring, but the second history item.  The patch below fixes this
problem.  It makes M-p to start visiting previous search strings from
the index 0 instead of 1.  And in those places where the last search
string is reused after typing `C-s C-s' it calls `isearch-ring-adjust1'
to adjust the isearch ring to the first element to prepare the correct
index for further M-p and M-n commands.

Index: lisp/isearch.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.230
diff -u -w -b -r1.230 isearch.el
--- lisp/isearch.el     1 Jul 2004 09:54:51 -0000       1.230
+++ lisp/isearch.el     3 Jul 2004 07:32:43 -0000
@@ -911,6 +911,7 @@
 
          ;; Empty isearch-string means use default.
          (if (= 0 (length isearch-string))
+             (progn
              (setq isearch-string (or (car (if isearch-regexp
                                                regexp-search-ring
                                              search-ring))
@@ -919,6 +920,7 @@
                    isearch-message
                    (mapconcat 'isearch-text-char-description
                               isearch-string ""))
+                (isearch-ring-adjust1 nil))
            ;; This used to set the last search string,
            ;; but I think it is not right to do that here.
            ;; Only the string actually used should be saved.
@@ -989,6 +991,7 @@
       ;; C-s in forward or C-r in reverse.
       (if (equal isearch-string "")
          ;; If search string is empty, use last one.
+         (progn
          (setq isearch-string
                (or (if isearch-regexp
                        (car regexp-search-ring)
@@ -998,6 +1001,7 @@
                (mapconcat 'isearch-text-char-description
                           isearch-string "")
                isearch-case-fold-search isearch-last-case-fold-search)
+            (isearch-ring-adjust1 nil))
        ;; If already have what to search for, repeat it.
        (or isearch-success
            (progn
@@ -1650,11 +1654,10 @@
        ()
       (set yank-pointer-name
           (setq yank-pointer
-                (mod (+ (or yank-pointer 0)
+                (mod (+ (or yank-pointer (if advance 0 -1))
                         (if advance -1 1))
                      length)))
       (setq isearch-string (nth yank-pointer ring)
@@ -1693,13 +1695,11 @@
        ()
       (set yank-pointer-name
           (setq yank-pointer
-                (mod (- (or yank-pointer 0) n)
+                (mod (- (or yank-pointer (if (> n 0) 0 -1)) n)
                      length)))

       (delete-field)
       (insert (nth yank-pointer ring))

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

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