aboutsummaryrefslogtreecommitdiff
path: root/src/nvim
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/nvim
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/nvim')
-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