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

Stephan Hugel urschrei at gmail.com
Mon Jul 26 23:05:18 UTC 2010


On 26 July 2010 22:59, Dr. Drang <drdrang at gmail.com> wrote:
> Let me make two more changes to that script. The footnote snippet
> clearly shouldn't have the beginning of a URL as the default text, and
> there has to be a blank line after the footnote.
>
>
> #!/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:Footnote}' . "\n\n";
>
> MultiMarkdown seems to have no trouble with mixing footnotes and
> reference links down at the bottom of the file, but it sure does make
> a mess.
I had actually successfully adapted the text insertion, but was doing
something stupid with the regex. I don't use the reference link
functionality often, so it's not too bad in terms of the mess. I'm
finding that there's a blank line required between each footnote for
some reason, but that's not a problem for me, and I've added a
. "\n" . after the $text var, and it's behaving fine. Thanks again for the help.
>
> --
> Dr. Drang
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
>



-- 

steph



More information about the textmate mailing list