jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

New and improved patch (was: An isearch command that wraps?)


At Sun, 14 Nov 2004 11:04:15 -0500,
Lloyd Zusman wrote:
> 
> I just hacked out this patch of isearch.sl (against the B0.99.17
> version). [ ... ]

Here is a new and improved patch for giving isearch the "wrap around"
capability.  It addresses a few "edge cases" that I overlooked in my
first version, and it gets rid of the 1-second pause that occurs when no
more matches can be found.  Instead of this pause, the prompt changes to

  Failed: isearch forward: ... etc. ...

(or "backward").  The "Failed:" prefix only appears this one time.
After wrapping, it disappears.

What do you folks think?


*** isearch.sl.orig     Sun Nov 14 11:34:32 2004
--- isearch.sl  Sun Nov 14 12:55:51 2004
***************
*** 18,19 ****
--- 18,21 ----
  
+ static variable Isearch_Last_Search_Failed = 0;
+ 
  static define get_bound_key (search_func, default)
***************
*** 41,42 ****
--- 43,45 ----
     
+    Isearch_Last_Search_Failed = 0;
     prompt = "Search:";
***************
*** 55,56 ****
--- 58,60 ----
  #else
+    Isearch_Last_Search_Failed = 0;
     if (dir < 0)
***************
*** 105,106 ****
--- 109,111 ----
     forever {
+       variable prompt_prefix;
        variable h = is_line_hidden ();
***************
*** 108,113 ****
  
        if (dir == 1)
!               prompt = "Isearch forward: ";
        else
!               prompt = "Isearch Backward: ";
        message (prompt + str);
--- 113,126 ----
  
+       if (Isearch_Last_Search_Failed)
+         {
+           prompt_prefix = "Failed: i";
+         }
+       else
+         {
+           prompt_prefix = "I";
+         }
        if (dir == 1)
!               prompt = prompt_prefix + "search forward: ";
        else
!               prompt = prompt_prefix + "search backward: ";
        message (prompt + str);
***************
*** 128,129 ****
--- 141,144 ----
           if (dir < 0) {
+               % Clear 'failed' indicator if we've changed direction.
+               Isearch_Last_Search_Failed = 0;
              dir = 1;
***************
*** 141,142 ****
--- 156,159 ----
           if (dir > 0) {   
+               % Clear 'failed' indicator if we've changed direction.
+               Isearch_Last_Search_Failed = 0;
              dir = -1;
***************
*** 162,163 ****
--- 179,183 ----
           beep ();
+            % Clear 'failed' indicator before returning.  This is
+            % probably not needed, but just in case ...
+            Isearch_Last_Search_Failed = 0;
           return;
***************
*** 199,200 ****
--- 219,241 ----
  
+       % The _next_ C-s or C-r after a previous C-s or C-r that failed
+       % will now redo the search from either the beginning or end of
+       % the buffer, depending on whether we've been going forwards or
+       % backwards.
+       if (Isearch_Last_Search_Failed)
+         {
+           Isearch_Last_Search_Failed = 0;
+           loop (m) { pop (); pop_mark (0);}
+           m = 0;
+           if (dir > 0)
+             {
+               bob();
+             }
+           else
+             {
+               eob();
+             }
+           perform_search (str, dir);
+           continue;
+         }
+ 
  % test (*), see ^R switch above
***************
*** 210,212 ****
           beep ();
!          () = input_pending (10); 
           if (() == 1) str = isearch_del (str);
--- 251,256 ----
            beep ();
!           % Now that we "wrap around", this delay doesn't feel
!           % right any more.  But it's easy to reinstate it by
!           % uncommenting the following line.
!           %() = input_pending (10); 
            if (() == 1) str = isearch_del (str);
***************
*** 215,216 ****
--- 259,263 ----
              error ("not found.");
+           % This piece of state information needs to be set as late
+           % as possible after a failed search attempt.
+           Isearch_Last_Search_Failed = 1;
        }
***************
*** 218,219 ****
--- 265,270 ----
    
+    % This needs to be reset in case we break out of the loop right
+    % after a failed isearch attempt.
+    Isearch_Last_Search_Failed = 0;
+ 
     EXECUTE_ERROR_BLOCK;


-- 
 Lloyd Zusman
 ljz@xxxxxxxxxx
 God bless you.

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]