[vim/vim] off by one error in column position of "getmarklist()" (#6173)

6 views
Skip to first unread message

lacygoill

unread,
May 31, 2020, 7:16:58 PM5/31/20
to vim/vim, Subscribed

Describe the bug

The column position of a mark as reported by getmarklist() is off by one.

To Reproduce

Run this shell command:

vim -Nu NONE -i NONE +"sil pu!=['abc', 'def', 'ghi']" +'norm! 2G3|mm1G1|' +'call getmarklist(bufnr("%"))->filter({_,v -> v.mark =~# ".m"})[0].pos->setpos(".")'

This populates a buffer with the text:

abc
def
ghi

Then, it sets the mark m on the character f (third character on second line), and moves the cursor back on the the character a (first character on first line). Finally, it invokes getmarklist() to retrieve the position of the mark m and setpos() to restore the cursor where the mark was set originally (i.e. on the character f).

The cursor is positioned on the character e.

Expected behavior

The cursor is positioned on the character f.

Environment

  • Vim version: 8.2 Included patches: 1-869
  • OS: Ubuntu 16.04.6 LTS
  • Terminal: XTerm(322)

Additional context

According to :h getmarklist(), the pos key should have the same meaning as for getpos():

pos - a |List| with the position of the mark:
[bufnum, lnum, col, off]
Refer to |getpos()| for more information.

If that's the case, then we should be able to restore the cursor position without having to apply a positive offset on the column number.


Unrelated to this issue, but I've also noticed that getmarklist() can't be used as a method contrary to the similar functions getjumplist() and getchangelist(). Let me know if you want me to open a new issue for that too.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
May 31, 2020, 7:22:52 PM5/31/20
to vim/vim, Subscribed

To summarize, getmarklist() starts indexing the column positions from the index 0, while getpos() starts from 1, which seems inconsistent.

Yegappan Lakshmanan

unread,
May 31, 2020, 8:44:08 PM5/31/20
to vim_dev, reply+ACY5DGFX2LWOJ2ZKET...@reply.github.com, vim/vim, Subscribed
Hi,

On Sun, May 31, 2020 at 4:22 PM lacygoill <vim-dev...@256bit.org> wrote:

To summarize, getmarklist() starts indexing the column positions from the index 0, while getpos() starts from 1, which seems inconsistent.



Thanks for reporting this issue. I have created the following PR to address this.


- Yegappan
 

vim-dev ML

unread,
May 31, 2020, 8:44:25 PM5/31/20
to vim/vim, vim-dev ML, Your activity

Bram Moolenaar

unread,
Jun 1, 2020, 8:24:47 AM6/1/20
to vim/vim, vim-dev ML, Comment

Fixed by 8.2.0871.


You are receiving this because you commented.

Bram Moolenaar

unread,
Jun 1, 2020, 8:24:48 AM6/1/20
to vim/vim, vim-dev ML, Comment

Closed #6173.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages