Update : Matrixify now on Sublime Package Control.
Matrixify gets it's first update .. Oh Yeah !! :P , Seriously just a little update. I am new to Python and Sublime Text 2 plugins development but I used enough plugins to make me have the hunch that the method I'm using to read the format is not the genius one !!
I am lazy to look for solution so I asked on the ST2 forum and facelessuser answered : Sublime have an input form that prompt so it's a logical choice.
Another thing that come up is the indexes that I used for my arrays to output the matrix become much easier to calculate when the lines 0 is included.
output += separators[i%dim] + line + (lengths[(i%dim)] - len(line))*" " if (i%dim) == dim-1: output += separators[dim] + "\n"
The full new code using show_input_panel :
import sublime, sublime_plugin class MatrixifyCommand(sublime_plugin.TextCommand): def run(self, edit): def on_done(input): sels = self.view.sel() for sel in sels: lines = [] separators = [] lengths = [] dim = 0 lines = self.view.substr(sel) lines = lines.splitlines() lines = filter(None, lines) lines = [i.strip() for i in lines] separators = input.split('%') dim = len(separators) - 1 lengths = [0] * dim for i in range(dim): for l in range(i,len(lines)-1,dim): lengths[i] = max(lengths[i] , len(lines[l])) output = "" for i in range(0,len(lines)): line = lines[i] output += separators[i%dim] + line + (lengths[(i%dim)] - len(line))*" " if (i%dim) == dim-1: output += separators[dim] + "\n" self.view.replace(edit, sel, output) self.view.window().show_input_panel("Enter matrix format", "", on_done, None, None)
Repository on github try it , fork it , develop it.
No comments:
Post a Comment