0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

Add 'relativenumber' patch from Markus Heidelberg.

This commit is contained in:
Bram Moolenaar
2010-05-16 15:46:46 +02:00
parent 13c4c5da67
commit 64486671c3
22 changed files with 204 additions and 62 deletions

View File

@@ -468,6 +468,57 @@ decl(lp)
return r;
}
/*
* Get the line number relative to the current cursor position, i.e. the
* difference between line number and cursor position. Only look for lines that
* can be visible, folded lines don't count.
*/
linenr_T
get_cursor_rel_lnum(wp, lnum)
win_T *wp;
linenr_T lnum; /* line number to get the result for */
{
linenr_T cursor = wp->w_cursor.lnum;
linenr_T retval = 0;
#ifdef FEAT_FOLDING
if (hasAnyFolding(wp))
{
if (lnum > cursor)
{
while (lnum > cursor)
{
(void)hasFolding(lnum, &lnum, NULL);
/* if lnum and cursor are in the same fold,
* now lnum <= cursor */
if (lnum > cursor)
retval++;
lnum--;
}
}
else if (lnum < cursor)
{
while (lnum < cursor)
{
(void)hasFolding(lnum, NULL, &lnum);
/* if lnum and cursor are in the same fold,
* now lnum >= cursor */
if (lnum < cursor)
retval--;
lnum++;
}
}
/* else if (lnum == cursor)
* retval = 0;
*/
}
else
#endif
retval = lnum - cursor;
return retval;
}
/*
* Make sure curwin->w_cursor.lnum is valid.
*/