[patch] lnum member of getbufinfo()

53 views
Skip to first unread message

Ken Takata

unread,
Jan 3, 2017, 4:23:47 AM1/3/17
to vim_dev
Hi,

The lnum member of getbufinfo() for the current buffer looks strange for me.
E.g.:

Open a new buffer and input some lines.
Move the cursor to line 5, then execute the following:
:echo getbufinfo('%')[0].lnum
1
I expect 5 for this (as same as :ls).

The following patch fixes this:

--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3979,7 +3979,8 @@ get_buffer_info(buf_T *buf)
dict_add_nr_str(dict, "bufnr", buf->b_fnum, NULL);
dict_add_nr_str(dict, "name", 0L,
buf->b_ffname != NULL ? buf->b_ffname : (char_u *)"");
- dict_add_nr_str(dict, "lnum", buflist_findlnum(buf), NULL);
+ dict_add_nr_str(dict, "lnum", buf == curbuf ? curwin->w_cursor.lnum
+ : buflist_findlnum(buf), NULL);
dict_add_nr_str(dict, "loaded", buf->b_ml.ml_mfp != NULL, NULL);
dict_add_nr_str(dict, "listed", buf->b_p_bl, NULL);
dict_add_nr_str(dict, "changed", bufIsChanged(buf), NULL);

This part is copied from the implementation of `:ls`.

Regards,
Ken Takata

Bram Moolenaar

unread,
Jan 6, 2017, 7:52:30 AM1/6/17
to vim...@googlegroups.com, Ken Takata
Thanks. Should be able to test this in src/testdir/test_bufwintabinfo.vim

--
hundred-and-one symptoms of being an internet addict:
192. Your boss asks you to "go fer" coffee and you come up with 235 FTP sites.

/// 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 ///
Reply all
Reply to author
Forward
0 new messages