[TxMt] math bundle feature request
Charilaos Skiadas
skiadas at hanover.edu
Fri Dec 8 03:22:33 UTC 2006
On Dec 7, 2006, at 7:07 PM, janssen at ccr.jussieu.fr wrote:
>> I personally use R for such things. You need to basically have
>> R.app running on already for the shift-cmd-R thing to work, but
>> then it does. And for your purposes, you can copy the command and
>> modify it so that the output is set to replace selection.
>> (Actually come to think of it, that would be a nice addition)
>
> May be you can, but not me!
Ok, here is the best I can do for now, with Eridius's help: Create a
textmate command that has input "Selected Text or Line", and output:
"Replace Selected Text". The text of the command should be the
following 8 lines:
#!/usr/bin/env ruby
include Math
class Float
def inspect
"%.#{ENV['TM_CALC_PREC'] || 3}f" % self
end
end
print(eval(STDIN.read).inspect)
this should be improved, but it is a start. It will not do integer
division properly unless you coerce it:
2/3=0, 2.0/3=0.667
You can use all the commands found here:
http://www.ruby-doc.org/core/classes/Math.html
without having to write the Math in front. Examples:
cos(2.6) -> -0.836
log(3.4) -> 1.224
etc.
You can adjust it by defining the TM_CALC_PREC variable to your
desired number of precision (defaults to 3). Hopefully we can come up
with something more robust etc etc, but this might serve most modest
needs, and it is very fast.
Needless to say, you should bind this to your favorite shortcut.
Haris
More information about the textmate
mailing list