aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/memline.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2018-11-02 08:36:38 +0100
committerGitHub <noreply@github.com>2018-11-02 08:36:38 +0100
commit48398d61e422f74db4fa5c2e279692dd97347f41 (patch)
treeef7e2f51195c6a5a1a5f7a210290b43868c4d3c8 /src/nvim/memline.c
parentc45a859171090746c8b81f183474c22e489b8ad0 (diff)
parentc40f992e10355edd586d5cfbca246b9659554438 (diff)
downloadrneovim-48398d61e422f74db4fa5c2e279692dd97347f41.tar.gz
rneovim-48398d61e422f74db4fa5c2e279692dd97347f41.tar.bz2
rneovim-48398d61e422f74db4fa5c2e279692dd97347f41.zip
Merge pull request #9183 from bfredl/offset2
api: make nvim_buf_get_offset independent on platform option
Diffstat (limited to 'src/nvim/memline.c')
-rw-r--r--src/nvim/memline.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index aad1750c85..95f3b0c623 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -3850,13 +3850,17 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
ml_upd_lastcurix = curix;
}
-/*
- * Find offset for line or line with offset.
- * Find line with offset if "lnum" is 0; return remaining offset in offp
- * Find offset of line if "lnum" > 0
- * return -1 if information is not available
- */
-long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
+/// Find offset for line or line with offset.
+///
+/// @param buf buffer to use
+/// @param lnum if > 0, find offset of lnum, store offset in offp
+/// if == 0, return line with offset *offp
+/// @param offp Location where offset of line is stored, or to read offset to
+/// use to find line. In the later case, store remaining offset.
+/// @param no_ff ignore 'fileformat' option, always use one byte for NL.
+///
+/// @return -1 if information is not available
+long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
{
linenr_T curline;
int curix;
@@ -3869,7 +3873,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
int text_end;
long offset;
int len;
- int ffdos = (get_fileformat(buf) == EOL_DOS);
+ int ffdos = !no_ff && (get_fileformat(buf) == EOL_DOS);
int extra = 0;
/* take care of cached line first */
@@ -3983,7 +3987,7 @@ void goto_byte(long cnt)
if (boff) {
boff--;
}
- lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff);
+ lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff, false);
if (lnum < 1) { // past the end
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
curwin->w_curswant = MAXCOL;