mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
vim-patch:8.1.0805: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 1.
135059724f
This commit is contained in:
@@ -3334,9 +3334,7 @@ void maketitle(void)
|
|||||||
len = (int)STRLEN(buf_p);
|
len = (int)STRLEN(buf_p);
|
||||||
if (len > 100) {
|
if (len > 100) {
|
||||||
len -= 100;
|
len -= 100;
|
||||||
if (has_mbyte) {
|
len += (*mb_tail_off)(buf_p, buf_p + len) + 1;
|
||||||
len += (*mb_tail_off)(buf_p, buf_p + len) + 1;
|
|
||||||
}
|
|
||||||
buf_p += len;
|
buf_p += len;
|
||||||
}
|
}
|
||||||
STRCPY(icon_str, buf_p);
|
STRCPY(icon_str, buf_p);
|
||||||
@@ -3661,17 +3659,12 @@ int build_stl_str_hl(
|
|||||||
// truncate by removing bytes from the start of the group text.
|
// truncate by removing bytes from the start of the group text.
|
||||||
if (group_len > stl_items[stl_groupitems[groupdepth]].maxwid) {
|
if (group_len > stl_items[stl_groupitems[groupdepth]].maxwid) {
|
||||||
// { Determine the number of bytes to remove
|
// { Determine the number of bytes to remove
|
||||||
long n;
|
|
||||||
if (has_mbyte) {
|
// Find the first character that should be included.
|
||||||
// Find the first character that should be included.
|
long n = 0;
|
||||||
n = 0;
|
while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) {
|
||||||
while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) {
|
group_len -= ptr2cells(t + n);
|
||||||
group_len -= ptr2cells(t + n);
|
n += (*mb_ptr2len)(t + n);
|
||||||
n += (*mb_ptr2len)(t + n);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
n = (long)(out_p - t)
|
|
||||||
- stl_items[stl_groupitems[groupdepth]].maxwid + 1;
|
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@@ -4183,13 +4176,10 @@ int build_stl_str_hl(
|
|||||||
|
|
||||||
// If the item is too wide, truncate it from the beginning
|
// If the item is too wide, truncate it from the beginning
|
||||||
if (l > maxwid) {
|
if (l > maxwid) {
|
||||||
while (l >= maxwid)
|
while (l >= maxwid) {
|
||||||
if (has_mbyte) {
|
l -= ptr2cells(t);
|
||||||
l -= ptr2cells(t);
|
t += utfc_ptr2len(t);
|
||||||
t += (*mb_ptr2len)(t);
|
}
|
||||||
} else {
|
|
||||||
l -= byte2cells(*t++);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Early out if there isn't enough room for the truncation marker
|
// Early out if there isn't enough room for the truncation marker
|
||||||
if (out_p >= out_end_p) {
|
if (out_p >= out_end_p) {
|
||||||
@@ -4372,26 +4362,19 @@ int build_stl_str_hl(
|
|||||||
// If the truncation point we found is beyond the maximum
|
// If the truncation point we found is beyond the maximum
|
||||||
// length of the string, truncate the end of the string.
|
// length of the string, truncate the end of the string.
|
||||||
if (width - vim_strsize(trunc_p) >= maxwidth) {
|
if (width - vim_strsize(trunc_p) >= maxwidth) {
|
||||||
// If we are using a multi-byte encoding, walk from the beginning of the
|
// Walk from the beginning of the
|
||||||
// string to find the last character that will fit.
|
// string to find the last character that will fit.
|
||||||
if (has_mbyte) {
|
trunc_p = out;
|
||||||
trunc_p = out;
|
width = 0;
|
||||||
width = 0;
|
for (;; ) {
|
||||||
for (;; ) {
|
width += ptr2cells(trunc_p);
|
||||||
width += ptr2cells(trunc_p);
|
if (width >= maxwidth) {
|
||||||
if (width >= maxwidth) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: Only advance the pointer if the next
|
|
||||||
// character will fit in the available output space
|
|
||||||
trunc_p += (*mb_ptr2len)(trunc_p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise put the truncation point at the end, leaving enough room
|
// Note: Only advance the pointer if the next
|
||||||
// for a single-character truncation marker
|
// character will fit in the available output space
|
||||||
} else {
|
trunc_p += utfc_ptr2len(trunc_p);
|
||||||
trunc_p = out + maxwidth - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore any items in the statusline that occur after
|
// Ignore any items in the statusline that occur after
|
||||||
@@ -4410,16 +4393,10 @@ int build_stl_str_hl(
|
|||||||
// Truncate at the truncation point we found
|
// Truncate at the truncation point we found
|
||||||
} else {
|
} else {
|
||||||
// { Determine how many bytes to remove
|
// { Determine how many bytes to remove
|
||||||
long trunc_len;
|
long trunc_len = 0;
|
||||||
if (has_mbyte) {
|
while (width >= maxwidth) {
|
||||||
trunc_len = 0;
|
width -= ptr2cells(trunc_p + trunc_len);
|
||||||
while (width >= maxwidth) {
|
trunc_len += utfc_ptr2len(trunc_p + trunc_len);
|
||||||
width -= ptr2cells(trunc_p + trunc_len);
|
|
||||||
trunc_len += (*mb_ptr2len)(trunc_p + trunc_len);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Truncate an extra character so we can insert our `<`.
|
|
||||||
trunc_len = (width - maxwidth) + 1;
|
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@@ -719,15 +719,12 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
|
|||||||
for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
|
for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
|
||||||
for (s = ml_get_buf(buf, lnum, false); *s != NUL; ) {
|
for (s = ml_get_buf(buf, lnum, false); *s != NUL; ) {
|
||||||
if (diff_flags & DIFF_ICASE) {
|
if (diff_flags & DIFF_ICASE) {
|
||||||
int c;
|
|
||||||
|
|
||||||
// xdiff doesn't support ignoring case, fold-case the text.
|
|
||||||
int orig_len;
|
|
||||||
char_u cbuf[MB_MAXBYTES + 1];
|
char_u cbuf[MB_MAXBYTES + 1];
|
||||||
|
|
||||||
c = PTR2CHAR(s);
|
// xdiff doesn't support ignoring case, fold-case the text.
|
||||||
|
int c = PTR2CHAR(s);
|
||||||
c = utf_fold(c);
|
c = utf_fold(c);
|
||||||
orig_len = utfc_ptr2len(s);
|
const int orig_len = utfc_ptr2len(s);
|
||||||
if (utf_char2bytes(c, cbuf) != orig_len) {
|
if (utf_char2bytes(c, cbuf) != orig_len) {
|
||||||
// TODO(Bram): handle byte length difference
|
// TODO(Bram): handle byte length difference
|
||||||
memmove(ptr + len, s, orig_len);
|
memmove(ptr + len, s, orig_len);
|
||||||
|
156
src/nvim/edit.c
156
src/nvim/edit.c
@@ -426,9 +426,9 @@ static void insert_enter(InsertState *s)
|
|||||||
|| curwin->w_curswant > curwin->w_virtcol)
|
|| curwin->w_curswant > curwin->w_virtcol)
|
||||||
&& *(s->ptr = get_cursor_line_ptr() + curwin->w_cursor.col) != NUL) {
|
&& *(s->ptr = get_cursor_line_ptr() + curwin->w_cursor.col) != NUL) {
|
||||||
if (s->ptr[1] == NUL) {
|
if (s->ptr[1] == NUL) {
|
||||||
++curwin->w_cursor.col;
|
curwin->w_cursor.col++;
|
||||||
} else if (has_mbyte) {
|
} else {
|
||||||
s->i = (*mb_ptr2len)(s->ptr);
|
s->i = utfc_ptr2len(s->ptr);
|
||||||
if (s->ptr[s->i] == NUL) {
|
if (s->ptr[s->i] == NUL) {
|
||||||
curwin->w_cursor.col += s->i;
|
curwin->w_cursor.col += s->i;
|
||||||
}
|
}
|
||||||
@@ -1299,11 +1299,10 @@ normalchar:
|
|||||||
// special character. Let CTRL-] expand abbreviations without
|
// special character. Let CTRL-] expand abbreviations without
|
||||||
// inserting it.
|
// inserting it.
|
||||||
if (vim_iswordc(s->c)
|
if (vim_iswordc(s->c)
|
||||||
|| (!echeck_abbr(
|
|
||||||
// Add ABBR_OFF for characters above 0x100, this is
|
// Add ABBR_OFF for characters above 0x100, this is
|
||||||
// what check_abbr() expects.
|
// what check_abbr() expects.
|
||||||
(has_mbyte && s->c >= 0x100) ? (s->c + ABBR_OFF) : s->c)
|
|| (!echeck_abbr((s->c >= 0x100) ? (s->c + ABBR_OFF) : s->c)
|
||||||
&& s->c != Ctrl_RSB)) {
|
&& s->c != Ctrl_RSB)) {
|
||||||
insert_special(s->c, false, false);
|
insert_special(s->c, false, false);
|
||||||
revins_legal++;
|
revins_legal++;
|
||||||
revins_chars++;
|
revins_chars++;
|
||||||
@@ -1574,14 +1573,12 @@ void edit_putchar(int c, bool highlight)
|
|||||||
pc_status = PC_STATUS_UNSET;
|
pc_status = PC_STATUS_UNSET;
|
||||||
if (curwin->w_p_rl) {
|
if (curwin->w_p_rl) {
|
||||||
pc_col += curwin->w_grid.Columns - 1 - curwin->w_wcol;
|
pc_col += curwin->w_grid.Columns - 1 - curwin->w_wcol;
|
||||||
if (has_mbyte) {
|
const int fix_col = grid_fix_col(&curwin->w_grid, pc_col, pc_row);
|
||||||
int fix_col = grid_fix_col(&curwin->w_grid, pc_col, pc_row);
|
|
||||||
|
|
||||||
if (fix_col != pc_col) {
|
if (fix_col != pc_col) {
|
||||||
grid_putchar(&curwin->w_grid, ' ', pc_row, fix_col, attr);
|
grid_putchar(&curwin->w_grid, ' ', pc_row, fix_col, attr);
|
||||||
curwin->w_wcol--;
|
curwin->w_wcol--;
|
||||||
pc_status = PC_STATUS_RIGHT;
|
pc_status = PC_STATUS_RIGHT;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pc_col += curwin->w_wcol;
|
pc_col += curwin->w_wcol;
|
||||||
@@ -1817,10 +1814,11 @@ change_indent (
|
|||||||
ptr = get_cursor_line_ptr();
|
ptr = get_cursor_line_ptr();
|
||||||
while (vcol <= (int)curwin->w_virtcol) {
|
while (vcol <= (int)curwin->w_virtcol) {
|
||||||
last_vcol = vcol;
|
last_vcol = vcol;
|
||||||
if (has_mbyte && new_cursor_col >= 0)
|
if (new_cursor_col >= 0) {
|
||||||
new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
|
new_cursor_col += utfc_ptr2len(ptr + new_cursor_col);
|
||||||
else
|
} else {
|
||||||
++new_cursor_col;
|
new_cursor_col++;
|
||||||
|
}
|
||||||
vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol);
|
vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol);
|
||||||
}
|
}
|
||||||
vcol = last_vcol;
|
vcol = last_vcol;
|
||||||
@@ -1975,7 +1973,7 @@ void backspace_until_column(int col)
|
|||||||
/// @return true when something was deleted.
|
/// @return true when something was deleted.
|
||||||
static bool del_char_after_col(int limit_col)
|
static bool del_char_after_col(int limit_col)
|
||||||
{
|
{
|
||||||
if (enc_utf8 && limit_col >= 0) {
|
if (limit_col >= 0) {
|
||||||
colnr_T ecol = curwin->w_cursor.col + 1;
|
colnr_T ecol = curwin->w_cursor.col + 1;
|
||||||
|
|
||||||
// Make sure the cursor is at the start of a character, but
|
// Make sure the cursor is at the start of a character, but
|
||||||
@@ -2174,15 +2172,14 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
|||||||
// Infer case of completed part.
|
// Infer case of completed part.
|
||||||
|
|
||||||
// Find actual length of completion.
|
// Find actual length of completion.
|
||||||
if (has_mbyte) {
|
{
|
||||||
const char_u *p = str;
|
const char_u *p = str;
|
||||||
actual_len = 0;
|
actual_len = 0;
|
||||||
while (*p != NUL) {
|
while (*p != NUL) {
|
||||||
MB_PTR_ADV(p);
|
MB_PTR_ADV(p);
|
||||||
actual_len++;
|
actual_len++;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
actual_len = len;
|
|
||||||
|
|
||||||
// Find actual length of original text.
|
// Find actual length of original text.
|
||||||
{
|
{
|
||||||
@@ -2204,11 +2201,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
|||||||
{
|
{
|
||||||
const char_u *p = str;
|
const char_u *p = str;
|
||||||
for (i = 0; i < actual_len; i++) {
|
for (i = 0; i < actual_len; i++) {
|
||||||
if (has_mbyte) {
|
wca[i] = mb_ptr2char_adv(&p);
|
||||||
wca[i] = mb_ptr2char_adv(&p);
|
|
||||||
} else {
|
|
||||||
wca[i] = *(p++);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2216,11 +2209,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
|||||||
{
|
{
|
||||||
const char_u *p = compl_orig_text;
|
const char_u *p = compl_orig_text;
|
||||||
for (i = 0; i < min_len; i++) {
|
for (i = 0; i < min_len; i++) {
|
||||||
if (has_mbyte) {
|
c = mb_ptr2char_adv(&p);
|
||||||
c = mb_ptr2char_adv(&p);
|
|
||||||
} else {
|
|
||||||
c = *(p++);
|
|
||||||
}
|
|
||||||
if (mb_islower(c)) {
|
if (mb_islower(c)) {
|
||||||
has_lower = true;
|
has_lower = true;
|
||||||
if (mb_isupper(wca[i])) {
|
if (mb_isupper(wca[i])) {
|
||||||
@@ -2241,11 +2230,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
|||||||
if (!has_lower) {
|
if (!has_lower) {
|
||||||
const char_u *p = compl_orig_text;
|
const char_u *p = compl_orig_text;
|
||||||
for (i = 0; i < min_len; i++) {
|
for (i = 0; i < min_len; i++) {
|
||||||
if (has_mbyte) {
|
c = mb_ptr2char_adv(&p);
|
||||||
c = mb_ptr2char_adv(&p);
|
|
||||||
} else {
|
|
||||||
c = *(p++);
|
|
||||||
}
|
|
||||||
if (was_letter && mb_isupper(c) && mb_islower(wca[i])) {
|
if (was_letter && mb_isupper(c) && mb_islower(wca[i])) {
|
||||||
// Rule 2 is satisfied.
|
// Rule 2 is satisfied.
|
||||||
for (i = actual_compl_length; i < actual_len; i++) {
|
for (i = actual_compl_length; i < actual_len; i++) {
|
||||||
@@ -2261,11 +2246,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
|||||||
{
|
{
|
||||||
const char_u *p = compl_orig_text;
|
const char_u *p = compl_orig_text;
|
||||||
for (i = 0; i < min_len; i++) {
|
for (i = 0; i < min_len; i++) {
|
||||||
if (has_mbyte) {
|
c = mb_ptr2char_adv(&p);
|
||||||
c = mb_ptr2char_adv(&p);
|
|
||||||
} else {
|
|
||||||
c = *(p++);
|
|
||||||
}
|
|
||||||
if (mb_islower(c)) {
|
if (mb_islower(c)) {
|
||||||
wca[i] = mb_tolower(wca[i]);
|
wca[i] = mb_tolower(wca[i]);
|
||||||
} else if (mb_isupper(c)) {
|
} else if (mb_isupper(c)) {
|
||||||
@@ -3059,12 +3040,9 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags,
|
|||||||
*/
|
*/
|
||||||
char_u *find_word_start(char_u *ptr)
|
char_u *find_word_start(char_u *ptr)
|
||||||
{
|
{
|
||||||
if (has_mbyte)
|
while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) {
|
||||||
while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
|
ptr += utfc_ptr2len(ptr);
|
||||||
ptr += (*mb_ptr2len)(ptr);
|
}
|
||||||
else
|
|
||||||
while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
|
|
||||||
++ptr;
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3074,19 +3052,15 @@ char_u *find_word_start(char_u *ptr)
|
|||||||
*/
|
*/
|
||||||
char_u *find_word_end(char_u *ptr)
|
char_u *find_word_end(char_u *ptr)
|
||||||
{
|
{
|
||||||
int start_class;
|
const int start_class = mb_get_class(ptr);
|
||||||
|
if (start_class > 1) {
|
||||||
if (has_mbyte) {
|
while (*ptr != NUL) {
|
||||||
start_class = mb_get_class(ptr);
|
ptr += utfc_ptr2len(ptr);
|
||||||
if (start_class > 1)
|
if (mb_get_class(ptr) != start_class) {
|
||||||
while (*ptr != NUL) {
|
break;
|
||||||
ptr += (*mb_ptr2len)(ptr);
|
|
||||||
if (mb_get_class(ptr) != start_class)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
while (vim_iswordc(*ptr))
|
}
|
||||||
++ptr;
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5557,10 +5531,9 @@ static void insert_special(int c, int allow_modmask, int ctrlv)
|
|||||||
*/
|
*/
|
||||||
# define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
|
# define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
|
||||||
|
|
||||||
# define WHITECHAR(cc) (ascii_iswhite(cc) && \
|
#define WHITECHAR(cc) ( \
|
||||||
(!enc_utf8 || \
|
ascii_iswhite(cc) \
|
||||||
!utf_iscomposing( \
|
&& !utf_iscomposing(utf_ptr2char(get_cursor_pos_ptr() + 1)))
|
||||||
utf_ptr2char(get_cursor_pos_ptr() + 1))))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "flags": INSCHAR_FORMAT - force formatting
|
* "flags": INSCHAR_FORMAT - force formatting
|
||||||
@@ -5697,7 +5670,7 @@ void insertchar(
|
|||||||
// Do the check for InsertCharPre before the call to vpeekc() because the
|
// Do the check for InsertCharPre before the call to vpeekc() because the
|
||||||
// InsertCharPre autocommand could change the input buffer.
|
// InsertCharPre autocommand could change the input buffer.
|
||||||
if (!ISSPECIAL(c)
|
if (!ISSPECIAL(c)
|
||||||
&& (!has_mbyte || (*mb_char2len)(c) == 1)
|
&& (utf_char2len(c) == 1)
|
||||||
&& !has_event(EVENT_INSERTCHARPRE)
|
&& !has_event(EVENT_INSERTCHARPRE)
|
||||||
&& vpeekc() != NUL
|
&& vpeekc() != NUL
|
||||||
&& !(State & REPLACE_FLAG)
|
&& !(State & REPLACE_FLAG)
|
||||||
@@ -7175,16 +7148,11 @@ static void replace_do_bs(int limit_col)
|
|||||||
getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
|
getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
|
||||||
orig_vcols = chartabsize(get_cursor_pos_ptr(), start_vcol);
|
orig_vcols = chartabsize(get_cursor_pos_ptr(), start_vcol);
|
||||||
}
|
}
|
||||||
if (has_mbyte) {
|
(void)del_char_after_col(limit_col);
|
||||||
(void)del_char_after_col(limit_col);
|
if (l_State & VREPLACE_FLAG) {
|
||||||
if (l_State & VREPLACE_FLAG)
|
orig_len = (int)STRLEN(get_cursor_pos_ptr());
|
||||||
orig_len = (int)STRLEN(get_cursor_pos_ptr());
|
|
||||||
replace_push(cc);
|
|
||||||
} else {
|
|
||||||
pchar_cursor(cc);
|
|
||||||
if (l_State & VREPLACE_FLAG)
|
|
||||||
orig_len = (int)STRLEN(get_cursor_pos_ptr()) - 1;
|
|
||||||
}
|
}
|
||||||
|
replace_push(cc);
|
||||||
replace_pop_ins();
|
replace_pop_ins();
|
||||||
|
|
||||||
if (l_State & VREPLACE_FLAG) {
|
if (l_State & VREPLACE_FLAG) {
|
||||||
@@ -7403,23 +7371,17 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
|
|||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
if (keytyped == KEY_COMPLETE) {
|
if (keytyped == KEY_COMPLETE) {
|
||||||
char_u *s;
|
char_u *n, *s;
|
||||||
|
|
||||||
/* Just completed a word, check if it starts with "look".
|
/* Just completed a word, check if it starts with "look".
|
||||||
* search back for the start of a word. */
|
* search back for the start of a word. */
|
||||||
line = get_cursor_line_ptr();
|
line = get_cursor_line_ptr();
|
||||||
if (has_mbyte) {
|
for (s = line + curwin->w_cursor.col; s > line; s = n) {
|
||||||
char_u *n;
|
n = mb_prevptr(line, s);
|
||||||
|
if (!vim_iswordp(n)) {
|
||||||
for (s = line + curwin->w_cursor.col; s > line; s = n) {
|
break;
|
||||||
n = mb_prevptr(line, s);
|
|
||||||
if (!vim_iswordp(n))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
for (s = line + curwin->w_cursor.col; s > line; --s)
|
|
||||||
if (!vim_iswordc(s[-1]))
|
|
||||||
break;
|
|
||||||
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
|
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
|
||||||
if (s + (p - look) <= line + curwin->w_cursor.col
|
if (s + (p - look) <= line + curwin->w_cursor.col
|
||||||
&& (icase
|
&& (icase
|
||||||
@@ -8255,10 +8217,8 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
}
|
}
|
||||||
cc = gchar_cursor();
|
cc = gchar_cursor();
|
||||||
// look multi-byte character class
|
// look multi-byte character class
|
||||||
if (has_mbyte) {
|
prev_cclass = cclass;
|
||||||
prev_cclass = cclass;
|
cclass = mb_get_class(get_cursor_pos_ptr());
|
||||||
cclass = mb_get_class(get_cursor_pos_ptr());
|
|
||||||
}
|
|
||||||
if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word?
|
if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word?
|
||||||
mode = BACKSPACE_WORD_NOT_SPACE;
|
mode = BACKSPACE_WORD_NOT_SPACE;
|
||||||
temp = vim_iswordc(cc);
|
temp = vim_iswordc(cc);
|
||||||
@@ -8272,19 +8232,18 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (State & REPLACE_FLAG)
|
if (State & REPLACE_FLAG) {
|
||||||
replace_do_bs(-1);
|
replace_do_bs(-1);
|
||||||
else {
|
} else {
|
||||||
const bool l_enc_utf8 = enc_utf8;
|
|
||||||
const int l_p_deco = p_deco;
|
const int l_p_deco = p_deco;
|
||||||
if (l_enc_utf8 && l_p_deco) {
|
if (l_p_deco) {
|
||||||
(void)utfc_ptr2char(get_cursor_pos_ptr(), cpc);
|
(void)utfc_ptr2char(get_cursor_pos_ptr(), cpc);
|
||||||
}
|
}
|
||||||
(void)del_char(false);
|
(void)del_char(false);
|
||||||
// If there are combining characters and 'delcombine' is set
|
// If there are combining characters and 'delcombine' is set
|
||||||
// move the cursor back. Don't back up before the base
|
// move the cursor back. Don't back up before the base
|
||||||
// character.
|
// character.
|
||||||
if (l_enc_utf8 && l_p_deco && cpc[0] != NUL) {
|
if (l_p_deco && cpc[0] != NUL) {
|
||||||
inc_cursor();
|
inc_cursor();
|
||||||
}
|
}
|
||||||
if (revins_chars) {
|
if (revins_chars) {
|
||||||
@@ -8522,13 +8481,10 @@ static void ins_right(void)
|
|||||||
AppendCharToRedobuff(K_RIGHT);
|
AppendCharToRedobuff(K_RIGHT);
|
||||||
}
|
}
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
if (virtual_active())
|
if (virtual_active()) {
|
||||||
oneright();
|
oneright();
|
||||||
else {
|
} else {
|
||||||
if (has_mbyte)
|
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
|
||||||
curwin->w_cursor.col += (*mb_ptr2len)(get_cursor_pos_ptr());
|
|
||||||
else
|
|
||||||
++curwin->w_cursor.col;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
revins_legal++;
|
revins_legal++;
|
||||||
|
@@ -783,10 +783,10 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
|
|||||||
if (*t == NUL) { // EOL reached.
|
if (*t == NUL) { // EOL reached.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (enc_utf8 && comp) {
|
if (comp) {
|
||||||
t += utf_ptr2len((const char_u *)t);
|
t += utf_ptr2len((const char_u *)t);
|
||||||
} else {
|
} else {
|
||||||
t += (*mb_ptr2len)((const char_u *)t);
|
t += utfc_ptr2len((const char_u *)t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rettv->vval.v_number = (varnumber_T)(t - str);
|
rettv->vval.v_number = (varnumber_T)(t - str);
|
||||||
@@ -1427,9 +1427,7 @@ static void f_cursor(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// Make sure the cursor is in a valid position.
|
// Make sure the cursor is in a valid position.
|
||||||
check_cursor();
|
check_cursor();
|
||||||
// Correct cursor for multi-byte character.
|
// Correct cursor for multi-byte character.
|
||||||
if (has_mbyte) {
|
mb_adjust_cursor();
|
||||||
mb_adjust_cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
curwin->w_set_curswant = set_curswant;
|
curwin->w_set_curswant = set_curswant;
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
@@ -4198,7 +4196,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
} else if (STRICMP(name, "ttyout") == 0) {
|
} else if (STRICMP(name, "ttyout") == 0) {
|
||||||
n = stdout_isatty;
|
n = stdout_isatty;
|
||||||
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
|
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
|
||||||
n = has_mbyte != 0;
|
n = true;
|
||||||
} else if (STRICMP(name, "syntax_items") == 0) {
|
} else if (STRICMP(name, "syntax_items") == 0) {
|
||||||
n = syntax_present(curwin);
|
n = syntax_present(curwin);
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
@@ -8025,14 +8023,9 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
if ((d = argvars[0].vval.v_dict) != NULL) {
|
if ((d = argvars[0].vval.v_dict) != NULL) {
|
||||||
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
|
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
|
||||||
if (csearch != NULL) {
|
if (csearch != NULL) {
|
||||||
if (enc_utf8) {
|
int pcc[MAX_MCO];
|
||||||
int pcc[MAX_MCO];
|
const int c = utfc_ptr2char(csearch, pcc);
|
||||||
int c = utfc_ptr2char(csearch, pcc);
|
set_last_csearch(c, csearch, utfc_ptr2len(csearch));
|
||||||
set_last_csearch(c, csearch, utfc_ptr2len(csearch));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
set_last_csearch(PTR2CHAR(csearch),
|
|
||||||
csearch, utfc_ptr2len(csearch));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
di = tv_dict_find(d, S_LEN("forward"));
|
di = tv_dict_find(d, S_LEN("forward"));
|
||||||
@@ -10711,72 +10704,54 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
garray_T ga;
|
garray_T ga;
|
||||||
ga_init(&ga, (int)sizeof(char), 80);
|
ga_init(&ga, (int)sizeof(char), 80);
|
||||||
|
|
||||||
if (!has_mbyte) {
|
|
||||||
// Not multi-byte: fromstr and tostr must be the same length.
|
|
||||||
if (strlen(fromstr) != strlen(tostr)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fromstr and tostr have to contain the same number of chars.
|
// fromstr and tostr have to contain the same number of chars.
|
||||||
bool first = true;
|
bool first = true;
|
||||||
while (*in_str != NUL) {
|
while (*in_str != NUL) {
|
||||||
if (has_mbyte) {
|
const char *cpstr = in_str;
|
||||||
const char *cpstr = in_str;
|
const int inlen = utfc_ptr2len((const char_u *)in_str);
|
||||||
const int inlen = (*mb_ptr2len)((const char_u *)in_str);
|
int cplen = inlen;
|
||||||
int cplen = inlen;
|
int idx = 0;
|
||||||
int idx = 0;
|
int fromlen;
|
||||||
int fromlen;
|
for (const char *p = fromstr; *p != NUL; p += fromlen) {
|
||||||
for (const char *p = fromstr; *p != NUL; p += fromlen) {
|
fromlen = utfc_ptr2len((const char_u *)p);
|
||||||
fromlen = (*mb_ptr2len)((const char_u *)p);
|
if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) {
|
||||||
if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) {
|
|
||||||
int tolen;
|
|
||||||
for (p = tostr; *p != NUL; p += tolen) {
|
|
||||||
tolen = (*mb_ptr2len)((const char_u *)p);
|
|
||||||
if (idx-- == 0) {
|
|
||||||
cplen = tolen;
|
|
||||||
cpstr = (char *)p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*p == NUL) { // tostr is shorter than fromstr.
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first && cpstr == in_str) {
|
|
||||||
// Check that fromstr and tostr have the same number of
|
|
||||||
// (multi-byte) characters. Done only once when a character
|
|
||||||
// of in_str doesn't appear in fromstr.
|
|
||||||
first = false;
|
|
||||||
int tolen;
|
int tolen;
|
||||||
for (const char *p = tostr; *p != NUL; p += tolen) {
|
for (p = tostr; *p != NUL; p += tolen) {
|
||||||
tolen = (*mb_ptr2len)((const char_u *)p);
|
tolen = utfc_ptr2len((const char_u *)p);
|
||||||
idx--;
|
if (idx-- == 0) {
|
||||||
|
cplen = tolen;
|
||||||
|
cpstr = (char *)p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (idx != 0) {
|
if (*p == NUL) { // tostr is shorter than fromstr.
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
idx++;
|
||||||
ga_grow(&ga, cplen);
|
|
||||||
memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
|
|
||||||
ga.ga_len += cplen;
|
|
||||||
|
|
||||||
in_str += inlen;
|
|
||||||
} else {
|
|
||||||
// When not using multi-byte chars we can do it faster.
|
|
||||||
const char *const p = strchr(fromstr, *in_str);
|
|
||||||
if (p != NULL) {
|
|
||||||
ga_append(&ga, tostr[p - fromstr]);
|
|
||||||
} else {
|
|
||||||
ga_append(&ga, *in_str);
|
|
||||||
}
|
|
||||||
in_str++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (first && cpstr == in_str) {
|
||||||
|
// Check that fromstr and tostr have the same number of
|
||||||
|
// (multi-byte) characters. Done only once when a character
|
||||||
|
// of in_str doesn't appear in fromstr.
|
||||||
|
first = false;
|
||||||
|
int tolen;
|
||||||
|
for (const char *p = tostr; *p != NUL; p += tolen) {
|
||||||
|
tolen = utfc_ptr2len((const char_u *)p);
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
if (idx != 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ga_grow(&ga, cplen);
|
||||||
|
memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
|
||||||
|
ga.ga_len += cplen;
|
||||||
|
|
||||||
|
in_str += inlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a terminating NUL
|
// add a terminating NUL
|
||||||
|
@@ -795,10 +795,7 @@ void ex_retab(exarg_T *eap)
|
|||||||
if (ptr[col] == NUL)
|
if (ptr[col] == NUL)
|
||||||
break;
|
break;
|
||||||
vcol += chartabsize(ptr + col, (colnr_T)vcol);
|
vcol += chartabsize(ptr + col, (colnr_T)vcol);
|
||||||
if (has_mbyte)
|
col += utfc_ptr2len(ptr + col);
|
||||||
col += (*mb_ptr2len)(ptr + col);
|
|
||||||
else
|
|
||||||
++col;
|
|
||||||
}
|
}
|
||||||
if (new_line == NULL) /* out of memory */
|
if (new_line == NULL) /* out of memory */
|
||||||
break;
|
break;
|
||||||
@@ -3465,7 +3462,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
int lastone;
|
int lastone;
|
||||||
long nmatch_tl = 0; // nr of lines matched below lnum
|
long nmatch_tl = 0; // nr of lines matched below lnum
|
||||||
int do_again; // do it again after joining lines
|
int do_again; // do it again after joining lines
|
||||||
int skip_match = false;
|
bool skip_match = false;
|
||||||
linenr_T sub_firstlnum; // nr of first sub line
|
linenr_T sub_firstlnum; // nr of first sub line
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3576,16 +3573,13 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
if (matchcol == prev_matchcol
|
if (matchcol == prev_matchcol
|
||||||
&& regmatch.endpos[0].lnum == 0
|
&& regmatch.endpos[0].lnum == 0
|
||||||
&& matchcol == regmatch.endpos[0].col) {
|
&& matchcol == regmatch.endpos[0].col) {
|
||||||
if (sub_firstline[matchcol] == NUL)
|
if (sub_firstline[matchcol] == NUL) {
|
||||||
/* We already were at the end of the line. Don't look
|
// We already were at the end of the line. Don't look
|
||||||
* for a match in this line again. */
|
// for a match in this line again.
|
||||||
skip_match = TRUE;
|
skip_match = true;
|
||||||
else {
|
} else {
|
||||||
/* search for a match at next column */
|
// search for a match at next column
|
||||||
if (has_mbyte)
|
matchcol += mb_ptr2len(sub_firstline + matchcol);
|
||||||
matchcol += mb_ptr2len(sub_firstline + matchcol);
|
|
||||||
else
|
|
||||||
++matchcol;
|
|
||||||
}
|
}
|
||||||
// match will be pushed to preview_lines, bring it into a proper state
|
// match will be pushed to preview_lines, bring it into a proper state
|
||||||
current_match.start.col = matchcol;
|
current_match.start.col = matchcol;
|
||||||
@@ -3609,7 +3603,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
if (nmatch > 1) {
|
if (nmatch > 1) {
|
||||||
matchcol = (colnr_T)STRLEN(sub_firstline);
|
matchcol = (colnr_T)STRLEN(sub_firstline);
|
||||||
nmatch = 1;
|
nmatch = 1;
|
||||||
skip_match = TRUE;
|
skip_match = true;
|
||||||
}
|
}
|
||||||
sub_nsubs++;
|
sub_nsubs++;
|
||||||
did_sub = TRUE;
|
did_sub = TRUE;
|
||||||
@@ -3779,7 +3773,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
* get stuck when pressing 'n'. */
|
* get stuck when pressing 'n'. */
|
||||||
if (nmatch > 1) {
|
if (nmatch > 1) {
|
||||||
matchcol = (colnr_T)STRLEN(sub_firstline);
|
matchcol = (colnr_T)STRLEN(sub_firstline);
|
||||||
skip_match = TRUE;
|
skip_match = true;
|
||||||
}
|
}
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
@@ -3956,8 +3950,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
STRMOVE(new_start, p1 + 1);
|
STRMOVE(new_start, p1 + 1);
|
||||||
p1 = new_start - 1;
|
p1 = new_start - 1;
|
||||||
}
|
}
|
||||||
} else if (has_mbyte) {
|
} else {
|
||||||
p1 += (*mb_ptr2len)(p1) - 1;
|
p1 += utfc_ptr2len(p1) - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t new_endcol = STRLEN(new_start);
|
size_t new_endcol = STRLEN(new_start);
|
||||||
|
@@ -2505,12 +2505,8 @@ static void append_command(char_u *cmd)
|
|||||||
STRCAT(IObuff, ": ");
|
STRCAT(IObuff, ": ");
|
||||||
d = IObuff + STRLEN(IObuff);
|
d = IObuff + STRLEN(IObuff);
|
||||||
while (*s != NUL && d - IObuff < IOSIZE - 7) {
|
while (*s != NUL && d - IObuff < IOSIZE - 7) {
|
||||||
if (
|
if (s[0] == 0xc2 && s[1] == 0xa0) {
|
||||||
enc_utf8 ? (s[0] == 0xc2 && s[1] == 0xa0) :
|
s += 2;
|
||||||
*s == 0xa0) {
|
|
||||||
s +=
|
|
||||||
enc_utf8 ? 2 :
|
|
||||||
1;
|
|
||||||
STRCPY(d, "<a0>");
|
STRCPY(d, "<a0>");
|
||||||
d += 4;
|
d += 4;
|
||||||
} else
|
} else
|
||||||
@@ -5564,7 +5560,8 @@ static char_u *uc_split_args(char_u *arg, size_t *lenp)
|
|||||||
break;
|
break;
|
||||||
len += 3; /* "," */
|
len += 3; /* "," */
|
||||||
} else {
|
} else {
|
||||||
int charlen = (*mb_ptr2len)(p);
|
const int charlen = utfc_ptr2len(p);
|
||||||
|
|
||||||
len += charlen;
|
len += charlen;
|
||||||
p += charlen;
|
p += charlen;
|
||||||
}
|
}
|
||||||
@@ -8266,12 +8263,10 @@ static void ex_normal(exarg_T *eap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// vgetc() expects a CSI and K_SPECIAL to have been escaped. Don't do
|
||||||
* vgetc() expects a CSI and K_SPECIAL to have been escaped. Don't do
|
// this for the K_SPECIAL leading byte, otherwise special keys will not
|
||||||
* this for the K_SPECIAL leading byte, otherwise special keys will not
|
// work.
|
||||||
* work.
|
{
|
||||||
*/
|
|
||||||
if (has_mbyte) {
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
/* Count the number of characters to be escaped. */
|
/* Count the number of characters to be escaped. */
|
||||||
@@ -8310,9 +8305,8 @@ static void ex_normal(exarg_T *eap)
|
|||||||
check_cursor_moved(curwin);
|
check_cursor_moved(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_normal_cmd(
|
exec_normal_cmd(arg != NULL ? arg : eap->arg,
|
||||||
arg != NULL ? arg :
|
eap->forceit ? REMAP_NONE : REMAP_YES, false);
|
||||||
eap->arg, eap->forceit ? REMAP_NONE : REMAP_YES, FALSE);
|
|
||||||
} while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int);
|
} while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2096,7 +2096,7 @@ static int command_line_handle_key(CommandLineState *s)
|
|||||||
s->do_abbr = false; // don't do abbreviation now
|
s->do_abbr = false; // don't do abbreviation now
|
||||||
ccline.special_char = NUL;
|
ccline.special_char = NUL;
|
||||||
// may need to remove ^ when composing char was typed
|
// may need to remove ^ when composing char was typed
|
||||||
if (enc_utf8 && utf_iscomposing(s->c) && !cmd_silent) {
|
if (utf_iscomposing(s->c) && !cmd_silent) {
|
||||||
if (ui_has(kUICmdline)) {
|
if (ui_has(kUICmdline)) {
|
||||||
// TODO(bfredl): why not make unputcmdline also work with true?
|
// TODO(bfredl): why not make unputcmdline also work with true?
|
||||||
unputcmdline();
|
unputcmdline();
|
||||||
@@ -2143,9 +2143,8 @@ static int command_line_handle_key(CommandLineState *s)
|
|||||||
if (s->do_abbr && (IS_SPECIAL(s->c) || !vim_iswordc(s->c))
|
if (s->do_abbr && (IS_SPECIAL(s->c) || !vim_iswordc(s->c))
|
||||||
// Add ABBR_OFF for characters above 0x100, this is
|
// Add ABBR_OFF for characters above 0x100, this is
|
||||||
// what check_abbr() expects.
|
// what check_abbr() expects.
|
||||||
&& (ccheck_abbr((has_mbyte && s->c >= 0x100) ?
|
&& (ccheck_abbr((s->c >= 0x100) ? (s->c + ABBR_OFF) : s->c)
|
||||||
(s->c + ABBR_OFF) : s->c)
|
|| s->c == Ctrl_RSB)) {
|
||||||
|| s->c == Ctrl_RSB)) {
|
|
||||||
return command_line_changed(s);
|
return command_line_changed(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2254,7 +2253,7 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
may_do_incsearch_highlighting(s->firstc, s->count, &s->is_state);
|
may_do_incsearch_highlighting(s->firstc, s->count, &s->is_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdmsg_rl || (p_arshape && !p_tbidi && enc_utf8)) {
|
if (cmdmsg_rl || (p_arshape && !p_tbidi)) {
|
||||||
// Always redraw the whole command line to fix shaping and
|
// Always redraw the whole command line to fix shaping and
|
||||||
// right-left typing. Not efficient, but it works.
|
// right-left typing. Not efficient, but it works.
|
||||||
// Do it only when there are no characters left to read
|
// Do it only when there are no characters left to read
|
||||||
@@ -3139,11 +3138,9 @@ static void draw_cmdline(int start, int len)
|
|||||||
if (cmdline_star > 0) {
|
if (cmdline_star > 0) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
msg_putchar('*');
|
msg_putchar('*');
|
||||||
if (has_mbyte) {
|
i += utfc_ptr2len(ccline.cmdbuff + start + i) - 1;
|
||||||
i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (p_arshape && !p_tbidi && enc_utf8 && len > 0) {
|
} else if (p_arshape && !p_tbidi && len > 0) {
|
||||||
bool do_arabicshape = false;
|
bool do_arabicshape = false;
|
||||||
int mb_l;
|
int mb_l;
|
||||||
for (int i = start; i < start + len; i += mb_l) {
|
for (int i = start; i < start + len; i += mb_l) {
|
||||||
@@ -3439,32 +3436,31 @@ void put_on_cmdline(char_u *str, int len, int redraw)
|
|||||||
(size_t)(ccline.cmdlen - ccline.cmdpos));
|
(size_t)(ccline.cmdlen - ccline.cmdpos));
|
||||||
ccline.cmdlen += len;
|
ccline.cmdlen += len;
|
||||||
} else {
|
} else {
|
||||||
if (has_mbyte) {
|
// Count nr of characters in the new string.
|
||||||
/* Count nr of characters in the new string. */
|
m = 0;
|
||||||
m = 0;
|
for (i = 0; i < len; i += utfc_ptr2len(str + i)) {
|
||||||
for (i = 0; i < len; i += (*mb_ptr2len)(str + i))
|
m++;
|
||||||
++m;
|
}
|
||||||
/* Count nr of bytes in cmdline that are overwritten by these
|
// Count nr of bytes in cmdline that are overwritten by these
|
||||||
* characters. */
|
// characters.
|
||||||
for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0;
|
for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0;
|
||||||
i += (*mb_ptr2len)(ccline.cmdbuff + i))
|
i += utfc_ptr2len(ccline.cmdbuff + i)) {
|
||||||
--m;
|
m--;
|
||||||
if (i < ccline.cmdlen) {
|
}
|
||||||
memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
if (i < ccline.cmdlen) {
|
||||||
ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i));
|
memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
||||||
ccline.cmdlen += ccline.cmdpos + len - i;
|
ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i));
|
||||||
} else
|
ccline.cmdlen += ccline.cmdpos + len - i;
|
||||||
ccline.cmdlen = ccline.cmdpos + len;
|
} else {
|
||||||
} else if (ccline.cmdpos + len > ccline.cmdlen)
|
|
||||||
ccline.cmdlen = ccline.cmdpos + len;
|
ccline.cmdlen = ccline.cmdpos + len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len);
|
memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len);
|
||||||
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
||||||
|
|
||||||
if (enc_utf8) {
|
{
|
||||||
/* When the inserted text starts with a composing character,
|
// When the inserted text starts with a composing character,
|
||||||
* backup to the character before it. There could be two of them.
|
// backup to the character before it. There could be two of them.
|
||||||
*/
|
|
||||||
i = 0;
|
i = 0;
|
||||||
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
||||||
while (ccline.cmdpos > 0 && utf_iscomposing(c)) {
|
while (ccline.cmdpos > 0 && utf_iscomposing(c)) {
|
||||||
@@ -3515,23 +3511,19 @@ void put_on_cmdline(char_u *str, int len, int redraw)
|
|||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
c = cmdline_charsize(ccline.cmdpos);
|
c = cmdline_charsize(ccline.cmdpos);
|
||||||
// count ">" for a double-wide char that doesn't fit.
|
// count ">" for a double-wide char that doesn't fit.
|
||||||
if (has_mbyte) {
|
correct_screencol(ccline.cmdpos, c, &ccline.cmdspos);
|
||||||
correct_screencol(ccline.cmdpos, c, &ccline.cmdspos);
|
|
||||||
}
|
|
||||||
// Stop cursor at the end of the screen, but do increment the
|
// Stop cursor at the end of the screen, but do increment the
|
||||||
// insert position, so that entering a very long command
|
// insert position, so that entering a very long command
|
||||||
// works, even though you can't see it.
|
// works, even though you can't see it.
|
||||||
if (ccline.cmdspos + c < m) {
|
if (ccline.cmdspos + c < m) {
|
||||||
ccline.cmdspos += c;
|
ccline.cmdspos += c;
|
||||||
}
|
}
|
||||||
if (has_mbyte) {
|
c = utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1;
|
||||||
c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1;
|
if (c > len - i - 1) {
|
||||||
if (c > len - i - 1) {
|
c = len - i - 1;
|
||||||
c = len - i - 1;
|
|
||||||
}
|
|
||||||
ccline.cmdpos += c;
|
|
||||||
i += c;
|
|
||||||
}
|
}
|
||||||
|
ccline.cmdpos += c;
|
||||||
|
i += c;
|
||||||
ccline.cmdpos++;
|
ccline.cmdpos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3676,11 +3668,7 @@ void cmdline_paste_str(char_u *s, int literally)
|
|||||||
if (cv == Ctrl_V && s[1]) {
|
if (cv == Ctrl_V && s[1]) {
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (has_mbyte) {
|
c = mb_cptr2char_adv((const char_u **)&s);
|
||||||
c = mb_cptr2char_adv((const char_u **)&s);
|
|
||||||
} else {
|
|
||||||
c = *s++;
|
|
||||||
}
|
|
||||||
if (cv == Ctrl_V || c == ESC || c == Ctrl_C
|
if (cv == Ctrl_V || c == ESC || c == Ctrl_C
|
||||||
|| c == CAR || c == NL || c == Ctrl_L
|
|| c == CAR || c == NL || c == Ctrl_L
|
||||||
|| (c == Ctrl_BSL && *s == Ctrl_N)) {
|
|| (c == Ctrl_BSL && *s == Ctrl_N)) {
|
||||||
|
@@ -910,20 +910,18 @@ retry:
|
|||||||
|
|
||||||
/* "ucs-bom" means we need to check the first bytes of the file
|
/* "ucs-bom" means we need to check the first bytes of the file
|
||||||
* for a BOM. */
|
* for a BOM. */
|
||||||
if (STRCMP(fenc, ENC_UCSBOM) == 0)
|
if (STRCMP(fenc, ENC_UCSBOM) == 0) {
|
||||||
fio_flags = FIO_UCSBOM;
|
fio_flags = FIO_UCSBOM;
|
||||||
|
} else {
|
||||||
/*
|
// Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be
|
||||||
* Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be
|
// done. This is handled below after read(). Prepare the
|
||||||
* done. This is handled below after read(). Prepare the
|
// fio_flags to avoid having to parse the string each time.
|
||||||
* fio_flags to avoid having to parse the string each time.
|
// Also check for Unicode to Latin1 conversion, because iconv()
|
||||||
* Also check for Unicode to Latin1 conversion, because iconv()
|
// appears not to handle this correctly. This works just like
|
||||||
* appears not to handle this correctly. This works just like
|
// conversion to UTF-8 except how the resulting character is put in
|
||||||
* conversion to UTF-8 except how the resulting character is put in
|
// the buffer.
|
||||||
* the buffer.
|
|
||||||
*/
|
|
||||||
else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0)
|
|
||||||
fio_flags = get_fio_flags(fenc);
|
fio_flags = get_fio_flags(fenc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -932,8 +930,7 @@ retry:
|
|||||||
if (fio_flags == 0
|
if (fio_flags == 0
|
||||||
&& !did_iconv
|
&& !did_iconv
|
||||||
) {
|
) {
|
||||||
iconv_fd = (iconv_t)my_iconv_open(
|
iconv_fd = (iconv_t)my_iconv_open((char_u *)"utf-8", fenc);
|
||||||
enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc);
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@@ -1202,7 +1199,7 @@ retry:
|
|||||||
&& (fio_flags == FIO_UCSBOM
|
&& (fio_flags == FIO_UCSBOM
|
||||||
|| (!curbuf->b_p_bomb
|
|| (!curbuf->b_p_bomb
|
||||||
&& tmpname == NULL
|
&& tmpname == NULL
|
||||||
&& (*fenc == 'u' || (*fenc == NUL && enc_utf8))))) {
|
&& (*fenc == 'u' || *fenc == NUL)))) {
|
||||||
char_u *ccname;
|
char_u *ccname;
|
||||||
int blen;
|
int blen;
|
||||||
|
|
||||||
@@ -1468,8 +1465,8 @@ retry:
|
|||||||
memmove(line_start, buffer, (size_t)linerest);
|
memmove(line_start, buffer, (size_t)linerest);
|
||||||
size = (long)((ptr + real_size) - dest);
|
size = (long)((ptr + real_size) - dest);
|
||||||
ptr = dest;
|
ptr = dest;
|
||||||
} else if (enc_utf8 && !curbuf->b_p_bin) {
|
} else if (!curbuf->b_p_bin) {
|
||||||
int incomplete_tail = FALSE;
|
bool incomplete_tail = false;
|
||||||
|
|
||||||
// Reading UTF-8: Check if the bytes are valid UTF-8.
|
// Reading UTF-8: Check if the bytes are valid UTF-8.
|
||||||
for (p = ptr;; p++) {
|
for (p = ptr;; p++) {
|
||||||
@@ -1486,15 +1483,16 @@ retry:
|
|||||||
// then.
|
// then.
|
||||||
l = utf_ptr2len_len(p, todo);
|
l = utf_ptr2len_len(p, todo);
|
||||||
if (l > todo && !incomplete_tail) {
|
if (l > todo && !incomplete_tail) {
|
||||||
/* Avoid retrying with a different encoding when
|
// Avoid retrying with a different encoding when
|
||||||
* a truncated file is more likely, or attempting
|
// a truncated file is more likely, or attempting
|
||||||
* to read the rest of an incomplete sequence when
|
// to read the rest of an incomplete sequence when
|
||||||
* we have already done so. */
|
// we have already done so.
|
||||||
if (p > ptr || filesize > 0)
|
if (p > ptr || filesize > 0) {
|
||||||
incomplete_tail = TRUE;
|
incomplete_tail = true;
|
||||||
/* Incomplete byte sequence, move it to conv_rest[]
|
}
|
||||||
* and try to read the rest of it, unless we've
|
// Incomplete byte sequence, move it to conv_rest[]
|
||||||
* already done so. */
|
// and try to read the rest of it, unless we've
|
||||||
|
// already done so.
|
||||||
if (p > ptr) {
|
if (p > ptr) {
|
||||||
conv_restlen = todo;
|
conv_restlen = todo;
|
||||||
memmove(conv_rest, p, conv_restlen);
|
memmove(conv_rest, p, conv_restlen);
|
||||||
@@ -2165,8 +2163,8 @@ readfile_charconvert (
|
|||||||
else {
|
else {
|
||||||
close(*fdp); /* close the input file, ignore errors */
|
close(*fdp); /* close the input file, ignore errors */
|
||||||
*fdp = -1;
|
*fdp = -1;
|
||||||
if (eval_charconvert((char *) fenc, enc_utf8 ? "utf-8" : (char *) p_enc,
|
if (eval_charconvert((char *)fenc, "utf-8",
|
||||||
(char *) fname, (char *) tmpname) == FAIL) {
|
(char *)fname, (char *)tmpname) == FAIL) {
|
||||||
errmsg = (char_u *)_("Conversion with 'charconvert' failed");
|
errmsg = (char_u *)_("Conversion with 'charconvert' failed");
|
||||||
}
|
}
|
||||||
if (errmsg == NULL && (*fdp = os_open((char *)tmpname, O_RDONLY, 0)) < 0) {
|
if (errmsg == NULL && (*fdp = os_open((char *)tmpname, O_RDONLY, 0)) < 0) {
|
||||||
@@ -3067,7 +3065,7 @@ nobackup:
|
|||||||
// Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
|
// Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
|
||||||
// Latin1 to Unicode conversion. This is handled in buf_write_bytes().
|
// Latin1 to Unicode conversion. This is handled in buf_write_bytes().
|
||||||
// Prepare the flags for it and allocate bw_conv_buf when needed.
|
// Prepare the flags for it and allocate bw_conv_buf when needed.
|
||||||
if (converted && (enc_utf8 || STRCMP(p_enc, "latin1") == 0)) {
|
if (converted) {
|
||||||
wb_flags = get_fio_flags(fenc);
|
wb_flags = get_fio_flags(fenc);
|
||||||
if (wb_flags & (FIO_UCS2 | FIO_UCS4 | FIO_UTF16 | FIO_UTF8)) {
|
if (wb_flags & (FIO_UCS2 | FIO_UCS4 | FIO_UTF16 | FIO_UTF8)) {
|
||||||
// Need to allocate a buffer to translate into.
|
// Need to allocate a buffer to translate into.
|
||||||
@@ -3089,8 +3087,7 @@ nobackup:
|
|||||||
# ifdef HAVE_ICONV
|
# ifdef HAVE_ICONV
|
||||||
// Use iconv() conversion when conversion is needed and it's not done
|
// Use iconv() conversion when conversion is needed and it's not done
|
||||||
// internally.
|
// internally.
|
||||||
write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc,
|
write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc, (char_u *)"utf-8");
|
||||||
enc_utf8 ? (char_u *)"utf-8" : p_enc);
|
|
||||||
if (write_info.bw_iconv_fd != (iconv_t)-1) {
|
if (write_info.bw_iconv_fd != (iconv_t)-1) {
|
||||||
/* We're going to use iconv(), allocate a buffer to convert in. */
|
/* We're going to use iconv(), allocate a buffer to convert in. */
|
||||||
write_info.bw_conv_buflen = bufsize * ICONV_MULT;
|
write_info.bw_conv_buflen = bufsize * ICONV_MULT;
|
||||||
@@ -3433,7 +3430,7 @@ restore_backup:
|
|||||||
// The file was written to a temp file, now it needs to be converted
|
// The file was written to a temp file, now it needs to be converted
|
||||||
// with 'charconvert' to (overwrite) the output file.
|
// with 'charconvert' to (overwrite) the output file.
|
||||||
if (end != 0) {
|
if (end != 0) {
|
||||||
if (eval_charconvert(enc_utf8 ? "utf-8" : (char *)p_enc, (char *)fenc,
|
if (eval_charconvert("utf-8", (char *)fenc,
|
||||||
(char *)wfname, (char *)fname) == FAIL) {
|
(char *)wfname, (char *)fname) == FAIL) {
|
||||||
write_info.bw_conv_error = true;
|
write_info.bw_conv_error = true;
|
||||||
end = 0;
|
end = 0;
|
||||||
@@ -4189,7 +4186,7 @@ static bool need_conversion(const char_u *fenc)
|
|||||||
|
|
||||||
/* Encodings differ. However, conversion is not needed when 'enc' is any
|
/* Encodings differ. However, conversion is not needed when 'enc' is any
|
||||||
* Unicode encoding and the file is UTF-8. */
|
* Unicode encoding and the file is UTF-8. */
|
||||||
return !(enc_utf8 && fenc_flags == FIO_UTF8);
|
return !(fenc_flags == FIO_UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the FIO_ flags needed for the internal conversion if 'name' was
|
/// Return the FIO_ flags needed for the internal conversion if 'name' was
|
||||||
|
@@ -1037,11 +1037,11 @@ void foldAdjustVisual(void)
|
|||||||
if (hasFolding(end->lnum, NULL, &end->lnum)) {
|
if (hasFolding(end->lnum, NULL, &end->lnum)) {
|
||||||
ptr = ml_get(end->lnum);
|
ptr = ml_get(end->lnum);
|
||||||
end->col = (colnr_T)STRLEN(ptr);
|
end->col = (colnr_T)STRLEN(ptr);
|
||||||
if (end->col > 0 && *p_sel == 'o')
|
if (end->col > 0 && *p_sel == 'o') {
|
||||||
--end->col;
|
end->col--;
|
||||||
/* prevent cursor from moving on the trail byte */
|
}
|
||||||
if (has_mbyte)
|
// prevent cursor from moving on the trail byte
|
||||||
mb_adjust_cursor();
|
mb_adjust_cursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user