[TxMt] Feature Request: Number of Characters Selected
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Mon Jun 25 18:11:16 UTC 2007
On 25.06.2007, at 19:51, Robert M. Zigweid wrote:
>
> Greetings. I saw a neat feature in another editor, and I was
> wondering if there was similar functionality in TextMate. If there
> is, I haven't found it yet and a pointer would be most appreciated.
>
> When making a selection, I was wondering if there was some
> interface point that easily displayed how many characters were
> selected.
>
> My use case? Constructing HTTP Requests and wishing to supply the
> accurate content length quickly and easily. I can imagine other
> use cases as well, but this is the one that I can see needing most
> often.
You will find the content of your selection in the TM variable
TM_SELECTED_TEXT. Now is up to you, what kind of programming language
do you prefer and what encoding to you need.
in bash: echo "$TM_SELECTED_TEXT" | wc -c
in Perl: length($ENV['TM_SELECTED_TEXT'])
etc.
If you have to deal with utf-8 then one solution would be to use
Ruby's/Perl's split(//u) function
...
Or you can calculate the length by using the TM variables:
TM_LINE_INDEX - TM_INPUT_START_LINE_INDEX
this only works for ASCII
...
You can use 'Filter through command'
Input: Selection
Command: wc -c
Output: Show Tool Tip
#this works for ascii
etc....
Hans
More information about the textmate
mailing list