Thursday, June 28, 2012

Re: Ensuring unique sign IDs

Ben Fritz wrote:
> On Wednesday, June 27, 2012 3:17:07 PM UTC-5, Charles Campbell wrote:
>
>> Ben Fritz wrote:
>>
>>> :help :sign-place says:
>>>
>>> It's up to the user to make sure the {id} is used only once in
>>> each file (if it's used several times unplacing will also have
>>> to be done several times and making changes may not work as
>>> expected).
>>>
>>> While it is easy enough to ensure that any one given plugin does not
>>> re-use signs, what is a good way to ensure that multiple plugins don't use
>>> overlapping signs?
>>>
>>> I can check the redirected output of :sign place buffer={buffer number}
>>> before I place any signs, but I'd guess not all plugin authors do this, so
>>> they could clobber my signs fairly easily.
>>>
>>> Is this the recommended approach or is the problem mostly ignored?
>>>
>>>
>>>
>> May I suggest looking into my RltvNmbr plugin
>> (http://www.drchip.org/astronaut/vim/index.html#RLTVNMBR) and glancing
>> at its "s:AvoidOtherSigns()" function.
>>
>>
> Well, at least I know YOUR plugins won't clobber my signs :-)
>
There's no guarantee that some plugin won't clobber signs, that's true.
> It looks like s:AvoidOtherSigns finds the max sign ID currently in use and starts there. That should work fairly well.
>
I haven't had any problems with it (crossing fingers, etc etc). Usually
I know how many signs my plugin will be using and so I want a block of
them. Gdbmgr also uses the max-sign-in-use plus one approach.
> The solution I ended up with, was to start at a sign ID equal to the return value of localtime(), and then whenever I define a new sign, check to see if the new ID I'm defining is already in use, and add 1 until I have one that is not.
>
Looks like you have a different sort of problem than I -- in that you
need to set up an indeterminate qty of signs (rather than a known qty of
them). However, perhaps you could still use my max-sign-id approach,
and wouldn't need to check each new sign for conflict. I'd be curious
about the speed differences.

Actually, gdbmgr has a similar indeterminate-qty-of-signs issue, too,
come to think of it. Users may assign any number of breakpoints (which
I indicate with signs), remove them, etc. I suppose that there could be
a problem if the user of gdbmgr applied some other sign-generating
plugin while gdbmgr is in-use. Perhaps I'll have to do like you and
check each new sign for conflict.
> I haven't release the plugin yet because I will need to patch the Vim source first; it's a plugin for manual diff alignment, but it depends on messing with the output of diff in the diffexpr, and Vim fails to parse the result because even though it follows the correct format, it doesn't match certain assumptions about things diff will output.
>
>
Sounds interesting!

Regards,
Chip Campbell


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment