Hello, I'm trying to write a snippet that will create a footnote in a TM file (using markdown syntax), and I'm having some difficulties: Footnote syntax works as follows: Here's a string of text [^footnote_identifier] which continues here.
then, at the beginning of a new line: [^footnote_identifier]: text of the footnote itself
So, what the snippet needs to do (theoretically) when snippet is triggered: generate a (not too long, 5 digit alphanumeric should be fine for a single document) unique id, and insert the full [^footnote_identifier] string, then jump to the end of the document, insert [^footnote_identifier]: and a space, allow typing of the footnote text, then return to the original insertion point when tab is pressed again.
I have no idea whether any of this is possible using snippet syntax, so any pointers would be appreciated.
I'll leave the unique ID for someone else to answer. As for the jumping back and forth in the document, take a look at this:
http://www.leancrew.com/all-this/2006/03/markdown-links-in-textmate-the-fina...
I use reference-style links and put the URLs at the bottom of the document. You should be able to adapt the logic of my command/snippet/macro combination to the footnote syntax.
-- Dr. Drang
On Sun, Jul 25, 2010 at 5:20 PM, Stephan Hugel urschrei@gmail.com wrote:
Hello, I'm trying to write a snippet that will create a footnote in a TM file (using markdown syntax), and I'm having some difficulties:
[snip]
So, what the snippet needs to do (theoretically) when snippet is triggered: generate a (not too long, 5 digit alphanumeric should be fine for a single document) unique id, and insert the full [^footnote_identifier] string, then jump to the end of the document, insert [^footnote_identifier]: and a space, allow typing of the footnote text, then return to the original insertion point when tab is pressed again.
On 26 July 2010 01:13, Dr. Drang drdrang@gmail.com wrote:
I'll leave the unique ID for someone else to answer. As for the jumping back and forth in the document, take a look at this:
http://www.leancrew.com/all-this/2006/03/markdown-links-in-textmate-the-fina...
I use reference-style links and put the URLs at the bottom of the document. You should be able to adapt the logic of my command/snippet/macro combination to the footnote syntax.
That seems to be exactly what I'm looking for. I can't seem to be able to adapt your regex pattern to match [^n]: though. I've tried both @nums = $text =~ /^[^(\d+)]: /mg; and @nums = $text =~ /^[(^\d+)]: /mg; Without success. Should I also be adapting: # Escape special characters. $text =~ s/([$\`])/\$1/g;
(apologies, my regex abilities are nonexistent)
-- Dr. Drang
On Sun, Jul 25, 2010 at 5:20 PM, Stephan Hugel urschrei@gmail.com wrote:
Hello, I'm trying to write a snippet that will create a footnote in a TM file (using markdown syntax), and I'm having some difficulties:
[snip]
So, what the snippet needs to do (theoretically) when snippet is triggered: generate a (not too long, 5 digit alphanumeric should be fine for a single document) unique id, and insert the full [^footnote_identifier] string, then jump to the end of the document, insert [^footnote_identifier]: and a space, allow typing of the footnote text, then return to the original insertion point when tab is pressed again.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
had a look - very cool! it strikes me that a variation on this could possibly be used to solve my earlier problem of selecting paragraphs with a keystroke that ONLY selects to the beginning and end characters (as opposed to entire beginning and ending lines with all the spaces and 'returns') if that's not clear you can look at my earlier question that I posted a few days ago.
since MY regex skills are even *less* than nonexistent =p I'd be intensely grateful if someone like yourself took this on as a project. it seems on the face of it that it would be an easy enough conversion from your current script... just without the bracket delimiters. OR - if that's not possible - perhaps you could use your script as it is and simply have the macro delete the brackets after the block is selected?
just thinking about ways to speed up the workflow - no mouse allowed! cheers, bennett
On Jul 26, 2010, at 10:02 AM, Stephan Hugel wrote:
On 26 July 2010 01:13, Dr. Drang drdrang@gmail.com wrote:
I'll leave the unique ID for someone else to answer. As for the jumping back and forth in the document, take a look at this:
http://www.leancrew.com/all-this/2006/03/markdown-links-in-textmate-the-fina...
I use reference-style links and put the URLs at the bottom of the document. You should be able to adapt the logic of my command/snippet/macro combination to the footnote syntax.
That seems to be exactly what I'm looking for. I can't seem to be able to adapt your regex pattern to match [^n]: though. I've tried both @nums = $text =~ /^[^(\d+)]: /mg; and @nums = $text =~ /^[(^\d+)]: /mg; Without success. Should I also be adapting: # Escape special characters. $text =~ s/([$\`])/\$1/g;
(apologies, my regex abilities are nonexistent)
-- Dr. Drang
On Sun, Jul 25, 2010 at 5:20 PM, Stephan Hugel urschrei@gmail.com wrote:
Hello, I'm trying to write a snippet that will create a footnote in a TM file (using markdown syntax), and I'm having some difficulties:
[snip]
So, what the snippet needs to do (theoretically) when snippet is triggered: generate a (not too long, 5 digit alphanumeric should be fine for a single document) unique id, and insert the full [^footnote_identifier] string, then jump to the end of the document, insert [^footnote_identifier]: and a space, allow typing of the footnote text, then return to the original insertion point when tab is pressed again.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
--
steph
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 26 July 2010 18:20, plastichairdoo plastichairdoo@gmail.com wrote:
had a look - very cool! it strikes me that a variation on this could possibly be used to solve my earlier problem of selecting paragraphs with a keystroke that ONLY selects to the beginning and end characters (as opposed to entire beginning and ending lines with all the spaces and 'returns') if that's not clear you can look at my earlier question that I posted a few days ago.
since MY regex skills are even *less* than nonexistent =p I'd be intensely grateful if someone like yourself took this on as a project. it seems on the face of it that it would be an easy enough conversion from your current script... just without the bracket delimiters. OR - if that's not possible - perhaps you could use your script as it is and simply have the macro delete the brackets after the block is selected?
just thinking about ways to speed up the workflow - no mouse allowed! cheers, bennett
On Jul 26, 2010, at 10:02 AM, Stephan Hugel wrote:
On 26 July 2010 01:13, Dr. Drang drdrang@gmail.com wrote:
I'll leave the unique ID for someone else to answer. As for the jumping back and forth in the document, take a look at this:
http://www.leancrew.com/all-this/2006/03/markdown-links-in-textmate-the-fina...
I use reference-style links and put the URLs at the bottom of the document. You should be able to adapt the logic of my command/snippet/macro combination to the footnote syntax.
That seems to be exactly what I'm looking for. I can't seem to be able to adapt your regex pattern to match [^n]: though. I've tried both @nums = $text =~ /^[^(\d+)]: /mg; and @nums = $text =~ /^[(^\d+)]: /mg;
Ignore me, I was having some sort of minor neurological event. Everything's working fine now. Thanks again!
Without success. Should I also be adapting: # Escape special characters. $text =~ s/([$\`])/\$1/g;
(apologies, my regex abilities are nonexistent)
-- Dr. Drang
On Sun, Jul 25, 2010 at 5:20 PM, Stephan Hugel urschrei@gmail.com wrote:
Hello, I'm trying to write a snippet that will create a footnote in a TM file (using markdown syntax), and I'm having some difficulties:
[snip]
So, what the snippet needs to do (theoretically) when snippet is triggered: generate a (not too long, 5 digit alphanumeric should be fine for a single document) unique id, and insert the full [^footnote_identifier] string, then jump to the end of the document, insert [^footnote_identifier]: and a space, allow typing of the footnote text, then return to the original insertion point when tab is pressed again.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
--
steph
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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
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.
-- Dr. Drang
On 26 July 2010 22:59, Dr. Drang drdrang@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@lists.macromates.com http://lists.macromates.com/listinfo/textmate