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.
Regards,
Robert M. Zigweid
On 25.06.2007, at 19:51, Robert M. Zigweid wrote:
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
On 25.06.2007, at 19:51, Robert M. Zigweid wrote:
Just for completion because someone asked for that :-}
utf-8 support (i.e. also for Japanese, accented characters, etc.)
You can use 'Filter through command' or create a command Input: Selection Command: ruby -ne 'print split(//u).size' Output: Show Tool Tip
Hans
On 25.06.2007, at 19:51, Robert M. Zigweid wrote:
Just for completeness’ sake:
Or yo can press ⇧⌃N [Text Bundle → Statistics for Document / Selection (Word Count)] which does the following behind the scenes:
wc -lwc|tr \ \n|grep '..*'|rev|perl -pe 's/\d{3}(?=.)/$&,/g'| rev|{ for unit in lines words bytes; do read cnt printf "%11.11s %s\n" $cnt $unit done }
So, yes, it is already built in.
regards, Soryu.