Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial release - ported to python3/st3
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
{ "keys": ["super+shift+x"], "command": "minipy_eval" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
{ "keys": ["ctrl+shift+x"], "command": "minipy_eval" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |