[TxMt] Re: snippet to generate unique ID, detect end of document, and move cursor

Dr. Drang drdrang at gmail.com
Mon Jul 26 21:34:26 UTC 2010


Stephan, your first regex is correct, but you need to change more than
just the regex. I just tried this:

----------

#!/usr/bin/perl
use List::Util qw(max);

$text = $ENV{'TM_SELECTED_TEXT'};

# Get the highest-numbered reference.
@nums = $text =~ /^\[\^(\d+)\]: /mg;
$n = max(@nums) + 1;

# Escape special characters.
$text =~ s/([\$\\`])/\\$1/g;

# Insert the snippet.
print '[^${1:' . $n . '}]$0'.
       $text . '[^$1]: ${2:http://}' . "\n";

-----------

and it worked for me. Note that you have to put the carets in the
snippet, or there won't be a caret to search for in the regex.

Note also that you won't have to use the bracketing command when doing
a footnote, because, unlike a normal link, footnotes supply their own
text. So your macro should just be two steps:

1. Select the text from the caret to the end of the document with
Command-Shift-Downarrow.

2. Invoke the snippet-inserting command (see above) from the little
gear menu, which pops the snippet and placeholders into the document.

I'm not sure, but mixing footnotes with reference-style links at the
bottom of the file may cause problems. Caveat emptor.

Good luck!

--
Dr. Drang



More information about the textmate mailing list