Sublime Forum

My very first plugin - add numbers to selections

#1

Ohai guys! I just created my very first plugin (for which i’ll write more chars in description).

So, what does it do?

Every now and then I need to do a multiselection and add a counter to each selection. Something similar with div>{$} in emmet/zen.

So, i had no idea if there is a plugin out there for this and i started to write my own.

https://gist.github.com/iamntz/5546478

All you have to do is to add multi_select_numbers into your keymap file. That’s it! Now, whenever you press your key combination near to a # sign, it will replace it with a number.

Thoughts?

preview:
(http://img.iamntz.com/jing/2012-11-28_1037.swf)

0 Likes

Little help with show_input_panel
#2

Great work! but…

… there is a plugin for this: https://github.com/duydao/Text-Pastry

0 Likes

#3

Yeah, but mine is better. You know, 'cause it’s mine! :mrgreen:

0 Likes

#4

exactly :smile:

welcome to the dark side. careful, it’s addictive …

0 Likes

#5

Thanks. It’s pretty cold on this side :frowning:

0 Likes

#6

Yeah, it can be tough to tell the reception of people on the forums. People don’t often post unless they have issues. Occasionally, there are some nice people who like to give kind words though. I am sure there are people trying it out though. I intend to give it a try when I get a chance.

For instance, my two most popular plugins are BracketHighlighter and HexViewer. BracketHighlighter is honestly the one I hear the most about. Being number 2 you would think I would good amount about about HexViewer…but I don’t, it works, so there is nothing to complain about, there aren’t really many more features you can request on it, I haven’t had to fix a bug in it for a very long time, and it is not a plugin that is universally used. Lots of people like highlighting brackets, only a few need to look at hex files. A lot of my plugins are niche plugins, unless you have a specific use for that functionality, or realize there might be a better way to do what you already do, you probably don’t need them. Not everyone needs a hex viewer/editor…but as an embedded programmer, I use it a lot.

I always write stuff I like and am interested in and will personally use, that way if no one wants to use it, I am still happy.

0 Likes

#7

@iamntz it would be nice if your plugin prompted for starting number and also maybe frequency (like by twos, by tens, etc.).

Currently it is only useful if you are starting a new list that starts from 1 and goes by ones.

I would just open an input panel and have the user enter that info. Like 30:10 would start at 30 and increment numbers by 10. If one isn’t provided, I guess you could default it. But then you could also add support for lists that decrements opposed to increment. Add support for floats, hex, etc.

There is a lot you can do to make this really useful.

0 Likes

#8

@faceless:
I think you understood that this:

It’s because i didn’t got any feedback. When in fact, it was because there is silence on the „plugins announcement” section (and on forum, in general) lately.

I didn’t really expected that anyone could find this useful or that i’ll get any feedback. But… i was wrong. I received feedback and ideas. Thanks!

(ps: feels funny - in a totally good way - to me to get feedback from users like you & castles :mrgreen: )

0 Likes

#9

[quote=“iamntz”]@faceless:
I think you understood that this:

It’s because i didn’t got any feedback. When in fact, it was because there is silence on the „plugins announcement” section (and on forum, in general) lately.

I didn’t really expected that anyone could find this useful or that i’ll get any feedback. But… i was wrong. I received feedback and ideas. Thanks!

(ps: feels funny - in a totally good way - to me to get feedback from users like you & castles :mrgreen: )[/quote]

Yeah, it is nice to get feedback. It helps you make good decisions early on how people actually might use things. I often need it to help sort out intuitiveness as well; what seems intuitive to me, sometimes is quite convoluted to others, it is nice to get those kinds of things cleared up early before you invest a lot of code into it.

I wrote a tool once and got no feedback after many many meetings throughout development. And when it finally got released, a flood of complaints (everyone knew it would impact them, but no one bothered to try it throughout the entire development)…I was so annoyed.

0 Likes

#10

Hehe, just added your suggestion: a pattern to follow on counting numbers!

pretty addictive stuff :geek:

0 Likes

#11

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?

0 Likes

#12

Well, i initially had this used for html. So i had some and some 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?

0 Likes

#13

[quote=“iamntz”]Well, i initially had this used for html. So i had some and some 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?[/quote]

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.

0 Likes

#14

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 :open_mouth:

0 Likes

#15

[quote=“iamntz”]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 :open_mouth:[/quote]

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

padding with zeros is easy.

>>> print "%03d" % 3 003

0 Likes

#16

Boom.

0 Likes

#17

Obviously, mine is better and yours it sucks! :smiling_imp: :mrgreen:

0 Likes

#18

Please update this plugin to work in Sublime Text 3 :unamused:

0 Likes

#19

@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):

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:

window.show_input_panel('Count Start:Step', '1:1', countThoseSelections, False, False)

And just call

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 :smile:

0 Likes

#20

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).

0 Likes