aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/textobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/textobject.c')
-rw-r--r--src/nvim/textobject.c94
1 files changed, 51 insertions, 43 deletions
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index 02174edeb1..ee6c39a8ba 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -4,8 +4,11 @@
// textobject.c: functions for text objects
#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
#include "nvim/ascii.h"
+#include "nvim/buffer_defs.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"
@@ -13,14 +16,19 @@
#include "nvim/fold.h"
#include "nvim/globals.h"
#include "nvim/indent.h"
+#include "nvim/macros.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
+#include "nvim/memory.h"
#include "nvim/normal.h"
+#include "nvim/option_defs.h"
#include "nvim/pos.h"
+#include "nvim/screen.h"
#include "nvim/search.h"
-#include "nvim/textformat.h"
+#include "nvim/strings.h"
#include "nvim/textobject.h"
+#include "nvim/types.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -213,11 +221,11 @@ bool findpar(bool *pincl, int dir, long count, int what, bool both)
}
curwin->w_cursor.lnum = curr;
if (curr == curbuf->b_ml.ml_line_count && what != '}') {
- char_u *line = ml_get(curr);
+ char *line = ml_get(curr);
// Put the cursor on the last character in the last line and make the
// motion inclusive.
- if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) {
+ if ((curwin->w_cursor.col = (colnr_T)strlen(line)) != 0) {
curwin->w_cursor.col--;
curwin->w_cursor.col -= utf_head_off(line, line + curwin->w_cursor.col);
*pincl = true;
@@ -229,9 +237,9 @@ bool findpar(bool *pincl, int dir, long count, int what, bool both)
}
/// check if the string 's' is a nroff macro that is in option 'opt'
-static bool inmacro(char_u *opt, char_u *s)
+static bool inmacro(char *opt, const char *s)
{
- char_u *macro;
+ char *macro;
for (macro = opt; macro[0]; macro++) {
// Accept two characters in the option being equal to two characters
@@ -258,14 +266,14 @@ static bool inmacro(char_u *opt, char_u *s)
/// If 'both' is true also stop at '}'
bool startPS(linenr_T lnum, int para, bool both)
{
- char_u *s;
+ char *s;
s = ml_get(lnum);
- if (*s == para || *s == '\f' || (both && *s == '}')) {
+ if ((uint8_t)(*s) == para || *s == '\f' || (both && *s == '}')) {
return true;
}
- if (*s == '.' && (inmacro((char_u *)p_sections, s + 1)
- || (!para && inmacro(p_para, s + 1)))) {
+ if (*s == '.' && (inmacro(p_sections, s + 1)
+ || (!para && inmacro((char *)p_para, s + 1)))) {
return true;
}
return false;
@@ -1032,8 +1040,8 @@ int current_block(oparg_T *oap, long count, bool include, int what, int other)
/// @return true if the cursor is on a "<aaa>" tag. Ignore "<aaa/>".
static bool in_html_tag(bool end_tag)
{
- char_u *line = get_cursor_line_ptr();
- char_u *p;
+ char *line = get_cursor_line_ptr();
+ char *p;
int c;
int lc = NUL;
pos_T pos;
@@ -1089,8 +1097,8 @@ int current_tagblock(oparg_T *oap, long count_arg, bool include)
pos_T start_pos;
pos_T end_pos;
pos_T old_start, old_end;
- char_u *p;
- char_u *cp;
+ char *p;
+ char *cp;
int len;
bool do_include = include;
bool save_p_ws = p_ws;
@@ -1196,7 +1204,7 @@ again:
}
}
} else {
- char_u *c = get_cursor_pos_ptr();
+ char *c = get_cursor_pos_ptr();
// Exclude the '<' of the end tag.
// If the closing tag is on new line, do not decrement cursor, but make
// operation exclusive, so that the linefeed will be selected
@@ -1433,15 +1441,15 @@ extend:
/// @param escape escape characters, can be NULL
///
/// @return column number of "quotechar" or -1 when not found.
-static int find_next_quote(char_u *line, int col, int quotechar, char_u *escape)
+static int find_next_quote(char *line, int col, int quotechar, char *escape)
{
int c;
for (;;) {
- c = line[col];
+ c = (uint8_t)line[col];
if (c == NUL) {
return -1;
- } else if (escape != NULL && vim_strchr((char *)escape, c)) {
+ } else if (escape != NULL && vim_strchr(escape, c)) {
col++;
if (line[col] == NUL) {
return -1;
@@ -1449,7 +1457,7 @@ static int find_next_quote(char_u *line, int col, int quotechar, char_u *escape)
} else if (c == quotechar) {
break;
}
- col += utfc_ptr2len((char *)line + col);
+ col += utfc_ptr2len(line + col);
}
return col;
}
@@ -1461,7 +1469,7 @@ static int find_next_quote(char_u *line, int col, int quotechar, char_u *escape)
/// @param escape escape characters, can be NULL
///
/// @return the found column or zero.
-static int find_prev_quote(char_u *line, int col_start, int quotechar, char_u *escape)
+static int find_prev_quote(char *line, int col_start, int quotechar, char *escape)
{
int n;
@@ -1470,14 +1478,14 @@ static int find_prev_quote(char_u *line, int col_start, int quotechar, char_u *e
col_start -= utf_head_off(line, line + col_start);
n = 0;
if (escape != NULL) {
- while (col_start - n > 0 && vim_strchr((char *)escape,
- line[col_start - n - 1]) != NULL) {
+ while (col_start - n > 0 && vim_strchr(escape,
+ (uint8_t)line[col_start - n - 1]) != NULL) {
n++;
}
}
if (n & 1) {
col_start -= n; // uneven number of escape chars, skip it
- } else if (line[col_start] == quotechar) {
+ } else if ((uint8_t)line[col_start] == quotechar) {
break;
}
}
@@ -1493,7 +1501,7 @@ static int find_prev_quote(char_u *line, int col_start, int quotechar, char_u *e
bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
FUNC_ATTR_NONNULL_ALL
{
- char_u *line = get_cursor_line_ptr();
+ char *line = get_cursor_line_ptr();
int col_end;
int col_start = curwin->w_cursor.col;
bool inclusive = false;
@@ -1503,7 +1511,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
bool inside_quotes = false; // Looks like "i'" done before
bool selected_quote = false; // Has quote inside selection
int i;
- bool restore_vis_bef = false; // resotre VIsual on abort
+ bool restore_vis_bef = false; // restore VIsual on abort
// When 'selection' is "exclusive" move the cursor to where it would be
// with 'selection' "inclusive", so that the logic is the same for both.
@@ -1542,16 +1550,16 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
// quotes.
if (vis_bef_curs) {
inside_quotes = VIsual.col > 0
- && line[VIsual.col - 1] == quotechar
+ && (uint8_t)line[VIsual.col - 1] == quotechar
&& line[curwin->w_cursor.col] != NUL
- && line[curwin->w_cursor.col + 1] == quotechar;
+ && (uint8_t)line[curwin->w_cursor.col + 1] == quotechar;
i = VIsual.col;
col_end = curwin->w_cursor.col;
} else {
inside_quotes = curwin->w_cursor.col > 0
- && line[curwin->w_cursor.col - 1] == quotechar
+ && (uint8_t)line[curwin->w_cursor.col - 1] == quotechar
&& line[VIsual.col] != NUL
- && line[VIsual.col + 1] == quotechar;
+ && (uint8_t)line[VIsual.col + 1] == quotechar;
i = curwin->w_cursor.col;
col_end = VIsual.col;
}
@@ -1563,14 +1571,14 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
if (line[i] == NUL) {
break;
}
- if (line[i++] == quotechar) {
+ if ((uint8_t)line[i++] == quotechar) {
selected_quote = true;
break;
}
}
}
- if (!vis_empty && line[col_start] == quotechar) {
+ if (!vis_empty && (uint8_t)line[col_start] == quotechar) {
// Already selecting something and on a quote character. Find the
// next quoted string.
if (vis_bef_curs) {
@@ -1580,7 +1588,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
if (col_start < 0) {
goto abort_search;
}
- col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe);
+ col_end = find_next_quote(line, col_start + 1, quotechar, curbuf->b_p_qe);
if (col_end < 0) {
// We were on a starting quote perhaps?
col_end = col_start;
@@ -1588,17 +1596,17 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
}
} else {
col_end = find_prev_quote(line, col_start, quotechar, NULL);
- if (line[col_end] != quotechar) {
+ if ((uint8_t)line[col_end] != quotechar) {
goto abort_search;
}
- col_start = find_prev_quote(line, col_end, quotechar, (char_u *)curbuf->b_p_qe);
- if (line[col_start] != quotechar) {
+ col_start = find_prev_quote(line, col_end, quotechar, curbuf->b_p_qe);
+ if ((uint8_t)line[col_start] != quotechar) {
// We were on an ending quote perhaps?
col_start = col_end;
col_end = curwin->w_cursor.col;
}
}
- } else if (line[col_start] == quotechar || !vis_empty) {
+ } else if ((uint8_t)line[col_start] == quotechar || !vis_empty) {
int first_col = col_start;
if (!vis_empty) {
@@ -1620,7 +1628,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
goto abort_search;
}
// Find close quote character.
- col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe);
+ col_end = find_next_quote(line, col_start + 1, quotechar, curbuf->b_p_qe);
if (col_end < 0) {
goto abort_search;
}
@@ -1633,8 +1641,8 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
}
} else {
// Search backward for a starting quote.
- col_start = find_prev_quote(line, col_start, quotechar, (char_u *)curbuf->b_p_qe);
- if (line[col_start] != quotechar) {
+ col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe);
+ if ((uint8_t)line[col_start] != quotechar) {
// No quote before the cursor, look after the cursor.
col_start = find_next_quote(line, col_start, quotechar, NULL);
if (col_start < 0) {
@@ -1643,7 +1651,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
}
// Find close quote character.
- col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe);
+ col_end = find_next_quote(line, col_start + 1, quotechar, curbuf->b_p_qe);
if (col_end < 0) {
goto abort_search;
}
@@ -1677,9 +1685,9 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
|| (vis_bef_curs
&& !selected_quote
&& (inside_quotes
- || (line[VIsual.col] != quotechar
+ || ((uint8_t)line[VIsual.col] != quotechar
&& (VIsual.col == 0
- || line[VIsual.col - 1] != quotechar))))) {
+ || (uint8_t)line[VIsual.col - 1] != quotechar))))) {
VIsual = curwin->w_cursor;
redraw_curbuf_later(UPD_INVERTED);
}
@@ -1707,9 +1715,9 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar)
// quote.
if (inside_quotes
|| (!selected_quote
- && line[VIsual.col] != quotechar
+ && (uint8_t)line[VIsual.col] != quotechar
&& (line[VIsual.col] == NUL
- || line[VIsual.col + 1] != quotechar))) {
+ || (uint8_t)line[VIsual.col + 1] != quotechar))) {
dec_cursor();
VIsual = curwin->w_cursor;
}