[TxMt] Modifying word selection

Charilaos Skiadas cskiadas at uchicago.edu
Tue Apr 11 14:44:07 UTC 2006


On Apr 11, 2006, at 9:21 AM, James Andrews wrote:

> Hi Haris,
>
> This wasn't quite what I had in mind (more an extension of existing  
> keyboard or mouse text selection techniques using an added modifier  
> key) but it would be an alternative (and quick to implement) if it  
> could be made to work.
>
> What commands would you combine with the regex to result in  
> selecting text at the cursor with the specified scope? I've done  
> some thinking and digging around in case I'd missed something, but  
> can't see how it could be done.
>
Wait, I don't see where scope comes in in what you discussed above, I  
don't thing that would help you select the foo in foo_bar. That is  
another, very interesting question, which does not have a trivial  
answer atm, though I guess Allan could possibly provide such a  
command, that selects the entire current scope. He has however given  
us the tools to create it ourselves, using the new inputFormat plist  
key (see the release notes):

  Basically it is now possible to get as input to a command an "xml"  
version of the text, where the tags are exactly the scopes. Scanning  
this file would, theoretically, allow you to select the current  
scope. The problem would probably be to locate the text right where  
the cursor is. Possible with a bit of programming.
You'd basically need (I think) to locate all text nodes and count  
newlines until you match TM_LINE_NUMBER. Then scan characters until  
TM_LINE_INDEX. Then select the text node containing this character.
At the end of the day you would have a command that outputs the whole  
text of the current scope. Then you could also have the command use  
pbcopy to place this into the pasteboard and discard its output. Then  
you could use this in a macro together with a literal backward search  
to actually select the corresponding text.
The only drawback of this, apart from its slowness in large  
documents, is the fact that it alters the pasteboard. Another  
alternative, if TextMate's applescripting possibilities allow this  
(which I think they don't at the moment, though I'd like to put it as  
a request if they don't), is to tell TextMate through osascript to do  
a backward search for the appropriate text, all from within the  
command. That would leave the pasteboard intact.

Sorry for the technical answer.
> Thanks,
> James

Haris





More information about the textmate mailing list