- Subject: isearch "wrap around" enhancements
- From: Lloyd Zusman <ljz@xxxxxxxxxx>
- Date: Thu, 18 Nov 2004 17:49:49 -0500
After much valuable help from Paul Boekholt <paul@xxxxxxxxxxxx> and
G� Milde <g.milde@xxxxxx>, I have a working patch for isearch that
optionally enables it to wrap around the buffer after a forward or
backward incremental search fails, much like Emacs' isearch.
To John Davis: this new behavior is optional, so would you be willing to
consider this new functionality to become part of the official isearch
capabilities for jed? Read on for details ...
If this optional capability is enabled, it is possible, _after_ a
forward isearch gives the "Failed: isearch forward: ..." message shows
up, to type ^S one more time, and thereby have the search start over
again at the top of the buffer.
The corresponding behavior also happens _after_ a backward isearch gives
the "Failed: isearch backward: ..." message prints, and ^R is typed one
more time.
Because this behavior is optional, the default isearch behavior is the
same as it is today: i.e., when a forward/backward isearch fails, no
"wrap around" takes place.
If a variable called SEARCH_WRAP is set to a value greater than 1, then
the new behavior comes into effect; if SEARCH_WRAP is not set, or if
it's set to something <= 0, isearch behaves as it does currently. If
this "wrap around" behavior is desired, I recommend putting the
following line into .jedrc or its moral equivalent:
variable SEARCH_WRAP = 1;
Per G� Milde's suggestion, this variable is named SEARCH_WRAP
instead of ISEARCH_WRAP, because my next project is to alter cuamisc.sl
in the same way, so that "wrap around" can also take place in
non-incremental searches when this same variable is appropriately set.
I'll make those cuamisc.sl changes within the next few days.
Also, I included G� Milde's recent enhancements into this patch.
These give the user the option of changing the Quit and Abort characters
from their defaults (Esc and ^G) to something else if desired.
This patch applies to the B0.99.17 version of isearch.sl. To apply it,
go into the directory where isearch.sl lives and issue this command
(assuming the patch file is named "isearch.patch")
patch -l <isearch.patch
Make sure not to forget the -l flag (that's a lower-case letter "L" for
those of you reading this in the Courier font).
So, John, what do you think about putting this enhancement into an
upcoming jed release?
Thanks again to Paul and G�.
*** isearch.sl.orig Sun Nov 14 11:34:32 2004
--- isearch.sl Thu Nov 18 17:26:03 2004
***************
*** 1,3 ****
! % Here is a new version of isearch.sl reworked by John Burnell <johnb@xxxxxxxxxxxxxxxxx>.
% This one is said to be more emacs-like.
%% isearch.sl
--- 1,11 ----
! % Here is a new version of isearch.sl
! % reworked by John Burnell <johnb@xxxxxxxxxxxxxxxxx>.
% This one is said to be more emacs-like.
+ %
+ %% with modifications and comments by Guenter Milde
+ %% <G.Milde@xxxxxxxxxxxxxxxxxxxx>
+ %
+ %% Further modifications by Lloyd Zusman
+ %% <ljz@xxxxxxxxxx>
+
%% isearch.sl
***************
*** 12,13 ****
--- 20,46 ----
+ %% Default bindings:
+ %%
+ %% ESCAPE quits the search
+ %% ^G aborts the search (returns to starting point)
+ %% ESCAPE or ENTER as first char: switch to non incremental search
+ %% with the last isearch match as default
+ %% BACKSPACE deletes last character entered and returns to previous point
+ %% ^S finds next match (and switches to forward search)
+ %% ^R finds previous match (and switches to backward search)
+ %%
+ %% You may use the following variables to change this behaviour,
+ %% either here or (better!) in your keybinding defining file (e.g. ".jedrc")
+
+ custom_variable ("Isearch_Quit_Char", '\e' );
+ custom_variable ("Isearch_Abort_Char", 7 ); % ^G
+ custom_variable ("Isearch_Forward_Char", 19 ); % ^S
+ custom_variable ("Isearch_Backward_Char", 18 ); % ^R
+
+
+ %% Cause isearch_{forward,backward} to behave in the traditional
+ %% manner by default. Otherwise, wrap around to the start/end
+ %% of the buffer and keep going after a forward/reverse search
+ %% fails.
+ custom_variable("SEARCH_WRAP", 0);
+
variable Isearch_Last_Search = Null_String;
***************
*** 18,19 ****
--- 51,54 ----
+ static variable Isearch_Last_Search_Failed = 0;
+
static define get_bound_key (search_func, default)
***************
*** 36,37 ****
--- 71,73 ----
+ %% switch to non incremental with the last isearch match as default
static define isearch_simple_search (dir)
***************
*** 41,42 ****
--- 77,79 ----
+ Isearch_Last_Search_Failed = 0;
prompt = "Search:";
***************
*** 55,56 ****
--- 92,94 ----
#else
+ Isearch_Last_Search_Failed = 0;
if (dir < 0)
***************
*** 69,71 ****
! if (dir == 1)
dir = fsearch (str);
--- 107,109 ----
! if (dir > 0)
dir = fsearch (str);
***************
*** 92,93 ****
--- 130,132 ----
variable len = 0;
+ variable sd = _stkdepth();
***************
*** 102,106 ****
m = 1;
! ERROR_BLOCK { loop (m) { pop (); pop_mark (0);}} %make sure we pop marks
forever {
variable h = is_line_hidden ();
--- 141,158 ----
m = 1;
!
! EXIT_BLOCK
! {
! _pop_n(_stkdepth() - sd);
! Isearch_Last_Search_Failed = 0;
! }
! ERROR_BLOCK
! {
! loop (m) { pop (); pop_mark (0); } %make sure we pop marks
! _pop_n(_stkdepth() - sd);
! Isearch_Last_Search_Failed = 0;
! }
forever {
+ variable prompt_prefix;
+ variable prompt_suffix;
variable h = is_line_hidden ();
***************
*** 108,113 ****
! if (dir == 1)
! prompt = "Isearch forward: ";
else
! prompt = "Isearch Backward: ";
message (prompt + str);
--- 160,178 ----
! if (Isearch_Last_Search_Failed)
! {
! prompt_prefix = "Failed: i";
! if (strlen(str) > 0)
! prompt_suffix = ": ";
! else
! prompt_suffix = "";
! }
else
! {
! prompt_prefix = "I";
! prompt_suffix = ": ";
! }
! if (dir > 0)
! prompt = prompt_prefix + "search forward" + prompt_suffix;
! else
! prompt = prompt_prefix + "search backward" + prompt_suffix;
message (prompt + str);
***************
*** 124,126 ****
switch (c)
! { case 27 and first : isearch_simple_search (dir); break;}
{ case Isearch_Forward_Char : % ^S
--- 189,193 ----
switch (c)
! { case Isearch_Quit_Char and first :
! isearch_simple_search (dir); break;
! }
{ case Isearch_Forward_Char : % ^S
***************
*** 128,129 ****
--- 195,198 ----
if (dir < 0) {
+ % Clear 'failed' indicator if we've changed direction.
+ Isearch_Last_Search_Failed = 0;
dir = 1;
***************
*** 141,142 ****
--- 210,213 ----
if (dir > 0) {
+ % Clear 'failed' indicator if we've changed direction.
+ Isearch_Last_Search_Failed = 0;
dir = -1;
***************
*** 149,150 ****
--- 220,223 ----
+ % Clear 'failed' indicator.
+ Isearch_Last_Search_Failed = 0;
if (m) {
***************
*** 157,159 ****
}
! { case 7 : % ^G go back to start
loop (m - 1) {pop (); pop_mark (0);} % pop marks
--- 230,232 ----
}
! { case Isearch_Abort_Char : % ^G go back to start
loop (m - 1) {pop (); pop_mark (0);} % pop marks
***************
*** 193,195 ****
! { str += char (c); % any other char
1; push_mark(); ++m; % push 1 and mark
--- 266,271 ----
! {
! % Clear 'failed' indicator.
! Isearch_Last_Search_Failed = 0;
! str += char (c); % any other char
1; push_mark(); ++m; % push 1 and mark
***************
*** 199,201 ****
! % test (*), see ^R switch above
if ((dir < 0) and (m > 1) and looking_at (str) and (c >= ' '))
--- 275,295 ----
! if (SEARCH_WRAP > 0)
! {
! % 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;
! if (dir > 0)
! bob();
! else
! eob();
! perform_search (str, dir);
! continue;
! }
! }
!
! % test (*), see ^R switch above
if ((dir < 0) and (m > 1) and looking_at (str) and (c >= ' '))
***************
*** 207,210 ****
{
if (c == Isearch_Forward_Char) go_left_1();
! flush (str + " not found.");
beep ();
--- 301,311 ----
{
+ variable msg;
if (c == Isearch_Forward_Char) go_left_1();
! if (strlen(str) > 0)
! msg = str + " not found.";
! else
! msg = "No search string.";
! flush (msg);
! % Only beep if we're not wrapping.
! if (SEARCH_WRAP < 1)
beep ();
***************
*** 214,216 ****
if (EXECUTING_MACRO)
! error ("not found.");
}
--- 315,320 ----
if (EXECUTING_MACRO)
! 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 ****
--- 322,327 ----
+ % 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;
***************
*** 221,223 ****
Isearch_Last_Search = str;
! if (dir == 1)
go_right (strlen (str) - len);
--- 329,331 ----
Isearch_Last_Search = str;
! if (dir > 0)
go_right (strlen (str) - len);
***************
*** 245,247 ****
}
-
-
--- 353 ----
--
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]