1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% async shell for jed
!if (is_defined ("Shell_Default_Shell"))
{
variable Shell_Default_Shell = getenv ("SHELL");
if (Shell_Default_Shell == NULL)
Shell_Default_Shell = "sh";
}
variable AShell_Id = -1;
define ashell_send_input ()
{
variable buf;
variable this_line, mark_line;
variable m, ch, prompt;
m = process_mark (AShell_Id);
this_line = what_line ();
push_mark ();
goto_user_mark (m);
mark_line = what_line ();
if (this_line >= mark_line)
{
pop_mark_0 ();
push_mark_eob ();
buf = bufsubstr ();
}
else
{
bskip_chars ("\t ");
push_mark ();
!if (bolp ())
{
go_left_1 ();
ch = what_char ();
}
bol ();
prompt = bufsubstr ();
pop_mark_1 ();
bol ();
if (looking_at (prompt))
{
go_right (strlen (prompt));
}
else if (ffind_char (ch))
{
go_right_1 ();
}
push_mark_eol ();
buf = bufsubstr ();
eob ();
insert (buf);
}
newline ();
move_user_mark (m);
send_process (AShell_Id, buf + "\n");
}
$1 = "AShellMap";
!if (keymap_p ($1)) make_keymap ($1);
definekey ("ashell_send_input", "^M", $1);
define ashell_signal_handler (pid, flags)
{
variable msg;
eob ();
switch (flags)
{ case 2: msg = "STOPPED";}
{ case 4: msg = "EXITED";}
{ case 8: msg = "SIGNALLED";}
{ error ("bad signal");}
vinsert ("\n\n----- Process %s ----------\n\n", msg, 1);
AShell_Id = -1;
}
define ashell_insert_output (pid, str)
{
eob ();
push_spot ();
insert (str);
pop_spot ();
bol ();
replace ("\r", Null_String);
eob ();
move_user_mark (process_mark (pid));
}
define ashell ()
{
variable buf = "*ashell*";
variable arg, nargs = 0;
if ((AShell_Id != -1) and bufferp (buf))
{
error ("Currently, only one shell process is supported.");
}
pop2buf (buf);
use_keymap ("AShellMap");
runhooks ("ashell_mode_hook");
erase_buffer ();
#iffalse
AShell_Id = open_process (Shell_Default_Shell, "-i", 1);
#else
% parse possible arguments
forever
{
arg = extract_element (Shell_Default_Shell, nargs, ' ');
if (arg == NULL)
break;
nargs++;
arg; % push on stack
}
"-i"; nargs; % push on stack
AShell_Id = open_process ();
#endif
set_process (AShell_Id, "signal", "ashell_signal_handler");
set_process (AShell_Id, "output", "ashell_insert_output");
}
|