jed-users mailing list

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

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


At Sun, 14 Nov 2004 13:05:35 -0500,
Lloyd Zusman wrote:
> 
> [ ... ]
>
> Here is a new and improved patch for giving isearch the "wrap around"
> capability.  [ ... ]

I found a few more edge cases and fixed them:

*** isearch.sl.orig     Sun Nov 14 11:34:32 2004
--- isearch.sl  Sun Nov 14 13:43:53 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;
***************
*** 149,150 ****
--- 166,169 ----
                  
+           % Clear 'failed' indicator.
+           Isearch_Last_Search_Failed = 0;
          if (m) {
***************
*** 158,159 ****
--- 177,180 ----
          { case 7 : % ^G go back to start
+            % Clear 'failed' indicator.
+            Isearch_Last_Search_Failed = 0;
           loop (m - 1) {pop (); pop_mark (0);}  % pop marks
***************
*** 162,163 ****
--- 183,187 ----
           beep ();
+            % Clear 'failed' indicator before returning.  This is
+            % probably not needed, but just in case ...
+            Isearch_Last_Search_Failed = 0;
           return;
***************
*** 193,195 ****
  
!       { str += char (c);             % any other char  
           1; push_mark(); ++m;        % push 1 and mark  
--- 217,222 ----
  
!       {
!            % Clear 'failed' indicator.
!            Isearch_Last_Search_Failed = 0;
!            str += char (c);             % any other char  
           1; push_mark(); ++m;        % push 1 and mark  
***************
*** 199,200 ****
--- 226,248 ----
  
+       % 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);
--- 258,263 ----
            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 ****
--- 266,270 ----
              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 ****
--- 272,277 ----
    
+    % 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]