Hello, I would like to create a command that in part pastes the contents of the clipboard, using TextMate 2. How would one access the contents of the clipboard in a command? I am using Ruby, but I am open to whatever works.
Thanks in advance, steven
the system command *pbpaste* does that, you can call it with *`pbpaste`*from inside ruby :)
Elia
— ☁ @elia http://twitter.com/elia (twitter) ✎ elia@schito.me (gtalk) ☎ (+39) 348/9051393 perlelia@gmail.com (FaceTime)
On Wed, Oct 3, 2012 at 1:01 AM, Steven Arnold thoth_amon@mac.com wrote:
Hello, I would like to create a command that in part pastes the contents of the clipboard, using TextMate 2. How would one access the contents of the clipboard in a command? I am using Ruby, but I am open to whatever works.
Thanks in advance, steven
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Awesome. I was trying that, but didn't realize it's an actual system command (and hence left out the backticks).
I have a followup question. It seems that macros are poorly supported in TextMate 2 so far. It also seems that much of what you might have wanted to do with a macro can be done with a command in whatever language you have installed on your system, such as Ruby, or bash, perl -- I've seen a number of examples. Nonetheless, macros were really easy to work with in TextMate 1.x, just do something and make a keybinding. Are there any plans to improve support for macros in TextMate 2, such as saving them as part of bundles, binding them to keys, things like that?
Thanks a lot for the great info. I am very excited to see the open-source TextMate 2, and I'd like to give my very sincere thanks to MacroMates for that extremely generous decision. Speaking only for myself, I wouldn't mind paying for the open-source binary. I'd like to see companies that do things like this be financially rewarded for it.
Thanks again, steven
On Oct 2, 2012, at 7:05 PM, Elia Schito elia@schito.me wrote:
the system command pbpaste does that, you can call it with `pbpaste` from inside ruby :)
Elia
— ☁ @elia (twitter) ✎ elia@schito.me (gtalk) ☎ (+39) 348/9051393 perlelia@gmail.com (FaceTime)
On Wed, Oct 3, 2012 at 1:01 AM, Steven Arnold thoth_amon@mac.com wrote: Hello, I would like to create a command that in part pastes the contents of the clipboard, using TextMate 2. How would one access the contents of the clipboard in a command? I am using Ruby, but I am open to whatever works.
Thanks in advance, steven
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
Let me try to sharpen the point of my last question in a way that will make macros mostly unnecessary for me. I'd like to be able to emulate keyboard activity using commands.
One simple example is hitting backspace. To delete the current line, I can take the current line as input and replace it with "". But, this merely deletes the content of the current line; it does not remove the entire line (the carriage return is still there).
I've tried things like:
print "\x08" print "\b"
These give the literal text "<BS>" instead of actually acting as if I had hit the backspace key.
This is only one example. I might want to emulate other "meta" keypresses too. Even though the paste problem is solved with `pbpaste`, command-V would have worked too. It would be nice to have the option of emulating those kinds of keypresses.
What's the best way to handle this kind of problem?
Thanks again for any information! steven
Hi Steven, Backspace doesn't delete unselected characters: so if you select a line, and press backspace, you merely end up with a carat at character 0 on the line.
If the \n preceding a line is in the selection, then a command setting the selection to "" will erase the newline.
Macro recording will be great when it comes (I'm actually waiting till TMs internal states like dynamic selections can be played with in bundle commands and snippets).
But if we can't code, then at least while we wait these kinds of example can be worked around pretty easily.
If the example really is simply "do what backspace does when a line and the preceeding feed are selected", then that comes built-in and bound to backspace :-)
cheers, tim
On 3 Oct 2012, at 00:43, Steven Arnold thoth_amon@mac.com wrote:
Let me try to sharpen the point of my last question in a way that will make macros mostly unnecessary for me. I'd like to be able to emulate keyboard activity using commands.
One simple example is hitting backspace. To delete the current line, I can take the current line as input and replace it with "". But, this merely deletes the content of the current line; it does not remove the entire line (the carriage return is still there).
I've tried things like:
print "\x08" print "\b"
These give the literal text "<BS>" instead of actually acting as if I had hit the backspace key.
This is only one example. I might want to emulate other "meta" keypresses too. Even though the paste problem is solved with `pbpaste`, command-V would have worked too. It would be nice to have the option of emulating those kinds of keypresses.
What's the best way to handle this kind of problem?
Thanks again for any information! steven
Hi Tim,
On Oct 2, 2012, at 7:56 PM, Timothy Bates timothy.c.bates@gmail.com wrote:
If the \n preceding a line is in the selection, then a command setting the selection to "" will erase the newline.
This is a clever idea, but I am not sure how to increase the selection from the current line to the current line plus one character. Do you have a code sample for that, or can you point me toward some resources that might document how that sort of thing can be done?
Macro recording will be great when it comes (I'm actually waiting till TMs internal states like dynamic selections can be played with in bundle commands and snippets).
Definitely. Editors like jEdit translate macros into a program. I like that idea. Everything that can be done in a macro is essentially translatable to a series of commands.
If the example really is simply "do what backspace does when a line and the preceeding feed are selected", then that comes built-in and bound to backspace :-)
But I don't know how to make that happen in an automated way. Are you saying just hit the backspace key manually each time? I grant that's not much work, but it's annoying.
Regards, steven
Here is my hackish way of deleting a line from a file. It seems like overkill. Anyone got a better approach?
#!/usr/bin/env ruby -wKU linenum = ENV['TM_LINE_NUMBER'].to_i lines = STDIN.readlines output = [] lines.each_with_index do |line, idx| if idx+1 != linenum output << line end end print output.join
You have to select the document as input, replace document as output, and use line interpolation as caret placement. It only works if there is no selection.
steven
On Oct 2, 2012, at 9:20 PM, Steven Arnold thoth_amon@mac.com wrote:
Hi Tim,
On Oct 2, 2012, at 7:56 PM, Timothy Bates timothy.c.bates@gmail.com wrote:
If the \n preceding a line is in the selection, then a command setting the selection to "" will erase the newline.
This is a clever idea, but I am not sure how to increase the selection from the current line to the current line plus one character. Do you have a code sample for that, or can you point me toward some resources that might document how that sort of thing can be done?
Macro recording will be great when it comes (I'm actually waiting till TMs internal states like dynamic selections can be played with in bundle commands and snippets).
Definitely. Editors like jEdit translate macros into a program. I like that idea. Everything that can be done in a macro is essentially translatable to a series of commands.
If the example really is simply "do what backspace does when a line and the preceeding feed are selected", then that comes built-in and bound to backspace :-)
But I don't know how to make that happen in an automated way. Are you saying just hit the backspace key manually each time? I grant that's not much work, but it's annoying.
Regards, steven
#!/usr/bin/env ruby -wKU lines = STDIN.readlines lines.delete_at(ENV['TM_LINE_NUMBER'].to_i - 1) print lines.join
Dave.
On 3 Oct 2012, at 03:59, Steven Arnold thoth_amon@mac.com wrote:
Here is my hackish way of deleting a line from a file. It seems like overkill. Anyone got a better approach?
#!/usr/bin/env ruby -wKU linenum = ENV['TM_LINE_NUMBER'].to_i lines = STDIN.readlines output = [] lines.each_with_index do |line, idx| if idx+1 != linenum output << line end end print output.join
You have to select the document as input, replace document as output, and use line interpolation as caret placement. It only works if there is no selection.
steven
On Oct 2, 2012, at 9:20 PM, Steven Arnold thoth_amon@mac.com wrote:
Hi Tim,
On Oct 2, 2012, at 7:56 PM, Timothy Bates timothy.c.bates@gmail.com wrote:
If the \n preceding a line is in the selection, then a command setting the selection to "" will erase the newline.
This is a clever idea, but I am not sure how to increase the selection from the current line to the current line plus one character. Do you have a code sample for that, or can you point me toward some resources that might document how that sort of thing can be done?
Macro recording will be great when it comes (I'm actually waiting till TMs internal states like dynamic selections can be played with in bundle commands and snippets).
Definitely. Editors like jEdit translate macros into a program. I like that idea. Everything that can be done in a macro is essentially translatable to a series of commands.
If the example really is simply "do what backspace does when a line and the preceeding feed are selected", then that comes built-in and bound to backspace :-)
But I don't know how to make that happen in an automated way. Are you saying just hit the backspace key manually each time? I grant that's not much work, but it's annoying.
Regards, steven
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate