0

I do a lot of work with temperatures in Textmate and I'd love to create a command or snippet that would do the following. I could highlight a number like the 131 below

Cook the food at 131.

Them run the command and it would automatically calculate the Celsius and format it, resulting in

Cook the food at 131°F / 55°C.

I have a little experience working with snippets but not too much, especially with manipulating the selected text. I figured it'd be a trivial problem for someone that knew commands better than me!

Thanks a lot.

Jason Logsdon
  • 507
  • 5
  • 19

1 Answers1

3

Got what you are looking for. Also, as a heads up, the command field really just accepts anything that can be executed via bash, so if you are familiar with any of that, or want to use a language you are comfy with, its an amazingly powerful field. For this I'll use python simply because bash and floating point math dont play well together.

Go to Bundles -> Bundle Editor -> Edit Commands and select the language that this best fits (if you are looking to apply this across the baord, you may want to use the Source or Text bundle.

Create a new Command and for the text, enter in:

#!/usr/bin/env python

from sys import stdin

degF = int( stdin.read() )
degC = (degF - 32) * 5 / 9

print str(degF) + "°F / " + str(degC) + "&degC;."

Next set your drop downs such that the Input is Selected Text and the Output is Replace Selected Text

The activation needs to be Key Equivalent and then input the keyboard command you wish to cause this to apply.

Finally, choose the scope for this. If you want it available across any type of file, leave this blank. If you want it across all non-code based files, (plain text, html, etc) enter text. For only code related files, enter source. Yuo can also get more granular if you wish (source.php)

Hope that helps!

Ben Roux
  • 7,308
  • 1
  • 18
  • 21
  • I can't think of any way to make that a more perfect answer. Thanks for the code and especially for such a good run down of why it works. I really appreciate it. – Jason Logsdon Jun 23 '12 at 11:24