Hello,
I am looking into building my own bundles and was wondering if it is possible to somehow get the last 3 or so words before the caret. I know there is a variable for the current line and current word, but can I somehow get the last 3 or so words even if they are on different lines? Thanks!
Christoph
On 19 Jun 2007, at 04:40, Christoph Koehler wrote:
I am looking into building my own bundles and was wondering if it is possible to somehow get the last 3 or so words before the caret. I know there is a variable for the current line and current word, but can I somehow get the last 3 or so words even if they are on different lines?
Well, there're some possibilities to do that. First in my mind would be if the number of words is fixed, in your example three, to record a macro:
moveWordRight moveWordLeftAndModifySelection moveWordLeftAndModifySelection moveWordLeftAndModifySelection
and bind it to any key equivalent
In general the macro will do: 1: place the caret at the end of the current word 2...4: expand the selection word by word
hans
In article D1CE11D3-005C-43C6-BBC0-80933A834178@eva.mpg.de Hans-JoergBibiko bibiko@eva.mpg.de wrote:
Well, there're some possibilities to do that. First in my mind would be if the number of words is fixed, in your example three, to record a macro: moveWordRight moveWordLeftAndModifySelection moveWordLeftAndModifySelection moveWordLeftAndModifySelection and bind it to any key equivalent In general the macro will do: 1: place the caret at the end of the current word 2...4: expand the selection word by word hans
Yeah that works, but that's not the whole story :) I need to get the last 3 words and then evaluate them based on what they are. Is that possible after selecting them with a macro? Sorry for the newbie questions! Christoph
On 19 Jun 2007, at 22:11, Christoph Koehler wrote:
Well, there're some possibilities to do that. First in my mind would be if the number of words is fixed, in your example three, to record a macro:
moveWordRight moveWordLeftAndModifySelection moveWordLeftAndModifySelection moveWordLeftAndModifySelection
Yeah that works, but that's not the whole story :) I need to get the last 3 words and then evaluate them based on what they are. Is that possible after selecting them with a macro? Sorry for the newbie questions!
-Write a command MYCOMMAND which evaluate something with $TM_SELECTED_TEXT (it contains the last three words) -Record a macro which does the following:
moveWordRight moveWordLeftAndModifySelection moveWordLeftAndModifySelection moveWordLeftAndModifySelection MYCOMMAND
and save it. Please note, if you change MYCOMMAND the macro won't notice your changes because the entire code is saved within this macro. You have to rerecord your macro.
If you are not lucky by using a macro you can write a command using Ruby, Perl, or what ever and work on $TM_CURRENT_LINE (if the three last words are in the same line) or on the entire document (if not).
Hans
On Wed, 20 Jun 2007, Hans-Joerg Bibiko wrote:
Please note, if you change MYCOMMAND the macro won't notice your changes because the entire code is saved within this macro. You have to rerecord your macro.
The way I handle this is to store all my commands in an external file. Each command in TM then just includes that file and makes a single subroutine call. This way I can change the behavior of my commands without having to dink around with changing the macros which use it.
For instance, I have a command set up to show all the Mac-specific key symbols as an HTML window. The command entry in TM's bundle editor looks like:
#! /usr/bin/perl require "$ENV{TM_BUNDLE_PATH}/tm_lib.pl"; print key_symbols();
The code for the key_symbols() function is in my bundle directory in <~/Library/Application Support/TextMate/Bundles/sking.tmbundle/tm_lib.pl>. (The 'require' statement is essentially Perl's version of '#include'.)
When I want to change the command's behavior (say, to add a key I'd forgotten) I just edit that external file. No need to change the command at all in the bundle editor. If I'd included the command in any macros, they'd all automatically pick up the changes without having to be individually modified.
Another benefit of storing the commands as an external library is that you edit them in the main TM window, not the bundle editor. This means you get all the nifty language features (syntax highlighting, etc.) that are the reason you use TextMate in the first place.
I find this technique of using an external library file so handy that I code all my TM commands (except trivial one-liners) this way.
In article alpine.OSX.0.99.0706201013560.28830@marimac.arbor.netSteve King steve@narbat.com wrote:
On Wed, 20 Jun 2007, Hans-Joerg Bibiko wrote:
Please note, if you change MYCOMMAND the macro won't notice your changes because the entire code is saved within this macro. You have to rerecord your macro.
The way I handle this is to store all my commands in an external file. Each command in TM then just includes that file and makes a single subroutine call. This way I can change the behavior of my commands without having to dink around with changing the macros which use it. For instance, I have a command set up to show all the Mac-specific key symbols as an HTML window. The command entry in TM's bundle editor looks like: #! /usr/bin/perl require "$ENV{TM_BUNDLE_PATH}/tm_lib.pl"; print key_symbols(); The code for the key_symbols() function is in my bundle directory in <~/Library/Application Support/TextMate/Bundles/sking.tmbundle/tm_lib.pl>. (The 'require' statement is essentially Perl's version of '#include'.) When I want to change the command's behavior (say, to add a key I'd forgotten) I just edit that external file. No need to change the command at all in the bundle editor. If I'd included the command in any macros, they'd all automatically pick up the changes without having to be individually modified. Another benefit of storing the commands as an external library is that you edit them in the main TM window, not the bundle editor. This means you get all the nifty language features (syntax highlighting, etc.) that are the reason you use TextMate in the first place. I find this technique of using an external library file so handy that I code all my TM commands (except trivial one-liners) this way.
Thanks guys! Very helpful! I will play with that!
Christoph
On 20 Jun 2007, at 18:35, Christoph Koehler wrote:
Another benefit of storing the commands as an external library is that you edit them in the main TM window, not the bundle editor. This means you get all the nifty language features (syntax highlighting, etc.) that are the reason you use TextMate in the first place.
⌃⌘E