RFC: Function to get the list of marks (getmarks)

24 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Sep 18, 2019, 11:18:39 AM9/18/19
to vim_dev
Hi all,

Currently the following Vim built-in functions are available to get
information about individual marks: getpos(), line() and col().

But we don't have a function to get the list of marks placed in a
buffer or the list of global marks (similar to the list displayed by
the :marks command).

What do you think about adding a getmarks() function that returns
the list of global marks or the list of marks placed in a buffer?

Thanks,
Yegappan

Andy Wokula

unread,
Sep 18, 2019, 11:47:11 AM9/18/19
to vim...@googlegroups.com
What do you mean by "a buffer" -- "the current buffer" or "any given buffer"?

Getting global marks or marks of the current buffer is trivial

:echo filter(split('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '\m'), 'line("''". v:val) >= 1')
:echo filter(split('abcdefghijklmnopqrstuvwxyz', '\m'), 'line("''". v:val) >= 1')
" (some other special marks omitted)

but I wouldn't know how to get marks from any given buffer without
making that buffer current. Anyway I'm not sure if I ever asked for
the local marks of a non-current buffer.

--
Andy

Yegappan Lakshmanan

unread,
Sep 18, 2019, 12:02:54 PM9/18/19
to vim_dev
Hi,

On Wed, Sep 18, 2019 at 8:47 AM 'Andy Wokula' via vim_dev
<vim...@googlegroups.com> wrote:
>
> Am 18.09.2019 um 17:18 schrieb Yegappan Lakshmanan:
> > Hi all,
> >
> > Currently the following Vim built-in functions are available to get
> > information about individual marks: getpos(), line() and col().
> >
> > But we don't have a function to get the list of marks placed in a
> > buffer or the list of global marks (similar to the list displayed by
> > the :marks command).
> >
> > What do you think about adding a getmarks() function that returns
> > the list of global marks or the list of marks placed in a buffer?
>
> What do you mean by "a buffer" -- "the current buffer" or "any given buffer"?
>

This function will return the local marks for any given buffer.

- Yegappan

Bram Moolenaar

unread,
Sep 19, 2019, 3:28:21 PM9/19/19
to vim...@googlegroups.com, Yegappan Lakshmanan
One can loop over all the mark names to get all the values. When would
it be useful to get the whole list?

If anybody would want to get marks for a buffer that is not in a window
we could add an optional argument to getpos(). But I don't recall
anyone asking for this.

--
GALAHAD: No look, really, this isn't nescess ...
PIGLET: We must examine you.
GALAHAD: There's nothing wrong with ... that.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// 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 ///

Yegappan Lakshmanan

unread,
Sep 19, 2019, 4:23:54 PM9/19/19
to Bram Moolenaar, vim_dev
Hi Bram,

On Thu, Sep 19, 2019 at 12:28 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
> Yegappan wrote:
>
> > Currently the following Vim built-in functions are available to get
> > information about individual marks: getpos(), line() and col().
> >
> > But we don't have a function to get the list of marks placed in a
> > buffer or the list of global marks (similar to the list displayed by
> > the :marks command).
> >
> > What do you think about adding a getmarks() function that returns
> > the list of global marks or the list of marks placed in a buffer?
>
> One can loop over all the mark names to get all the values. When would
> it be useful to get the whole list?
>
> If anybody would want to get marks for a buffer that is not in a window
> we could add an optional argument to getpos(). But I don't recall
> anyone asking for this.
>

This feature request came up in the "Support for plugin authors needs to be
improved (poll) #3573" last year:

https://github.com/vim/vim/issues/3573

In addition to this, the discussion also centered around adding support for
user-specified custom marks from a plugin.

- Yegappan

Bram Moolenaar

unread,
Sep 20, 2019, 8:22:26 AM9/20/19
to vim...@googlegroups.com, Yegappan Lakshmanan
That has been implemented with text properties. You can use an
invisible text property, it will stick to the text. Also when
characters are inserted/deleted. Marks only keep the line.

--
GALAHAD: No, please. Please! I can defeat them! There's only a hundred.
GIRLS: He will beat us easily. We haven't a chance.
Reply all
Reply to author
Forward
0 new messages