Home Download Buy Blog Forum Support

MiniPy - followup on EJ12N

MiniPy - followup on EJ12N

Postby vim on Mon Jun 15, 2009 4:30 pm

i was amazed from EJ12N screen cast and tried to implement the exec python myself, to see how far can i take it. well i came up with this:

NOTE: if you plan to use it, see better plugin bellow


Code: Select all
from math import *
from random import *
import sublime, sublimeplugin

class MiniPyCommand(sublimeplugin.TextCommand):
   def run(self, view, args):
      script = ""
      for region in view.sel():
         script = view.substr(region)
         view.replace(region, str(eval(script)))
     
   def isEnabled(self, view, args):
      return True


and binding:
Code: Select all
<binding key="ctrl+e" command="miniPy"/>


so, just ctrl+e on a selected text, and tada! THANKS EJ12N !!!

anyway, i write this here because of my limited python knowledge. i thought it would be really nice if i could do something like:

Code: Select all
$x=0
$x++
$x++
...


or

Code: Select all
$x = "a."
$x".my_class"


etc. any idea how to implement it? if at all?

to be clear i want use variables which will be alive on this mini program, i chose to mark it with $ but that just an idea

ideas/help will be appreciated :)

vim.
Last edited by vim on Mon Jun 15, 2009 9:17 pm, edited 1 time in total.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: MiniPy - followup on EJ12N

Postby EJ12N on Mon Jun 15, 2009 6:01 pm

Nice :D

BTW Guys just to make it clear, all of these customizations you see on my screencasts WILL BE available in the repository, soon... I just keep commenting stuff and making it "public" friendly so at least you guys know what do with it...
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: MiniPy - followup on EJ12N

Postby tgkeul on Mon Jun 15, 2009 6:22 pm

@EJ12N: this day will be like christmas...
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: MiniPy - followup on EJ12N

Postby vim on Mon Jun 15, 2009 8:33 pm

this what i been able to do:
Code: Select all
from math import *
from random import *
import re
import sublime, sublimeplugin

class MiniPyCommand(sublimeplugin.TextCommand):
   def run(self, view, args):
      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 = range(1,total+1)
      serial_number.reverse()
     
      print str(serial_number)
     
      # replace each special char $ with the next index from serial_number list
      # and eval the expression
      for region in view.sel():
         script = view.substr(region)
         for n in range(script.count("$")):
            script = re.sub(r"\$", str(serial_number.pop()), script, 1)
         view.replace(region, str(eval(script)))
     
   def isEnabled(self, view, args):
      return True



so if you mark the column with the $ sign on the bottom code, and press ctrl+e
Code: Select all
arr[$]
arr[$]
arr[$]
arr[$]


it will result with
Code: Select all
arr[0]
arr[1]
arr[2]
arr[3]


or mark (and split to lines with ctrl+shift+L):
Code: Select all
$+$+$
$+$
$


will result:
Code: Select all
6 # the sum of 1+2+3
9 # the sum of 4+5
6 # the 6th $ char is single


:shock:

of course those will work too:
Code: Select all
random()
sin(1.2)
1+2+3
34*5.5
"x" * 10
len("abracatabra")


result:
Code: Select all
0.409628710502
0.932039085967
6
187.0
xxxxxxxxxx
11
Last edited by vim on Mon Jun 15, 2009 9:15 pm, edited 2 times in total.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: MiniPy - followup on EJ12N

Postby EJ12N on Mon Jun 15, 2009 8:54 pm

tgkeul wrote:@EJ12N: this day will be like christmas...

No, lol closer than you might actually think ;)
You pretty much got it there vim! That's what I got, an eval on selected text.
Good job :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 5 guests