[TxMt] [ANN] Select Balanced HTML Tag!!!3!

Hans-Jörg Bibiko bibiko at eva.mpg.de
Wed Nov 28 20:47:44 UTC 2007


On 28.11.2007, at 15:47, Thomas Aylott - subtleGradient wrote:
> Yes, I've been wanting a proper way to get the REAL cursor location  
> forever. Just check out what I'm doing inside the Support/lib/ 
> codecompletion.rb to get the actual cursor location no matter if  
> you have a selection or if the selection was started from the left  
> or the right, etc...
I did it that way:

get the caret position or if a selection is done take the start point:
[TM_INPUT_START_LINE is only set for a selection]

if defined "TM_INPUT_START_LINE"
  line       = "TM_INPUT_START_LINE" - 1
  line_index = "TM_INPUT_START_LINE_INDEX"
else
  line       = "TM_LINE_NUMBER" - 1
  line_index = "TM_LINE_INDEX"
end


get the real caret position (in bytes but depends on the regexp engine):
1) via regexp:
THE_ENTIRE_TEXT =~ /((.*\n){line})(.{line_index})/
TEXT_BEFORE_CARET = "$1$3";
CARET_POSITION = length (TEXT_BEFORE_CARET)

[Perl crashes here for a very large text chunk; Ruby is fine]

2) count \n + line_index
CARET_POSITION = 0
count = line;
while(count--){
	CARET_POSITION = index(THE_ENTIRE_TEXT,"\n", CARET_POSITION)
	CARET_POSITION++
}
CARET_POSITION = CARET_POSITION  + line_index

or others

> I already replaced the version in Experimental with this version  
> and added the contents only version too.
> Is that one good enough or will you be updatingthe contents version  
> too?

I attached a slightly modified version of "Select Balanced (HT|X)ML  
Tags". I cleaned the code, improved the error handling (e.g. if  
HTML::Parser is not installed); Tool Tip if nothing is found or there  
is a mismatch.

Based on that "Select Balanced (HT|X)ML Tags" macro I will post a new  
(and more robust) version of "Select Content of Balanced (HT|X)ML  
Tags" (hopefully tomorrow). Maybe I will have some time to write a  
macro for "Select Balanced (HT|X)ML Tags backwards" like yours using  
UNDO.

Best,

--Hans

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Select Balanced (HT|X)ML Tags.tmMacro
Type: application/octet-stream
Size: 6198 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20071128/22909794/attachment.tmMacro>


More information about the textmate mailing list