Hello all,
I am trying to find information in regards of how to copy and paste text in a new line, for example:
before snippet:
myText
after snippet:
myText theText = myText
currently I am able to create a snippet that will copy the selected word and create a new line like this:
theText = $TM_SELECTED_TEXT
but of course this replaces the selected text so I did the following
$TM_SELECTED_TEXT theText = $TM_SELECTED_TEXT
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
TIA Helmut
On Jan 24, 2007, at 11:48 AM, Helmut Granda wrote:
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
You would need to use a command, that has as input the entire document and output probably insert as snippet. Then you would have to locate the line the caret is at, and then add a line right after it with what you want. You then need to snippet-escape all the regular text, and add a $0 at the correct location where you want the caret to end up.
Sorry, short on time here, but there are ruby libraries that make most of the above very easy (for instance the escaping part). The location can be found via the [dynamic environment variables][http:// macromates.com/textmate/manual/ environment_variables#environment_variables]. There are a number of commands that do similar things in most bundles, certainly in GTDAlt and LaTeX bundles. It should be a short 5-6 line ruby script, if the text manipulation you want to do is simple like above. I'll try to write an example when I get a chance.
TIA Helmut
Haris
Great! thanks for the information. I will go ahead and do a research on that and like you suggested there might be a place where they are doing what I need like in Ruby.
Thanks again, Helmut
On 1/24/07, Charilaos Skiadas skiadas@hanover.edu wrote:
On Jan 24, 2007, at 11:48 AM, Helmut Granda wrote:
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
You would need to use a command, that has as input the entire document and output probably insert as snippet. Then you would have to locate the line the caret is at, and then add a line right after it with what you want. You then need to snippet-escape all the regular text, and add a $0 at the correct location where you want the caret to end up.
Sorry, short on time here, but there are ruby libraries that make most of the above very easy (for instance the escaping part). The location can be found via the [dynamic environment variables][http:// macromates.com/textmate/manual/ environment_variables#environment_variables]. There are a number of commands that do similar things in most bundles, certainly in GTDAlt and LaTeX bundles. It should be a short 5-6 line ruby script, if the text manipulation you want to do is simple like above. I'll try to write an example when I get a chance.
TIA Helmut
Haris
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 Jan 24, 2007, at 12:08 PM, Charilaos Skiadas wrote:
On Jan 24, 2007, at 11:48 AM, Helmut Granda wrote:
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
You would need to use a command, that has as input the entire document and output probably insert as snippet. Then you would have to locate the line the caret is at, and then add a line right after it with what you want. You then need to snippet-escape all the regular text, and add a $0 at the correct location where you want the caret to end up.
Sorry, short on time here, but there are ruby libraries that make most of the above very easy (for instance the escaping part). The location can be found via the [dynamic environment variables] [http://macromates.com/textmate/manual/ environment_variables#environment_variables]. There are a number of commands that do similar things in most bundles, certainly in GTDAlt and LaTeX bundles. It should be a short 5-6 line ruby script, if the text manipulation you want to do is simple like above. I'll try to write an example when I get a chance.
TIA Helmut
I spoke too soon here. Actually there is no way to do what I described exactly. The gist of it is that you need to set the output of the command to "insert as snippet', so as to be able to decide where you want the caret to end. However, in order for the snippet to actually overwrite the entire text, you must make it so that TM thinks that there is a selection, and hence it should replace the selection when inserting the snippet. So the input should be selection with fallback document.
But in your case you already have the selection there, so the whole document will never end up being entered as input.
So I think as Dr. Drang suggested a macro is closer to what you want to do. Depending on whether this "theText" part is the same or different in each case, you would want to use a snippet or command or neither WITHIN your macro. If all you want is to solve the exact problem you described in the first message, then this is probably what you want (slightly different that Dr. Drang's suggestion):
select the text you want. Start macro recording (Bundles -> Macros ...) Copy use cmd + right arrow to move to end of line Press Return Type "theText = " Paste Stop macro recording (Bundles -> Macros ...) Save scratch macro Test scratch macro
Haris
Haris
Thanks for your suggestions guys, the Macros seemed to work but it has the same behavior as if it is used inside a para (it brakes the sentences in the middle).
Let me back up a little, the item I am using this for is ActionScript (Flash) and there is a function within actionscript that is called Trace, similar to echo or print but for debugging purposes.
So if I am writing my application by hand I would do something like this
var i:Number = 10; trace (" Var i = " i);
So I am trying to find a way to do it where i can just select a part of a sentence (in this case a variable) and have the result back when I need it instead of typing it by hand.
but in this case the Macros still does something like this:
var i trace("i =e + ir = 10;
the snippet(which you guys figured out its not a good idea does the following:
var trace("i = " i);:Number = 10;
So anyways, I was thinking of doing something like this:
1. type the code -- var:i:Number = 10; 2. type the item I need to "trace" (in this case -i- by itself) 3. run macros or snipped and it shoudl work.
I still would have to take an extra step but saves a little bit of typing.
On 1/24/07, Charilaos Skiadas skiadas@hanover.edu wrote:
On Jan 24, 2007, at 12:08 PM, Charilaos Skiadas wrote:
On Jan 24, 2007, at 11:48 AM, Helmut Granda wrote:
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
You would need to use a command, that has as input the entire document and output probably insert as snippet. Then you would have to locate the line the caret is at, and then add a line right after it with what you want. You then need to snippet-escape all the regular text, and add a $0 at the correct location where you want the caret to end up.
Sorry, short on time here, but there are ruby libraries that make most of the above very easy (for instance the escaping part). The location can be found via the [dynamic environment variables] [http://macromates.com/textmate/manual/ environment_variables#environment_variables]. There are a number of commands that do similar things in most bundles, certainly in GTDAlt and LaTeX bundles. It should be a short 5-6 line ruby script, if the text manipulation you want to do is simple like above. I'll try to write an example when I get a chance.
TIA Helmut
I spoke too soon here. Actually there is no way to do what I described exactly. The gist of it is that you need to set the output of the command to "insert as snippet', so as to be able to decide where you want the caret to end. However, in order for the snippet to actually overwrite the entire text, you must make it so that TM thinks that there is a selection, and hence it should replace the selection when inserting the snippet. So the input should be selection with fallback document.
But in your case you already have the selection there, so the whole document will never end up being entered as input.
So I think as Dr. Drang suggested a macro is closer to what you want to do. Depending on whether this "theText" part is the same or different in each case, you would want to use a snippet or command or neither WITHIN your macro. If all you want is to solve the exact problem you described in the first message, then this is probably what you want (slightly different that Dr. Drang's suggestion):
select the text you want. Start macro recording (Bundles -> Macros ...) Copy use cmd + right arrow to move to end of line Press Return Type "theText = " Paste Stop macro recording (Bundles -> Macros ...) Save scratch macro Test scratch macro
Haris
Haris
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 Jan 24, 2007, at 5:40 PM, Helmut Granda wrote:
So if I am writing my application by hand I would do something like this
var i:Number = 10; trace (" Var i = " i);
I think the macro I've attached should do something similar to what you want. We can modify it a bit accordingly, but I am not seeing any of the problems you mentioned.
Haris
You are correct, your macro works great. is there a way to change the macros manually? For example there is a "," where I need a "+" and a "=" somewhere....
Thanks again, I am looking at your macro and I am trying to reproduce your steps.
On 1/24/07, Charilaos Skiadas skiadas@hanover.edu wrote:
On Jan 24, 2007, at 5:40 PM, Helmut Granda wrote:
So if I am writing my application by hand I would do something like this
var i:Number = 10; trace (" Var i = " i);
I think the macro I've attached should do something similar to what you want. We can modify it a bit accordingly, but I am not seeing any of the problems you mentioned.
Haris
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
No need to edit manually, after following your steps I was able to produce what I needed. this works great thanks again!
On 1/24/07, Helmut Granda contact@helmutgranda.com wrote:
You are correct, your macro works great. is there a way to change the macros manually? For example there is a "," where I need a "+" and a "=" somewhere....
Thanks again, I am looking at your macro and I am trying to reproduce your steps.
On 1/24/07, Charilaos Skiadas skiadas@hanover.edu wrote:
On Jan 24, 2007, at 5:40 PM, Helmut Granda wrote:
So if I am writing my application by hand I would do something like this
var i:Number = 10; trace (" Var i = " i);
I think the macro I've attached should do something similar to what you want. We can modify it a bit accordingly, but I am not seeing any of the problems you mentioned.
Haris
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
Oh I just figured out that if I open the Macro with TextMate then I will be able to edit the macro manually.
On 1/24/07, Helmut Granda contact@helmutgranda.com wrote:
No need to edit manually, after following your steps I was able to produce what I needed. this works great thanks again!
On 1/24/07, Helmut Granda < contact@helmutgranda.com> wrote:
You are correct, your macro works great. is there a way to change the macros manually? For example there is a "," where I need a "+" and a "=" somewhere....
Thanks again, I am looking at your macro and I am trying to reproduce your steps.
On 1/24/07, Charilaos Skiadas < skiadas@hanover.edu> wrote:
On Jan 24, 2007, at 5:40 PM, Helmut Granda wrote:
So if I am writing my application by hand I would do something like this
var i:Number = 10; trace (" Var i = " i);
I think the macro I've attached should do something similar to what you want. We can modify it a bit accordingly, but I am not seeing any of the problems you mentioned.
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't)
I'm not sure how many different situations you need to handle, but this sounds like a job for a macro, not a snippet.
1. Create a document with the sort of text you want to transform 2. Select the text 3. Start recording the macro (look in the Bundles menu) a. Copy b. Arrow down a line c. Type in "theText = " d. Paste 4. Stop recording the macro 5. Test the macro 6. Save the macro and give it a good name and key combination
If the text you need to transform is more complicated than what you described in your message, you may need to do something more complicated than just arrow down one line in step 3b.
On Jan 24, 2007, at 10:48 AM, Helmut Granda wrote:
Hello all,
I am trying to find information in regards of how to copy and paste text in a new line, for example:
before snippet:
myText
after snippet:
myText theText = myText
currently I am able to create a snippet that will copy the selected word and create a new line like this:
theText = $TM_SELECTED_TEXT
but of course this replaces the selected text so I did the following
$TM_SELECTED_TEXT theText = $TM_SELECTED_TEXT
and this works great if there is only one line of text but lets say I need to select a certain word in the middle of a pharragraph then i get the following
before snippet: first word theText second word
after snippet: first word theText theText = theText second word
as you can tell the snippet inserts the comman din the middle of the sentence, is there a way to avoid that?
TIA Helmut
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
-- Mark Lawrence vCard: www.unified-eng.com/people/MAL.vcf