MOO-cows Mailing List Archive

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

$verb_editor:"comment uncom*ment"




Hi :)

Just a potentially useful addition to LambdaCore's Verb Editor; pardon me
those who use other cores.  This code either comments or uncomments lines
in the Verb Editor, with "comment 1-5", "uncomment 16-$", etc.  (Lots
stolen directly from :delete().)

------------------------

@verb $verb_editor:"comment uncom*ment" any any any
@program $verb_editor:comment
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 = match(verb[1], "c") ? "comment" | "uncomment";
  for i in [from = range[1]..to = range[2]]
    if (v_name == "comment")
      this.texts[who][i] = tostr("\"", this.texts[who][i], "\";");
    else
      this.texts[who][i] = this.texts[who][i][2..$ - 2];
      "Remember we add \";, so it's two characters at the end of a comment.";
    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] = from;
endif
.
"Finished.
----------------------------------------

Caveat: no checking in the "uncomment" version for if a line is in fact
already a comment.  Fix, use carefully, or lose beginning and ending
characters in lines of code ... :-)

Colin


Follow-Ups:

Home | Subject Index | Thread Index