"This is a script to upload a edit command to $command_utils "It takes the form LIST = $command_utils:edit(string/list) "Supports many features of $generic editor and can be modified by adding "new edit_* verb modules, follow the examples. " "Notes: Change the ownership of the object to $hacker as a wiz and @chown the "edit and edit_enter verbs to a wizard. "The edit verb must be called by a wiz verb for it to work. I added a $command_utils:edit verb that calls the edit verb on this object and that does the trick. " "Comments can be directed to me (Tarod) on LambdaMOO. " @create $root_class named editor object:editor,editor object @prop editor."abort_msg" "-=Aborted=-" rc @prop editor."save_strings" {"save", "done", "end"} rc @prop editor."help_msg" {"Help:",""} rc @verb editor:"edit" this none this rx #2 @program editor:edit c = callers(); dude = c[length(c)][5]; save_cmds = this.save_strings; if (!save_cmds) dude:notify("Error: this.save_strings is not defined."); return; elseif (typeof(save_cmds) != LIST) dude:notify("Invalid value in this.save_strings."); return; elseif ("" in save_cmds) dude:notify("Error: Empty string in this.save_strings."); return; else dude:notify(tostr("To save type: ", $string_utils:english_list(save_cmds, "", " or "))); dude:notify("To abort type: abort or kill"); dude:notify(""); dude:notify("For help type: H, Help, or ?"); dude:notify("----------------------------"); endif if (!args) text = {}; else text = args[1]; endif if (typeof(text) == STR) text = {text}; endif insert = (length(text) + 1); while (!((line = read()) in {@save_cmds, "abort", "kill"})) if (line) cmd = ("edit_" + line[1]); i = 2; while (i <= length(line)) if (index($string_utils.alphabet, line[i])) cmd = (cmd + line[i]); else i = length(line); endif i = (i + 1); endwhile if ($object_utils:has_verb(this, cmd)) results = this:(cmd)(text, line, insert); text = results[1]; insert = results[2]; else dude:notify("Syntax error."); endif endif endwhile if (line in {"abort", "kill"}) dude:notify(this.abort_msg); kill_task(task_id()); elseif (line in save_cmds) return text; endif . @verb editor:"list_text" this none this @program editor:list_text text = args[1]; insert = args[2]; if (length(args) == 3) range = this:parse_range(length(text), args[3]); low = range[1]; high = range[2]; else low = (((insert - 7) > 1) ? insert - 7 | 1); high = (((insert + 7) > length(text)) ? length(text) | (insert + 7)); endif lh = length(tostr(high)); indent = " "; index = 1; for index in [low..high] indent = " "[1..(lh - length(tostr(index))) + 1]; player:tell(indent, index, ":", (index == insert) ? "* " | " ", text[index]); endfor if ((high + 1) == insert) player:tell("-------"[1..length(tostr(index) + indent)], "-*-"); else player:tell("----"); endif . @verb editor:"parse_range" this none this @program editor:parse_range lines = args[1]; string = args[2]; string = $string_utils:strip_chars(string, $string_utils.alphabet); range = $string_utils:explode(string, "-"); if (length(range) == 2) low = tonum(range[1]); high = tonum(range[2]); else low = tonum(range[1]); high = low; endif if (!low) low = 1; endif if (!high) high = lines; endif if (low > lines) low = lines; endif if (high > lines) high = lines; endif if (low > high) temp = low; low = high; high = temp; endif return {low, high}; . @verb editor:"edit_d*elete" this none this @program editor:edit_delete "delete [range of lines/line] - eg, d 2-45 deletes lines 2 through 45."; text = args[1]; line = args[2]; if (!text) return {{}, 0}; endif range = this:parse_range(length(text), line); low = range[1]; high = range[2]; insert = low; for index in [low..high] text = listdelete(text, low); endfor this:list_text(text, insert); return {text, insert}; . @verb editor:"edit_i*nsert edit_." this none this @program editor:edit_insert "insert/. [line] - sets the pointer where you want to insert text."; text = args[1]; line = args[2]; insert = args[3]; lines = length(text); line = $string_utils:strip_chars(line, $string_utils.alphabet + "."); low = tonum(line); low = (low ? low | 1); insert = (((lines + 1) <= low) ? lines + 1 | low); this:list_text(text, insert, tostr(insert - 1, "-", insert + 1)); return {text, insert}; . @verb editor:"edit_e*nter" this none this rxd #2 @program editor:edit_enter "enter - allows you to add text at the insert mark."; text = args[1]; line = args[2]; insert = args[3]; player:notify("Enter lines of text, press return on a new line to end."); while (input = read()) text = listinsert(text, input, insert); insert = (insert + 1); endwhile this:list_text(text, insert); return {text, insert}; . @verb editor:"edit_m*ove" this none this @program editor:edit_move "move [range of lines/line] to line. Self - explanatory."; text = args[1]; line = args[2]; insert = args[3]; if (!(parse = $string_utils:match_string(line, "* * to *"))) return {text, insert}; endif parse = listdelete(parse, 1); range = this:parse_range(length(text), parse[1]); low = range[1]; high = range[2]; if ((to = tonum(parse[2])) > (length(text) + 1)) return {text, insert}; elseif (!to) return {text, insert}; elseif ((to >= low) && (to <= high)) return {text, insert}; endif buff = {}; offset = (to > high); for i in [low..high] buff = {@buff, text[low]}; text = listdelete(text, low); to = (to - offset); endfor insert = to; for all in (buff) text = listinsert(text, all, insert); insert = (insert + 1); endfor this:list_text(text, insert); return {text, insert}; . @verb editor:"edit_c*opy" this none this @program editor:edit_copy "copy [range of lines/line] to line. Self explanatory."; text = args[1]; line = args[2]; insert = args[3]; if (!(parse = $string_utils:match_string(line, "* * to *"))) return {text, insert}; endif parse = listdelete(parse, 1); range = this:parse_range(length(text), parse[1]); low = range[1]; high = range[2]; if ((to = tonum(parse[2])) > (length(text) + 1)) return {text, insert}; elseif (!to) return {text, insert}; elseif ((to >= low) && (to <= high)) return {text, insert}; endif buff = {}; for i in [low..high] buff = {@buff, text[i]}; endfor insert = to; for all in (buff) text = listinsert(text, all, insert); insert = (insert + 1); endfor this:list_text(text, insert); return {text, insert}; . @verb editor:"edit_h*elp edit_?" this none this @program editor:edit_help "help/h/? - Displays this help text."; help_text = this:description(); if (typeof(help_text) == STR) help_text = {help_text}; endif for i in [0..length(verbs(this)) - 1] verbnum = tostr(i); verb = verb_info(this, verbnum)[3]; if ($string_utils:match_string(verb, "edit_*")) line = verb_code(this, verbnum)[1]; if (line[1] == "\"") help_text = {@help_text, line[2..length(line) - 2]}; endif endif endfor if ((this.save_strings && (typeof(this.save_strings) == LIST)) && (!("" in this.save_strings))) help_text = {@help_text, $string_utils:english_list(this.save_strings, "", " or ") + " - saves the text."}; endif help_text = {@help_text, ""}; player:tell_lines(help_text); return {args[1], args[3]}; . @verb editor:"edit_j*oin" this none this @program editor:edit_join "join [range of lines] - makes one line out of several."; text = args[1]; line = args[2]; insert = args[3]; parse = $string_utils:strip_chars(line, $string_utils.alphabet); range = this:parse_range(length(text), parse); low = range[1]; high = range[2]; if (low == high) return {text, insert}; endif for i in [low + 1..high] text[low] = ((text[low] + " ") + text[low + 1]); text = listdelete(text, low + 1); if (insert > low) insert = (insert - 1); endif endfor player:tell(low, ": ", text[low]); player:tell("----"); return {text, insert}; . @verb editor:"edit_l*ist" this none this @program editor:edit_list "list [range of lines (optional)] - lists lines of text in range."; text = args[1]; line = args[2]; insert = args[3]; line = $string_utils:strip_chars(line, $string_utils.alphabet + " "); if (line) this:list_text(text, insert, line); else this:list_text(text, insert); endif return {text, insert}; . @verb editor:"edit_s*ubstitute" this none this @program editor:edit_substitute "substitute - substitute text in lines. Usage: s/old text/new text/[range of lines/line]"; text = args[1]; line = args[2]; insert = args[3]; line = $string_utils:trimr(line); i = 1; sepchar = "/"; while ((i = (i + 1)) <= length(line)) if (!index($string_utils.alphabet, line[i])) sepchar = line[i]; i = length(line); endif endwhile sublist = $string_utils:explode(line, sepchar); if (length(sublist) >= 4) range = this:parse_range(length(text), sublist[4]); low = range[1]; high = range[2]; else low = length(text); high = low; endif for index in [low..high] if (line = $string_utils:match_string(text[index], ("~" + sublist[2]) + "~", "~")) text[index] = ((line[1] + sublist[3]) + line[2]); player:tell(index, ": ", text[index]); endif endfor player:tell("----"); return {text, insert}; . @prop #0.editor_object editor @verb $command_utils:edit this none this rxd #2 @program $command_utils:edit return $editor_object:edit(@args); .