home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
jed098-4.zip
/
JED
/
LIB
/
MACRO.SL
< prev
next >
Wrap
Text File
|
1997-02-01
|
2KB
|
116 lines
%!% Prototype: macro_save_macro ()
define macro_save_macro ()
{
variable str = get_last_macro ();
variable file;
variable macro_name;
file = read_file_from_mini ("Macro filename:");
!if (strlen (file)) return;
macro_name = read_mini ("Name of macro:", Null_String, Null_String);
!if (strlen (macro_name)) return;
str = Sprintf ("%%%%%%MACRO NAME: %s\n@%s\n\n", macro_name, str, 2);
if (-1 == append_string_to_file (str, file))
{
error ("Error appending macro to file");
}
}
define macro_to_function ()
{
variable macro = get_last_macro ();
variable i, imax, ch, num;
variable last_was_insert, f, ftype;
pop2buf ("*macro*");
eob ();
newline ();
insert ("\ndefine macro_");
push_spot ();
insert ("\n{\n");
imax = strlen (macro);
num = 0;
i = 0;
% Push macro characters on stack
while (i < imax)
{
ch = macro[i];
if (ch == '\\')
{
i++;
ch = macro[i];
}
else if (ch == '^')
{
i++;
ch = macro[i];
ch -= '@';
}
ch; % push it on stack
num++;
i++;
}
while (num)
{
num--;
ungetkey (());
}
while (input_pending (0))
{
(ftype, f) = get_key_function ();
if (0 == strcmp (f, "self_insert_cmd"))
{
!if (last_was_insert)
{
insert (" insert (\"\"); % insert text here\n");
last_was_insert = 1;
}
continue;
}
if (ftype)
{
insert (Sprintf (" call (\"%s\");\n", f, 1));
}
else insert (Sprintf (" %s ();\n", f, 1));
last_was_insert = 0;
}
insert ("}\n");
pop_spot ();
}
define macro_assign_macro_to_key ()
{
variable key = Null_String;
variable ch = 0;
flush ("Press key to assign macro to:");
do
{
ch = getkey ();
if (ch == 0) ch = "^@"; else ch = char (ch);
key = strcat (key, ch);
}
while (input_pending (5));
local_setkey (strcat ("@", get_last_macro ()), key);
message (strcat ("Macro set to ", expand_keystring (key)));
}