Accelerating your Editor with Acme::MetaSyntactic

The Acme namespace on CPAN is a collection of supposedly useless junk that often has no other purpose than to amuse or otherwise entertain the author and Perl aficionados. This said, not all of it's useless, with one particular module Acme::MetaSyntactic being much more useful than you might first think. Acme::MetaSyntactic is a module responsible for spewing out on demand random interesting names for things. While this isn't something that you might want to do yourself, it's great for extending your editor. Six years ago at YACP::NA::Florida Damian Conway gave a talk about how he'd wired up vi to greatly speed up his Perl development. While I haven't invested as much time as Damian has, with the help of Acme::MetaSyntatic I've been able to do some rudimentary code generation techniques that save me a lot of time without much outlay. I'm currently using the TextMate editor (Your Millage May Vary, and I've no bones to pick with anyone else who uses another editor.) One of the simplest accelerators TextMate offers is "Snippets" - little bits of text inserted when you hit a key combination, or when you type a given string and hit tab. Not just limited to simple text, these snippets can can also insert the result of running shell scripts, and thus allow a quick and rudimentary way to extend the editor's functionality.

The Poor Man's Debugger

One of the most basic snippets I have is to type "acme[TAB]". This triggers the following snippet:
  print STDERR "`meta batman` `meta batman`\n";
In TextMate the backticks are one of the ways that snippets can call shell scripts, and in this case executes the "meta" command that ships with Acme::MetaSyntactic to give me a sound effect from the batman theme. Thus typing:
  acme[TAB]
  acme[TAB]
  acme[TAB]
Would give me something like:
  print STDERR "wham_eth thunk\n";
  print STDERR "powie sock\n";
  print STDERR "whack uggh\n";
This is a very quick way to get a unique human readable print statement, and is a lot less tedious then having to keep writing things like:
  print STDERR "Got to here\n";
And
  print STDERR "Also got to here\n";
And so on.

'One Off' script variables

One of the great things about Acme::MetaSyntatic names is that they're always valid Perl variable names, so they're great for creating one off scripts. I have multiple snippets that insert code that executes something and assigns it to a uniquely named variables. Let me give you a real example. I have a remote service I have to access quite often and rather than using the interactive console I prefer to instead write "one off" scripts (which I can then check into version control just incase I need them again several months hence.) Of course, with a handy set of snippets, the time it takes to write the boilerplate of code can be eliminated. For example I type:
  call[TAB]
And it spits out this:
  my $sergeant_colon = $remote->call(
    method => "ReticulateSplines",
    id     => $id,
    param  => {
      
    },
  );
And then I type:
  call[TAB]
And this time it spits out:
  my $windle_poons = $remote->call(
    method => "ReticulateSplines",
    id     => $id,
    param  => {
      
    },
  );
So each result that I get back from the remote server is assigned to it's own variable name. Again, this was just as simple as creating a snippet that looks like:
  my \$`meta discworld` = \$bc->call(
    method => "${1:ReticulateSplines}",
    id     => \$id,
    param  => { 
      $2
    },
  );
(The $1 and $2 let TextMate know where to put the cursor when I execute this snippet and when I subsequently hit tab.)

And More...

Of course Acme::MetaSyntatic isn't just limited to Perl. I have macros that do JavaScript and HTML:
  console.log("holy_taxation holy_shows_up");
  <div id="Barney_Gumble"></div>
You get the idea. I'm sure you can think of a million places where you can save yourself thirty seconds each time by some clever basic code generation.

- to blog -

blog built using the cayman-theme by Jason Long. LICENSE