[TxMt] Copy and Duplicate word snippet

Helmut Granda contact at helmutgranda.com
Wed Jan 24 22:40:12 UTC 2007


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 at 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 at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20070124/295d7c00/attachment.html>


More information about the textmate mailing list