Home Download Buy Blog Forum Support

My very first plugin - add numbers to selections

Re: My very first plugin - add numbers to selections

Postby facelessuser on Fri Nov 30, 2012 7:31 am

Cool, I will give it a try. One other question, why the requirement for the '#'? Why not just implement it on all selections when invoked?
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: My very first plugin - add numbers to selections

Postby iamntz on Fri Nov 30, 2012 8:11 am

Well, i initially had this used for html. So i had some <a href="#"> and some <a href="real_url"> and needed to change # to #page-X. Easier to select all href then move 2 chars to right and... that's it.

If i didn't had # required, i had no way of making only some of the selections counted. Make sense?
iamntz
 
Posts: 917
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: My very first plugin - add numbers to selections

Postby facelessuser on Fri Nov 30, 2012 3:40 pm

iamntz wrote:Well, i initially had this used for html. So i had some <a href="#"> and some <a href="real_url"> and needed to change # to #page-X. Easier to select all href then move 2 chars to right and... that's it.

If i didn't had # required, i had no way of making only some of the selections counted. Make sense?


Makes sense...I guess anytime I am about to do a multi-select command, I only have multi-selected what I intend to modify. Requiring the number is very specific to your particular case. If this were applied to anything but href="#", it would require the user to type "#", then execute the command...

So if this plugin is geared specifically to the href scenario, then it is probably fine, if it is meant to be more general purpose, I would suggest removing the "#" requirement. It all depends how it is intended to be used.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: My very first plugin - add numbers to selections

Postby iamntz on Fri Nov 30, 2012 4:50 pm

Well, having it as a text, i guess it's easy to remove the condition :mrgreen:

Another reason for having # is that initially i was thinking to have patterns like:
- if there is only one # the count goes „natural” (1, 2, 3)
- if there are like ### the count goes this way: 001, 002, ... 010, 011 and so on.

I stumbled a little and i didn't knew how to do that at that moment and i was happy enough with it. Not sure if i'll ever add this or not :shock:
iamntz
 
Posts: 917
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: My very first plugin - add numbers to selections

Postby facelessuser on Fri Nov 30, 2012 5:39 pm

iamntz wrote:Well, having it as a text, i guess it's easy to remove the condition :mrgreen:

Another reason for having # is that initially i was thinking to have patterns like:
- if there is only one # the count goes „natural” (1, 2, 3)
- if there are like ### the count goes this way: 001, 002, ... 010, 011 and so on.

I stumbled a little and i didn't knew how to do that at that moment and i was happy enough with it. Not sure if i'll ever add this or not :shock:

You can define your own syntax for the input panel to allow that kind of stuff.

padding with zeros is easy.

Code: Select all
>>> print "%03d" % 3
003
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: My very first plugin - add numbers to selections

Postby jbrooksuk on Mon Dec 03, 2012 10:31 am

jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: My very first plugin - add numbers to selections

Postby iamntz on Mon Dec 03, 2012 11:08 am

Boom.

Obviously, mine is better and yours it sucks! :twisted: :mrgreen:
iamntz
 
Posts: 917
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: My very first plugin - add numbers to selections

Postby Dimox on Thu May 09, 2013 9:15 am

Please update this plugin to work in Sublime Text 3 :roll:
Dimox
 
Posts: 2
Joined: Thu May 09, 2013 7:51 am

Re: My very first plugin - add numbers to selections

Postby iamntz on Thu May 09, 2013 10:00 am

@Dimox: As much as I'd like to get this fixed, I have no idea how to do this. I updated the code and fixed some stuff, but there is this error that i can't understand (nor have too much time to fix):

Code: Select all
Traceback (most recent call last):
  File "C:\Users\Ionut Staicu\AppData\Roaming\Sublime Text 3\Packages\User\add_number_to_multiselects.py", line 17, in countThoseSelections
    self.view.replace( edit, replaceRegion, str( region_index ) )
  File "C:\Program Files\Sublime Text 3\sublime.py", line 598, in replace
    raise ValueError("Edit objects may not be used after the TextCommand's run method has returned")
ValueError: Edit objects may not be used after the TextCommand's run method has returned


The weirdest part is that if i ditch this part:
Code: Select all
window.show_input_panel('Count Start:Step', '1:1', countThoseSelections, False, False)


And just call
Code: Select all
countThoseSelections('1:1')

it is working

I assume there is related new async stuff on ST3. When i'll get some spare time, i'll look into it, but don't hold your breath :)
iamntz
 
Posts: 917
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: My very first plugin - add numbers to selections

Postby bizoo on Fri May 10, 2013 10:02 am

My guess:
The edit object is invalidated when you exit the TextCommand, so unusable in the countThoseSelections callback.

In ST3 you couldn't create one by yourself, so you probably must:
Split your command in two command:
-one (the main, a WindowCommand) that ask for the parameters with show_input_panel and call the second command.
-one to do the job (a TextCommand).
bizoo
 
Posts: 888
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 8 guests