I'm trying to build a complicated macro to add a footnote to text selected in a document. There are two values that I need to maintain while the macro runs, so that those values can be inserted into the proper places within the links that the macro creates. The values are CURRENT_FN_NUMBER, a unique id I create with the shell date command; and CURRENT_FN_TITLE, which is the value of $TM_SELECTED_TEXT when the macro launches.
I'd like to us those values to insert code into the document, e.g.
At the beginning of the current paragraph:
Replace selected text with: #fn{$CURRENT_FN_NUMBER} $CURRENT_FN_TITLE
At bottom of document, just before "<!--<next footnote -->": #{CURRENT_FN_NUMBER} $CURRENT_FN_TITLE
There's more to it than that, but you get the idea. The macro does a lot of jumping around within the document, setting and removing bookmarks as it goes.
I've set CURRENT_FN_NUMBER and CURRENT_FN_TITLE as project environmental variables, but I can't figure out how to set values for those variables when the macro executes.
I'm (obviously) new at this game; I'd appreciate help.
Thanks.
Richard
On 19 Nov 2007, at 20:29, Richard Blumberg wrote:
I'm trying to build a complicated macro to add a footnote to text selected in a document. There are two values that I need to maintain while the macro runs, so that those values can be inserted into the proper places within the links that the macro creates. The values are CURRENT_FN_NUMBER, a unique id I create with the shell date command; and CURRENT_FN_TITLE, which is the value of $TM_SELECTED_TEXT when the macro launches.
I'd like to us those values to insert code into the document, e.g.
At the beginning of the current paragraph:
Replace selected text with: #fn{$CURRENT_FN_NUMBER} $CURRENT_FN_TITLE
At bottom of document, just before "<!--<next footnote -->": #{CURRENT_FN_NUMBER} $CURRENT_FN_TITLE
There's more to it than that, but you get the idea. The macro does a lot of jumping around within the document, setting and removing bookmarks as it goes.
I've set CURRENT_FN_NUMBER and CURRENT_FN_TITLE as project environmental variables, but I can't figure out how to set values for those variables when the macro executes.
Hmm, I don't see way to do this via macros. Did you think about to write a (shell/perl/ruby/etc) command for that problem? If there are reasons to use macros, well I believe TMTOOLS could do that. With TMTOOLS you can execute dynamic generated macros using a bash shell. But as I mentioned in an earlier mail, TMTOOLS should ONLY be used for 'private scripting'.
Cheers, --Hans
Thanks, Hans.
I'd pretty much concluded that what I was trying to do was impossible, the way I was trying to do it.
What I wound up doing was creating three snippets that generated the code for the various links and anchors, along with a command that placed a unique id on the clipboard: "echo -n `date -n '+%H%M%S'` | pbcopy". The snippets inserted a placeholder "%0" at the point where I wanted the id.
Then it was pretty simple to string the snippets together in a macro, at the end of which a Find/Replace operation, using the clipboard for the replace string, inserted the text I needed at the proper points. It works great. TextMate is wonderful!
Thanks again.
Richard
Hans-Jörg Bibiko wrote:
On 19 Nov 2007, at 20:29, Richard Blumberg wrote:
<snip problem >
Hmm, I don't see way to do this via macros. Did you think about to write a (shell/perl/ruby/etc) command for that problem? If there are reasons to use macros, well I believe TMTOOLS could do that. With TMTOOLS you can execute dynamic generated macros using a bash shell. But as I mentioned in an earlier mail, TMTOOLS should ONLY be used for 'private scripting'.
Cheers, --Hans
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate