I don't speak any scripting language so I was hoping you all could help me out with two simple commands.
1. Take the current line number, divide my 38 and display the result as a tooltip that reads: Aprox. Page-Count for Current Line: XX 2. Take the total number of lines in the document, divide my 38 and display the result as a tooltip that reads: Aprox. Page-Count for Document: XX
Thanks in advance!
—oliver
Oliver,
This should do what you need:
npp=38 res=$(echo `wc -l`) pretty () { rev <<<$1|perl -pe 's/(\d{3})(?=.)/$1,/g'|rev; } total=$(pretty $(cut <<<$res -d\ -f1)) php -r "echo ceil($TM_LINE_NUMBER/$npp).'/'.ceil($total/$npp);"
Just "Add new command" in Bundle Editor, input "Entire Document", and output "Show as Tool Tip". Part of that comes form Text's statistics for document command. It's a good place to start even if you don't know how to script.
Hope that helps,
Jeff.
On May 9, 2006, at 9:19 PM, Oliver Taylor wrote:
I don't speak any scripting language so I was hoping you all could help me out with two simple commands.
- Take the current line number, divide my 38 and display the result
as a tooltip that reads: Aprox. Page-Count for Current Line: XX 2. Take the total number of lines in the document, divide my 38 and display the result as a tooltip that reads: Aprox. Page-Count for Document: XX
Thanks in advance!
—oliver
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 10/5/2006, at 3:19, Oliver Taylor wrote:
- Take the current line number, divide my 38 and display the result
as a tooltip that reads: Aprox. Page-Count for Current Line: XX 2. Take the total number of lines in the document, divide my 38 and display the result as a tooltip that reads: Aprox. Page-Count for Document: XX
As a shell script (i.e. just paste in body of command):
echo "Aprox. page #$(( (TM_LINE_NUMBER+37) / 38 ))" echo "Aprox. total pages $(( `wc -l` / 38 + 1 ))"
Basically $((…)) allows you to do math in the shell. `…` runs a command, in this case, it runs `wc -l` which is word count (but with - l, gives number of lines).
The command should have Input set to Entire Document.
I add 37 to the current line number, since the shell truncates the value, and I assume you want it rounded up. I.e. line 1-37 should say page #1.
As for total number of pages, I just add 1 to the result, since `wc` gives a zero-based number, so I would have to add one to make it one- based, and then 37 to round up (1 + 37 = 38).