aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/getchar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r--src/nvim/getchar.c98
1 files changed, 44 insertions, 54 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 8ed9381bca..37840f8875 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -155,7 +155,6 @@ static char *get_buffcont(buffheader_T *buffer, int dozero)
{
size_t count = 0;
char *p = NULL;
- char *p2;
// compute the total length of the string
for (const buffblock_T *bp = buffer->bh_first.b_next;
@@ -165,7 +164,7 @@ static char *get_buffcont(buffheader_T *buffer, int dozero)
if (count || dozero) {
p = xmalloc(count + 1);
- p2 = p;
+ char *p2 = p;
for (const buffblock_T *bp = buffer->bh_first.b_next;
bp != NULL; bp = bp->b_next) {
for (const char *str = bp->b_str; *str;) {
@@ -180,7 +179,7 @@ static char *get_buffcont(buffheader_T *buffer, int dozero)
/// Return the contents of the record buffer as a single string
/// and clear the record buffer.
/// K_SPECIAL in the returned string is escaped.
-char_u *get_recorded(void)
+char *get_recorded(void)
{
char *p;
size_t len;
@@ -202,7 +201,7 @@ char_u *get_recorded(void)
p[len - 1] = NUL;
}
- return (char_u *)p;
+ return p;
}
/// Return the contents of the redo buffer as a single string.
@@ -583,7 +582,7 @@ void stuffRedoReadbuff(const char *s)
add_buff(&readbuf2, s, -1L);
}
-void stuffReadbuffLen(const char *s, long len)
+void stuffReadbuffLen(const char *s, ptrdiff_t len)
{
add_buff(&readbuf1, s, len);
}
@@ -635,7 +634,7 @@ void stuffescaped(const char *arg, bool literally)
arg++;
}
if (arg > start) {
- stuffReadbuffLen(start, (arg - start));
+ stuffReadbuffLen(start, arg - start);
}
// stuff a single special character
@@ -662,7 +661,6 @@ static int read_redo(bool init, bool old_redo)
int c;
int n;
char_u buf[MB_MAXBYTES + 1];
- int i;
if (init) {
bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next;
@@ -683,7 +681,7 @@ static int read_redo(bool init, bool old_redo)
} else {
n = 1;
}
- for (i = 0;; i++) {
+ for (int i = 0;; i++) {
if (c == K_SPECIAL) { // special key or escaped K_SPECIAL
c = TO_SPECIAL(p[1], p[2]);
p += 2;
@@ -858,7 +856,6 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
{
char_u *s1, *s2;
int addlen;
- int i;
int val;
int nrm;
@@ -948,7 +945,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
} else {
nrm = noremap;
}
- for (i = 0; i < addlen; i++) {
+ for (int i = 0; i < addlen; i++) {
typebuf.tb_noremap[typebuf.tb_off + i + offset] =
(uint8_t)((--nrm >= 0) ? val : RM_YES);
}
@@ -979,7 +976,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
int ins_char_typebuf(int c, int modifiers)
{
char_u buf[MB_MAXBYTES * 3 + 4];
- unsigned int len = special_to_buf(c, modifiers, true, buf);
+ unsigned int len = special_to_buf(c, modifiers, true, (char *)buf);
assert(len < sizeof(buf));
buf[len] = NUL;
(void)ins_typebuf((char *)buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
@@ -1020,8 +1017,6 @@ int typebuf_maplen(void)
// remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset]
void del_typebuf(int len, int offset)
{
- int i;
-
if (len == 0) {
return; // nothing to do
}
@@ -1034,7 +1029,7 @@ void del_typebuf(int len, int offset)
typebuf.tb_off += len;
} else {
// Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[]
- i = typebuf.tb_off + offset;
+ int i = typebuf.tb_off + offset;
// Leave some extra room at the end to avoid reallocation.
if (typebuf.tb_off > MAXMAPLEN) {
memmove(typebuf.tb_buf + MAXMAPLEN,
@@ -1408,10 +1403,8 @@ int merge_modifiers(int c_arg, int *modifiers)
/// Returns the modifiers in the global "mod_mask".
int vgetc(void)
{
- int c, c2;
- int n;
+ int c;
char_u buf[MB_MAXBYTES + 1];
- int i;
// Do garbage collection when garbagecollect() was called previously and
// we are now at the toplevel.
@@ -1429,6 +1422,8 @@ int vgetc(void)
mouse_row = old_mouse_row;
mouse_col = old_mouse_col;
} else {
+ int c2;
+ int n;
// number of characters recorded from the last vgetc() call
static size_t last_vgetc_recorded_len = 0;
@@ -1554,7 +1549,7 @@ int vgetc(void)
if ((n = MB_BYTE2LEN_CHECK(c)) > 1) {
no_mapping++;
buf[0] = (char_u)c;
- for (i = 1; i < n; i++) {
+ for (int i = 1; i < n; i++) {
buf[i] = (char_u)vgetorpeek(true);
if (buf[i] == K_SPECIAL) {
// Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence,
@@ -1754,9 +1749,9 @@ static void getchar_common(typval_T *argvars, typval_T *rettv)
int grid = mouse_grid;
linenr_T lnum;
win_T *wp;
- int winnr = 1;
if (row >= 0 && col >= 0) {
+ int winnr = 1;
// Find the window at the mouse coordinates and compute the
// text position.
win_T *const win = mouse_find_win(&grid, &row, &col);
@@ -1921,9 +1916,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
int max_mlen = 0;
int tb_c1;
int mlen;
- int nolmaplen;
int keylen = *keylenp;
- int i;
int local_State = get_real_state();
bool is_plug_map = false;
@@ -1956,6 +1949,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
&& State != MODE_ASKMORE
&& State != MODE_CONFIRM
&& !at_ins_compl_key()) {
+ int nolmaplen;
if (tb_c1 == K_SPECIAL) {
nolmaplen = 2;
} else {
@@ -2168,6 +2162,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// complete match
if (keylen >= 0 && keylen <= typebuf.tb_len) {
+ int i;
char *map_str = NULL;
// Write chars to script file(s).
@@ -2199,7 +2194,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// mode temporarily. Append K_SELECT to switch back to Select mode.
if (VIsual_active && VIsual_select && (mp->m_mode & MODE_VISUAL)) {
VIsual_select = false;
- (void)ins_typebuf((char *)K_SELECT_STRING, REMAP_NONE, 0, true, false);
+ (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false);
}
// Copy the values from *mp that are used, because evaluating the
@@ -2218,9 +2213,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
if (mp->m_expr) {
const int save_vgetc_busy = vgetc_busy;
const bool save_may_garbage_collect = may_garbage_collect;
- const int save_cursor_row = ui_current_row();
- const int save_cursor_col = ui_current_col();
- const handle_T save_cursor_grid = ui_cursor_grid();
const int prev_did_emsg = did_emsg;
vgetc_busy = 0;
@@ -2232,28 +2224,28 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
}
map_str = eval_map_expr(mp, NUL);
- // The mapping may do anything, but we expect it to take care of
- // redrawing. Do put the cursor back where it was.
- ui_grid_cursor_goto(save_cursor_grid, save_cursor_row, save_cursor_col);
- ui_flush();
-
- // If an error was displayed and the expression returns an empty
- // string, generate a <Nop> to allow for a redraw.
- if (prev_did_emsg != did_emsg && (map_str == NULL || *map_str == NUL)) {
- char buf[4];
- xfree(map_str);
- buf[0] = (char)K_SPECIAL;
- buf[1] = (char)KS_EXTRA;
- buf[2] = KE_IGNORE;
- buf[3] = NUL;
- map_str = xstrdup(buf);
- if (State & MODE_CMDLINE) {
- // redraw the command below the error
- msg_didout = true;
- if (msg_row < cmdline_row) {
- msg_row = cmdline_row;
+ if ((map_str == NULL || *map_str == NUL)) {
+ // If an error was displayed and the expression returns an empty
+ // string, generate a <Nop> to allow for a redraw.
+ if (prev_did_emsg != did_emsg) {
+ char buf[4];
+ xfree(map_str);
+ buf[0] = (char)K_SPECIAL;
+ buf[1] = (char)KS_EXTRA;
+ buf[2] = KE_IGNORE;
+ buf[3] = NUL;
+ map_str = xstrdup(buf);
+ if (State & MODE_CMDLINE) {
+ // redraw the command below the error
+ msg_didout = true;
+ if (msg_row < cmdline_row) {
+ msg_row = cmdline_row;
+ }
+ redrawcmd();
}
- redrawcmd();
+ } else if (State & (MODE_NORMAL | MODE_INSERT)) {
+ // otherwise, just put back the cursor
+ setcursor();
}
}
@@ -2512,9 +2504,6 @@ static int vgetorpeek(bool advance)
&& (State & MODE_INSERT)
&& (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout))
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) {
- colnr_T col = 0;
- char_u *ptr;
-
if (mode_displayed) {
unshowmode(true);
mode_deleted = true;
@@ -2525,6 +2514,8 @@ static int vgetorpeek(bool advance)
// move cursor left, if possible
if (curwin->w_cursor.col != 0) {
+ colnr_T col = 0;
+ char_u *ptr;
if (curwin->w_wcol > 0) {
// After auto-indenting and no text is following,
// we are expecting to truncate the trailing
@@ -2893,13 +2884,13 @@ int inchar(char_u *buf, int maxlen, long wait_time)
typebuf.tb_change_cnt = 1;
}
- return fix_input_buffer(buf, len);
+ return fix_input_buffer((char *)buf, len);
}
// Fix typed characters for use by vgetc() and check_termcode().
// "buf[]" must have room to triple the number of bytes!
// Returns the new length.
-int fix_input_buffer(char_u *buf, int len)
+int fix_input_buffer(char *buf, int len)
FUNC_ATTR_NONNULL_ALL
{
if (!using_script()) {
@@ -2910,13 +2901,12 @@ int fix_input_buffer(char_u *buf, int len)
}
// Reading from script, need to process special bytes
- int i;
- char_u *p = buf;
+ char_u *p = (char_u *)buf;
// Two characters are special: NUL and K_SPECIAL.
// Replace NUL by K_SPECIAL KS_ZERO KE_FILLER
// Replace K_SPECIAL by K_SPECIAL KS_SPECIAL KE_FILLER
- for (i = len; --i >= 0; p++) {
+ for (int i = len; --i >= 0; p++) {
if (p[0] == NUL
|| (p[0] == K_SPECIAL
&& (i < 2 || p[1] != KS_EXTRA))) {