home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hot Shareware 35
/
hot35.iso
/
ficheros
/
9TXT
/
ZE32V270.ZIP
/
WORDCOMP.ZM_
/
WORDCOMP.ZM
Wrap
Text File
|
1997-10-04
|
7KB
|
269 lines
/*************************************************************************
Name: WordComplete
Description: This macro provides a word completion search feature. To
use this macro either run it directly or install it to the
Macros menu using the Options Macros menu item. To use the
macro just run it within or at the end of the current word
that is to be completed. The following navigation keys are
also supported:
ESC - cancel the completion
Enter - to accept the completed word
ArrowUp - search for previous occurrence
ArrowDown - search for next occurrence
NOTE: Note that this macro does a case insensitive search.
Author: Brander, Bertel K.
Contact: bertel@post4.tele.dk
**************************************************************************/
int WordComplete()
{
int a;
int b;
int search_x;
int search_y;
int end;
char ch;
string org_txt;
string new_txt;
int sResult = is_document();
// make sure it is a document window
if (is_document() == 0)
{
message("This macro only works for document files!");
beep();
return;
}
key_left = 37;
key_up = 38;
key_right = 39;
key_down = 40;
key_escape = 27;
key_backspace = 8;
key_enter = 13;
ch = 0;
end = 0;
found = 0;
MoveLineLeft();
org_txt = "$W";
if(strlen(org_txt) == 0)
{
message("No word found to complete!");
beep();
}
else
{
MarkWordCurrent();
MarkDelete();
cursor_save(); // save the start position of the word to be completed
search_save(); // save search engine settings
search_update(0); // disable the search screen updates
SearchCaseReset(); // no case sensitive search
SearchWordReset(); // no whole word search
SearchRegexpReset(); // no regex search
search_x = 0; // start at the start of document
search_y = 0;
set_find_text(org_txt);
set_line_pos(search_y);
set_column_pos(search_x);
while(found == 0)
{
found = SearchNext();
if(found == 1)
{ // A match is found
new_txt = "$W";
MoveLineRight();
if (stricmp(org_txt, new_txt) == 0)
{
// false alarm
found = 0;
}
else
{
get_column_pos(search_x);
get_line_pos(search_y);
cursor_restore();
put_string(new_txt);
}
}
else
{
message("No match found.");
cursor_restore();
put_string(org_txt);
end = -1;
found = 1;
}
}
while(end == 0)
{
// gets ascii keys and extended keys
ch = getch(sExtended);
if(ch != -1)
{ // Is a key hit
if(ch == key_enter)
{ // We are done
end = 1;
}
else if(ch == key_escape)
{ // Put in the old word
cursor_restore();
MarkWordCurrent();
MarkDelete();
cursor_restore();
put_string(org_txt);
end = 1;
}
else if((ch == 0) && (sExtended == key_down))
{ // Find the next match
set_line_pos(search_y);
set_column_pos(search_x);
a = 0;
b = 0;
while(a == 0)
{
found = SearchNext();
if(found == 0)
{ // No new match is found
a = 1;
b = 1;
}
else
{
// make sure it is a new word
a = stricmp(org_txt, "$W");
if (a)
{
a = stricmp(new_txt, "$W");
}
}
}
if(b == 0)
{ // A match is found
if(found == 0)
{ // The word where we started, search again
get_column_pos(search_x);
get_line_pos(search_y);
found = SearchNext();
if(found == 0)
{
message("No match found.");
MoveWordNext();
}
}
if(found == 1)
{ // Ok, insert new word
new_txt = "$W";
get_column_pos(search_x);
get_line_pos(search_y);
cursor_restore();
// Remove the old word
MoveLineRight();
MarkWordCurrent();
MarkDelete();
put_string(new_txt);
}
}
else
{
message("No match found.");
cursor_restore();
MoveWordNext();
}
}
else if((ch == 0) && (sExtended == key_up))
{ // Find the previous match
set_line_pos(search_y);
set_column_pos(search_x);
a = 0;
b = 0;
while(a == 0)
{
found = SearchPrevious();
if(found == 0)
{ // No new match is found
a = 1;
b = 1;
}
else
{
// make sure it is a new word
a = stricmp(org_txt, "$W");
if (a)
{
a = stricmp(new_txt, "$W");
}
}
}
if(b == 0)
{ // A match is found
if(found == 0)
{ // The word where we started, search again
found = SearchPrevious();
if(found == 0)
{
message("No match found.");
MoveWordNext();
}
}
if(found == 1)
{ // Ok, insert new word
new_txt = "$W";
get_column_pos(search_x);
get_line_pos(search_y);
cursor_restore();
// Remove the old word
MoveLineRight();
MarkWordCurrent();
MarkDelete();
put_string(new_txt);
}
}
else
{
message("No match found.");
cursor_restore();
MoveWordNext();
}
}
else if (ch != 0)
{
// any other key and just beep
beep();
message("Currently running the Word Completion macro. Use the ESC key to cancel.");
}
}
}
search_restore(); // restore the search engine
search_update(1); // restore the search screen updating
if(end != -1) message("Word completion ended.");
}
}