aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-05-28 10:47:25 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-05-28 10:47:58 -0400
commit3dddceedceebb73b93d399f2c56b0f1b5394c645 (patch)
treeed1d11dcde7c7eb64f9474ae1c8ef891757fd554 /src
parente4fe2dbd777a59a9a9b386d960eb9dddc459e84e (diff)
parent7e3681c32e4fd1e19c01ffe7286ea29aafb2efc4 (diff)
downloadrneovim-3dddceedceebb73b93d399f2c56b0f1b5394c645.tar.gz
rneovim-3dddceedceebb73b93d399f2c56b0f1b5394c645.tar.bz2
rneovim-3dddceedceebb73b93d399f2c56b0f1b5394c645.zip
Merge #674 'Extract cursor.h from misc{1,2}.h and memline.h'
Diffstat (limited to 'src')
-rw-r--r--src/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/api/buffer.c1
-rw-r--r--src/nvim/api/window.c1
-rw-r--r--src/nvim/buffer.c1
-rw-r--r--src/nvim/cursor.c467
-rw-r--r--src/nvim/cursor.h29
-rw-r--r--src/nvim/diff.c1
-rw-r--r--src/nvim/edit.c97
-rw-r--r--src/nvim/eval.c7
-rw-r--r--src/nvim/ex_cmds.c5
-rw-r--r--src/nvim/ex_docmd.c3
-rw-r--r--src/nvim/ex_getln.c3
-rw-r--r--src/nvim/farsi.c27
-rw-r--r--src/nvim/fileio.c1
-rw-r--r--src/nvim/fold.c1
-rw-r--r--src/nvim/getchar.c5
-rw-r--r--src/nvim/indent.c15
-rw-r--r--src/nvim/indent_c.c81
-rw-r--r--src/nvim/mbyte.c9
-rw-r--r--src/nvim/memline.c18
-rw-r--r--src/nvim/memline.h2
-rw-r--r--src/nvim/menu.c1
-rw-r--r--src/nvim/misc1.c32
-rw-r--r--src/nvim/misc1.h2
-rw-r--r--src/nvim/misc2.c447
-rw-r--r--src/nvim/misc2.h14
-rw-r--r--src/nvim/move.c3
-rw-r--r--src/nvim/normal.c48
-rw-r--r--src/nvim/ops.c37
-rw-r--r--src/nvim/option.c1
-rw-r--r--src/nvim/quickfix.c3
-rw-r--r--src/nvim/screen.c3
-rw-r--r--src/nvim/search.c21
-rw-r--r--src/nvim/spell.c11
-rw-r--r--src/nvim/tag.c1
-rw-r--r--src/nvim/ui.c1
-rw-r--r--src/nvim/undo.c1
-rw-r--r--src/nvim/window.c3
38 files changed, 719 insertions, 685 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index bdb262731d..b74832840c 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -36,6 +36,7 @@ file( GLOB API_PRIV_SOURCES api/private/*.c )
set(CONV_SRCS
api.c
arabic.c
+ cursor.c
garray.c
hashtab.c
memory.c
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index d2b4cafaac..332b7425d2 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -8,6 +8,7 @@
#include "nvim/api/private/defs.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
+#include "nvim/cursor.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 8bd8316477..60de6ea219 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -6,6 +6,7 @@
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/vim.h"
+#include "nvim/cursor.h"
#include "nvim/window.h"
#include "nvim/screen.h"
#include "nvim/misc2.h"
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 7c50b1721c..946053140d 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -30,6 +30,7 @@
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
new file mode 100644
index 0000000000..8f8bc60510
--- /dev/null
+++ b/src/nvim/cursor.c
@@ -0,0 +1,467 @@
+#include <stdbool.h>
+
+#include "nvim/cursor.h"
+#include "nvim/charset.h"
+#include "nvim/fold.h"
+#include "nvim/memline.h"
+#include "nvim/memory.h"
+#include "nvim/misc1.h"
+#include "nvim/move.h"
+#include "nvim/screen.h"
+#include "nvim/vim.h"
+
+static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol);
+
+/*
+ * Get the screen position of the cursor.
+ */
+int getviscol(void)
+{
+ colnr_T x;
+
+ getvvcol(curwin, &curwin->w_cursor, &x, NULL, NULL);
+ return (int)x;
+}
+
+/*
+ * Get the screen position of character col with a coladd in the cursor line.
+ */
+int getviscol2(colnr_T col, colnr_T coladd)
+{
+ colnr_T x;
+ pos_T pos;
+
+ pos.lnum = curwin->w_cursor.lnum;
+ pos.col = col;
+ pos.coladd = coladd;
+ getvvcol(curwin, &pos, &x, NULL, NULL);
+ return (int)x;
+}
+
+/*
+ * Go to column "wcol", and add/insert white space as necessary to get the
+ * cursor in that column.
+ * The caller must have saved the cursor line for undo!
+ */
+int coladvance_force(colnr_T wcol)
+{
+ int rc = coladvance2(&curwin->w_cursor, true, false, wcol);
+
+ if (wcol == MAXCOL) {
+ curwin->w_valid &= ~VALID_VIRTCOL;
+ } else {
+ /* Virtcol is valid */
+ curwin->w_valid |= VALID_VIRTCOL;
+ curwin->w_virtcol = wcol;
+ }
+ return rc;
+}
+
+/*
+ * Try to advance the Cursor to the specified screen column.
+ * If virtual editing: fine tune the cursor position.
+ * Note that all virtual positions off the end of a line should share
+ * a curwin->w_cursor.col value (n.b. this is equal to STRLEN(line)),
+ * beginning at coladd 0.
+ *
+ * return OK if desired column is reached, FAIL if not
+ */
+int coladvance(colnr_T wcol)
+{
+ int rc = getvpos(&curwin->w_cursor, wcol);
+
+ if (wcol == MAXCOL || rc == FAIL)
+ curwin->w_valid &= ~VALID_VIRTCOL;
+ else if (*get_cursor_pos_ptr() != TAB) {
+ /* Virtcol is valid when not on a TAB */
+ curwin->w_valid |= VALID_VIRTCOL;
+ curwin->w_virtcol = wcol;
+ }
+ return rc;
+}
+
+static int coladvance2(
+ pos_T *pos,
+ bool addspaces, /* change the text to achieve our goal? */
+ bool finetune, /* change char offset for the exact column */
+ colnr_T wcol /* column to move to */
+)
+{
+ int idx;
+ char_u *ptr;
+ char_u *line;
+ colnr_T col = 0;
+ int csize = 0;
+ int one_more;
+ int head = 0;
+
+ one_more = (State & INSERT)
+ || restart_edit != NUL
+ || (VIsual_active && *p_sel != 'o')
+ || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL);
+ line = ml_get_buf(curbuf, pos->lnum, false);
+
+ if (wcol >= MAXCOL) {
+ idx = (int)STRLEN(line) - 1 + one_more;
+ col = wcol;
+
+ if ((addspaces || finetune) && !VIsual_active) {
+ curwin->w_curswant = linetabsize(line) + one_more;
+ if (curwin->w_curswant > 0)
+ --curwin->w_curswant;
+ }
+ } else {
+ int width = W_WIDTH(curwin) - win_col_off(curwin);
+
+ if (finetune
+ && curwin->w_p_wrap
+ && curwin->w_width != 0
+ && wcol >= (colnr_T)width) {
+ csize = linetabsize(line);
+ if (csize > 0)
+ csize--;
+
+ if (wcol / width > (colnr_T)csize / width
+ && ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
+ /* In case of line wrapping don't move the cursor beyond the
+ * right screen edge. In Insert mode allow going just beyond
+ * the last character (like what happens when typing and
+ * reaching the right window edge). */
+ wcol = (csize / width + 1) * width - 1;
+ }
+ }
+
+ ptr = line;
+ while (col <= wcol && *ptr != NUL) {
+ /* Count a tab for what it's worth (if list mode not on) */
+ csize = win_lbr_chartabsize(curwin, ptr, col, &head);
+ mb_ptr_adv(ptr);
+ col += csize;
+ }
+ idx = (int)(ptr - line);
+ /*
+ * Handle all the special cases. The virtual_active() check
+ * is needed to ensure that a virtual position off the end of
+ * a line has the correct indexing. The one_more comparison
+ * replaces an explicit add of one_more later on.
+ */
+ if (col > wcol || (!virtual_active() && one_more == 0)) {
+ idx -= 1;
+ /* Don't count the chars from 'showbreak'. */
+ csize -= head;
+ col -= csize;
+ }
+
+ if (virtual_active()
+ && addspaces
+ && ((col != wcol && col != wcol + 1) || csize > 1)) {
+ /* 'virtualedit' is set: The difference between wcol and col is
+ * filled with spaces. */
+
+ if (line[idx] == NUL) {
+ /* Append spaces */
+ int correct = wcol - col;
+ char_u *newline = xmallocz((size_t)(idx + correct));
+ memcpy(newline, line, (size_t)idx);
+ memset(newline + idx, ' ', (size_t)correct);
+
+ ml_replace(pos->lnum, newline, false);
+ changed_bytes(pos->lnum, (colnr_T)idx);
+ idx += correct;
+ col = wcol;
+ } else {
+ /* Break a tab */
+ int linelen = (int)STRLEN(line);
+ int correct = wcol - col - csize + 1; /* negative!! */
+ char_u *newline;
+
+ if (-correct > csize)
+ return FAIL;
+
+ newline = xmallocz((size_t)(linelen - 1 + csize));
+ // Copy first idx chars
+ memcpy(newline, line, (size_t)idx);
+ // Replace idx'th char with csize spaces
+ memset(newline + idx, ' ', (size_t)csize);
+ // Copy the rest of the line
+ memcpy(newline + idx + csize, line + idx + 1,
+ (size_t)(linelen - idx - 1));
+
+ ml_replace(pos->lnum, newline, false);
+ changed_bytes(pos->lnum, idx);
+ idx += (csize - 1 + correct);
+ col += correct;
+ }
+ }
+ }
+
+ if (idx < 0)
+ pos->col = 0;
+ else
+ pos->col = idx;
+
+ pos->coladd = 0;
+
+ if (finetune) {
+ if (wcol == MAXCOL) {
+ /* The width of the last character is used to set coladd. */
+ if (!one_more) {
+ colnr_T scol, ecol;
+
+ getvcol(curwin, pos, &scol, NULL, &ecol);
+ pos->coladd = ecol - scol;
+ }
+ } else {
+ int b = (int)wcol - (int)col;
+
+ /* The difference between wcol and col is used to set coladd. */
+ if (b > 0 && b < (MAXCOL - 2 * W_WIDTH(curwin)))
+ pos->coladd = b;
+
+ col += b;
+ }
+ }
+
+ /* prevent from moving onto a trail byte */
+ if (has_mbyte)
+ mb_adjustpos(curbuf, pos);
+
+ if (col < wcol)
+ return FAIL;
+ return OK;
+}
+
+/*
+ * Return in "pos" the position of the cursor advanced to screen column "wcol".
+ * return OK if desired column is reached, FAIL if not
+ */
+int getvpos(pos_T *pos, colnr_T wcol)
+{
+ return coladvance2(pos, false, virtual_active(), wcol);
+}
+
+/*
+ * Increment the cursor position. See inc() for return values.
+ */
+int inc_cursor(void)
+{
+ return inc(&curwin->w_cursor);
+}
+
+/*
+ * dec(p)
+ *
+ * Decrement the line pointer 'p' crossing line boundaries as necessary.
+ * Return 1 when crossing a line, -1 when at start of file, 0 otherwise.
+ */
+int dec_cursor(void)
+{
+ return dec(&curwin->w_cursor);
+}
+
+/// 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.
+///
+/// @param lnum line number to get the result for
+linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)
+{
+ linenr_T cursor = wp->w_cursor.lnum;
+ if (lnum == cursor || !hasAnyFolding(wp)) {
+ return lnum - cursor;
+ }
+
+ linenr_T from_line = lnum < cursor ? lnum : cursor;
+ linenr_T to_line = lnum > cursor ? lnum : cursor;
+ linenr_T retval = 0;
+
+ // Loop until we reach to_line, skipping folds.
+ for (; from_line < to_line; from_line++, retval++) {
+ // If from_line is in a fold, set it to the last line of that fold.
+ hasFoldingWin(wp, from_line, NULL, &from_line, true, NULL);
+ }
+
+ // If to_line is in a closed fold, the line count is off by +1. Correct it.
+ if (from_line > to_line) {
+ retval--;
+ }
+
+ return (lnum < cursor) ? -retval : retval;
+}
+
+/*
+ * Make sure curwin->w_cursor.lnum is valid.
+ */
+void check_cursor_lnum(void)
+{
+ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
+ /* If there is a closed fold at the end of the file, put the cursor in
+ * its first line. Otherwise in the last line. */
+ if (!hasFolding(curbuf->b_ml.ml_line_count,
+ &curwin->w_cursor.lnum, NULL))
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
+ if (curwin->w_cursor.lnum <= 0)
+ curwin->w_cursor.lnum = 1;
+}
+
+/*
+ * Make sure curwin->w_cursor.col is valid.
+ */
+void check_cursor_col(void)
+{
+ check_cursor_col_win(curwin);
+}
+
+/*
+ * Make sure win->w_cursor.col is valid.
+ */
+void check_cursor_col_win(win_T *win)
+{
+ colnr_T len;
+ colnr_T oldcol = win->w_cursor.col;
+ colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
+
+ len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, false));
+ if (len == 0) {
+ win->w_cursor.col = 0;
+ } else if (win->w_cursor.col >= len) {
+ /* Allow cursor past end-of-line when:
+ * - in Insert mode or restarting Insert mode
+ * - in Visual mode and 'selection' isn't "old"
+ * - 'virtualedit' is set */
+ if ((State & INSERT) || restart_edit
+ || (VIsual_active && *p_sel != 'o')
+ || (ve_flags & VE_ONEMORE)
+ || virtual_active()) {
+ win->w_cursor.col = len;
+ } else {
+ win->w_cursor.col = len - 1;
+ /* Move the cursor to the head byte. */
+ if (has_mbyte)
+ mb_adjustpos(win->w_buffer, &win->w_cursor);
+ }
+ } else if (win->w_cursor.col < 0) {
+ win->w_cursor.col = 0;
+ }
+
+ /* If virtual editing is on, we can leave the cursor on the old position,
+ * only we must set it to virtual. But don't do it when at the end of the
+ * line. */
+ if (oldcol == MAXCOL)
+ win->w_cursor.coladd = 0;
+ else if (ve_flags == VE_ALL) {
+ if (oldcoladd > win->w_cursor.col)
+ win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
+ else
+ /* avoid weird number when there is a miscalculation or overflow */
+ win->w_cursor.coladd = 0;
+ }
+}
+
+/*
+ * make sure curwin->w_cursor in on a valid character
+ */
+void check_cursor(void)
+{
+ check_cursor_lnum();
+ check_cursor_col();
+}
+
+/*
+ * Make sure curwin->w_cursor is not on the NUL at the end of the line.
+ * Allow it when in Visual mode and 'selection' is not "old".
+ */
+void adjust_cursor_col(void)
+{
+ if (curwin->w_cursor.col > 0
+ && (!VIsual_active || *p_sel == 'o')
+ && gchar_cursor() == NUL)
+ --curwin->w_cursor.col;
+}
+
+/*
+ * When curwin->w_leftcol has changed, adjust the cursor position.
+ * Return true if the cursor was moved.
+ */
+bool leftcol_changed(void)
+{
+ // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long.
+ // Perhaps we can change p_siso to int.
+ int64_t lastcol;
+ colnr_T s, e;
+ bool retval = false;
+
+ changed_cline_bef_curs();
+ lastcol = curwin->w_leftcol + W_WIDTH(curwin) - curwin_col_off() - 1;
+ validate_virtcol();
+
+ /*
+ * If the cursor is right or left of the screen, move it to last or first
+ * character.
+ */
+ if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso)) {
+ retval = true;
+ coladvance((colnr_T)(lastcol - p_siso));
+ } else if (curwin->w_virtcol < curwin->w_leftcol + p_siso) {
+ retval = true;
+ coladvance((colnr_T)(curwin->w_leftcol + p_siso));
+ }
+
+ /*
+ * If the start of the character under the cursor is not on the screen,
+ * advance the cursor one more char. If this fails (last char of the
+ * line) adjust the scrolling.
+ */
+ getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
+ if (e > (colnr_T)lastcol) {
+ retval = true;
+ coladvance(s - 1);
+ } else if (s < curwin->w_leftcol) {
+ retval = true;
+ if (coladvance(e + 1) == FAIL) { /* there isn't another character */
+ curwin->w_leftcol = s; /* adjust w_leftcol instead */
+ changed_cline_bef_curs();
+ }
+ }
+
+ if (retval)
+ curwin->w_set_curswant = true;
+ redraw_later(NOT_VALID);
+ return retval;
+}
+
+int gchar_cursor(void)
+{
+ if (has_mbyte)
+ return (*mb_ptr2char)(get_cursor_pos_ptr());
+ return (int)*get_cursor_pos_ptr();
+}
+
+/*
+ * Write a character at the current cursor position.
+ * It is directly written into the block.
+ */
+void pchar_cursor(char_u c)
+{
+ *(ml_get_buf(curbuf, curwin->w_cursor.lnum, true)
+ + curwin->w_cursor.col) = c;
+}
+
+/*
+ * Return pointer to cursor line.
+ */
+char_u *get_cursor_line_ptr(void)
+{
+ return ml_get_buf(curbuf, curwin->w_cursor.lnum, false);
+}
+
+/*
+ * Return pointer to cursor position.
+ */
+char_u *get_cursor_pos_ptr(void)
+{
+ return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) +
+ curwin->w_cursor.col;
+}
+
diff --git a/src/nvim/cursor.h b/src/nvim/cursor.h
new file mode 100644
index 0000000000..62ea34ab30
--- /dev/null
+++ b/src/nvim/cursor.h
@@ -0,0 +1,29 @@
+#ifndef NVIM_CURSOR_H
+#define NVIM_CURSOR_H
+
+#include <stdbool.h>
+
+#include "nvim/vim.h"
+#include "nvim/misc2.h"
+
+int coladvance(colnr_T wcol);
+int coladvance_force(colnr_T wcol);
+int getvpos(pos_T *pos, colnr_T wcol);
+int getviscol(void);
+int getviscol2(colnr_T col, colnr_T coladd);
+int inc_cursor(void);
+int dec_cursor(void);
+linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum);
+void check_cursor_lnum(void);
+void check_cursor_col(void);
+void check_cursor_col_win(win_T *win);
+void check_cursor(void);
+void adjust_cursor_col(void);
+bool leftcol_changed(void);
+int gchar_cursor(void);
+void pchar_cursor(char_u c);
+char_u *get_cursor_line_ptr(void);
+char_u *get_cursor_pos_ptr(void);
+
+#endif // NVIM_CURSOR_H
+
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 06416639bd..b01a7a934a 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -6,6 +6,7 @@
#include "nvim/diff.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index bbb4ea0c03..6ea88843ab 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -16,6 +16,7 @@
#include "nvim/edit.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
@@ -427,7 +428,7 @@ edit (
if (startln)
Insstart.col = 0;
}
- Insstart_textlen = (colnr_T)linetabsize(ml_get_curline());
+ Insstart_textlen = (colnr_T)linetabsize(get_cursor_line_ptr());
Insstart_blank_vcol = MAXCOL;
if (!did_ai)
ai_col = 0;
@@ -520,7 +521,7 @@ edit (
update_curswant();
if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
|| curwin->w_curswant > curwin->w_virtcol)
- && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL) {
+ && *(ptr = get_cursor_line_ptr() + curwin->w_cursor.col) != NUL) {
if (ptr[1] == NUL)
++curwin->w_cursor.col;
else if (has_mbyte) {
@@ -1500,7 +1501,7 @@ void display_dollar(colnr_T col)
char_u *p;
/* If on the last byte of a multi-byte move to the first byte. */
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
}
curs_columns(FALSE); /* recompute w_wrow and w_wcol */
@@ -1554,7 +1555,7 @@ change_indent (
/* VREPLACE mode needs to know what the line was like before changing */
if (State & VREPLACE_FLAG) {
- orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
+ orig_line = vim_strsave(get_cursor_line_ptr()); /* Deal with NULL below */
orig_col = curwin->w_cursor.col;
}
@@ -1635,7 +1636,7 @@ change_indent (
*/
vcol = last_vcol = 0;
new_cursor_col = -1;
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
while (vcol <= (int)curwin->w_virtcol) {
last_vcol = vcol;
if (has_mbyte && new_cursor_col >= 0)
@@ -1726,7 +1727,7 @@ change_indent (
return;
/* Save new line */
- new_line = vim_strsave(ml_get_curline());
+ new_line = vim_strsave(get_cursor_line_ptr());
/* We only put back the new line up to the cursor */
new_line[curwin->w_cursor.col] = NUL;
@@ -1797,13 +1798,13 @@ static int del_char_after_col(int limit_col)
* composing character. */
mb_adjust_cursor();
while (curwin->w_cursor.col < (colnr_T)limit_col) {
- int l = utf_ptr2len(ml_get_cursor());
+ int l = utf_ptr2len(get_cursor_pos_ptr());
if (l == 0) /* end of line */
break;
curwin->w_cursor.col += l;
}
- if (*ml_get_cursor() == NUL || curwin->w_cursor.col == ecol)
+ if (*get_cursor_pos_ptr() == NUL || curwin->w_cursor.col == ecol)
return FALSE;
del_bytes((long)((int)ecol - curwin->w_cursor.col), FALSE, TRUE);
} else
@@ -2320,7 +2321,8 @@ void set_completion(colnr_T startcol, list_T *list)
compl_col = startcol;
compl_length = (int)curwin->w_cursor.col - (int)startcol;
/* compl_pattern doesn't need to be set */
- compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
+ compl_orig_text = vim_strnsave(get_cursor_line_ptr() + compl_col,
+ compl_length);
if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0,
ORIGINAL_TEXT, FALSE) != OK) {
return;
@@ -2848,7 +2850,7 @@ static int ins_compl_bs(void)
char_u *line;
char_u *p;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
p = line + curwin->w_cursor.col;
mb_ptr_back(line, p);
@@ -2970,7 +2972,7 @@ static void ins_compl_addleader(int c)
* break redo. */
if (!compl_opt_refresh_always) {
free(compl_leader);
- compl_leader = vim_strnsave(ml_get_curline() + compl_col,
+ compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col,
(int)(curwin->w_cursor.col - compl_col));
ins_compl_new_leader();
}
@@ -3219,7 +3221,7 @@ static int ins_compl_prep(int c)
if (stop_arrow() == OK)
insertchar(NUL, 0, -1);
if (prev_col > 0
- && ml_get_curline()[curwin->w_cursor.col] != NUL)
+ && get_cursor_line_ptr()[curwin->w_cursor.col] != NUL)
inc_cursor();
}
@@ -4920,7 +4922,8 @@ insert_special (
# define WHITECHAR(cc) (vim_iswhite(cc) && \
(!enc_utf8 || \
- !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1))))
+ !utf_iscomposing( \
+ utf_ptr2char(get_cursor_pos_ptr() + 1))))
/*
* "flags": INSCHAR_FORMAT - force formatting
@@ -4966,7 +4969,7 @@ insertchar (
|| (!vim_iswhite(c)
&& !((State & REPLACE_FLAG)
&& !(State & VREPLACE_FLAG)
- && *ml_get_cursor() != NUL)
+ && *get_cursor_pos_ptr() != NUL)
&& (curwin->w_cursor.lnum != Insstart.lnum
|| ((!has_format_option(FO_INS_LONG)
|| Insstart_textlen <= (colnr_T)textwidth)
@@ -5001,7 +5004,7 @@ insertchar (
* Need to remove existing (middle) comment leader and insert end
* comment leader. First, check what comment leader we can find.
*/
- i = get_leader_len(line = ml_get_curline(), &p, FALSE, TRUE);
+ i = get_leader_len(line = get_cursor_line_ptr(), &p, FALSE, TRUE);
if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) { /* Just checking */
/* Skip middle-comment string */
while (*p && p[-1] != ':') /* find end of middle flags */
@@ -5197,7 +5200,7 @@ internal_format (
/* Don't break until after the comment leader */
if (do_comments)
- leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE);
+ leader_len = get_leader_len(get_cursor_line_ptr(), NULL, FALSE, TRUE);
else
leader_len = 0;
@@ -5349,7 +5352,7 @@ internal_format (
* In VREPLACE mode, we will backspace over the text to be
* wrapped, so save a copy now to put on the next line.
*/
- saved_text = vim_strsave(ml_get_cursor());
+ saved_text = vim_strsave(get_cursor_pos_ptr());
curwin->w_cursor.col = orig_col;
if (saved_text == NULL)
break; /* Can't do it, out of memory */
@@ -5427,7 +5430,7 @@ internal_format (
* may have added or removed indent.
*/
curwin->w_cursor.col += startcol;
- len = (colnr_T)STRLEN(ml_get_curline());
+ len = (colnr_T)STRLEN(get_cursor_line_ptr());
if (curwin->w_cursor.col > len)
curwin->w_cursor.col = len;
}
@@ -5475,7 +5478,7 @@ auto_format (
return;
pos = curwin->w_cursor;
- old = ml_get_curline();
+ old = get_cursor_line_ptr();
/* may remove added space */
check_auto_format(FALSE);
@@ -5538,7 +5541,7 @@ auto_format (
* need to add a space when 'w' is in 'formatoptions' to keep a paragraph
* formatted. */
if (!wasatend && has_format_option(FO_WHITE_PAR)) {
- new = ml_get_curline();
+ new = get_cursor_line_ptr();
len = (colnr_T)STRLEN(new);
if (curwin->w_cursor.col == len) {
pnew = vim_strnsave(new, len + 2);
@@ -5701,7 +5704,7 @@ int stop_arrow(void)
ins_need_undo = FALSE;
}
Insstart = curwin->w_cursor; /* new insertion starts here */
- Insstart_textlen = (colnr_T)linetabsize(ml_get_curline());
+ Insstart_textlen = (colnr_T)linetabsize(get_cursor_line_ptr());
ai_col = 0;
if (State & VREPLACE_FLAG) {
orig_line_count = curbuf->b_ml.ml_line_count;
@@ -5819,7 +5822,7 @@ stop_insert (
/* <C-S-Right> may have started Visual mode, adjust the position for
* deleted characters. */
if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum) {
- int len = (int)STRLEN(ml_get_curline());
+ int len = (int)STRLEN(get_cursor_line_ptr());
if (VIsual.col > len) {
VIsual.col = len;
@@ -5916,7 +5919,7 @@ void beginline(int flags)
if (flags & (BL_WHITE | BL_SOL)) {
char_u *ptr;
- for (ptr = ml_get_curline(); vim_iswhite(*ptr)
+ for (ptr = get_cursor_line_ptr(); vim_iswhite(*ptr)
&& !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
++curwin->w_cursor.col;
}
@@ -5941,7 +5944,7 @@ int oneright(void)
pos_T prevpos = curwin->w_cursor;
/* Adjust for multi-wide char (excluding TAB) */
- ptr = ml_get_cursor();
+ ptr = get_cursor_pos_ptr();
coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
(*mb_ptr2char)(ptr)
))
@@ -5952,7 +5955,7 @@ int oneright(void)
|| prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
}
- ptr = ml_get_cursor();
+ ptr = get_cursor_pos_ptr();
if (*ptr == NUL)
return FAIL; /* already at the very end */
@@ -5999,7 +6002,7 @@ int oneleft(void)
char_u *ptr;
/* Adjust for multi-wide char (not a TAB) */
- ptr = ml_get_cursor();
+ ptr = get_cursor_pos_ptr();
if (*ptr != TAB && vim_isprintc(
(*mb_ptr2char)(ptr)
) && ptr2cells(ptr) > 1)
@@ -6225,7 +6228,7 @@ static int echeck_abbr(int c)
if (p_paste || no_abbr || arrow_used)
return FALSE;
- return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
+ return check_abbr(c, get_cursor_line_ptr(), curwin->w_cursor.col,
curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
}
@@ -6416,23 +6419,23 @@ static void replace_do_bs(int limit_col)
/* Get the number of screen cells used by the character we are
* going to delete. */
getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
- orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
+ orig_vcols = chartabsize(get_cursor_pos_ptr(), start_vcol);
}
if (has_mbyte) {
(void)del_char_after_col(limit_col);
if (State & VREPLACE_FLAG)
- orig_len = (int)STRLEN(ml_get_cursor());
+ orig_len = (int)STRLEN(get_cursor_pos_ptr());
replace_push(cc);
} else {
pchar_cursor(cc);
if (State & VREPLACE_FLAG)
- orig_len = (int)STRLEN(ml_get_cursor()) - 1;
+ orig_len = (int)STRLEN(get_cursor_pos_ptr()) - 1;
}
replace_pop_ins();
if (State & VREPLACE_FLAG) {
/* Get the number of screen cells used by the inserted characters */
- p = ml_get_cursor();
+ p = get_cursor_pos_ptr();
ins_len = (int)STRLEN(p) - orig_len;
vcol = start_vcol;
for (i = 0; i < ins_len; ++i) {
@@ -6575,7 +6578,7 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
*/
else if (*look == 'e') {
if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) {
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
return TRUE;
@@ -6589,18 +6592,18 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
*/
else if (*look == ':') {
if (try_match && keytyped == ':') {
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
if (cin_iscase(p, FALSE) || cin_isscopedecl(p) || cin_islabel())
return TRUE;
/* Need to get the line again after cin_islabel(). */
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
if (curwin->w_cursor.col > 2
&& p[curwin->w_cursor.col - 1] == ':'
&& p[curwin->w_cursor.col - 2] == ':') {
p[curwin->w_cursor.col - 1] = ' ';
i = (cin_iscase(p, FALSE) || cin_isscopedecl(p)
|| cin_islabel());
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
p[curwin->w_cursor.col - 1] = ':';
if (i)
return TRUE;
@@ -6652,7 +6655,7 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
/* Just completed a word, check if it starts with "look".
* search back for the start of a word. */
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
if (has_mbyte) {
char_u *n;
@@ -6675,7 +6678,7 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
if (keytyped == (int)p[-1] || (icase && keytyped < 256
&& TOLOWER_LOC(keytyped) ==
TOLOWER_LOC((int)p[-1]))) {
- line = ml_get_cursor();
+ line = get_cursor_pos_ptr();
if ((curwin->w_cursor.col == (colnr_T)(p - look)
|| !vim_iswordc(line[-(p - look) - 1]))
&& (icase
@@ -6687,7 +6690,7 @@ int in_cinkeys(int keytyped, int when, int line_is_empty)
if (match && try_match_word && !try_match) {
/* "0=word": Check if there are only blanks before the
* word. */
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
if ((int)(skipwhite(line) - line) !=
(int)(curwin->w_cursor.col - (p - look)))
match = FALSE;
@@ -7228,7 +7231,7 @@ static void ins_shift(int c, int lastc)
} else
change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0, TRUE);
- if (did_ai && *skipwhite(ml_get_curline()) != NUL)
+ if (did_ai && *skipwhite(get_cursor_line_ptr()) != NUL)
did_ai = FALSE;
did_si = FALSE;
can_si = FALSE;
@@ -7451,8 +7454,8 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
&& ((p_sta && in_indent)
|| (get_sts_value() != 0
&& curwin->w_cursor.col > 0
- && (*(ml_get_cursor() - 1) == TAB
- || (*(ml_get_cursor() - 1) == ' '
+ && (*(get_cursor_pos_ptr() - 1) == TAB
+ || (*(get_cursor_pos_ptr() - 1) == ' '
&& (!*inserted_space_p
|| arrow_used)))))) {
int ts;
@@ -7477,7 +7480,7 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
/* delete characters until we are at or before want_vcol */
while (vcol > want_vcol
- && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
+ && (cc = *(get_cursor_pos_ptr() - 1), vim_iswhite(cc)))
ins_bs_one(&vcol);
/* insert extra spaces until we are at want_vcol */
@@ -7529,7 +7532,7 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
replace_do_bs(-1);
else {
if (enc_utf8 && p_deco)
- (void)utfc_ptr2char(ml_get_cursor(), cpc);
+ (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc);
(void)del_char(FALSE);
/*
* If there are combining characters and 'delcombine' is set
@@ -7766,7 +7769,7 @@ static void ins_right(void)
oneright();
else {
if (has_mbyte)
- curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
+ curwin->w_cursor.col += (*mb_ptr2len)(get_cursor_pos_ptr());
else
++curwin->w_cursor.col;
}
@@ -7975,10 +7978,10 @@ static int ins_tab(void)
if (State & VREPLACE_FLAG) {
pos = curwin->w_cursor;
cursor = &pos;
- saved_line = vim_strsave(ml_get_curline());
+ saved_line = vim_strsave(get_cursor_line_ptr());
ptr = saved_line + pos.col;
} else {
- ptr = ml_get_cursor();
+ ptr = get_cursor_pos_ptr();
cursor = &curwin->w_cursor;
}
@@ -8119,7 +8122,7 @@ static int ins_eol(int c)
/* NL in reverse insert will always start in the end of
* current line. */
if (revins_on)
- curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
+ curwin->w_cursor.col += (colnr_T)STRLEN(get_cursor_pos_ptr());
AppendToRedobuff(NL_STR);
i = open_line(FORWARD,
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 83bbd9a24c..95fb6ed732 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -16,6 +16,7 @@
#include "nvim/eval.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/ex_cmds.h"
@@ -8035,7 +8036,7 @@ static void f_col(typval_T *argvars, typval_T *rettv)
/* col(".") when the cursor is on the NUL at the end of the line
* because of "coladd" can be seen as an extra column. */
if (virtual_active() && fp == &curwin->w_cursor) {
- char_u *p = ml_get_cursor();
+ char_u *p = get_cursor_pos_ptr();
if (curwin->w_cursor.coladd >= (colnr_T)chartabsize(p,
curwin->w_virtcol - curwin->w_cursor.coladd)) {
@@ -13831,7 +13832,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv)
/* Find the start and length of the badly spelled word. */
len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr);
if (len != 0)
- word = ml_get_cursor();
+ word = get_cursor_pos_ptr();
} else if (curwin->w_p_spell && *curbuf->b_s.b_p_spl != NUL) {
char_u *str = get_tv_string_chk(&argvars[0]);
int capcol = -1;
@@ -15392,7 +15393,7 @@ var2fpos (
pos.col = 0;
} else {
pos.lnum = curwin->w_cursor.lnum;
- pos.col = (colnr_T)STRLEN(ml_get_curline());
+ pos.col = (colnr_T)STRLEN(get_cursor_line_ptr());
}
return &pos;
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 6c297f399b..de01665286 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -18,6 +18,7 @@
#include "nvim/ex_cmds.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
@@ -90,7 +91,7 @@ void do_ascii(exarg_T *eap)
int len;
if (enc_utf8)
- c = utfc_ptr2char(ml_get_cursor(), cc);
+ c = utfc_ptr2char(get_cursor_pos_ptr(), cc);
else
c = gchar_cursor();
if (c == NUL) {
@@ -257,7 +258,7 @@ static int linelen(int *has_tab)
int len;
/* find the first non-blank character */
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
first = skipwhite(line);
/* find the character after the last non-blank character */
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index ae55c5b65a..832870cf2d 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -16,6 +16,7 @@
#include "nvim/ex_docmd.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
@@ -6119,7 +6120,7 @@ static void ex_open(exarg_T *eap)
regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0);
if (regmatch.regprog != NULL) {
regmatch.rm_ic = p_ic;
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
if (vim_regexec(&regmatch, p, (colnr_T)0))
curwin->w_cursor.col = (colnr_T)(regmatch.startp[0] - p);
else
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 278886cf5e..57af0c20e4 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -18,6 +18,7 @@
#include "nvim/ex_getln.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
@@ -5305,7 +5306,7 @@ static int ex_window(void)
* and don't modify the cmd window. */
ccline.cmdbuff = NULL;
} else
- ccline.cmdbuff = vim_strsave(ml_get_curline());
+ ccline.cmdbuff = vim_strsave(get_cursor_line_ptr());
if (ccline.cmdbuff == NULL)
cmdwin_result = Ctrl_C;
else {
diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c
index 1f9dbf8985..6e532bbe0a 100644
--- a/src/nvim/farsi.c
+++ b/src/nvim/farsi.c
@@ -4,6 +4,7 @@
///
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
@@ -169,7 +170,7 @@ static int toF_Xor_X_(int c)
tempc = _HE;
if (p_ri &&
- (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(ml_get_curline()))) {
+ (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr()))) {
inc_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = _HE_;
@@ -177,7 +178,7 @@ static int toF_Xor_X_(int c)
dec_cursor();
}
- if (!p_ri && STRLEN(ml_get_curline())) {
+ if (!p_ri && STRLEN(get_cursor_line_ptr())) {
dec_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = _HE_;
@@ -454,7 +455,7 @@ static void put_curr_and_l_to_X(int c)
return;
}
- if ((curwin->w_cursor.col < (colnr_T)STRLEN(ml_get_curline()))) {
+ if ((curwin->w_cursor.col < (colnr_T)STRLEN(get_cursor_line_ptr()))) {
if ((p_ri && curwin->w_cursor.col) || !p_ri) {
if (p_ri) {
dec_cursor();
@@ -698,7 +699,7 @@ static void chg_c_to_X_or_X(void)
tempc = gchar_cursor();
- if (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(ml_get_curline())) {
+ if (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr())) {
inc_cursor();
if ((tempc == F_HE) && (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))) {
tempc = _HE_;
@@ -721,7 +722,7 @@ static void chg_l_to_X_orX_(void)
int tempc;
if ((curwin->w_cursor.col != 0)
- && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) {
+ && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) {
return;
}
@@ -801,7 +802,7 @@ static void chg_l_toXor_X(void)
int tempc;
if ((curwin->w_cursor.col != 0) &&
- (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) {
+ (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) {
return;
}
@@ -1563,7 +1564,7 @@ int fkmap(int c)
break;
case 'G':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (gchar_cursor() == _LAM) {
chg_c_toX_orX();
} else if (p_ri) {
@@ -1599,7 +1600,7 @@ int fkmap(int c)
return tempc;
case 'h':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (p_ri) {
chg_c_to_X_or_X();
}
@@ -1642,7 +1643,7 @@ int fkmap(int c)
case 'i':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (!p_ri && !F_is_TyE(tempc)) {
chg_c_to_X_orX_();
}
@@ -1677,7 +1678,7 @@ int fkmap(int c)
case 'J':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (p_ri) {
chg_c_to_X_or_X();
}
@@ -1752,7 +1753,7 @@ int fkmap(int c)
break;
case 'u':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (!p_ri && !F_is_TyE(tempc)) {
chg_c_to_X_orX_();
}
@@ -1796,7 +1797,7 @@ int fkmap(int c)
break;
case 'y':
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (!p_ri && !F_is_TyE(tempc)) {
chg_c_to_X_orX_();
}
@@ -1856,7 +1857,7 @@ int fkmap(int c)
}
if ((F_isalpha(tempc) || F_isdigit(tempc))) {
- if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) {
+ if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) {
if (!p_ri && !F_is_TyE(tempc)) {
chg_c_to_X_orX_();
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 027c7b07d5..290ff424cc 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -16,6 +16,7 @@
#include "nvim/fileio.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 1215d5b24d..fe05ba76ac 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -16,6 +16,7 @@
#include "nvim/vim.h"
#include "nvim/fold.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 52322244e1..d215bb06e7 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -20,6 +20,7 @@
#include "nvim/vim.h"
#include "nvim/getchar.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
@@ -2171,7 +2172,7 @@ static int vgetorpeek(int advance)
* character -- webb
*/
col = vcol = curwin->w_wcol = 0;
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
while (col < curwin->w_cursor.col) {
if (!vim_iswhite(ptr[col]))
curwin->w_wcol = vcol;
@@ -2199,7 +2200,7 @@ static int vgetorpeek(int advance)
if (has_mbyte && col > 0 && curwin->w_wcol > 0) {
/* Correct when the cursor is on the right halve
* of a double-wide character. */
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
col -= (*mb_head_off)(ptr, ptr + col);
if ((*mb_ptr2cells)(ptr + col) > 1)
--curwin->w_wcol;
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 06273e98c2..fcdc71e636 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -1,6 +1,7 @@
#include "nvim/indent.h"
#include "nvim/eval.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
@@ -17,7 +18,7 @@ static int lisp_match(char_u *p);
// Count the size (in window cells) of the indent in the current line.
int get_indent(void)
{
- return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts);
+ return get_indent_str(get_cursor_line_ptr(), (int)curbuf->b_p_ts);
}
@@ -87,7 +88,7 @@ int set_indent(int size, int flags)
// characters needed for the indent.
todo = size;
ind_len = 0;
- p = oldline = ml_get_curline();
+ p = oldline = get_cursor_line_ptr();
// Calculate the buffer size for the new indent, and check to see if it
// isn't already set.
@@ -367,14 +368,14 @@ int copy_indent(int size, char_u *src)
if (p == NULL) {
// Allocate memory for the result: the copied indent, new indent
// and the rest of the line.
- line_len = (int)STRLEN(ml_get_curline()) + 1;
+ line_len = (int)STRLEN(get_cursor_line_ptr()) + 1;
line = xmalloc(ind_len + line_len);
p = line;
}
}
// Append the original line
- memmove(p, ml_get_curline(), (size_t)line_len);
+ memmove(p, get_cursor_line_ptr(), (size_t)line_len);
// Replace the line
ml_replace(curwin->w_cursor.lnum, line, false);
@@ -436,7 +437,7 @@ int inindent(int extra)
char_u *ptr;
colnr_T col;
- for (col = 0, ptr = ml_get_curline(); vim_iswhite(*ptr); ++col) {
+ for (col = 0, ptr = get_cursor_line_ptr(); vim_iswhite(*ptr); ++col) {
ptr++;
}
@@ -549,7 +550,7 @@ int get_lisp_indent(void)
continue;
}
- for (that = ml_get_curline(); *that != NUL; ++that) {
+ for (that = get_cursor_line_ptr(); *that != NUL; ++that) {
if (*that == ';') {
while (*(that + 1) != NUL) {
that++;
@@ -596,7 +597,7 @@ int get_lisp_indent(void)
curwin->w_cursor.col = pos->col;
col = pos->col;
- that = ml_get_curline();
+ that = get_cursor_line_ptr();
if (vi_lisp && (get_indent() == 0)) {
amount = 2;
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 8979635823..631ef06d01 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -1,6 +1,7 @@
#include "nvim/vim.h"
#include "nvim/misc1.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
@@ -266,7 +267,7 @@ int cin_islabel(void)
{ /* XXX */
char_u *s;
- s = cin_skipcomment(ml_get_curline());
+ s = cin_skipcomment(get_cursor_line_ptr());
/*
* Exclude "default" from labels, since it should be indented
@@ -297,7 +298,7 @@ int cin_islabel(void)
if ((trypos = ind_find_start_comment()) != NULL) /* XXX */
curwin->w_cursor = *trypos;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
continue;
if (*(line = cin_skipcomment(line)) == NUL)
@@ -327,7 +328,7 @@ static int cin_isinit(void)
char_u *s;
static char *skip[] = {"static", "public", "protected", "private"};
- s = cin_skipcomment(ml_get_curline());
+ s = cin_skipcomment(get_cursor_line_ptr());
if (cin_starts_with(s, "typedef"))
s = cin_skipcomment(s + 7);
@@ -521,16 +522,16 @@ static int skip_label(linenr_T lnum, char_u **pp)
cursor_save = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/* XXX */
if (cin_iscase(l, FALSE) || cin_isscopedecl(l) || cin_islabel()) {
amount = get_indent_nolabel(lnum);
- l = after_label(ml_get_curline());
+ l = after_label(get_cursor_line_ptr());
if (l == NULL) /* just in case */
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
} else {
amount = get_indent();
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
}
*pp = l;
@@ -552,7 +553,7 @@ static int cin_first_id_amount(void)
pos_T fp;
colnr_T col;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
p = skipwhite(line);
len = (int)(skiptowhite(p) - p);
if (len == 6 && STRNCMP(p, "static", 6) == 0) {
@@ -868,7 +869,7 @@ cin_iswhileofdo ( /* XXX */
cursor_save = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = 0;
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
while (*p && *p != 'w') { /* skip any '}', until the 'w' of the "while" */
++p;
++curwin->w_cursor.col;
@@ -941,7 +942,7 @@ static int cin_iswhileofdo_end(int terminated)
if (terminated != ';') /* there must be a ';' at the end */
return FALSE;
- p = line = ml_get_curline();
+ p = line = get_cursor_line_ptr();
while (*p != NUL) {
p = cin_skipcomment(p);
if (*p == ')') {
@@ -963,7 +964,7 @@ static int cin_iswhileofdo_end(int terminated)
}
/* Searching may have made "line" invalid, get it again. */
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
p = line + i;
}
}
@@ -999,7 +1000,7 @@ cin_is_cpp_baseclass (
char_u *s;
int class_or_struct, lookfor_ctor_init, cpp_base_class;
linenr_T lnum = curwin->w_cursor.lnum;
- char_u *line = ml_get_curline();
+ char_u *line = get_cursor_line_ptr();
*col = 0;
@@ -1125,10 +1126,10 @@ static int get_baseclass_amount(int col)
if (col == 0) {
amount = get_indent();
- if (find_last_paren(ml_get_curline(), '(', ')')
+ if (find_last_paren(get_cursor_line_ptr(), '(', ')')
&& (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
amount = get_indent_lnum(trypos->lnum); /* XXX */
- if (!cin_ends_in(ml_get_curline(), (char_u *)",", NULL))
+ if (!cin_ends_in(get_cursor_line_ptr(), (char_u *)",", NULL))
amount += curbuf->b_ind_cpp_baseclass;
} else {
curwin->w_cursor.col = col;
@@ -1865,7 +1866,7 @@ int get_c_indent(void)
/* Ignore a '(' in front of the line that has a match before
* our matching '('. */
curwin->w_cursor.lnum = our_paren_pos.lnum;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
look_col = (int)(look - line);
curwin->w_cursor.col = look_col + 1;
if ((trypos = findmatchlimit(NULL, ')', 0,
@@ -2041,7 +2042,7 @@ int get_c_indent(void)
* }
*/
if (curbuf->b_ind_js || (curbuf->b_ind_keep_case_label
- && cin_iscase(skipwhite(ml_get_curline()),
+ && cin_iscase(skipwhite(get_cursor_line_ptr()),
FALSE)))
amount = get_indent();
else
@@ -2105,7 +2106,7 @@ int get_c_indent(void)
if (start_brace == BRACE_AT_END) { /* '{' is at end of line */
amount += curbuf->b_ind_open_imag;
- l = skipwhite(ml_get_curline());
+ l = skipwhite(get_cursor_line_ptr());
if (cin_is_cpp_namespace(l))
amount += curbuf->b_ind_cpp_namespace;
} else {
@@ -2177,7 +2178,7 @@ int get_c_indent(void)
break;
}
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/*
* If we're in a comment now, skip to the start of the
@@ -2286,7 +2287,7 @@ int get_c_indent(void)
< ourscope - FIND_NAMESPACE_LIM)
break;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/* If we're in a comment now, skip to the start of
* the comment. */
@@ -2324,7 +2325,7 @@ int get_c_indent(void)
continue;
}
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/*
* If this is a switch() label, may line up relative to that.
@@ -2405,7 +2406,7 @@ int get_c_indent(void)
*/
if (n) {
amount = n;
- l = after_label(ml_get_curline());
+ l = after_label(get_cursor_line_ptr());
if (l != NULL && cin_is_cinword(l)) {
if (theline[0] == '{')
amount += curbuf->b_ind_open_extra;
@@ -2449,7 +2450,7 @@ int get_c_indent(void)
* Ignore jump labels with nothing after them.
*/
if (!curbuf->b_ind_js && cin_islabel()) {
- l = after_label(ml_get_curline());
+ l = after_label(get_cursor_line_ptr());
if (l == NULL || cin_nocode(l))
continue;
}
@@ -2460,7 +2461,7 @@ int get_c_indent(void)
* (need to get the line again, cin_islabel() may have
* unlocked it)
*/
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)
|| cin_nocode(l))
continue;
@@ -2472,7 +2473,7 @@ int get_c_indent(void)
n = FALSE;
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
n = cin_is_cpp_baseclass(&col);
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
}
if (n) {
if (lookfor == LOOKFOR_UNTERM) {
@@ -2544,7 +2545,7 @@ int get_c_indent(void)
* asdf)
*/
curwin->w_cursor = *trypos;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
if (cin_iscase(l, FALSE) || cin_isscopedecl(l)) {
++curwin->w_cursor.lnum;
curwin->w_cursor.col = 0;
@@ -2656,7 +2657,7 @@ int get_c_indent(void)
* x = 1;
* -> here
*/
- l = skipwhite(ml_get_curline());
+ l = skipwhite(get_cursor_line_ptr());
if (cin_isdo(l)) {
if (whilelevel == 0)
break;
@@ -2675,7 +2676,7 @@ int get_c_indent(void)
* not the one from "if () {". */
if (*l == '}')
curwin->w_cursor.col =
- (colnr_T)(l - ml_get_curline()) + 1;
+ (colnr_T)(l - get_cursor_line_ptr()) + 1;
if ((trypos = find_start_brace()) == NULL
|| find_match(LOOKFOR_IF, trypos->lnum)
@@ -2801,7 +2802,7 @@ int get_c_indent(void)
* may be lined up with the case label.
*/
if (lookfor == LOOKFOR_NOBREAK
- && cin_isbreak(skipwhite(ml_get_curline()))) {
+ && cin_isbreak(skipwhite(get_cursor_line_ptr()))) {
lookfor = LOOKFOR_ANY;
continue;
}
@@ -2810,7 +2811,7 @@ int get_c_indent(void)
* Handle "do {" line.
*/
if (whilelevel > 0) {
- l = cin_skipcomment(ml_get_curline());
+ l = cin_skipcomment(get_cursor_line_ptr());
if (cin_isdo(l)) {
amount = get_indent(); /* XXX */
--whilelevel;
@@ -2866,7 +2867,7 @@ int get_c_indent(void)
* here;
*/
term_again:
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
if (find_last_paren(l, '(', ')')
&& (trypos = find_match_paren(
curbuf->b_ind_maxparen)) != NULL) {
@@ -2877,7 +2878,7 @@ term_again:
* asdf)
*/
curwin->w_cursor = *trypos;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
if (cin_iscase(l, FALSE) || cin_isscopedecl(l)) {
++curwin->w_cursor.lnum;
curwin->w_cursor.col = 0;
@@ -2934,13 +2935,13 @@ term_again:
* If we're at the end of a block, skip to the start of
* that block.
*/
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
if (find_last_paren(l, '{', '}') /* XXX */
&& (trypos = find_start_brace()) != NULL) {
curwin->w_cursor = *trypos;
/* if not "else {" check for terminated again */
/* but skip block for "} else {" */
- l = cin_skipcomment(ml_get_curline());
+ l = cin_skipcomment(get_cursor_line_ptr());
if (*l == '}' || !cin_iselse(l))
goto term_again;
++curwin->w_cursor.lnum;
@@ -3005,7 +3006,7 @@ term_again:
curwin->w_cursor.lnum--;
curwin->w_cursor.col = 0;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/*
* If we're in a comment now, skip to the start of the comment.
@@ -3023,7 +3024,7 @@ term_again:
n = FALSE;
if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{') {
n = cin_is_cpp_baseclass(&col);
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
}
if (n) {
/* XXX */
@@ -3090,7 +3091,7 @@ term_again:
*/
if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) /* XXX */
break;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
/*
* Finding the closing '}' of a previous function. Put
@@ -3151,7 +3152,7 @@ term_again:
if (cin_ends_in(l, (char_u *)",", NULL)
|| (*l != NUL && l[STRLEN(l) - 1] == '\\'))
break;
- l = ml_get_curline();
+ l = get_cursor_line_ptr();
}
/*
@@ -3225,7 +3226,7 @@ static int find_match(int lookfor, linenr_T ourscope)
curwin->w_cursor.lnum--;
curwin->w_cursor.col = 0;
- look = cin_skipcomment(ml_get_curline());
+ look = cin_skipcomment(get_cursor_line_ptr());
if (cin_iselse(look)
|| cin_isif(look)
|| cin_isdo(look) /* XXX */
@@ -3259,7 +3260,7 @@ static int find_match(int lookfor, linenr_T ourscope)
* then we need to go back to another if, so
* increment elselevel
*/
- look = cin_skipcomment(ml_get_curline());
+ look = cin_skipcomment(get_cursor_line_ptr());
if (cin_iselse(look)) {
mightbeif = cin_skipcomment(look + 4);
if (!cin_isif(mightbeif))
@@ -3277,7 +3278,7 @@ static int find_match(int lookfor, linenr_T ourscope)
}
/* If it's an "if" decrement elselevel */
- look = cin_skipcomment(ml_get_curline());
+ look = cin_skipcomment(get_cursor_line_ptr());
if (cin_isif(look)) {
elselevel--;
/*
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 10e94d7ced..ec1997657b 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -82,6 +82,7 @@
#include "nvim/vim.h"
#include "nvim/mbyte.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/fileio.h"
#include "nvim/memline.h"
#include "nvim/message.h"
@@ -2859,7 +2860,7 @@ void show_utf8()
/* Get the byte length of the char under the cursor, including composing
* characters. */
- line = ml_get_cursor();
+ line = get_cursor_pos_ptr();
len = utfc_ptr2len(line);
if (len == 0) {
MSG("NUL");
@@ -3096,7 +3097,7 @@ void utf_find_illegal()
curwin->w_cursor.coladd = 0;
for (;; ) {
- p = ml_get_cursor();
+ p = get_cursor_pos_ptr();
if (vimconv.vc_type != CONV_NONE) {
free(tofree);
tofree = string_convert(&vimconv, p, NULL);
@@ -3112,12 +3113,12 @@ void utf_find_illegal()
if (*p >= 0x80 && (len == 1
|| utf_char2len(utf_ptr2char(p)) != len)) {
if (vimconv.vc_type == CONV_NONE)
- curwin->w_cursor.col += (colnr_T)(p - ml_get_cursor());
+ curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr());
else {
int l;
len = (int)(p - tofree);
- for (p = ml_get_cursor(); *p != NUL && len-- > 0; p += l) {
+ for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
l = utf_ptr2len(p);
curwin->w_cursor.col += l;
}
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index dc6823c8fa..c831727a0a 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -46,6 +46,7 @@
#include "nvim/vim.h"
#include "nvim/memline.h"
#include "nvim/buffer.h"
+#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/fileio.h"
#include "nvim/main.h"
@@ -1777,23 +1778,6 @@ char_u *ml_get_pos(pos_T *pos)
}
/*
- * Return pointer to cursor line.
- */
-char_u *ml_get_curline(void)
-{
- return ml_get_buf(curbuf, curwin->w_cursor.lnum, FALSE);
-}
-
-/*
- * Return pointer to cursor position.
- */
-char_u *ml_get_cursor(void)
-{
- return ml_get_buf(curbuf, curwin->w_cursor.lnum, FALSE) +
- curwin->w_cursor.col;
-}
-
-/*
* Return a pointer to a line in a specific buffer
*
* "will_change": if TRUE mark the buffer dirty (chars in the line will be
diff --git a/src/nvim/memline.h b/src/nvim/memline.h
index 704a98b20e..831cf46a35 100644
--- a/src/nvim/memline.h
+++ b/src/nvim/memline.h
@@ -19,8 +19,6 @@ void ml_sync_all(int check_file, int check_char);
void ml_preserve(buf_T *buf, int message);
char_u *ml_get(linenr_T lnum);
char_u *ml_get_pos(pos_T *pos);
-char_u *ml_get_curline(void);
-char_u *ml_get_cursor(void);
char_u *ml_get_buf(buf_T *buf, linenr_T lnum, int will_change);
int ml_line_alloced(void);
int ml_append(linenr_T lnum, char_u *line, colnr_T len, int newfile);
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index d9b84eae71..f71c1a351d 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -16,6 +16,7 @@
#include "nvim/vim.h"
#include "nvim/menu.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/getchar.h"
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index d83c03c9fd..e63ca008bc 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -16,6 +16,7 @@
#include "nvim/version_defs.h"
#include "nvim/misc1.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
@@ -119,7 +120,7 @@ open_line (
/*
* make a copy of the current line so we can mess with it
*/
- saved_line = vim_strsave(ml_get_curline());
+ saved_line = vim_strsave(get_cursor_line_ptr());
if (State & VREPLACE_FLAG) {
/*
@@ -285,7 +286,7 @@ open_line (
if ((pos = findmatch(NULL, '(')) != NULL) {
curwin->w_cursor.lnum = pos->lnum;
newindent = get_indent();
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
}
}
/*
@@ -886,7 +887,7 @@ open_line (
&& curbuf->b_p_lisp
&& curbuf->b_p_ai) {
fixthisline(get_lisp_indent);
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
ai_col = (colnr_T)(skipwhite(p) - p);
}
/*
@@ -900,7 +901,7 @@ open_line (
? KEY_OPEN_FORW
: KEY_OPEN_BACK, ' ', linewhite(curwin->w_cursor.lnum))) {
do_c_expr_indent();
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
ai_col = (colnr_T)(skipwhite(p) - p);
}
if (vreplace_mode != 0)
@@ -913,7 +914,7 @@ open_line (
*/
if (State & VREPLACE_FLAG) {
/* Put new line in p_extra */
- p_extra = vim_strsave(ml_get_curline());
+ p_extra = vim_strsave(get_cursor_line_ptr());
/* Put back original line */
ml_replace(curwin->w_cursor.lnum, next_line, FALSE);
@@ -1594,7 +1595,7 @@ int del_char(int fixpos)
if (has_mbyte) {
/* Make sure the cursor is at the start of a character. */
mb_adjust_cursor();
- if (*ml_get_cursor() == NUL)
+ if (*get_cursor_pos_ptr() == NUL)
return FAIL;
return del_chars(1L, fixpos);
}
@@ -1611,7 +1612,7 @@ int del_chars(long count, int fixpos)
char_u *p;
int l;
- p = ml_get_cursor();
+ p = get_cursor_pos_ptr();
for (i = 0; i < count && *p != NUL; ++i) {
l = (*mb_ptr2len)(p);
bytes += l;
@@ -1795,23 +1796,6 @@ int gchar_pos(pos_T *pos)
return (int)*ptr;
}
-int gchar_cursor(void)
-{
- if (has_mbyte)
- return (*mb_ptr2char)(ml_get_cursor());
- return (int)*ml_get_cursor();
-}
-
-/*
- * Write a character at the current cursor position.
- * It is directly written into the block.
- */
-void pchar_cursor(int c)
-{
- *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE)
- + curwin->w_cursor.col) = c;
-}
-
/*
* Skip to next part of an option argument: Skip space and comma.
*/
diff --git a/src/nvim/misc1.h b/src/nvim/misc1.h
index df1d630621..5d9d2f084b 100644
--- a/src/nvim/misc1.h
+++ b/src/nvim/misc1.h
@@ -25,8 +25,6 @@ int del_bytes(long count, int fixpos_arg, int use_delcombine);
void truncate_line(int fixpos);
void del_lines(long nlines, int undo);
int gchar_pos(pos_T *pos);
-int gchar_cursor(void);
-void pchar_cursor(int c);
char_u *skip_to_option_part(char_u *p);
void changed(void);
void changed_int(void);
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index d49898815f..1db6c4193c 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -16,6 +16,7 @@
#include "nvim/file_search.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
@@ -51,9 +52,6 @@
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
-static int coladvance2(pos_T *pos, int addspaces, int finetune,
- colnr_T wcol);
-
/*
* Return TRUE if in the current mode we need to use virtual.
*/
@@ -70,256 +68,6 @@ int virtual_active(void)
}
/*
- * Get the screen position of the cursor.
- */
-int getviscol(void)
-{
- colnr_T x;
-
- getvvcol(curwin, &curwin->w_cursor, &x, NULL, NULL);
- return (int)x;
-}
-
-/*
- * Get the screen position of character col with a coladd in the cursor line.
- */
-int getviscol2(colnr_T col, colnr_T coladd)
-{
- colnr_T x;
- pos_T pos;
-
- pos.lnum = curwin->w_cursor.lnum;
- pos.col = col;
- pos.coladd = coladd;
- getvvcol(curwin, &pos, &x, NULL, NULL);
- return (int)x;
-}
-
-/*
- * Go to column "wcol", and add/insert white space as necessary to get the
- * cursor in that column.
- * The caller must have saved the cursor line for undo!
- */
-int coladvance_force(colnr_T wcol)
-{
- int rc = coladvance2(&curwin->w_cursor, TRUE, FALSE, wcol);
-
- if (wcol == MAXCOL)
- curwin->w_valid &= ~VALID_VIRTCOL;
- else {
- /* Virtcol is valid */
- curwin->w_valid |= VALID_VIRTCOL;
- curwin->w_virtcol = wcol;
- }
- return rc;
-}
-
-/*
- * Try to advance the Cursor to the specified screen column.
- * If virtual editing: fine tune the cursor position.
- * Note that all virtual positions off the end of a line should share
- * a curwin->w_cursor.col value (n.b. this is equal to STRLEN(line)),
- * beginning at coladd 0.
- *
- * return OK if desired column is reached, FAIL if not
- */
-int coladvance(colnr_T wcol)
-{
- int rc = getvpos(&curwin->w_cursor, wcol);
-
- if (wcol == MAXCOL || rc == FAIL)
- curwin->w_valid &= ~VALID_VIRTCOL;
- else if (*ml_get_cursor() != TAB) {
- /* Virtcol is valid when not on a TAB */
- curwin->w_valid |= VALID_VIRTCOL;
- curwin->w_virtcol = wcol;
- }
- return rc;
-}
-
-/*
- * Return in "pos" the position of the cursor advanced to screen column "wcol".
- * return OK if desired column is reached, FAIL if not
- */
-int getvpos(pos_T *pos, colnr_T wcol)
-{
- return coladvance2(pos, FALSE, virtual_active(), wcol);
-}
-
-static int
-coladvance2 (
- pos_T *pos,
- int addspaces, /* change the text to achieve our goal? */
- int finetune, /* change char offset for the exact column */
- colnr_T wcol /* column to move to */
-)
-{
- int idx;
- char_u *ptr;
- char_u *line;
- colnr_T col = 0;
- int csize = 0;
- int one_more;
- int head = 0;
-
- one_more = (State & INSERT)
- || restart_edit != NUL
- || (VIsual_active && *p_sel != 'o')
- || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL)
- ;
- line = ml_get_buf(curbuf, pos->lnum, FALSE);
-
- if (wcol >= MAXCOL) {
- idx = (int)STRLEN(line) - 1 + one_more;
- col = wcol;
-
- if ((addspaces || finetune) && !VIsual_active) {
- curwin->w_curswant = linetabsize(line) + one_more;
- if (curwin->w_curswant > 0)
- --curwin->w_curswant;
- }
- } else {
- int width = W_WIDTH(curwin) - win_col_off(curwin);
-
- if (finetune
- && curwin->w_p_wrap
- && curwin->w_width != 0
- && wcol >= (colnr_T)width) {
- csize = linetabsize(line);
- if (csize > 0)
- csize--;
-
- if (wcol / width > (colnr_T)csize / width
- && ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
- /* In case of line wrapping don't move the cursor beyond the
- * right screen edge. In Insert mode allow going just beyond
- * the last character (like what happens when typing and
- * reaching the right window edge). */
- wcol = (csize / width + 1) * width - 1;
- }
- }
-
- ptr = line;
- while (col <= wcol && *ptr != NUL) {
- /* Count a tab for what it's worth (if list mode not on) */
- csize = win_lbr_chartabsize(curwin, ptr, col, &head);
- mb_ptr_adv(ptr);
- col += csize;
- }
- idx = (int)(ptr - line);
- /*
- * Handle all the special cases. The virtual_active() check
- * is needed to ensure that a virtual position off the end of
- * a line has the correct indexing. The one_more comparison
- * replaces an explicit add of one_more later on.
- */
- if (col > wcol || (!virtual_active() && one_more == 0)) {
- idx -= 1;
- /* Don't count the chars from 'showbreak'. */
- csize -= head;
- col -= csize;
- }
-
- if (virtual_active()
- && addspaces
- && ((col != wcol && col != wcol + 1) || csize > 1)) {
- /* 'virtualedit' is set: The difference between wcol and col is
- * filled with spaces. */
-
- if (line[idx] == NUL) {
- /* Append spaces */
- int correct = wcol - col;
- char_u *newline = xmalloc(idx + correct + 1);
- int t;
-
- for (t = 0; t < idx; ++t)
- newline[t] = line[t];
-
- for (t = 0; t < correct; ++t)
- newline[t + idx] = ' ';
-
- newline[idx + correct] = NUL;
-
- ml_replace(pos->lnum, newline, FALSE);
- changed_bytes(pos->lnum, (colnr_T)idx);
- idx += correct;
- col = wcol;
- } else {
- /* Break a tab */
- int linelen = (int)STRLEN(line);
- int correct = wcol - col - csize + 1; /* negative!! */
- char_u *newline;
- int t, s = 0;
- int v;
-
- if (-correct > csize)
- return FAIL;
-
- newline = xmalloc(linelen + csize);
-
- for (t = 0; t < linelen; t++) {
- if (t != idx)
- newline[s++] = line[t];
- else
- for (v = 0; v < csize; v++)
- newline[s++] = ' ';
- }
-
- newline[linelen + csize - 1] = NUL;
-
- ml_replace(pos->lnum, newline, FALSE);
- changed_bytes(pos->lnum, idx);
- idx += (csize - 1 + correct);
- col += correct;
- }
- }
- }
-
- if (idx < 0)
- pos->col = 0;
- else
- pos->col = idx;
-
- pos->coladd = 0;
-
- if (finetune) {
- if (wcol == MAXCOL) {
- /* The width of the last character is used to set coladd. */
- if (!one_more) {
- colnr_T scol, ecol;
-
- getvcol(curwin, pos, &scol, NULL, &ecol);
- pos->coladd = ecol - scol;
- }
- } else {
- int b = (int)wcol - (int)col;
-
- /* The difference between wcol and col is used to set coladd. */
- if (b > 0 && b < (MAXCOL - 2 * W_WIDTH(curwin)))
- pos->coladd = b;
-
- col += b;
- }
- }
-
- /* prevent from moving onto a trail byte */
- if (has_mbyte)
- mb_adjustpos(curbuf, pos);
-
- if (col < wcol)
- return FAIL;
- return OK;
-}
-
-/*
- * Increment the cursor position. See inc() for return values.
- */
-int inc_cursor(void)
-{
- return inc(&curwin->w_cursor);
-}
-
-/*
* Increment the line pointer "lp" crossing line boundaries as necessary.
* Return 1 when going to the next line.
* Return 2 when moving forward onto a NUL at the end of the line).
@@ -362,17 +110,6 @@ int incl(pos_T *lp)
return r;
}
-/*
- * dec(p)
- *
- * Decrement the line pointer 'p' crossing line boundaries as necessary.
- * Return 1 when crossing a line, -1 when at start of file, 0 otherwise.
- */
-int dec_cursor(void)
-{
- return dec(&curwin->w_cursor);
-}
-
int dec(pos_T *lp)
{
char_u *p;
@@ -410,188 +147,6 @@ int decl(pos_T *lp)
}
/*
- * 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 (
- win_T *wp,
- linenr_T lnum /* line number to get the result for */
-)
-{
- linenr_T cursor = wp->w_cursor.lnum;
- linenr_T retval = 0;
-
- if (hasAnyFolding(wp)) {
- if (lnum > cursor) {
- while (lnum > cursor) {
- (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, 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)hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL);
- /* if lnum and cursor are in the same fold,
- * now lnum >= cursor */
- if (lnum < cursor)
- retval--;
- lnum++;
- }
- }
- /* else if (lnum == cursor)
- * retval = 0;
- */
- } else
- retval = lnum - cursor;
-
- return retval;
-}
-
-/*
- * Make sure curwin->w_cursor.lnum is valid.
- */
-void check_cursor_lnum(void)
-{
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
- /* If there is a closed fold at the end of the file, put the cursor in
- * its first line. Otherwise in the last line. */
- if (!hasFolding(curbuf->b_ml.ml_line_count,
- &curwin->w_cursor.lnum, NULL))
- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- }
- if (curwin->w_cursor.lnum <= 0)
- curwin->w_cursor.lnum = 1;
-}
-
-/*
- * Make sure curwin->w_cursor.col is valid.
- */
-void check_cursor_col(void)
-{
- check_cursor_col_win(curwin);
-}
-
-/*
- * Make sure win->w_cursor.col is valid.
- */
-void check_cursor_col_win(win_T *win)
-{
- colnr_T len;
- colnr_T oldcol = win->w_cursor.col;
- colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
-
- len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE));
- if (len == 0)
- win->w_cursor.col = 0;
- else if (win->w_cursor.col >= len) {
- /* Allow cursor past end-of-line when:
- * - in Insert mode or restarting Insert mode
- * - in Visual mode and 'selection' isn't "old"
- * - 'virtualedit' is set */
- if ((State & INSERT) || restart_edit
- || (VIsual_active && *p_sel != 'o')
- || (ve_flags & VE_ONEMORE)
- || virtual_active())
- win->w_cursor.col = len;
- else {
- win->w_cursor.col = len - 1;
- /* Move the cursor to the head byte. */
- if (has_mbyte)
- mb_adjustpos(win->w_buffer, &win->w_cursor);
- }
- } else if (win->w_cursor.col < 0)
- win->w_cursor.col = 0;
-
- /* If virtual editing is on, we can leave the cursor on the old position,
- * only we must set it to virtual. But don't do it when at the end of the
- * line. */
- if (oldcol == MAXCOL)
- win->w_cursor.coladd = 0;
- else if (ve_flags == VE_ALL) {
- if (oldcoladd > win->w_cursor.col)
- win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
- else
- /* avoid weird number when there is a miscalculation or overflow */
- win->w_cursor.coladd = 0;
- }
-}
-
-/*
- * make sure curwin->w_cursor in on a valid character
- */
-void check_cursor(void)
-{
- check_cursor_lnum();
- check_cursor_col();
-}
-
-/*
- * Make sure curwin->w_cursor is not on the NUL at the end of the line.
- * Allow it when in Visual mode and 'selection' is not "old".
- */
-void adjust_cursor_col(void)
-{
- if (curwin->w_cursor.col > 0
- && (!VIsual_active || *p_sel == 'o')
- && gchar_cursor() == NUL)
- --curwin->w_cursor.col;
-}
-
-/*
- * When curwin->w_leftcol has changed, adjust the cursor position.
- * Return TRUE if the cursor was moved.
- */
-int leftcol_changed(void)
-{
- long lastcol;
- colnr_T s, e;
- int retval = FALSE;
-
- changed_cline_bef_curs();
- lastcol = curwin->w_leftcol + W_WIDTH(curwin) - curwin_col_off() - 1;
- validate_virtcol();
-
- /*
- * If the cursor is right or left of the screen, move it to last or first
- * character.
- */
- if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso)) {
- retval = TRUE;
- coladvance((colnr_T)(lastcol - p_siso));
- } else if (curwin->w_virtcol < curwin->w_leftcol + p_siso) {
- retval = TRUE;
- (void)coladvance((colnr_T)(curwin->w_leftcol + p_siso));
- }
-
- /*
- * If the start of the character under the cursor is not on the screen,
- * advance the cursor one more char. If this fails (last char of the
- * line) adjust the scrolling.
- */
- getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
- if (e > (colnr_T)lastcol) {
- retval = TRUE;
- coladvance(s - 1);
- } else if (s < curwin->w_leftcol) {
- retval = TRUE;
- if (coladvance(e + 1) == FAIL) { /* there isn't another character */
- curwin->w_leftcol = s; /* adjust w_leftcol instead */
- changed_cline_bef_curs();
- }
- }
-
- if (retval)
- curwin->w_set_curswant = TRUE;
- redraw_later(NOT_VALID);
- return retval;
-}
-
-/*
* Return TRUE when 'shell' has "csh" in the tail.
*/
int csh_like_shell(void)
diff --git a/src/nvim/misc2.h b/src/nvim/misc2.h
index 71a55bb94a..b94e35e258 100644
--- a/src/nvim/misc2.h
+++ b/src/nvim/misc2.h
@@ -6,24 +6,10 @@
/* misc2.c */
int virtual_active(void);
-int getviscol(void);
-int getviscol2(colnr_T col, colnr_T coladd);
-int coladvance_force(colnr_T wcol);
-int coladvance(colnr_T wcol);
-int getvpos(pos_T *pos, colnr_T wcol);
-int inc_cursor(void);
int inc(pos_T *lp);
int incl(pos_T *lp);
-int dec_cursor(void);
int dec(pos_T *lp);
int decl(pos_T *lp);
-linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum);
-void check_cursor_lnum(void);
-void check_cursor_col(void);
-void check_cursor_col_win(win_T *win);
-void check_cursor(void);
-void adjust_cursor_col(void);
-int leftcol_changed(void);
int csh_like_shell(void);
int copy_option_part(char_u **option, char_u *buf, int maxlen,
char *sep_chars);
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 758275578f..f744e1b812 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -19,6 +19,7 @@
#include "nvim/vim.h"
#include "nvim/move.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/fold.h"
@@ -797,7 +798,7 @@ curs_columns (
/* When cursor wraps to first char of next line in Insert
* mode, the 'showbreak' string isn't shown, backup to first
* column */
- if (*p_sbr && *ml_get_cursor() == NUL
+ if (*p_sbr && *get_cursor_pos_ptr() == NUL
&& curwin->w_wcol == (int)vim_strsize(p_sbr))
curwin->w_wcol = 0;
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index b505c349ae..210fc1227c 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -18,6 +18,7 @@
#include "nvim/normal.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
@@ -1348,7 +1349,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
oap->start.col = 0;
if (hasFolding(curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum))
- curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline());
+ curwin->w_cursor.col = (colnr_T)STRLEN(get_cursor_line_ptr());
}
oap->end = curwin->w_cursor;
curwin->w_cursor = oap->start;
@@ -2518,9 +2519,9 @@ do_mouse (
find_end_of_word(&VIsual);
} else {
find_start_of_word(&VIsual);
- if (*p_sel == 'e' && *ml_get_cursor() != NUL)
+ if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL)
curwin->w_cursor.col +=
- (*mb_ptr2len)(ml_get_cursor());
+ (*mb_ptr2len)(get_cursor_pos_ptr());
find_end_of_word(&curwin->w_cursor);
}
}
@@ -2982,9 +2983,9 @@ void clear_showcmd(void)
if (cursor_bot) {
s = ml_get_pos(&VIsual);
- e = ml_get_cursor();
+ e = get_cursor_pos_ptr();
} else {
- s = ml_get_cursor();
+ s = get_cursor_pos_ptr();
e = ml_get_pos(&VIsual);
}
while ((*p_sel != 'e') ? s <= e : s < e) {
@@ -3405,7 +3406,8 @@ find_decl (
par_pos = curwin->w_cursor;
} else {
par_pos = curwin->w_cursor;
- while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL)
+ while (curwin->w_cursor.lnum > 1
+ && *skipwhite(get_cursor_line_ptr()) != NUL)
--curwin->w_cursor.lnum;
}
curwin->w_cursor.col = 0;
@@ -3437,7 +3439,7 @@ find_decl (
}
break;
}
- if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) {
+ if (get_leader_len(get_cursor_line_ptr(), NULL, FALSE, TRUE) > 0) {
/* Ignore this line, continue at start of next line. */
++curwin->w_cursor.lnum;
curwin->w_cursor.col = 0;
@@ -3483,7 +3485,7 @@ find_decl (
*/
static int nv_screengo(oparg_T *oap, int dir, long dist)
{
- int linelen = linetabsize(ml_get_curline());
+ int linelen = linetabsize(get_cursor_line_ptr());
int retval = OK;
int atend = FALSE;
int n;
@@ -3544,7 +3546,7 @@ static int nv_screengo(oparg_T *oap, int dir, long dist)
if (!(fdo_flags & FDO_ALL))
(void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
- linelen = linetabsize(ml_get_curline());
+ linelen = linetabsize(get_cursor_line_ptr());
if (linelen > width1)
curwin->w_curswant += (((linelen - width1 - 1) / width2)
+ 1) * width2;
@@ -3568,7 +3570,7 @@ static int nv_screengo(oparg_T *oap, int dir, long dist)
}
curwin->w_cursor.lnum++;
curwin->w_curswant %= width2;
- linelen = linetabsize(ml_get_curline());
+ linelen = linetabsize(get_cursor_line_ptr());
}
}
}
@@ -4369,7 +4371,7 @@ static void nv_ident(cmdarg_T *cap)
* it was.
*/
setpcmark();
- curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline());
+ curwin->w_cursor.col = (colnr_T) (ptr - get_cursor_line_ptr());
if (!g_cmd && vim_iswordp(ptr))
STRCPY(buf, "\\<");
@@ -4482,7 +4484,7 @@ static void nv_ident(cmdarg_T *cap)
*/
if (cmdchar == '*' || cmdchar == '#') {
if (!g_cmd && (
- has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) :
+ has_mbyte ? vim_iswordp(mb_prevptr(get_cursor_line_ptr(), ptr)) :
vim_iswordc(ptr[-1])))
STRCAT(buf, "\\>");
/* put pattern in search history */
@@ -4514,7 +4516,7 @@ get_visual_text (
return FAIL;
}
if (VIsual_mode == 'V') {
- *pp = ml_get_curline();
+ *pp = get_cursor_line_ptr();
*lenp = (int)STRLEN(*pp);
} else {
if (lt(curwin->w_cursor, VIsual)) {
@@ -4644,7 +4646,7 @@ static void nv_right(cmdarg_T *cap)
for (n = cap->count1; n > 0; --n) {
if ((!PAST_LINE && oneright() == FAIL)
- || (PAST_LINE && *ml_get_cursor() == NUL)
+ || (PAST_LINE && *get_cursor_pos_ptr() == NUL)
) {
/*
* <Space> wraps to next line if 'whichwrap' has 's'.
@@ -4690,7 +4692,7 @@ static void nv_right(cmdarg_T *cap)
else {
if (has_mbyte)
curwin->w_cursor.col +=
- (*mb_ptr2len)(ml_get_cursor());
+ (*mb_ptr2len)(get_cursor_pos_ptr());
else
++curwin->w_cursor.col;
}
@@ -4745,7 +4747,7 @@ static void nv_left(cmdarg_T *cap)
if ( (cap->oap->op_type == OP_DELETE
|| cap->oap->op_type == OP_CHANGE)
&& !lineempty(curwin->w_cursor.lnum)) {
- char_u *cp = ml_get_cursor();
+ char_u *cp = get_cursor_pos_ptr();
if (*cp != NUL) {
if (has_mbyte) {
@@ -5469,7 +5471,7 @@ static void nv_replace(cmdarg_T *cap)
}
/* Abort if not enough characters to replace. */
- ptr = ml_get_cursor();
+ ptr = get_cursor_pos_ptr();
if (STRLEN(ptr) < (unsigned)cap->count1
|| (has_mbyte && mb_charlen(ptr) < cap->count1)
) {
@@ -6308,7 +6310,7 @@ static void nv_g_cmd(cmdarg_T *cap)
cap->oap->op_type == OP_NOP) == FAIL)
clearopbeep(cap->oap);
else {
- char_u *ptr = ml_get_curline();
+ char_u *ptr = get_cursor_line_ptr();
/* In Visual mode we may end up after the line. */
if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL)
@@ -6412,7 +6414,7 @@ static void nv_g_cmd(cmdarg_T *cap)
if (curbuf->b_last_insert.lnum != 0) {
curwin->w_cursor = curbuf->b_last_insert;
check_cursor_lnum();
- i = (int)STRLEN(ml_get_curline());
+ i = (int)STRLEN(get_cursor_line_ptr());
if (curwin->w_cursor.col > (colnr_T)i) {
if (virtual_active())
curwin->w_cursor.coladd += curwin->w_cursor.col - i;
@@ -7116,7 +7118,7 @@ static void nv_edit(cmdarg_T *cap)
coladvance((colnr_T)MAXCOL);
State = save_State;
} else
- curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
+ curwin->w_cursor.col += (colnr_T)STRLEN(get_cursor_pos_ptr());
break;
case 'I': /* "I"nsert before the first non-blank */
@@ -7131,10 +7133,10 @@ static void nv_edit(cmdarg_T *cap)
* column otherwise, also to append after an unprintable char */
if (virtual_active()
&& (curwin->w_cursor.coladd > 0
- || *ml_get_cursor() == NUL
- || *ml_get_cursor() == TAB))
+ || *get_cursor_pos_ptr() == NUL
+ || *get_cursor_pos_ptr() == TAB))
curwin->w_cursor.coladd++;
- else if (*ml_get_cursor() != NUL)
+ else if (*get_cursor_pos_ptr() != NUL)
inc_cursor();
break;
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 05ca402d39..4c5a9fdf63 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -17,6 +17,7 @@
#include "nvim/ops.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -211,7 +212,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
block_col = curwin->w_cursor.col;
for (i = oap->line_count; --i >= 0; ) {
- first_char = *ml_get_curline();
+ first_char = *get_cursor_line_ptr();
if (first_char == NUL) /* empty line */
curwin->w_cursor.col = 0;
else if (oap->block_mode)
@@ -344,7 +345,7 @@ static void shift_block(oparg_T *oap, int amount)
/* total is number of screen columns to be inserted/removed */
total = amount * p_sw;
- oldp = ml_get_curline();
+ oldp = get_cursor_line_ptr();
if (!left) {
/*
@@ -597,7 +598,7 @@ int (*how)(void);
*/
if (i != oap->line_count - 1 || oap->line_count == 1
|| how != get_lisp_indent) {
- l = skipwhite(ml_get_curline());
+ l = skipwhite(get_cursor_line_ptr());
if (*l == NUL) /* empty or blank line */
count = 0;
else
@@ -1562,7 +1563,7 @@ int op_delete(oparg_T *oap)
/* fix up things for virtualedit-delete:
* break the tabs which are going to get in our way
*/
- char_u *curline = ml_get_curline();
+ char_u *curline = get_cursor_line_ptr();
int len = (int)STRLEN(curline);
if (oap->end.coladd != 0
@@ -1743,7 +1744,7 @@ int op_replace(oparg_T *oap, int c)
/* oldlen includes textlen, so don't double count */
n += numc - bd.textlen;
- oldp = ml_get_curline();
+ oldp = get_cursor_line_ptr();
oldlen = STRLEN(oldp);
newp = (char_u *) xmalloc((size_t)(oldlen + 1 + n));
memset(newp, NUL, (size_t)(oldlen + 1 + n));
@@ -2011,7 +2012,7 @@ int swapchar(int op_type, pos_T *pos)
curwin->w_cursor = *pos;
/* don't use del_char(), it also removes composing chars */
- del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE);
+ del_bytes(utf_ptr2len(get_cursor_pos_ptr()), FALSE, FALSE);
ins_char(nc);
curwin->w_cursor = sp;
} else
@@ -2069,7 +2070,7 @@ void op_insert(oparg_T *oap, long count1)
) {
/* Move the cursor to the character right of the block. */
curwin->w_set_curswant = TRUE;
- while (*ml_get_cursor() != NUL
+ while (*get_cursor_pos_ptr() != NUL
&& (curwin->w_cursor.col < bd.textcol + bd.textlen))
++curwin->w_cursor.col;
if (bd.is_short && !bd.is_MAX) {
@@ -2686,11 +2687,11 @@ do_put (
* between. */
if (u_save_cursor() == FAIL)
goto end;
- ptr = vim_strsave(ml_get_cursor());
+ ptr = vim_strsave(get_cursor_pos_ptr());
ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE);
free(ptr);
- ptr = vim_strnsave(ml_get_curline(), curwin->w_cursor.col);
+ ptr = vim_strnsave(get_cursor_line_ptr(), curwin->w_cursor.col);
ml_replace(curwin->w_cursor.lnum, ptr, FALSE);
++nr_lines;
dir = FORWARD;
@@ -2775,7 +2776,7 @@ do_put (
if (has_mbyte)
/* move to start of next multi-byte character */
- curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
+ curwin->w_cursor.col += (*mb_ptr2len)(get_cursor_pos_ptr());
else if (c != TAB || ve_flags != VE_ALL)
++curwin->w_cursor.col;
++col;
@@ -2816,7 +2817,7 @@ do_put (
++nr_lines;
}
/* get the old line and advance to the position to insert at */
- oldp = ml_get_curline();
+ oldp = get_cursor_line_ptr();
oldlen = (int)STRLEN(oldp);
for (ptr = oldp; vcol < col && *ptr; ) {
/* Count a tab for what it's worth (if list mode not on) */
@@ -2905,7 +2906,7 @@ do_put (
curwin->w_cursor.col++;
/* in Insert mode we might be after the NUL, correct for that */
- len = (colnr_T)STRLEN(ml_get_curline());
+ len = (colnr_T)STRLEN(get_cursor_line_ptr());
if (curwin->w_cursor.col > len)
curwin->w_cursor.col = len;
} else
@@ -2919,7 +2920,7 @@ do_put (
* char */
if (dir == FORWARD && gchar_cursor() != NUL) {
if (has_mbyte) {
- int bytelen = (*mb_ptr2len)(ml_get_cursor());
+ int bytelen = (*mb_ptr2len)(get_cursor_pos_ptr());
/* put it on the next of the multi-byte character. */
col += bytelen;
@@ -3950,7 +3951,7 @@ format_lines (
mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
(long)-next_leader_len);
} else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */
- char_u *p = ml_get_curline();
+ char_u *p = get_cursor_line_ptr();
int indent = (int)(skipwhite(p) - p);
if (indent > 0) {
@@ -3966,7 +3967,7 @@ format_lines (
}
first_par_line = FALSE;
/* If the line is getting long, format it next time */
- if (STRLEN(ml_get_curline()) > (size_t)max_len)
+ if (STRLEN(get_cursor_line_ptr()) > (size_t)max_len)
force_format = TRUE;
else
force_format = FALSE;
@@ -4240,7 +4241,7 @@ int do_addsub(int command, linenr_T Prenum1)
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */
doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
RLADDSUBFIX(ptr);
/*
@@ -4289,7 +4290,7 @@ int do_addsub(int command, linenr_T Prenum1)
}
/* get ptr again, because u_save() may have changed it */
- ptr = ml_get_curline();
+ ptr = get_cursor_line_ptr();
RLADDSUBFIX(ptr);
if (doalp && ASCII_ISALPHA(firstdigit)) {
@@ -5118,7 +5119,7 @@ void cursor_pos_info(void)
(int64_t)char_count_cursor, (int64_t)char_count,
(int64_t)byte_count_cursor, (int64_t)byte_count);
} else {
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
validate_virtcol();
col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1,
(int)curwin->w_virtcol + 1);
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 33d146161b..5934f57dc8 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -39,6 +39,7 @@
#include "nvim/option.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 269a33edcc..cba6b5f94d 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -16,6 +16,7 @@
#include "nvim/quickfix.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -1638,7 +1639,7 @@ win_found:
* found, reduce the error column value by the length of
* a tab character.
*/
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
screen_col = 0;
for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) {
if (*line == NUL)
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index f4616d3b8e..e14f7d20d3 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -93,6 +93,7 @@
#include "nvim/screen.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -6779,7 +6780,7 @@ void setcursor(void)
* character, position it on the leftmost column. */
curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - (
(has_mbyte
- && (*mb_ptr2cells)(ml_get_cursor()) == 2
+ && (*mb_ptr2cells)(get_cursor_pos_ptr()) == 2
&& vim_isprintc(gchar_cursor())) ? 2 :
1)) :
curwin->w_wcol));
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 9d37aa3339..fc741955da 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -14,6 +14,7 @@
#include "nvim/vim.h"
#include "nvim/search.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -1338,7 +1339,7 @@ int searchc(cmdarg_T *cap, int t_cmd)
else
cap->oap->inclusive = TRUE;
- p = ml_get_curline();
+ p = get_cursor_line_ptr();
col = curwin->w_cursor.col;
len = (int)STRLEN(p);
@@ -2415,7 +2416,7 @@ fwd_word (
/*
* We'll stop if we land on a blank line
*/
- if (curwin->w_cursor.col == 0 && *ml_get_curline() == NUL)
+ if (curwin->w_cursor.col == 0 && *get_cursor_line_ptr() == NUL)
break;
i = inc_cursor();
@@ -3098,7 +3099,7 @@ static int in_html_tag(int);
*/
static int in_html_tag(int end_tag)
{
- char_u *line = ml_get_curline();
+ char_u *line = get_cursor_line_ptr();
char_u *p;
int c;
int lc = NUL;
@@ -3201,12 +3202,12 @@ current_tagblock (
if (in_html_tag(FALSE)) {
/* cursor on start tag, move to its '>' */
- while (*ml_get_cursor() != '>')
+ while (*get_cursor_pos_ptr() != '>')
if (inc_cursor() < 0)
break;
} else if (in_html_tag(TRUE)) {
/* cursor on end tag, move to just before it */
- while (*ml_get_cursor() != '<')
+ while (*get_cursor_pos_ptr() != '<')
if (dec_cursor() < 0)
break;
dec_cursor();
@@ -3239,7 +3240,7 @@ again:
* Search for matching "</aaa>". First isolate the "aaa".
*/
inc_cursor();
- p = ml_get_cursor();
+ p = get_cursor_pos_ptr();
for (cp = p; *cp != NUL && *cp != '>' && !vim_iswhite(*cp); mb_ptr_adv(cp))
;
len = (int)(cp - p);
@@ -3269,12 +3270,12 @@ again:
if (do_include || r < 1) {
/* Include up to the '>'. */
- while (*ml_get_cursor() != '>')
+ while (*get_cursor_pos_ptr() != '>')
if (inc_cursor() < 0)
break;
} else {
/* Exclude the '<' of the end tag. */
- if (*ml_get_cursor() == '<')
+ if (*get_cursor_pos_ptr() == '<')
dec_cursor();
}
end_pos = curwin->w_cursor;
@@ -3283,7 +3284,7 @@ again:
/* Exclude the start tag. */
curwin->w_cursor = start_pos;
while (inc_cursor() >= 0)
- if (*ml_get_cursor() == '>') {
+ if (*get_cursor_pos_ptr() == '>') {
inc_cursor();
start_pos = curwin->w_cursor;
break;
@@ -3566,7 +3567,7 @@ current_quote (
int quotechar /* Quote character */
)
{
- char_u *line = ml_get_curline();
+ char_u *line = get_cursor_line_ptr();
int col_end;
int col_start = curwin->w_cursor.col;
int inclusive = FALSE;
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 1fe957d17c..901115e55f 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -291,6 +291,7 @@
#include "nvim/spell.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -8647,7 +8648,7 @@ void spell_suggest(int count)
// No bad word or it starts after the cursor: use the word under the
// cursor.
curwin->w_cursor = prev_cursor;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
p = line + curwin->w_cursor.col;
// Backup to before start of word.
while (p > line && spell_iswordp_nmw(p, curwin))
@@ -8669,7 +8670,7 @@ void spell_suggest(int count)
need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col);
// Make a copy of current line since autocommands may free the line.
- line = vim_strsave(ml_get_curline());
+ line = vim_strsave(get_cursor_line_ptr());
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
// 'spellsuggest', whatever is smaller.
@@ -8823,7 +8824,7 @@ static int check_need_cap(linenr_T lnum, colnr_T col)
if (curwin->w_s->b_cap_prog == NULL)
return FALSE;
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
endcol = 0;
if ((int)(skipwhite(line) - line) >= (int)col) {
// At start of line, check if previous line is empty or sentence
@@ -8898,7 +8899,7 @@ void ex_spellrepall(exarg_T *eap)
// Only replace when the right word isn't there yet. This happens
// when changing "etc" to "etc.".
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
repl_to, STRLEN(repl_to)) != 0) {
p = xmalloc(STRLEN(line) + addlen + 1);
@@ -13547,7 +13548,7 @@ int spell_word_start(int startcol)
return startcol;
// Find a word character before "startcol".
- line = ml_get_curline();
+ line = get_cursor_line_ptr();
for (p = line + startcol; p > line; ) {
mb_ptr_back(line, p);
if (spell_iswordp_nmw(p, curwin))
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index a87210cbb8..3b1610682b 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -16,6 +16,7 @@
#include "nvim/tag.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 6d27822bc0..ef61117126 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -19,6 +19,7 @@
#include "nvim/vim.h"
#include "nvim/ui.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/ex_cmds2.h"
#include "nvim/fold.h"
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 805dfa547c..42804210d0 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -84,6 +84,7 @@
#include "nvim/vim.h"
#include "nvim/undo.h"
+#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/fileio.h"
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 534805b766..6f97401a80 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -11,6 +11,7 @@
#include "nvim/window.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
@@ -4772,7 +4773,7 @@ char_u *grab_file_name(long count, linenr_T *file_lnum)
*/
char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum)
{
- return file_name_in_line(ml_get_curline(),
+ return file_name_in_line(get_cursor_line_ptr(),
curwin->w_cursor.col, options, count, curbuf->b_ffname,
file_lnum);
}