From a20b62652c026c26bfa22106b94c503f4ddecc3d Mon Sep 17 00:00:00 2001 From: ofer affias Date: Fri, 1 Mar 2013 22:02:29 +0200 Subject: [PATCH] initial release - ported to python3/st3 --- Default (Linux).sublime-keymap | 3 +++ Default (OSX).sublime-keymap | 3 +++ Default (Windows).sublime-keymap | 3 +++ MiniPy.py | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 Default (Linux).sublime-keymap create mode 100644 Default (OSX).sublime-keymap create mode 100644 Default (Windows).sublime-keymap create mode 100644 MiniPy.py diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap new file mode 100644 index 0000000..8bc4135 --- /dev/null +++ b/Default (Linux).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["ctrl+shift+x"], "command": "minipy_eval" } +] \ No newline at end of file diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap new file mode 100644 index 0000000..31637b0 --- /dev/null +++ b/Default (OSX).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["super+shift+x"], "command": "minipy_eval" } +] \ No newline at end of file diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap new file mode 100644 index 0000000..8bc4135 --- /dev/null +++ b/Default (Windows).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["ctrl+shift+x"], "command": "minipy_eval" } +] \ No newline at end of file diff --git a/MiniPy.py b/MiniPy.py new file mode 100644 index 0000000..9c9c210 --- /dev/null +++ b/MiniPy.py @@ -0,0 +1,34 @@ +from math import * +from random import * +import re +import sublime, sublime_plugin + +# reverse() in python3 +def rev(s): return s[::-1] + +class Minipy_evalCommand(sublime_plugin.TextCommand): + def run(self, edit, user_input=None): + self.edit = edit + view = self.view + script = "" + + # sum the total number of special char $ + total = 0 + for region in view.sel(): + total += view.substr(region).count("$") + + # build a list from 1 to the number of special chars + serial_number = list(range(total+1,1)) + # serial_number.reverse() + # serial_number = rev(serial_number) + # print(repr(serial_number)) + + # replace each special char $ with the next index from serial_number list + # and eval the expression + for region in view.sel(): + if region.begin() != region.end(): + script = view.substr(region) + for n in range(script.count("$")): + script = re.sub(r"\$", str(serial_number.pop()), script, 1) + # print(eval(script)) + view.replace(edit, region, str(eval(script)))