MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: $verb_editor:"comment uncom*ment"



On Thu, 1 Aug 1996 slayer@kaiwan.com wrote:

> At 09:49 AM 8/1/96 PDT, Colin McCormick wrote:
> 
> this looks good, but does it escape/unescape characters such as " and \? it
> might not compile otherwise...
> oh yeah and checking verb[1]=="c" would be better than match(verb[1], "c") I
> think...

Good points, both.  Here's take 2, and I'm sure any remaining bugs can be
smoothed out by those interested in using it.  This version _will_ replace
special characters with escaped versions (you have to replace \ before ",
this was tripping me up for a while) and return them to original upon
uncommenting; it will also not uncomment a line unless it is in fact a
comment. 

------------------$verb_editor:"comment uncom*ment"----------

@verb $verb_editor:"comment uncom*ment" any any any
@program $verb_editor:comment
"$verb_editor:comment(uncom*ment) <range>";
"(Un)comment the lines in <range>.";
if (!(who = this:loaded(player)))
  player:tell(this:nothing_loaded_msg());
elseif (typeof(range = this:parse_range(who, {"_", "1"}, @args)) != LIST)
  player:tell(range);
elseif (range[3])
  player:tell("Junk at end of cmd:  ", range[3]);
else
  v_name = verb[1] == "c" ? "comment" | "uncomment";
  for i in [from = range[1]..to = range[2]]
    line = this.texts[who][i];
    if (v_name == "comment")
      line = strsub(line, "\\", "\\\\");
      line = strsub(line, "\"", "\\\"");
      this.texts[who][i] = tostr("\"", line, "\";");
    elseif (line[1] == "\"" && line[$ - 1..$] == "\";")
      line = strsub(line, "\\\\", "\\");
      line = strsub(line, "\\\"", "\"");
      this.texts[who][i] = line[2..$ - 2];
    endif
  endfor
  player:tell_lines(this.texts[who][from..to]);
  player:tell("---Line", to > from ? "s" | "", " ", v_name, "ed.  Insertion point is before line ", to + 1, ".");
  if (!this.changes[who])
    this.changes[who] = 1;
    this.times[who] = time();
  endif
  this.inserting[who] = to + 1;
endif
.
"Finished.
-----------------------


Colin



References:

Home | Subject Index | Thread Index