Skip to content

Commit a20b626

Browse files
committed
initial release - ported to python3/st3
1 parent f9bf4c6 commit a20b626

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Default (Linux).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" }
3+
]

Default (OSX).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["super+shift+x"], "command": "minipy_eval" }
3+
]

Default (Windows).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" }
3+
]

MiniPy.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from math import *
2+
from random import *
3+
import re
4+
import sublime, sublime_plugin
5+
6+
# reverse() in python3
7+
def rev(s): return s[::-1]
8+
9+
class Minipy_evalCommand(sublime_plugin.TextCommand):
10+
def run(self, edit, user_input=None):
11+
self.edit = edit
12+
view = self.view
13+
script = ""
14+
15+
# sum the total number of special char $
16+
total = 0
17+
for region in view.sel():
18+
total += view.substr(region).count("$")
19+
20+
# build a list from 1 to the number of special chars
21+
serial_number = list(range(total+1,1))
22+
# serial_number.reverse()
23+
# serial_number = rev(serial_number)
24+
# print(repr(serial_number))
25+
26+
# replace each special char $ with the next index from serial_number list
27+
# and eval the expression
28+
for region in view.sel():
29+
if region.begin() != region.end():
30+
script = view.substr(region)
31+
for n in range(script.count("$")):
32+
script = re.sub(r"\$", str(serial_number.pop()), script, 1)
33+
# print(eval(script))
34+
view.replace(edit, region, str(eval(script)))

0 commit comments

Comments
 (0)