% Editor functions. % These are used to provide a reasonable line editor, and also % provide some library functions for addition of characters, etc. % Setup some of the more useful things. Like a backspace/delete key handler, % and the Command Mode stuff. private define set_command_mode(yesno) { if(yesno) { irc_command_mode = 1; irc_set_status("Command Mode"); } else { irc_command_mode = 0; irc_set_status("Say Mode"); } } variable cmd_char = '/'; define bs_del_key() { if(irc_edit_insert_pos <= 0) return; variable BufLen = strlen(irc_buffer); if(irc_edit_insert_pos > BufLen) % shouldn't happen irc_edit_insert_pos = BufLen; !if(BufLen) return; variable buf; if(irc_edit_insert_pos >= BufLen) { irc_edit_insert_pos--; buf = chop_last(irc_buffer); irc_set_buffer(buf); } else { irc_edit_insert_pos--; buf = substr(irc_buffer, 1, irc_edit_insert_pos) + substr(irc_buffer, irc_edit_insert_pos + 2, -1); irc_set_buffer(buf); } !if(irc_edit_insert_pos) set_command_mode(cmd_char == int(irc_buffer)); } % There. Wasn't that nice? % That's overridden the default handling of BS/DEL (Nothing special) to % removing the last character of the string. Which is, at least, bearable... % The magic Hex is from the SL_KEY_* in slang.h, by the way... % It's also given us the normal '/' command mode we know and love. % You should be able to change the char, actually. % % Override the standard key function. This is much nicer... % This supports left<->right scrolling, basically. % Well, it does when it's used with the stuph below... % define std_key(ch) { if (ch >= 0x80) { if(ch >= 0x100) return; if(ch < 0x0a0) return; % ISO-LATIN-1 are 0xa0-0xff } variable buf; if(irc_edit_insert_pos >= strlen(irc_buffer)) { irc_set_buffer(irc_buffer + char(ch)); irc_edit_insert_pos = strlen(irc_buffer); } else { if(irc_edit_insert_pos <= 0) { buf = char(ch) + irc_buffer; irc_edit_insert_pos = 1; } else { buf = substr(irc_buffer, 1, irc_edit_insert_pos) + char(ch) + substr(irc_buffer, irc_edit_insert_pos + 1, -1); irc_edit_insert_pos++; } irc_set_buffer(buf); } if (irc_edit_insert_pos == 1) set_command_mode(cmd_char == int(irc_buffer)); } define do_scroll_left() { if(irc_edit_insert_pos > 0) irc_edit_insert_pos --; } define do_scroll_right() { if(irc_edit_insert_pos < strlen(irc_buffer)) irc_edit_insert_pos++; } define do_scroll_bob() { irc_edit_insert_pos = 0; } define do_scroll_eob() { irc_edit_insert_pos = strlen(irc_buffer); } define do_page_up() { irc_scroll(-8); } define do_page_down() { irc_scroll(8); } define do_scroll_up() { irc_scroll(-1); } define do_scroll_down() { irc_scroll(1); } private variable history = make_list(); private variable hist_p = NULL; private variable hist_muck = NullString; define history_save_buffer() { variable p = history.f; if (p != NULL) { p = p.p; % last if (irc_buffer == p.v) { % don't save dup's hist_p = p; return; } } () = s_putlast(history,irc_buffer); hist_p = NULL; hist_muck = NullString; } define history_up() { !if (history.ct) return; if (hist_p == NULL) { hist_muck = irc_buffer; hist_p = history.f.p; }else{ if (hist_p == history.f) return; hist_p = hist_p.p; } irc_set_buffer(hist_p.v); irc_edit_insert_pos = 0; set_command_mode(cmd_char == int(irc_buffer)); } define history_down() { !if (history.ct) return; if (hist_p == NULL) return; if (hist_p.n == history.f) { irc_set_buffer(hist_muck); hist_p = NULL; }else{ hist_p = hist_p.n; irc_set_buffer(hist_p.v); } irc_edit_insert_pos = 0; set_command_mode(cmd_char == int(irc_buffer)); } %%% see slang.h for mapping of key-codes () = irc_set_keysym(0x101, "history_up", 0); % up arrow () = irc_set_keysym(0x102, "history_down", 0); % down arrow () = irc_set_keysym(0x103, "do_scroll_left", 0); () = irc_set_keysym(0x104, "do_scroll_right", 0); () = irc_set_keysym(0x105, "do_page_up", 0); () = irc_set_keysym(0x106, "do_page_down", 0); () = irc_set_keysym(0x107, "irc_bob", 0); % PC home () = irc_set_keysym(0x108, "irc_eob", 0); % PC end () = irc_set_keysym(0x110, "bs_del_key", 0); () = irc_set_keysym(0x112, "do_scroll_up", 0); % PC insert () = irc_set_keysym(0x113, "do_scroll_down", 0); % PC delete () = irc_set_keysym(0x1, "do_scroll_bob", 0); () = irc_set_keysym(0x5, "do_scroll_eob", 0); % this next is just in case you don't have a reasonable number of % ordinary function-keys... for example, in config.sl, you might put % setup_func_keys("\e"); % to use as function-key-n define setup_func_keys(pfx) { variable i; for (i = 1; i < 10; i++) () = define_keysym(pfx + string(i), 0x200 + i); } % this was an idea for doing ISO-LATIN-1, but unfortunately % define_keysym() doesn't work the (IMHO) right way... %() = define_keysym("''",'\''); %() = define_keysym("``",'`'); %() = define_keysym("^^",'^'); %() = define_keysym("`a",0xe0); %() = define_keysym("'a",0xe1); %() = define_keysym("^a",0xe2); %() = define_keysym("`e",0xe8); %() = define_keysym("'e",0xe9); %() = define_keysym("^e",0xea); %() = define_keysym("`i",0xec); %() = define_keysym("'i",0xed); %() = define_keysym("^i",0xee); %() = define_keysym("`o",0xf2); %() = define_keysym("'o",0xf3); %() = define_keysym("^o",0xf4); %() = define_keysym("`u",0xf9); %() = define_keysym("'u",0xfa); %() = define_keysym("^u",0xfb); % used by tab-ex: define do_delete(howmany) { variable i; for(i = 0; i < howmany; i++) bs_del_key(); } % used by tab-ex: define do_insert_char(ch) { std_key(ch); } define do_insert_string(st) { variable i; for(i = 0; i < strlen(st); i++) std_key(st[i]); } define cmd_mode_switch() { !if(strlen(irc_buffer)) set_command_mode(1); std_key(cmd_char); } () = irc_set_keysym(cmd_char, "cmd_mode_switch", 0); irc_log("[STD-Edit] Loaded."); irc_update_display();