diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-02-23 22:49:57 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-02-23 23:00:06 -0500 |
commit | ab5083b5fc9fc8c62dae6aefc4fb2615a61c6fff (patch) | |
tree | 390d832a3ba5097718141f87a19eb1a9e789d927 | |
parent | ceed85ea431b8fb4f694e4fca09f97e2a22f69d9 (diff) | |
download | rneovim-ab5083b5fc9fc8c62dae6aefc4fb2615a61c6fff.tar.gz rneovim-ab5083b5fc9fc8c62dae6aefc4fb2615a61c6fff.tar.bz2 rneovim-ab5083b5fc9fc8c62dae6aefc4fb2615a61c6fff.zip |
pos: define MAXCOL to INT_MAX
Partial port of patch v8.1.0953.
Remove useless casts on MAXCOL.
-rw-r--r-- | src/nvim/charset.c | 2 | ||||
-rw-r--r-- | src/nvim/edit.c | 15 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 2 | ||||
-rw-r--r-- | src/nvim/memline.c | 2 | ||||
-rw-r--r-- | src/nvim/misc1.c | 2 | ||||
-rw-r--r-- | src/nvim/normal.c | 23 | ||||
-rw-r--r-- | src/nvim/ops.c | 9 | ||||
-rw-r--r-- | src/nvim/pos.h | 7 | ||||
-rw-r--r-- | src/nvim/search.c | 10 | ||||
-rw-r--r-- | src/nvim/tag.c | 2 |
11 files changed, 41 insertions, 37 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index be265e3f27..5ad1fe0dfd 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -708,7 +708,7 @@ int ptr2cells(const char_u *p) /// @return number of character cells. int vim_strsize(char_u *s) { - return vim_strnsize(s, (int)MAXCOL); + return vim_strnsize(s, MAXCOL); } /// Return the number of character cells string "s[len]" will take on the diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 100e88e261..53717229f6 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1627,11 +1627,11 @@ static void init_prompt(int cmdchar_todo) ml_append(curbuf->b_ml.ml_line_count, prompt, 0, false); } curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); changed_bytes(curbuf->b_ml.ml_line_count, 0); } if (cmdchar_todo == 'A') { - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) { curwin->w_cursor.col = STRLEN(prompt); @@ -6246,9 +6246,10 @@ void auto_format( if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { // "cannot happen" curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); - } else + coladvance(MAXCOL); + } else { check_cursor_col(); + } // Insert mode: If the cursor is now after the end of the line while it // previously wasn't, the line was broken. Because of the rule above we @@ -8432,8 +8433,8 @@ static void ins_left(void) // if 'whichwrap' set for cursor in insert mode may go to previous line. // always break undo when moving upwards/downwards, else undo may break start_arrow(&tpos); - --(curwin->w_cursor.lnum); - coladvance((colnr_T)MAXCOL); + curwin->w_cursor.lnum--; + coladvance(MAXCOL); curwin->w_set_curswant = true; // so we stay at the end } else { vim_beep(BO_CRSR); @@ -8467,7 +8468,7 @@ static void ins_end(int c) tpos = curwin->w_cursor; if (c == K_C_END) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); curwin->w_curswant = MAXCOL; start_arrow(&tpos); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b220b034dd..103c081143 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4198,7 +4198,7 @@ skip: // when interactive leave cursor on the match if (!subflags.do_ask) { if (endcolumn) { - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else { beginline(BL_WHITE | BL_FIX); } @@ -5020,7 +5020,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, if (keep_lang) { flags |= TAG_KEEP_LANG; } - if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK + if (find_tags(IObuff, num_matches, matches, flags, MAXCOL, NULL) == OK && *num_matches > 0) { /* Sort the matches found on the heuristic number that is after the * tag name. */ diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c66ae13f53..d470bfb418 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -6774,6 +6774,6 @@ static void set_search_match(pos_T *t) t->col = search_match_endcol; if (t->lnum > curbuf->b_ml.ml_line_count) { t->lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 31dc6b3649..293a4d01db 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -4142,7 +4142,7 @@ void goto_byte(long cnt) if (lnum < 1) { // past the end curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_curswant = MAXCOL; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else { curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = (colnr_T)boff; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index fcffe64595..34c43da0f7 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -412,7 +412,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) s = ml_get_buf(wp->w_buffer, lnum, FALSE); if (*s == NUL) /* empty line */ return 1; - col = win_linetabsize(wp, s, (colnr_T)MAXCOL); + col = win_linetabsize(wp, s, MAXCOL); // If list mode is on, then the '$' at the end of the line may take up one // extra column. diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 530c0a17e5..d5c92bc3e6 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5225,16 +5225,13 @@ static void nv_left(cmdarg_T *cap) * 'h' wraps to previous line if 'whichwrap' has 'h'. * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. */ - if ( (((cap->cmdchar == K_BS - || cap->cmdchar == Ctrl_H) - && vim_strchr(p_ww, 'b') != NULL) - || (cap->cmdchar == 'h' - && vim_strchr(p_ww, 'h') != NULL) - || (cap->cmdchar == K_LEFT - && vim_strchr(p_ww, '<') != NULL)) - && curwin->w_cursor.lnum > 1) { - --(curwin->w_cursor.lnum); - coladvance((colnr_T)MAXCOL); + if ((((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) + && vim_strchr(p_ww, 'b') != NULL) + || (cap->cmdchar == 'h' && vim_strchr(p_ww, 'h') != NULL) + || (cap->cmdchar == K_LEFT && vim_strchr(p_ww, '<') != NULL)) + && curwin->w_cursor.lnum > 1) { + curwin->w_cursor.lnum--; + coladvance(MAXCOL); curwin->w_set_curswant = true; // When the NL before the first char has to be deleted we @@ -6471,7 +6468,7 @@ static void nv_visual(cmdarg_T *cap) } if (resel_VIsual_vcol == MAXCOL) { curwin->w_curswant = MAXCOL; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else if (VIsual_mode == Ctrl_V) { validate_virtcol(); assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX); @@ -7610,7 +7607,7 @@ void set_cursor_for_append_to_line(void) // Pretend Insert mode here to allow the cursor on the // character past the end of the line State = INSERT; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); State = save_State; } else { curwin->w_cursor.col += (colnr_T)STRLEN(get_cursor_pos_ptr()); @@ -7998,7 +7995,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) * line. */ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } } auto_format(false, true); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ea52d6a3d3..3038fad894 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4305,11 +4305,12 @@ format_lines( * tabs and spaces, according to current options */ (void)set_indent(get_indent(), SIN_CHANGED); - /* put cursor on last non-space */ - State = NORMAL; /* don't go past end-of-line */ - coladvance((colnr_T)MAXCOL); - while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) + // put cursor on last non-space + State = NORMAL; // don't go past end-of-line + coladvance(MAXCOL); + while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) { dec_cursor(); + } /* do the formatting, without 'showmode' */ State = INSERT; /* for open_line() */ diff --git a/src/nvim/pos.h b/src/nvim/pos.h index 8e86ea08c5..b7c4b6ef92 100644 --- a/src/nvim/pos.h +++ b/src/nvim/pos.h @@ -1,6 +1,9 @@ #ifndef NVIM_POS_H #define NVIM_POS_H +// for INT_MAX, LONG_MAX et al. +#include <limits.h> + typedef long linenr_T; // line number type /// Format used to print values which have linenr_T type #define PRIdLINENR "ld" @@ -12,8 +15,8 @@ typedef int colnr_T; /// Maximal (invalid) line number enum { MAXLNUM = 0x7fffffff }; -/// Maximal column number, 31 bits -enum { MAXCOL = 0x7fffffff }; +/// Maximal column number +enum { MAXCOL = INT_MAX }; // Minimum line number enum { MINLNUM = 1 }; // minimum column number diff --git a/src/nvim/search.c b/src/nvim/search.c index 2802da6f7f..84b71d56a0 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2685,8 +2685,9 @@ fwd_word( while (--count >= 0) { /* When inside a range of folded lines, move to the last char of the * last line. */ - if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) - coladvance((colnr_T)MAXCOL); + if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { + coladvance(MAXCOL); + } sclass = cls(); /* @@ -2803,8 +2804,9 @@ int end_word(long count, int bigword, int stop, int empty) while (--count >= 0) { /* When inside a range of folded lines, move to the last char of the * last line. */ - if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) - coladvance((colnr_T)MAXCOL); + if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { + coladvance(MAXCOL); + } sclass = cls(); if (inc_cursor() == -1) return FAIL; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 84ca240734..4ea298fba9 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -3152,7 +3152,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) bool is_static; ret = find_tags(pat, &num_matches, &matches, - TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname); + TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname); if (ret == OK && num_matches > 0) { for (i = 0; i < num_matches; ++i) { int parse_result = parse_match(matches[i], &tp); |