[patch] exists() tests for sign-ids

62 views
Skip to first unread message

Christian Brabandt

unread,
Jan 26, 2013, 10:22:07 AM1/26/13
to vim...@vim.org
Bram,
this patch adds the possibility to query for the existence of sign ids
using exists().

Current idea is to use exists('#number') to check for the numeric id
(and thus it can't be an autocommand).

regards,
Christian
--
sign_exists.diff

ZyX

unread,
Jan 26, 2013, 10:34:17 AM1/26/13
to vim...@googlegroups.com, vim...@vim.org, cbl...@256bit.org
> this patch adds the possibility to query for the existence of sign ids
> using exists().
>
> Current idea is to use exists('#number') to check for the numeric id
> (and thus it can't be an autocommand).

I don’t like the overloading: exists('#…') is already ambigious*, don’t make it more ambigious: it *can* be an autocmd group. I would rather suggest “>N” for place ids and reserve “>>name” for defined sign names.

* “#abc” can mean “augroup” or “event”, same for “#abc#pattern”. Also note that autocmd group name can contain a hash (and even a space which prevents using it in :doau). Thus there is no way to check whether random autocmd group is defined using “exists()” (“#abc#def” is always “#event_or_group#pattern”).

Ingo Karkat

unread,
Jan 26, 2013, 10:45:24 AM1/26/13
to vim...@googlegroups.com
On 26-Jan-13 16:34:17 +0100, ZyX wrote:

>> this patch adds the possibility to query for the existence of sign
>> ids using exists().
>>
>> Current idea is to use exists('#number') to check for the numeric id
>> (and thus it can't be an autocommand).
>
> I don�t like the overloading: exists('#�') is already ambigious*, don�
> t make it more ambigious: it *can* be an autocmd group. I would rather
> suggest �>N� for place ids and reserve �>>name� for defined sign
> names.
>
> * �#abc� can mean �augroup� or �event�, same for �#abc#pattern�. Also
> note that autocmd group name can contain a hash (and even a space
> which prevents using it in :doau). Thus there is no way to check
> whether random autocmd group is defined using �exists()� (�#abc#def�
> is always �#event_or_group#pattern�).

Yes, this is complex enough already. The sign stuff is lacking good Vimscript
support in general (one needs to resort to capture and parse :sign output with
:redir), as exemplified by this Stack Overflow question:

http://stackoverflow.com/questions/14502710/query-position-of-sign-in-vim-with-sign-id

Maybe we should add an entire Vimscript API (i.e. sign...() functions), and
handle this there?!

-- regards, ingo

Christian Brabandt

unread,
Jan 26, 2013, 4:35:22 PM1/26/13
to vim...@googlegroups.com
Hi Ingo!

On Sa, 26 Jan 2013, Ingo Karkat wrote:

> On 26-Jan-13 16:34:17 +0100, ZyX wrote:
>
> >> this patch adds the possibility to query for the existence of sign
> >> ids using exists().
> >>
> >> Current idea is to use exists('#number') to check for the numeric id
> >> (and thus it can't be an autocommand).
> >
> > I don’t like the overloading: exists('#…') is already ambigious*, don’
> > t make it more ambigious: it *can* be an autocmd group. I would rather
> > suggest “>N” for place ids and reserve “>>name” for defined sign
> > names.
> >
> > * “#abc” can mean “augroup” or “event”, same for “#abc#pattern”. Also
> > note that autocmd group name can contain a hash (and even a space
> > which prevents using it in :doau). Thus there is no way to check
> > whether random autocmd group is defined using “exists()” (“#abc#def”
> > is always “#event_or_group#pattern”).

ok.
>
> Yes, this is complex enough already. The sign stuff is lacking good Vimscript
> support in general (one needs to resort to capture and parse :sign output with
> :redir), as exemplified by this Stack Overflow question:
>
> http://stackoverflow.com/questions/14502710/query-position-of-sign-in-vim-with-sign-id
>
> Maybe we should add an entire Vimscript API (i.e. sign...() functions), and
> handle this there?!

What would be needed?

The following patch adds:
- exists('|nr')
returns true, if sign id nr exists
- exists('||name')
returns true, if sign name has been defined
- line('|nr')
returns the line number of sign id nr
- getsign('lnum')
returns the Sign id at line lnum in the current buffer

Anything else would be needed?

regards,
Christian
--
Der größte Sinnengenuß, der gar keine Beimischung von Ekel bei sich
führt, ist, im gesunden Zustande, Ruhe nach der Arbeit.
-- Immanuel Kant
sign_functions.diff

Ingo Karkat

unread,
Jan 26, 2013, 5:25:04 PM1/26/13
to vim...@googlegroups.com
On 26-Jan-13 22:35:22 +0100, Christian Brabandt wrote:

> Hi Ingo!
>
> On Sa, 26 Jan 2013, Ingo Karkat wrote:
>
>> On 26-Jan-13 16:34:17 +0100, ZyX wrote:
>>
>>>> this patch adds the possibility to query for the existence of sign
>>>> ids using exists().
>>>>
>>>> Current idea is to use exists('#number') to check for the numeric id
>>>> (and thus it can't be an autocommand).
>>>
>>> I don�t like the overloading: exists('#�') is already ambigious*, don�
>>> t make it more ambigious: it *can* be an autocmd group. I would rather
>>> suggest �>N� for place ids and reserve �>>name� for defined sign
>>> names.
>>>
>>> * �#abc� can mean �augroup� or �event�, same for �#abc#pattern�. Also
>>> note that autocmd group name can contain a hash (and even a space
>>> which prevents using it in :doau). Thus there is no way to check
>>> whether random autocmd group is defined using �exists()� (�#abc#def�
>>> is always �#event_or_group#pattern�).
>
> ok.
>>
>> Yes, this is complex enough already. The sign stuff is lacking good Vimscript
>> support in general (one needs to resort to capture and parse :sign output with
>> :redir), as exemplified by this Stack Overflow question:
>>
>> http://stackoverflow.com/questions/14502710/query-position-of-sign-in-vim-with-sign-id
>>
>> Maybe we should add an entire Vimscript API (i.e. sign...() functions), and
>> handle this there?!
>
> What would be needed?
>
> The following patch adds:
> - exists('|nr')
> returns true, if sign id nr exists
> - exists('||name')
> returns true, if sign name has been defined
> - line('|nr')
> returns the line number of sign id nr
> - getsign('lnum')
> returns the Sign id at line lnum in the current buffer
>
> Anything else would be needed?

Wow, terrific. Though it's hard to make the connection between the "|" sigil and
signs, it is consistent and short. This addresses the mentioned question; I
can't think of anything else (though I haven't used signs that much myself yet).

Thank you for volunteering your Saturday evening :-)

-- regards, ingo

Christian Brabandt

unread,
Jan 26, 2013, 5:31:37 PM1/26/13
to vim...@googlegroups.com
Hi Ingo!

On Sa, 26 Jan 2013, Ingo Karkat wrote:

> Thank you for volunteering your Saturday evening :-)

What else can you do, when "Dschungelcamp"� is on TV? ;)

http://en.wikipedia.org/wiki/Ich_bin_ein_Star_%E2%80%93_Holt_mich_hier_raus!

regards,
Christian

Christian Brabandt

unread,
Jan 27, 2013, 8:57:35 AM1/27/13
to vim...@googlegroups.com
Hi,

Here is an update.

I wrote:
> The following patch adds:
> - exists('|nr')
> returns true, if sign id nr exists
> - exists('||name')
> returns true, if sign name has been defined
> - line('|nr')
> returns the line number of sign id nr
> - getsign('lnum')
> returns the Sign id at line lnum in the current buffer
- getsign('lnum')
returns a list of all placed sign ids in line lnum in the
current buffer
-getsign()
returns a list of all placed sign ids in the current buffer

Also this patch compiles for non-sign builds (which the previous patch
did not because of a missing #ifdef).

regards,
Christian
--
sign_functions.diff

Bram Moolenaar

unread,
Jan 27, 2013, 9:22:11 AM1/27/13
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

> Bram,
> this patch adds the possibility to query for the existence of sign ids
> using exists().
>
> Current idea is to use exists('#number') to check for the numeric id
> (and thus it can't be an autocommand).

Is this superceded by the other patch for sign support?

--
The question is: What do you do with your life?
The wrong answer is: Become the richest guy in the graveyard.
(billionaire and Oracle founder Larry Ellison)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Jan 27, 2013, 9:27:42 AM1/27/13
to vim...@vim.org
Hi Bram!

On So, 27 Jan 2013, Bram Moolenaar wrote:

>
> Christian Brabandt wrote:
>
> > Bram,
> > this patch adds the possibility to query for the existence of sign ids
> > using exists().
> >
> > Current idea is to use exists('#number') to check for the numeric id
> > (and thus it can't be an autocommand).
>
> Is this superceded by the other patch for sign support?

Yes

regards,
Christian
--
Es gibt Frauen, die Darwin falsch verstanden haben: Sie machen aus
jedem Mann einen Affen.
-- Carola H�hn
Reply all
Reply to author
Forward
0 new messages