diff options
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 107f61919a..4b1aea5720 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -111,7 +111,7 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) // the end. This makes it possible to retry when 'fileformat' or // 'fileencoding' was guessed wrong. line_count = curbuf->b_ml.ml_line_count; - retval = readfile(read_stdin ? NULL : curbuf->b_ffname, + retval = readfile(read_stdin ? NULL : (char *)curbuf->b_ffname, read_stdin ? NULL : curbuf->b_fname, line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, flags | READ_BUFFER, silent); @@ -229,7 +229,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags) } #endif - retval = readfile(curbuf->b_ffname, curbuf->b_fname, + retval = readfile((char *)curbuf->b_ffname, curbuf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, flags | READ_NEW | (read_fifo ? READ_FIFO : 0), silent); #ifdef UNIX @@ -1219,8 +1219,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) return FAIL; } } else { - semsg(_("E89: %s will be killed (add ! to override)"), - (char *)buf->b_fname); + semsg(_("E89: %s will be killed (add ! to override)"), buf->b_fname); return FAIL; } } @@ -1476,7 +1475,7 @@ void set_curbuf(buf_T *buf, int action) // Do not sync when in Insert mode and the buffer is open in // another window, might be a timer doing something in another // window. - if (prevbuf == curbuf && ((State & INSERT) == 0 || curbuf->b_nwindows <= 1)) { + if (prevbuf == curbuf && ((State & MODE_INSERT) == 0 || curbuf->b_nwindows <= 1)) { u_sync(false); } close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, @@ -1803,7 +1802,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl hash_init(&buf->b_s.b_keywtab); hash_init(&buf->b_s.b_keywtab_ic); - buf->b_fname = buf->b_sfname; + buf->b_fname = (char *)buf->b_sfname; if (!file_id_valid) { buf->file_id_valid = false; } else { @@ -2113,10 +2112,10 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis { int match = -1; int find_listed; - char_u *pat; - char_u *patend; + char *pat; + char *patend; int attempt; - char_u *p; + char *p; int toggledollar; if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) { @@ -2138,7 +2137,7 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis // Repeat this for finding an unlisted buffer if there was no matching // listed buffer. - pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false); + pat = file_pat_to_reg_pat((char *)pattern, (char *)pattern_end, NULL, false); if (pat == NULL) { return -1; } @@ -2271,7 +2270,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) } regmatch_T regmatch; - regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); + regmatch.regprog = vim_regcomp((char *)patc + attempt * 11, RE_MAGIC); if (regmatch.regprog == NULL) { if (patc != pat) { xfree(patc); @@ -2366,7 +2365,7 @@ static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) { // First try the short file name, then the long file name. char_u *match = fname_match(rmp, buf->b_sfname, ignore_case); - if (match == NULL) { + if (match == NULL && rmp->regprog != NULL) { match = fname_match(rmp, buf->b_ffname, ignore_case); } return match; @@ -2387,7 +2386,7 @@ static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case) rmp->rm_ic = p_fic || ignore_case; if (vim_regexec(rmp, name, (colnr_T)0)) { match = name; - } else { + } else if (rmp->regprog != NULL) { // Replace $(HOME) with '~' and try matching again. p = home_replace_save(NULL, name); if (vim_regexec(rmp, p, (colnr_T)0)) { @@ -2426,7 +2425,7 @@ char_u *buflist_nr2name(int n, int fullname, int helptail) return NULL; } return home_replace_save(helptail ? buf : NULL, - fullname ? buf->b_ffname : buf->b_fname); + fullname ? buf->b_ffname : (char_u *)buf->b_fname); } /// Set the line and column numbers for the given buffer and window @@ -2622,7 +2621,7 @@ void buflist_list(exarg_T *eap) garray_T buflist; buf_T **buflist_data = NULL; - if (vim_strchr((char_u *)eap->arg, 't')) { + if (vim_strchr(eap->arg, 't')) { ga_init(&buflist, sizeof(buf_T *), 50); for (buf = firstbuf; buf != NULL; buf = buf->b_next) { ga_grow(&buflist, 1); @@ -2645,28 +2644,28 @@ void buflist_list(exarg_T *eap) const bool job_running = buf->terminal && terminal_running(buf->terminal); // skip unspecified buffers - if ((!buf->b_p_bl && !eap->forceit && !vim_strchr((char_u *)eap->arg, 'u')) - || (vim_strchr((char_u *)eap->arg, 'u') && buf->b_p_bl) - || (vim_strchr((char_u *)eap->arg, '+') + if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) + || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) + || (vim_strchr(eap->arg, '+') && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) - || (vim_strchr((char_u *)eap->arg, 'a') + || (vim_strchr(eap->arg, 'a') && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0)) - || (vim_strchr((char_u *)eap->arg, 'h') + || (vim_strchr(eap->arg, 'h') && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0)) - || (vim_strchr((char_u *)eap->arg, 'R') && (!is_terminal || !job_running)) - || (vim_strchr((char_u *)eap->arg, 'F') && (!is_terminal || job_running)) - || (vim_strchr((char_u *)eap->arg, '-') && buf->b_p_ma) - || (vim_strchr((char_u *)eap->arg, '=') && !buf->b_p_ro) - || (vim_strchr((char_u *)eap->arg, 'x') && !(buf->b_flags & BF_READERR)) - || (vim_strchr((char_u *)eap->arg, '%') && buf != curbuf) - || (vim_strchr((char_u *)eap->arg, '#') + || (vim_strchr(eap->arg, 'R') && (!is_terminal || !job_running)) + || (vim_strchr(eap->arg, 'F') && (!is_terminal || job_running)) + || (vim_strchr(eap->arg, '-') && buf->b_p_ma) + || (vim_strchr(eap->arg, '=') && !buf->b_p_ro) + || (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR)) + || (vim_strchr(eap->arg, '%') && buf != curbuf) + || (vim_strchr(eap->arg, '#') && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) { continue; } if (buf_spname(buf) != NULL) { STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); } else { - home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, true); + home_replace(buf, (char_u *)buf->b_fname, NameBuff, MAXPATHL, true); } if (message_filtered(NameBuff)) { @@ -2700,7 +2699,7 @@ void buflist_list(exarg_T *eap) do { IObuff[len++] = ' '; } while (--i > 0 && len < IOSIZE - 18); - if (vim_strchr((char_u *)eap->arg, 't') && buf->b_last_used) { + if (vim_strchr(eap->arg, 't') && buf->b_last_used) { undo_fmt_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used); } else { vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), _("line %" PRId64), @@ -2730,7 +2729,7 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum) return FAIL; } - *fname = buf->b_fname; + *fname = (char_u *)buf->b_fname; *lnum = buflist_findlnum(buf); return OK; @@ -2794,7 +2793,7 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message) buf->b_ffname = ffname; buf->b_sfname = sfname; } - buf->b_fname = buf->b_sfname; + buf->b_fname = (char *)buf->b_sfname; if (!file_id_valid) { buf->file_id_valid = false; } else { @@ -2823,7 +2822,7 @@ void buf_set_name(int fnum, char_u *name) // Allocate ffname and expand into full path. Also resolves .lnk // files on Win32. fname_expand(buf, &buf->b_ffname, &buf->b_sfname); - buf->b_fname = buf->b_sfname; + buf->b_fname = (char *)buf->b_sfname; } } @@ -2980,7 +2979,7 @@ void buf_set_file_id(buf_T *buf) { FileID file_id; if (buf->b_fname != NULL - && os_fileid((char *)buf->b_fname, &file_id)) { + && os_fileid(buf->b_fname, &file_id)) { buf->file_id_valid = true; buf->file_id = file_id; } else { @@ -3023,7 +3022,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) STRLCPY(p, buf_spname(curbuf), IOSIZE - (p - buffer)); } else { if (!fullname && curbuf->b_fname != NULL) { - name = curbuf->b_fname; + name = (char_u *)curbuf->b_fname; } else { name = curbuf->b_ffname; } @@ -3285,7 +3284,7 @@ void maketitle(void) if (buf_spname(curbuf) != NULL) { buf_p = buf_spname(curbuf); } else { // use file name only in icon - buf_p = path_tail(curbuf->b_ffname); + buf_p = (char_u *)path_tail((char *)curbuf->b_ffname); } *icon_str = NUL; // Truncate name at 100 bytes. @@ -3635,7 +3634,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san // correct the start of the items for the truncation for (int idx = stl_groupitems[groupdepth] + 1; idx < curitem; idx++) { // Shift everything back by the number of removed bytes - stl_items[idx].start -= n; + // Minus one for the leading '<' added above. + stl_items[idx].start -= n - 1; // If the item was partially or completely truncated, set its // start to the start of the group @@ -3833,14 +3833,14 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san STRLCPY(NameBuff, buf_spname(wp->w_buffer), MAXPATHL); } else { char_u *t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname - : wp->w_buffer->b_fname; + : (char_u *)wp->w_buffer->b_fname; home_replace(wp->w_buffer, t, NameBuff, MAXPATHL, true); } trans_characters(NameBuff, MAXPATHL); if (opt != STL_FILENAME) { str = (char *)NameBuff; } else { - str = (char *)path_tail(NameBuff); + str = path_tail((char *)NameBuff); } break; case STL_VIM_EXPR: // '{' @@ -3908,7 +3908,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san // Check if the evaluated result is a number. // If so, convert the number to an int and free the string. if (str != NULL && *str != 0) { - if (*skipdigits((char_u *)str) == NUL) { + if (*skipdigits(str) == NUL) { num = atoi(str); XFREE_CLEAR(str); itemisflag = false; @@ -3961,8 +3961,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san break; case STL_COLUMN: - num = !(State & INSERT) && empty_line - ? 0 : (int)wp->w_cursor.col + 1; + num = (State & MODE_INSERT) == 0 && empty_line ? 0 : (int)wp->w_cursor.col + 1; break; case STL_VIRTCOL: @@ -3970,7 +3969,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san colnr_T virtcol = wp->w_virtcol + 1; // Don't display %V if it's the same as %c. if (opt == STL_VIRTCOL_ALT - && (virtcol == (colnr_T)(!(State & INSERT) && empty_line + && (virtcol == (colnr_T)((State & MODE_INSERT) == 0 && empty_line ? 0 : (int)wp->w_cursor.col + 1))) { break; } @@ -4028,7 +4027,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL, false); num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? - 0L : l + 1 + (!(State & INSERT) && empty_line ? + 0L : l + 1 + ((State & MODE_INSERT) == 0 && empty_line ? 0 : (int)wp->w_cursor.col); break; } @@ -4650,7 +4649,7 @@ char_u *alist_name(aentry_T *aep) if (bp == NULL || bp->b_fname == NULL) { return aep->ae_fname; } - return bp->b_fname; + return (char_u *)bp->b_fname; } /// do_arg_all(): Open up to 'count' windows, one for each argument. @@ -5201,9 +5200,9 @@ static int chk_modeline(linenr_T lnum, int flags) s = linecopy = vim_strsave(s); // copy the line, it will change save_sourcing_lnum = sourcing_lnum; - save_sourcing_name = sourcing_name; + save_sourcing_name = (char_u *)sourcing_name; sourcing_lnum = lnum; // prepare for emsg() - sourcing_name = (char_u *)"modelines"; + sourcing_name = "modelines"; end = false; while (end == false) { @@ -5234,7 +5233,7 @@ static int chk_modeline(linenr_T lnum, int flags) break; } end = true; - s = vim_strchr(s, ' ') + 1; + s = (char_u *)vim_strchr((char *)s, ' ') + 1; } *e = NUL; // truncate the set command @@ -5259,7 +5258,7 @@ static int chk_modeline(linenr_T lnum, int flags) } sourcing_lnum = save_sourcing_lnum; - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; xfree(linecopy); @@ -5358,7 +5357,7 @@ char_u *buf_spname(buf_T *buf) // contains the name as specified by the user. if (bt_nofile(buf)) { if (buf->b_fname != NULL) { - return buf->b_fname; + return (char_u *)buf->b_fname; } if (bt_prompt(buf)) { return (char_u *)_("[Prompt]"); @@ -5552,7 +5551,7 @@ char_u *buf_get_fname(const buf_T *buf) if (buf->b_fname == NULL) { return (char_u *)_("[No Name]"); } - return buf->b_fname; + return (char_u *)buf->b_fname; } /// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. @@ -5594,7 +5593,7 @@ bool buf_contents_changed(buf_T *buf) aucmd_prepbuf(&aco, newbuf); if (ml_open(curbuf) == OK - && readfile(buf->b_ffname, buf->b_fname, + && readfile((char *)buf->b_ffname, buf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, READ_NEW | READ_DUMMY, false) == OK) { // compare the two files line by line |