Home Download Buy Blog Forum Support

Evaluate Selection?

Evaluate Selection?

Postby baronvonkanehoffen on Tue Sep 20, 2011 12:47 pm

In Textmate, there's a great shortcut (Shift+Ctrl+C) to evaluate the selected text, so for instance I'd select:
8*2
and it'd print:
8*2 = 16

Very useful! Is there already something like this in Sublime Text I haven't found yet, or would someone consider putting it in?

Love the rest of the editor btw. Well on the way to being better than TM! :-)
baronvonkanehoffen
 
Posts: 3
Joined: Tue Sep 20, 2011 12:43 pm

Re: Evaluate Selection?

Postby iamntz on Tue Sep 20, 2011 12:54 pm

If you install zen coding you will have the same behaviour with ctrl+alt+shift+=
iamntz
 
Posts: 917
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Evaluate Selection?

Postby jbrooksuk on Tue Sep 20, 2011 2:50 pm

I've just modified wbond's Prefixr plugin to evaluate selections.

Check it out on GitHub.
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Evaluate Selection?

Postby timchesney on Tue Sep 20, 2011 9:22 pm

Hey this is great - just install and is working really well. I'm not awesome (ie totally rubbish!) at python. Is there some simple way to get it to not round the result... or to only round to say 4 decimal places or something like that? At the moment 19/4 evaluates to 4 which isn't accurate enough for working out em sizes in CSS layouts (my main us for this function) - what I need is it to evaluate to 4.75 (which should really round to 5 btw).

Thanks again for sharing this!
timchesney
 
Posts: 1
Joined: Tue Sep 20, 2011 9:17 pm

Re: Evaluate Selection?

Postby jbrooksuk on Wed Sep 21, 2011 7:49 am

timchesney wrote:Hey this is great - just install and is working really well. I'm not awesome (ie totally rubbish!) at python. Is there some simple way to get it to not round the result... or to only round to say 4 decimal places or something like that? At the moment 19/4 evaluates to 4 which isn't accurate enough for working out em sizes in CSS layouts (my main us for this function) - what I need is it to evaluate to 4.75 (which should really round to 5 btw).

Thanks again for sharing this!

I'm using using Pythons
Code: Select all
eval()
function. But I plan on implementing some kind of custom top-down parser. Give better arithmetic functions, and allow for custom functions such as Textmate,
Code: Select all
date
etc.

Check the forum discussion here.
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Evaluate Selection?

Postby baronvonkanehoffen on Wed Sep 21, 2011 3:39 pm

iamntz wrote:If you install zen coding you will have the same behaviour with ctrl+alt+shift+=

Hey that's great! Thanks a lot!
Had to put a user key binding on:
Code: Select all
{ "keys": ["ctrl+shift+c"], "command": "run_zen_action", "args": {"action": "evaluate_math_expression"} }

Syntax took a bit to work out, so thought I'd post here (i'm on osx btw)

Don't suppose you know any way to get the command to do floating point? For instance if I evaluate "15/16", I get "0", not ".9375"
Bit silly that!

Unfortunately my knowledge of Python only extends as far as "it's also the name of a snake" :)
baronvonkanehoffen
 
Posts: 3
Joined: Tue Sep 20, 2011 12:43 pm

Re: Evaluate Selection?

Postby bizoo on Wed Sep 21, 2011 4:26 pm

"15/16." will probably work...
bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Evaluate Selection?

Postby jbrooksuk on Thu Sep 22, 2011 8:00 am

bizoo wrote:"15/16." will probably work...

Since my plugin and I assume that ZenCoding uses eval too... That will work :)
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Evaluate Selection?

Postby baronvonkanehoffen on Thu Sep 22, 2011 9:37 am

Hmmm... Then any idea what I could be doing wrong? Just tried your Evaluate plugin and no joy with that either.
I create a new file, type 3/2, highlight it, press shift+ctrl+e, the text is replaced with 1.
If I do the same with 15/16, it doesn't replace it at all - I just get the message "0 selection regions; Evaluated 0 selections!" ...and the region in question was definitely selected :)

I'm on the latest beta (2111). Wonder if it's a bug or my own stupidity?
baronvonkanehoffen
 
Posts: 3
Joined: Tue Sep 20, 2011 12:43 pm

Re: Evaluate Selection?

Postby jbrooksuk on Thu Sep 22, 2011 10:57 am

baronvonkanehoffen wrote:Hmmm... Then any idea what I could be doing wrong? Just tried your Evaluate plugin and no joy with that either.
I create a new file, type 3/2, highlight it, press shift+ctrl+e, the text is replaced with 1.
If I do the same with 15/16, it doesn't replace it at all - I just get the message "0 selection regions; Evaluated 0 selections!" ...and the region in question was definitely selected :)

I'm on the latest beta (2111). Wonder if it's a bug or my own stupidity?


Just place a period after the last number, so... Select:
Code: Select all
15/16.

Or
Code: Select all
3/2.
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Next

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests