From: "Carlo Hogeveen"
This is a multi-part message in MIME format.
------=_NextPart_000_004A_01BD7D41.1C024920
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi Skip and others
Version 2 of the Findws macro adressed Skip's
request for a find _again_ function, and here is
version 3 that solves a bug.
If "Great" is at the end of a line,
and "Small Britain" is on the next line,
then Findws would erroneously find "Great Britain".
The attached Findws.s solves this problem.
I'm thinking about expanding Findws, so it can
replace the standard Find(), RepeatFind() and Replace()
in the .UI file.
One benefit of this is, that it would no longer take up
extra keys and it would work transparent for the
usual Find() etc.
Another benefit would be, that the user can once again
choose his and her own options.
The user would then have to add an extra option S to
indicate that "Space matches whitespace", and could
add an extra option M to mark the found text as a block.
I would take the opportunity to let Find(), Replace() and
"Replace_by" all use the same find_history, and to let
the option box list all options
I suppose that in case of a found text that spans lines,
Replace() should add the Replace_by text to the end
of the first found line, though this might make the line
longer than the screen.
Perhaps the "S" option or something like it would be
a nice one for TSE's wishlist.
I'm thinking out loud here, because what I'm going to build
won't necessarily have to reflect just my own whishes.
Any ideas or comments?
Carlo
------=_NextPart_000_004A_01BD7D41.1C024920
Content-Type: application/octet-stream;
name="findws.s"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="findws.s"
/*
Macro. Findws.
Author. Carlo Hogeveen (hyphen@xs4all.nl)
Date-written. 12 may 1998.
Version 3.
This macro finds a sequence of words separated by whitespace.
You enter the words separated by a single space, which the macro =
matches
with whitespace.
Whitespace is any combination of spaces, horizontal_tabs and =
end_of_lines.
The words may not contain spaces and are searched using =
case-insensitive
regular expressions starting right from the cursor position.
Findws can be started from the menu with Macro Execute, or from =
another
macro or using a key definition with ExecMacro().
It can be started with or without parameters.
By searching "_again_" the previous find is repeated.
Examples:
begfile()
execmacro("findws")
execmacro("findws great britain")
execmacro("findws _again_")
*/
#define horizontal_tab 9
#define space 32
integer find_history =3D 0
string previous_findws[255] =3D ""
proc main()
string word[255] =3D ""
string searching[255] =3D query(macrocmdline)
integer found =3D false
integer found_line =3D 0
integer found_column =3D 0
integer word_line =3D 0
integer word_column =3D 0
integer token_counter =3D 0
// set(break, on)
if searching =3D=3D ""
ask("Enter words separated by spaces", searching, find_history)
else
if lower(searching) =3D=3D "_again_"
searching =3D previous_findws
endif
endif
if searching ""
previous_findws =3D searching
endif
pushposition()
repeat
token_counter =3D 0
repeat
token_counter =3D token_counter + 1
word =3D gettoken(searching, " ", token_counter)
if word ""
if token_counter =3D=3D 1
if lfind(word, "ix+")
found =3D true
found_line =3D currline()
found_column =3D currcol()
else
found =3D false
word =3D ""
endif
else
// Cursor is on previous found word: goto next =
whitespace.
while currchar() space
and currchar() horizontal_tab
and currchar() _at_eol_
nextchar()
endwhile
// Cursor is on first whitespace: goto next =
non-whitespace.
while currchar() =3D=3D space
or currchar() =3D=3D horizontal_tab
or currchar() =3D=3D _at_eol_
nextchar()
endwhile
// Check if the word under the cursor is the next search =
word.
word_line =3D currline()
word_column =3D currcol()
if lfind(word, "cix")
and currline() =3D=3D word_line
and currcol() =3D=3D word_column
// Yes, the next search word was and is under the =
cursor.
else
found =3D false
endif
endif
endif
until found =3D=3D false
or word =3D=3D ""
until word =3D=3D ""
if found
killposition()
gotoline(found_line)
gotocolumn(found_column)
else
alarm()
popposition()
message(searching, " not found.")
endif
end
proc whenloaded()
find_history =3D getfreehistory("findws:find")
end
------=_NextPart_000_004A_01BD7D41.1C024920--
---
---------------
* Origin: apana>>>>>fidonet [sawasdi.apana.org.au] (3:800/846.13)
|