Sublime Forum

Evaluate Selection?

#1

In Textmate, there’s a great shortcut (Shift+Ctrl+C) to evaluate the selected text, so for instance I’d select:
82
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! :smile:

0 Likes

#2

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

0 Likes

#3

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

Check it out on GitHub.

0 Likes

#4

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!

0 Likes

#5

[quote=“timchesney”]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![/quote]

I’m using using Pythons 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, date etc.

Check the forum discussion here.

0 Likes

#6

Hey that’s great! Thanks a lot!
Had to put a user key binding on:

{ "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” :smile:

0 Likes

#7

“15/16.” will probably work…

0 Likes

#8

Since my plugin and I assume that ZenCoding uses eval too… That will work :smile:

0 Likes

#9

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 :smile:

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

0 Likes

#10

[quote=“baronvonkanehoffen”]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 :smile:

I’m on the latest beta (2111). Wonder if it’s a bug or my own stupidity?[/quote]

Just place a period after the last number, so… Select:

15/16.

Or

3/2.
0 Likes

#11

[quote=“baronvonkanehoffen”]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 :smile:

I’m on the latest beta (2111). Wonder if it’s a bug or my own stupidity?[/quote]

Upgrade to the latest version! I’ve fixed it :smile:

0 Likes