When writing Markdown, I like to use reference-style links:
[link text][id] . . <rest of text> . . [id]: http://www.site.com
I've written a snippet that does some of what I want:
[${1:description}][${2:id}]$0 [${2:id}]: ${3:href}
but it puts the reference on the line below the link rather than at the bottom of the file. Although I haven't done it, I suspect that writing a command that takes the link label line and puts it at the bottom of the file wouldn't be too difficult. But before I give it a try, I'd like to know if it's possible to combine the snippet and the command into a single instruction that allows me to enter the 3 pieces of information, puts the link label at the bottom of the file, and leaves the caret back at the [id].
-- Dr. Drang
On Feb 21, 2006, at 1:45 PM, Dr. Drang wrote:
I've written a snippet that does some of what I want:
[${1:description}][${2:id}]$0 [${2:id}]: ${3:href}
but it puts the reference on the line below the link rather than at the bottom of the file. Although I haven't done it, I suspect that writing a command that takes the link label line and puts it at the bottom of the file wouldn't be too difficult. But before I give it a try, I'd like to know if it's possible to combine the snippet and the command into a single instruction that allows me to enter the 3 pieces of information, puts the link label at the bottom of the file, and leaves the caret back at the [id].
You could do the following. Write a macro that does the following:
1) selects everything from where you are to the end of file 2) Calls a command that does the following: 2a) Input is current selection 2b) Output is as snippet 2c) The command prepends to the selected text the top line, and appends to it the bottom line, and then just spits it out.
You could do this with ruby for instance: #!/usr/bin/env ruby print "[${1:description}][${2:id}]$0" + STDIN.read + "\n[${2:id}]: ${3:href}"
I'm sure there is an easier way through the "filter through command..." menu item, and a bit of shell magic.
-- Dr. Drang
Haris
On Feb 21, 2006, at 3:38 PM, Charilaos Skiadas wrote:
You could do this with ruby for instance: #!/usr/bin/env ruby print "[${1:description}][${2:id}]$0" + STDIN.read + "\n[${2:id}]: $ {3:href}"
oops, spoke too soon. You'll want to escape all $ in STDIN.read, so: print "[${1:description}][${2:id}]$0" + STDIN.read.gsub('$','\$') + "\n[${2:id}]: ${3:href}"
Haris
On Feb 21, 2006, at 3:47 PM, Charilaos Skiadas wrote:
On Feb 21, 2006, at 3:38 PM, Charilaos Skiadas wrote:
You could do this with ruby for instance: #!/usr/bin/env ruby print "[${1:description}][${2:id}]$0" + STDIN.read + "\n[${2:id}]: ${3:href}"
oops, spoke too soon. You'll want to escape all $ in STDIN.read, so: print "[${1:description}][${2:id}]$0" + STDIN.read.gsub('$','\$')
- "\n[${2:id}]: ${3:href}"
I'll give it a try tonight. Thanks.
-- Dr. Drang
On 21/2/2006, at 23:47, Dr. Drang wrote:
You could do this with ruby for instance: #!/usr/bin/env ruby print "[${1:description}][${2:id}]$0" + STDIN.read + "\n [${2:id}]: ${3:href}"
oops, spoke too soon. You'll want to escape all $ in STDIN.read, so: print "[${1:description}][${2:id}]$0" + STDIN.read.gsub('$','\$')
- "\n[${2:id}]: ${3:href}"
I'll give it a try tonight. Thanks.
Also remember to escape ` and . So that’d be:
STDIN.read.gsub(/[$`\]/, '\\\1')
Instead of a macro, it is also possible to set the commands input to entire document and then use TM_LINE_NUMBER and TM_LINE_INDEX as the carets location.
On Feb 21, 2006, at 4:56 PM, Allan Odgaard wrote:
Instead of a macro, it is also possible to set the commands input to entire document and then use TM_LINE_NUMBER and TM_LINE_INDEX as the carets location.
But you'd need the output method to be "Insert as snippet", to get the placeholders to hold. How would that work if the rest of the document is not selected?
Haris
On 22/2/2006, at 0:31, Charilaos Skiadas wrote:
Instead of a macro, it is also possible to set the commands input to entire document and then use TM_LINE_NUMBER and TM_LINE_INDEX as the carets location.
But you'd need the output method to be "Insert as snippet", to get the placeholders to hold. How would that work if the rest of the document is not selected?
Ah true, I forgot that output as snippet won’t replace input.
On that note, I think I am slowly homing in on how to redo the output options.
I want to keep it simple but at the same time offer more choices of what to replace, and of course make it more explicit exactly what is replaced. E.g. currently an input choice of “[ Selection ] or [ Word ]” with output set to “[ Replace Selection ]” doesn’t explicitly say that the current word will be replaced, when there is no selection.
So I will change the output menu to fewer choices:
Output: [ Discard ] [ Text ] which is [ pop-up ] [ Snippet ] which is [ pop-up ] [ HTML ] [ Tool Tip ] [ New Document ]
And then the pop-up showing for the Text and Snippet output options have the folowing options:
which is [ Replacing Input ] [ Replacing Selection ] [ Replacing Document ] [ Inserted After Caret ]
As for the number of options and combinations, I think I am satisfied. But I am not too happy about the phrasing of things. Especially the “which is” label precedding the conditionally showing extra options pop-up.
The HTML output option might also be ambigious w/o the mention of “new window” (though that alone doesn’t say that it’s actually a web- kit window).
And “Inserted After Caret” is also not entirely clear e.g. when input is Selection, as there practically is no caret from the users POV in that situation. But “Inserted After Input” is also bad incase input is set to None.
On Feb 22, 2006, at 4:18 AM, Allan Odgaard wrote:
Output: [ Discard ] [ Text ] which is [ pop-up ] [ Snippet ] which is [ pop-up ] [ HTML ] [ Tool Tip ] [ New Document ]
This menu mixes two different concepts, "format" and location. One possibility would be to separate them:
Output: [ Discard ] [ Text ] Placement: [ pop-up ] [ Snippet ] Placement: [ pop-up ] [ HTML ] In Preview Window
Placement: [ Replace Input ] [ Replace Selection ] [ Replace Document ] [ Insert After Selection ] [ New Text Window ] [ Tool Tip ] if Text
Chris
On 22/2/2006, at 17:28, Chris Thomas wrote:
This menu mixes two different concepts, "format" and location [...]
I love this observation, as it begs the question: why can’t tool tips show HTML (i.e. formatted) text, and why can’t new documents hold snippets? :)
Thanks for the input, to Dom and Ben as well.
Output: ( Discard |v) [ New Document ] [ Text ] [ Snippet ] [ HTML ] [ Tool Tip ]
[X] Replace Selection
simpler, ain't it? (of course, if "input" was "document", the label on the checkbox would be "Replace Document").
by the way, al: my ascii art rendering of a combo box pwnz yours.
Domenico
sorry for dupe posting :(
this would not allow for commands that take the whole document as input and the current selection as output, and autocompletion thingies wouldn't work _that_ good, so considering this I'm on +1 for allan's proposal. by the way, I'd like an option to show the output as a popup menu (or something like that): this would perfectly suit autocompletion. think about it, al.
Domenico
On 23/2/2006, at 3:09, Domenico Carbotta wrote:
[...] by the way, I'd like an option to show the output as a popup menu (or something like that)
Snippets will get that ability in the ${1|future|present|past}.
Allan Odgaard
I'd like an option to show the choices as a popup menu
Snippets will get that ability in the ${1|future|present|past}.
That will be fantastic: it is one of the major speed-advantages in writing html in Dreamweaver.
The other thing that would be a nice counterpart to this is to have regex triggers which fire a snipped based on text matching around the insertion point.
That way, popup lists of options could appear in front of you as you type in an html object, on the basis of detecting the preceding context.
Move the insertion point to after "<a " and href and # appear in a pop-up menu
Tim
"Having your book turned into a movie is like seeing your ox turned into bouillon cubes."
--John Le Carré
Hello,
Because of this thread I've been able to do something similar for inserting migrations into self.down in a Rails project. It's documented in this post -> http://sami.samhuri.net/articles/ 2006/02/21/textmate-insert-text-into-self-down . Many thanks! TextMate is awesome.
Thanks to the helpful comments, I was able to put together a command and macro combination that does just what I wanted. It's described in some detail at
http://www.leancrew.com/all-this/2006/02/textmate_and_links_again.html
-- Dr. Drang
On 28 Feb 2006, at 06:47, Dr. Drang wrote:
Thanks to the helpful comments, I was able to put together a command and macro combination that does just what I wanted. It's described in some detail at
http://www.leancrew.com/all-this/2006/02/textmate_and_links_again.html
Very good description on your blog!
Following your questions on the list and the answers to it, I did the same yesterday, but with Ruby.
The only difference is that it increments the last id number and insert it instead of "id". That may interest you.
When recording the macro, I added "ctrl + L" at the end, so it centers on the caret, I which I could do that automatically after I made a new link, I don't think it's possible though...
#!/usr/bin/env ruby
str = STDIN.read n = str.scan( %r{.*[(\d+)]: }m ).to_s.to_i + 1 print "[${1:description}][${2:#{n}}]$0" + str.gsub(/[$`\]/, '\\ \1') + "[${2:#{n}}]: ${3:http://%7D%5Cn"
On Feb 28, 2006, at 8:54 AM, Fred B. wrote:
Following your questions on the list and the answers to it, I did the same yesterday, but with Ruby.
The only difference is that it increments the last id number and insert it instead of "id". That may interest you.
Clever! And if I'm reading your code correctly, you're updating from the last number but still allowing the user to override, which is nice.
#!/usr/bin/env ruby
str = STDIN.read n = str.scan( %r{.*[(\d+)]: }m ).to_s.to_i + 1 print "[${1:description}][${2:#{n}}]$0" + str.gsub(/[$`\]/, '\\ \1') + "[${2:#{n}}]: ${3:http://%7D%5Cn"
-- Dr. Drang
On 28 Feb 2006, at 17:42, Dr. Drang wrote:
Clever! And if I'm reading your code correctly, you're updating from the last number but still allowing the user to override, which is nice.
Yes, because I sometimes use something else than numbers like e.g. [mail]. And if it's the first numerical reference, it proposes "1".
BTW, the second reference I make to #{n} was not necessary, I removed it.
#!/usr/bin/env ruby
str = STDIN.read n = str.scan( %r{.*[(\d+)]: }m ).to_s.to_i + 1 print "[${1:description}][${2:#{n}}]$0" + str.gsub(/[$`\]/, '\\ \1') + "[$2]: ${3:http://%7D%5Cn"
-- FredB
This is getting awfully close to a general footnoting tool. If you remove the link formatting for description, you are pretty much there. That would be a useful (different) add-on. As it is, I like this one for its intended purpose. I'm using the ruby version, mostly because I did something dumb in the original install and tried ruby to see if that worked. It did, so I left it alone -- using ruby.
On 2/28/06, Fred B. fredb7@starflam.com wrote:
On 28 Feb 2006, at 17:42, Dr. Drang wrote:
Clever! And if I'm reading your code correctly, you're updating from the last number but still allowing the user to override, which is nice.
Yes, because I sometimes use something else than numbers like e.g. [mail]. And if it's the first numerical reference, it proposes "1".
BTW, the second reference I make to #{n} was not necessary, I removed it.
#!/usr/bin/env ruby
str = STDIN.read n = str.scan( %r{.*[(\d+)]: }m ).to_s.to_i + 1 print "[${1:description}][${2:#{n}}]$0" + str.gsub(/[$`\]/, '\\\1') + "[$2]: ${3:http://%7D%5Cn"
-- FredB
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
On 2/28/06, Fred B. fredb7@starflam.com wrote:
Following your questions on the list and the answers to it, I did the same yesterday, but with Ruby.
The only difference is that it increments the last id number and insert it instead of "id". That may interest you.
As I mentioned in a previous message, it did interest me, and I have now implemented Fred B's clever reference incrementing in my (Perl) command. It works the same as Mr. B's except that it finds the highest-numbered reference and increments that, rather than assuming that the last reference has the highest number. For organized people, there won't be any difference; for inveterate rewriters and rearrangers like me, it prevents some duplicate numbering.
I've given a full description on my blog: http://www.leancrew.com/all-this/2006/03/new_and_improved_textmate_and.html
-- Dr. Drang