Skip to content

Commit

Permalink
initial release - ported to python3/st3
Browse files Browse the repository at this point in the history
  • Loading branch information
vim-zz committed Mar 1, 2013
1 parent f9bf4c6 commit a20b626
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Default (Linux).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" }
]
3 changes: 3 additions & 0 deletions Default (OSX).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["super+shift+x"], "command": "minipy_eval" }
]
3 changes: 3 additions & 0 deletions Default (Windows).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" }
]
34 changes: 34 additions & 0 deletions 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)))

0 comments on commit a20b626

Please sign in to comment.